@@ -15,10 +15,10 @@ |
||
| 15 | 15 | $settings = array(); |
| 16 | 16 | $settings['restUrl'] = get_rest_url( |
| 17 | 17 | null, |
| 18 | - Api_Config::REST_NAMESPACE . '/tags' |
|
| 18 | + Api_Config::REST_NAMESPACE.'/tags' |
|
| 19 | 19 | ); |
| 20 | - $settings['baseUrl'] = get_rest_url( null, Api_Config::REST_NAMESPACE ); |
|
| 21 | - $settings['nonce'] = wp_create_nonce( 'wp_rest' ); |
|
| 20 | + $settings['baseUrl'] = get_rest_url(null, Api_Config::REST_NAMESPACE); |
|
| 21 | + $settings['nonce'] = wp_create_nonce('wp_rest'); |
|
| 22 | 22 | |
| 23 | 23 | return $settings; |
| 24 | 24 | } |
@@ -8,19 +8,19 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Api_Config { |
| 10 | 10 | |
| 11 | - const REST_NAMESPACE = 'cafemediakg/v1'; |
|
| 11 | + const REST_NAMESPACE = 'cafemediakg/v1'; |
|
| 12 | 12 | |
| 13 | - public static function get_api_config() { |
|
| 14 | - // Create ui settings array to be used by js client. |
|
| 15 | - $settings = array(); |
|
| 16 | - $settings['restUrl'] = get_rest_url( |
|
| 17 | - null, |
|
| 18 | - Api_Config::REST_NAMESPACE . '/tags' |
|
| 19 | - ); |
|
| 20 | - $settings['baseUrl'] = get_rest_url( null, Api_Config::REST_NAMESPACE ); |
|
| 21 | - $settings['nonce'] = wp_create_nonce( 'wp_rest' ); |
|
| 13 | + public static function get_api_config() { |
|
| 14 | + // Create ui settings array to be used by js client. |
|
| 15 | + $settings = array(); |
|
| 16 | + $settings['restUrl'] = get_rest_url( |
|
| 17 | + null, |
|
| 18 | + Api_Config::REST_NAMESPACE . '/tags' |
|
| 19 | + ); |
|
| 20 | + $settings['baseUrl'] = get_rest_url( null, Api_Config::REST_NAMESPACE ); |
|
| 21 | + $settings['nonce'] = wp_create_nonce( 'wp_rest' ); |
|
| 22 | 22 | |
| 23 | - return $settings; |
|
| 24 | - } |
|
| 23 | + return $settings; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | } |
@@ -14,132 +14,132 @@ |
||
| 14 | 14 | |
| 15 | 15 | class Background_Analysis_Endpoint { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var Analysis_Background_Service |
|
| 19 | - */ |
|
| 20 | - private $background_service; |
|
| 21 | - /** |
|
| 22 | - * @var Options_Cache |
|
| 23 | - */ |
|
| 24 | - private $cache_service; |
|
| 25 | - |
|
| 26 | - public function __construct( $background_service, $cache_service ) { |
|
| 27 | - $this->background_service = $background_service; |
|
| 28 | - $this->cache_service = $cache_service; |
|
| 29 | - $this->register_routes(); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function register_routes() { |
|
| 33 | - $that = $this; |
|
| 34 | - add_action( 'rest_api_init', |
|
| 35 | - function () use ( $that ) { |
|
| 36 | - $that->register_start_route(); |
|
| 37 | - $that->register_stop_route(); |
|
| 38 | - $that->register_stats_route(); |
|
| 39 | - $that->register_restart_route(); |
|
| 40 | - } ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - private function register_start_route() { |
|
| 44 | - register_rest_route( |
|
| 45 | - Api_Config::REST_NAMESPACE, |
|
| 46 | - '/background_analysis/start', |
|
| 47 | - array( |
|
| 48 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 49 | - 'callback' => array( $this, 'start' ), |
|
| 50 | - 'permission_callback' => function () { |
|
| 51 | - return current_user_can( 'manage_options' ); |
|
| 52 | - }, |
|
| 53 | - ) |
|
| 54 | - ); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - private function register_stop_route() { |
|
| 58 | - register_rest_route( |
|
| 59 | - Api_Config::REST_NAMESPACE, |
|
| 60 | - '/background_analysis/stop', |
|
| 61 | - array( |
|
| 62 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 63 | - 'callback' => array( $this, 'stop' ), |
|
| 64 | - 'permission_callback' => function () { |
|
| 65 | - return current_user_can( 'manage_options' ); |
|
| 66 | - }, |
|
| 67 | - ) |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - private function register_stats_route() { |
|
| 72 | - register_rest_route( |
|
| 73 | - Api_Config::REST_NAMESPACE, |
|
| 74 | - '/background_analysis/stats', |
|
| 75 | - array( |
|
| 76 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 77 | - 'callback' => array( $this, 'get_stats' ), |
|
| 78 | - 'permission_callback' => function () { |
|
| 79 | - return current_user_can( 'manage_options' ); |
|
| 80 | - }, |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - private function register_restart_route() { |
|
| 87 | - register_rest_route( |
|
| 88 | - Api_Config::REST_NAMESPACE, |
|
| 89 | - '/background_analysis/restart', |
|
| 90 | - array( |
|
| 91 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 92 | - 'callback' => array( $this, 'restart' ), |
|
| 93 | - 'permission_callback' => function () { |
|
| 94 | - return current_user_can( 'manage_options' ); |
|
| 95 | - }, |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - public function get_stats() { |
|
| 102 | - /** |
|
| 103 | - * @var $state Sync_State |
|
| 104 | - */ |
|
| 105 | - $state = get_option( Analysis_Background_Process::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
| 106 | - |
|
| 107 | - return $state->get_array(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function start() { |
|
| 111 | - $this->background_service->start(); |
|
| 112 | - |
|
| 113 | - return true; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - public function restart() { |
|
| 118 | - $this->background_service->cancel(); |
|
| 119 | - // clear the flags and restart again. |
|
| 120 | - global $wpdb; |
|
| 121 | - $query = <<<EOF |
|
| 17 | + /** |
|
| 18 | + * @var Analysis_Background_Service |
|
| 19 | + */ |
|
| 20 | + private $background_service; |
|
| 21 | + /** |
|
| 22 | + * @var Options_Cache |
|
| 23 | + */ |
|
| 24 | + private $cache_service; |
|
| 25 | + |
|
| 26 | + public function __construct( $background_service, $cache_service ) { |
|
| 27 | + $this->background_service = $background_service; |
|
| 28 | + $this->cache_service = $cache_service; |
|
| 29 | + $this->register_routes(); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function register_routes() { |
|
| 33 | + $that = $this; |
|
| 34 | + add_action( 'rest_api_init', |
|
| 35 | + function () use ( $that ) { |
|
| 36 | + $that->register_start_route(); |
|
| 37 | + $that->register_stop_route(); |
|
| 38 | + $that->register_stats_route(); |
|
| 39 | + $that->register_restart_route(); |
|
| 40 | + } ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + private function register_start_route() { |
|
| 44 | + register_rest_route( |
|
| 45 | + Api_Config::REST_NAMESPACE, |
|
| 46 | + '/background_analysis/start', |
|
| 47 | + array( |
|
| 48 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 49 | + 'callback' => array( $this, 'start' ), |
|
| 50 | + 'permission_callback' => function () { |
|
| 51 | + return current_user_can( 'manage_options' ); |
|
| 52 | + }, |
|
| 53 | + ) |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + private function register_stop_route() { |
|
| 58 | + register_rest_route( |
|
| 59 | + Api_Config::REST_NAMESPACE, |
|
| 60 | + '/background_analysis/stop', |
|
| 61 | + array( |
|
| 62 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 63 | + 'callback' => array( $this, 'stop' ), |
|
| 64 | + 'permission_callback' => function () { |
|
| 65 | + return current_user_can( 'manage_options' ); |
|
| 66 | + }, |
|
| 67 | + ) |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + private function register_stats_route() { |
|
| 72 | + register_rest_route( |
|
| 73 | + Api_Config::REST_NAMESPACE, |
|
| 74 | + '/background_analysis/stats', |
|
| 75 | + array( |
|
| 76 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 77 | + 'callback' => array( $this, 'get_stats' ), |
|
| 78 | + 'permission_callback' => function () { |
|
| 79 | + return current_user_can( 'manage_options' ); |
|
| 80 | + }, |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + private function register_restart_route() { |
|
| 87 | + register_rest_route( |
|
| 88 | + Api_Config::REST_NAMESPACE, |
|
| 89 | + '/background_analysis/restart', |
|
| 90 | + array( |
|
| 91 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 92 | + 'callback' => array( $this, 'restart' ), |
|
| 93 | + 'permission_callback' => function () { |
|
| 94 | + return current_user_can( 'manage_options' ); |
|
| 95 | + }, |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + public function get_stats() { |
|
| 102 | + /** |
|
| 103 | + * @var $state Sync_State |
|
| 104 | + */ |
|
| 105 | + $state = get_option( Analysis_Background_Process::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
| 106 | + |
|
| 107 | + return $state->get_array(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function start() { |
|
| 111 | + $this->background_service->start(); |
|
| 112 | + |
|
| 113 | + return true; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + public function restart() { |
|
| 118 | + $this->background_service->cancel(); |
|
| 119 | + // clear the flags and restart again. |
|
| 120 | + global $wpdb; |
|
| 121 | + $query = <<<EOF |
|
| 122 | 122 | DELETE FROM $wpdb->termmeta WHERE meta_key=%s OR meta_key=%s |
| 123 | 123 | EOF; |
| 124 | - // Remove the flags, if the tag is already accepted we wont remove that ui flag. |
|
| 125 | - $query = $wpdb->prepare( $query, array( |
|
| 126 | - Analysis_Background_Service::ANALYSIS_DONE_FLAG, |
|
| 127 | - Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM |
|
| 128 | - ) ); |
|
| 129 | - $wpdb->query( $query ); |
|
| 130 | - // clear the cache |
|
| 131 | - $this->cache_service->flush_all(); |
|
| 132 | - $this->background_service->start(); |
|
| 124 | + // Remove the flags, if the tag is already accepted we wont remove that ui flag. |
|
| 125 | + $query = $wpdb->prepare( $query, array( |
|
| 126 | + Analysis_Background_Service::ANALYSIS_DONE_FLAG, |
|
| 127 | + Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM |
|
| 128 | + ) ); |
|
| 129 | + $wpdb->query( $query ); |
|
| 130 | + // clear the cache |
|
| 131 | + $this->cache_service->flush_all(); |
|
| 132 | + $this->background_service->start(); |
|
| 133 | 133 | |
| 134 | - return array( 'status' => 'restart_complete' ); |
|
| 135 | - } |
|
| 134 | + return array( 'status' => 'restart_complete' ); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | |
| 138 | - public function stop() { |
|
| 139 | - $this->background_service->stop(); |
|
| 138 | + public function stop() { |
|
| 139 | + $this->background_service->stop(); |
|
| 140 | 140 | |
| 141 | - return true; |
|
| 142 | - } |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | 145 | } |
| 146 | 146 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | private $cache_service; |
| 25 | 25 | |
| 26 | - public function __construct( $background_service, $cache_service ) { |
|
| 26 | + public function __construct($background_service, $cache_service) { |
|
| 27 | 27 | $this->background_service = $background_service; |
| 28 | 28 | $this->cache_service = $cache_service; |
| 29 | 29 | $this->register_routes(); |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function register_routes() { |
| 33 | 33 | $that = $this; |
| 34 | - add_action( 'rest_api_init', |
|
| 35 | - function () use ( $that ) { |
|
| 34 | + add_action('rest_api_init', |
|
| 35 | + function() use ($that) { |
|
| 36 | 36 | $that->register_start_route(); |
| 37 | 37 | $that->register_stop_route(); |
| 38 | 38 | $that->register_stats_route(); |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | '/background_analysis/start', |
| 47 | 47 | array( |
| 48 | 48 | 'methods' => WP_REST_Server::CREATABLE, |
| 49 | - 'callback' => array( $this, 'start' ), |
|
| 50 | - 'permission_callback' => function () { |
|
| 51 | - return current_user_can( 'manage_options' ); |
|
| 49 | + 'callback' => array($this, 'start'), |
|
| 50 | + 'permission_callback' => function() { |
|
| 51 | + return current_user_can('manage_options'); |
|
| 52 | 52 | }, |
| 53 | 53 | ) |
| 54 | 54 | ); |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | '/background_analysis/stop', |
| 61 | 61 | array( |
| 62 | 62 | 'methods' => WP_REST_Server::CREATABLE, |
| 63 | - 'callback' => array( $this, 'stop' ), |
|
| 64 | - 'permission_callback' => function () { |
|
| 65 | - return current_user_can( 'manage_options' ); |
|
| 63 | + 'callback' => array($this, 'stop'), |
|
| 64 | + 'permission_callback' => function() { |
|
| 65 | + return current_user_can('manage_options'); |
|
| 66 | 66 | }, |
| 67 | 67 | ) |
| 68 | 68 | ); |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | '/background_analysis/stats', |
| 75 | 75 | array( |
| 76 | 76 | 'methods' => WP_REST_Server::CREATABLE, |
| 77 | - 'callback' => array( $this, 'get_stats' ), |
|
| 78 | - 'permission_callback' => function () { |
|
| 79 | - return current_user_can( 'manage_options' ); |
|
| 77 | + 'callback' => array($this, 'get_stats'), |
|
| 78 | + 'permission_callback' => function() { |
|
| 79 | + return current_user_can('manage_options'); |
|
| 80 | 80 | }, |
| 81 | 81 | ) |
| 82 | 82 | ); |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | '/background_analysis/restart', |
| 90 | 90 | array( |
| 91 | 91 | 'methods' => WP_REST_Server::CREATABLE, |
| 92 | - 'callback' => array( $this, 'restart' ), |
|
| 93 | - 'permission_callback' => function () { |
|
| 94 | - return current_user_can( 'manage_options' ); |
|
| 92 | + 'callback' => array($this, 'restart'), |
|
| 93 | + 'permission_callback' => function() { |
|
| 94 | + return current_user_can('manage_options'); |
|
| 95 | 95 | }, |
| 96 | 96 | ) |
| 97 | 97 | ); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * @var $state Sync_State |
| 104 | 104 | */ |
| 105 | - $state = get_option( Analysis_Background_Process::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
| 105 | + $state = get_option(Analysis_Background_Process::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown()); |
|
| 106 | 106 | |
| 107 | 107 | return $state->get_array(); |
| 108 | 108 | } |
@@ -122,16 +122,16 @@ discard block |
||
| 122 | 122 | DELETE FROM $wpdb->termmeta WHERE meta_key=%s OR meta_key=%s |
| 123 | 123 | EOF; |
| 124 | 124 | // Remove the flags, if the tag is already accepted we wont remove that ui flag. |
| 125 | - $query = $wpdb->prepare( $query, array( |
|
| 125 | + $query = $wpdb->prepare($query, array( |
|
| 126 | 126 | Analysis_Background_Service::ANALYSIS_DONE_FLAG, |
| 127 | 127 | Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM |
| 128 | - ) ); |
|
| 129 | - $wpdb->query( $query ); |
|
| 128 | + )); |
|
| 129 | + $wpdb->query($query); |
|
| 130 | 130 | // clear the cache |
| 131 | 131 | $this->cache_service->flush_all(); |
| 132 | 132 | $this->background_service->start(); |
| 133 | 133 | |
| 134 | - return array( 'status' => 'restart_complete' ); |
|
| 134 | + return array('status' => 'restart_complete'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -4,56 +4,56 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Sync_State { |
| 6 | 6 | |
| 7 | - public $started; |
|
| 8 | - public $index; |
|
| 9 | - public $count; |
|
| 10 | - public $last_update; |
|
| 11 | - public $state; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * Sync_Model constructor. |
|
| 15 | - * |
|
| 16 | - * @param $started |
|
| 17 | - * @param $index |
|
| 18 | - * @param $count |
|
| 19 | - * @param $last_update |
|
| 20 | - * @param $state |
|
| 21 | - */ |
|
| 22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
| 23 | - $this->started = $started; |
|
| 24 | - $this->index = $index; |
|
| 25 | - $this->count = (int) $count; |
|
| 26 | - $this->last_update = $last_update; |
|
| 27 | - $this->state = $state; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function increment_index( $count ) { |
|
| 31 | - $this->index += $count; |
|
| 32 | - $this->last_update = time(); |
|
| 33 | - |
|
| 34 | - return $this; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function set_state( $value ) { |
|
| 38 | - $this->state = $value; |
|
| 39 | - $this->last_update = time(); |
|
| 40 | - |
|
| 41 | - return $this; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function get_array() { |
|
| 45 | - return array( |
|
| 46 | - 'started' => $this->started, |
|
| 47 | - 'index' => $this->index, |
|
| 48 | - 'count' => $this->count, |
|
| 49 | - 'last_update' => $this->last_update, |
|
| 50 | - 'state' => $this->state |
|
| 51 | - ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public static function unknown() { |
|
| 55 | - |
|
| 56 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
| 57 | - } |
|
| 7 | + public $started; |
|
| 8 | + public $index; |
|
| 9 | + public $count; |
|
| 10 | + public $last_update; |
|
| 11 | + public $state; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * Sync_Model constructor. |
|
| 15 | + * |
|
| 16 | + * @param $started |
|
| 17 | + * @param $index |
|
| 18 | + * @param $count |
|
| 19 | + * @param $last_update |
|
| 20 | + * @param $state |
|
| 21 | + */ |
|
| 22 | + public function __construct( $started, $index, $count, $last_update, $state ) { |
|
| 23 | + $this->started = $started; |
|
| 24 | + $this->index = $index; |
|
| 25 | + $this->count = (int) $count; |
|
| 26 | + $this->last_update = $last_update; |
|
| 27 | + $this->state = $state; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function increment_index( $count ) { |
|
| 31 | + $this->index += $count; |
|
| 32 | + $this->last_update = time(); |
|
| 33 | + |
|
| 34 | + return $this; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function set_state( $value ) { |
|
| 38 | + $this->state = $value; |
|
| 39 | + $this->last_update = time(); |
|
| 40 | + |
|
| 41 | + return $this; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function get_array() { |
|
| 45 | + return array( |
|
| 46 | + 'started' => $this->started, |
|
| 47 | + 'index' => $this->index, |
|
| 48 | + 'count' => $this->count, |
|
| 49 | + 'last_update' => $this->last_update, |
|
| 50 | + 'state' => $this->state |
|
| 51 | + ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public static function unknown() { |
|
| 55 | + |
|
| 56 | + return new self( time(), 0, 0, time(), 'unknown' ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @param $last_update |
| 20 | 20 | * @param $state |
| 21 | 21 | */ |
| 22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
| 22 | + public function __construct($started, $index, $count, $last_update, $state) { |
|
| 23 | 23 | $this->started = $started; |
| 24 | 24 | $this->index = $index; |
| 25 | 25 | $this->count = (int) $count; |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | $this->state = $state; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function increment_index( $count ) { |
|
| 31 | - $this->index += $count; |
|
| 30 | + public function increment_index($count) { |
|
| 31 | + $this->index += $count; |
|
| 32 | 32 | $this->last_update = time(); |
| 33 | 33 | |
| 34 | 34 | return $this; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public function set_state( $value ) { |
|
| 37 | + public function set_state($value) { |
|
| 38 | 38 | $this->state = $value; |
| 39 | 39 | $this->last_update = time(); |
| 40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | public static function unknown() { |
| 45 | 45 | |
| 46 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
| 46 | + return new self(time(), 0, 0, time(), 'unknown'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | \ No newline at end of file |
@@ -6,135 +6,135 @@ |
||
| 6 | 6 | class Analysis_Background_Service { |
| 7 | 7 | |
| 8 | 8 | |
| 9 | - const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache'; |
|
| 10 | - const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count'; |
|
| 11 | - const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache'; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * @var Analysis_Service |
|
| 15 | - */ |
|
| 16 | - private $analysis_service; |
|
| 17 | - /** |
|
| 18 | - * @var Analysis_Background_Process |
|
| 19 | - */ |
|
| 20 | - private $analysis_background_process; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var \Wordlift_Log_Service |
|
| 24 | - */ |
|
| 25 | - private $log; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - public function __construct( $analysis_service ) { |
|
| 29 | - |
|
| 30 | - $this->analysis_service = $analysis_service; |
|
| 31 | - |
|
| 32 | - $this->analysis_background_process = new Analysis_Background_Process( $this ); |
|
| 33 | - |
|
| 34 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function start() { |
|
| 38 | - $this->analysis_background_process->start(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function cancel() { |
|
| 42 | - $this->analysis_background_process->cancel(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function stop() { |
|
| 46 | - $this->analysis_background_process->cancel(); |
|
| 47 | - $this->analysis_background_process->request_cancel(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * A list of term ids. |
|
| 52 | - * @return int|\WP_Error|\WP_Term[] |
|
| 53 | - */ |
|
| 54 | - public function next() { |
|
| 55 | - |
|
| 56 | - $state = $this->info(); |
|
| 57 | - |
|
| 58 | - return get_terms( array( |
|
| 59 | - 'fields' => 'ids', |
|
| 60 | - 'taxonomy' => 'post_tag', |
|
| 61 | - 'hide_empty' => false, |
|
| 62 | - 'number' => $this->get_batch_size(), |
|
| 63 | - 'offset' => $state->index, |
|
| 64 | - 'meta_query' => array( |
|
| 65 | - array( |
|
| 66 | - 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 67 | - 'compare' => 'NOT EXISTS' |
|
| 68 | - ) |
|
| 69 | - ), |
|
| 70 | - ) ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function count() { |
|
| 74 | - |
|
| 75 | - $count = count( get_terms( array( |
|
| 76 | - 'fields' => 'ids', |
|
| 77 | - 'taxonomy' => 'post_tag', |
|
| 78 | - 'hide_empty' => false, |
|
| 79 | - // return all terms, we cant pass -1 here. |
|
| 80 | - 'number' => 0, |
|
| 81 | - 'meta_query' => array( |
|
| 82 | - array( |
|
| 83 | - 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 84 | - 'compare' => 'NOT EXISTS' |
|
| 85 | - ) |
|
| 86 | - ), |
|
| 87 | - ) ) ); |
|
| 88 | - |
|
| 89 | - $this->log->debug( "Count returned as $count" ); |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - return $count; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function get_batch_size() { |
|
| 96 | - return 10; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function info() { |
|
| 100 | - return Analysis_Background_Process::get_state(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param $term_ids |
|
| 105 | - * |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public function perform_analysis_for_terms( $term_ids ) { |
|
| 109 | - |
|
| 110 | - foreach ( $term_ids as $term_id ) { |
|
| 111 | - |
|
| 112 | - $tag = get_term( $term_id ); |
|
| 113 | - |
|
| 114 | - // This adds the entities to ttl cache |
|
| 115 | - $result = $this->analysis_service->get_entities( $tag ); |
|
| 9 | + const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache'; |
|
| 10 | + const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count'; |
|
| 11 | + const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache'; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * @var Analysis_Service |
|
| 15 | + */ |
|
| 16 | + private $analysis_service; |
|
| 17 | + /** |
|
| 18 | + * @var Analysis_Background_Process |
|
| 19 | + */ |
|
| 20 | + private $analysis_background_process; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var \Wordlift_Log_Service |
|
| 24 | + */ |
|
| 25 | + private $log; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + public function __construct( $analysis_service ) { |
|
| 29 | + |
|
| 30 | + $this->analysis_service = $analysis_service; |
|
| 31 | + |
|
| 32 | + $this->analysis_background_process = new Analysis_Background_Process( $this ); |
|
| 33 | + |
|
| 34 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function start() { |
|
| 38 | + $this->analysis_background_process->start(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function cancel() { |
|
| 42 | + $this->analysis_background_process->cancel(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function stop() { |
|
| 46 | + $this->analysis_background_process->cancel(); |
|
| 47 | + $this->analysis_background_process->request_cancel(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * A list of term ids. |
|
| 52 | + * @return int|\WP_Error|\WP_Term[] |
|
| 53 | + */ |
|
| 54 | + public function next() { |
|
| 55 | + |
|
| 56 | + $state = $this->info(); |
|
| 57 | + |
|
| 58 | + return get_terms( array( |
|
| 59 | + 'fields' => 'ids', |
|
| 60 | + 'taxonomy' => 'post_tag', |
|
| 61 | + 'hide_empty' => false, |
|
| 62 | + 'number' => $this->get_batch_size(), |
|
| 63 | + 'offset' => $state->index, |
|
| 64 | + 'meta_query' => array( |
|
| 65 | + array( |
|
| 66 | + 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 67 | + 'compare' => 'NOT EXISTS' |
|
| 68 | + ) |
|
| 69 | + ), |
|
| 70 | + ) ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function count() { |
|
| 74 | + |
|
| 75 | + $count = count( get_terms( array( |
|
| 76 | + 'fields' => 'ids', |
|
| 77 | + 'taxonomy' => 'post_tag', |
|
| 78 | + 'hide_empty' => false, |
|
| 79 | + // return all terms, we cant pass -1 here. |
|
| 80 | + 'number' => 0, |
|
| 81 | + 'meta_query' => array( |
|
| 82 | + array( |
|
| 83 | + 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 84 | + 'compare' => 'NOT EXISTS' |
|
| 85 | + ) |
|
| 86 | + ), |
|
| 87 | + ) ) ); |
|
| 88 | + |
|
| 89 | + $this->log->debug( "Count returned as $count" ); |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + return $count; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function get_batch_size() { |
|
| 96 | + return 10; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function info() { |
|
| 100 | + return Analysis_Background_Process::get_state(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param $term_ids |
|
| 105 | + * |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public function perform_analysis_for_terms( $term_ids ) { |
|
| 109 | + |
|
| 110 | + foreach ( $term_ids as $term_id ) { |
|
| 111 | + |
|
| 112 | + $tag = get_term( $term_id ); |
|
| 113 | + |
|
| 114 | + // This adds the entities to ttl cache |
|
| 115 | + $result = $this->analysis_service->get_entities( $tag ); |
|
| 116 | 116 | |
| 117 | - $this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" ); |
|
| 117 | + $this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" ); |
|
| 118 | 118 | |
| 119 | - if ( $result !== false ) { |
|
| 120 | - // then set the analysis complete flag. |
|
| 121 | - update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 ); |
|
| 122 | - if ( count( $result ) > 0 ) { |
|
| 123 | - update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 ); |
|
| 124 | - } |
|
| 125 | - } |
|
| 119 | + if ( $result !== false ) { |
|
| 120 | + // then set the analysis complete flag. |
|
| 121 | + update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 ); |
|
| 122 | + if ( count( $result ) > 0 ) { |
|
| 123 | + update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 ); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * This action fires when the analysis is complete for the current batch |
|
| 131 | - * @since 3.30.0 |
|
| 132 | - */ |
|
| 133 | - do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' ); |
|
| 134 | - |
|
| 135 | - return true; |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - } |
|
| 129 | + /** |
|
| 130 | + * This action fires when the analysis is complete for the current batch |
|
| 131 | + * @since 3.30.0 |
|
| 132 | + */ |
|
| 133 | + do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' ); |
|
| 134 | + |
|
| 135 | + return true; |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | private $log; |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function __construct( $analysis_service ) { |
|
| 28 | + public function __construct($analysis_service) { |
|
| 29 | 29 | |
| 30 | 30 | $this->analysis_service = $analysis_service; |
| 31 | 31 | |
| 32 | - $this->analysis_background_process = new Analysis_Background_Process( $this ); |
|
| 32 | + $this->analysis_background_process = new Analysis_Background_Process($this); |
|
| 33 | 33 | |
| 34 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 34 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function start() { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $state = $this->info(); |
| 57 | 57 | |
| 58 | - return get_terms( array( |
|
| 58 | + return get_terms(array( |
|
| 59 | 59 | 'fields' => 'ids', |
| 60 | 60 | 'taxonomy' => 'post_tag', |
| 61 | 61 | 'hide_empty' => false, |
@@ -67,12 +67,12 @@ discard block |
||
| 67 | 67 | 'compare' => 'NOT EXISTS' |
| 68 | 68 | ) |
| 69 | 69 | ), |
| 70 | - ) ); |
|
| 70 | + )); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function count() { |
| 74 | 74 | |
| 75 | - $count = count( get_terms( array( |
|
| 75 | + $count = count(get_terms(array( |
|
| 76 | 76 | 'fields' => 'ids', |
| 77 | 77 | 'taxonomy' => 'post_tag', |
| 78 | 78 | 'hide_empty' => false, |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | 'compare' => 'NOT EXISTS' |
| 85 | 85 | ) |
| 86 | 86 | ), |
| 87 | - ) ) ); |
|
| 87 | + ))); |
|
| 88 | 88 | |
| 89 | - $this->log->debug( "Count returned as $count" ); |
|
| 89 | + $this->log->debug("Count returned as $count"); |
|
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | return $count; |
@@ -105,22 +105,22 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return bool |
| 107 | 107 | */ |
| 108 | - public function perform_analysis_for_terms( $term_ids ) { |
|
| 108 | + public function perform_analysis_for_terms($term_ids) { |
|
| 109 | 109 | |
| 110 | - foreach ( $term_ids as $term_id ) { |
|
| 110 | + foreach ($term_ids as $term_id) { |
|
| 111 | 111 | |
| 112 | - $tag = get_term( $term_id ); |
|
| 112 | + $tag = get_term($term_id); |
|
| 113 | 113 | |
| 114 | 114 | // This adds the entities to ttl cache |
| 115 | - $result = $this->analysis_service->get_entities( $tag ); |
|
| 115 | + $result = $this->analysis_service->get_entities($tag); |
|
| 116 | 116 | |
| 117 | - $this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" ); |
|
| 117 | + $this->log->debug("Received result ".var_export($result)." for ${term_id}"); |
|
| 118 | 118 | |
| 119 | - if ( $result !== false ) { |
|
| 119 | + if ($result !== false) { |
|
| 120 | 120 | // then set the analysis complete flag. |
| 121 | - update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 ); |
|
| 122 | - if ( count( $result ) > 0 ) { |
|
| 123 | - update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 ); |
|
| 121 | + update_term_meta($term_id, self::ANALYSIS_DONE_FLAG, 1); |
|
| 122 | + if (count($result) > 0) { |
|
| 123 | + update_term_meta($term_id, self::ENTITIES_PRESENT_FOR_TERM, 1); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * This action fires when the analysis is complete for the current batch |
| 131 | 131 | * @since 3.30.0 |
| 132 | 132 | */ |
| 133 | - do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' ); |
|
| 133 | + do_action('wordlift_vocabulary_analysis_complete_for_terms_batch'); |
|
| 134 | 134 | |
| 135 | 135 | return true; |
| 136 | 136 | |
@@ -9,35 +9,35 @@ discard block |
||
| 9 | 9 | * @author Naveen Muthusamy <[email protected]> |
| 10 | 10 | */ |
| 11 | 11 | class Term_Matches_Widget { |
| 12 | - /** |
|
| 13 | - * @var Term_Count |
|
| 14 | - */ |
|
| 15 | - private $term_count; |
|
| 12 | + /** |
|
| 13 | + * @var Term_Count |
|
| 14 | + */ |
|
| 15 | + private $term_count; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Term_Matches_Widget constructor. |
|
| 19 | - * |
|
| 20 | - * @param $term_count Term_Count |
|
| 21 | - */ |
|
| 22 | - public function __construct( $term_count ) { |
|
| 23 | - $this->term_count = $term_count; |
|
| 24 | - } |
|
| 17 | + /** |
|
| 18 | + * Term_Matches_Widget constructor. |
|
| 19 | + * |
|
| 20 | + * @param $term_count Term_Count |
|
| 21 | + */ |
|
| 22 | + public function __construct( $term_count ) { |
|
| 23 | + $this->term_count = $term_count; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function connect_hook() { |
|
| 27 | - add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) ); |
|
| 28 | - } |
|
| 26 | + public function connect_hook() { |
|
| 27 | + add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) ); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function render_widget() { |
|
| 31 | - $term_count = $this->term_count->get_term_count(); |
|
| 32 | - if ( $term_count <= 0 ) { |
|
| 33 | - return; |
|
| 34 | - } |
|
| 30 | + public function render_widget() { |
|
| 31 | + $term_count = $this->term_count->get_term_count(); |
|
| 32 | + if ( $term_count <= 0 ) { |
|
| 33 | + return; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $match_terms_url = menu_page_url('wl-vocabulary-match-terms', false); |
|
| 37 | - $term_count_link = "<a href='$match_terms_url'>" . $term_count . " term(s)</a>"; |
|
| 38 | - $match_terms = __('Match terms', 'wordlift'); |
|
| 39 | - $additional_text = __(' waiting to be matched with entities.', 'wordlift'); |
|
| 40 | - echo <<<EOF |
|
| 36 | + $match_terms_url = menu_page_url('wl-vocabulary-match-terms', false); |
|
| 37 | + $term_count_link = "<a href='$match_terms_url'>" . $term_count . " term(s)</a>"; |
|
| 38 | + $match_terms = __('Match terms', 'wordlift'); |
|
| 39 | + $additional_text = __(' waiting to be matched with entities.', 'wordlift'); |
|
| 40 | + echo <<<EOF |
|
| 41 | 41 | <div id="wl-match-terms" class="wl-dashboard__block wl-dashboard__block--match-terms"> |
| 42 | 42 | <header> |
| 43 | 43 | <h3>$match_terms</h3> |
@@ -47,6 +47,6 @@ discard block |
||
| 47 | 47 | </p> |
| 48 | 48 | </div> |
| 49 | 49 | EOF; |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -19,22 +19,22 @@ |
||
| 19 | 19 | * |
| 20 | 20 | * @param $term_count Term_Count |
| 21 | 21 | */ |
| 22 | - public function __construct( $term_count ) { |
|
| 22 | + public function __construct($term_count) { |
|
| 23 | 23 | $this->term_count = $term_count; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function connect_hook() { |
| 27 | - add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) ); |
|
| 27 | + add_action('wl_admin_dashboard_widgets', array($this, 'render_widget')); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function render_widget() { |
| 31 | - $term_count = $this->term_count->get_term_count(); |
|
| 32 | - if ( $term_count <= 0 ) { |
|
| 31 | + $term_count = $this->term_count->get_term_count(); |
|
| 32 | + if ($term_count <= 0) { |
|
| 33 | 33 | return; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $match_terms_url = menu_page_url('wl-vocabulary-match-terms', false); |
| 37 | - $term_count_link = "<a href='$match_terms_url'>" . $term_count . " term(s)</a>"; |
|
| 37 | + $term_count_link = "<a href='$match_terms_url'>".$term_count." term(s)</a>"; |
|
| 38 | 38 | $match_terms = __('Match terms', 'wordlift'); |
| 39 | 39 | $additional_text = __(' waiting to be matched with entities.', 'wordlift'); |
| 40 | 40 | echo <<<EOF |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Tag_Created_Hook { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @var $analysis_background_service Analysis_Background_Service |
|
| 11 | - */ |
|
| 12 | - private $analysis_background_service; |
|
| 9 | + /** |
|
| 10 | + * @var $analysis_background_service Analysis_Background_Service |
|
| 11 | + */ |
|
| 12 | + private $analysis_background_service; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Tag_Created_Hook constructor. |
|
| 16 | - * |
|
| 17 | - * @param $analysis_background_service Analysis_Background_Service |
|
| 18 | - */ |
|
| 19 | - public function __construct( $analysis_background_service ) { |
|
| 20 | - $this->analysis_background_service = $analysis_background_service; |
|
| 21 | - add_action( 'created_post_tag', array( $this, 'created_post_tag' ) ); |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * Tag_Created_Hook constructor. |
|
| 16 | + * |
|
| 17 | + * @param $analysis_background_service Analysis_Background_Service |
|
| 18 | + */ |
|
| 19 | + public function __construct( $analysis_background_service ) { |
|
| 20 | + $this->analysis_background_service = $analysis_background_service; |
|
| 21 | + add_action( 'created_post_tag', array( $this, 'created_post_tag' ) ); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function created_post_tag() { |
|
| 25 | - $this->analysis_background_service->start(); |
|
| 26 | - } |
|
| 24 | + public function created_post_tag() { |
|
| 25 | + $this->analysis_background_service->start(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | } |
| 29 | 29 | \ No newline at end of file |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @param $analysis_background_service Analysis_Background_Service |
| 18 | 18 | */ |
| 19 | - public function __construct( $analysis_background_service ) { |
|
| 19 | + public function __construct($analysis_background_service) { |
|
| 20 | 20 | $this->analysis_background_service = $analysis_background_service; |
| 21 | - add_action( 'created_post_tag', array( $this, 'created_post_tag' ) ); |
|
| 21 | + add_action('created_post_tag', array($this, 'created_post_tag')); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function created_post_tag() { |
@@ -11,116 +11,116 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Analysis_Service { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var Default_Api_Service |
|
| 16 | - */ |
|
| 17 | - private $analysis_service; |
|
| 18 | - /** |
|
| 19 | - * @var Options_Cache |
|
| 20 | - */ |
|
| 21 | - private $cache_service; |
|
| 14 | + /** |
|
| 15 | + * @var Default_Api_Service |
|
| 16 | + */ |
|
| 17 | + private $analysis_service; |
|
| 18 | + /** |
|
| 19 | + * @var Options_Cache |
|
| 20 | + */ |
|
| 21 | + private $cache_service; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Tag_Rest_Endpoint constructor. |
|
| 26 | - * |
|
| 27 | - * @param Default_Api_Service $analysis_service |
|
| 28 | - * @param Options_Cache $cache_service |
|
| 29 | - */ |
|
| 30 | - public function __construct( $analysis_service, $cache_service ) { |
|
| 24 | + /** |
|
| 25 | + * Tag_Rest_Endpoint constructor. |
|
| 26 | + * |
|
| 27 | + * @param Default_Api_Service $analysis_service |
|
| 28 | + * @param Options_Cache $cache_service |
|
| 29 | + */ |
|
| 30 | + public function __construct( $analysis_service, $cache_service ) { |
|
| 31 | 31 | |
| 32 | - $this->analysis_service = $analysis_service; |
|
| 32 | + $this->analysis_service = $analysis_service; |
|
| 33 | 33 | |
| 34 | - $this->cache_service = $cache_service; |
|
| 34 | + $this->cache_service = $cache_service; |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Check if entities are in cache, if not return the results from |
|
| 41 | - * cache service. |
|
| 42 | - * |
|
| 43 | - * @param $tag \WP_Term |
|
| 44 | - */ |
|
| 45 | - public function get_entities( $tag ) { |
|
| 39 | + /** |
|
| 40 | + * Check if entities are in cache, if not return the results from |
|
| 41 | + * cache service. |
|
| 42 | + * |
|
| 43 | + * @param $tag \WP_Term |
|
| 44 | + */ |
|
| 45 | + public function get_entities( $tag ) { |
|
| 46 | 46 | |
| 47 | - $cache_key = $tag->term_id; |
|
| 48 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
| 49 | - if ( $cache_result !== false ) { |
|
| 50 | - return $cache_result; |
|
| 51 | - } |
|
| 47 | + $cache_key = $tag->term_id; |
|
| 48 | + $cache_result = $this->cache_service->get( $cache_key ); |
|
| 49 | + if ( $cache_result !== false ) { |
|
| 50 | + return $cache_result; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // send the request. |
|
| 54 | - $response = $this->analysis_service->request( |
|
| 55 | - 'POST', |
|
| 56 | - "/analysis/single", |
|
| 57 | - array( 'Content-Type' => 'application/json' ), |
|
| 58 | - wp_json_encode( array( |
|
| 59 | - "content" => $tag->name, |
|
| 60 | - "contentType" => "text/plain", |
|
| 61 | - "version" => "1.0.0", |
|
| 62 | - "contentLanguage" => "en", |
|
| 63 | - "scope" => "network", |
|
| 64 | - ) ) |
|
| 65 | - ); |
|
| 53 | + // send the request. |
|
| 54 | + $response = $this->analysis_service->request( |
|
| 55 | + 'POST', |
|
| 56 | + "/analysis/single", |
|
| 57 | + array( 'Content-Type' => 'application/json' ), |
|
| 58 | + wp_json_encode( array( |
|
| 59 | + "content" => $tag->name, |
|
| 60 | + "contentType" => "text/plain", |
|
| 61 | + "version" => "1.0.0", |
|
| 62 | + "contentLanguage" => "en", |
|
| 63 | + "scope" => "network", |
|
| 64 | + ) ) |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - if ( ! $response->is_success() ) { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 68 | + if ( ! $response->is_success() ) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $response = json_decode( $response->get_body(), true ); |
|
| 72 | + $response = json_decode( $response->get_body(), true ); |
|
| 73 | 73 | |
| 74 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
| 75 | - return false; |
|
| 76 | - } |
|
| 74 | + if ( ! array_key_exists( 'entities', $response ) ) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
| 79 | + $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
| 80 | 80 | |
| 81 | - $this->cache_service->put( $cache_key, $entities ); |
|
| 81 | + $this->cache_service->put( $cache_key, $entities ); |
|
| 82 | 82 | |
| 83 | - return $entities; |
|
| 83 | + return $entities; |
|
| 84 | 84 | |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - private function get_meta( $entity_url ) { |
|
| 88 | + private function get_meta( $entity_url ) { |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
| 91 | + $cache_results = $this->cache_service->get( $entity_url ); |
|
| 92 | 92 | |
| 93 | - if ( $cache_results !== false ) { |
|
| 94 | - return $cache_results; |
|
| 95 | - } |
|
| 93 | + if ( $cache_results !== false ) { |
|
| 94 | + return $cache_results; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $response = wp_remote_get( "https://app.wordlift.io/knowledge-cafemedia-com-food/wp-json/wordlift/v1/jsonld/meta/entity_url?meta_value=" . urlencode($entity_url) ); |
|
| 97 | + $response = wp_remote_get( "https://app.wordlift.io/knowledge-cafemedia-com-food/wp-json/wordlift/v1/jsonld/meta/entity_url?meta_value=" . urlencode($entity_url) ); |
|
| 98 | 98 | |
| 99 | - if ( ! is_wp_error( $response ) ) { |
|
| 100 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 101 | - $this->cache_service->put( $entity_url, $meta ); |
|
| 102 | - return $meta; |
|
| 103 | - } |
|
| 99 | + if ( ! is_wp_error( $response ) ) { |
|
| 100 | + $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 101 | + $this->cache_service->put( $entity_url, $meta ); |
|
| 102 | + return $meta; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return array(); |
|
| 105 | + return array(); |
|
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - private function get_meta_for_entities( $entities ) { |
|
| 109 | + private function get_meta_for_entities( $entities ) { |
|
| 110 | 110 | |
| 111 | - $filtered_entities = array(); |
|
| 112 | - foreach ( $entities as $entity ) { |
|
| 113 | - $entity['meta'] = array(); |
|
| 114 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
| 115 | - if ( $meta && count( $meta ) > 0 ) { |
|
| 116 | - $entity['meta'] = $meta[0]; |
|
| 117 | - } |
|
| 118 | - $filtered_entities[] = $entity; |
|
| 119 | - } |
|
| 111 | + $filtered_entities = array(); |
|
| 112 | + foreach ( $entities as $entity ) { |
|
| 113 | + $entity['meta'] = array(); |
|
| 114 | + $meta = $this->get_meta( $entity['entityId'] ); |
|
| 115 | + if ( $meta && count( $meta ) > 0 ) { |
|
| 116 | + $entity['meta'] = $meta[0]; |
|
| 117 | + } |
|
| 118 | + $filtered_entities[] = $entity; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - return $filtered_entities; |
|
| 121 | + return $filtered_entities; |
|
| 122 | 122 | |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @param Default_Api_Service $analysis_service |
| 28 | 28 | * @param Options_Cache $cache_service |
| 29 | 29 | */ |
| 30 | - public function __construct( $analysis_service, $cache_service ) { |
|
| 30 | + public function __construct($analysis_service, $cache_service) { |
|
| 31 | 31 | |
| 32 | 32 | $this->analysis_service = $analysis_service; |
| 33 | 33 | |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @param $tag \WP_Term |
| 44 | 44 | */ |
| 45 | - public function get_entities( $tag ) { |
|
| 45 | + public function get_entities($tag) { |
|
| 46 | 46 | |
| 47 | 47 | $cache_key = $tag->term_id; |
| 48 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
| 49 | - if ( $cache_result !== false ) { |
|
| 48 | + $cache_result = $this->cache_service->get($cache_key); |
|
| 49 | + if ($cache_result !== false) { |
|
| 50 | 50 | return $cache_result; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -54,51 +54,51 @@ discard block |
||
| 54 | 54 | $response = $this->analysis_service->request( |
| 55 | 55 | 'POST', |
| 56 | 56 | "/analysis/single", |
| 57 | - array( 'Content-Type' => 'application/json' ), |
|
| 58 | - wp_json_encode( array( |
|
| 57 | + array('Content-Type' => 'application/json'), |
|
| 58 | + wp_json_encode(array( |
|
| 59 | 59 | "content" => $tag->name, |
| 60 | 60 | "contentType" => "text/plain", |
| 61 | 61 | "version" => "1.0.0", |
| 62 | 62 | "contentLanguage" => "en", |
| 63 | 63 | "scope" => "network", |
| 64 | - ) ) |
|
| 64 | + )) |
|
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - if ( ! $response->is_success() ) { |
|
| 68 | + if ( ! $response->is_success()) { |
|
| 69 | 69 | return false; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $response = json_decode( $response->get_body(), true ); |
|
| 72 | + $response = json_decode($response->get_body(), true); |
|
| 73 | 73 | |
| 74 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
| 74 | + if ( ! array_key_exists('entities', $response)) { |
|
| 75 | 75 | return false; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
| 79 | + $entities = $this->get_meta_for_entities($response['entities']); |
|
| 80 | 80 | |
| 81 | - $this->cache_service->put( $cache_key, $entities ); |
|
| 81 | + $this->cache_service->put($cache_key, $entities); |
|
| 82 | 82 | |
| 83 | 83 | return $entities; |
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - private function get_meta( $entity_url ) { |
|
| 88 | + private function get_meta($entity_url) { |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
| 91 | + $cache_results = $this->cache_service->get($entity_url); |
|
| 92 | 92 | |
| 93 | - if ( $cache_results !== false ) { |
|
| 93 | + if ($cache_results !== false) { |
|
| 94 | 94 | return $cache_results; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $response = wp_remote_get( "https://app.wordlift.io/knowledge-cafemedia-com-food/wp-json/wordlift/v1/jsonld/meta/entity_url?meta_value=" . urlencode($entity_url) ); |
|
| 97 | + $response = wp_remote_get("https://app.wordlift.io/knowledge-cafemedia-com-food/wp-json/wordlift/v1/jsonld/meta/entity_url?meta_value=".urlencode($entity_url)); |
|
| 98 | 98 | |
| 99 | - if ( ! is_wp_error( $response ) ) { |
|
| 100 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 101 | - $this->cache_service->put( $entity_url, $meta ); |
|
| 99 | + if ( ! is_wp_error($response)) { |
|
| 100 | + $meta = json_decode(wp_remote_retrieve_body($response), true); |
|
| 101 | + $this->cache_service->put($entity_url, $meta); |
|
| 102 | 102 | return $meta; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - private function get_meta_for_entities( $entities ) { |
|
| 109 | + private function get_meta_for_entities($entities) { |
|
| 110 | 110 | |
| 111 | 111 | $filtered_entities = array(); |
| 112 | - foreach ( $entities as $entity ) { |
|
| 112 | + foreach ($entities as $entity) { |
|
| 113 | 113 | $entity['meta'] = array(); |
| 114 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
| 115 | - if ( $meta && count( $meta ) > 0 ) { |
|
| 114 | + $meta = $this->get_meta($entity['entityId']); |
|
| 115 | + if ($meta && count($meta) > 0) { |
|
| 116 | 116 | $entity['meta'] = $meta[0]; |
| 117 | 117 | } |
| 118 | 118 | $filtered_entities[] = $entity; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | white-space: nowrap; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - <?php $blu_dot_url = plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'images/blu-dot.gif'; ?> |
|
| 122 | + <?php $blu_dot_url = plugin_dir_url(dirname(dirname(__FILE__))).'images/blu-dot.gif'; ?> |
|
| 123 | 123 | #wl-dashboard-v2 .wl-dashboard__block--top-entities .wl-dashboard__block__body > div:nth-child(even) { |
| 124 | 124 | flex: calc(100% - 120px); |
| 125 | 125 | background-color: #ebf6ff; |
@@ -223,65 +223,65 @@ discard block |
||
| 223 | 223 | <div class="wl-dashboard__block wl-dashboard__block--search-rankings"> |
| 224 | 224 | <header> |
| 225 | 225 | <span class="dashicons dashicons-editor-help"></span> |
| 226 | - <h3><?php echo __( 'Search rankings', 'wordlift' ); ?></h3> |
|
| 226 | + <h3><?php echo __('Search rankings', 'wordlift'); ?></h3> |
|
| 227 | 227 | <div class="pull-right"> |
| 228 | - <?php echo esc_html( __( Wordlift_Countries::get_country_name( $country_code ) ) ); ?> |
|
| 229 | - <img width="16" height="16" src="<?php echo Wordlift_Countries::get_flag_url( $country_code ); ?>"> |
|
| 228 | + <?php echo esc_html(__(Wordlift_Countries::get_country_name($country_code))); ?> |
|
| 229 | + <img width="16" height="16" src="<?php echo Wordlift_Countries::get_flag_url($country_code); ?>"> |
|
| 230 | 230 | <img width="16" height="16" |
| 231 | - src="<?php echo plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'images/woorank-16x16.png'; ?>"> |
|
| 231 | + src="<?php echo plugin_dir_url(dirname(dirname(__FILE__))).'images/woorank-16x16.png'; ?>"> |
|
| 232 | 232 | </div> |
| 233 | 233 | </header> |
| 234 | 234 | <?php |
| 235 | - if ( in_array( $configuration_service->get_package_type(), array( 'editorial', 'business' ) ) ) { ?> |
|
| 235 | + if (in_array($configuration_service->get_package_type(), array('editorial', 'business'))) { ?> |
|
| 236 | 236 | <div class="wl-dashboard__block__body"> |
| 237 | - <div><?php echo esc_html( _x( 'Keywords', 'Dashboard', 'wordlift' ) ); ?>: |
|
| 238 | - <a href="<?php echo admin_url( 'admin.php?page=wl_search_rankings' ); ?>"><?php echo wp_count_terms( Wordlift_Search_Keyword_Taxonomy::TAXONOMY_NAME ); ?></a> |
|
| 237 | + <div><?php echo esc_html(_x('Keywords', 'Dashboard', 'wordlift')); ?>: |
|
| 238 | + <a href="<?php echo admin_url('admin.php?page=wl_search_rankings'); ?>"><?php echo wp_count_terms(Wordlift_Search_Keyword_Taxonomy::TAXONOMY_NAME); ?></a> |
|
| 239 | 239 | </div> |
| 240 | - <div><?php echo esc_html( _x( 'Average position', 'Dashboard', 'wordlift' ) ); ?>: |
|
| 241 | - <a href="<?php echo admin_url( 'admin.php?page=wl_search_rankings' ); ?>"><?php echo $average_position_string; ?></a> |
|
| 240 | + <div><?php echo esc_html(_x('Average position', 'Dashboard', 'wordlift')); ?>: |
|
| 241 | + <a href="<?php echo admin_url('admin.php?page=wl_search_rankings'); ?>"><?php echo $average_position_string; ?></a> |
|
| 242 | 242 | </div> |
| 243 | 243 | </div> |
| 244 | 244 | <?php } else { ?> |
| 245 | 245 | <div class="wl-dashboard__block__body wl-dashboard__block__body--locked"> |
| 246 | - <?php echo esc_html( _x( 'Search Rankings are only available to Business and Editorial users', 'Dashboard', 'wordlift' ) ); ?> |
|
| 246 | + <?php echo esc_html(_x('Search Rankings are only available to Business and Editorial users', 'Dashboard', 'wordlift')); ?> |
|
| 247 | 247 | <a href="https://wordlift.io/upgrade" target="_blank" |
| 248 | - class="button button-primary"><?php echo esc_html( __( 'Upgrade', 'wordlift' ) ); ?></a> |
|
| 248 | + class="button button-primary"><?php echo esc_html(__('Upgrade', 'wordlift')); ?></a> |
|
| 249 | 249 | </div> |
| 250 | 250 | <?php } ?> |
| 251 | 251 | </div> |
| 252 | 252 | |
| 253 | 253 | <?php |
| 254 | 254 | $top_entities = $this->get_top_entities(); |
| 255 | -if ( ! empty( $top_entities ) ) { |
|
| 255 | +if ( ! empty($top_entities)) { |
|
| 256 | 256 | ?> |
| 257 | 257 | <div class="wl-dashboard__block wl-dashboard__block--top-entities"> |
| 258 | 258 | <header> |
| 259 | 259 | <span class="dashicons dashicons-editor-help"></span> |
| 260 | - <h3><?php echo __( 'Top entities', 'wordlift' ); ?></h3> |
|
| 261 | - <span class="wl-dashboard__legend wl-dashboard__legend--entities"><?php echo esc_html( _x( 'Links with entities', 'Dashboard', 'wordlift' ) ); ?></span> |
|
| 262 | - <span class="wl-dashboard__legend wl-dashboard__legend--posts"><?php echo esc_html( _x( 'Post with entities', 'Dashboard', 'wordlift' ) ); ?></span> |
|
| 260 | + <h3><?php echo __('Top entities', 'wordlift'); ?></h3> |
|
| 261 | + <span class="wl-dashboard__legend wl-dashboard__legend--entities"><?php echo esc_html(_x('Links with entities', 'Dashboard', 'wordlift')); ?></span> |
|
| 262 | + <span class="wl-dashboard__legend wl-dashboard__legend--posts"><?php echo esc_html(_x('Post with entities', 'Dashboard', 'wordlift')); ?></span> |
|
| 263 | 263 | </header> |
| 264 | 264 | <div class="wl-dashboard__block__body"> |
| 265 | 265 | <?php |
| 266 | 266 | $max = $top_entities[0]->total; |
| 267 | - $unit = intval( '1' . str_repeat( '0', strlen( $max ) - 1 ) ); |
|
| 268 | - $max_value = ceil( (float) $max / $unit ) * $unit; |
|
| 267 | + $unit = intval('1'.str_repeat('0', strlen($max) - 1)); |
|
| 268 | + $max_value = ceil((float) $max / $unit) * $unit; |
|
| 269 | 269 | $chunk_value = $max_value / 4; |
| 270 | 270 | ?> |
| 271 | 271 | <div></div> |
| 272 | 272 | <div class="wl-dashboard__block__body__table-header"> |
| 273 | - <?php for ( $i = 0; $i <= $max_value; $i += $chunk_value ) { ?><span><?php echo $i; ?></span><?php } ?> |
|
| 273 | + <?php for ($i = 0; $i <= $max_value; $i += $chunk_value) { ?><span><?php echo $i; ?></span><?php } ?> |
|
| 274 | 274 | </div> |
| 275 | 275 | <?php |
| 276 | 276 | $i = 0; |
| 277 | - foreach ( $this->get_top_entities() as $post ) { |
|
| 278 | - $permalink = get_permalink( $post->ID ); |
|
| 277 | + foreach ($this->get_top_entities() as $post) { |
|
| 278 | + $permalink = get_permalink($post->ID); |
|
| 279 | 279 | $title = $post->post_title; |
| 280 | 280 | $entities_100 = 100 * $post->entities / $max_value; |
| 281 | 281 | $posts_100 = 100 * $post->posts / $max_value; |
| 282 | 282 | |
| 283 | 283 | ?> |
| 284 | - <div><a href="<?php echo esc_attr( $permalink ); ?>"><?php echo esc_html( $title ); ?></a></div> |
|
| 284 | + <div><a href="<?php echo esc_attr($permalink); ?>"><?php echo esc_html($title); ?></a></div> |
|
| 285 | 285 | <div> |
| 286 | 286 | <div class="wl-dashboard__bar wl-dashboard__bar--posts" style="width: <?php echo $posts_100 ?>%;"> |
| 287 | 287 | </div> |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | </div> |
| 291 | 291 | </div> |
| 292 | 292 | <?php |
| 293 | - if ( 4 === $i ++ ) { |
|
| 293 | + if (4 === $i++) { |
|
| 294 | 294 | ?> |
| 295 | 295 | <input id="wl-dashboard__show-more" type="checkbox"> |
| 296 | 296 | <label for="wl-dashboard__show-more"> |
| 297 | 297 | <span> |
| 298 | - <?php echo esc_html( __( 'Show more', 'Dashboard', 'wordlift' ) ); ?> |
|
| 298 | + <?php echo esc_html(__('Show more', 'Dashboard', 'wordlift')); ?> |
|
| 299 | 299 | </span> |
| 300 | 300 | <span> |
| 301 | - <?php echo esc_html( __( 'Hide', 'Dashboard', 'wordlift' ) ); ?> |
|
| 301 | + <?php echo esc_html(__('Hide', 'Dashboard', 'wordlift')); ?> |
|
| 302 | 302 | </span> |
| 303 | 303 | </label> |
| 304 | 304 | <?php |
@@ -310,40 +310,40 @@ discard block |
||
| 310 | 310 | <?php |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | -$not_enriched_url = admin_url( 'edit.php?post_type=post&wl_enriched=no' ); ?> |
|
| 313 | +$not_enriched_url = admin_url('edit.php?post_type=post&wl_enriched=no'); ?> |
|
| 314 | 314 | <div class="wl-dashboard__block wl-dashboard__block--enriched-posts"> |
| 315 | 315 | <header> |
| 316 | 316 | <span class="dashicons dashicons-editor-help"></span> |
| 317 | - <h3><?php echo __( 'Enriched posts', 'wordlift' ); ?></h3> |
|
| 317 | + <h3><?php echo __('Enriched posts', 'wordlift'); ?></h3> |
|
| 318 | 318 | </header> |
| 319 | 319 | <div class="wl-dashboard__block__body"> |
| 320 | 320 | <a href="<?php echo $not_enriched_url; ?>"><?php echo $this->dashboard_service->count_annotated_posts(); ?></a> |
| 321 | 321 | / <?php echo $this->dashboard_service->count_posts(); ?> |
| 322 | - <a href="<?php echo $not_enriched_url; ?>"><?php echo esc_html( _x( 'Enrich', 'Dashboard', 'wordlift' ) ); ?></a> |
|
| 322 | + <a href="<?php echo $not_enriched_url; ?>"><?php echo esc_html(_x('Enrich', 'Dashboard', 'wordlift')); ?></a> |
|
| 323 | 323 | </div> |
| 324 | 324 | </div> |
| 325 | 325 | |
| 326 | -<?php $vocabulary_url = admin_url( 'edit.php?post_type=entity' ); ?> |
|
| 326 | +<?php $vocabulary_url = admin_url('edit.php?post_type=entity'); ?> |
|
| 327 | 327 | <div class="wl-dashboard__block wl-dashboard__block--created-entities"> |
| 328 | 328 | <header> |
| 329 | 329 | <span class="dashicons dashicons-editor-help"></span> |
| 330 | - <h3><?php echo __( 'Created entities', 'wordlift' ); ?></h3> |
|
| 330 | + <h3><?php echo __('Created entities', 'wordlift'); ?></h3> |
|
| 331 | 331 | </header> |
| 332 | 332 | <div class="wl-dashboard__block__body"> |
| 333 | 333 | <a href="<?php echo $vocabulary_url; ?>"><?php echo $this->entity_service->count(); ?></a> |
| 334 | - <a href="<?php echo $vocabulary_url; ?>"><?php echo esc_html( _x( 'Vocabulary', 'Dashboard', 'wordlift' ) ); ?></a> |
|
| 334 | + <a href="<?php echo $vocabulary_url; ?>"><?php echo esc_html(_x('Vocabulary', 'Dashboard', 'wordlift')); ?></a> |
|
| 335 | 335 | </div> |
| 336 | 336 | </div> |
| 337 | 337 | |
| 338 | -<?php $boost_url = admin_url( 'admin.php?page=wl_search_rankings' ); ?> |
|
| 338 | +<?php $boost_url = admin_url('admin.php?page=wl_search_rankings'); ?> |
|
| 339 | 339 | <div class="wl-dashboard__block wl-dashboard__block--average-entity-rating"> |
| 340 | 340 | <header> |
| 341 | 341 | <span class="dashicons dashicons-editor-help"></span> |
| 342 | - <h3><?php echo __( 'Average entity rating', 'wordlift' ); ?></h3> |
|
| 342 | + <h3><?php echo __('Average entity rating', 'wordlift'); ?></h3> |
|
| 343 | 343 | </header> |
| 344 | 344 | <div class="wl-dashboard__block__body"> |
| 345 | 345 | <a href="<?php echo $boost_url; ?>"><?php echo $this->dashboard_service->average_entities_rating(); ?></a> |
| 346 | - <a href="<?php echo $boost_url; ?>"><?php echo esc_html( _x( 'Boost', 'Dashboard', 'wordlift' ) ); ?></a> |
|
| 346 | + <a href="<?php echo $boost_url; ?>"><?php echo esc_html(_x('Boost', 'Dashboard', 'wordlift')); ?></a> |
|
| 347 | 347 | </div> |
| 348 | 348 | </div> |
| 349 | 349 | <?php |
@@ -359,12 +359,12 @@ discard block |
||
| 359 | 359 | <div style="display: none;"> |
| 360 | 360 | <header> |
| 361 | 361 | <span class="dashicons dashicons-editor-help"></span> |
| 362 | - <h3><?php echo __( 'Graph data', 'wordlift' ); ?></h3> |
|
| 362 | + <h3><?php echo __('Graph data', 'wordlift'); ?></h3> |
|
| 363 | 363 | </header> |
| 364 | 364 | <div> |
| 365 | - <?php echo esc_html( _x( 'Created triples', 'Dashboard', 'wordlift' ) ); ?> |
|
| 366 | - : <?php echo number_format( $this->dashboard_service->count_triples() ); ?><br/> |
|
| 367 | - <?php echo esc_html( _x( 'Ratio on Wikidata', 'Dashboard', 'wordlift' ) ); ?>: |
|
| 368 | - <?php echo number_format( $this->dashboard_service->count_triples() * 100 / 947690143, 4 ); ?>% |
|
| 365 | + <?php echo esc_html(_x('Created triples', 'Dashboard', 'wordlift')); ?> |
|
| 366 | + : <?php echo number_format($this->dashboard_service->count_triples()); ?><br/> |
|
| 367 | + <?php echo esc_html(_x('Ratio on Wikidata', 'Dashboard', 'wordlift')); ?>: |
|
| 368 | + <?php echo number_format($this->dashboard_service->count_triples() * 100 / 947690143, 4); ?>% |
|
| 369 | 369 | </div> |
| 370 | 370 | </div> |
@@ -14,79 +14,79 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Reconcile_Progress_Endpoint { |
| 16 | 16 | |
| 17 | - public function register_routes() { |
|
| 18 | - $that = $this; |
|
| 19 | - add_action( 'rest_api_init', |
|
| 20 | - function () use ( $that ) { |
|
| 21 | - $that->register_progress_route(); |
|
| 22 | - } ); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - public function get_terms_compat( $taxonomy, $args_with_taxonomy_key ) { |
|
| 27 | - global $wp_version; |
|
| 28 | - |
|
| 29 | - if ( version_compare( $wp_version, '4.5', '<' ) ) { |
|
| 30 | - return get_terms( $taxonomy, $args_with_taxonomy_key ); |
|
| 31 | - } else { |
|
| 32 | - return get_terms( $args_with_taxonomy_key ); |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - public function progress() { |
|
| 38 | - |
|
| 39 | - $total_tags = count( $this->get_terms_compat( 'post_tag', array( |
|
| 40 | - 'taxonomy' => 'post_tag', |
|
| 41 | - 'hide_empty' => false, |
|
| 42 | - 'fields' => 'ids', |
|
| 43 | - 'meta_query' => array( |
|
| 44 | - array( |
|
| 45 | - 'key' => Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM, |
|
| 46 | - 'compare' => '=', |
|
| 47 | - 'value' => '1' |
|
| 48 | - ) |
|
| 49 | - ), |
|
| 50 | - ) ) ); |
|
| 51 | - |
|
| 52 | - $completed = count( $this->get_terms_compat( |
|
| 53 | - 'post_tag', |
|
| 54 | - array( |
|
| 55 | - 'taxonomy' => 'post_tag', |
|
| 56 | - 'hide_empty' => false, |
|
| 57 | - 'fields' => 'ids', |
|
| 58 | - 'meta_query' => array( |
|
| 59 | - array( |
|
| 60 | - 'key' => Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, |
|
| 61 | - 'compare' => '=', |
|
| 62 | - 'value' => '1' |
|
| 63 | - ) |
|
| 64 | - ), |
|
| 65 | - ) |
|
| 66 | - ) |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - return array( |
|
| 71 | - 'completed' => $completed, |
|
| 72 | - 'total' => $total_tags |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - private function register_progress_route() { |
|
| 78 | - register_rest_route( |
|
| 79 | - Api_Config::REST_NAMESPACE, |
|
| 80 | - '/reconcile_progress/progress', |
|
| 81 | - array( |
|
| 82 | - 'methods' => \WP_REST_Server::CREATABLE, |
|
| 83 | - 'callback' => array( $this, 'progress' ), |
|
| 84 | - 'permission_callback' => function () { |
|
| 85 | - return current_user_can( 'manage_options' ); |
|
| 86 | - }, |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 17 | + public function register_routes() { |
|
| 18 | + $that = $this; |
|
| 19 | + add_action( 'rest_api_init', |
|
| 20 | + function () use ( $that ) { |
|
| 21 | + $that->register_progress_route(); |
|
| 22 | + } ); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + public function get_terms_compat( $taxonomy, $args_with_taxonomy_key ) { |
|
| 27 | + global $wp_version; |
|
| 28 | + |
|
| 29 | + if ( version_compare( $wp_version, '4.5', '<' ) ) { |
|
| 30 | + return get_terms( $taxonomy, $args_with_taxonomy_key ); |
|
| 31 | + } else { |
|
| 32 | + return get_terms( $args_with_taxonomy_key ); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + public function progress() { |
|
| 38 | + |
|
| 39 | + $total_tags = count( $this->get_terms_compat( 'post_tag', array( |
|
| 40 | + 'taxonomy' => 'post_tag', |
|
| 41 | + 'hide_empty' => false, |
|
| 42 | + 'fields' => 'ids', |
|
| 43 | + 'meta_query' => array( |
|
| 44 | + array( |
|
| 45 | + 'key' => Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM, |
|
| 46 | + 'compare' => '=', |
|
| 47 | + 'value' => '1' |
|
| 48 | + ) |
|
| 49 | + ), |
|
| 50 | + ) ) ); |
|
| 51 | + |
|
| 52 | + $completed = count( $this->get_terms_compat( |
|
| 53 | + 'post_tag', |
|
| 54 | + array( |
|
| 55 | + 'taxonomy' => 'post_tag', |
|
| 56 | + 'hide_empty' => false, |
|
| 57 | + 'fields' => 'ids', |
|
| 58 | + 'meta_query' => array( |
|
| 59 | + array( |
|
| 60 | + 'key' => Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, |
|
| 61 | + 'compare' => '=', |
|
| 62 | + 'value' => '1' |
|
| 63 | + ) |
|
| 64 | + ), |
|
| 65 | + ) |
|
| 66 | + ) |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + return array( |
|
| 71 | + 'completed' => $completed, |
|
| 72 | + 'total' => $total_tags |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + private function register_progress_route() { |
|
| 78 | + register_rest_route( |
|
| 79 | + Api_Config::REST_NAMESPACE, |
|
| 80 | + '/reconcile_progress/progress', |
|
| 81 | + array( |
|
| 82 | + 'methods' => \WP_REST_Server::CREATABLE, |
|
| 83 | + 'callback' => array( $this, 'progress' ), |
|
| 84 | + 'permission_callback' => function () { |
|
| 85 | + return current_user_can( 'manage_options' ); |
|
| 86 | + }, |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | } |
| 93 | 93 | \ No newline at end of file |
@@ -16,27 +16,27 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function register_routes() { |
| 18 | 18 | $that = $this; |
| 19 | - add_action( 'rest_api_init', |
|
| 20 | - function () use ( $that ) { |
|
| 19 | + add_action('rest_api_init', |
|
| 20 | + function() use ($that) { |
|
| 21 | 21 | $that->register_progress_route(); |
| 22 | 22 | } ); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - public function get_terms_compat( $taxonomy, $args_with_taxonomy_key ) { |
|
| 26 | + public function get_terms_compat($taxonomy, $args_with_taxonomy_key) { |
|
| 27 | 27 | global $wp_version; |
| 28 | 28 | |
| 29 | - if ( version_compare( $wp_version, '4.5', '<' ) ) { |
|
| 30 | - return get_terms( $taxonomy, $args_with_taxonomy_key ); |
|
| 29 | + if (version_compare($wp_version, '4.5', '<')) { |
|
| 30 | + return get_terms($taxonomy, $args_with_taxonomy_key); |
|
| 31 | 31 | } else { |
| 32 | - return get_terms( $args_with_taxonomy_key ); |
|
| 32 | + return get_terms($args_with_taxonomy_key); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | public function progress() { |
| 38 | 38 | |
| 39 | - $total_tags = count( $this->get_terms_compat( 'post_tag', array( |
|
| 39 | + $total_tags = count($this->get_terms_compat('post_tag', array( |
|
| 40 | 40 | 'taxonomy' => 'post_tag', |
| 41 | 41 | 'hide_empty' => false, |
| 42 | 42 | 'fields' => 'ids', |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | 'value' => '1' |
| 48 | 48 | ) |
| 49 | 49 | ), |
| 50 | - ) ) ); |
|
| 50 | + ))); |
|
| 51 | 51 | |
| 52 | - $completed = count( $this->get_terms_compat( |
|
| 52 | + $completed = count($this->get_terms_compat( |
|
| 53 | 53 | 'post_tag', |
| 54 | 54 | array( |
| 55 | 55 | 'taxonomy' => 'post_tag', |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | '/reconcile_progress/progress', |
| 81 | 81 | array( |
| 82 | 82 | 'methods' => \WP_REST_Server::CREATABLE, |
| 83 | - 'callback' => array( $this, 'progress' ), |
|
| 84 | - 'permission_callback' => function () { |
|
| 85 | - return current_user_can( 'manage_options' ); |
|
| 83 | + 'callback' => array($this, 'progress'), |
|
| 84 | + 'permission_callback' => function() { |
|
| 85 | + return current_user_can('manage_options'); |
|
| 86 | 86 | }, |
| 87 | 87 | ) |
| 88 | 88 | ); |