@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter |
| 49 | 49 | * @param $cached_postid_to_jsonld_converter |
| 50 | 50 | */ |
| 51 | - public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) { |
|
| 51 | + public function __construct($post_to_jsonld_converter, $cached_postid_to_jsonld_converter) { |
|
| 52 | 52 | |
| 53 | 53 | $this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled(); |
| 54 | 54 | |
@@ -67,16 +67,16 @@ discard block |
||
| 67 | 67 | $this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance(); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function after_get_jsonld( $jsonld, $post_id, $context ) { |
|
| 70 | + public function after_get_jsonld($jsonld, $post_id, $context) { |
|
| 71 | 71 | |
| 72 | 72 | // Invalid data structure |
| 73 | - if ( ! is_array( $jsonld ) || ! isset( $jsonld[0] ) || ! is_array( $jsonld[0] ) ) { |
|
| 73 | + if ( ! is_array($jsonld) || ! isset($jsonld[0]) || ! is_array($jsonld[0])) { |
|
| 74 | 74 | return $jsonld; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( Jsonld_Context_Enum::PAGE !== $context |
|
| 77 | + if (Jsonld_Context_Enum::PAGE !== $context |
|
| 78 | 78 | // Returns true for "1", "true", "on" and "yes". Returns false otherwise. |
| 79 | - && ! filter_input( INPUT_GET, 'article_wrapper', FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 79 | + && ! filter_input(INPUT_GET, 'article_wrapper', FILTER_VALIDATE_BOOLEAN)) { |
|
| 80 | 80 | return $jsonld; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be |
| 87 | 87 | // in the schema.org context, i.e. `Article`, not `http://schema.org/Article`. |
| 88 | - if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) { |
|
| 88 | + if ( ! isset($post_jsonld['@id']) || ! isset($post_jsonld['@type']) || $this->is_article($post_jsonld['@type'])) { |
|
| 89 | 89 | return $jsonld; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -93,32 +93,32 @@ discard block |
||
| 93 | 93 | $reference_infos = array(); |
| 94 | 94 | |
| 95 | 95 | // Convert the post as Article. |
| 96 | - $article_jsonld = $this->post_to_jsonld_converter->convert( $post_id, $references, $reference_infos, new Relations() ); |
|
| 96 | + $article_jsonld = $this->post_to_jsonld_converter->convert($post_id, $references, $reference_infos, new Relations()); |
|
| 97 | 97 | |
| 98 | - $article_jsonld['@id'] = $post_jsonld['@id'] . '#article'; |
|
| 98 | + $article_jsonld['@id'] = $post_jsonld['@id'].'#article'; |
|
| 99 | 99 | // Reset the type, since by default the type assigned via the Entity Type taxonomy is used. |
| 100 | 100 | $article_jsonld['@type'] = 'Article'; |
| 101 | - $article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] ); |
|
| 101 | + $article_jsonld['about'] = array('@id' => $post_jsonld['@id']); |
|
| 102 | 102 | |
| 103 | 103 | // Copy over the URLs. |
| 104 | - if ( isset( $post_jsonld['url'] ) ) { |
|
| 104 | + if (isset($post_jsonld['url'])) { |
|
| 105 | 105 | $article_jsonld['url'] = $post_jsonld['url']; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - array_unshift( $jsonld, $article_jsonld ); |
|
| 108 | + array_unshift($jsonld, $article_jsonld); |
|
| 109 | 109 | |
| 110 | - $author_jsonld = $this->get_author_linked_entity( $article_jsonld ); |
|
| 110 | + $author_jsonld = $this->get_author_linked_entity($article_jsonld); |
|
| 111 | 111 | |
| 112 | - if ( $author_jsonld ) { |
|
| 112 | + if ($author_jsonld) { |
|
| 113 | 113 | // Get primary author in case co-authors exist. |
| 114 | - $primary_author = $this->get_primary_author( $article_jsonld['author'] ); |
|
| 114 | + $primary_author = $this->get_primary_author($article_jsonld['author']); |
|
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * The author entities can be present in graph for some entity types |
| 118 | 118 | * for Person and Organization, so check before we add it to graph. |
| 119 | 119 | * reference : https://schema.org/author |
| 120 | 120 | */ |
| 121 | - if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $primary_author['@id'] ) ) { |
|
| 121 | + if ($author_jsonld && ! $this->is_author_entity_present_in_graph($jsonld, $primary_author['@id'])) { |
|
| 122 | 122 | $jsonld[] = $author_jsonld; |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | return $jsonld; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - private function is_article( $schema_types ) { |
|
| 129 | + private function is_article($schema_types) { |
|
| 130 | 130 | |
| 131 | - $array_intersect = array_intersect( self::$article_types, (array) $schema_types ); |
|
| 131 | + $array_intersect = array_intersect(self::$article_types, (array) $schema_types); |
|
| 132 | 132 | |
| 133 | - return ! empty( $array_intersect ); |
|
| 133 | + return ! empty($array_intersect); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -144,32 +144,32 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @since 3.51.4 |
| 146 | 146 | */ |
| 147 | - private function get_primary_author( $author ) { |
|
| 147 | + private function get_primary_author($author) { |
|
| 148 | 148 | |
| 149 | 149 | // Nested array of co-authors. Return the primary author. |
| 150 | - if ( is_array( $author ) && ! empty( $author ) && ! isset( $author['@id'] ) ) { |
|
| 150 | + if (is_array($author) && ! empty($author) && ! isset($author['@id'])) { |
|
| 151 | 151 | return $author[0]; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $author; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - private function get_author_linked_entity( $article_jsonld ) { |
|
| 158 | - if ( ! array_key_exists( 'author', $article_jsonld ) ) { |
|
| 157 | + private function get_author_linked_entity($article_jsonld) { |
|
| 158 | + if ( ! array_key_exists('author', $article_jsonld)) { |
|
| 159 | 159 | return false; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $author = $this->get_primary_author( $article_jsonld['author'] ); |
|
| 162 | + $author = $this->get_primary_author($article_jsonld['author']); |
|
| 163 | 163 | |
| 164 | - if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) { |
|
| 164 | + if (count(array_keys($author)) !== 1 || ! array_key_exists('@id', $author)) { |
|
| 165 | 165 | return false; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | $author_linked_entity_id = $author['@id']; |
| 169 | 169 | |
| 170 | - $author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id ); |
|
| 170 | + $author_entity_post = $this->entity_uri_service->get_entity($author_linked_entity_id); |
|
| 171 | 171 | |
| 172 | - if ( ! $author_entity_post instanceof \WP_Post ) { |
|
| 172 | + if ( ! $author_entity_post instanceof \WP_Post) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) { |
|
| 188 | + private function is_author_entity_present_in_graph($jsonld, $author_entity_id) { |
|
| 189 | 189 | |
| 190 | - foreach ( $jsonld as $item ) { |
|
| 191 | - if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) { |
|
| 190 | + foreach ($jsonld as $item) { |
|
| 191 | + if ($item && array_key_exists('@id', $item) && $item['@id'] === $author_entity_id) { |
|
| 192 | 192 | return true; |
| 193 | 193 | } |
| 194 | 194 | } |