Completed
Pull Request — develop (#1698)
by
unknown
01:26
created
src/wordlift/videoobject/jsonld/class-jsonld.php 2 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -11,175 +11,175 @@
 block discarded – undo
11 11
 use Wordlift\Videoobject\Data\Video_Storage\Storage;
12 12
 
13 13
 class Jsonld {
14
-	/**
15
-	 * @var Storage
16
-	 */
17
-	private $video_storage;
18
-
19
-	/**
20
-	 * Jsonld constructor.
21
-	 *
22
-	 * @param $video_storage Storage
23
-	 */
24
-	public function __construct( $video_storage ) {
25
-		add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 );
26
-		add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
27
-		$this->video_storage = $video_storage;
28
-	}
29
-
30
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
31
-		if ( 0 === count( $jsonld ) ) {
32
-			return $jsonld;
33
-		}
34
-		$current_item = $jsonld[0];
35
-
36
-		if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) {
37
-			// Cant determine type return early.
38
-			return $jsonld;
39
-		}
40
-
41
-		$type = $current_item['@type'];
42
-		if ( is_string( $type ) ) {
43
-			$type = array( $type );
44
-		}
45
-		// If its a article or descendant of article, then dont add the
46
-		// videoobject in this hook, they will be already added to video property.
47
-		if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) {
48
-			return $jsonld;
49
-		}
50
-
51
-		$videos_jsonld = $this->get_videos_jsonld( $post_id );
52
-		if ( 0 === count( $videos_jsonld ) ) {
53
-			return $jsonld;
54
-		}
55
-
56
-		// check if we have @id in jsonld for first item.
57
-		$id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : '';
58
-
59
-		foreach ( $videos_jsonld as &$video_jsonld ) {
60
-			if ( ! $id ) {
61
-				continue;
62
-			}
63
-			if ( ! array_key_exists( 'mentions', $video_jsonld ) ) {
64
-				$video_jsonld['mentions'] = array( '@id' => $id );
65
-			} else {
66
-				$video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) );
67
-			}
68
-		}
69
-
70
-		return array_merge( $jsonld, $videos_jsonld );
71
-	}
72
-
73
-	/**
74
-	 * @param $existing_video_data string | array associative or sequential array.
75
-	 * @param $new_video_data array Sequential array.
76
-	 *
77
-	 * @return array
78
-	 */
79
-	private function merge_video_data( $existing_video_data, $new_video_data ) {
80
-		if ( ! is_array( $existing_video_data ) ) {
81
-			$new_video_data[] = $existing_video_data;
82
-
83
-			return $new_video_data;
84
-		}
85
-
86
-		if ( $this->is_associative_array( $existing_video_data ) ) {
87
-			$new_video_data[] = $existing_video_data;
88
-
89
-			return $new_video_data;
90
-		}
91
-
92
-		return array_merge( $existing_video_data, $new_video_data );
93
-	}
94
-
95
-	public function wl_post_jsonld( $jsonld, $post_id ) {
96
-
97
-		$video_jsonld = $this->get_videos_jsonld( $post_id );
98
-		if ( count( $video_jsonld ) === 0 ) {
99
-			return $jsonld;
100
-		}
101
-		// Before adding the video jsonld check if the key
102
-		// is present and additional data might be present,
103
-		// if not present just add the data and return early.
104
-		if ( ! array_key_exists( 'video', $jsonld ) ) {
105
-			$jsonld['video'] = $video_jsonld;
106
-
107
-			return $jsonld;
108
-		}
109
-
110
-		// since key exists, we need to merge the data based on type.
111
-		$previous_video_data = $jsonld['video'];
112
-		$jsonld['video']     = $this->merge_video_data( $previous_video_data, $video_jsonld );
113
-
114
-		return $jsonld;
115
-	}
116
-
117
-	/**
118
-	 * @param $post_id int Post id.
119
-	 *
120
-	 * @return array
121
-	 */
122
-	public function get_videos_jsonld( $post_id ) {
123
-
124
-		$videos = $this->video_storage->get_all_videos( $post_id );
125
-
126
-		$jsonld = array();
127
-
128
-		foreach ( $videos as $video ) {
129
-			/**
130
-			 * @var $video Video
131
-			 */
132
-			$description = $video->description;
133
-			if ( ! $video->description ) {
134
-				// If description is empty then use the video title as description
135
-				$description = $video->name;
136
-			}
137
-			$single_jsonld = array(
138
-				'@context'     => 'http://schema.org',
139
-				'@type'        => 'VideoObject',
140
-				'name'         => $video->name,
141
-				'description'  => $description,
142
-				'contentUrl'   => $video->content_url,
143
-				'uploadDate'   => $video->upload_date,
144
-				'thumbnailUrl' => $video->thumbnail_urls,
145
-				'duration'     => $video->duration,
146
-			);
147
-
148
-			if ( $video->embed_url ) {
149
-				$single_jsonld['embedUrl'] = $video->embed_url;
150
-			}
151
-
152
-			if ( $video->views ) {
153
-				$single_jsonld['interactionStatistic'] = array(
154
-					'@type'                => 'InteractionCounter',
155
-					'interactionType'      => array(
156
-						'@type' => 'http://schema.org/WatchAction',
157
-					),
158
-					'userInteractionCount' => $video->views,
159
-				);
160
-			}
161
-
162
-			if ( $video->is_live_video ) {
163
-				$single_jsonld['publication'] = array(
164
-					'@type'           => 'BroadcastEvent',
165
-					'isLiveBroadcast' => true,
166
-					'startDate'       => $video->live_video_start_date,
167
-					'endDate'         => $video->live_video_end_date,
168
-				);
169
-			}
170
-
171
-			$jsonld[] = $single_jsonld;
172
-		}
173
-
174
-		return $jsonld;
175
-	}
176
-
177
-	private function is_associative_array( $arr ) {
178
-		if ( array() === $arr ) {
179
-			return false;
180
-		}
181
-
182
-		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
183
-	}
14
+    /**
15
+     * @var Storage
16
+     */
17
+    private $video_storage;
18
+
19
+    /**
20
+     * Jsonld constructor.
21
+     *
22
+     * @param $video_storage Storage
23
+     */
24
+    public function __construct( $video_storage ) {
25
+        add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 );
26
+        add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
27
+        $this->video_storage = $video_storage;
28
+    }
29
+
30
+    public function wl_after_get_jsonld( $jsonld, $post_id ) {
31
+        if ( 0 === count( $jsonld ) ) {
32
+            return $jsonld;
33
+        }
34
+        $current_item = $jsonld[0];
35
+
36
+        if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) {
37
+            // Cant determine type return early.
38
+            return $jsonld;
39
+        }
40
+
41
+        $type = $current_item['@type'];
42
+        if ( is_string( $type ) ) {
43
+            $type = array( $type );
44
+        }
45
+        // If its a article or descendant of article, then dont add the
46
+        // videoobject in this hook, they will be already added to video property.
47
+        if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) {
48
+            return $jsonld;
49
+        }
50
+
51
+        $videos_jsonld = $this->get_videos_jsonld( $post_id );
52
+        if ( 0 === count( $videos_jsonld ) ) {
53
+            return $jsonld;
54
+        }
55
+
56
+        // check if we have @id in jsonld for first item.
57
+        $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : '';
58
+
59
+        foreach ( $videos_jsonld as &$video_jsonld ) {
60
+            if ( ! $id ) {
61
+                continue;
62
+            }
63
+            if ( ! array_key_exists( 'mentions', $video_jsonld ) ) {
64
+                $video_jsonld['mentions'] = array( '@id' => $id );
65
+            } else {
66
+                $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) );
67
+            }
68
+        }
69
+
70
+        return array_merge( $jsonld, $videos_jsonld );
71
+    }
72
+
73
+    /**
74
+     * @param $existing_video_data string | array associative or sequential array.
75
+     * @param $new_video_data array Sequential array.
76
+     *
77
+     * @return array
78
+     */
79
+    private function merge_video_data( $existing_video_data, $new_video_data ) {
80
+        if ( ! is_array( $existing_video_data ) ) {
81
+            $new_video_data[] = $existing_video_data;
82
+
83
+            return $new_video_data;
84
+        }
85
+
86
+        if ( $this->is_associative_array( $existing_video_data ) ) {
87
+            $new_video_data[] = $existing_video_data;
88
+
89
+            return $new_video_data;
90
+        }
91
+
92
+        return array_merge( $existing_video_data, $new_video_data );
93
+    }
94
+
95
+    public function wl_post_jsonld( $jsonld, $post_id ) {
96
+
97
+        $video_jsonld = $this->get_videos_jsonld( $post_id );
98
+        if ( count( $video_jsonld ) === 0 ) {
99
+            return $jsonld;
100
+        }
101
+        // Before adding the video jsonld check if the key
102
+        // is present and additional data might be present,
103
+        // if not present just add the data and return early.
104
+        if ( ! array_key_exists( 'video', $jsonld ) ) {
105
+            $jsonld['video'] = $video_jsonld;
106
+
107
+            return $jsonld;
108
+        }
109
+
110
+        // since key exists, we need to merge the data based on type.
111
+        $previous_video_data = $jsonld['video'];
112
+        $jsonld['video']     = $this->merge_video_data( $previous_video_data, $video_jsonld );
113
+
114
+        return $jsonld;
115
+    }
116
+
117
+    /**
118
+     * @param $post_id int Post id.
119
+     *
120
+     * @return array
121
+     */
122
+    public function get_videos_jsonld( $post_id ) {
123
+
124
+        $videos = $this->video_storage->get_all_videos( $post_id );
125
+
126
+        $jsonld = array();
127
+
128
+        foreach ( $videos as $video ) {
129
+            /**
130
+             * @var $video Video
131
+             */
132
+            $description = $video->description;
133
+            if ( ! $video->description ) {
134
+                // If description is empty then use the video title as description
135
+                $description = $video->name;
136
+            }
137
+            $single_jsonld = array(
138
+                '@context'     => 'http://schema.org',
139
+                '@type'        => 'VideoObject',
140
+                'name'         => $video->name,
141
+                'description'  => $description,
142
+                'contentUrl'   => $video->content_url,
143
+                'uploadDate'   => $video->upload_date,
144
+                'thumbnailUrl' => $video->thumbnail_urls,
145
+                'duration'     => $video->duration,
146
+            );
147
+
148
+            if ( $video->embed_url ) {
149
+                $single_jsonld['embedUrl'] = $video->embed_url;
150
+            }
151
+
152
+            if ( $video->views ) {
153
+                $single_jsonld['interactionStatistic'] = array(
154
+                    '@type'                => 'InteractionCounter',
155
+                    'interactionType'      => array(
156
+                        '@type' => 'http://schema.org/WatchAction',
157
+                    ),
158
+                    'userInteractionCount' => $video->views,
159
+                );
160
+            }
161
+
162
+            if ( $video->is_live_video ) {
163
+                $single_jsonld['publication'] = array(
164
+                    '@type'           => 'BroadcastEvent',
165
+                    'isLiveBroadcast' => true,
166
+                    'startDate'       => $video->live_video_start_date,
167
+                    'endDate'         => $video->live_video_end_date,
168
+                );
169
+            }
170
+
171
+            $jsonld[] = $single_jsonld;
172
+        }
173
+
174
+        return $jsonld;
175
+    }
176
+
177
+    private function is_associative_array( $arr ) {
178
+        if ( array() === $arr ) {
179
+            return false;
180
+        }
181
+
182
+        return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
183
+    }
184 184
 
