Completed
Push — master ( caa748...46d5e9 )
by David
01:05
created
src/includes/class-wordlift-post-to-jsonld-converter.php 2 patches
Indentation   +498 added lines, -498 removed lines patch added patch discarded remove patch
@@ -19,522 +19,522 @@
 block discarded – undo
19 19
  */
20 20
 class Wordlift_Post_To_Jsonld_Converter extends Wordlift_Abstract_Post_To_Jsonld_Converter {
21 21
 
22
-	/**
23
-	 * @var Wordlift_Post_To_Jsonld_Converter
24
-	 */
25
-	private static $instance;
26
-
27
-	/**
28
-	 * A {@link Wordlift_Log_Service} instance.
29
-	 *
30
-	 * @since  3.10.0
31
-	 * @access private
32
-	 * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
33
-	 */
34
-	private $log;
35
-
36
-	/**
37
-	 * @var false
38
-	 */
39
-	private $disable_convert_filters;
40
-	/**
41
-	 * @var Object_Relation_Service
42
-	 */
43
-	private $object_relation_service;
44
-
45
-	/**
46
-	 * Wordlift_Post_To_Jsonld_Converter constructor.
47
-	 *
48
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
49
-	 * @param \Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
50
-	 * @param \Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
51
-	 *
52
-	 * @since 3.10.0
53
-	 */
54
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) {
55
-		parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() );
56
-		$this->disable_convert_filters = $disable_convert_filters;
57
-		$this->object_relation_service = Object_Relation_Service::get_instance();
58
-		// Set a reference to the logger.
59
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' );
60
-
61
-		self::$instance = $this;
62
-
63
-	}
64
-
65
-	public static function get_instance() {
66
-
67
-		return self::$instance;
68
-	}
69
-
70
-	public function new_instance_with_filters_disabled() {
71
-		return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true );
72
-	}
73
-
74
-	/**
75
-	 * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
76
-	 * found while processing the post is set in the $references array.
77
-	 *
78
-	 * @param int              $post_id The post id.
79
-	 * @param array<Reference> $references An array of entity references.
80
-	 * @param array            $references_infos
81
-	 *
82
-	 * @return array A JSON-LD array.
83
-	 * @since 3.10.0
84
-	 */
85
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
86
-
87
-		// Get the post instance.
88
-		$post = get_post( $post_id );
89
-		if ( null === $post ) {
90
-			// Post not found.
91
-			return null;
92
-		}
93
-
94
-		// Get the base JSON-LD and the list of entities referenced by this entity.
95
-		$jsonld = parent::convert( $post_id, $references, $references_infos );
96
-
97
-		// Set WebPage by default.
98
-		if ( empty( $jsonld['@type'] ) ) {
99
-			$jsonld['@type'] = 'WebPage';
100
-		}
101
-
102
-		// Get the entity name.
103
-		$jsonld['headline'] = $post->post_title;
104
-
105
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
106
-
107
-		if ( isset( $custom_fields ) ) {
108
-			$this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
109
-		}
110
-
111
-		// Set the published and modified dates.
112
-		/*
22
+    /**
23
+     * @var Wordlift_Post_To_Jsonld_Converter
24
+     */
25
+    private static $instance;
26
+
27
+    /**
28
+     * A {@link Wordlift_Log_Service} instance.
29
+     *
30
+     * @since  3.10.0
31
+     * @access private
32
+     * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
33
+     */
34
+    private $log;
35
+
36
+    /**
37
+     * @var false
38
+     */
39
+    private $disable_convert_filters;
40
+    /**
41
+     * @var Object_Relation_Service
42
+     */
43
+    private $object_relation_service;
44
+
45
+    /**
46
+     * Wordlift_Post_To_Jsonld_Converter constructor.
47
+     *
48
+     * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
49
+     * @param \Wordlift_User_Service        $user_service A {@link Wordlift_User_Service} instance.
50
+     * @param \Wordlift_Attachment_Service  $attachment_service A {@link Wordlift_Attachment_Service} instance.
51
+     *
52
+     * @since 3.10.0
53
+     */
54
+    public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) {
55
+        parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() );
56
+        $this->disable_convert_filters = $disable_convert_filters;
57
+        $this->object_relation_service = Object_Relation_Service::get_instance();
58
+        // Set a reference to the logger.
59
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' );
60
+
61
+        self::$instance = $this;
62
+
63
+    }
64
+
65
+    public static function get_instance() {
66
+
67
+        return self::$instance;
68
+    }
69
+
70
+    public function new_instance_with_filters_disabled() {
71
+        return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true );
72
+    }
73
+
74
+    /**
75
+     * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference
76
+     * found while processing the post is set in the $references array.
77
+     *
78
+     * @param int              $post_id The post id.
79
+     * @param array<Reference> $references An array of entity references.
80
+     * @param array            $references_infos
81
+     *
82
+     * @return array A JSON-LD array.
83
+     * @since 3.10.0
84
+     */
85
+    public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
86
+
87
+        // Get the post instance.
88
+        $post = get_post( $post_id );
89
+        if ( null === $post ) {
90
+            // Post not found.
91
+            return null;
92
+        }
93
+
94
+        // Get the base JSON-LD and the list of entities referenced by this entity.
95
+        $jsonld = parent::convert( $post_id, $references, $references_infos );
96
+
97
+        // Set WebPage by default.
98
+        if ( empty( $jsonld['@type'] ) ) {
99
+            $jsonld['@type'] = 'WebPage';
100
+        }
101
+
102
+        // Get the entity name.
103
+        $jsonld['headline'] = $post->post_title;
104
+
105
+        $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
106
+
107
+        if ( isset( $custom_fields ) ) {
108
+            $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
109
+        }
110
+
111
+        // Set the published and modified dates.
112
+        /*
113 113
 		 * Set the `datePublished` and `dateModified` using the local timezone.
114 114
 		 *
115 115
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/887
116 116
 		 *
117 117
 		 * @since 3.20.0
118 118
 		 */
119
-		try {
120
-			$default_timezone = date_default_timezone_get();
121
-			$timezone         = get_option( 'timezone_string' );
122
-			if ( ! empty( $timezone ) ) {
123
-				date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
124
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post );
125
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post );
126
-				date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
127
-			} else {
128
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
129
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
130
-			}
131
-		} catch ( Exception $e ) {
132
-			$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
133
-			$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
134
-		}
135
-
136
-		// Get the word count for the post.
137
-		/*
119
+        try {
120
+            $default_timezone = date_default_timezone_get();
121
+            $timezone         = get_option( 'timezone_string' );
122
+            if ( ! empty( $timezone ) ) {
123
+                date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
124
+                $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post );
125
+                $jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post );
126
+                date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
127
+            } else {
128
+                $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
129
+                $jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
130
+            }
131
+        } catch ( Exception $e ) {
132
+            $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
133
+            $jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
134
+        }
135
+
136
+        // Get the word count for the post.
137
+        /*
138 138
 		 * Do not display the `wordCount` on a `WebPage`.
139 139
 		 *
140 140
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/888
141 141
 		 *
142 142
 		 * @since 3.20.0
143 143
 		 */
144
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
145
-			$post_adapter        = new Wordlift_Post_Adapter( $post_id );
146
-			$jsonld['wordCount'] = $post_adapter->word_count();
147
-		}
144
+        if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
145
+            $post_adapter        = new Wordlift_Post_Adapter( $post_id );
146
+            $jsonld['wordCount'] = $post_adapter->word_count();
147
+        }
148 148
 
149
-		/*
149
+        /*
150 150
 		 * Add keywords, articleSection, commentCount and inLanguage properties to `Article` JSON-LD
151 151
 		 *
152 152
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/1140
153 153
 		 *
154 154
 		 * @since 3.27.2
155 155
 		 */
