@@ -6,10 +6,10 @@ |
||
6 | 6 | |
7 | 7 | interface Remote_Entity_Importer { |
8 | 8 | |
9 | - /** |
|
10 | - * @return Wordpress_Content_Id|boolean |
|
11 | - * Returns content id or false. |
|
12 | - */ |
|
13 | - public function import(); |
|
9 | + /** |
|
10 | + * @return Wordpress_Content_Id|boolean |
|
11 | + * Returns content id or false. |
|
12 | + */ |
|
13 | + public function import(); |
|
14 | 14 | |
15 | 15 | } |
@@ -7,9 +7,9 @@ |
||
7 | 7 | */ |
8 | 8 | class Invalid_Remote_Entity_Importer implements Remote_Entity_Importer { |
9 | 9 | |
10 | - public function import() { |
|
11 | - // Cant import invalid entities. |
|
12 | - return false; |
|
13 | - } |
|
10 | + public function import() { |
|
11 | + // Cant import invalid entities. |
|
12 | + return false; |
|
13 | + } |
|
14 | 14 | |
15 | 15 | } |
@@ -8,39 +8,39 @@ |
||
8 | 8 | |
9 | 9 | class Valid_Remote_Entity_Importer implements Remote_Entity_Importer { |
10 | 10 | |
11 | - /** |
|
12 | - * @var Valid_Remote_Entity |
|
13 | - */ |
|
14 | - private $entity; |
|
15 | - |
|
16 | - /** |
|
17 | - * @param $entity Valid_Remote_Entity |
|
18 | - */ |
|
19 | - public function __construct( $entity ) { |
|
20 | - $this->entity = $entity; |
|
21 | - } |
|
22 | - |
|
23 | - public function import() { |
|
24 | - |
|
25 | - $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
|
26 | - |
|
27 | - $post_id = wp_insert_post( |
|
28 | - array( |
|
29 | - 'post_title' => $this->entity->get_name(), |
|
30 | - 'post_content' => $this->entity->get_description(), |
|
31 | - 'post_status' => 'draft', |
|
32 | - 'post_type' => 'entity', |
|
33 | - ) |
|
34 | - ); |
|
35 | - |
|
36 | - foreach ( $this->entity->get_types() as $type ) { |
|
37 | - $entity_type_service->set( $post_id, "http://schema.org/$type", false ); |
|
38 | - } |
|
39 | - |
|
40 | - foreach ( $this->entity->get_same_as() as $same_as ) { |
|
41 | - add_post_meta( $post_id, 'entity_same_as', $same_as ); |
|
42 | - } |
|
43 | - |
|
44 | - return Wordpress_Content_Id::create_post( $post_id ); |
|
45 | - } |
|
11 | + /** |
|
12 | + * @var Valid_Remote_Entity |
|
13 | + */ |
|
14 | + private $entity; |
|
15 | + |
|
16 | + /** |
|
17 | + * @param $entity Valid_Remote_Entity |
|
18 | + */ |
|
19 | + public function __construct( $entity ) { |
|
20 | + $this->entity = $entity; |
|
21 | + } |
|
22 | + |
|
23 | + public function import() { |
|
24 | + |
|
25 | + $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
|
26 | + |
|
27 | + $post_id = wp_insert_post( |
|
28 | + array( |
|
29 | + 'post_title' => $this->entity->get_name(), |
|
30 | + 'post_content' => $this->entity->get_description(), |
|
31 | + 'post_status' => 'draft', |
|
32 | + 'post_type' => 'entity', |
|
33 | + ) |
|
34 | + ); |
|
35 | + |
|
36 | + foreach ( $this->entity->get_types() as $type ) { |
|
37 | + $entity_type_service->set( $post_id, "http://schema.org/$type", false ); |
|
38 | + } |
|
39 | + |
|
40 | + foreach ( $this->entity->get_same_as() as $same_as ) { |
|
41 | + add_post_meta( $post_id, 'entity_same_as', $same_as ); |
|
42 | + } |
|
43 | + |
|
44 | + return Wordpress_Content_Id::create_post( $post_id ); |
|
45 | + } |
|
46 | 46 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @param $entity Valid_Remote_Entity |
18 | 18 | */ |
19 | - public function __construct( $entity ) { |
|
19 | + public function __construct($entity) { |
|
20 | 20 | $this->entity = $entity; |
21 | 21 | } |
22 | 22 | |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | ) |
34 | 34 | ); |
35 | 35 | |
36 | - foreach ( $this->entity->get_types() as $type ) { |
|
37 | - $entity_type_service->set( $post_id, "http://schema.org/$type", false ); |
|
36 | + foreach ($this->entity->get_types() as $type) { |
|
37 | + $entity_type_service->set($post_id, "http://schema.org/$type", false); |
|
38 | 38 | } |
39 | 39 | |
40 | - foreach ( $this->entity->get_same_as() as $same_as ) { |
|
41 | - add_post_meta( $post_id, 'entity_same_as', $same_as ); |
|
40 | + foreach ($this->entity->get_same_as() as $same_as) { |
|
41 | + add_post_meta($post_id, 'entity_same_as', $same_as); |
|
42 | 42 | } |
43 | 43 | |
44 | - return Wordpress_Content_Id::create_post( $post_id ); |
|
44 | + return Wordpress_Content_Id::create_post($post_id); |
|
45 | 45 | } |
46 | 46 | } |
@@ -6,16 +6,16 @@ |
||
6 | 6 | |
7 | 7 | class Url_To_Remote_Entity_Converter { |
8 | 8 | |
9 | - /** |
|
10 | - * @param $url |
|
11 | - * |
|
12 | - * @return Remote_Entity |
|
13 | - */ |
|
14 | - public static function convert( $url ) { |
|
15 | - $target_path = '/id/' . preg_replace( '@^(https?)://@', '$1/', $url ); |
|
16 | - $response = Default_Api_Service::get_instance()->get( $target_path ); |
|
9 | + /** |
|
10 | + * @param $url |
|
11 | + * |
|
12 | + * @return Remote_Entity |
|
13 | + */ |
|
14 | + public static function convert( $url ) { |
|
15 | + $target_path = '/id/' . preg_replace( '@^(https?)://@', '$1/', $url ); |
|
16 | + $response = Default_Api_Service::get_instance()->get( $target_path ); |
|
17 | 17 | |
18 | - return Remote_Entity_Factory::from_response( $url, $response ); |
|
19 | - } |
|
18 | + return Remote_Entity_Factory::from_response( $url, $response ); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | } |
@@ -11,11 +11,11 @@ |
||
11 | 11 | * |
12 | 12 | * @return Remote_Entity |
13 | 13 | */ |
14 | - public static function convert( $url ) { |
|
15 | - $target_path = '/id/' . preg_replace( '@^(https?)://@', '$1/', $url ); |
|
16 | - $response = Default_Api_Service::get_instance()->get( $target_path ); |
|
14 | + public static function convert($url) { |
|
15 | + $target_path = '/id/'.preg_replace('@^(https?)://@', '$1/', $url); |
|
16 | + $response = Default_Api_Service::get_instance()->get($target_path); |
|
17 | 17 | |
18 | - return Remote_Entity_Factory::from_response( $url, $response ); |
|
18 | + return Remote_Entity_Factory::from_response($url, $response); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | } |
@@ -4,19 +4,19 @@ |
||
4 | 4 | |
5 | 5 | class Invalid_Remote_Entity implements Remote_Entity { |
6 | 6 | |
7 | - public function get_name() { |
|
8 | - // TODO: Implement getName() method. |
|
9 | - } |
|
7 | + public function get_name() { |
|
8 | + // TODO: Implement getName() method. |
|
9 | + } |
|
10 | 10 | |
11 | - public function get_description() { |
|
12 | - // TODO: Implement getDescription() method. |
|
13 | - } |
|
11 | + public function get_description() { |
|
12 | + // TODO: Implement getDescription() method. |
|
13 | + } |
|
14 | 14 | |
15 | - public function get_same_as() { |
|
16 | - // TODO: Implement getSameAs() method. |
|
17 | - } |
|
15 | + public function get_same_as() { |
|
16 | + // TODO: Implement getSameAs() method. |
|
17 | + } |
|
18 | 18 | |
19 | - public function get_types() { |
|
20 | - // TODO: Implement getTypes() method. |
|
21 | - } |
|
19 | + public function get_types() { |
|
20 | + // TODO: Implement getTypes() method. |
|
21 | + } |
|
22 | 22 | } |
@@ -4,47 +4,47 @@ |
||
4 | 4 | |
5 | 5 | class Remote_Entity_Factory { |
6 | 6 | |
7 | - /** |
|
8 | - * |
|
9 | - * @param $entity_url string |
|
10 | - * @param $response \Wordlift\Api\Response |
|
11 | - * |
|
12 | - * @return Remote_Entity |
|
13 | - */ |
|
14 | - public static function from_response( $entity_url, $response ) { |
|
15 | - |
|
16 | - if ( ! $response->is_success() ) { |
|
17 | - return new Invalid_Remote_Entity(); |
|
18 | - } |
|
19 | - |
|
20 | - $entity_data = json_decode( $response->get_body(), true ); |
|
21 | - |
|
22 | - if ( ! $entity_data ) { |
|
23 | - return new Invalid_Remote_Entity(); |
|
24 | - } |
|
25 | - |
|
26 | - if ( ! array_key_exists( '@type', $entity_data ) |
|
27 | - || ! array_key_exists( 'name', $entity_data ) |
|
28 | - || ! array_key_exists( 'description', $entity_data ) ) { |
|
29 | - |
|
30 | - return new Invalid_Remote_Entity(); |
|
31 | - } |
|
32 | - |
|
33 | - return new Valid_Remote_Entity( |
|
34 | - self::may_be_wrap_array( $entity_data['@type'] ), |
|
35 | - $entity_data['name'], |
|
36 | - $entity_data['description'], |
|
37 | - array_merge( array( $entity_url ), self::may_be_wrap_array( $entity_data['sameAs'] ) ) |
|
38 | - ); |
|
39 | - |
|
40 | - } |
|
41 | - |
|
42 | - private static function may_be_wrap_array( $el ) { |
|
43 | - if ( is_array( $el ) ) { |
|
44 | - return $el; |
|
45 | - } |
|
46 | - |
|
47 | - return array( $el ); |
|
48 | - } |
|
7 | + /** |
|
8 | + * |
|
9 | + * @param $entity_url string |
|
10 | + * @param $response \Wordlift\Api\Response |
|
11 | + * |
|
12 | + * @return Remote_Entity |
|
13 | + */ |
|
14 | + public static function from_response( $entity_url, $response ) { |
|
15 | + |
|
16 | + if ( ! $response->is_success() ) { |
|
17 | + return new Invalid_Remote_Entity(); |
|
18 | + } |
|
19 | + |
|
20 | + $entity_data = json_decode( $response->get_body(), true ); |
|
21 | + |
|
22 | + if ( ! $entity_data ) { |
|
23 | + return new Invalid_Remote_Entity(); |
|
24 | + } |
|
25 | + |
|
26 | + if ( ! array_key_exists( '@type', $entity_data ) |
|
27 | + || ! array_key_exists( 'name', $entity_data ) |
|
28 | + || ! array_key_exists( 'description', $entity_data ) ) { |
|
29 | + |
|
30 | + return new Invalid_Remote_Entity(); |
|
31 | + } |
|
32 | + |
|
33 | + return new Valid_Remote_Entity( |
|
34 | + self::may_be_wrap_array( $entity_data['@type'] ), |
|
35 | + $entity_data['name'], |
|
36 | + $entity_data['description'], |
|
37 | + array_merge( array( $entity_url ), self::may_be_wrap_array( $entity_data['sameAs'] ) ) |
|
38 | + ); |
|
39 | + |
|
40 | + } |
|
41 | + |
|
42 | + private static function may_be_wrap_array( $el ) { |
|
43 | + if ( is_array( $el ) ) { |
|
44 | + return $el; |
|
45 | + } |
|
46 | + |
|
47 | + return array( $el ); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | } |
@@ -11,40 +11,40 @@ |
||
11 | 11 | * |
12 | 12 | * @return Remote_Entity |
13 | 13 | */ |
14 | - public static function from_response( $entity_url, $response ) { |
|
14 | + public static function from_response($entity_url, $response) { |
|
15 | 15 | |
16 | - if ( ! $response->is_success() ) { |
|
16 | + if ( ! $response->is_success()) { |
|
17 | 17 | return new Invalid_Remote_Entity(); |
18 | 18 | } |
19 | 19 | |
20 | - $entity_data = json_decode( $response->get_body(), true ); |
|
20 | + $entity_data = json_decode($response->get_body(), true); |
|
21 | 21 | |
22 | - if ( ! $entity_data ) { |
|
22 | + if ( ! $entity_data) { |
|
23 | 23 | return new Invalid_Remote_Entity(); |
24 | 24 | } |
25 | 25 | |
26 | - if ( ! array_key_exists( '@type', $entity_data ) |
|
27 | - || ! array_key_exists( 'name', $entity_data ) |
|
28 | - || ! array_key_exists( 'description', $entity_data ) ) { |
|
26 | + if ( ! array_key_exists('@type', $entity_data) |
|
27 | + || ! array_key_exists('name', $entity_data) |
|
28 | + || ! array_key_exists('description', $entity_data)) { |
|
29 | 29 | |
30 | 30 | return new Invalid_Remote_Entity(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | return new Valid_Remote_Entity( |
34 | - self::may_be_wrap_array( $entity_data['@type'] ), |
|
34 | + self::may_be_wrap_array($entity_data['@type']), |
|
35 | 35 | $entity_data['name'], |
36 | 36 | $entity_data['description'], |
37 | - array_merge( array( $entity_url ), self::may_be_wrap_array( $entity_data['sameAs'] ) ) |
|
37 | + array_merge(array($entity_url), self::may_be_wrap_array($entity_data['sameAs'])) |
|
38 | 38 | ); |
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | - private static function may_be_wrap_array( $el ) { |
|
43 | - if ( is_array( $el ) ) { |
|
42 | + private static function may_be_wrap_array($el) { |
|
43 | + if (is_array($el)) { |
|
44 | 44 | return $el; |
45 | 45 | } |
46 | 46 | |
47 | - return array( $el ); |
|
47 | + return array($el); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -4,50 +4,50 @@ |
||
4 | 4 | |
5 | 5 | class Valid_Remote_Entity implements Remote_Entity { |
6 | 6 | |
7 | - /** |
|
8 | - * @var array<string> |
|
9 | - */ |
|
10 | - private $types; |
|
11 | - |
|
12 | - /** |
|
13 | - * Title or name of the entity. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - private $name; |
|
18 | - /** |
|
19 | - * The entity description. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - private $description; |
|
24 | - /** |
|
25 | - * An array of sameAs urls. |
|
26 | - * |
|
27 | - * @var array<string> |
|
28 | - */ |
|
29 | - private $same_as; |
|
30 | - |
|
31 | - public function __construct( $types, $name, $description, $same_as ) { |
|
32 | - $this->types = $types; |
|
33 | - $this->name = $name; |
|
34 | - $this->description = $description; |
|
35 | - $this->same_as = $same_as; |
|
36 | - } |
|
37 | - |
|
38 | - public function get_name() { |
|
39 | - return $this->name; |
|
40 | - } |
|
41 | - |
|
42 | - public function get_description() { |
|
43 | - return $this->description; |
|
44 | - } |
|
45 | - |
|
46 | - public function get_same_as() { |
|
47 | - return $this->same_as; |
|
48 | - } |
|
49 | - |
|
50 | - public function get_types() { |
|
51 | - return $this->types; |
|
52 | - } |
|
7 | + /** |
|
8 | + * @var array<string> |
|
9 | + */ |
|
10 | + private $types; |
|
11 | + |
|
12 | + /** |
|
13 | + * Title or name of the entity. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + private $name; |
|
18 | + /** |
|
19 | + * The entity description. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + private $description; |
|
24 | + /** |
|
25 | + * An array of sameAs urls. |
|
26 | + * |
|
27 | + * @var array<string> |
|
28 | + */ |
|
29 | + private $same_as; |
|
30 | + |
|
31 | + public function __construct( $types, $name, $description, $same_as ) { |
|
32 | + $this->types = $types; |
|
33 | + $this->name = $name; |
|
34 | + $this->description = $description; |
|
35 | + $this->same_as = $same_as; |
|
36 | + } |
|
37 | + |
|
38 | + public function get_name() { |
|
39 | + return $this->name; |
|
40 | + } |
|
41 | + |
|
42 | + public function get_description() { |
|
43 | + return $this->description; |
|
44 | + } |
|
45 | + |
|
46 | + public function get_same_as() { |
|
47 | + return $this->same_as; |
|
48 | + } |
|
49 | + |
|
50 | + public function get_types() { |
|
51 | + return $this->types; |
|
52 | + } |
|
53 | 53 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | */ |
29 | 29 | private $same_as; |
30 | 30 | |
31 | - public function __construct( $types, $name, $description, $same_as ) { |
|
31 | + public function __construct($types, $name, $description, $same_as) { |
|
32 | 32 | $this->types = $types; |
33 | 33 | $this->name = $name; |
34 | 34 | $this->description = $description; |
@@ -4,24 +4,24 @@ |
||
4 | 4 | |
5 | 5 | interface Remote_Entity { |
6 | 6 | |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function get_name(); |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function get_name(); |
|
11 | 11 | |
12 | - /** |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public function get_description(); |
|
12 | + /** |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public function get_description(); |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array<string> |
|
19 | - */ |
|
20 | - public function get_same_as(); |
|
17 | + /** |
|
18 | + * @return array<string> |
|
19 | + */ |
|
20 | + public function get_same_as(); |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return array<string> |
|
24 | - */ |
|
25 | - public function get_types(); |
|
22 | + /** |
|
23 | + * @return array<string> |
|
24 | + */ |
|
25 | + public function get_types(); |
|
26 | 26 | |
27 | 27 | } |
@@ -14,75 +14,75 @@ |
||
14 | 14 | |
15 | 15 | class Entity_Helper { |
16 | 16 | |
17 | - private $entity_uri_service; |
|
18 | - |
|
19 | - private $entity_service; |
|
20 | - |
|
21 | - /** |
|
22 | - * Entity_Helper constructor. |
|
23 | - * |
|
24 | - * @param Wordlift_Entity_Uri_Service $entity_uri_service |
|
25 | - * @param Wordlift_Entity_Service $entity_service |
|
26 | - */ |
|
27 | - protected function __construct( $entity_uri_service, $entity_service ) { |
|
28 | - |
|
29 | - $this->entity_uri_service = $entity_uri_service; |
|
30 | - $this->entity_service = $entity_service; |
|
31 | - |
|
32 | - } |
|
33 | - |
|
34 | - private static $instance; |
|
35 | - |
|
36 | - public static function get_instance() { |
|
37 | - if ( ! isset( self::$instance ) ) { |
|
38 | - self::$instance = new self( Wordlift_Entity_Uri_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
39 | - } |
|
40 | - |
|
41 | - return self::$instance; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Maps the provided URIs to local URIs. |
|
46 | - * |
|
47 | - * The input array is filtered out of the local URIs. Then each URI is checked with itemid and sameAs in the local |
|
48 | - * database. If found a mapping is added from the external URI to the local URI. |
|
49 | - * |
|
50 | - * An array of mappings is returned, where the key is the external URI and the value is the local URI. |
|
51 | - * |
|
52 | - * @param array $uris An array of URIs. |
|
53 | - * |
|
54 | - * @return array The mappings array. |
|
55 | - */ |
|
56 | - public function map_many_to_local( $uris ) { |
|
57 | - |
|
58 | - // Filter only the external URIs. |
|
59 | - $entity_uri_service = $this->entity_uri_service; |
|
60 | - $external_uris = array_filter( |
|
61 | - $uris, |
|
62 | - function ( $item ) use ( $entity_uri_service ) { |
|
63 | - return ! $entity_uri_service->is_internal( $item ); |
|
64 | - } |
|
65 | - ); |
|
66 | - |
|
67 | - // Preload the URIs. |
|
68 | - $entity_uri_service->preload_uris( $external_uris ); |
|
69 | - |
|
70 | - $mappings = array(); |
|
71 | - foreach ( $external_uris as $external_uri ) { |
|
72 | - if ( empty( $external_uri ) ) { |
|
73 | - continue; |
|
74 | - } |
|
75 | - |
|
76 | - $entity = $entity_uri_service->get_entity( $external_uri ); |
|
77 | - if ( null !== $entity ) { |
|
78 | - |
|
79 | - // Get the internal URI. |
|
80 | - $internal_uri = $this->entity_service->get_uri( $entity->ID ); |
|
81 | - $mappings[ $external_uri ] = $internal_uri; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return $mappings; |
|
86 | - } |
|
17 | + private $entity_uri_service; |
|
18 | + |
|
19 | + private $entity_service; |
|
20 | + |
|
21 | + /** |
|
22 | + * Entity_Helper constructor. |
|
23 | + * |
|
24 | + * @param Wordlift_Entity_Uri_Service $entity_uri_service |
|
25 | + * @param Wordlift_Entity_Service $entity_service |
|
26 | + */ |
|
27 | + protected function __construct( $entity_uri_service, $entity_service ) { |
|
28 | + |
|
29 | + $this->entity_uri_service = $entity_uri_service; |
|
30 | + $this->entity_service = $entity_service; |
|
31 | + |
|
32 | + } |
|
33 | + |
|
34 | + private static $instance; |
|
35 | + |
|
36 | + public static function get_instance() { |
|
37 | + if ( ! isset( self::$instance ) ) { |
|
38 | + self::$instance = new self( Wordlift_Entity_Uri_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
39 | + } |
|
40 | + |
|
41 | + return self::$instance; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Maps the provided URIs to local URIs. |
|
46 | + * |
|
47 | + * The input array is filtered out of the local URIs. Then each URI is checked with itemid and sameAs in the local |
|
48 | + * database. If found a mapping is added from the external URI to the local URI. |
|
49 | + * |
|
50 | + * An array of mappings is returned, where the key is the external URI and the value is the local URI. |
|
51 | + * |
|
52 | + * @param array $uris An array of URIs. |
|
53 | + * |
|
54 | + * @return array The mappings array. |
|
55 | + */ |
|
56 | + public function map_many_to_local( $uris ) { |
|
57 | + |
|
58 | + // Filter only the external URIs. |
|
59 | + $entity_uri_service = $this->entity_uri_service; |
|
60 | + $external_uris = array_filter( |
|
61 | + $uris, |
|
62 | + function ( $item ) use ( $entity_uri_service ) { |
|
63 | + return ! $entity_uri_service->is_internal( $item ); |
|
64 | + } |
|
65 | + ); |
|
66 | + |
|
67 | + // Preload the URIs. |
|
68 | + $entity_uri_service->preload_uris( $external_uris ); |
|
69 | + |
|
70 | + $mappings = array(); |
|
71 | + foreach ( $external_uris as $external_uri ) { |
|
72 | + if ( empty( $external_uri ) ) { |
|
73 | + continue; |
|
74 | + } |
|
75 | + |
|
76 | + $entity = $entity_uri_service->get_entity( $external_uri ); |
|
77 | + if ( null !== $entity ) { |
|
78 | + |
|
79 | + // Get the internal URI. |
|
80 | + $internal_uri = $this->entity_service->get_uri( $entity->ID ); |
|
81 | + $mappings[ $external_uri ] = $internal_uri; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return $mappings; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @param Wordlift_Entity_Uri_Service $entity_uri_service |
25 | 25 | * @param Wordlift_Entity_Service $entity_service |
26 | 26 | */ |
27 | - protected function __construct( $entity_uri_service, $entity_service ) { |
|
27 | + protected function __construct($entity_uri_service, $entity_service) { |
|
28 | 28 | |
29 | 29 | $this->entity_uri_service = $entity_uri_service; |
30 | 30 | $this->entity_service = $entity_service; |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | private static $instance; |
35 | 35 | |
36 | 36 | public static function get_instance() { |
37 | - if ( ! isset( self::$instance ) ) { |
|
38 | - self::$instance = new self( Wordlift_Entity_Uri_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
37 | + if ( ! isset(self::$instance)) { |
|
38 | + self::$instance = new self(Wordlift_Entity_Uri_Service::get_instance(), Wordlift_Entity_Service::get_instance()); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return self::$instance; |
@@ -53,32 +53,32 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return array The mappings array. |
55 | 55 | */ |
56 | - public function map_many_to_local( $uris ) { |
|
56 | + public function map_many_to_local($uris) { |
|
57 | 57 | |
58 | 58 | // Filter only the external URIs. |
59 | 59 | $entity_uri_service = $this->entity_uri_service; |
60 | 60 | $external_uris = array_filter( |
61 | 61 | $uris, |
62 | - function ( $item ) use ( $entity_uri_service ) { |
|
63 | - return ! $entity_uri_service->is_internal( $item ); |
|
62 | + function($item) use ($entity_uri_service) { |
|
63 | + return ! $entity_uri_service->is_internal($item); |
|
64 | 64 | } |
65 | 65 | ); |
66 | 66 | |
67 | 67 | // Preload the URIs. |
68 | - $entity_uri_service->preload_uris( $external_uris ); |
|
68 | + $entity_uri_service->preload_uris($external_uris); |
|
69 | 69 | |
70 | 70 | $mappings = array(); |
71 | - foreach ( $external_uris as $external_uri ) { |
|
72 | - if ( empty( $external_uri ) ) { |
|
71 | + foreach ($external_uris as $external_uri) { |
|
72 | + if (empty($external_uri)) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | |
76 | - $entity = $entity_uri_service->get_entity( $external_uri ); |
|
77 | - if ( null !== $entity ) { |
|
76 | + $entity = $entity_uri_service->get_entity($external_uri); |
|
77 | + if (null !== $entity) { |
|
78 | 78 | |
79 | 79 | // Get the internal URI. |
80 | - $internal_uri = $this->entity_service->get_uri( $entity->ID ); |
|
81 | - $mappings[ $external_uri ] = $internal_uri; |
|
80 | + $internal_uri = $this->entity_service->get_uri($entity->ID); |
|
81 | + $mappings[$external_uri] = $internal_uri; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 |