185 185
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -21,53 +21,53 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param $video_storage Storage
23 23
 	 */
24
-	public function __construct( $video_storage ) {
25
-		add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 );
26
-		add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
24
+	public function __construct($video_storage) {
25
+		add_action('wl_post_jsonld', array($this, 'wl_post_jsonld'), 10, 2);
26
+		add_action('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2);
27 27
 		$this->video_storage = $video_storage;
28 28
 	}
29 29
 
30
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
31
-		if ( 0 === count( $jsonld ) ) {
30
+	public function wl_after_get_jsonld($jsonld, $post_id) {
31
+		if (0 === count($jsonld)) {
32 32
 			return $jsonld;
33 33
 		}
34 34
 		$current_item = $jsonld[0];
35 35
 
36
-		if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) {
36
+		if ( ! is_array($current_item) || ! array_key_exists('@type', $current_item)) {
37 37
 			// Cant determine type return early.
38 38
 			return $jsonld;
39 39
 		}
40 40
 
41 41
 		$type = $current_item['@type'];
42
-		if ( is_string( $type ) ) {
43
-			$type = array( $type );
42
+		if (is_string($type)) {
43
+			$type = array($type);
44 44
 		}
45 45
 		// If its a article or descendant of article, then dont add the
46 46
 		// videoobject in this hook, they will be already added to video property.
47
-		if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) {
47
+		if (array_intersect(Jsonld_Article_Wrapper::$article_types, $type)) {
48 48
 			return $jsonld;
49 49
 		}
50 50
 
51
-		$videos_jsonld = $this->get_videos_jsonld( $post_id );
52
-		if ( 0 === count( $videos_jsonld ) ) {
51
+		$videos_jsonld = $this->get_videos_jsonld($post_id);
52
+		if (0 === count($videos_jsonld)) {
53 53
 			return $jsonld;
54 54
 		}
55 55
 
56 56
 		// check if we have @id in jsonld for first item.
57
-		$id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : '';
57
+		$id = array_key_exists('@id', $current_item) ? $current_item['@id'] : '';
58 58
 
59
-		foreach ( $videos_jsonld as &$video_jsonld ) {
60
-			if ( ! $id ) {
59
+		foreach ($videos_jsonld as &$video_jsonld) {
60
+			if ( ! $id) {
61 61
 				continue;
62 62
 			}
63
-			if ( ! array_key_exists( 'mentions', $video_jsonld ) ) {
64
-				$video_jsonld['mentions'] = array( '@id' => $id );
63
+			if ( ! array_key_exists('mentions', $video_jsonld)) {
64
+				$video_jsonld['mentions'] = array('@id' => $id);
65 65
 			} else {
66
-				$video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) );
66
+				$video_jsonld['mentions'] = array_merge($video_jsonld['mentions'], array('@id' => $id));
67 67
 			}
68 68
 		}
69 69
 
70
-		return array_merge( $jsonld, $videos_jsonld );
70
+		return array_merge($jsonld, $videos_jsonld);
71 71
 	}
72 72
 
73 73
 	/**
@@ -76,32 +76,32 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return array
78 78
 	 */
79
-	private function merge_video_data( $existing_video_data, $new_video_data ) {
80
-		if ( ! is_array( $existing_video_data ) ) {
79
+	private function merge_video_data($existing_video_data, $new_video_data) {
80
+		if ( ! is_array($existing_video_data)) {
81 81
 			$new_video_data[] = $existing_video_data;
82 82
 
83 83
 			return $new_video_data;
84 84
 		}
85 85
 
86
-		if ( $this->is_associative_array( $existing_video_data ) ) {
86
+		if ($this->is_associative_array($existing_video_data)) {
87 87
 			$new_video_data[] = $existing_video_data;
88 88
 
89 89
 			return $new_video_data;
90 90
 		}
91 91
 
92
-		return array_merge( $existing_video_data, $new_video_data );
92
+		return array_merge($existing_video_data, $new_video_data);
93 93
 	}
94 94
 
95
-	public function wl_post_jsonld( $jsonld, $post_id ) {
95
+	public function wl_post_jsonld($jsonld, $post_id) {
96 96
 
97
-		$video_jsonld = $this->get_videos_jsonld( $post_id );
98
-		if ( count( $video_jsonld ) === 0 ) {
97
+		$video_jsonld = $this->get_videos_jsonld($post_id);
98
+		if (count($video_jsonld) === 0) {
99 99
 			return $jsonld;
100 100
 		}
101 101
 		// Before adding the video jsonld check if the key
102 102
 		// is present and additional data might be present,
103 103
 		// if not present just add the data and return early.
104
-		if ( ! array_key_exists( 'video', $jsonld ) ) {
104
+		if ( ! array_key_exists('video', $jsonld)) {
105 105
 			$jsonld['video'] = $video_jsonld;
106 106
 
107 107
 			return $jsonld;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
 		// since key exists, we need to merge the data based on type.
111 111
 		$previous_video_data = $jsonld['video'];
112
-		$jsonld['video']     = $this->merge_video_data( $previous_video_data, $video_jsonld );
112
+		$jsonld['video']     = $this->merge_video_data($previous_video_data, $video_jsonld);
113 113
 
114 114
 		return $jsonld;
115 115
 	}
@@ -119,18 +119,18 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_videos_jsonld( $post_id ) {
122
+	public function get_videos_jsonld($post_id) {
123 123
 
124
-		$videos = $this->video_storage->get_all_videos( $post_id );
124
+		$videos = $this->video_storage->get_all_videos($post_id);
125 125
 
126 126
 		$jsonld = array();
127 127
 
128
-		foreach ( $videos as $video ) {
128
+		foreach ($videos as $video) {
129 129
 			/**
130 130
 			 * @var $video Video
131 131
 			 */
132 132
 			$description = $video->description;
133
-			if ( ! $video->description ) {
133
+			if ( ! $video->description) {
134 134
 				// If description is empty then use the video title as description
135 135
 				$description = $video->name;
136 136
 			}
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 				'duration'     => $video->duration,
146 146
 			);
147 147
 
148
-			if ( $video->embed_url ) {
148
+			if ($video->embed_url) {
149 149
 				$single_jsonld['embedUrl'] = $video->embed_url;
150 150
 			}
151 151
 
152
-			if ( $video->views ) {
152
+			if ($video->views) {
153 153
 				$single_jsonld['interactionStatistic'] = array(
154 154
 					'@type'                => 'InteractionCounter',
155 155
 					'interactionType'      => array(
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 				);
160 160
 			}
161 161
 
162
-			if ( $video->is_live_video ) {
162
+			if ($video->is_live_video) {
163 163
 				$single_jsonld['publication'] = array(
164 164
 					'@type'           => 'BroadcastEvent',
165 165
 					'isLiveBroadcast' => true,
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 		return $jsonld;
175 175
 	}
176 176
 
177
-	private function is_associative_array( $arr ) {
178
-		if ( array() === $arr ) {
177
+	private function is_associative_array($arr) {
178
+		if (array() === $arr) {
179 179
 			return false;
180 180
 		}
181 181
 
182
-		return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
182
+		return array_keys($arr) !== range(0, count($arr) - 1);
183 183
 	}
184 184
 
185 185
 }
Please login to merge, or discard this patch.
src/wordlift/videoobject/class-loader.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,25 +25,25 @@
 block discarded – undo
25 25
 
26 26
 	public function init_all_dependencies() {
27 27
 		$video_storage = Video_Storage_Factory::get_storage();
28
-		new Jsonld( $video_storage );
28
+		new Jsonld($video_storage);
29 29
 
30
-		$sitemap_cache = new Ttl_Cache( 'wl_video_sitemap', 86400 );
30
+		$sitemap_cache = new Ttl_Cache('wl_video_sitemap', 86400);
31 31
 
32 32
 		$video_processor = new Video_Processor();
33 33
 		// Hook in to save_post to save the videos
34
-		$post_filter = new Post_Filter( $video_processor );
34
+		$post_filter = new Post_Filter($video_processor);
35 35
 		$post_filter->init();
36 36
 		// Add entry to wordlift admin tabs
37 37
 		$settings_tab = new Settings_Tab();
38 38
 		$settings_tab->init();
39 39
 
40
-		$video_sitemap = new Video_Sitemap( $sitemap_cache );
40
+		$video_sitemap = new Video_Sitemap($sitemap_cache);
41 41
 		$video_sitemap->init();
42 42
 
43
-		$background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' );
44
-		$background_process             = new Videoobject_Background_Process( $video_processor, $background_process_data_source );
43
+		$background_process_data_source = new Videos_Data_Source('__wl_videoobject_import_state');
44
+		$background_process             = new Videoobject_Background_Process($video_processor, $background_process_data_source);
45 45
 
46
-		$rest_controller = new Rest_Controller( $background_process );
46
+		$rest_controller = new Rest_Controller($background_process);
47 47
 		$rest_controller->register_all_routes();
48 48
 
49 49
 		$post_edit_screen = new Post_Edit_Screen();
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -24,60 +24,60 @@
 block discarded – undo
24 24
  */
25 25
 class Loader extends Default_Loader {
26 26
 
27
-	public function init_all_dependencies() {
28
-		$video_storage = Video_Storage_Factory::get_storage();
29
-		new Jsonld( $video_storage );
30
-
31
-		$sitemap_cache = new Ttl_Cache( 'wl_video_sitemap', 86400 );
32
-
33
-		$video_processor = new Video_Processor();
34
-		// Hook in to save_post to save the videos
35
-		$post_filter = new Post_Filter( $video_processor );
36
-		$post_filter->init();
37
-		// Add entry to wordlift admin tabs
38
-		$settings_tab = new Settings_Tab();
39
-		$settings_tab->init();
40
-
41
-		$video_sitemap = new Video_Sitemap( $sitemap_cache );
42
-		$video_sitemap->init();
43
-
44
-		$background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' );
45
-		$background_process             = new Videoobject_Background_Process( $video_processor, $background_process_data_source );
46
-
47
-		$rest_controller = new Rest_Controller( $background_process );
48
-		$rest_controller->register_all_routes();
49
-
50
-		$post_edit_screen = new Post_Edit_Screen();
51
-		$post_edit_screen->init();
52
-
53
-		new Import_Videos_Page();
54
-
55
-		/**
56
-		 * @since 3.32.0
57
-		 * Allow videoobject to capture embed shortcode.
58
-		 */
59
-		$embed_shortcode_capture = new Embed_Shortcode_Capture();
60
-		$embed_shortcode_capture->init();
61
-
62
-		/**
63
-		 * @since 3.32.0
64
-		 * Get videos from jw player.
65
-		 */
66
-		$jw_player_capture_videos = new Jw_Player_Capture();
67
-		$jw_player_capture_videos->init();
68
-
69
-		/**
70
-		 * Validate API Key for Youtube, Vimeo.
71
-		 */
72
-		new Video_Key_Validation_Service();
73
-
74
-	}
75
-
76
-	public function get_feature_slug() {
77
-		return 'videoobject';
78
-	}
79
-
80
-	public function get_feature_default_value() {
81
-		return false;
82
-	}
27
+    public function init_all_dependencies() {
28
+        $video_storage = Video_Storage_Factory::get_storage();
29
+        new Jsonld( $video_storage );
30
+
31
+        $sitemap_cache = new Ttl_Cache( 'wl_video_sitemap', 86400 );
32
+
33
+        $video_processor = new Video_Processor();
34
+        // Hook in to save_post to save the videos
35
+        $post_filter = new Post_Filter( $video_processor );
36
+        $post_filter->init();
37
+        // Add entry to wordlift admin tabs
38
+        $settings_tab = new Settings_Tab();
39
+        $settings_tab->init();
40
+
41
+        $video_sitemap = new Video_Sitemap( $sitemap_cache );
42
+        $video_sitemap->init();
43
+
44
+        $background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' );
45
+        $background_process             = new Videoobject_Background_Process( $video_processor, $background_process_data_source );
46
+
47
+        $rest_controller = new Rest_Controller( $background_process );
48
+        $rest_controller->register_all_routes();
49
+
50
+        $post_edit_screen = new Post_Edit_Screen();
51
+        $post_edit_screen->init();
52
+
53
+        new Import_Videos_Page();
54
+
55
+        /**
56
+         * @since 3.32.0
57
+         * Allow videoobject to capture embed shortcode.
58
+         */
59
+        $embed_shortcode_capture = new Embed_Shortcode_Capture();
60
+        $embed_shortcode_capture->init();
61
+
62
+        /**
63
+         * @since 3.32.0
64
+         * Get videos from jw player.
65
+         */
66
+        $jw_player_capture_videos = new Jw_Player_Capture();
67
+        $jw_player_capture_videos->init();
68
+
69
+        /**
70
+         * Validate API Key for Youtube, Vimeo.
71
+         */
72
+        new Video_Key_Validation_Service();
73
+
74
+    }
75
+
76
+    public function get_feature_slug() {
77
+        return 'videoobject';
78
+    }
79
+
80
+    public function get_feature_default_value() {
81
+        return false;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
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.