156
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
157
-			$post_adapter    = new Wordlift_Post_Adapter( $post_id );
158
-			$keywords        = $post_adapter->keywords();
159
-			$article_section = $post_adapter->article_section();
160
-			$comment_count   = $post_adapter->comment_count();
161
-			$locale          = $post_adapter->locale();
162
-
163
-			if ( isset( $keywords ) ) {
164
-				$jsonld['keywords'] = $keywords;
165
-			}
166
-			if ( ! empty( $article_section ) ) {
167
-				$jsonld['articleSection'] = $article_section;
168
-			}
169
-			$jsonld['commentCount'] = $comment_count;
170
-			$jsonld['inLanguage']   = $locale;
171
-			$post_adapter->add_references( $post_id, $references );
172
-		}
173
-
174
-		// Set the publisher.
175
-		$this->set_publisher( $jsonld );
176
-
177
-		$references = $this->convert_references( $references );
178
-
179
-		// Process the references if any.
180
-		$this->set_mentions_and_about( $references, $post, $jsonld );
181
-
182
-		// Finally set the author.
183
-		$jsonld['author'] = $this->get_author( $post->post_author, $references );
184
-
185
-		// Return the JSON-LD if filters are disabled by the client.
186
-		if ( $this->disable_convert_filters ) {
187
-			return $jsonld;
188
-		}
189
-
190
-		/**
191
-		 * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references.
192
-		 *
193
-		 * @param array $value {
194
-		 *
195
-		 * @type array $jsonld The JSON-LD structure.
196
-		 * @type int[] $references An array of post IDs.
197
-		 * }
198
-		 * @since 3.25.0
199
-		 *
200
-		 * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
201
-		 *
202
-		 * @api
203
-		 */
204
-		$ret_val = apply_filters(
205
-			'wl_post_jsonld_array',
206
-			array(
207
-				'jsonld'     => $jsonld,
208
-				'references' => $references,
209
-			),
210
-			$post_id
211
-		);
212
-
213
-		$jsonld     = $ret_val['jsonld'];
214
-		$references = $ret_val['references'];
215
-
216
-		/**
217
-		 * Call the `wl_post_jsonld` filter.
218
-		 *
219
-		 * @param array $jsonld The JSON-LD structure.
220
-		 * @param int $post_id The {@link WP_Post} `id`.
221
-		 * @param array $references The array of referenced entities.
222
-		 *
223
-		 * @since 3.14.0
224
-		 *
225
-		 * @api
226
-		 */
227
-		return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references );
228
-	}
229
-
230
-	/**
231
-	 * Get the author's JSON-LD fragment.
232
-	 *
233
-	 * The JSON-LD fragment is generated using the {@link WP_User}'s data or
234
-	 * the referenced entity if configured for the {@link WP_User}.
235
-	 *
236
-	 * @param int   $author_id The author {@link WP_User}'s `id`.
237
-	 * @param array $references An array of referenced entities.
238
-	 *
239
-	 * @return string|array A JSON-LD structure.
240
-	 * @since 3.14.0
241
-	 */
242
-	public function get_author( $author_id, &$references ) {
243
-
244
-		// Get the entity bound to this user.
245
-		$entity_id = $this->user_service->get_entity( $author_id );
246
-
247
-		// If there's no entity bound return a simple author structure.
248
-		if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) {
249
-
250
-			$author            = get_the_author_meta( 'display_name', $author_id );
251
-			$author_first_name = get_the_author_meta( 'first_name', $author_id );
252
-			$author_last_name  = get_the_author_meta( 'last_name', $author_id );
253
-			$author_uri        = $this->user_service->get_uri( $author_id );
254
-
255
-			return array(
256
-				'@type'      => 'Person',
257
-				'@id'        => $author_uri,
258
-				'name'       => $author,
259
-				'givenName'  => $author_first_name,
260
-				'familyName' => $author_last_name,
261
-				'url'        => get_author_posts_url( $author_id ),
262
-			);
263
-		}
264
-
265
-		// Add the author to the references.
266
-		$author_uri   = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id );
267
-		$references[] = $entity_id;
268
-
269
-		// Return the JSON-LD for the referenced entity.
270
-		return array(
271
-			'@id' => $author_uri,
272
-		);
273
-	}
274
-
275
-	/**
276
-	 * Enrich the provided params array with publisher data, if available.
277
-	 *
278
-	 * @param array $params The parameters array.
279
-	 *
280
-	 * @since 3.10.0
281
-	 */
282
-	protected function set_publisher( &$params ) {
283
-
284
-		// If the publisher id isn't set don't do anything.
285
-		$publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
286
-		if ( null === $publisher_id ) {
287
-			return;
288
-		}
289
-
290
-		// Get the post instance.
291
-		$post = get_post( $publisher_id );
292
-		if ( null === $post ) {
293
-			// Publisher not found.
294
-			return;
295
-		}
296
-
297
-		// Get the item id.
298
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id );
299
-
300
-		// Get the type.
301
-		$type = $this->entity_type_service->get( $publisher_id );
302
-
303
-		// Get the name.
304
-		$name = $post->post_title;
305
-
306
-		// Set the publisher data.
307
-		$params['publisher'] = array(
308
-			'@type' => $this->relative_to_context( $type['uri'] ),
309
-			'@id'   => $id,
310
-			'name'  => $name,
311
-		);
312
-
313
-		// Add the sameAs values associated with the publisher.
314
-		$storage_factory = Wordlift_Storage_Factory::get_instance();
315
-		$sameas          = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id );
316
-		if ( ! empty( $sameas ) ) {
317
-			$params['publisher']['sameAs'] = $sameas;
318
-		}
319
-
320
-		// Set the logo, only for http://schema.org/Organization as Person doesn't
321
-		// support the logo property.
322
-		//
323
-		// See http://schema.org/logo.
324
-		if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) {
325
-			return;
326
-		}
327
-
328
-		// Get the publisher logo.
329
-		$publisher_logo = $this->get_publisher_logo( $post->ID );
330
-
331
-		// Bail out if the publisher logo isn't set.
332
-		if ( false === $publisher_logo ) {
333
-			return;
334
-		}
335
-
336
-		// Copy over some useful properties.
337
-		//
338
-		// See https://developers.google.com/search/docs/data-types/articles.
339
-		$params['publisher']['logo']['@type'] = 'ImageObject';
340
-		$params['publisher']['logo']['url']   = $publisher_logo['url'];
341
-
342
-		// If you specify a "width" or "height" value you should leave out
343
-		// 'px'. For example: "width":"4608px" should be "width":"4608".
344
-		//
345
-		// See https://github.com/insideout10/wordlift-plugin/issues/451.
346
-		$params['publisher']['logo']['width']  = $publisher_logo['width'];
347
-		$params['publisher']['logo']['height'] = $publisher_logo['height'];
348
-
349
-	}
350
-
351
-	/**
352
-	 * Get the publisher logo structure.
353
-	 *
354
-	 * The function returns false when the publisher logo cannot be determined, i.e.:
355
-	 *  - the post has no featured image.
356
-	 *  - the featured image has no file.
357
-	 *  - a wp_image_editor instance cannot be instantiated on the original file or on the publisher logo file.
358
-	 *
359
-	 * @param int $post_id The post id.
360
-	 *
361
-	 * @return array|false Returns an array with the `url`, `width` and `height` for the publisher logo or false in case
362
-	 *  of errors.
363
-	 * @since 3.19.2
364
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue.
365
-	 */
366
-	private function get_publisher_logo( $post_id ) {
367
-
368
-		// Get the featured image for the post.
369
-		$thumbnail_id = get_post_thumbnail_id( $post_id );
370
-
371
-		// Bail out if thumbnail not available.
372
-		if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) {
373
-			$this->log->info( "Featured image not set for post $post_id." );
374
-
375
-			return false;
376
-		}
377
-
378
-		// Get the uploads base URL.
379
-		$uploads_dir = wp_upload_dir();
380
-
381
-		// Get the attachment metadata.
382
-		$metadata = wp_get_attachment_metadata( $thumbnail_id );
383
-
384
-		// Bail out if the file isn't set.
385
-		if ( ! isset( $metadata['file'] ) ) {
386
-			$this->log->warn( "Featured image file not found for post $post_id." );
387
-
388
-			return false;
389
-		}
390
-
391
-		// Retrieve the relative filename, e.g. "2018/05/logo_publisher.png"
392
-		$path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
393
-
394
-		// Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149
395
-		if ( ! file_exists( $path ) ) {
396
-			$this->log->warn( "Featured image file $path doesn't exist for post $post_id." );
397
-
398
-			$attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' );
399
-			if ( $attachment_image_src ) {
400
-				return array(
401
-					'url'    => $attachment_image_src[0],
402
-					'width'  => $attachment_image_src[1],
403
-					'height' => $attachment_image_src[2],
404
-				);
405
-			}
406
-
407
-			// Bail out if we cant fetch wp_get_attachment_image_src
408
-			return false;
409
-
410
-		}
411
-
412
-		// Try to get the image editor and bail out if the editor cannot be instantiated.
413
-		$original_file_editor = wp_get_image_editor( $path );
414
-		if ( is_wp_error( $original_file_editor ) ) {
415
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." );
416
-
417
-			return false;
418
-		}
419
-
420
-		// Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling
421
-		// and we don't actually know the end values.
422
-		$publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' );
423
-
424
-		// If the file doesn't exist yet, create it.
425
-		if ( ! file_exists( $publisher_logo_path ) ) {
426
-			$original_file_editor->resize( 600, 60 );
427
-			$original_file_editor->save( $publisher_logo_path );
428
-		}
429
-
430
-		// Try to get the image editor and bail out if the editor cannot be instantiated.
431
-		$publisher_logo_editor = wp_get_image_editor( $publisher_logo_path );
432
-		if ( is_wp_error( $publisher_logo_editor ) ) {
433
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." );
434
-
435
-			return false;
436
-		}
437
-
438
-		// Get the actual size.
439
-		$size = $publisher_logo_editor->get_size();
440
-
441
-		// Finally return the array with data.
442
-		return array(
443
-			'url'    => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ),
444
-			'width'  => $size['width'],
445
-			'height' => $size['height'],
446
-		);
447
-	}
448
-
449
-	/**
450
-	 * @param $references
451
-	 * @param $post
452
-	 * @param $jsonld
453
-	 *
454
-	 * @return void
455
-	 */
456
-	private function set_mentions_and_about( $references, $post, &$jsonld ) {
457
-
458
-		if ( count( $references ) === 0 ) {
459
-			return;
460
-		}
461
-
462
-		// Prepare the `about` and `mentions` array.
463
-		$mentions = array();
464
-		$about    = array();
465
-
466
-		// If the entity is in the title, then it should be an `about`.
467
-		foreach ( $references as $reference ) {
468
-
469
-			if ( ! $reference instanceof Reference ) {
470
-				// This condition should never be reached.
471
-				continue;
472
-			}
473
-
474
-			// Get the entity labels.
475
-			$labels = Wordlift_Entity_Service::get_instance()->get_labels( $reference->get_id(), $reference->get_type() );
476
-			// Get the entity URI.
477
-			$item = array(
478
-				'@id' => Wordlift_Entity_Service::get_instance()->get_uri( $reference->get_id(), $reference->get_type() ),
479
-			);
480
-
481
-			$escaped_labels = array_map(
482
-				function ( $value ) {
483
-					return preg_quote( $value, '/' );
484
-				},
485
-				$labels
486
-			);
487
-
488
-			$matches = false;
489
-
490
-			// When the title is empty, then we shouldn't yield a match to about section.
491
-			if ( array_filter( $escaped_labels ) ) {
492
-				// Check if the labels match any part of the title.
493
-				$matches = 1 === preg_match( '/' . implode( '|', $escaped_labels ) . '/', $post->post_title );
494
-			}
495
-
496
-			// If the title matches, assign the entity to the about, otherwise to the mentions.
497
-			if ( $matches ) {
498
-				$about[] = $item;
499
-			} else {
500
-				$mentions[] = $item;
501
-			}
502
-		}
503
-
504
-		// If we have abouts, assign them to the JSON-LD.
505
-		if ( 0 < count( $about ) ) {
506
-			$jsonld['about'] = $about;
507
-		}
508
-
509
-		// If we have mentions, assign them to the JSON-LD.
510
-		if ( 0 < count( $mentions ) ) {
511
-			$jsonld['mentions'] = $mentions;
512
-		}
513
-
514
-		return $jsonld;
515
-	}
516
-
517
-	/**
518
-	 * Convert references to abstract data type if we find any.
519
-	 *
520
-	 * @param $references array<int|Reference>
521
-	 *
522
-	 * @return Reference[]
523
-	 */
524
-	private function convert_references( $references ) {
525
-		return array_map(
526
-			function ( $reference ) {
527
-				// Legacy code may still push numerical references to this
528
-				// $references variable, so convert it to post references.
529
-				if ( is_numeric( $reference ) ) {
530
-					  return new Post_Reference( $reference );
531
-				}
532
-
533
-				return $reference;
534
-
535
-			},
536
-			$references
537
-		);
538
-	}
156
+        if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
157
+            $post_adapter    = new Wordlift_Post_Adapter( $post_id );
158
+            $keywords        = $post_adapter->keywords();
159
+            $article_section = $post_adapter->article_section();
160
+            $comment_count   = $post_adapter->comment_count();
161
+            $locale          = $post_adapter->locale();
162
+
163
+            if ( isset( $keywords ) ) {
164
+                $jsonld['keywords'] = $keywords;
165
+            }
166
+            if ( ! empty( $article_section ) ) {
167
+                $jsonld['articleSection'] = $article_section;
168
+            }
169
+            $jsonld['commentCount'] = $comment_count;
170
+            $jsonld['inLanguage']   = $locale;
171
+            $post_adapter->add_references( $post_id, $references );
172
+        }
173
+
174
+        // Set the publisher.
175
+        $this->set_publisher( $jsonld );
176
+
177
+        $references = $this->convert_references( $references );
178
+
179
+        // Process the references if any.
180
+        $this->set_mentions_and_about( $references, $post, $jsonld );
181
+
182
+        // Finally set the author.
183
+        $jsonld['author'] = $this->get_author( $post->post_author, $references );
184
+
185
+        // Return the JSON-LD if filters are disabled by the client.
186
+        if ( $this->disable_convert_filters ) {
187
+            return $jsonld;
188
+        }
189
+
190
+        /**
191
+         * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references.
192
+         *
193
+         * @param array $value {
194
+         *
195
+         * @type array $jsonld The JSON-LD structure.
196
+         * @type int[] $references An array of post IDs.
197
+         * }
198
+         * @since 3.25.0
199
+         *
200
+         * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
201
+         *
202
+         * @api
203
+         */
204
+        $ret_val = apply_filters(
205
+            'wl_post_jsonld_array',
206
+            array(
207
+                'jsonld'     => $jsonld,
208
+                'references' => $references,
209
+            ),
210
+            $post_id
211
+        );
212
+
213
+        $jsonld     = $ret_val['jsonld'];
214
+        $references = $ret_val['references'];
215
+
216
+        /**
217
+         * Call the `wl_post_jsonld` filter.
218
+         *
219
+         * @param array $jsonld The JSON-LD structure.
220
+         * @param int $post_id The {@link WP_Post} `id`.
221
+         * @param array $references The array of referenced entities.
222
+         *
223
+         * @since 3.14.0
224
+         *
225
+         * @api
226
+         */
227
+        return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references );
228
+    }
229
+
230
+    /**
231
+     * Get the author's JSON-LD fragment.
232
+     *
233
+     * The JSON-LD fragment is generated using the {@link WP_User}'s data or
234
+     * the referenced entity if configured for the {@link WP_User}.
235
+     *
236
+     * @param int   $author_id The author {@link WP_User}'s `id`.
237
+     * @param array $references An array of referenced entities.
238
+     *
239
+     * @return string|array A JSON-LD structure.
240
+     * @since 3.14.0
241
+     */
242
+    public function get_author( $author_id, &$references ) {
243
+
244
+        // Get the entity bound to this user.
245
+        $entity_id = $this->user_service->get_entity( $author_id );
246
+
247
+        // If there's no entity bound return a simple author structure.
248
+        if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) {
249
+
250
+            $author            = get_the_author_meta( 'display_name', $author_id );
251
+            $author_first_name = get_the_author_meta( 'first_name', $author_id );
252
+            $author_last_name  = get_the_author_meta( 'last_name', $author_id );
253
+            $author_uri        = $this->user_service->get_uri( $author_id );
254
+
255
+            return array(
256
+                '@type'      => 'Person',
257
+                '@id'        => $author_uri,
258
+                'name'       => $author,
259
+                'givenName'  => $author_first_name,
260
+                'familyName' => $author_last_name,
261
+                'url'        => get_author_posts_url( $author_id ),
262
+            );
263
+        }
264
+
265
+        // Add the author to the references.
266
+        $author_uri   = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id );
267
+        $references[] = $entity_id;
268
+
269
+        // Return the JSON-LD for the referenced entity.
270
+        return array(
271
+            '@id' => $author_uri,
272
+        );
273
+    }
274
+
275
+    /**
276
+     * Enrich the provided params array with publisher data, if available.
277
+     *
278
+     * @param array $params The parameters array.
279
+     *
280
+     * @since 3.10.0
281
+     */
282
+    protected function set_publisher( &$params ) {
283
+
284
+        // If the publisher id isn't set don't do anything.
285
+        $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
286
+        if ( null === $publisher_id ) {
287
+            return;
288
+        }
289
+
290
+        // Get the post instance.
291
+        $post = get_post( $publisher_id );
292
+        if ( null === $post ) {
293
+            // Publisher not found.
294
+            return;
295
+        }
296
+
297
+        // Get the item id.
298
+        $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id );
299
+
300
+        // Get the type.
301
+        $type = $this->entity_type_service->get( $publisher_id );
302
+
303
+        // Get the name.
304
+        $name = $post->post_title;
305
+
306
+        // Set the publisher data.
307
+        $params['publisher'] = array(
308
+            '@type' => $this->relative_to_context( $type['uri'] ),
309
+            '@id'   => $id,
310
+            'name'  => $name,
311
+        );
312
+
313
+        // Add the sameAs values associated with the publisher.
314
+        $storage_factory = Wordlift_Storage_Factory::get_instance();
315
+        $sameas          = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id );
316
+        if ( ! empty( $sameas ) ) {
317
+            $params['publisher']['sameAs'] = $sameas;
318
+        }
319
+
320
+        // Set the logo, only for http://schema.org/Organization as Person doesn't
321
+        // support the logo property.
322
+        //
323
+        // See http://schema.org/logo.
324
+        if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) {
325
+            return;
326
+        }
327
+
328
+        // Get the publisher logo.
329
+        $publisher_logo = $this->get_publisher_logo( $post->ID );
330
+
331
+        // Bail out if the publisher logo isn't set.
332
+        if ( false === $publisher_logo ) {
333
+            return;
334
+        }
335
+
336
+        // Copy over some useful properties.
337
+        //
338
+        // See https://developers.google.com/search/docs/data-types/articles.
339
+        $params['publisher']['logo']['@type'] = 'ImageObject';
340
+        $params['publisher']['logo']['url']   = $publisher_logo['url'];
341
+
342
+        // If you specify a "width" or "height" value you should leave out
343
+        // 'px'. For example: "width":"4608px" should be "width":"4608".
344
+        //
345
+        // See https://github.com/insideout10/wordlift-plugin/issues/451.
346
+        $params['publisher']['logo']['width']  = $publisher_logo['width'];
347
+        $params['publisher']['logo']['height'] = $publisher_logo['height'];
348
+
349
+    }
350
+
351
+    /**
352
+     * Get the publisher logo structure.
353
+     *
354
+     * The function returns false when the publisher logo cannot be determined, i.e.:
355
+     *  - the post has no featured image.
356
+     *  - the featured image has no file.
357
+     *  - a wp_image_editor instance cannot be instantiated on the original file or on the publisher logo file.
358
+     *
359
+     * @param int $post_id The post id.
360
+     *
361
+     * @return array|false Returns an array with the `url`, `width` and `height` for the publisher logo or false in case
362
+     *  of errors.
363
+     * @since 3.19.2
364
+     * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue.
365
+     */
366
+    private function get_publisher_logo( $post_id ) {
367
+
368
+        // Get the featured image for the post.
369
+        $thumbnail_id = get_post_thumbnail_id( $post_id );
370
+
371
+        // Bail out if thumbnail not available.
372
+        if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) {
373
+            $this->log->info( "Featured image not set for post $post_id." );
374
+
375
+            return false;
376
+        }
377
+
378
+        // Get the uploads base URL.
379
+        $uploads_dir = wp_upload_dir();
380
+
381
+        // Get the attachment metadata.
382
+        $metadata = wp_get_attachment_metadata( $thumbnail_id );
383
+
384
+        // Bail out if the file isn't set.
385
+        if ( ! isset( $metadata['file'] ) ) {
386
+            $this->log->warn( "Featured image file not found for post $post_id." );
387
+
388
+            return false;
389
+        }
390
+
391
+        // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png"
392
+        $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
393
+
394
+        // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149
395
+        if ( ! file_exists( $path ) ) {
396
+            $this->log->warn( "Featured image file $path doesn't exist for post $post_id." );
397
+
398
+            $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' );
399
+            if ( $attachment_image_src ) {
400
+                return array(
401
+                    'url'    => $attachment_image_src[0],
402
+                    'width'  => $attachment_image_src[1],
403
+                    'height' => $attachment_image_src[2],
404
+                );
405
+            }
406
+
407
+            // Bail out if we cant fetch wp_get_attachment_image_src
408
+            return false;
409
+
410
+        }
411
+
412
+        // Try to get the image editor and bail out if the editor cannot be instantiated.
413
+        $original_file_editor = wp_get_image_editor( $path );
414
+        if ( is_wp_error( $original_file_editor ) ) {
415
+            $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." );
416
+
417
+            return false;
418
+        }
419
+
420
+        // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling
421
+        // and we don't actually know the end values.
422
+        $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' );
423
+
424
+        // If the file doesn't exist yet, create it.
425
+        if ( ! file_exists( $publisher_logo_path ) ) {
426
+            $original_file_editor->resize( 600, 60 );
427
+            $original_file_editor->save( $publisher_logo_path );
428
+        }
429
+
430
+        // Try to get the image editor and bail out if the editor cannot be instantiated.
431
+        $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path );
432
+        if ( is_wp_error( $publisher_logo_editor ) ) {
433
+            $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." );
434
+
435
+            return false;
436
+        }
437
+
438
+        // Get the actual size.
439
+        $size = $publisher_logo_editor->get_size();
440
+
441
+        // Finally return the array with data.
442
+        return array(
443
+            'url'    => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ),
444
+            'width'  => $size['width'],
445
+            'height' => $size['height'],
446
+        );
447
+    }
448
+
449
+    /**
450
+     * @param $references
451
+     * @param $post
452
+     * @param $jsonld
453
+     *
454
+     * @return void
455
+     */
456
+    private function set_mentions_and_about( $references, $post, &$jsonld ) {
457
+
458
+        if ( count( $references ) === 0 ) {
459
+            return;
460
+        }
461
+
462
+        // Prepare the `about` and `mentions` array.
463
+        $mentions = array();
464
+        $about    = array();
465
+
466
+        // If the entity is in the title, then it should be an `about`.
467
+        foreach ( $references as $reference ) {
468
+
469
+            if ( ! $reference instanceof Reference ) {
470
+                // This condition should never be reached.
471
+                continue;
472
+            }
473
+
474
+            // Get the entity labels.
475
+            $labels = Wordlift_Entity_Service::get_instance()->get_labels( $reference->get_id(), $reference->get_type() );
476
+            // Get the entity URI.
477
+            $item = array(
478
+                '@id' => Wordlift_Entity_Service::get_instance()->get_uri( $reference->get_id(), $reference->get_type() ),
479
+            );
480
+
481
+            $escaped_labels = array_map(
482
+                function ( $value ) {
483
+                    return preg_quote( $value, '/' );
484
+                },
485
+                $labels
486
+            );
487
+
488
+            $matches = false;
489
+
490
+            // When the title is empty, then we shouldn't yield a match to about section.
491
+            if ( array_filter( $escaped_labels ) ) {
492
+                // Check if the labels match any part of the title.
493
+                $matches = 1 === preg_match( '/' . implode( '|', $escaped_labels ) . '/', $post->post_title );
494
+            }
495
+
496
+            // If the title matches, assign the entity to the about, otherwise to the mentions.
497
+            if ( $matches ) {
498
+                $about[] = $item;
499
+            } else {
500
+                $mentions[] = $item;
501
+            }
502
+        }
503
+
504
+        // If we have abouts, assign them to the JSON-LD.
505
+        if ( 0 < count( $about ) ) {
506
+            $jsonld['about'] = $about;
507
+        }
508
+
509
+        // If we have mentions, assign them to the JSON-LD.
510
+        if ( 0 < count( $mentions ) ) {
511
+            $jsonld['mentions'] = $mentions;
512
+        }
513
+
514
+        return $jsonld;
515
+    }
516
+
517
+    /**
518
+     * Convert references to abstract data type if we find any.
519
+     *
520
+     * @param $references array<int|Reference>
521
+     *
522
+     * @return Reference[]
523
+     */
524
+    private function convert_references( $references ) {
525
+        return array_map(
526
+            function ( $reference ) {
527
+                // Legacy code may still push numerical references to this
528
+                // $references variable, so convert it to post references.
529
+                if ( is_numeric( $reference ) ) {
530
+                        return new Post_Reference( $reference );
531
+                }
532
+
533
+                return $reference;
534
+
535
+            },
536
+            $references
537
+        );
538
+    }
539 539
 
