@@ -14,65 +14,65 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Term_Page_Hook { |
| 16 | 16 | |
| 17 | - const HANDLE = 'wl-vocabulary-term-page-handle'; |
|
| 17 | + const HANDLE = 'wl-vocabulary-term-page-handle'; |
|
| 18 | 18 | |
| 19 | - const LOCALIZED_KEY = '_wlVocabularyTermPageSettings'; |
|
| 19 | + const LOCALIZED_KEY = '_wlVocabularyTermPageSettings'; |
|
| 20 | 20 | |
| 21 | - private $term_data_factory; |
|
| 21 | + private $term_data_factory; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Term_Page_Hook constructor. |
|
| 25 | - * |
|
| 26 | - * @param $term_data_factory Term_Data_Factory |
|
| 27 | - */ |
|
| 28 | - public function __construct( $term_data_factory ) { |
|
| 29 | - $this->term_data_factory = $term_data_factory; |
|
| 30 | - } |
|
| 23 | + /** |
|
| 24 | + * Term_Page_Hook constructor. |
|
| 25 | + * |
|
| 26 | + * @param $term_data_factory Term_Data_Factory |
|
| 27 | + */ |
|
| 28 | + public function __construct( $term_data_factory ) { |
|
| 29 | + $this->term_data_factory = $term_data_factory; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function connect_hook() { |
|
| 33 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 34 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 35 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'load_scripts' ), 2, PHP_INT_MAX ); |
|
| 36 | - } |
|
| 37 | - } |
|
| 32 | + public function connect_hook() { |
|
| 33 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 34 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 35 | + add_action( "${taxonomy}_edit_form_fields", array( $this, 'load_scripts' ), 2, PHP_INT_MAX ); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param $term \WP_Term |
|
| 41 | - */ |
|
| 42 | - public function load_scripts( $term ) { |
|
| 39 | + /** |
|
| 40 | + * @param $term \WP_Term |
|
| 41 | + */ |
|
| 42 | + public function load_scripts( $term ) { |
|
| 43 | 43 | |
| 44 | - $term_data = $this->term_data_factory->get_term_data( $term ); |
|
| 44 | + $term_data = $this->term_data_factory->get_term_data( $term ); |
|
| 45 | 45 | |
| 46 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
| 47 | - self::HANDLE, |
|
| 48 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/vocabulary-term-page', |
|
| 49 | - array( 'react', 'react-dom', 'wp-polyfill' ), |
|
| 50 | - true |
|
| 51 | - ); |
|
| 46 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
| 47 | + self::HANDLE, |
|
| 48 | + plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/vocabulary-term-page', |
|
| 49 | + array( 'react', 'react-dom', 'wp-polyfill' ), |
|
| 50 | + true |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - wp_enqueue_style( self::HANDLE, plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/vocabulary-term-page.full.css' ); |
|
| 53 | + wp_enqueue_style( self::HANDLE, plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/vocabulary-term-page.full.css' ); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - $term_data_arr = $term_data->get_data(); |
|
| 56 | + $term_data_arr = $term_data->get_data(); |
|
| 57 | 57 | |
| 58 | - $term_data_arr['entities'] = Entity_List_Utils::mark_is_active_for_entities( $term->term_id, $term_data_arr['entities'] ); |
|
| 58 | + $term_data_arr['entities'] = Entity_List_Utils::mark_is_active_for_entities( $term->term_id, $term_data_arr['entities'] ); |
|
| 59 | 59 | |
| 60 | - wp_localize_script( self::HANDLE, self::LOCALIZED_KEY, array( |
|
| 61 | - 'termData' => $term_data_arr, |
|
| 62 | - 'apiConfig' => Api_Config::get_api_config(), |
|
| 63 | - 'restUrl' => get_rest_url( null, Api_Config::REST_NAMESPACE . '/search-entity/' ), |
|
| 64 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 65 | - ) ); |
|
| 60 | + wp_localize_script( self::HANDLE, self::LOCALIZED_KEY, array( |
|
| 61 | + 'termData' => $term_data_arr, |
|
| 62 | + 'apiConfig' => Api_Config::get_api_config(), |
|
| 63 | + 'restUrl' => get_rest_url( null, Api_Config::REST_NAMESPACE . '/search-entity/' ), |
|
| 64 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 65 | + ) ); |
|
| 66 | 66 | |
| 67 | - echo "<tr class=\"form-field\"> |
|
| 67 | + echo "<tr class=\"form-field\"> |
|
| 68 | 68 | <th>Match</th> |
| 69 | 69 | <td style='width: 100%;' id='wl_vocabulary_terms_widget'></td> |
| 70 | 70 | </tr>"; |
| 71 | 71 | |
| 72 | - echo "<tr class=\"form-field\"> |
|
| 72 | + echo "<tr class=\"form-field\"> |
|
| 73 | 73 | <th></th> |
| 74 | 74 | <td id='wl_vocabulary_terms_autocomplete_select'></td></tr>"; |
| 75 | 75 | |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
@@ -25,44 +25,44 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @param $term_data_factory Term_Data_Factory |
| 27 | 27 | */ |
| 28 | - public function __construct( $term_data_factory ) { |
|
| 28 | + public function __construct($term_data_factory) { |
|
| 29 | 29 | $this->term_data_factory = $term_data_factory; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function connect_hook() { |
| 33 | 33 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
| 34 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 35 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'load_scripts' ), 2, PHP_INT_MAX ); |
|
| 34 | + foreach ($taxonomies as $taxonomy) { |
|
| 35 | + add_action("${taxonomy}_edit_form_fields", array($this, 'load_scripts'), 2, PHP_INT_MAX); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * @param $term \WP_Term |
| 41 | 41 | */ |
| 42 | - public function load_scripts( $term ) { |
|
| 42 | + public function load_scripts($term) { |
|
| 43 | 43 | |
| 44 | - $term_data = $this->term_data_factory->get_term_data( $term ); |
|
| 44 | + $term_data = $this->term_data_factory->get_term_data($term); |
|
| 45 | 45 | |
| 46 | 46 | Scripts_Helper::enqueue_based_on_wordpress_version( |
| 47 | 47 | self::HANDLE, |
| 48 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/vocabulary-term-page', |
|
| 49 | - array( 'react', 'react-dom', 'wp-polyfill' ), |
|
| 48 | + plugin_dir_url(dirname(dirname(__DIR__))).'js/dist/vocabulary-term-page', |
|
| 49 | + array('react', 'react-dom', 'wp-polyfill'), |
|
| 50 | 50 | true |
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | - wp_enqueue_style( self::HANDLE, plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/vocabulary-term-page.full.css' ); |
|
| 53 | + wp_enqueue_style(self::HANDLE, plugin_dir_url(dirname(dirname(__DIR__))).'js/dist/vocabulary-term-page.full.css'); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | $term_data_arr = $term_data->get_data(); |
| 57 | 57 | |
| 58 | - $term_data_arr['entities'] = Entity_List_Utils::mark_is_active_for_entities( $term->term_id, $term_data_arr['entities'] ); |
|
| 58 | + $term_data_arr['entities'] = Entity_List_Utils::mark_is_active_for_entities($term->term_id, $term_data_arr['entities']); |
|
| 59 | 59 | |
| 60 | - wp_localize_script( self::HANDLE, self::LOCALIZED_KEY, array( |
|
| 60 | + wp_localize_script(self::HANDLE, self::LOCALIZED_KEY, array( |
|
| 61 | 61 | 'termData' => $term_data_arr, |
| 62 | 62 | 'apiConfig' => Api_Config::get_api_config(), |
| 63 | - 'restUrl' => get_rest_url( null, Api_Config::REST_NAMESPACE . '/search-entity/' ), |
|
| 64 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 65 | - ) ); |
|
| 63 | + 'restUrl' => get_rest_url(null, Api_Config::REST_NAMESPACE.'/search-entity/'), |
|
| 64 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
| 65 | + )); |
|
| 66 | 66 | |
| 67 | 67 | echo "<tr class=\"form-field\"> |
| 68 | 68 | <th>Match</th> |
@@ -9,119 +9,119 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Search_Entity_Rest_Endpoint { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var Analysis_Service |
|
| 14 | - */ |
|
| 15 | - private $analysis_service; |
|
| 16 | - |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var Cache |
|
| 20 | - */ |
|
| 21 | - private $cache_service; |
|
| 22 | - |
|
| 23 | - public function __construct( $api_service, $cache_service ) { |
|
| 24 | - $this->analysis_service = $api_service; |
|
| 25 | - $this->cache_service = $cache_service; |
|
| 26 | - add_action( 'rest_api_init', array( $this, 'register_route_callback' ) ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function register_route_callback() { |
|
| 30 | - register_rest_route( |
|
| 31 | - Api_Config::REST_NAMESPACE, |
|
| 32 | - '/search-entity', |
|
| 33 | - array( |
|
| 34 | - 'methods' => \WP_REST_Server::CREATABLE, |
|
| 35 | - 'callback' => array( $this, 'get_entities_from_api' ), |
|
| 36 | - 'args' => array( |
|
| 37 | - 'entity' => array( |
|
| 38 | - 'validate_callback' => function ( $param ) { |
|
| 39 | - return is_string( $param ); |
|
| 40 | - } |
|
| 41 | - ), |
|
| 42 | - ), |
|
| 43 | - 'permission_callback' => function () { |
|
| 44 | - return current_user_can( 'manage_options' ); |
|
| 45 | - } |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - |
|
| 49 | - register_rest_route( |
|
| 50 | - Api_Config::REST_NAMESPACE, |
|
| 51 | - '/add-entity', |
|
| 52 | - array( |
|
| 53 | - 'methods' => \WP_REST_Server::CREATABLE, |
|
| 54 | - 'callback' => array( $this, 'add_entity_to_matches' ), |
|
| 55 | - 'args' => array( |
|
| 56 | - 'entity_data' => array( |
|
| 57 | - 'validate_callback' => function ( $param ) { |
|
| 58 | - return is_array( $param ); |
|
| 59 | - } |
|
| 60 | - ), |
|
| 61 | - 'term_id' => array( |
|
| 62 | - 'validate_callback' => function ( $param ) { |
|
| 63 | - return is_numeric( $param ); |
|
| 64 | - } |
|
| 65 | - ) |
|
| 66 | - ), |
|
| 67 | - 'permission_callback' => function () { |
|
| 68 | - return current_user_can( 'manage_options' ); |
|
| 69 | - } |
|
| 70 | - ) |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public function add_entity_to_matches( $request ) { |
|
| 75 | - $data = $request->get_params(); |
|
| 76 | - $entity_data = $data['entity_data']; |
|
| 77 | - $term_id = (int) $data['term_id']; |
|
| 78 | - $existing_entities = $this->cache_service->get( $term_id ); |
|
| 79 | - $existing_entities[] = $entity_data; |
|
| 80 | - $this->cache_service->put( $term_id, $existing_entities ); |
|
| 81 | - |
|
| 82 | - $entity = Entity_List_Factory::get_instance( $term_id ); |
|
| 83 | - $entity->save_jsonld_data( $entity_data ); |
|
| 84 | - update_term_meta( $term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, 1 ); |
|
| 85 | - Ttl_Cache::flush_all(); |
|
| 86 | - |
|
| 87 | - return $existing_entities; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function get_entities_from_api( $request ) { |
|
| 91 | - $data = $request->get_params(); |
|
| 92 | - $search = $data['entity']; |
|
| 93 | - $entities = $this->analysis_service->get_entities_by_search_query( (string) $search ); |
|
| 94 | - |
|
| 95 | - return $this->convert_to_autocomplete_ui_response( $entities ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - private function convert_to_autocomplete_ui_response( $entities ) { |
|
| 99 | - |
|
| 100 | - $autocomplete_entities = array(); |
|
| 101 | - |
|
| 102 | - foreach ( $entities as $entity_id => $entity_data ) { |
|
| 103 | - |
|
| 104 | - $label = $entity_data['label']; |
|
| 105 | - $types = $entity_data['types']; |
|
| 106 | - $autocomplete_entities[] = array( |
|
| 107 | - "id" => $entity_data["entityId"], |
|
| 108 | - "labels" => array( $label ), |
|
| 109 | - "descriptions" => array( $entity_data['description'] ), |
|
| 110 | - "types" => $types, |
|
| 111 | - "urls" => array( $entity_id ), |
|
| 112 | - "images" => array(), |
|
| 113 | - "sameAss" => $entity_data['sameAs'], |
|
| 114 | - "scope" => "cloud", |
|
| 115 | - "description" => $entity_data['description'], |
|
| 116 | - "mainType" => $entity_data['mainType'], |
|
| 117 | - "label" => $label, |
|
| 118 | - "displayTypes" => $types, |
|
| 119 | - "value" => $entity_id, |
|
| 120 | - "confidence" => $entity_data["confidence"], |
|
| 121 | - "meta" => $entity_data["meta"] |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $autocomplete_entities; |
|
| 126 | - } |
|
| 12 | + /** |
|
| 13 | + * @var Analysis_Service |
|
| 14 | + */ |
|
| 15 | + private $analysis_service; |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var Cache |
|
| 20 | + */ |
|
| 21 | + private $cache_service; |
|
| 22 | + |
|
| 23 | + public function __construct( $api_service, $cache_service ) { |
|
| 24 | + $this->analysis_service = $api_service; |
|
| 25 | + $this->cache_service = $cache_service; |
|
| 26 | + add_action( 'rest_api_init', array( $this, 'register_route_callback' ) ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function register_route_callback() { |
|
| 30 | + register_rest_route( |
|
| 31 | + Api_Config::REST_NAMESPACE, |
|
| 32 | + '/search-entity', |
|
| 33 | + array( |
|
| 34 | + 'methods' => \WP_REST_Server::CREATABLE, |
|
| 35 | + 'callback' => array( $this, 'get_entities_from_api' ), |
|
| 36 | + 'args' => array( |
|
| 37 | + 'entity' => array( |
|
| 38 | + 'validate_callback' => function ( $param ) { |
|
| 39 | + return is_string( $param ); |
|
| 40 | + } |
|
| 41 | + ), |
|
| 42 | + ), |
|
| 43 | + 'permission_callback' => function () { |
|
| 44 | + return current_user_can( 'manage_options' ); |
|
| 45 | + } |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + |
|
| 49 | + register_rest_route( |
|
| 50 | + Api_Config::REST_NAMESPACE, |
|
| 51 | + '/add-entity', |
|
| 52 | + array( |
|
| 53 | + 'methods' => \WP_REST_Server::CREATABLE, |
|
| 54 | + 'callback' => array( $this, 'add_entity_to_matches' ), |
|
| 55 | + 'args' => array( |
|
| 56 | + 'entity_data' => array( |
|
| 57 | + 'validate_callback' => function ( $param ) { |
|
| 58 | + return is_array( $param ); |
|
| 59 | + } |
|
| 60 | + ), |
|
| 61 | + 'term_id' => array( |
|
| 62 | + 'validate_callback' => function ( $param ) { |
|
| 63 | + return is_numeric( $param ); |
|
| 64 | + } |
|
| 65 | + ) |
|
| 66 | + ), |
|
| 67 | + 'permission_callback' => function () { |
|
| 68 | + return current_user_can( 'manage_options' ); |
|
| 69 | + } |
|
| 70 | + ) |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public function add_entity_to_matches( $request ) { |
|
| 75 | + $data = $request->get_params(); |
|
| 76 | + $entity_data = $data['entity_data']; |
|
| 77 | + $term_id = (int) $data['term_id']; |
|
| 78 | + $existing_entities = $this->cache_service->get( $term_id ); |
|
| 79 | + $existing_entities[] = $entity_data; |
|
| 80 | + $this->cache_service->put( $term_id, $existing_entities ); |
|
| 81 | + |
|
| 82 | + $entity = Entity_List_Factory::get_instance( $term_id ); |
|
| 83 | + $entity->save_jsonld_data( $entity_data ); |
|
| 84 | + update_term_meta( $term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, 1 ); |
|
| 85 | + Ttl_Cache::flush_all(); |
|
| 86 | + |
|
| 87 | + return $existing_entities; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function get_entities_from_api( $request ) { |
|
| 91 | + $data = $request->get_params(); |
|
| 92 | + $search = $data['entity']; |
|
| 93 | + $entities = $this->analysis_service->get_entities_by_search_query( (string) $search ); |
|
| 94 | + |
|
| 95 | + return $this->convert_to_autocomplete_ui_response( $entities ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + private function convert_to_autocomplete_ui_response( $entities ) { |
|
| 99 | + |
|
| 100 | + $autocomplete_entities = array(); |
|
| 101 | + |
|
| 102 | + foreach ( $entities as $entity_id => $entity_data ) { |
|
| 103 | + |
|
| 104 | + $label = $entity_data['label']; |
|
| 105 | + $types = $entity_data['types']; |
|
| 106 | + $autocomplete_entities[] = array( |
|
| 107 | + "id" => $entity_data["entityId"], |
|
| 108 | + "labels" => array( $label ), |
|
| 109 | + "descriptions" => array( $entity_data['description'] ), |
|
| 110 | + "types" => $types, |
|
| 111 | + "urls" => array( $entity_id ), |
|
| 112 | + "images" => array(), |
|
| 113 | + "sameAss" => $entity_data['sameAs'], |
|
| 114 | + "scope" => "cloud", |
|
| 115 | + "description" => $entity_data['description'], |
|
| 116 | + "mainType" => $entity_data['mainType'], |
|
| 117 | + "label" => $label, |
|
| 118 | + "displayTypes" => $types, |
|
| 119 | + "value" => $entity_id, |
|
| 120 | + "confidence" => $entity_data["confidence"], |
|
| 121 | + "meta" => $entity_data["meta"] |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return $autocomplete_entities; |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | private $cache_service; |
| 22 | 22 | |
| 23 | - public function __construct( $api_service, $cache_service ) { |
|
| 23 | + public function __construct($api_service, $cache_service) { |
|
| 24 | 24 | $this->analysis_service = $api_service; |
| 25 | 25 | $this->cache_service = $cache_service; |
| 26 | - add_action( 'rest_api_init', array( $this, 'register_route_callback' ) ); |
|
| 26 | + add_action('rest_api_init', array($this, 'register_route_callback')); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function register_route_callback() { |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | '/search-entity', |
| 33 | 33 | array( |
| 34 | 34 | 'methods' => \WP_REST_Server::CREATABLE, |
| 35 | - 'callback' => array( $this, 'get_entities_from_api' ), |
|
| 35 | + 'callback' => array($this, 'get_entities_from_api'), |
|
| 36 | 36 | 'args' => array( |
| 37 | 37 | 'entity' => array( |
| 38 | - 'validate_callback' => function ( $param ) { |
|
| 39 | - return is_string( $param ); |
|
| 38 | + 'validate_callback' => function($param) { |
|
| 39 | + return is_string($param); |
|
| 40 | 40 | } |
| 41 | 41 | ), |
| 42 | 42 | ), |
| 43 | - 'permission_callback' => function () { |
|
| 44 | - return current_user_can( 'manage_options' ); |
|
| 43 | + 'permission_callback' => function() { |
|
| 44 | + return current_user_can('manage_options'); |
|
| 45 | 45 | } |
| 46 | 46 | ) |
| 47 | 47 | ); |
@@ -51,64 +51,64 @@ discard block |
||
| 51 | 51 | '/add-entity', |
| 52 | 52 | array( |
| 53 | 53 | 'methods' => \WP_REST_Server::CREATABLE, |
| 54 | - 'callback' => array( $this, 'add_entity_to_matches' ), |
|
| 54 | + 'callback' => array($this, 'add_entity_to_matches'), |
|
| 55 | 55 | 'args' => array( |
| 56 | 56 | 'entity_data' => array( |
| 57 | - 'validate_callback' => function ( $param ) { |
|
| 58 | - return is_array( $param ); |
|
| 57 | + 'validate_callback' => function($param) { |
|
| 58 | + return is_array($param); |
|
| 59 | 59 | } |
| 60 | 60 | ), |
| 61 | 61 | 'term_id' => array( |
| 62 | - 'validate_callback' => function ( $param ) { |
|
| 63 | - return is_numeric( $param ); |
|
| 62 | + 'validate_callback' => function($param) { |
|
| 63 | + return is_numeric($param); |
|
| 64 | 64 | } |
| 65 | 65 | ) |
| 66 | 66 | ), |
| 67 | - 'permission_callback' => function () { |
|
| 68 | - return current_user_can( 'manage_options' ); |
|
| 67 | + 'permission_callback' => function() { |
|
| 68 | + return current_user_can('manage_options'); |
|
| 69 | 69 | } |
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public function add_entity_to_matches( $request ) { |
|
| 74 | + public function add_entity_to_matches($request) { |
|
| 75 | 75 | $data = $request->get_params(); |
| 76 | 76 | $entity_data = $data['entity_data']; |
| 77 | 77 | $term_id = (int) $data['term_id']; |
| 78 | - $existing_entities = $this->cache_service->get( $term_id ); |
|
| 78 | + $existing_entities = $this->cache_service->get($term_id); |
|
| 79 | 79 | $existing_entities[] = $entity_data; |
| 80 | - $this->cache_service->put( $term_id, $existing_entities ); |
|
| 80 | + $this->cache_service->put($term_id, $existing_entities); |
|
| 81 | 81 | |
| 82 | - $entity = Entity_List_Factory::get_instance( $term_id ); |
|
| 83 | - $entity->save_jsonld_data( $entity_data ); |
|
| 84 | - update_term_meta( $term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, 1 ); |
|
| 82 | + $entity = Entity_List_Factory::get_instance($term_id); |
|
| 83 | + $entity->save_jsonld_data($entity_data); |
|
| 84 | + update_term_meta($term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, 1); |
|
| 85 | 85 | Ttl_Cache::flush_all(); |
| 86 | 86 | |
| 87 | 87 | return $existing_entities; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public function get_entities_from_api( $request ) { |
|
| 90 | + public function get_entities_from_api($request) { |
|
| 91 | 91 | $data = $request->get_params(); |
| 92 | 92 | $search = $data['entity']; |
| 93 | - $entities = $this->analysis_service->get_entities_by_search_query( (string) $search ); |
|
| 93 | + $entities = $this->analysis_service->get_entities_by_search_query((string) $search); |
|
| 94 | 94 | |
| 95 | - return $this->convert_to_autocomplete_ui_response( $entities ); |
|
| 95 | + return $this->convert_to_autocomplete_ui_response($entities); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - private function convert_to_autocomplete_ui_response( $entities ) { |
|
| 98 | + private function convert_to_autocomplete_ui_response($entities) { |
|
| 99 | 99 | |
| 100 | 100 | $autocomplete_entities = array(); |
| 101 | 101 | |
| 102 | - foreach ( $entities as $entity_id => $entity_data ) { |
|
| 102 | + foreach ($entities as $entity_id => $entity_data) { |
|
| 103 | 103 | |
| 104 | 104 | $label = $entity_data['label']; |
| 105 | 105 | $types = $entity_data['types']; |
| 106 | 106 | $autocomplete_entities[] = array( |
| 107 | 107 | "id" => $entity_data["entityId"], |
| 108 | - "labels" => array( $label ), |
|
| 109 | - "descriptions" => array( $entity_data['description'] ), |
|
| 108 | + "labels" => array($label), |
|
| 109 | + "descriptions" => array($entity_data['description']), |
|
| 110 | 110 | "types" => $types, |
| 111 | - "urls" => array( $entity_id ), |
|
| 111 | + "urls" => array($entity_id), |
|
| 112 | 112 | "images" => array(), |
| 113 | 113 | "sameAss" => $entity_data['sameAs'], |
| 114 | 114 | "scope" => "cloud", |
@@ -13,178 +13,178 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Analysis_Service { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var Default_Api_Service |
|
| 18 | - */ |
|
| 19 | - private $api_service; |
|
| 20 | - /** |
|
| 21 | - * @var Cache |
|
| 22 | - */ |
|
| 23 | - private $cache_service; |
|
| 24 | - /** |
|
| 25 | - * @var \Wordlift_Log_Service |
|
| 26 | - */ |
|
| 27 | - private $log; |
|
| 16 | + /** |
|
| 17 | + * @var Default_Api_Service |
|
| 18 | + */ |
|
| 19 | + private $api_service; |
|
| 20 | + /** |
|
| 21 | + * @var Cache |
|
| 22 | + */ |
|
| 23 | + private $cache_service; |
|
| 24 | + /** |
|
| 25 | + * @var \Wordlift_Log_Service |
|
| 26 | + */ |
|
| 27 | + private $log; |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Tag_Rest_Endpoint constructor. |
|
| 32 | - * |
|
| 33 | - * @param Default_Api_Service $api_service |
|
| 34 | - * @param Cache $cache_service |
|
| 35 | - */ |
|
| 36 | - public function __construct( $api_service, $cache_service ) { |
|
| 30 | + /** |
|
| 31 | + * Tag_Rest_Endpoint constructor. |
|
| 32 | + * |
|
| 33 | + * @param Default_Api_Service $api_service |
|
| 34 | + * @param Cache $cache_service |
|
| 35 | + */ |
|
| 36 | + public function __construct( $api_service, $cache_service ) { |
|
| 37 | 37 | |
| 38 | - $this->api_service = $api_service; |
|
| 38 | + $this->api_service = $api_service; |
|
| 39 | 39 | |
| 40 | - $this->cache_service = $cache_service; |
|
| 40 | + $this->cache_service = $cache_service; |
|
| 41 | 41 | |
| 42 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 42 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 43 | 43 | |
| 44 | - } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Check if entities are in cache, if not return the results from |
|
| 49 | - * cache service. |
|
| 50 | - * |
|
| 51 | - * @param $tag \WP_Term |
|
| 52 | - */ |
|
| 53 | - public function get_entities( $tag ) { |
|
| 47 | + /** |
|
| 48 | + * Check if entities are in cache, if not return the results from |
|
| 49 | + * cache service. |
|
| 50 | + * |
|
| 51 | + * @param $tag \WP_Term |
|
| 52 | + */ |
|
| 53 | + public function get_entities( $tag ) { |
|
| 54 | 54 | |
| 55 | - $cache_key = $tag->term_id; |
|
| 56 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
| 57 | - if ( $cache_result !== false ) { |
|
| 58 | - return $cache_result; |
|
| 59 | - } |
|
| 55 | + $cache_key = $tag->term_id; |
|
| 56 | + $cache_result = $this->cache_service->get( $cache_key ); |
|
| 57 | + if ( $cache_result !== false ) { |
|
| 58 | + return $cache_result; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - // send the request. |
|
| 62 | - $tag_name = $tag->name; |
|
| 63 | - |
|
| 64 | - $entities = $this->get_entities_by_search_query( $tag_name ); |
|
| 65 | - |
|
| 66 | - if ( ! $entities ) { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $this->cache_service->put( $cache_key, $entities ); |
|
| 71 | - |
|
| 72 | - return $entities; |
|
| 73 | - |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param $entity_url string |
|
| 79 | - * Formats the entity url from https://foo.com/some/path to |
|
| 80 | - * https/foo.com/some/path |
|
| 81 | - * |
|
| 82 | - * @return bool|string |
|
| 83 | - */ |
|
| 84 | - public static function format_entity_url( $entity_url ) { |
|
| 85 | - $result = parse_url( $entity_url ); |
|
| 86 | - if ( ! $result ) { |
|
| 87 | - return false; |
|
| 88 | - } |
|
| 89 | - if ( ! array_key_exists( 'scheme', $result ) |
|
| 90 | - || ! array_key_exists( 'host', $result ) |
|
| 91 | - || ! array_key_exists( 'path', $result ) ) { |
|
| 92 | - return false; |
|
| 93 | - } |
|
| 61 | + // send the request. |
|
| 62 | + $tag_name = $tag->name; |
|
| 63 | + |
|
| 64 | + $entities = $this->get_entities_by_search_query( $tag_name ); |
|
| 65 | + |
|
| 66 | + if ( ! $entities ) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $this->cache_service->put( $cache_key, $entities ); |
|
| 71 | + |
|
| 72 | + return $entities; |
|
| 73 | + |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param $entity_url string |
|
| 79 | + * Formats the entity url from https://foo.com/some/path to |
|
| 80 | + * https/foo.com/some/path |
|
| 81 | + * |
|
| 82 | + * @return bool|string |
|
| 83 | + */ |
|
| 84 | + public static function format_entity_url( $entity_url ) { |
|
| 85 | + $result = parse_url( $entity_url ); |
|
| 86 | + if ( ! $result ) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 89 | + if ( ! array_key_exists( 'scheme', $result ) |
|
| 90 | + || ! array_key_exists( 'host', $result ) |
|
| 91 | + || ! array_key_exists( 'path', $result ) ) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return $result['scheme'] . "/" . $result['host'] . $result['path']; |
|
| 96 | - } |
|
| 95 | + return $result['scheme'] . "/" . $result['host'] . $result['path']; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - private function get_meta( $entity_url ) { |
|
| 98 | + private function get_meta( $entity_url ) { |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
| 101 | + $cache_results = $this->cache_service->get( $entity_url ); |
|
| 102 | 102 | |
| 103 | - if ( $cache_results !== false ) { |
|
| 104 | - return $cache_results; |
|
| 105 | - } |
|
| 103 | + if ( $cache_results !== false ) { |
|
| 104 | + return $cache_results; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - $formatted_url = self::format_entity_url( $entity_url ); |
|
| 107 | + $formatted_url = self::format_entity_url( $entity_url ); |
|
| 108 | 108 | |
| 109 | - if ( ! $formatted_url ) { |
|
| 110 | - return array(); |
|
| 111 | - } |
|
| 109 | + if ( ! $formatted_url ) { |
|
| 110 | + return array(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
| 113 | + $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
| 114 | 114 | |
| 115 | - $response = wp_remote_get( $meta_url ); |
|
| 115 | + $response = wp_remote_get( $meta_url ); |
|
| 116 | 116 | |
| 117 | - $this->log->debug( "Requesting entity data for url :" . $meta_url ); |
|
| 118 | - $this->log->debug( "Got entity meta data as : " ); |
|
| 119 | - $this->log->debug( var_export( $response, true ) ); |
|
| 120 | - if ( ! is_wp_error( $response ) ) { |
|
| 121 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 122 | - $this->log->debug( "Saved entity data to meta :" ); |
|
| 123 | - $this->log->debug( var_export( $meta, true ) ); |
|
| 124 | - $this->cache_service->put( $entity_url, $meta ); |
|
| 117 | + $this->log->debug( "Requesting entity data for url :" . $meta_url ); |
|
| 118 | + $this->log->debug( "Got entity meta data as : " ); |
|
| 119 | + $this->log->debug( var_export( $response, true ) ); |
|
| 120 | + if ( ! is_wp_error( $response ) ) { |
|
| 121 | + $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 122 | + $this->log->debug( "Saved entity data to meta :" ); |
|
| 123 | + $this->log->debug( var_export( $meta, true ) ); |
|
| 124 | + $this->cache_service->put( $entity_url, $meta ); |
|
| 125 | 125 | |
| 126 | - return $meta; |
|
| 127 | - } |
|
| 126 | + return $meta; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | |
| 130 | - return array(); |
|
| 130 | + return array(); |
|
| 131 | 131 | |
| 132 | - } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - private function get_meta_for_entities( $entities ) { |
|
| 134 | + private function get_meta_for_entities( $entities ) { |
|
| 135 | 135 | |
| 136 | - $filtered_entities = array(); |
|
| 137 | - foreach ( $entities as $entity ) { |
|
| 138 | - $entity['meta'] = array(); |
|
| 139 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
| 140 | - $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
| 141 | - if ( $meta ) { |
|
| 142 | - $entity['meta'] = $meta; |
|
| 143 | - } |
|
| 144 | - $filtered_entities[] = $entity; |
|
| 145 | - } |
|
| 146 | - $this->log->debug( "Returning filtered entities as" ); |
|
| 147 | - $this->log->debug( var_export( $filtered_entities, true ) ); |
|
| 136 | + $filtered_entities = array(); |
|
| 137 | + foreach ( $entities as $entity ) { |
|
| 138 | + $entity['meta'] = array(); |
|
| 139 | + $meta = $this->get_meta( $entity['entityId'] ); |
|
| 140 | + $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
| 141 | + if ( $meta ) { |
|
| 142 | + $entity['meta'] = $meta; |
|
| 143 | + } |
|
| 144 | + $filtered_entities[] = $entity; |
|
| 145 | + } |
|
| 146 | + $this->log->debug( "Returning filtered entities as" ); |
|
| 147 | + $this->log->debug( var_export( $filtered_entities, true ) ); |
|
| 148 | 148 | |
| 149 | - return $filtered_entities; |
|
| 149 | + return $filtered_entities; |
|
| 150 | 150 | |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @param $tag_name |
|
| 155 | - * |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - public function get_entities_by_search_query( $tag_name ) { |
|
| 159 | - $response = $this->api_service->request( |
|
| 160 | - 'POST', |
|
| 161 | - "/analysis/single", |
|
| 162 | - array( 'Content-Type' => 'application/json' ), |
|
| 163 | - wp_json_encode( array( |
|
| 164 | - "content" => $tag_name, |
|
| 165 | - "contentType" => "text/plain", |
|
| 166 | - "version" => "1.0.0", |
|
| 167 | - "contentLanguage" => "en", |
|
| 168 | - "scope" => "all", |
|
| 169 | - ) ) |
|
| 170 | - ); |
|
| 153 | + /** |
|
| 154 | + * @param $tag_name |
|
| 155 | + * |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + public function get_entities_by_search_query( $tag_name ) { |
|
| 159 | + $response = $this->api_service->request( |
|
| 160 | + 'POST', |
|
| 161 | + "/analysis/single", |
|
| 162 | + array( 'Content-Type' => 'application/json' ), |
|
| 163 | + wp_json_encode( array( |
|
| 164 | + "content" => $tag_name, |
|
| 165 | + "contentType" => "text/plain", |
|
| 166 | + "version" => "1.0.0", |
|
| 167 | + "contentLanguage" => "en", |
|
| 168 | + "scope" => "all", |
|
| 169 | + ) ) |
|
| 170 | + ); |
|
| 171 | 171 | |
| 172 | 172 | |
| 173 | - if ( ! $response->is_success() ) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $response = json_decode( $response->get_body(), true ); |
|
| 178 | - |
|
| 179 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 173 | + if ( ! $response->is_success() ) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $response = json_decode( $response->get_body(), true ); |
|
| 178 | + |
|
| 179 | + if ( ! array_key_exists( 'entities', $response ) ) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | |
| 184 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
| 184 | + $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
| 185 | 185 | |
| 186 | - return $entities; |
|
| 187 | - } |
|
| 186 | + return $entities; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | } |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | * @param Default_Api_Service $api_service |
| 34 | 34 | * @param Cache $cache_service |
| 35 | 35 | */ |
| 36 | - public function __construct( $api_service, $cache_service ) { |
|
| 36 | + public function __construct($api_service, $cache_service) { |
|
| 37 | 37 | |
| 38 | 38 | $this->api_service = $api_service; |
| 39 | 39 | |
| 40 | 40 | $this->cache_service = $cache_service; |
| 41 | 41 | |
| 42 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 42 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
| 43 | 43 | |
| 44 | 44 | } |
| 45 | 45 | |
@@ -50,24 +50,24 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @param $tag \WP_Term |
| 52 | 52 | */ |
| 53 | - public function get_entities( $tag ) { |
|
| 53 | + public function get_entities($tag) { |
|
| 54 | 54 | |
| 55 | 55 | $cache_key = $tag->term_id; |
| 56 | - $cache_result = $this->cache_service->get( $cache_key ); |
|
| 57 | - if ( $cache_result !== false ) { |
|
| 56 | + $cache_result = $this->cache_service->get($cache_key); |
|
| 57 | + if ($cache_result !== false) { |
|
| 58 | 58 | return $cache_result; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // send the request. |
| 62 | 62 | $tag_name = $tag->name; |
| 63 | 63 | |
| 64 | - $entities = $this->get_entities_by_search_query( $tag_name ); |
|
| 64 | + $entities = $this->get_entities_by_search_query($tag_name); |
|
| 65 | 65 | |
| 66 | - if ( ! $entities ) { |
|
| 66 | + if ( ! $entities) { |
|
| 67 | 67 | return false; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $this->cache_service->put( $cache_key, $entities ); |
|
| 70 | + $this->cache_service->put($cache_key, $entities); |
|
| 71 | 71 | |
| 72 | 72 | return $entities; |
| 73 | 73 | |
@@ -81,47 +81,47 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return bool|string |
| 83 | 83 | */ |
| 84 | - public static function format_entity_url( $entity_url ) { |
|
| 85 | - $result = parse_url( $entity_url ); |
|
| 86 | - if ( ! $result ) { |
|
| 84 | + public static function format_entity_url($entity_url) { |
|
| 85 | + $result = parse_url($entity_url); |
|
| 86 | + if ( ! $result) { |
|
| 87 | 87 | return false; |
| 88 | 88 | } |
| 89 | - if ( ! array_key_exists( 'scheme', $result ) |
|
| 90 | - || ! array_key_exists( 'host', $result ) |
|
| 91 | - || ! array_key_exists( 'path', $result ) ) { |
|
| 89 | + if ( ! array_key_exists('scheme', $result) |
|
| 90 | + || ! array_key_exists('host', $result) |
|
| 91 | + || ! array_key_exists('path', $result)) { |
|
| 92 | 92 | return false; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - return $result['scheme'] . "/" . $result['host'] . $result['path']; |
|
| 95 | + return $result['scheme']."/".$result['host'].$result['path']; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - private function get_meta( $entity_url ) { |
|
| 98 | + private function get_meta($entity_url) { |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - $cache_results = $this->cache_service->get( $entity_url ); |
|
| 101 | + $cache_results = $this->cache_service->get($entity_url); |
|
| 102 | 102 | |
| 103 | - if ( $cache_results !== false ) { |
|
| 103 | + if ($cache_results !== false) { |
|
| 104 | 104 | return $cache_results; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - $formatted_url = self::format_entity_url( $entity_url ); |
|
| 107 | + $formatted_url = self::format_entity_url($entity_url); |
|
| 108 | 108 | |
| 109 | - if ( ! $formatted_url ) { |
|
| 109 | + if ( ! $formatted_url) { |
|
| 110 | 110 | return array(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $meta_url = 'https://api.wordlift.io/id/' . $formatted_url; |
|
| 113 | + $meta_url = 'https://api.wordlift.io/id/'.$formatted_url; |
|
| 114 | 114 | |
| 115 | - $response = wp_remote_get( $meta_url ); |
|
| 115 | + $response = wp_remote_get($meta_url); |
|
| 116 | 116 | |
| 117 | - $this->log->debug( "Requesting entity data for url :" . $meta_url ); |
|
| 118 | - $this->log->debug( "Got entity meta data as : " ); |
|
| 119 | - $this->log->debug( var_export( $response, true ) ); |
|
| 120 | - if ( ! is_wp_error( $response ) ) { |
|
| 121 | - $meta = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 122 | - $this->log->debug( "Saved entity data to meta :" ); |
|
| 123 | - $this->log->debug( var_export( $meta, true ) ); |
|
| 124 | - $this->cache_service->put( $entity_url, $meta ); |
|
| 117 | + $this->log->debug("Requesting entity data for url :".$meta_url); |
|
| 118 | + $this->log->debug("Got entity meta data as : "); |
|
| 119 | + $this->log->debug(var_export($response, true)); |
|
| 120 | + if ( ! is_wp_error($response)) { |
|
| 121 | + $meta = json_decode(wp_remote_retrieve_body($response), true); |
|
| 122 | + $this->log->debug("Saved entity data to meta :"); |
|
| 123 | + $this->log->debug(var_export($meta, true)); |
|
| 124 | + $this->cache_service->put($entity_url, $meta); |
|
| 125 | 125 | |
| 126 | 126 | return $meta; |
| 127 | 127 | } |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - private function get_meta_for_entities( $entities ) { |
|
| 134 | + private function get_meta_for_entities($entities) { |
|
| 135 | 135 | |
| 136 | 136 | $filtered_entities = array(); |
| 137 | - foreach ( $entities as $entity ) { |
|
| 137 | + foreach ($entities as $entity) { |
|
| 138 | 138 | $entity['meta'] = array(); |
| 139 | - $meta = $this->get_meta( $entity['entityId'] ); |
|
| 140 | - $meta = Default_Entity_List::compact_jsonld( $meta ); |
|
| 141 | - if ( $meta ) { |
|
| 139 | + $meta = $this->get_meta($entity['entityId']); |
|
| 140 | + $meta = Default_Entity_List::compact_jsonld($meta); |
|
| 141 | + if ($meta) { |
|
| 142 | 142 | $entity['meta'] = $meta; |
| 143 | 143 | } |
| 144 | 144 | $filtered_entities[] = $entity; |
| 145 | 145 | } |
| 146 | - $this->log->debug( "Returning filtered entities as" ); |
|
| 147 | - $this->log->debug( var_export( $filtered_entities, true ) ); |
|
| 146 | + $this->log->debug("Returning filtered entities as"); |
|
| 147 | + $this->log->debug(var_export($filtered_entities, true)); |
|
| 148 | 148 | |
| 149 | 149 | return $filtered_entities; |
| 150 | 150 | |
@@ -155,33 +155,33 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return array |
| 157 | 157 | */ |
| 158 | - public function get_entities_by_search_query( $tag_name ) { |
|
| 158 | + public function get_entities_by_search_query($tag_name) { |
|
| 159 | 159 | $response = $this->api_service->request( |
| 160 | 160 | 'POST', |
| 161 | 161 | "/analysis/single", |
| 162 | - array( 'Content-Type' => 'application/json' ), |
|
| 163 | - wp_json_encode( array( |
|
| 162 | + array('Content-Type' => 'application/json'), |
|
| 163 | + wp_json_encode(array( |
|
| 164 | 164 | "content" => $tag_name, |
| 165 | 165 | "contentType" => "text/plain", |
| 166 | 166 | "version" => "1.0.0", |
| 167 | 167 | "contentLanguage" => "en", |
| 168 | 168 | "scope" => "all", |
| 169 | - ) ) |
|
| 169 | + )) |
|
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | 172 | |
| 173 | - if ( ! $response->is_success() ) { |
|
| 173 | + if ( ! $response->is_success()) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - $response = json_decode( $response->get_body(), true ); |
|
| 177 | + $response = json_decode($response->get_body(), true); |
|
| 178 | 178 | |
| 179 | - if ( ! array_key_exists( 'entities', $response ) ) { |
|
| 179 | + if ( ! array_key_exists('entities', $response)) { |
|
| 180 | 180 | return false; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
| 184 | - $entities = $this->get_meta_for_entities( $response['entities'] ); |
|
| 184 | + $entities = $this->get_meta_for_entities($response['entities']); |
|
| 185 | 185 | |
| 186 | 186 | return $entities; |
| 187 | 187 | } |
@@ -23,67 +23,67 @@ |
||
| 23 | 23 | |
| 24 | 24 | class Vocabulary_Loader { |
| 25 | 25 | |
| 26 | - public function init_vocabulary() { |
|
| 26 | + public function init_vocabulary() { |
|
| 27 | 27 | |
| 28 | - $configuration_service = \Wordlift_Configuration_Service::get_instance(); |
|
| 28 | + $configuration_service = \Wordlift_Configuration_Service::get_instance(); |
|
| 29 | 29 | |
| 30 | - $api_service = new Default_Api_Service( |
|
| 31 | - apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), |
|
| 32 | - 60, |
|
| 33 | - User_Agent::get_user_agent(), |
|
| 34 | - $configuration_service->get_key() |
|
| 35 | - ); |
|
| 30 | + $api_service = new Default_Api_Service( |
|
| 31 | + apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), |
|
| 32 | + 60, |
|
| 33 | + User_Agent::get_user_agent(), |
|
| 34 | + $configuration_service->get_key() |
|
| 35 | + ); |
|
| 36 | 36 | |
| 37 | - $cache_service = Cache_Service_Factory::get_cache_service(); |
|
| 37 | + $cache_service = Cache_Service_Factory::get_cache_service(); |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - $analysis_service = new Analysis_Service( $api_service, $cache_service ); |
|
| 40 | + $analysis_service = new Analysis_Service( $api_service, $cache_service ); |
|
| 41 | 41 | |
| 42 | - $term_data_factory = new Term_Data_Factory( $analysis_service ); |
|
| 42 | + $term_data_factory = new Term_Data_Factory( $analysis_service ); |
|
| 43 | 43 | |
| 44 | - $tag_rest_endpoint = new Tag_Rest_Endpoint( $term_data_factory ); |
|
| 45 | - $tag_rest_endpoint->register_routes(); |
|
| 44 | + $tag_rest_endpoint = new Tag_Rest_Endpoint( $term_data_factory ); |
|
| 45 | + $tag_rest_endpoint->register_routes(); |
|
| 46 | 46 | |
| 47 | - new Search_Entity_Rest_Endpoint( $analysis_service, $cache_service ); |
|
| 47 | + new Search_Entity_Rest_Endpoint( $analysis_service, $cache_service ); |
|
| 48 | 48 | |
| 49 | - $entity_rest_endpoint = new Entity_Rest_Endpoint(); |
|
| 50 | - $entity_rest_endpoint->register_routes(); |
|
| 49 | + $entity_rest_endpoint = new Entity_Rest_Endpoint(); |
|
| 50 | + $entity_rest_endpoint->register_routes(); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - $post_jsonld = new Post_Jsonld(); |
|
| 55 | - $post_jsonld->enhance_post_jsonld(); |
|
| 54 | + $post_jsonld = new Post_Jsonld(); |
|
| 55 | + $post_jsonld->enhance_post_jsonld(); |
|
| 56 | 56 | |
| 57 | - $term_jsonld = new Term_Jsonld(); |
|
| 58 | - $term_jsonld->init(); |
|
| 57 | + $term_jsonld = new Term_Jsonld(); |
|
| 58 | + $term_jsonld->init(); |
|
| 59 | 59 | |
| 60 | - $term_count = Term_Count_Factory::get_instance( Term_Count_Factory::CACHED_TERM_COUNT ); |
|
| 61 | - new Match_Terms( $term_count ); |
|
| 60 | + $term_count = Term_Count_Factory::get_instance( Term_Count_Factory::CACHED_TERM_COUNT ); |
|
| 61 | + new Match_Terms( $term_count ); |
|
| 62 | 62 | |
| 63 | - $analysis_background_service = new Analysis_Background_Service( $analysis_service ); |
|
| 63 | + $analysis_background_service = new Analysis_Background_Service( $analysis_service ); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - new Tag_Created_Hook( $analysis_background_service ); |
|
| 66 | + new Tag_Created_Hook( $analysis_background_service ); |
|
| 67 | 67 | |
| 68 | - new Background_Analysis_Endpoint( $analysis_background_service, $cache_service ); |
|
| 68 | + new Background_Analysis_Endpoint( $analysis_background_service, $cache_service ); |
|
| 69 | 69 | |
| 70 | - $reconcile_progress_endpoint = new Reconcile_Progress_Endpoint(); |
|
| 71 | - $reconcile_progress_endpoint->register_routes(); |
|
| 70 | + $reconcile_progress_endpoint = new Reconcile_Progress_Endpoint(); |
|
| 71 | + $reconcile_progress_endpoint->register_routes(); |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | - $term_page_hook = new Term_Page_Hook( $term_data_factory ); |
|
| 75 | - $term_page_hook->connect_hook(); |
|
| 74 | + $term_page_hook = new Term_Page_Hook( $term_data_factory ); |
|
| 75 | + $term_page_hook->connect_hook(); |
|
| 76 | 76 | |
| 77 | - $dashboard_widget = new Term_Matches_Widget( $term_count ); |
|
| 78 | - $dashboard_widget->connect_hook(); |
|
| 77 | + $dashboard_widget = new Term_Matches_Widget( $term_count ); |
|
| 78 | + $dashboard_widget->connect_hook(); |
|
| 79 | 79 | |
| 80 | - $cached_term_count_manager = new Cached_Term_count_Manager(); |
|
| 81 | - $cached_term_count_manager->connect_hook(); |
|
| 80 | + $cached_term_count_manager = new Cached_Term_count_Manager(); |
|
| 81 | + $cached_term_count_manager->connect_hook(); |
|
| 82 | 82 | |
| 83 | - $settings_tab = new Settings_Tab(); |
|
| 84 | - $settings_tab->connect_hook(); |
|
| 83 | + $settings_tab = new Settings_Tab(); |
|
| 84 | + $settings_tab->connect_hook(); |
|
| 85 | 85 | |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $configuration_service = \Wordlift_Configuration_Service::get_instance(); |
| 29 | 29 | |
| 30 | 30 | $api_service = new Default_Api_Service( |
| 31 | - apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), |
|
| 31 | + apply_filters('wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE), |
|
| 32 | 32 | 60, |
| 33 | 33 | User_Agent::get_user_agent(), |
| 34 | 34 | $configuration_service->get_key() |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | $cache_service = Cache_Service_Factory::get_cache_service(); |
| 38 | 38 | |
| 39 | 39 | |
| 40 | - $analysis_service = new Analysis_Service( $api_service, $cache_service ); |
|
| 40 | + $analysis_service = new Analysis_Service($api_service, $cache_service); |
|
| 41 | 41 | |
| 42 | - $term_data_factory = new Term_Data_Factory( $analysis_service ); |
|
| 42 | + $term_data_factory = new Term_Data_Factory($analysis_service); |
|
| 43 | 43 | |
| 44 | - $tag_rest_endpoint = new Tag_Rest_Endpoint( $term_data_factory ); |
|
| 44 | + $tag_rest_endpoint = new Tag_Rest_Endpoint($term_data_factory); |
|
| 45 | 45 | $tag_rest_endpoint->register_routes(); |
| 46 | 46 | |
| 47 | - new Search_Entity_Rest_Endpoint( $analysis_service, $cache_service ); |
|
| 47 | + new Search_Entity_Rest_Endpoint($analysis_service, $cache_service); |
|
| 48 | 48 | |
| 49 | 49 | $entity_rest_endpoint = new Entity_Rest_Endpoint(); |
| 50 | 50 | $entity_rest_endpoint->register_routes(); |
@@ -57,24 +57,24 @@ discard block |
||
| 57 | 57 | $term_jsonld = new Term_Jsonld(); |
| 58 | 58 | $term_jsonld->init(); |
| 59 | 59 | |
| 60 | - $term_count = Term_Count_Factory::get_instance( Term_Count_Factory::CACHED_TERM_COUNT ); |
|
| 61 | - new Match_Terms( $term_count ); |
|
| 60 | + $term_count = Term_Count_Factory::get_instance(Term_Count_Factory::CACHED_TERM_COUNT); |
|
| 61 | + new Match_Terms($term_count); |
|
| 62 | 62 | |
| 63 | - $analysis_background_service = new Analysis_Background_Service( $analysis_service ); |
|
| 63 | + $analysis_background_service = new Analysis_Background_Service($analysis_service); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - new Tag_Created_Hook( $analysis_background_service ); |
|
| 66 | + new Tag_Created_Hook($analysis_background_service); |
|
| 67 | 67 | |
| 68 | - new Background_Analysis_Endpoint( $analysis_background_service, $cache_service ); |
|
| 68 | + new Background_Analysis_Endpoint($analysis_background_service, $cache_service); |
|
| 69 | 69 | |
| 70 | 70 | $reconcile_progress_endpoint = new Reconcile_Progress_Endpoint(); |
| 71 | 71 | $reconcile_progress_endpoint->register_routes(); |
| 72 | 72 | |
| 73 | 73 | |
| 74 | - $term_page_hook = new Term_Page_Hook( $term_data_factory ); |
|
| 74 | + $term_page_hook = new Term_Page_Hook($term_data_factory); |
|
| 75 | 75 | $term_page_hook->connect_hook(); |
| 76 | 76 | |
| 77 | - $dashboard_widget = new Term_Matches_Widget( $term_count ); |
|
| 77 | + $dashboard_widget = new Term_Matches_Widget($term_count); |
|
| 78 | 78 | $dashboard_widget->connect_hook(); |
| 79 | 79 | |
| 80 | 80 | $cached_term_count_manager = new Cached_Term_count_Manager(); |