Completed
Pull Request — develop (#1633)
by Naveen
01:05
created
src/wordlift/videoobject/background-process/class-videos-data-source.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -6,74 +6,74 @@
 block discarded – undo
6 6
 
7 7
 class Videos_Data_Source extends Data_Source {
8 8
 
9
-	/**
10
-	 * @var \Wordlift_Log_Service
11
-	 */
12
-	private $log;
9
+    /**
10
+     * @var \Wordlift_Log_Service
11
+     */
12
+    private $log;
13 13
 
14
-	public function __construct( $state_storage_key ) {
15
-		parent::__construct( $state_storage_key );
16
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
17
-	}
14
+    public function __construct( $state_storage_key ) {
15
+        parent::__construct( $state_storage_key );
16
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
17
+    }
18 18
 
19
-	public function next() {
20
-		$this->log->debug( 'Received video data source index as ' . $this->get_state()->index );
21
-		$this->log->debug( 'Count set to ' . $this->get_batch_size() );
19
+    public function next() {
20
+        $this->log->debug( 'Received video data source index as ' . $this->get_state()->index );
21
+        $this->log->debug( 'Count set to ' . $this->get_batch_size() );
22 22
 
23
-		return get_posts(
24
-			array(
25
-				'fields'      => 'ids',
26
-				'post_status' => 'any',
27
-				'numberposts' => $this->get_batch_size(),
28
-				'offset'      => $this->get_state()->index,
29
-				/**
30
-				* @return array<string> An array of supported post types for the video import procedure.
31
-				* @since 3.31.4
32
-				* Filter name : wl_videoobject_procedure_post_types
33
-				*/
34
-			'post_type'       => array_unique(
35
-				apply_filters(
36
-					'wl_videoobject_procedure_post_types',
37
-					array(
38
-						'post',
39
-						'page',
40
-					)
41
-				)
42
-			),
43
-			)
44
-		);
45
-	}
23
+        return get_posts(
24
+            array(
25
+                'fields'      => 'ids',
26
+                'post_status' => 'any',
27
+                'numberposts' => $this->get_batch_size(),
28
+                'offset'      => $this->get_state()->index,
29
+                /**
30
+                 * @return array<string> An array of supported post types for the video import procedure.
31
+                 * @since 3.31.4
32
+                 * Filter name : wl_videoobject_procedure_post_types
33
+                 */
34
+            'post_type'       => array_unique(
35
+                apply_filters(
36
+                    'wl_videoobject_procedure_post_types',
37
+                    array(
38
+                        'post',
39
+                        'page',
40
+                    )
41
+                )
42
+            ),
43
+            )
44
+        );
45
+    }
46 46
 
47
-	public function count() {
48
-		return count(
49
-			get_posts(
50
-				array(
51
-					'fields'      => 'ids',
52
-					'numberposts' => - 1,
53
-					'post_status' => 'any',
54
-					/**
55
-					* @return array<string> An array of supported post types for the video import procedure.
56
-					* @since 3.31.4
57
-					* Filter name : wl_videoobject_procedure_post_types
58
-					*/
59
-					'post_type'   => array_unique(
60
-						apply_filters(
61
-							'wl_videoobject_procedure_post_types',
62
-							array(
63
-								'post',
64
-								'page',
65
-							)
66
-						)
67
-					),
68
-				)
69
-			)
70
-		);
47
+    public function count() {
48
+        return count(
49
+            get_posts(
50
+                array(
51
+                    'fields'      => 'ids',
52
+                    'numberposts' => - 1,
53
+                    'post_status' => 'any',
54
+                    /**
55
+                     * @return array<string> An array of supported post types for the video import procedure.
56
+                     * @since 3.31.4
57
+                     * Filter name : wl_videoobject_procedure_post_types
58
+                     */
59
+                    'post_type'   => array_unique(
60
+                        apply_filters(
61
+                            'wl_videoobject_procedure_post_types',
62
+                            array(
63
+                                'post',
64
+                                'page',
65
+                            )
66
+                        )
67
+                    ),
68
+                )
69
+            )
70
+        );
71 71
 
72
-	}
72
+    }
73 73
 
74
-	public function get_batch_size() {
75
-		// For now use only 5 in order to prevent exceeding api limit.
76
-		return 5;
77
-	}
74
+    public function get_batch_size() {
75
+        // For now use only 5 in order to prevent exceeding api limit.
76
+        return 5;
77
+    }
78 78
 
79 79
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 	 */
12 12
 	private $log;
13 13
 
14
-	public function __construct( $state_storage_key ) {
15
-		parent::__construct( $state_storage_key );
16
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
14
+	public function __construct($state_storage_key) {
15
+		parent::__construct($state_storage_key);
16
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
17 17
 	}
18 18
 
19 19
 	public function next() {
20
-		$this->log->debug( 'Received video data source index as ' . $this->get_state()->index );
21
-		$this->log->debug( 'Count set to ' . $this->get_batch_size() );
20
+		$this->log->debug('Received video data source index as '.$this->get_state()->index);
21
+		$this->log->debug('Count set to '.$this->get_batch_size());
22 22
 
23 23
 		return get_posts(
24 24
 			array(
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			get_posts(
50 50
 				array(
51 51
 					'fields'      => 'ids',
52
-					'numberposts' => - 1,
52
+					'numberposts' => -1,
53 53
 					'post_status' => 'any',
54 54
 					/**
55 55
 					* @return array<string> An array of supported post types for the video import procedure.
Please login to merge, or discard this patch.
src/wordlift/videoobject/filters/class-post-filter.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,32 +10,32 @@
 block discarded – undo
10 10
  */
11 11
 class Post_Filter {
12 12
 
13
-	/**
14
-	 * @var Video_Processor
15
-	 */
16
-	private $video_processor;
13
+    /**
14
+     * @var Video_Processor
15
+     */
16
+    private $video_processor;
17 17
 
18
-	public function __construct( $video_processor ) {
19
-		$this->video_processor = $video_processor;
20
-	}
18
+    public function __construct( $video_processor ) {
19
+        $this->video_processor = $video_processor;
20
+    }
21 21
 
22
-	public function init() {
23
-		add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
24
-	}
22
+    public function init() {
23
+        add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
24
+    }
25 25
 
26
-	/**
27
-	 * @param $post_id int
28
-	 * @param $post \WP_Post
29
-	 * @param $update bool
30
-	 */
31
-	public function save_post( $post_id, $post ) {
26
+    /**
27
+     * @param $post_id int
28
+     * @param $post \WP_Post
29
+     * @param $update bool
30
+     */
31
+    public function save_post( $post_id, $post ) {
32 32
 
33
-		if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
34
-			return;
35
-		}
33
+        if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
34
+            return;
35
+        }
36 36
 
37
-		$this->video_processor->process_video_urls( $post, $post_id );
37
+        $this->video_processor->process_video_urls( $post, $post_id );
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	private $video_processor;
17 17
 
18
-	public function __construct( $video_processor ) {
18
+	public function __construct($video_processor) {
19 19
 		$this->video_processor = $video_processor;
20 20
 	}
21 21
 
22 22
 	public function init() {
23
-		add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
23
+		add_action('save_post', array($this, 'save_post'), 10, 2);
24 24
 	}
25 25
 
26 26
 	/**
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 	 * @param $post \WP_Post
29 29
 	 * @param $update bool
30 30
 	 */
31
-	public function save_post( $post_id, $post ) {
31
+	public function save_post($post_id, $post) {
32 32
 
33
-		if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
33
+		if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
34 34
 			return;
35 35
 		}
36 36
 
37
-		$this->video_processor->process_video_urls( $post, $post_id );
37
+		$this->video_processor->process_video_urls($post, $post_id);
38 38
 
39 39
 	}
40 40
 
Please login to merge, or discard this patch.
src/wordlift/videoobject/filters/class-embed-shortcode-capture.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -13,43 +13,43 @@
 block discarded – undo
13 13
 
14 14
 class Embed_Shortcode_Capture {
15 15
 
16
-	public function init() {
17
-		add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
18
-	}
19
-
20
-	public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
21
-
22
-		$post         = get_post( $post_id );
23
-		$post_content = $post->post_content;
24
-		$embed_regex  = get_shortcode_regex( array( 'embed' ) );
25
-
26
-		$matches = array();
27
-
28
-		preg_match_all( '/' . $embed_regex . '/', $post_content, $matches, PREG_SET_ORDER );
29
-
30
-		// The url is returned in index 5
31
-		$embed_shortcode_urls = array_filter(
32
-			array_map(
33
-				function ( $item ) {
34
-					if ( isset( $item[5] ) && is_string( $item[5] ) && $item[5] ) {
35
-						  return $item[5];
36
-					}
37
-					return false;
38
-				},
39
-				$matches
40
-			)
41
-		);
42
-
43
-		$embed_shortcode_videos = array_map(
44
-			function ( $url ) {
45
-				return new Default_Embedded_Video( $url );
46
-			},
47
-			$embed_shortcode_urls
48
-		);
49
-
50
-		return array_merge( $embedded_videos, $embed_shortcode_videos );
51
-
52
-	}
16
+    public function init() {
17
+        add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
18
+    }
19
+
20
+    public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
21
+
22
+        $post         = get_post( $post_id );
23
+        $post_content = $post->post_content;
24
+        $embed_regex  = get_shortcode_regex( array( 'embed' ) );
25
+
26
+        $matches = array();
27
+
28
+        preg_match_all( '/' . $embed_regex . '/', $post_content, $matches, PREG_SET_ORDER );
29
+
30
+        // The url is returned in index 5
31
+        $embed_shortcode_urls = array_filter(
32
+            array_map(
33
+                function ( $item ) {
34
+                    if ( isset( $item[5] ) && is_string( $item[5] ) && $item[5] ) {
35
+                            return $item[5];
36
+                    }
37
+                    return false;
38
+                },
39
+                $matches
40
+            )
41
+        );
42
+
43
+        $embed_shortcode_videos = array_map(
44
+            function ( $url ) {
45
+                return new Default_Embedded_Video( $url );
46
+            },
47
+            $embed_shortcode_urls
48
+        );
49
+
50
+        return array_merge( $embedded_videos, $embed_shortcode_videos );
51
+
52
+    }
53 53
 
54 54
 }
55 55
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -14,24 +14,24 @@  discard block
 block discarded – undo
14 14
 class Embed_Shortcode_Capture {
15 15
 
16 16
 	public function init() {
17
-		add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
17
+		add_filter('wl_videoobject_embedded_videos', array($this, 'wl_videoobject_embedded_videos'), 10, 2);
18 18
 	}
19 19
 
20
-	public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
20
+	public function wl_videoobject_embedded_videos($embedded_videos, $post_id) {
21 21
 
22
-		$post         = get_post( $post_id );
22
+		$post         = get_post($post_id);
23 23
 		$post_content = $post->post_content;
24
-		$embed_regex  = get_shortcode_regex( array( 'embed' ) );
24
+		$embed_regex  = get_shortcode_regex(array('embed'));
25 25
 
26 26
 		$matches = array();
27 27
 
28
-		preg_match_all( '/' . $embed_regex . '/', $post_content, $matches, PREG_SET_ORDER );
28
+		preg_match_all('/'.$embed_regex.'/', $post_content, $matches, PREG_SET_ORDER);
29 29
 
30 30
 		// The url is returned in index 5
31 31
 		$embed_shortcode_urls = array_filter(
32 32
 			array_map(
33
-				function ( $item ) {
34
-					if ( isset( $item[5] ) && is_string( $item[5] ) && $item[5] ) {
33
+				function($item) {
34
+					if (isset($item[5]) && is_string($item[5]) && $item[5]) {
35 35
 						  return $item[5];
36 36
 					}
37 37
 					return false;
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
 		);
42 42
 
43 43
 		$embed_shortcode_videos = array_map(
44
-			function ( $url ) {
45
-				return new Default_Embedded_Video( $url );
44
+			function($url) {
45
+				return new Default_Embedded_Video($url);
46 46
 			},
47 47
 			$embed_shortcode_urls
48 48
 		);
49 49
 
50
-		return array_merge( $embedded_videos, $embed_shortcode_videos );
50
+		return array_merge($embedded_videos, $embed_shortcode_videos);
51 51
 
52 52
 	}
53 53
 
Please login to merge, or discard this patch.
src/wordlift/videoobject/filters/class-jw-player-capture.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,33 +13,33 @@
 block discarded – undo
13 13
 
14 14
 class Jw_Player_Capture {
15 15
 
16
-	public function init() {
17
-		add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
18
-	}
19
-
20
-	public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
21
-		// we cant reliably determine count for external plugin without
22
-		// this method.
23
-		global $wpdb;
24
-		$video_ids = $wpdb->get_col(
25
-			$wpdb->prepare(
26
-				"SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key LIKE %s AND post_id=%d",
27
-				'_jwppp-video-url-%',
28
-				$post_id
29
-			)
30
-		);
31
-		if ( ! $video_ids ) {
32
-			return $embedded_videos;
33
-		}
34
-
35
-		$jw_player_videos = array_map(
36
-			function ( $video_id ) {
37
-				return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id );
38
-			},
39
-			$video_ids
40
-		);
41
-
42
-		return array_merge( $embedded_videos, $jw_player_videos );
43
-	}
16
+    public function init() {
17
+        add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
18
+    }
19
+
20
+    public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
21
+        // we cant reliably determine count for external plugin without
22
+        // this method.
23
+        global $wpdb;
24
+        $video_ids = $wpdb->get_col(
25
+            $wpdb->prepare(
26
+                "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key LIKE %s AND post_id=%d",
27
+                '_jwppp-video-url-%',
28
+                $post_id
29
+            )
30
+        );
31
+        if ( ! $video_ids ) {
32
+            return $embedded_videos;
33
+        }
34
+
35
+        $jw_player_videos = array_map(
36
+            function ( $video_id ) {
37
+                return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id );
38
+            },
39
+            $video_ids
40
+        );
41
+
42
+        return array_merge( $embedded_videos, $jw_player_videos );
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
 class Jw_Player_Capture {
15 15
 
16 16
 	public function init() {
17
-		add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
17
+		add_filter('wl_videoobject_embedded_videos', array($this, 'wl_videoobject_embedded_videos'), 10, 2);
18 18
 	}
19 19
 
20
-	public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
20
+	public function wl_videoobject_embedded_videos($embedded_videos, $post_id) {
21 21
 		// we cant reliably determine count for external plugin without
22 22
 		// this method.
23 23
 		global $wpdb;
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
 				$post_id
29 29
 			)
30 30
 		);
31
-		if ( ! $video_ids ) {
31
+		if ( ! $video_ids) {
32 32
 			return $embedded_videos;
33 33
 		}
34 34
 
35 35
 		$jw_player_videos = array_map(
36
-			function ( $video_id ) {
37
-				return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id );
36
+			function($video_id) {
37
+				return new Default_Embedded_Video('https://cdn.jwplayer.com/v2/media/'.$video_id);
38 38
 			},
39 39
 			$video_ids
40 40
 		);
41 41
 
42
-		return array_merge( $embedded_videos, $jw_player_videos );
42
+		return array_merge($embedded_videos, $jw_player_videos);
43 43
 	}
44 44
 
45 45
 }
Please login to merge, or discard this patch.
src/wordlift/synonym/class-rest-field.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -6,62 +6,62 @@
 block discarded – undo
6 6
 
7 7
 class Rest_Field {
8 8
 
9
-	public function __construct() {
10
-		add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
11
-	}
12
-
13
-	public function register_rest_field() {
14
-
15
-		if ( ! function_exists( 'register_rest_field' ) ) {
16
-			return;
17
-		}
18
-
19
-		$post_types = Wordlift_Entity_Service::valid_entity_post_types();
20
-
21
-		foreach ( $post_types as $post_type ) {
22
-
23
-			register_rest_field(
24
-				$post_type,
25
-				\Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
26
-				array(
27
-					'get_callback'    => array( $this, 'get_value' ),
28
-					'update_callback' => array( $this, 'update_value' ),
29
-				)
30
-			);
31
-
32
-		}
33
-
34
-	}
35
-
36
-	/**
37
-	 * @param $meta_values array
38
-	 * @param $post \WP_Post
39
-	 * @param $meta_key string
40
-	 */
41
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
-	public function update_value( $meta_values, $post, $meta_key ) {
43
-
44
-		if ( ! is_array( $meta_values ) ) {
45
-			return;
46
-		}
47
-
48
-		$entity_service = Wordlift_Entity_Service::get_instance();
49
-
50
-		$entity_service->set_alternative_labels( $post->ID, $meta_values );
51
-	}
52
-
53
-	/**
54
-	 * @param $post array Post array.
55
-	 *
56
-	 * @return array|mixed
57
-	 */
58
-	public function get_value( $post ) {
59
-		$data = get_post_meta( (int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
60
-		if ( ! is_array( $data ) ) {
61
-			return array();
62
-		}
63
-
64
-		return $data;
65
-	}
9
+    public function __construct() {
10
+        add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
11
+    }
12
+
13
+    public function register_rest_field() {
14
+
15
+        if ( ! function_exists( 'register_rest_field' ) ) {
16
+            return;
17
+        }
18
+
19
+        $post_types = Wordlift_Entity_Service::valid_entity_post_types();
20
+
21
+        foreach ( $post_types as $post_type ) {
22
+
23
+            register_rest_field(
24
+                $post_type,
25
+                \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
26
+                array(
27
+                    'get_callback'    => array( $this, 'get_value' ),
28
+                    'update_callback' => array( $this, 'update_value' ),
29
+                )
30
+            );
31
+
32
+        }
33
+
34
+    }
35
+
36
+    /**
37
+     * @param $meta_values array
38
+     * @param $post \WP_Post
39
+     * @param $meta_key string
40
+     */
41
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
+    public function update_value( $meta_values, $post, $meta_key ) {
43
+
44
+        if ( ! is_array( $meta_values ) ) {
45
+            return;
46
+        }
47
+
48
+        $entity_service = Wordlift_Entity_Service::get_instance();
49
+
50
+        $entity_service->set_alternative_labels( $post->ID, $meta_values );
51
+    }
52
+
53
+    /**
54
+     * @param $post array Post array.
55
+     *
56
+     * @return array|mixed
57
+     */
58
+    public function get_value( $post ) {
59
+        $data = get_post_meta( (int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
60
+        if ( ! is_array( $data ) ) {
61
+            return array();
62
+        }
63
+
64
+        return $data;
65
+    }
66 66
 
67 67
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@  discard block
 block discarded – undo
7 7
 class Rest_Field {
8 8
 
9 9
 	public function __construct() {
10
-		add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
10
+		add_action('rest_api_init', array($this, 'register_rest_field'));
11 11
 	}
12 12
 
13 13
 	public function register_rest_field() {
14 14
 
15
-		if ( ! function_exists( 'register_rest_field' ) ) {
15
+		if ( ! function_exists('register_rest_field')) {
16 16
 			return;
17 17
 		}
18 18
 
19 19
 		$post_types = Wordlift_Entity_Service::valid_entity_post_types();
20 20
 
21
-		foreach ( $post_types as $post_type ) {
21
+		foreach ($post_types as $post_type) {
22 22
 
23 23
 			register_rest_field(
24 24
 				$post_type,
25 25
 				\Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
26 26
 				array(
27
-					'get_callback'    => array( $this, 'get_value' ),
28
-					'update_callback' => array( $this, 'update_value' ),
27
+					'get_callback'    => array($this, 'get_value'),
28
+					'update_callback' => array($this, 'update_value'),
29 29
 				)
30 30
 			);
31 31
 
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 	 * @param $meta_key string
40 40
 	 */
41 41
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
-	public function update_value( $meta_values, $post, $meta_key ) {
42
+	public function update_value($meta_values, $post, $meta_key) {
43 43
 
44
-		if ( ! is_array( $meta_values ) ) {
44
+		if ( ! is_array($meta_values)) {
45 45
 			return;
46 46
 		}
47 47
 
48 48
 		$entity_service = Wordlift_Entity_Service::get_instance();
49 49
 
50
-		$entity_service->set_alternative_labels( $post->ID, $meta_values );
50
+		$entity_service->set_alternative_labels($post->ID, $meta_values);
51 51
 	}
52 52
 
53 53
 	/**
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return array|mixed
57 57
 	 */
58
-	public function get_value( $post ) {
59
-		$data = get_post_meta( (int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
60
-		if ( ! is_array( $data ) ) {
58
+	public function get_value($post) {
59
+		$data = get_post_meta((int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY);
60
+		if ( ! is_array($data)) {
61 61
 			return array();
62 62
 		}
63 63
 
Please login to merge, or discard this patch.
src/wordlift/synonym/class-loader.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@
 block discarded – undo
9 9
  */
10 10
 class Loader extends Default_Loader {
11 11
 
12
-	public function init_all_dependencies() {
13
-		new Rest_Field();
14
-	}
12
+    public function init_all_dependencies() {
13
+        new Rest_Field();
14
+    }
15 15
 
16
-	protected function get_feature_slug() {
17
-		return 'add-synonyms';
18
-	}
16
+    protected function get_feature_slug() {
17
+        return 'add-synonyms';
18
+    }
19 19
 
20
-	protected function get_feature_default_value() {
21
-		return true;
22
-	}
20
+    protected function get_feature_default_value() {
21
+        return true;
22
+    }
23 23
 }
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-service.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -10,78 +10,78 @@
 block discarded – undo
10 10
 
11 11
 class Jsonld_Service {
12 12
 
13
-	/**
14
-	 * @var Jsonld_Service
15
-	 */
16
-	private static $instance;
17
-
18
-	/**
19
-	 * @var Wordlift_Jsonld_Service
20
-	 */
21
-	private $legacy_jsonld_service;
22
-
23
-	/**
24
-	 * @var Wordlift_Term_JsonLd_Adapter
25
-	 */
26
-	private $term_jsonld_service;
27
-
28
-	/**
29
-	 * @var Jsonld_User_Service
30
-	 */
31
-	private $jsonld_user_service;
32
-
33
-	/**
34
-	 * Jsonld_Service constructor.
35
-	 *
36
-	 * @param Wordlift_Jsonld_Service      $legacy_jsonld_service
37
-	 * @param Wordlift_Term_JsonLd_Adapter $term_jsonld_adapter
38
-	 * @param Jsonld_User_Service          $jsonld_user_service
39
-	 *
40
-	 * @throws Exception when an error occurs.
41
-	 */
42
-	public function __construct( $legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service ) {
43
-
44
-		Assertions::assert_of_type( $legacy_jsonld_service, 'Wordlift_Jsonld_Service' );
45
-		Assertions::assert_of_type( $term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter' );
46
-		Assertions::assert_of_type( $jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service' );
47
-
48
-		$this->legacy_jsonld_service = $legacy_jsonld_service;
49
-		$this->term_jsonld_service   = $term_jsonld_adapter;
50
-		$this->jsonld_user_service   = $jsonld_user_service;
51
-		$this->jsonld_user_service->set_jsonld_service( $this );
52
-
53
-		self::$instance = $this;
54
-	}
55
-
56
-	public static function get_instance() {
57
-		return self::$instance;
58
-	}
59
-
60
-	/**
61
-	 * Get the JSON-LD structure for the specified type and id.
62
-	 *
63
-	 * @param int      $type The requested type, one of 'HOMEPAGE', 'POST' or 'TERM'. Default 'POST'.
64
-	 * @param int|null $id The id. Default `null`.
65
-	 * @param int      $context A context for the JSON-LD generation, valid values in Jsonld_Context_Enum.
66
-	 *
67
-	 * @return array The JSON-LD structure.
68
-	 * @throws Exception Throws an exception if the type isn't recognized.
69
-	 */
70
-	public function get( $type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
71
-
72
-		switch ( $type ) {
73
-			case Object_Type_Enum::HOMEPAGE:
74
-				return $this->legacy_jsonld_service->get_jsonld( true, $id, $context );
75
-			case Object_Type_Enum::POST:
76
-				return $this->legacy_jsonld_service->get_jsonld( false, $id, $context );
77
-			case Object_Type_Enum::TERM:
78
-				return $this->term_jsonld_service->get( $id, $context );
79
-			case Object_Type_Enum::USER:
80
-				return $this->jsonld_user_service->get( $id );
81
-			default:
82
-				throw new Exception( "Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'." );
83
-		}
84
-
85
-	}
13
+    /**
14
+     * @var Jsonld_Service
15
+     */
16
+    private static $instance;
17
+
18
+    /**
19
+     * @var Wordlift_Jsonld_Service
20
+     */
21
+    private $legacy_jsonld_service;
22
+
23
+    /**
24
+     * @var Wordlift_Term_JsonLd_Adapter
25
+     */
26
+    private $term_jsonld_service;
27
+
28
+    /**
29
+     * @var Jsonld_User_Service
30
+     */
31
+    private $jsonld_user_service;
32
+
33
+    /**
34
+     * Jsonld_Service constructor.
35
+     *
36
+     * @param Wordlift_Jsonld_Service      $legacy_jsonld_service
37
+     * @param Wordlift_Term_JsonLd_Adapter $term_jsonld_adapter
38
+     * @param Jsonld_User_Service          $jsonld_user_service
39
+     *
40
+     * @throws Exception when an error occurs.
41
+     */
42
+    public function __construct( $legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service ) {
43
+
44
+        Assertions::assert_of_type( $legacy_jsonld_service, 'Wordlift_Jsonld_Service' );
45
+        Assertions::assert_of_type( $term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter' );
46
+        Assertions::assert_of_type( $jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service' );
47
+
48
+        $this->legacy_jsonld_service = $legacy_jsonld_service;
49
+        $this->term_jsonld_service   = $term_jsonld_adapter;
50
+        $this->jsonld_user_service   = $jsonld_user_service;
51
+        $this->jsonld_user_service->set_jsonld_service( $this );
52
+
53
+        self::$instance = $this;
54
+    }
55
+
56
+    public static function get_instance() {
57
+        return self::$instance;
58
+    }
59
+
60
+    /**
61
+     * Get the JSON-LD structure for the specified type and id.
62
+     *
63
+     * @param int      $type The requested type, one of 'HOMEPAGE', 'POST' or 'TERM'. Default 'POST'.
64
+     * @param int|null $id The id. Default `null`.
65
+     * @param int      $context A context for the JSON-LD generation, valid values in Jsonld_Context_Enum.
66
+     *
67
+     * @return array The JSON-LD structure.
68
+     * @throws Exception Throws an exception if the type isn't recognized.
69
+     */
70
+    public function get( $type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
71
+
72
+        switch ( $type ) {
73
+            case Object_Type_Enum::HOMEPAGE:
74
+                return $this->legacy_jsonld_service->get_jsonld( true, $id, $context );
75
+            case Object_Type_Enum::POST:
76
+                return $this->legacy_jsonld_service->get_jsonld( false, $id, $context );
77
+            case Object_Type_Enum::TERM:
78
+                return $this->term_jsonld_service->get( $id, $context );
79
+            case Object_Type_Enum::USER:
80
+                return $this->jsonld_user_service->get( $id );
81
+            default:
82
+                throw new Exception( "Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'." );
83
+        }
84
+
85
+    }
86 86
 
87 87
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -39,16 +39,16 @@  discard block
 block discarded – undo
39 39
 	 *
40 40
 	 * @throws Exception when an error occurs.
41 41
 	 */
42
-	public function __construct( $legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service ) {
42
+	public function __construct($legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service) {
43 43
 
44
-		Assertions::assert_of_type( $legacy_jsonld_service, 'Wordlift_Jsonld_Service' );
45
-		Assertions::assert_of_type( $term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter' );
46
-		Assertions::assert_of_type( $jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service' );
44
+		Assertions::assert_of_type($legacy_jsonld_service, 'Wordlift_Jsonld_Service');
45
+		Assertions::assert_of_type($term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter');
46
+		Assertions::assert_of_type($jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service');
47 47
 
48 48
 		$this->legacy_jsonld_service = $legacy_jsonld_service;
49 49
 		$this->term_jsonld_service   = $term_jsonld_adapter;
50 50
 		$this->jsonld_user_service   = $jsonld_user_service;
51
-		$this->jsonld_user_service->set_jsonld_service( $this );
51
+		$this->jsonld_user_service->set_jsonld_service($this);
52 52
 
53 53
 		self::$instance = $this;
54 54
 	}
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 	 * @return array The JSON-LD structure.
68 68
 	 * @throws Exception Throws an exception if the type isn't recognized.
69 69
 	 */
70
-	public function get( $type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
70
+	public function get($type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN) {
71 71
 
72
-		switch ( $type ) {
72
+		switch ($type) {
73 73
 			case Object_Type_Enum::HOMEPAGE:
74
-				return $this->legacy_jsonld_service->get_jsonld( true, $id, $context );
74
+				return $this->legacy_jsonld_service->get_jsonld(true, $id, $context);
75 75
 			case Object_Type_Enum::POST:
76
-				return $this->legacy_jsonld_service->get_jsonld( false, $id, $context );
76
+				return $this->legacy_jsonld_service->get_jsonld(false, $id, $context);
77 77
 			case Object_Type_Enum::TERM:
78
-				return $this->term_jsonld_service->get( $id, $context );
78
+				return $this->term_jsonld_service->get($id, $context);
79 79
 			case Object_Type_Enum::USER:
80
-				return $this->jsonld_user_service->get( $id );
80
+				return $this->jsonld_user_service->get($id);
81 81
 			default:
82
-				throw new Exception( "Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'." );
82
+				throw new Exception("Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'.");
83 83
 		}
84 84
 
85 85
 	}
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-article-wrapper.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -6,142 +6,142 @@
 block discarded – undo
6 6
 
7 7
 class Jsonld_Article_Wrapper {
8 8
 
9
-	public static $article_types = array(
10
-		'Article',
11
-		'AdvertiserContentArticle',
12
-		'NewsArticle',
13
-		'AnalysisNewsArticle',
14
-		'AskPublicNewsArticle',
15
-		'BackgroundNewsArticle',
16
-		'OpinionNewsArticle',
17
-		'ReportageNewsArticle',
18
-		'ReviewNewsArticle',
19
-		'Report',
20
-		'SatiricalArticle',
21
-		'ScholarlyArticle',
22
-		'MedicalScholarlyArticle',
23
-		'SocialMediaPosting',
24
-		'BlogPosting',
25
-		'LiveBlogPosting',
26
-		'DiscussionForumPosting',
27
-		'TechArticle',
28
-		'APIReference',
29
-	);
30
-
31
-	/**
32
-	 * @var Wordlift_Post_To_Jsonld_Converter
33
-	 */
34
-	private $post_to_jsonld_converter;
35
-	/**
36
-	 * @var \Wordlift_Cached_Post_Converter
37
-	 */
38
-	private $cached_postid_to_jsonld_converter;
39
-	/**
40
-	 * @var \Wordlift_Entity_Uri_Service
41
-	 */
42
-	private $entity_uri_service;
43
-
44
-	/**
45
-	 * Jsonld_Article_Wrapper constructor.
46
-	 *
47
-	 * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter
48
-	 * @param $cached_postid_to_jsonld_converter
49
-	 */
50
-	public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) {
51
-
52
-		$this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled();
53
-
54
-		add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ), PHP_INT_MAX - 100, 3 );
55
-
56
-		$this->cached_postid_to_jsonld_converter = $cached_postid_to_jsonld_converter;
57
-
58
-		$this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance();
59
-	}
60
-
61
-	public function after_get_jsonld( $jsonld, $post_id, $context ) {
62
-
63
-		if ( Jsonld_Context_Enum::PAGE !== $context || ! is_array( $jsonld ) || ! isset( $jsonld[0] )
64
-			 || ! is_array( $jsonld[0] ) ) {
65
-			return $jsonld;
66
-		}
67
-
68
-		// Copy the 1st array element
69
-		$post_jsonld = $jsonld[0];
70
-
71
-		// Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be
72
-		// in the schema.org context, i.e. `Article`, not `http://schema.org/Article`.
73
-		if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) {
74
-			return $jsonld;
75
-		}
76
-
77
-		// Convert the post as Article.
78
-		$article_jsonld = $this->post_to_jsonld_converter->convert( $post_id );
79
-
80
-		$article_jsonld['@id'] = $post_jsonld['@id'] . '#article';
81
-		// Reset the type, since by default the type assigned via the Entity Type taxonomy is used.
82
-		$article_jsonld['@type'] = 'Article';
83
-		$article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] );
84
-
85
-		// Copy over the URLs.
86
-		if ( isset( $post_jsonld['url'] ) ) {
87
-			$article_jsonld['url'] = $post_jsonld['url'];
88
-		}
89
-
90
-		array_unshift( $jsonld, $article_jsonld );
91
-
92
-		$author_jsonld = $this->get_author_linked_entity( $article_jsonld );
93
-
94
-		/**
95
-		 * The author entities can be present in graph for some entity types
96
-		 * for Person and Organization, so check before we add it to graph.
97
-		 * reference : https://schema.org/author
98
-		 */
99
-		if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $article_jsonld['author']['@id'] ) ) {
100
-			$jsonld[] = $author_jsonld;
101
-		}
102
-
103
-		return $jsonld;
104
-	}
105
-
106
-	private function is_article( $schema_types ) {
107
-
108
-		$array_intersect = array_intersect( self::$article_types, (array) $schema_types );
109
-
110
-		return ! empty( $array_intersect );
111
-	}
112
-
113
-	private function get_author_linked_entity( $article_jsonld ) {
114
-		if ( ! array_key_exists( 'author', $article_jsonld ) ) {
115
-			return false;
116
-		}
117
-
118
-		$author = $article_jsonld['author'];
9
+    public static $article_types = array(
10
+        'Article',
11
+        'AdvertiserContentArticle',
12
+        'NewsArticle',
13
+        'AnalysisNewsArticle',
14
+        'AskPublicNewsArticle',
15
+        'BackgroundNewsArticle',
16
+        'OpinionNewsArticle',
17
+        'ReportageNewsArticle',
18
+        'ReviewNewsArticle',
19
+        'Report',
20
+        'SatiricalArticle',
21
+        'ScholarlyArticle',
22
+        'MedicalScholarlyArticle',
23
+        'SocialMediaPosting',
24
+        'BlogPosting',
25
+        'LiveBlogPosting',
26
+        'DiscussionForumPosting',
27
+        'TechArticle',
28
+        'APIReference',
29
+    );
30
+
31
+    /**
32
+     * @var Wordlift_Post_To_Jsonld_Converter
33
+     */
34
+    private $post_to_jsonld_converter;
35
+    /**
36
+     * @var \Wordlift_Cached_Post_Converter
37
+     */
38
+    private $cached_postid_to_jsonld_converter;
39
+    /**
40
+     * @var \Wordlift_Entity_Uri_Service
41
+     */
42
+    private $entity_uri_service;
43
+
44
+    /**
45
+     * Jsonld_Article_Wrapper constructor.
46
+     *
47
+     * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter
48
+     * @param $cached_postid_to_jsonld_converter
49
+     */
50
+    public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) {
51
+
52
+        $this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled();
53
+
54
+        add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ), PHP_INT_MAX - 100, 3 );
55
+
56
+        $this->cached_postid_to_jsonld_converter = $cached_postid_to_jsonld_converter;
57
+
58
+        $this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance();
59
+    }
60
+
61
+    public function after_get_jsonld( $jsonld, $post_id, $context ) {
62
+
63
+        if ( Jsonld_Context_Enum::PAGE !== $context || ! is_array( $jsonld ) || ! isset( $jsonld[0] )
64
+             || ! is_array( $jsonld[0] ) ) {
65
+            return $jsonld;
66
+        }
67
+
68
+        // Copy the 1st array element
69
+        $post_jsonld = $jsonld[0];
70
+
71
+        // Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be
72
+        // in the schema.org context, i.e. `Article`, not `http://schema.org/Article`.
73
+        if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) {
74
+            return $jsonld;
75
+        }
76
+
77
+        // Convert the post as Article.
78
+        $article_jsonld = $this->post_to_jsonld_converter->convert( $post_id );
79
+
80
+        $article_jsonld['@id'] = $post_jsonld['@id'] . '#article';
81
+        // Reset the type, since by default the type assigned via the Entity Type taxonomy is used.
82
+        $article_jsonld['@type'] = 'Article';
83
+        $article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] );
84
+
85
+        // Copy over the URLs.
86
+        if ( isset( $post_jsonld['url'] ) ) {
87
+            $article_jsonld['url'] = $post_jsonld['url'];
88
+        }
89
+
90
+        array_unshift( $jsonld, $article_jsonld );
91
+
92
+        $author_jsonld = $this->get_author_linked_entity( $article_jsonld );
93
+
94
+        /**
95
+         * The author entities can be present in graph for some entity types
96
+         * for Person and Organization, so check before we add it to graph.
97
+         * reference : https://schema.org/author
98
+         */
99
+        if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $article_jsonld['author']['@id'] ) ) {
100
+            $jsonld[] = $author_jsonld;
101
+        }
102
+
103
+        return $jsonld;
104
+    }
105
+
106
+    private function is_article( $schema_types ) {
107
+
108
+        $array_intersect = array_intersect( self::$article_types, (array) $schema_types );
109
+
110
+        return ! empty( $array_intersect );
111
+    }
112
+
113
+    private function get_author_linked_entity( $article_jsonld ) {
114
+        if ( ! array_key_exists( 'author', $article_jsonld ) ) {
115
+            return false;
116
+        }
117
+
118
+        $author = $article_jsonld['author'];
119 119
 
120
-		if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) {
121
-			return false;
122
-		}
120
+        if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) {
121
+            return false;
122
+        }
123 123
 
124
-		$author_linked_entity_id = $author['@id'];
124
+        $author_linked_entity_id = $author['@id'];
125 125
 
126
-		$author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id );
126
+        $author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id );
127 127
 
128
-		if ( ! $author_entity_post instanceof \WP_Post ) {
129
-			return false;
130
-		}
128
+        if ( ! $author_entity_post instanceof \WP_Post ) {
129
+            return false;
130
+        }
131 131
 
132
-		return $this->cached_postid_to_jsonld_converter->convert( $author_entity_post->ID );
132
+        return $this->cached_postid_to_jsonld_converter->convert( $author_entity_post->ID );
133 133
 
134
-	}
134
+    }
135 135
 
136
-	private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) {
136
+    private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) {
137 137
 
138
-		foreach ( $jsonld as $item ) {
139
-			if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) {
140
-				return true;
141
-			}
142
-		}
138
+        foreach ( $jsonld as $item ) {
139
+            if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) {
140
+                return true;
141
+            }
142
+        }
143 143
 
144
-		return false;
145
-	}
144
+        return false;
145
+    }
146 146
 
147 147
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
 	 * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter
48 48
 	 * @param $cached_postid_to_jsonld_converter
49 49
 	 */
50
-	public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) {
50
+	public function __construct($post_to_jsonld_converter, $cached_postid_to_jsonld_converter) {
51 51
 
52 52
 		$this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled();
53 53
 
54
-		add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ), PHP_INT_MAX - 100, 3 );
54
+		add_filter('wl_after_get_jsonld', array($this, 'after_get_jsonld'), PHP_INT_MAX - 100, 3);
55 55
 
56 56
 		$this->cached_postid_to_jsonld_converter = $cached_postid_to_jsonld_converter;
57 57
 
58 58
 		$this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance();
59 59
 	}
60 60
 
61
-	public function after_get_jsonld( $jsonld, $post_id, $context ) {
61
+	public function after_get_jsonld($jsonld, $post_id, $context) {
62 62
 
63
-		if ( Jsonld_Context_Enum::PAGE !== $context || ! is_array( $jsonld ) || ! isset( $jsonld[0] )
64
-			 || ! is_array( $jsonld[0] ) ) {
63
+		if (Jsonld_Context_Enum::PAGE !== $context || ! is_array($jsonld) || ! isset($jsonld[0])
64
+			 || ! is_array($jsonld[0])) {
65 65
 			return $jsonld;
66 66
 		}
67 67
 
@@ -70,73 +70,73 @@  discard block
 block discarded – undo
70 70
 
71 71
 		// Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be
72 72
 		// in the schema.org context, i.e. `Article`, not `http://schema.org/Article`.
73
-		if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) {
73
+		if ( ! isset($post_jsonld['@id']) || ! isset($post_jsonld['@type']) || $this->is_article($post_jsonld['@type'])) {
74 74
 			return $jsonld;
75 75
 		}
76 76
 
77 77
 		// Convert the post as Article.
78
-		$article_jsonld = $this->post_to_jsonld_converter->convert( $post_id );
78
+		$article_jsonld = $this->post_to_jsonld_converter->convert($post_id);
79 79
 
80
-		$article_jsonld['@id'] = $post_jsonld['@id'] . '#article';
80
+		$article_jsonld['@id'] = $post_jsonld['@id'].'#article';
81 81
 		// Reset the type, since by default the type assigned via the Entity Type taxonomy is used.
82 82
 		$article_jsonld['@type'] = 'Article';
83
-		$article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] );
83
+		$article_jsonld['about'] = array('@id' => $post_jsonld['@id']);
84 84
 
85 85
 		// Copy over the URLs.
86
-		if ( isset( $post_jsonld['url'] ) ) {
86
+		if (isset($post_jsonld['url'])) {
87 87
 			$article_jsonld['url'] = $post_jsonld['url'];
88 88
 		}
89 89
 
90
-		array_unshift( $jsonld, $article_jsonld );
90
+		array_unshift($jsonld, $article_jsonld);
91 91
 
92
-		$author_jsonld = $this->get_author_linked_entity( $article_jsonld );
92
+		$author_jsonld = $this->get_author_linked_entity($article_jsonld);
93 93
 
94 94
 		/**
95 95
 		 * The author entities can be present in graph for some entity types
96 96
 		 * for Person and Organization, so check before we add it to graph.
97 97
 		 * reference : https://schema.org/author
98 98
 		 */
99
-		if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $article_jsonld['author']['@id'] ) ) {
99
+		if ($author_jsonld && ! $this->is_author_entity_present_in_graph($jsonld, $article_jsonld['author']['@id'])) {
100 100
 			$jsonld[] = $author_jsonld;
101 101
 		}
102 102
 
103 103
 		return $jsonld;
104 104
 	}
105 105
 
106
-	private function is_article( $schema_types ) {
106
+	private function is_article($schema_types) {
107 107
 
108
-		$array_intersect = array_intersect( self::$article_types, (array) $schema_types );
108
+		$array_intersect = array_intersect(self::$article_types, (array) $schema_types);
109 109
 
110
-		return ! empty( $array_intersect );
110
+		return ! empty($array_intersect);
111 111
 	}
112 112
 
113
-	private function get_author_linked_entity( $article_jsonld ) {
114
-		if ( ! array_key_exists( 'author', $article_jsonld ) ) {
113
+	private function get_author_linked_entity($article_jsonld) {
114
+		if ( ! array_key_exists('author', $article_jsonld)) {
115 115
 			return false;
116 116
 		}
117 117
 
118 118
 		$author = $article_jsonld['author'];
119 119
 
120
-		if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) {
120
+		if (count(array_keys($author)) !== 1 || ! array_key_exists('@id', $author)) {
121 121
 			return false;
122 122
 		}
123 123
 
124 124
 		$author_linked_entity_id = $author['@id'];
125 125
 
126
-		$author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id );
126
+		$author_entity_post = $this->entity_uri_service->get_entity($author_linked_entity_id);
127 127
 
128
-		if ( ! $author_entity_post instanceof \WP_Post ) {
128
+		if ( ! $author_entity_post instanceof \WP_Post) {
129 129
 			return false;
130 130
 		}
131 131
 
132
-		return $this->cached_postid_to_jsonld_converter->convert( $author_entity_post->ID );
132
+		return $this->cached_postid_to_jsonld_converter->convert($author_entity_post->ID);
133 133
 
134 134
 	}
135 135
 
136
-	private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) {
136
+	private function is_author_entity_present_in_graph($jsonld, $author_entity_id) {
137 137
 
138
-		foreach ( $jsonld as $item ) {
139
-			if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) {
138
+		foreach ($jsonld as $item) {
139
+			if ($item && array_key_exists('@id', $item) && $item['@id'] === $author_entity_id) {
140 140
 				return true;
141 141
 			}
142 142
 		}
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-by-id-endpoint.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -23,123 +23,123 @@
 block discarded – undo
23 23
  */
24 24
 class Jsonld_By_Id_Endpoint {
25 25
 
26
-	/**
27
-	 * The {@link Wordlift_Jsonld_Service} instance.
28
-	 *
29
-	 * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
30
-	 */
31
-	private $jsonld_service;
32
-
33
-	/**
34
-	 * @var \Wordlift_Entity_Uri_Service
35
-	 */
36
-	private $entity_uri_service;
37
-
38
-	/**
39
-	 * Jsonld_Endpoint constructor.
40
-	 *
41
-	 * @param \Wordlift_Jsonld_Service     $jsonld_service
42
-	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
43
-	 */
44
-	public function __construct( $jsonld_service, $entity_uri_service ) {
45
-
46
-		$this->jsonld_service     = $jsonld_service;
47
-		$this->entity_uri_service = $entity_uri_service;
48
-
49
-		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Get the JSON-LD.
55
-	 *
56
-	 * @param \WP_REST_Request $request The incoming {@link \WP_REST_Request}.
57
-	 *
58
-	 * @return WP_REST_Response The outgoing {@link WP_REST_Response}.
59
-	 * @throws \Exception when an error occurs.
60
-	 */
61
-	public function jsonld_by_id( $request ) {
62
-
63
-		// Get the ids.
64
-		$ids = (array) $request->get_param( 'id' );
65
-
66
-		// Preload the URIs to reduce the number of DB roundtrips.
67
-		$this->entity_uri_service->preload_uris( array_map( 'urldecode', $ids ) );
68
-
69
-		$that = $this;
70
-
71
-		// Get the posts, filtering out those not found.
72
-		$posts = array_filter(
73
-			array_map(
74
-				function ( $item ) use ( $that ) {
75
-					return $that->entity_uri_service->get_entity( urldecode( $item ) );
76
-				},
77
-				$ids
78
-			)
79
-		);
80
-
81
-		// Get the posts' IDs and make the unique.
82
-		$post_ids = array_unique(
83
-			array_map(
84
-				function ( $item ) {
85
-					return $item->ID;
86
-				},
87
-				$posts
88
-			)
89
-		);
90
-
91
-		// Get the JSON-LD.
92
-		$data = array();
93
-		foreach ( $post_ids as $post_id ) {
94
-			$data = array_merge( $data, $that->jsonld_service->get_jsonld( false, $post_id ) );
95
-		}
96
-
97
-		// Add the WebSite fragment if requested.
98
-		if ( $request->get_param( 'website' ) ) {
99
-			$data[] = $this->jsonld_service->get_jsonld( true );
100
-		}
101
-
102
-		return Jsonld_Response_Helper::to_response( $data );
103
-	}
104
-
105
-	public function register_routes() {
106
-
107
-		register_rest_route(
108
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
109
-			'/jsonld',
110
-			array(
111
-				'methods'             => WP_REST_Server::READABLE,
112
-				'callback'            => array( $this, 'jsonld_by_id' ),
113
-				'permission_callback' => '__return_true',
114
-				'args'                => array(
115
-					'id'      => array(
116
-						'description'       => __( 'One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift' ),
117
-						// We expect an array of strings.
118
-						'type'              => 'array',
119
-						'items'             => array(
120
-							'type' => 'string',
121
-						),
122
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123
-						'validate_callback' => function ( $values, $request, $param ) {
124
-
125
-							if ( ! is_array( $values ) ) {
126
-								return new WP_Error( 'rest_invalid_param', esc_html__( 'The id argument must be an array (try passing `id[]=...`.', 'wordlift' ), array( 'status' => 400 ) );
127
-							}
128
-
129
-							foreach ( $values as $value ) {
130
-								if ( 0 !== strpos( $value, 'http' ) ) {
131
-									return new WP_Error( 'rest_invalid_param', esc_html__( 'Ids must start with http.', 'wordlift' ), array( 'status' => 400 ) );
132
-								}
133
-							}
134
-						},
135
-					),
136
-					'website' => array(
137
-						'description' => __( 'Whether to include the WebSite markup.', 'wordlift' ),
138
-					),
139
-				),
140
-			)
141
-		);
142
-
143
-	}
26
+    /**
27
+     * The {@link Wordlift_Jsonld_Service} instance.
28
+     *
29
+     * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
30
+     */
31
+    private $jsonld_service;
32
+
33
+    /**
34
+     * @var \Wordlift_Entity_Uri_Service
35
+     */
36
+    private $entity_uri_service;
37
+
38
+    /**
39
+     * Jsonld_Endpoint constructor.
40
+     *
41
+     * @param \Wordlift_Jsonld_Service     $jsonld_service
42
+     * @param \Wordlift_Entity_Uri_Service $entity_uri_service
43
+     */
44
+    public function __construct( $jsonld_service, $entity_uri_service ) {
45
+
46
+        $this->jsonld_service     = $jsonld_service;
47
+        $this->entity_uri_service = $entity_uri_service;
48
+
49
+        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
50
+
51
+    }
52
+
53
+    /**
54
+     * Get the JSON-LD.
55
+     *
56
+     * @param \WP_REST_Request $request The incoming {@link \WP_REST_Request}.
57
+     *
58
+     * @return WP_REST_Response The outgoing {@link WP_REST_Response}.
59
+     * @throws \Exception when an error occurs.
60
+     */
61
+    public function jsonld_by_id( $request ) {
62
+
63
+        // Get the ids.
64
+        $ids = (array) $request->get_param( 'id' );
65
+
66
+        // Preload the URIs to reduce the number of DB roundtrips.
67
+        $this->entity_uri_service->preload_uris( array_map( 'urldecode', $ids ) );
68
+
69
+        $that = $this;
70
+
71
+        // Get the posts, filtering out those not found.
72
+        $posts = array_filter(
73
+            array_map(
74
+                function ( $item ) use ( $that ) {
75
+                    return $that->entity_uri_service->get_entity( urldecode( $item ) );
76
+                },
77
+                $ids
78
+            )
79
+        );
80
+
81
+        // Get the posts' IDs and make the unique.
82
+        $post_ids = array_unique(
83
+            array_map(
84
+                function ( $item ) {
85
+                    return $item->ID;
86
+                },
87
+                $posts
88
+            )
89
+        );
90
+
91
+        // Get the JSON-LD.
92
+        $data = array();
93
+        foreach ( $post_ids as $post_id ) {
94
+            $data = array_merge( $data, $that->jsonld_service->get_jsonld( false, $post_id ) );
95
+        }
96
+
97
+        // Add the WebSite fragment if requested.
98
+        if ( $request->get_param( 'website' ) ) {
99
+            $data[] = $this->jsonld_service->get_jsonld( true );
100
+        }
101
+
102
+        return Jsonld_Response_Helper::to_response( $data );
103
+    }
104
+
105
+    public function register_routes() {
106
+
107
+        register_rest_route(
108
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
109
+            '/jsonld',
110
+            array(
111
+                'methods'             => WP_REST_Server::READABLE,
112
+                'callback'            => array( $this, 'jsonld_by_id' ),
113
+                'permission_callback' => '__return_true',
114
+                'args'                => array(
115
+                    'id'      => array(
116
+                        'description'       => __( 'One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift' ),
117
+                        // We expect an array of strings.
118
+                        'type'              => 'array',
119
+                        'items'             => array(
120
+                            'type' => 'string',
121
+                        ),
122
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123
+                        'validate_callback' => function ( $values, $request, $param ) {
124
+
125
+                            if ( ! is_array( $values ) ) {
126
+                                return new WP_Error( 'rest_invalid_param', esc_html__( 'The id argument must be an array (try passing `id[]=...`.', 'wordlift' ), array( 'status' => 400 ) );
127
+                            }
128
+
129
+                            foreach ( $values as $value ) {
130
+                                if ( 0 !== strpos( $value, 'http' ) ) {
131
+                                    return new WP_Error( 'rest_invalid_param', esc_html__( 'Ids must start with http.', 'wordlift' ), array( 'status' => 400 ) );
132
+                                }
133
+                            }
134
+                        },
135
+                    ),
136
+                    'website' => array(
137
+                        'description' => __( 'Whether to include the WebSite markup.', 'wordlift' ),
138
+                    ),
139
+                ),
140
+            )
141
+        );
142
+
143
+    }
144 144
 
145 145
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
 	 * @param \Wordlift_Jsonld_Service     $jsonld_service
42 42
 	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
43 43
 	 */
44
-	public function __construct( $jsonld_service, $entity_uri_service ) {
44
+	public function __construct($jsonld_service, $entity_uri_service) {
45 45
 
46 46
 		$this->jsonld_service     = $jsonld_service;
47 47
 		$this->entity_uri_service = $entity_uri_service;
48 48
 
49
-		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
49
+		add_action('rest_api_init', array($this, 'register_routes'));
50 50
 
51 51
 	}
52 52
 
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
 	 * @return WP_REST_Response The outgoing {@link WP_REST_Response}.
59 59
 	 * @throws \Exception when an error occurs.
60 60
 	 */
61
-	public function jsonld_by_id( $request ) {
61
+	public function jsonld_by_id($request) {
62 62
 
63 63
 		// Get the ids.
64
-		$ids = (array) $request->get_param( 'id' );
64
+		$ids = (array) $request->get_param('id');
65 65
 
66 66
 		// Preload the URIs to reduce the number of DB roundtrips.
67
-		$this->entity_uri_service->preload_uris( array_map( 'urldecode', $ids ) );
67
+		$this->entity_uri_service->preload_uris(array_map('urldecode', $ids));
68 68
 
69 69
 		$that = $this;
70 70
 
71 71
 		// Get the posts, filtering out those not found.
72 72
 		$posts = array_filter(
73 73
 			array_map(
74
-				function ( $item ) use ( $that ) {
75
-					return $that->entity_uri_service->get_entity( urldecode( $item ) );
74
+				function($item) use ($that) {
75
+					return $that->entity_uri_service->get_entity(urldecode($item));
76 76
 				},
77 77
 				$ids
78 78
 			)
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		// Get the posts' IDs and make the unique.
82 82
 		$post_ids = array_unique(
83 83
 			array_map(
84
-				function ( $item ) {
84
+				function($item) {
85 85
 					return $item->ID;
86 86
 				},
87 87
 				$posts
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
 
91 91
 		// Get the JSON-LD.
92 92
 		$data = array();
93
-		foreach ( $post_ids as $post_id ) {
94
-			$data = array_merge( $data, $that->jsonld_service->get_jsonld( false, $post_id ) );
93
+		foreach ($post_ids as $post_id) {
94
+			$data = array_merge($data, $that->jsonld_service->get_jsonld(false, $post_id));
95 95
 		}
96 96
 
97 97
 		// Add the WebSite fragment if requested.
98
-		if ( $request->get_param( 'website' ) ) {
99
-			$data[] = $this->jsonld_service->get_jsonld( true );
98
+		if ($request->get_param('website')) {
99
+			$data[] = $this->jsonld_service->get_jsonld(true);
100 100
 		}
101 101
 
102
-		return Jsonld_Response_Helper::to_response( $data );
102
+		return Jsonld_Response_Helper::to_response($data);
103 103
 	}
104 104
 
105 105
 	public function register_routes() {
@@ -109,32 +109,32 @@  discard block
 block discarded – undo
109 109
 			'/jsonld',
110 110
 			array(
111 111
 				'methods'             => WP_REST_Server::READABLE,
112
-				'callback'            => array( $this, 'jsonld_by_id' ),
112
+				'callback'            => array($this, 'jsonld_by_id'),
113 113
 				'permission_callback' => '__return_true',
114 114
 				'args'                => array(
115 115
 					'id'      => array(
116
-						'description'       => __( 'One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift' ),
116
+						'description'       => __('One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift'),
117 117
 						// We expect an array of strings.
118 118
 						'type'              => 'array',
119 119
 						'items'             => array(
120 120
 							'type' => 'string',
121 121
 						),
122 122
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123
-						'validate_callback' => function ( $values, $request, $param ) {
123
+						'validate_callback' => function($values, $request, $param) {
124 124
 
125
-							if ( ! is_array( $values ) ) {
126
-								return new WP_Error( 'rest_invalid_param', esc_html__( 'The id argument must be an array (try passing `id[]=...`.', 'wordlift' ), array( 'status' => 400 ) );
125
+							if ( ! is_array($values)) {
126
+								return new WP_Error('rest_invalid_param', esc_html__('The id argument must be an array (try passing `id[]=...`.', 'wordlift'), array('status' => 400));
127 127
 							}
128 128
 
129
-							foreach ( $values as $value ) {
130
-								if ( 0 !== strpos( $value, 'http' ) ) {
131
-									return new WP_Error( 'rest_invalid_param', esc_html__( 'Ids must start with http.', 'wordlift' ), array( 'status' => 400 ) );
129
+							foreach ($values as $value) {
130
+								if (0 !== strpos($value, 'http')) {
131
+									return new WP_Error('rest_invalid_param', esc_html__('Ids must start with http.', 'wordlift'), array('status' => 400));
132 132
 								}
133 133
 							}
134 134
 						},
135 135
 					),
136 136
 					'website' => array(
137
-						'description' => __( 'Whether to include the WebSite markup.', 'wordlift' ),
137
+						'description' => __('Whether to include the WebSite markup.', 'wordlift'),
138 138
 					),
139 139
 				),
140 140
 			)
Please login to merge, or discard this patch.