540 540
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @since 3.10.0
53 53
 	 */
54
-	public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) {
55
-		parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() );
54
+	public function __construct($entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false) {
55
+		parent::__construct($entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create());
56 56
 		$this->disable_convert_filters = $disable_convert_filters;
57 57
 		$this->object_relation_service = Object_Relation_Service::get_instance();
58 58
 		// Set a reference to the logger.
59
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' );
59
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Post_To_Jsonld_Converter');
60 60
 
61 61
 		self::$instance = $this;
62 62
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	}
69 69
 
70 70
 	public function new_instance_with_filters_disabled() {
71
-		return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true );
71
+		return new static($this->entity_type_service, $this->user_service, $this->attachment_service, true);
72 72
 	}
73 73
 
74 74
 	/**
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
 	 * @return array A JSON-LD array.
83 83
 	 * @since 3.10.0
84 84
 	 */
85
-	public function convert( $post_id, &$references = array(), &$references_infos = array() ) {
85
+	public function convert($post_id, &$references = array(), &$references_infos = array()) {
86 86
 
87 87
 		// Get the post instance.
88
-		$post = get_post( $post_id );
89
-		if ( null === $post ) {
88
+		$post = get_post($post_id);
89
+		if (null === $post) {
90 90
 			// Post not found.
91 91
 			return null;
92 92
 		}
93 93
 
94 94
 		// Get the base JSON-LD and the list of entities referenced by this entity.
95
-		$jsonld = parent::convert( $post_id, $references, $references_infos );
95
+		$jsonld = parent::convert($post_id, $references, $references_infos);
96 96
 
97 97
 		// Set WebPage by default.
98
-		if ( empty( $jsonld['@type'] ) ) {
98
+		if (empty($jsonld['@type'])) {
99 99
 			$jsonld['@type'] = 'WebPage';
100 100
 		}
101 101
 
102 102
 		// Get the entity name.
103 103
 		$jsonld['headline'] = $post->post_title;
104 104
 
105
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id );
105
+		$custom_fields = $this->entity_type_service->get_custom_fields_for_post($post_id);
106 106
 
107
-		if ( isset( $custom_fields ) ) {
108
-			$this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos );
107
+		if (isset($custom_fields)) {
108
+			$this->process_type_custom_fields($jsonld, $custom_fields, $post, $references, $references_infos);
109 109
 		}
110 110
 
111 111
 		// Set the published and modified dates.
@@ -118,19 +118,19 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 		try {
120 120
 			$default_timezone = date_default_timezone_get();
121
-			$timezone         = get_option( 'timezone_string' );
122
-			if ( ! empty( $timezone ) ) {
123
-				date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
124
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post );
125
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post );
126
-				date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
121
+			$timezone         = get_option('timezone_string');
122
+			if ( ! empty($timezone)) {
123
+				date_default_timezone_set($timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
124
+				$jsonld['datePublished'] = get_post_time('Y-m-d\TH:i:sP', false, $post);
125
+				$jsonld['dateModified']  = get_post_modified_time('Y-m-d\TH:i:sP', false, $post);
126
+				date_default_timezone_set($default_timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
127 127
 			} else {
128
-				$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
129
-				$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
128
+				$jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false);
129
+				$jsonld['dateModified']  = get_post_modified_time('Y-m-d\TH:i', true, $post, false);
130 130
 			}
131
-		} catch ( Exception $e ) {
132
-			$jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false );
133
-			$jsonld['dateModified']  = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false );
131
+		} catch (Exception $e) {
132
+			$jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false);
133
+			$jsonld['dateModified']  = get_post_modified_time('Y-m-d\TH:i', true, $post, false);
134 134
 		}
135 135
 
136 136
 		// Get the word count for the post.
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 		 *
142 142
 		 * @since 3.20.0
143 143
 		 */
144
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
145
-			$post_adapter        = new Wordlift_Post_Adapter( $post_id );
144
+		if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) {
145
+			$post_adapter        = new Wordlift_Post_Adapter($post_id);
146 146
 			$jsonld['wordCount'] = $post_adapter->word_count();
147 147
 		}
148 148
 
@@ -153,37 +153,37 @@  discard block
 block discarded – undo
153 153
 		 *
154 154
 		 * @since 3.27.2
155 155
 		 */
156
-		if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) {
157
-			$post_adapter    = new Wordlift_Post_Adapter( $post_id );
156
+		if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) {
157
+			$post_adapter    = new Wordlift_Post_Adapter($post_id);
158 158
 			$keywords        = $post_adapter->keywords();
159 159
 			$article_section = $post_adapter->article_section();
160 160
 			$comment_count   = $post_adapter->comment_count();
161 161
 			$locale          = $post_adapter->locale();
162 162
 
163
-			if ( isset( $keywords ) ) {
163
+			if (isset($keywords)) {
164 164
 				$jsonld['keywords'] = $keywords;
165 165
 			}
166
-			if ( ! empty( $article_section ) ) {
166
+			if ( ! empty($article_section)) {
167 167
 				$jsonld['articleSection'] = $article_section;
168 168
 			}
169 169
 			$jsonld['commentCount'] = $comment_count;
170 170
 			$jsonld['inLanguage']   = $locale;
171
-			$post_adapter->add_references( $post_id, $references );
171
+			$post_adapter->add_references($post_id, $references);
172 172
 		}
173 173
 
174 174
 		// Set the publisher.
175
-		$this->set_publisher( $jsonld );
175
+		$this->set_publisher($jsonld);
176 176
 
177
-		$references = $this->convert_references( $references );
177
+		$references = $this->convert_references($references);
178 178
 
179 179
 		// Process the references if any.
180
-		$this->set_mentions_and_about( $references, $post, $jsonld );
180
+		$this->set_mentions_and_about($references, $post, $jsonld);
181 181
 
182 182
 		// Finally set the author.
183
-		$jsonld['author'] = $this->get_author( $post->post_author, $references );
183
+		$jsonld['author'] = $this->get_author($post->post_author, $references);
184 184
 
185 185
 		// Return the JSON-LD if filters are disabled by the client.
186
-		if ( $this->disable_convert_filters ) {
186
+		if ($this->disable_convert_filters) {
187 187
 			return $jsonld;
188 188
 		}
189 189
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		 *
225 225
 		 * @api
226 226
 		 */
227
-		return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references );
227
+		return apply_filters('wl_post_jsonld', $jsonld, $post_id, $references);
228 228
 	}
229 229
 
230 230
 	/**
@@ -239,18 +239,18 @@  discard block
 block discarded – undo
239 239
 	 * @return string|array A JSON-LD structure.
240 240
 	 * @since 3.14.0
241 241
 	 */
242
-	public function get_author( $author_id, &$references ) {
242
+	public function get_author($author_id, &$references) {
243 243
 
244 244
 		// Get the entity bound to this user.
245
-		$entity_id = $this->user_service->get_entity( $author_id );
245
+		$entity_id = $this->user_service->get_entity($author_id);
246 246
 
247 247
 		// If there's no entity bound return a simple author structure.
248
-		if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) {
248
+		if (empty($entity_id) || 'publish' !== get_post_status($entity_id)) {
249 249
 
250
-			$author            = get_the_author_meta( 'display_name', $author_id );
251
-			$author_first_name = get_the_author_meta( 'first_name', $author_id );
252
-			$author_last_name  = get_the_author_meta( 'last_name', $author_id );
253
-			$author_uri        = $this->user_service->get_uri( $author_id );
250
+			$author            = get_the_author_meta('display_name', $author_id);
251
+			$author_first_name = get_the_author_meta('first_name', $author_id);
252
+			$author_last_name  = get_the_author_meta('last_name', $author_id);
253
+			$author_uri        = $this->user_service->get_uri($author_id);
254 254
 
255 255
 			return array(
256 256
 				'@type'      => 'Person',
@@ -258,12 +258,12 @@  discard block
 block discarded – undo
258 258
 				'name'       => $author,
259 259
 				'givenName'  => $author_first_name,
260 260
 				'familyName' => $author_last_name,
261
-				'url'        => get_author_posts_url( $author_id ),
261
+				'url'        => get_author_posts_url($author_id),
262 262
 			);
263 263
 		}
264 264
 
265 265
 		// Add the author to the references.
266
-		$author_uri   = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id );
266
+		$author_uri   = Wordlift_Entity_Service::get_instance()->get_uri($entity_id);
267 267
 		$references[] = $entity_id;
268 268
 
269 269
 		// Return the JSON-LD for the referenced entity.
@@ -279,41 +279,41 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @since 3.10.0
281 281
 	 */
282
-	protected function set_publisher( &$params ) {
282
+	protected function set_publisher(&$params) {
283 283
 
284 284
 		// If the publisher id isn't set don't do anything.
285 285
 		$publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id();
286
-		if ( null === $publisher_id ) {
286
+		if (null === $publisher_id) {
287 287
 			return;
288 288
 		}
289 289
 
290 290
 		// Get the post instance.
291
-		$post = get_post( $publisher_id );
292
-		if ( null === $post ) {
291
+		$post = get_post($publisher_id);
292
+		if (null === $post) {
293 293
 			// Publisher not found.
294 294
 			return;
295 295
 		}
296 296
 
297 297
 		// Get the item id.
298
-		$id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id );
298
+		$id = Wordlift_Entity_Service::get_instance()->get_uri($publisher_id);
299 299
 
300 300
 		// Get the type.
301
-		$type = $this->entity_type_service->get( $publisher_id );
301
+		$type = $this->entity_type_service->get($publisher_id);
302 302
 
303 303
 		// Get the name.
304 304
 		$name = $post->post_title;
305 305
 
306 306
 		// Set the publisher data.
307 307
 		$params['publisher'] = array(
308
-			'@type' => $this->relative_to_context( $type['uri'] ),
308
+			'@type' => $this->relative_to_context($type['uri']),
309 309
 			'@id'   => $id,
310 310
 			'name'  => $name,
311 311
 		);
312 312
 
313 313
 		// Add the sameAs values associated with the publisher.
314 314
 		$storage_factory = Wordlift_Storage_Factory::get_instance();
315
-		$sameas          = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id );
316
-		if ( ! empty( $sameas ) ) {
315
+		$sameas          = $storage_factory->post_meta(Wordlift_Schema_Service::FIELD_SAME_AS)->get($publisher_id);
316
+		if ( ! empty($sameas)) {
317 317
 			$params['publisher']['sameAs'] = $sameas;
318 318
 		}
319 319
 
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
 		// support the logo property.
322 322
 		//
323 323
 		// See http://schema.org/logo.
324
-		if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) {
324
+		if (1 !== preg_match('~Organization$~', $type['uri'])) {
325 325
 			return;
326 326
 		}
327 327
 
328 328
 		// Get the publisher logo.
329
-		$publisher_logo = $this->get_publisher_logo( $post->ID );
329
+		$publisher_logo = $this->get_publisher_logo($post->ID);
330 330
 
331 331
 		// Bail out if the publisher logo isn't set.
332
-		if ( false === $publisher_logo ) {
332
+		if (false === $publisher_logo) {
333 333
 			return;
334 334
 		}
335 335
 
@@ -363,14 +363,14 @@  discard block
 block discarded – undo
363 363
 	 * @since 3.19.2
364 364
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue.
365 365
 	 */
366
-	private function get_publisher_logo( $post_id ) {
366
+	private function get_publisher_logo($post_id) {
367 367
 
368 368
 		// Get the featured image for the post.
369
-		$thumbnail_id = get_post_thumbnail_id( $post_id );
369
+		$thumbnail_id = get_post_thumbnail_id($post_id);
370 370
 
371 371
 		// Bail out if thumbnail not available.
372
-		if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) {
373
-			$this->log->info( "Featured image not set for post $post_id." );
372
+		if (empty($thumbnail_id) || 0 === $thumbnail_id) {
373
+			$this->log->info("Featured image not set for post $post_id.");
374 374
 
375 375
 			return false;
376 376
 		}
@@ -379,24 +379,24 @@  discard block
 block discarded – undo
379 379
 		$uploads_dir = wp_upload_dir();
380 380
 
381 381
 		// Get the attachment metadata.
382
-		$metadata = wp_get_attachment_metadata( $thumbnail_id );
382
+		$metadata = wp_get_attachment_metadata($thumbnail_id);
383 383
 
384 384
 		// Bail out if the file isn't set.
385
-		if ( ! isset( $metadata['file'] ) ) {
386
-			$this->log->warn( "Featured image file not found for post $post_id." );
385
+		if ( ! isset($metadata['file'])) {
386
+			$this->log->warn("Featured image file not found for post $post_id.");
387 387
 
388 388
 			return false;
389 389
 		}
390 390
 
391 391
 		// Retrieve the relative filename, e.g. "2018/05/logo_publisher.png"
392
-		$path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file'];
392
+		$path = $uploads_dir['basedir'].DIRECTORY_SEPARATOR.$metadata['file'];
393 393
 
394 394
 		// Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149
395
-		if ( ! file_exists( $path ) ) {
396
-			$this->log->warn( "Featured image file $path doesn't exist for post $post_id." );
395
+		if ( ! file_exists($path)) {
396
+			$this->log->warn("Featured image file $path doesn't exist for post $post_id.");
397 397
 
398
-			$attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' );
399
-			if ( $attachment_image_src ) {
398
+			$attachment_image_src = wp_get_attachment_image_src($thumbnail_id, '');
399
+			if ($attachment_image_src) {
400 400
 				return array(
401 401
 					'url'    => $attachment_image_src[0],
402 402
 					'width'  => $attachment_image_src[1],
@@ -410,27 +410,27 @@  discard block
 block discarded – undo
410 410
 		}
411 411
 
412 412
 		// Try to get the image editor and bail out if the editor cannot be instantiated.
413
-		$original_file_editor = wp_get_image_editor( $path );
414
-		if ( is_wp_error( $original_file_editor ) ) {
415
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." );
413
+		$original_file_editor = wp_get_image_editor($path);
414
+		if (is_wp_error($original_file_editor)) {
415
+			$this->log->warn("Cannot instantiate WP Image Editor on file $path for post $post_id.");
416 416
 
417 417
 			return false;
418 418
 		}
419 419
 
420 420
 		// Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling
421 421
 		// and we don't actually know the end values.
422
-		$publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' );
422
+		$publisher_logo_path = $original_file_editor->generate_filename('-publisher-logo');
423 423
 
424 424
 		// If the file doesn't exist yet, create it.
425
-		if ( ! file_exists( $publisher_logo_path ) ) {
426
-			$original_file_editor->resize( 600, 60 );
427
-			$original_file_editor->save( $publisher_logo_path );
425
+		if ( ! file_exists($publisher_logo_path)) {
426
+			$original_file_editor->resize(600, 60);
427
+			$original_file_editor->save($publisher_logo_path);
428 428
 		}
429 429
 
430 430
 		// Try to get the image editor and bail out if the editor cannot be instantiated.
431
-		$publisher_logo_editor = wp_get_image_editor( $publisher_logo_path );
432
-		if ( is_wp_error( $publisher_logo_editor ) ) {
433
-			$this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." );
431
+		$publisher_logo_editor = wp_get_image_editor($publisher_logo_path);
432
+		if (is_wp_error($publisher_logo_editor)) {
433
+			$this->log->warn("Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id.");
434 434
 
435 435
 			return false;
436 436
 		}
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
 		// Finally return the array with data.
442 442
 		return array(
443
-			'url'    => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ),
443
+			'url'    => $uploads_dir['baseurl'].substr($publisher_logo_path, strlen($uploads_dir['basedir'])),
444 444
 			'width'  => $size['width'],
445 445
 			'height' => $size['height'],
446 446
 		);
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
 	 *
454 454
 	 * @return void
455 455
 	 */
456
-	private function set_mentions_and_about( $references, $post, &$jsonld ) {
456
+	private function set_mentions_and_about($references, $post, &$jsonld) {
457 457
 
458
-		if ( count( $references ) === 0 ) {
458
+		if (count($references) === 0) {
459 459
 			return;
460 460
 		}
461 461
 
@@ -464,23 +464,23 @@  discard block
 block discarded – undo
464 464
 		$about    = array();
465 465
 
466 466
 		// If the entity is in the title, then it should be an `about`.
467
-		foreach ( $references as $reference ) {
467
+		foreach ($references as $reference) {
468 468
 
469
-			if ( ! $reference instanceof Reference ) {
469
+			if ( ! $reference instanceof Reference) {
470 470
 				// This condition should never be reached.
471 471
 				continue;
472 472
 			}
473 473
 
474 474
 			// Get the entity labels.
475
-			$labels = Wordlift_Entity_Service::get_instance()->get_labels( $reference->get_id(), $reference->get_type() );
475
+			$labels = Wordlift_Entity_Service::get_instance()->get_labels($reference->get_id(), $reference->get_type());
476 476
 			// Get the entity URI.
477 477
 			$item = array(
478
-				'@id' => Wordlift_Entity_Service::get_instance()->get_uri( $reference->get_id(), $reference->get_type() ),
478
+				'@id' => Wordlift_Entity_Service::get_instance()->get_uri($reference->get_id(), $reference->get_type()),
479 479
 			);
480 480
 
481 481
 			$escaped_labels = array_map(
482
-				function ( $value ) {
483
-					return preg_quote( $value, '/' );
482
+				function($value) {
483
+					return preg_quote($value, '/');
484 484
 				},
485 485
 				$labels
486 486
 			);
@@ -488,13 +488,13 @@  discard block
 block discarded – undo
488 488
 			$matches = false;
489 489
 
490 490
 			// When the title is empty, then we shouldn't yield a match to about section.
491
-			if ( array_filter( $escaped_labels ) ) {
491
+			if (array_filter($escaped_labels)) {
492 492
 				// Check if the labels match any part of the title.
493
-				$matches = 1 === preg_match( '/' . implode( '|', $escaped_labels ) . '/', $post->post_title );
493
+				$matches = 1 === preg_match('/'.implode('|', $escaped_labels).'/', $post->post_title);
494 494
 			}
495 495
 
496 496
 			// If the title matches, assign the entity to the about, otherwise to the mentions.
497
-			if ( $matches ) {
497
+			if ($matches) {
498 498
 				$about[] = $item;
499 499
 			} else {
500 500
 				$mentions[] = $item;
@@ -502,12 +502,12 @@  discard block
 block discarded – undo
502 502
 		}
503 503
 
504 504
 		// If we have abouts, assign them to the JSON-LD.
505
-		if ( 0 < count( $about ) ) {
505
+		if (0 < count($about)) {
506 506
 			$jsonld['about'] = $about;
507 507
 		}
508 508
 
509 509
 		// If we have mentions, assign them to the JSON-LD.
510
-		if ( 0 < count( $mentions ) ) {
510
+		if (0 < count($mentions)) {
511 511
 			$jsonld['mentions'] = $mentions;
512 512
 		}
513 513
 
@@ -521,13 +521,13 @@  discard block
 block discarded – undo
521 521
 	 *
522 522
 	 * @return Reference[]
523 523
 	 */
524
-	private function convert_references( $references ) {
524
+	private function convert_references($references) {
525 525
 		return array_map(
526
-			function ( $reference ) {
526
+			function($reference) {
527 527
 				// Legacy code may still push numerical references to this
528 528
 				// $references variable, so convert it to post references.
529
-				if ( is_numeric( $reference ) ) {
530
-					  return new Post_Reference( $reference );
529
+				if (is_numeric($reference)) {
530
+					  return new Post_Reference($reference);
531 531
 				}
532 532
 
533 533
 				return $reference;
Please login to merge, or discard this patch.
src/includes/class-wordlift-debug-service.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -13,64 +13,64 @@
 block discarded – undo
13 13
  */
14 14
 class Wordlift_Debug_Service {
15 15
 
16
-	/**
17
-	 * The {@link Wordlift_Entity_Service} instance.
18
-	 *
19
-	 * @since  3.7.2
20
-	 * @access private
21
-	 * @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
22
-	 */
23
-	private $entity_service;
16
+    /**
17
+     * The {@link Wordlift_Entity_Service} instance.
18
+     *
19
+     * @since  3.7.2
20
+     * @access private
21
+     * @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
22
+     */
23
+    private $entity_service;
24 24
 
25
-	/**
26
-	 * A {@link Wordlift_Uri_Service} instance.
27
-	 *
28
-	 * @since  3.10.0
29
-	 * @access private
30
-	 * @var \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance.
31
-	 */
32
-	private $uri_service;
25
+    /**
26
+     * A {@link Wordlift_Uri_Service} instance.
27
+     *
28
+     * @since  3.10.0
29
+     * @access private
30
+     * @var \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance.
31
+     */
32
+    private $uri_service;
33 33
 
34
-	/**
35
-	 * Wordlift_Debug_Service constructor.
36
-	 *
37
-	 * @since 3.7.2
38
-	 *
39
-	 * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
40
-	 * @param \Wordlift_Uri_Service   $uri_service    A {@link Wordlift_Uri_Service} instance.
41
-	 */
42
-	public function __construct( $entity_service, $uri_service ) {
34
+    /**
35
+     * Wordlift_Debug_Service constructor.
36
+     *
37
+     * @since 3.7.2
38
+     *
39
+     * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
40
+     * @param \Wordlift_Uri_Service   $uri_service    A {@link Wordlift_Uri_Service} instance.
41
+     */
42
+    public function __construct( $entity_service, $uri_service ) {
43 43
 
44
-		$this->entity_service = $entity_service;
45
-		$this->uri_service    = $uri_service;
44
+        $this->entity_service = $entity_service;
45
+        $this->uri_service    = $uri_service;
46 46
 
47
-		add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) );
47
+        add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) );
48 48
 
49
-	}
49
+    }
50 50
 
51
-	public function dump_uri() {
51
+    public function dump_uri() {
52 52
 
53
-		if ( ! isset( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
54
-			wp_send_json_error( 'id not set' );
55
-		}
53
+        if ( ! isset( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
54
+            wp_send_json_error( 'id not set' );
55
+        }
56 56
 
57
-		$post_id = (int) $_GET['id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
57
+        $post_id = (int) $_GET['id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
58 58
 
59
-		$post = get_post( $post_id );
59
+        $post = get_post( $post_id );
60 60
 
61
-		$uri       = $this->entity_service->get_uri( $post_id );
62
-		$build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type );
61
+        $uri       = $this->entity_service->get_uri( $post_id );
62
+        $build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type );
63 63
 
64
-		wp_send_json_success(
65
-			array(
66
-				'uri'               => $uri,
67
-				'post_title'        => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ),
68
-				'post_title_ascii'  => mb_convert_encoding( $post->post_title, 'ASCII' ),
69
-				'build_uri'         => $build_uri,
70
-				'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ),
71
-			)
72
-		);
64
+        wp_send_json_success(
65
+            array(
66
+                'uri'               => $uri,
67
+                'post_title'        => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ),
68
+                'post_title_ascii'  => mb_convert_encoding( $post->post_title, 'ASCII' ),
69
+                'build_uri'         => $build_uri,
70
+                'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ),
71
+            )
72
+        );
73 73
 
74
-	}
74
+    }
75 75
 
76 76
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,35 +39,35 @@
 block discarded – undo
39 39
 	 * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
40 40
 	 * @param \Wordlift_Uri_Service   $uri_service    A {@link Wordlift_Uri_Service} instance.
41 41
 	 */
42
-	public function __construct( $entity_service, $uri_service ) {
42
+	public function __construct($entity_service, $uri_service) {
43 43
 
44 44
 		$this->entity_service = $entity_service;
45 45
 		$this->uri_service    = $uri_service;
46 46
 
47
-		add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) );
47
+		add_action('wp_ajax_wl_dump_uri', array($this, 'dump_uri'));
48 48
 
49 49
 	}
50 50
 
51 51
 	public function dump_uri() {
52 52
 
53
-		if ( ! isset( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
54
-			wp_send_json_error( 'id not set' );
53
+		if ( ! isset($_GET['id'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
54
+			wp_send_json_error('id not set');
55 55
 		}
56 56
 
57 57
 		$post_id = (int) $_GET['id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
58 58
 
59
-		$post = get_post( $post_id );
59
+		$post = get_post($post_id);
60 60
 
61
-		$uri       = $this->entity_service->get_uri( $post_id );
62
-		$build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type );
61
+		$uri       = $this->entity_service->get_uri($post_id);
62
+		$build_uri = $this->uri_service->build_uri($post->post_title, $post->post_type);
63 63
 
64 64
 		wp_send_json_success(
65 65
 			array(
66 66
 				'uri'               => $uri,
67
-				'post_title'        => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ),
68
-				'post_title_ascii'  => mb_convert_encoding( $post->post_title, 'ASCII' ),
67
+				'post_title'        => sprintf('%s (%s)', $post->post_title, mb_detect_encoding($post->post_title)),
68
+				'post_title_ascii'  => mb_convert_encoding($post->post_title, 'ASCII'),
69 69
 				'build_uri'         => $build_uri,
70
-				'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ),
70
+				'build_uri_convert' => mb_convert_encoding($build_uri, 'ASCII'),
71 71
 			)
72 72
 		);
73 73
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-property-factory.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -11,58 +11,58 @@
 block discarded – undo
11 11
  */
12 12
 class Wordlift_Property_Factory {
13 13
 
14
-	/**
15
-	 * The default {@link Wordlift_Property_Service}.
16
-	 *
17
-	 * @since 3.7.0
18
-	 * @access private
19
-	 * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}.
20
-	 */
21
-	private $default_property_service;
14
+    /**
15
+     * The default {@link Wordlift_Property_Service}.
16
+     *
17
+     * @since 3.7.0
18
+     * @access private
19
+     * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}.
20
+     */
21
+    private $default_property_service;
22 22
 
23
-	private $property_services = array();
23
+    private $property_services = array();
24 24
 
25
-	/**
26
-	 * Wordlift_Property_Factory constructor.
27
-	 *
28
-	 * @since 3.7.0
29
-	 *
30
-	 * @param \Wordlift_Property_Service $default_property_service
31
-	 */
32
-	public function __construct( $default_property_service ) {
25
+    /**
26
+     * Wordlift_Property_Factory constructor.
27
+     *
28
+     * @since 3.7.0
29
+     *
30
+     * @param \Wordlift_Property_Service $default_property_service
31
+     */
32
+    public function __construct( $default_property_service ) {
33 33
 
34
-		$this->default_property_service = $default_property_service;
34
+        $this->default_property_service = $default_property_service;
35 35
 
36
-	}
36
+    }
37 37
 
38
-	/**
39
-	 * Set the {@link Wordlift_Property_Service} which handles that meta key.
40
-	 *
41
-	 * @since 3.7.0
42
-	 *
43
-	 * @param string                     $meta_key WordPress' meta key.
44
-	 * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance.
45
-	 */
46
-	public function register( $meta_key, $property_service ) {
38
+    /**
39
+     * Set the {@link Wordlift_Property_Service} which handles that meta key.
40
+     *
41
+     * @since 3.7.0
42
+     *
43
+     * @param string                     $meta_key WordPress' meta key.
44
+     * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance.
45
+     */
46
+    public function register( $meta_key, $property_service ) {
47 47
 
48
-		$this->property_services[ $meta_key ] = $property_service;
48
+        $this->property_services[ $meta_key ] = $property_service;
49 49
 
50
-	}
50
+    }
51 51
 
52
-	/**
53
-	 * Get the {@link Wordlift_Property_Service} which handles the specified meta key.
54
-	 *
55
-	 * @since 3.7.0
56
-	 *
57
-	 * @param $meta_key
58
-	 *
59
-	 * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key.
60
-	 */
61
-	public function get( $meta_key ) {
52
+    /**
53
+     * Get the {@link Wordlift_Property_Service} which handles the specified meta key.
54
+     *
55
+     * @since 3.7.0
56
+     *
57
+     * @param $meta_key
58
+     *
59
+     * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key.
60
+     */
61
+    public function get( $meta_key ) {
62 62
 
63
-		$service = $this->property_services[ $meta_key ];
63
+        $service = $this->property_services[ $meta_key ];
64 64
 
65
-		return $service ? $service : $this->default_property_service;
66
-	}
65
+        return $service ? $service : $this->default_property_service;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param \Wordlift_Property_Service $default_property_service
31 31
 	 */
32
-	public function __construct( $default_property_service ) {
32
+	public function __construct($default_property_service) {
33 33
 
34 34
 		$this->default_property_service = $default_property_service;
35 35
 
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * @param string                     $meta_key WordPress' meta key.
44 44
 	 * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance.
45 45
 	 */
46
-	public function register( $meta_key, $property_service ) {
46
+	public function register($meta_key, $property_service) {
47 47
 
48
-		$this->property_services[ $meta_key ] = $property_service;
48
+		$this->property_services[$meta_key] = $property_service;
49 49
 
50 50
 	}
51 51
 
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key.
60 60
 	 */
61
-	public function get( $meta_key ) {
61
+	public function get($meta_key) {
62 62
 
63
-		$service = $this->property_services[ $meta_key ];
63
+		$service = $this->property_services[$meta_key];
64 64
 
65 65
 		return $service ? $service : $this->default_property_service;
66 66
 	}
Please login to merge, or discard this patch.
src/includes/linked-data/storage/class-wordlift-post-image-storage.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Image_Storage extends Wordlift_Storage {
20 20
 
21
-	/**
22
-	 * Get the property value.
23
-	 *
24
-	 * @param int $post_id The {@link WP_Post}'s id.
25
-	 *
26
-	 * @return array|string|null A single string, or an array of values or null
27
-	 *                           if the property isn't recognized.
28
-	 * @since 3.15.0
29
-	 */
30
-	public function get( $post_id ) {
31
-
32
-		// Prepare the return array.
33
-		$image_urls = array();
34
-
35
-		// If there is a featured image it has the priority.
36
-		$featured_image_id = get_post_thumbnail_id( $post_id );
37
-		if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) {
38
-			$image_url = wp_get_attachment_url( $featured_image_id );
39
-
40
-			$image_urls[] = $image_url;
41
-		}
42
-
43
-		$images = get_children(
44
-			array(
45
-				'post_parent'    => $post_id,
46
-				'post_type'      => 'attachment',
47
-				'post_mime_type' => 'image',
48
-			)
49
-		);
50
-
51
-		// Collect the URLs.
52
-		foreach ( $images as $attachment_id => $attachment ) {
53
-			$image_url = wp_get_attachment_url( $attachment_id );
54
-			// Ensure the URL isn't collected already.
55
-			if ( ! in_array( $image_url, $image_urls, true ) ) {
56
-				array_push( $image_urls, $image_url );
57
-			}
58
-		}
59
-
60
-		return $image_urls;
61
-	}
21
+    /**
22
+     * Get the property value.
23
+     *
24
+     * @param int $post_id The {@link WP_Post}'s id.
25
+     *
26
+     * @return array|string|null A single string, or an array of values or null
27
+     *                           if the property isn't recognized.
28
+     * @since 3.15.0
29
+     */
30
+    public function get( $post_id ) {
31
+
32
+        // Prepare the return array.
33
+        $image_urls = array();
34
+
35
+        // If there is a featured image it has the priority.
36
+        $featured_image_id = get_post_thumbnail_id( $post_id );
37
+        if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) {
38
+            $image_url = wp_get_attachment_url( $featured_image_id );
39
+
40
+            $image_urls[] = $image_url;
41
+        }
42
+
43
+        $images = get_children(
44
+            array(
45
+                'post_parent'    => $post_id,
46
+                'post_type'      => 'attachment',
47
+                'post_mime_type' => 'image',
48
+            )
49
+        );
50
+
51
+        // Collect the URLs.
52
+        foreach ( $images as $attachment_id => $attachment ) {
53
+            $image_url = wp_get_attachment_url( $attachment_id );
54
+            // Ensure the URL isn't collected already.
55
+            if ( ! in_array( $image_url, $image_urls, true ) ) {
56
+                array_push( $image_urls, $image_url );
57
+            }
58
+        }
59
+
60
+        return $image_urls;
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@  discard block
 block discarded – undo
27 27
 	 *                           if the property isn't recognized.
28 28
 	 * @since 3.15.0
29 29
 	 */
30
-	public function get( $post_id ) {
30
+	public function get($post_id) {
31 31
 
32 32
 		// Prepare the return array.
33 33
 		$image_urls = array();
34 34
 
35 35
 		// If there is a featured image it has the priority.
36
-		$featured_image_id = get_post_thumbnail_id( $post_id );
37
-		if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) {
38
-			$image_url = wp_get_attachment_url( $featured_image_id );
36
+		$featured_image_id = get_post_thumbnail_id($post_id);
37
+		if (is_numeric($featured_image_id) && 0 < $featured_image_id) {
38
+			$image_url = wp_get_attachment_url($featured_image_id);
39 39
 
40 40
 			$image_urls[] = $image_url;
41 41
 		}
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 		);
50 50
 
51 51
 		// Collect the URLs.
52
-		foreach ( $images as $attachment_id => $attachment ) {
53
-			$image_url = wp_get_attachment_url( $attachment_id );
52
+		foreach ($images as $attachment_id => $attachment) {
53
+			$image_url = wp_get_attachment_url($attachment_id);
54 54
 			// Ensure the URL isn't collected already.
55
-			if ( ! in_array( $image_url, $image_urls, true ) ) {
56
-				array_push( $image_urls, $image_url );
55
+			if ( ! in_array($image_url, $image_urls, true)) {
56
+				array_push($image_urls, $image_url);
57 57
 			}
58 58
 		}
59 59
 
Please login to merge, or discard this patch.
src/includes/linked-data/storage/class-wordlift-post-meta-uri-storage.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,53 +18,53 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Meta_Uri_Storage extends Wordlift_Post_Meta_Storage {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift_Entity_Service} instance.
23
-	 *
24
-	 * @since  3.15.0
25
-	 * @access private
26
-	 * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
27
-	 */
28
-	private $entity_service;
21
+    /**
22
+     * The {@link Wordlift_Entity_Service} instance.
23
+     *
24
+     * @since  3.15.0
25
+     * @access private
26
+     * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
27
+     */
28
+    private $entity_service;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Post_Meta_Uri_Storage} instance.
32
-	 *
33
-	 * @since 3.15.0
34
-	 *
35
-	 * @param string                   $meta_key       The meta key to read data from.
36
-	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
37
-	 */
38
-	public function __construct( $meta_key, $entity_service ) {
39
-		parent::__construct( $meta_key );
30
+    /**
31
+     * Create a {@link Wordlift_Post_Meta_Uri_Storage} instance.
32
+     *
33
+     * @since 3.15.0
34
+     *
35
+     * @param string                   $meta_key       The meta key to read data from.
36
+     * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
37
+     */
38
+    public function __construct( $meta_key, $entity_service ) {
39
+        parent::__construct( $meta_key );
40 40
 
41
-		$this->entity_service = $entity_service;
41
+        $this->entity_service = $entity_service;
42 42
 
43
-	}
43
+    }
44 44
 
45
-	/**
46
-	 * Get the value for the specified meta key.
47
-	 *
48
-	 * The value is expected to be an entity post, for which the URI is loaded
49
-	 * and returned.
50
-	 *
51
-	 * @since 3.15.0
52
-	 *
53
-	 * @param int $post_id The {@link WP_Post}'s id.
54
-	 *
55
-	 * @return array An array of URIs (or an empty array if nothing is set).
56
-	 */
57
-	public function get( $post_id ) {
58
-		$values = parent::get( $post_id );
45
+    /**
46
+     * Get the value for the specified meta key.
47
+     *
48
+     * The value is expected to be an entity post, for which the URI is loaded
49
+     * and returned.
50
+     *
51
+     * @since 3.15.0
52
+     *
53
+     * @param int $post_id The {@link WP_Post}'s id.
54
+     *
55
+     * @return array An array of URIs (or an empty array if nothing is set).
56
+     */
57
+    public function get( $post_id ) {
58
+        $values = parent::get( $post_id );
59 59
 
60
-		$entity_service = $this->entity_service;
60
+        $entity_service = $this->entity_service;
61 61
 
62
-		return array_map(
63
-			function ( $item ) use ( $entity_service ) {
64
-				return $entity_service->get_uri( $item );
65
-			},
66
-			$values
67
-		);
68
-	}
62
+        return array_map(
63
+            function ( $item ) use ( $entity_service ) {
64
+                return $entity_service->get_uri( $item );
65
+            },
66
+            $values
67
+        );
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 	 * @param string                   $meta_key       The meta key to read data from.
36 36
 	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
37 37
 	 */
38
-	public function __construct( $meta_key, $entity_service ) {
39
-		parent::__construct( $meta_key );
38
+	public function __construct($meta_key, $entity_service) {
39
+		parent::__construct($meta_key);
40 40
 
41 41
 		$this->entity_service = $entity_service;
42 42
 
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return array An array of URIs (or an empty array if nothing is set).
56 56
 	 */
57
-	public function get( $post_id ) {
58
-		$values = parent::get( $post_id );
57
+	public function get($post_id) {
58
+		$values = parent::get($post_id);
59 59
 
60 60
 		$entity_service = $this->entity_service;
61 61
 
62 62
 		return array_map(
63
-			function ( $item ) use ( $entity_service ) {
64
-				return $entity_service->get_uri( $item );
63
+			function($item) use ($entity_service) {
64
+				return $entity_service->get_uri($item);
65 65
 			},
66 66
 			$values
67 67
 		);
Please login to merge, or discard this patch.
src/includes/linked-data/storage/class-wordlift-post-taxonomy-storage.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -18,52 +18,52 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Taxonomy_Storage extends Wordlift_Storage {
20 20
 
21
-	/**
22
-	 * The taxonomy name.
23
-	 *
24
-	 * @since  3.15.0
25
-	 * @access private
26
-	 * @var string $taxonomy The taxonomy name.
27
-	 */
28
-	private $taxonomy;
21
+    /**
22
+     * The taxonomy name.
23
+     *
24
+     * @since  3.15.0
25
+     * @access private
26
+     * @var string $taxonomy The taxonomy name.
27
+     */
28
+    private $taxonomy;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified
32
-	 * taxonomy name.
33
-	 *
34
-	 * @since 3.15.0
35
-	 *
36
-	 * @param string $taxonomy The taxonomy name.
37
-	 */
38
-	public function __construct( $taxonomy ) {
30
+    /**
31
+     * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified
32
+     * taxonomy name.
33
+     *
34
+     * @since 3.15.0
35
+     *
36
+     * @param string $taxonomy The taxonomy name.
37
+     */
38
+    public function __construct( $taxonomy ) {
39 39
 
40
-		$this->taxonomy = $taxonomy;
41
-	}
40
+        $this->taxonomy = $taxonomy;
41
+    }
42 42
 
43
-	/**
44
-	 * Get the taxonomy's terms associated with the specified {@link WP_Post}.
45
-	 *
46
-	 * @since 3.15.0
47
-	 *
48
-	 * @param int $post_id The {@link WP_Post}'s id.
49
-	 *
50
-	 * @return array|WP_Error An array of terms or {@link WP_Error} in case of error.
51
-	 */
52
-	public function get( $post_id ) {
43
+    /**
44
+     * Get the taxonomy's terms associated with the specified {@link WP_Post}.
45
+     *
46
+     * @since 3.15.0
47
+     *
48
+     * @param int $post_id The {@link WP_Post}'s id.
49
+     *
50
+     * @return array|WP_Error An array of terms or {@link WP_Error} in case of error.
51
+     */
52
+    public function get( $post_id ) {
53 53
 
54
-		return wp_get_post_terms(
55
-			$post_id,
56
-			$this->taxonomy,
57
-			array(
58
-				'hide_empty' => false,
59
-				// Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'.
60
-				// An issue has been opened with the AAM plugin author as well.
61
-				//
62
-				// see https://github.com/insideout10/wordlift-plugin/issues/334
63
-				// see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863
64
-				'fields'     => 'all',
65
-			)
66
-		);
67
-	}
54
+        return wp_get_post_terms(
55
+            $post_id,
56
+            $this->taxonomy,
57
+            array(
58
+                'hide_empty' => false,
59
+                // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'.
60
+                // An issue has been opened with the AAM plugin author as well.
61
+                //
62
+                // see https://github.com/insideout10/wordlift-plugin/issues/334
63
+                // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863
64
+                'fields'     => 'all',
65
+            )
66
+        );
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param string $taxonomy The taxonomy name.
37 37
 	 */
38
-	public function __construct( $taxonomy ) {
38
+	public function __construct($taxonomy) {
39 39
 
40 40
 		$this->taxonomy = $taxonomy;
41 41
 	}
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @return array|WP_Error An array of terms or {@link WP_Error} in case of error.
51 51
 	 */
52
-	public function get( $post_id ) {
52
+	public function get($post_id) {
53 53
 
54 54
 		return wp_get_post_terms(
55 55
 			$post_id,
Please login to merge, or discard this patch.
includes/linked-data/storage/class-wordlift-post-schema-class-storage.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -18,37 +18,37 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Schema_Class_Storage extends Wordlift_Storage {
20 20
 
21
-	/**
22
-	 * Get the schema class for the specified {@link WP_Post}.
23
-	 *
24
-	 * @since 3.15.0
25
-	 *
26
-	 * @param int $post_id The {@link WP_Post}'s id.
27
-	 *
28
-	 * @return string|array An array of schema classes.
29
-	 */
30
-	public function get( $post_id ) {
31
-
32
-		// Get the type names (CamelCase).
33
-		$names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id );
34
-
35
-		// If we don't find any type use the legacy function to get the URI.
36
-		if ( empty( $names ) ) {
37
-			$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
38
-
39
-			return $type['uri'];
40
-		}
41
-
42
-		// Prepend the `schema.org` base URI.
43
-		$uris = array_map(
44
-			function ( $item ) {
45
-				return "http://schema.org/$item";
46
-			},
47
-			$names
48
-		);
49
-
50
-		// Finally return the schema uri.
51
-		return 1 === count( $uris ) ? $uris[0] : $uris;
52
-	}
21
+    /**
22
+     * Get the schema class for the specified {@link WP_Post}.
23
+     *
24
+     * @since 3.15.0
25
+     *
26
+     * @param int $post_id The {@link WP_Post}'s id.
27
+     *
28
+     * @return string|array An array of schema classes.
29
+     */
30
+    public function get( $post_id ) {
31
+
32
+        // Get the type names (CamelCase).
33
+        $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id );
34
+
35
+        // If we don't find any type use the legacy function to get the URI.
36
+        if ( empty( $names ) ) {
37
+            $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
38
+
39
+            return $type['uri'];
40
+        }
41
+
42
+        // Prepend the `schema.org` base URI.
43
+        $uris = array_map(
44
+            function ( $item ) {
45
+                return "http://schema.org/$item";
46
+            },
47
+            $names
48
+        );
49
+
50
+        // Finally return the schema uri.
51
+        return 1 === count( $uris ) ? $uris[0] : $uris;
52
+    }
53 53
 
54 54
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,28 +27,28 @@
 block discarded – undo
27 27
 	 *
28 28
 	 * @return string|array An array of schema classes.
29 29
 	 */
30
-	public function get( $post_id ) {
30
+	public function get($post_id) {
31 31
 
32 32
 		// Get the type names (CamelCase).
33
-		$names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id );
33
+		$names = Wordlift_Entity_Type_Service::get_instance()->get_names($post_id);
34 34
 
35 35
 		// If we don't find any type use the legacy function to get the URI.
36
-		if ( empty( $names ) ) {
37
-			$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
36
+		if (empty($names)) {
37
+			$type = Wordlift_Entity_Type_Service::get_instance()->get($post_id);
38 38
 
39 39
 			return $type['uri'];
40 40
 		}
41 41
 
42 42
 		// Prepend the `schema.org` base URI.
43 43
 		$uris = array_map(
44
-			function ( $item ) {
44
+			function($item) {
45 45
 				return "http://schema.org/$item";
46 46
 			},
47 47
 			$names
48 48
 		);
49 49
 
50 50
 		// Finally return the schema uri.
51
-		return 1 === count( $uris ) ? $uris[0] : $uris;
51
+		return 1 === count($uris) ? $uris[0] : $uris;
52 52
 	}
53 53
 
54 54
 }
Please login to merge, or discard this patch.
src/includes/linked-data/storage/class-wordlift-post-related-storage.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -21,56 +21,56 @@
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Post_Related_Storage extends Wordlift_Storage {
23 23
 
24
-	/**
25
-	 * The {@link Wordlift_Entity_Service} instance.
26
-	 *
27
-	 * @since  3.15.0
28
-	 * @access private
29
-	 * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
30
-	 */
31
-	private $entity_service;
24
+    /**
25
+     * The {@link Wordlift_Entity_Service} instance.
26
+     *
27
+     * @since  3.15.0
28
+     * @access private
29
+     * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
30
+     */
31
+    private $entity_service;
32 32
 
33
-	/**
34
-	 * Create a {@link Wordlift_Post_Related_Storage} instance.
35
-	 *
36
-	 * @since 3.15.0
37
-	 *
38
-	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
39
-	 */
40
-	public function __construct( $entity_service ) {
33
+    /**
34
+     * Create a {@link Wordlift_Post_Related_Storage} instance.
35
+     *
36
+     * @since 3.15.0
37
+     *
38
+     * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
39
+     */
40
+    public function __construct( $entity_service ) {
41 41
 
42
-		$this->entity_service = $entity_service;
42
+        $this->entity_service = $entity_service;
43 43
 
44
-	}
44
+    }
45 45
 
46
-	/**
47
-	 * Get the property value.
48
-	 *
49
-	 * There is no filter for entities or posts, the returned data here can
50
-	 * be used for `relations` and `references` according to the client.
51
-	 *
52
-	 * @since 3.15.0
53
-	 *
54
-	 * @param int $post_id The {@link WP_Post}'s id.
55
-	 *
56
-	 * @return array|string|null A single string, or an array of values or null
57
-	 *                           if the property isn't recognized.
58
-	 */
59
-	public function get( $post_id ) {
46
+    /**
47
+     * Get the property value.
48
+     *
49
+     * There is no filter for entities or posts, the returned data here can
50
+     * be used for `relations` and `references` according to the client.
51
+     *
52
+     * @since 3.15.0
53
+     *
54
+     * @param int $post_id The {@link WP_Post}'s id.
55
+     *
56
+     * @return array|string|null A single string, or an array of values or null
57
+     *                           if the property isn't recognized.
58
+     */
59
+    public function get( $post_id ) {
60 60
 
61
-		// get related entities.
62
-		$related = wl_core_get_related_entity_ids( $post_id );
61
+        // get related entities.
62
+        $related = wl_core_get_related_entity_ids( $post_id );
63 63
 
64
-		// A reference to the entity service.
65
-		$entity_service = $this->entity_service;
64
+        // A reference to the entity service.
65
+        $entity_service = $this->entity_service;
66 66
 
67
-		// Map the related posts' ids to URIs.
68
-		return array_map(
69
-			function ( $item ) use ( $entity_service ) {
70
-				return $entity_service->get_uri( $item );
71
-			},
72
-			$related
73
-		);
74
-	}
67
+        // Map the related posts' ids to URIs.
68
+        return array_map(
69
+            function ( $item ) use ( $entity_service ) {
70
+                return $entity_service->get_uri( $item );
71
+            },
72
+            $related
73
+        );
74
+    }
75 75
 
76 76
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
39 39
 	 */
40
-	public function __construct( $entity_service ) {
40
+	public function __construct($entity_service) {
41 41
 
42 42
 		$this->entity_service = $entity_service;
43 43
 
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
 	 * @return array|string|null A single string, or an array of values or null
57 57
 	 *                           if the property isn't recognized.
58 58
 	 */
59
-	public function get( $post_id ) {
59
+	public function get($post_id) {
60 60
 
61 61
 		// get related entities.
62
-		$related = wl_core_get_related_entity_ids( $post_id );
62
+		$related = wl_core_get_related_entity_ids($post_id);
63 63
 
64 64
 		// A reference to the entity service.
65 65
 		$entity_service = $this->entity_service;
66 66
 
67 67
 		// Map the related posts' ids to URIs.
68 68
 		return array_map(
69
-			function ( $item ) use ( $entity_service ) {
70
-				return $entity_service->get_uri( $item );
69
+			function($item) use ($entity_service) {
70
+				return $entity_service->get_uri($item);
71 71
 			},
72 72
 			$related
73 73
 		);
Please login to merge, or discard this patch.
src/includes/class-wordlift-tinymce-adapter.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -14,77 +14,77 @@
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Tinymce_Adapter {
16 16
 
17
-	/**
18
-	 * The {@link Wordlift} plugin instance.
19
-	 *
20
-	 * @since  3.12.0
21
-	 * @access private
22
-	 * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
23
-	 */
24
-	private $plugin;
17
+    /**
18
+     * The {@link Wordlift} plugin instance.
19
+     *
20
+     * @since  3.12.0
21
+     * @access private
22
+     * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
23
+     */
24
+    private $plugin;
25 25
 
26
-	/**
27
-	 * Wordlift_Tinymce_Adapter constructor.
28
-	 *
29
-	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
30
-	 */
31
-	public function __construct( $plugin ) {
26
+    /**
27
+     * Wordlift_Tinymce_Adapter constructor.
28
+     *
29
+     * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
30
+     */
31
+    public function __construct( $plugin ) {
32 32
 
33
-		$this->plugin = $plugin;
33
+        $this->plugin = $plugin;
34 34
 
35
-	}
35
+    }
36 36
 
37
-	/**
38
-	 * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook.
39
-	 *
40
-	 * @param array $plugins The existing plugins array.
41
-	 *
42
-	 * @return array The modified plugins array.
43
-	 * @since 3.12.0
44
-	 */
45
-	public function mce_external_plugins( $plugins ) {
37
+    /**
38
+     * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook.
39
+     *
40
+     * @param array $plugins The existing plugins array.
41
+     *
42
+     * @return array The modified plugins array.
43
+     * @since 3.12.0
44
+     */
45
+    public function mce_external_plugins( $plugins ) {
46 46
 
47
-		/**
48
-		 * Bail out if you are on Media Library
49
-		 *
50
-		 * @since 3.27.1
51
-		 *
52
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/1122
53
-		 */
54
-		if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) {
55
-			return $plugins;
56
-		}
47
+        /**
48
+         * Bail out if you are on Media Library
49
+         *
50
+         * @since 3.27.1
51
+         *
52
+         * @see https://github.com/insideout10/wordlift-plugin/issues/1122
53
+         */
54
+        if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) {
55
+            return $plugins;
56
+        }
57 57
 
58
-		/*
58
+        /*
59 59
 		 * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box.
60 60
 		 *
61 61
 		 * @since 3.20.3
62 62
 		 *
63 63
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/914
64 64
 		 */
65
-		if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) {
66
-			return $plugins;
67
-		}
65
+        if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) {
66
+            return $plugins;
67
+        }
68 68
 
69
-		// Get WordLift's version as a cache killer.
70
-		$version = $this->plugin->get_version();
69
+        // Get WordLift's version as a cache killer.
70
+        $version = $this->plugin->get_version();
71 71
 
72
-		// User can edit?
73
-		$can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
72
+        // User can edit?
73
+        $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
74 74
 
75
-		// If user can't edit or rich editing isn't enabled, bail out.
76
-		if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) {
77
-			return $plugins;
78
-		}
75
+        // If user can't edit or rich editing isn't enabled, bail out.
76
+        if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) {
77
+            return $plugins;
78
+        }
79 79
 
80
-		// Add our own JavaScript file to TinyMCE's extensions.
81
-		// DO NOT use the minified version, it'll yield errors with AngularJS.
82
-		$plugins['wordlift']      = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version;
83
-		$plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version;
84
-		$plugins['wl_tinymce']    = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version;
85
-		$plugins['wl_tinymce_2']  = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version;
80
+        // Add our own JavaScript file to TinyMCE's extensions.
81
+        // DO NOT use the minified version, it'll yield errors with AngularJS.
82
+        $plugins['wordlift']      = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version;
83
+        $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version;
84
+        $plugins['wl_tinymce']    = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version;
85
+        $plugins['wl_tinymce_2']  = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version;
86 86
 
87
-		return $plugins;
88
-	}
87
+        return $plugins;
88
+    }
89 89
 
90 90
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
30 30
 	 */
31
-	public function __construct( $plugin ) {
31
+	public function __construct($plugin) {
32 32
 
33 33
 		$this->plugin = $plugin;
34 34
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @return array The modified plugins array.
43 43
 	 * @since 3.12.0
44 44
 	 */
45
-	public function mce_external_plugins( $plugins ) {
45
+	public function mce_external_plugins($plugins) {
46 46
 
47 47
 		/**
48 48
 		 * Bail out if you are on Media Library
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		 *
52 52
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/1122
53 53
 		 */
54
-		if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) {
54
+		if (isset(get_current_screen()->base) && get_current_screen()->base === 'upload') {
55 55
 			return $plugins;
56 56
 		}
57 57
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		 *
63 63
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/914
64 64
 		 */
65
-		if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) {
65
+		if ( ! apply_filters('wl_can_see_classification_box', true)) {
66 66
 			return $plugins;
67 67
 		}
68 68
 
@@ -70,19 +70,19 @@  discard block
 block discarded – undo
70 70
 		$version = $this->plugin->get_version();
71 71
 
72 72
 		// User can edit?
73
-		$can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
73
+		$can_edit = current_user_can('edit_posts') || current_user_can('edit_pages');
74 74
 
75 75
 		// If user can't edit or rich editing isn't enabled, bail out.
76
-		if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) {
76
+		if ( ! $can_edit || ! get_user_option('rich_editing')) {
77 77
 			return $plugins;
78 78
 		}
79 79
 
80 80
 		// Add our own JavaScript file to TinyMCE's extensions.
81 81
 		// DO NOT use the minified version, it'll yield errors with AngularJS.
82
-		$plugins['wordlift']      = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version;
83
-		$plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version;
84
-		$plugins['wl_tinymce']    = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version;
85
-		$plugins['wl_tinymce_2']  = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version;
82
+		$plugins['wordlift']      = plugin_dir_url(__DIR__).'js/wordlift-reloaded.js?ver='.$version;
83
+		$plugins['wl_shortcodes'] = plugin_dir_url(__DIR__).'admin/js/wordlift_shortcode_tinymce_plugin.js?ver='.$version;
84
+		$plugins['wl_tinymce']    = plugin_dir_url(__DIR__).'admin/js/1/tinymce.js?ver='.$version;
85
+		$plugins['wl_tinymce_2']  = plugin_dir_url(__DIR__).'js/dist/tiny-mce.js?ver='.$version;
86 86
 
87 87
 		return $plugins;
88 88
 	}
Please login to merge, or discard this patch.