Completed
Pull Request — master (#1641)
by Naveen
01:35
created
src/wordlift/videoobject/data/video-storage/class-meta-storage.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -8,57 +8,57 @@
 block discarded – undo
8 8
 
9 9
 class Meta_Storage implements Storage {
10 10
 
11
-	const META_KEY = '_wl_video_object_videos';
11
+    const META_KEY = '_wl_video_object_videos';
12 12
 
13
-	public function add_video( $post_id, $video ) {
14
-		/**
15
-		 * @since 3.31.0
16
-		 * Fires when the video storage gets updated
17
-		 */
18
-		do_action( 'wordlift_videoobject_video_storage_updated' );
19
-		add_post_meta( $post_id, self::META_KEY, $video );
20
-	}
13
+    public function add_video( $post_id, $video ) {
14
+        /**
15
+         * @since 3.31.0
16
+         * Fires when the video storage gets updated
17
+         */
18
+        do_action( 'wordlift_videoobject_video_storage_updated' );
19
+        add_post_meta( $post_id, self::META_KEY, $video );
20
+    }
21 21
 
22
-	public function get_all_videos( $post_id ) {
22
+    public function get_all_videos( $post_id ) {
23 23
 
24
-		return get_post_meta( $post_id, self::META_KEY );
24
+        return get_post_meta( $post_id, self::META_KEY );
25 25
 
26
-	}
26
+    }
27 27
 
28
-	public function remove_videos( $videos_to_be_removed, $post_id ) {
29
-		/**
30
-		 * @since 3.31.0
31
-		 * Fires when the video storage gets updated
32
-		 */
33
-		do_action( 'wordlift_videoobject_video_storage_updated' );
34
-		$videos_to_be_removed_ids = array_map(
35
-			function ( $video ) {
36
-				return $video->id;
37
-			},
38
-			$videos_to_be_removed
39
-		);
28
+    public function remove_videos( $videos_to_be_removed, $post_id ) {
29
+        /**
30
+         * @since 3.31.0
31
+         * Fires when the video storage gets updated
32
+         */
33
+        do_action( 'wordlift_videoobject_video_storage_updated' );
34
+        $videos_to_be_removed_ids = array_map(
35
+            function ( $video ) {
36
+                return $video->id;
37
+            },
38
+            $videos_to_be_removed
39
+        );
40 40
 
41
-		$present_videos = $this->get_all_videos( $post_id );
41
+        $present_videos = $this->get_all_videos( $post_id );
42 42
 
43
-		$filtered_videos = array_filter(
44
-			$present_videos,
45
-			function ( $video ) use ( $videos_to_be_removed_ids ) {
46
-				// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
47
-				return ! in_array( $video->id, $videos_to_be_removed_ids );
48
-			}
49
-		);
43
+        $filtered_videos = array_filter(
44
+            $present_videos,
45
+            function ( $video ) use ( $videos_to_be_removed_ids ) {
46
+                // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
47
+                return ! in_array( $video->id, $videos_to_be_removed_ids );
48
+            }
49
+        );
50 50
 
51
-		// Remove all existing videos.
52
-		$this->remove_all_videos( $post_id );
51
+        // Remove all existing videos.
52
+        $this->remove_all_videos( $post_id );
53 53
 
54
-		// Save the remaining videos.
55
-		foreach ( $filtered_videos as $video ) {
56
-			$this->add_video( $post_id, $video );
57
-		}
54
+        // Save the remaining videos.
55
+        foreach ( $filtered_videos as $video ) {
56
+            $this->add_video( $post_id, $video );
57
+        }
58 58
 
59
-	}
59
+    }
60 60
 
61
-	public function remove_all_videos( $post_id ) {
62
-		delete_post_meta( $post_id, self::META_KEY );
63
-	}
61
+    public function remove_all_videos( $post_id ) {
62
+        delete_post_meta( $post_id, self::META_KEY );
63
+    }
64 64
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,55 +10,55 @@
 block discarded – undo
10 10
 
11 11
 	const META_KEY = '_wl_video_object_videos';
12 12
 
13
-	public function add_video( $post_id, $video ) {
13
+	public function add_video($post_id, $video) {
14 14
 		/**
15 15
 		 * @since 3.31.0
16 16
 		 * Fires when the video storage gets updated
17 17
 		 */
18
-		do_action( 'wordlift_videoobject_video_storage_updated' );
19
-		add_post_meta( $post_id, self::META_KEY, $video );
18
+		do_action('wordlift_videoobject_video_storage_updated');
19
+		add_post_meta($post_id, self::META_KEY, $video);
20 20
 	}
21 21
 
22
-	public function get_all_videos( $post_id ) {
22
+	public function get_all_videos($post_id) {
23 23
 
24
-		return get_post_meta( $post_id, self::META_KEY );
24
+		return get_post_meta($post_id, self::META_KEY);
25 25
 
26 26
 	}
27 27
 
28
-	public function remove_videos( $videos_to_be_removed, $post_id ) {
28
+	public function remove_videos($videos_to_be_removed, $post_id) {
29 29
 		/**
30 30
 		 * @since 3.31.0
31 31
 		 * Fires when the video storage gets updated
32 32
 		 */
33
-		do_action( 'wordlift_videoobject_video_storage_updated' );
33
+		do_action('wordlift_videoobject_video_storage_updated');
34 34
 		$videos_to_be_removed_ids = array_map(
35
-			function ( $video ) {
35
+			function($video) {
36 36
 				return $video->id;
37 37
 			},
38 38
 			$videos_to_be_removed
39 39
 		);
40 40
 
41
-		$present_videos = $this->get_all_videos( $post_id );
41
+		$present_videos = $this->get_all_videos($post_id);
42 42
 
43 43
 		$filtered_videos = array_filter(
44 44
 			$present_videos,
45
-			function ( $video ) use ( $videos_to_be_removed_ids ) {
45
+			function($video) use ($videos_to_be_removed_ids) {
46 46
 				// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
47
-				return ! in_array( $video->id, $videos_to_be_removed_ids );
47
+				return ! in_array($video->id, $videos_to_be_removed_ids);
48 48
 			}
49 49
 		);
50 50
 
51 51
 		// Remove all existing videos.
52
-		$this->remove_all_videos( $post_id );
52
+		$this->remove_all_videos($post_id);
53 53
 
54 54
 		// Save the remaining videos.
55
-		foreach ( $filtered_videos as $video ) {
56
-			$this->add_video( $post_id, $video );
55
+		foreach ($filtered_videos as $video) {
56
+			$this->add_video($post_id, $video);
57 57
 		}
58 58
 
59 59
 	}
60 60
 
61
-	public function remove_all_videos( $post_id ) {
62
-		delete_post_meta( $post_id, self::META_KEY );
61
+	public function remove_all_videos($post_id) {
62
+		delete_post_meta($post_id, self::META_KEY);
63 63
 	}
64 64
 }
Please login to merge, or discard this patch.
src/wordlift/videoobject/sitemap/class-xml-generator.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -12,111 +12,111 @@  discard block
 block discarded – undo
12 12
 
13 13
 class Xml_Generator {
14 14
 
15
-	private static function iso8601_to_seconds( $iso8601_interval_string ) {
16
-		try {
17
-			$interval = new \DateInterval( $iso8601_interval_string );
18
-		} catch ( \Exception $e ) {
19
-			return 0;
20
-		}
21
-
22
-		$days_to_seconds    = $interval->d * 60 * 60 * 24;
23
-		$hours_to_seconds   = $interval->h * 60 * 60;
24
-		$minutes_to_seconds = $interval->i * 60;
25
-		$seconds            = $interval->s;
26
-
27
-		return $days_to_seconds + $hours_to_seconds + $minutes_to_seconds + $seconds;
28
-
29
-	}
30
-
31
-	public static function get_xml_for_all_posts_with_videos() {
32
-		/**
33
-		 * @since 3.31.6
34
-		 * Filter the query args, add support for all custom public post types.
35
-		 */
36
-		$video_sitemap_query_args = apply_filters(
37
-			'wl_videoobject_sitemap_query_args',
38
-			array(
39
-				'fields'      => 'ids',
40
-				'numberposts' => - 1,
41
-				'post_type'   => get_post_types( array( 'public' => true ) ),
42
-				'meta_query'  => array(
43
-					array(
44
-						'key'     => Meta_Storage::META_KEY,
45
-						'compare' => 'EXISTS',
46
-					),
47
-				),
48
-			)
49
-		);
50
-
51
-		$posts = get_posts( $video_sitemap_query_args );
52
-
53
-		$all_posts_xml = '';
54
-
55
-		if ( ! $posts ) {
56
-			return $all_posts_xml;
57
-		}
58
-
59
-		foreach ( $posts as $post_id ) {
60
-			$all_posts_xml .= self::get_xml_for_single_post( $post_id );
61
-		}
62
-
63
-		return $all_posts_xml;
64
-
65
-	}
66
-
67
-	/**
68
-	 * @param $post_id
69
-	 *
70
-	 * @return string XML string for single post.
71
-	 */
72
-	public static function get_xml_for_single_post( $post_id ) {
73
-		$videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id );
74
-		if ( ! $videos ) {
75
-			return '';
76
-		}
77
-		$single_post_xml = '';
78
-		foreach ( $videos as $video ) {
79
-			$single_post_xml .= self::get_xml_for_single_video( $video, $post_id );
80
-		}
81
-
82
-		return $single_post_xml;
83
-
84
-	}
85
-
86
-	/**
87
-	 * @param $video Video
88
-	 * @param $post_id int
89
-	 *
90
-	 * @return string
91
-	 */
92
-	public static function get_xml_for_single_video( $video, $post_id ) {
93
-
94
-		$permalink     = get_permalink( $post_id );
95
-		$title         = esc_html( $video->name );
96
-		$description   = esc_html( $video->description );
97
-		$thumbnail_url = $video->thumbnail_urls[0];
98
-
99
-		// If description is empty use title.
100
-		if ( ! $description ) {
101
-			$description = $title;
102
-		}
103
-
104
-		$optional_fields = array(
105
-			'content_loc' => $video->content_url,
106
-			'player_loc'  => $video->embed_url,
107
-			'duration'    => self::iso8601_to_seconds( $video->duration ),
108
-			'view_count'  => $video->views,
109
-			'live'        => $video->is_live_video ? 'yes' : 'no',
110
-		);
111
-
112
-		$optional_data = '';
113
-		foreach ( $optional_fields as $xml_key => $xml_value ) {
114
-			if ( $xml_value ) {
115
-				$optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>";
116
-			}
117
-		}
118
-
119
-		return "
15
+    private static function iso8601_to_seconds( $iso8601_interval_string ) {
16
+        try {
17
+            $interval = new \DateInterval( $iso8601_interval_string );
18
+        } catch ( \Exception $e ) {
19
+            return 0;
20
+        }
21
+
22
+        $days_to_seconds    = $interval->d * 60 * 60 * 24;
23
+        $hours_to_seconds   = $interval->h * 60 * 60;
24
+        $minutes_to_seconds = $interval->i * 60;
25
+        $seconds            = $interval->s;
26
+
27
+        return $days_to_seconds + $hours_to_seconds + $minutes_to_seconds + $seconds;
28
+
29
+    }
30
+
31
+    public static function get_xml_for_all_posts_with_videos() {
32
+        /**
33
+         * @since 3.31.6
34
+         * Filter the query args, add support for all custom public post types.
35
+         */
36
+        $video_sitemap_query_args = apply_filters(
37
+            'wl_videoobject_sitemap_query_args',
38
+            array(
39
+                'fields'      => 'ids',
40
+                'numberposts' => - 1,
41
+                'post_type'   => get_post_types( array( 'public' => true ) ),
42
+                'meta_query'  => array(
43
+                    array(
44
+                        'key'     => Meta_Storage::META_KEY,
45
+                        'compare' => 'EXISTS',
46
+                    ),
47
+                ),
48
+            )
49
+        );
50
+
51
+        $posts = get_posts( $video_sitemap_query_args );
52
+
53
+        $all_posts_xml = '';
54
+
55
+        if ( ! $posts ) {
56
+            return $all_posts_xml;
57
+        }
58
+
59
+        foreach ( $posts as $post_id ) {
60
+            $all_posts_xml .= self::get_xml_for_single_post( $post_id );
61
+        }
62
+
63
+        return $all_posts_xml;
64
+
65
+    }
66
+
67
+    /**
68
+     * @param $post_id
69
+     *
70
+     * @return string XML string for single post.
71
+     */
72
+    public static function get_xml_for_single_post( $post_id ) {
73
+        $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id );
74
+        if ( ! $videos ) {
75
+            return '';
76
+        }
77
+        $single_post_xml = '';
78
+        foreach ( $videos as $video ) {
79
+            $single_post_xml .= self::get_xml_for_single_video( $video, $post_id );
80
+        }
81
+
82
+        return $single_post_xml;
83
+
84
+    }
85
+
86
+    /**
87
+     * @param $video Video
88
+     * @param $post_id int
89
+     *
90
+     * @return string
91
+     */
92
+    public static function get_xml_for_single_video( $video, $post_id ) {
93
+
94
+        $permalink     = get_permalink( $post_id );
95
+        $title         = esc_html( $video->name );
96
+        $description   = esc_html( $video->description );
97
+        $thumbnail_url = $video->thumbnail_urls[0];
98
+
99
+        // If description is empty use title.
100
+        if ( ! $description ) {
101
+            $description = $title;
102
+        }
103
+
104
+        $optional_fields = array(
105
+            'content_loc' => $video->content_url,
106
+            'player_loc'  => $video->embed_url,
107
+            'duration'    => self::iso8601_to_seconds( $video->duration ),
108
+            'view_count'  => $video->views,
109
+            'live'        => $video->is_live_video ? 'yes' : 'no',
110
+        );
111
+
112
+        $optional_data = '';
113
+        foreach ( $optional_fields as $xml_key => $xml_value ) {
114
+            if ( $xml_value ) {
115
+                $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>";
116
+            }
117
+        }
118
+
119
+        return "
120 120
    <url>
121 121
      <loc>${permalink}</loc>
122 122
      <video:video>
@@ -128,6 +128,6 @@  discard block
 block discarded – undo
128 128
    </url>
129 129
 ";
130 130
 
131
-	}
131
+    }
132 132
 
133 133
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 class Xml_Generator {
14 14
 
15
-	private static function iso8601_to_seconds( $iso8601_interval_string ) {
15
+	private static function iso8601_to_seconds($iso8601_interval_string) {
16 16
 		try {
17
-			$interval = new \DateInterval( $iso8601_interval_string );
18
-		} catch ( \Exception $e ) {
17
+			$interval = new \DateInterval($iso8601_interval_string);
18
+		} catch (\Exception $e) {
19 19
 			return 0;
20 20
 		}
21 21
 
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 			'wl_videoobject_sitemap_query_args',
38 38
 			array(
39 39
 				'fields'      => 'ids',
40
-				'numberposts' => - 1,
41
-				'post_type'   => get_post_types( array( 'public' => true ) ),
40
+				'numberposts' => -1,
41
+				'post_type'   => get_post_types(array('public' => true)),
42 42
 				'meta_query'  => array(
43 43
 					array(
44 44
 						'key'     => Meta_Storage::META_KEY,
@@ -48,16 +48,16 @@  discard block
 block discarded – undo
48 48
 			)
49 49
 		);
50 50
 
51
-		$posts = get_posts( $video_sitemap_query_args );
51
+		$posts = get_posts($video_sitemap_query_args);
52 52
 
53 53
 		$all_posts_xml = '';
54 54
 
55
-		if ( ! $posts ) {
55
+		if ( ! $posts) {
56 56
 			return $all_posts_xml;
57 57
 		}
58 58
 
59
-		foreach ( $posts as $post_id ) {
60
-			$all_posts_xml .= self::get_xml_for_single_post( $post_id );
59
+		foreach ($posts as $post_id) {
60
+			$all_posts_xml .= self::get_xml_for_single_post($post_id);
61 61
 		}
62 62
 
63 63
 		return $all_posts_xml;
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string XML string for single post.
71 71
 	 */
72
-	public static function get_xml_for_single_post( $post_id ) {
73
-		$videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id );
74
-		if ( ! $videos ) {
72
+	public static function get_xml_for_single_post($post_id) {
73
+		$videos = Video_Storage_Factory::get_storage()->get_all_videos($post_id);
74
+		if ( ! $videos) {
75 75
 			return '';
76 76
 		}
77 77
 		$single_post_xml = '';
78
-		foreach ( $videos as $video ) {
79
-			$single_post_xml .= self::get_xml_for_single_video( $video, $post_id );
78
+		foreach ($videos as $video) {
79
+			$single_post_xml .= self::get_xml_for_single_video($video, $post_id);
80 80
 		}
81 81
 
82 82
 		return $single_post_xml;
@@ -89,29 +89,29 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return string
91 91
 	 */
92
-	public static function get_xml_for_single_video( $video, $post_id ) {
92
+	public static function get_xml_for_single_video($video, $post_id) {
93 93
 
94
-		$permalink     = get_permalink( $post_id );
95
-		$title         = esc_html( $video->name );
96
-		$description   = esc_html( $video->description );
94
+		$permalink     = get_permalink($post_id);
95
+		$title         = esc_html($video->name);
96
+		$description   = esc_html($video->description);
97 97
 		$thumbnail_url = $video->thumbnail_urls[0];
98 98
 
99 99
 		// If description is empty use title.
100
-		if ( ! $description ) {
100
+		if ( ! $description) {
101 101
 			$description = $title;
102 102
 		}
103 103
 
104 104
 		$optional_fields = array(
105 105
 			'content_loc' => $video->content_url,
106 106
 			'player_loc'  => $video->embed_url,
107
-			'duration'    => self::iso8601_to_seconds( $video->duration ),
107
+			'duration'    => self::iso8601_to_seconds($video->duration),
108 108
 			'view_count'  => $video->views,
109 109
 			'live'        => $video->is_live_video ? 'yes' : 'no',
110 110
 		);
111 111
 
112 112
 		$optional_data = '';
113
-		foreach ( $optional_fields as $xml_key => $xml_value ) {
114
-			if ( $xml_value ) {
113
+		foreach ($optional_fields as $xml_key => $xml_value) {
114
+			if ($xml_value) {
115 115
 				$optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>";
116 116
 			}
117 117
 		}
Please login to merge, or discard this patch.
src/wordlift/videoobject/class-video-processor.php 2 patches
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -12,249 +12,249 @@
 block discarded – undo
12 12
 
13 13
 class Video_Processor {
14 14
 
15
-	/**
16
-	 * @var array<Client>
17
-	 */
18
-	private $api_clients;
19
-
20
-	public function __construct() {
21
-		$this->api_clients = array(
22
-			Client_Factory::get_client( Client_Factory::YOUTUBE ),
23
-			Client_Factory::get_client( Client_Factory::VIMEO ),
24
-			Client_Factory::get_client( Client_Factory::JWPLAYER ),
25
-		);
26
-	}
27
-
28
-	private function get_data_for_videos( $embedded_videos ) {
29
-
30
-		$youtube_videos   = $this->get_youtube_videos( $embedded_videos );
31
-		$youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE );
32
-		$youtube_videos   = $youtube_provider->get_videos_data( $youtube_videos );
33
-
34
-		$vimeo_videos   = $this->get_vimeo_videos( $embedded_videos );
35
-		$vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO );
36
-		$vimeo_videos   = $vimeo_provider->get_videos_data( $vimeo_videos );
37
-
38
-		$jwplayer_videos   = $this->get_jw_player_videos( $embedded_videos );
39
-		$jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER );
40
-		$jwplayer_videos   = $jwplayer_provider->get_videos_data( $jwplayer_videos );
41
-
42
-		return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos );
43
-
44
-	}
45
-
46
-	private function get_video_ids( $video_urls ) {
47
-		$clients   = $this->api_clients;
48
-		$video_ids = array();
49
-		foreach ( $clients as $client ) {
50
-			$ids = $client->get_video_ids( $video_urls );
51
-			if ( $ids ) {
52
-				$video_ids = array_merge( $video_ids, $ids );
53
-			}
54
-		}
55
-
56
-		return array_unique( $video_ids );
57
-	}
58
-
59
-	/**
60
-	 * @param $storage Storage
61
-	 * @param $post_id int
62
-	 * @param $embedded_videos array<Embedded_Video>
63
-	 */
64
-	private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) {
65
-
66
-		$videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos );
67
-		$storage->remove_videos( $videos_to_be_deleted, $post_id );
68
-
69
-	}
70
-
71
-	/**
72
-	 * @param Storage $storage
73
-	 * @param $post_id
74
-	 * @param array   $embedded_videos
75
-	 *
76
-	 * @return array An array of videos which exist on storage, not on post content.
77
-	 */
78
-	private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) {
79
-		$videos_in_store     = $storage->get_all_videos( $post_id );
80
-		$embedded_video_urls = array_map(
81
-			function ( $embedded_video ) {
82
-				/**
83
-				 * @var $embedded_video Embedded_Video
84
-				 */
85
-				return $embedded_video->get_url();
86
-			},
87
-			$embedded_videos
88
-		);
89
-
90
-		/**
91
-		 * Previously we are checking if the captured url is content_url to delete it from the storage
92
-		 * but this might not work well if we want to support multiple URL formats, we extract the video
93
-		 * ids for embedded URLs.
94
-		 */
95
-		$embedded_video_ids = $this->get_video_ids( $embedded_video_urls );
96
-
97
-		$that = $this;
98
-
99
-		return array_filter(
100
-			$videos_in_store,
101
-			function ( $video ) use ( $embedded_video_ids, $that ) {
102
-				/**
103
-				 * If the video id doesn't exist on the content then we need to return it
104
-				 * in order to delete that video.
105
-				 */
106
-				return count(
107
-					array_intersect(
108
-						$that->get_video_ids( array( $video->id ) ),
109
-						$embedded_video_ids
110
-					)
111
-				) === 0;
112
-
113
-			}
114
-		);
115
-	}
116
-
117
-	/**
118
-	 * @param \WP_Post $post
119
-	 * @param $post_id
120
-	 */
121
-	public function process_video_urls( \WP_Post $post, $post_id ) {
122
-
123
-		$parser = Parser_Factory::get_parser_from_content( $post->post_content );
124
-
125
-		$embedded_videos = $parser->get_videos( $post_id );
126
-		/**
127
-		 * Filters the embedded videos on post contet, custom plugins can add their video urls
128
-		 * by constructing \Default_Embedded_Video or implement Embedded_Video class
129
-		 *
130
-		 * @param $embedded_videos array<Embedded_Video>
131
-		 * @param $post_id int The post id for the videoobject is processed.
132
-		 *
133
-		 * @return array<Embedded_Video>
134
-		 * @since 3.31.4
135
-		 * Filter name : wl_videoobject_embedded_videos
136
-		 */
137
-		$embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id );
138
-
139
-		$storage = Video_Storage_Factory::get_storage();
140
-
141
-		// Before sending api requests we need to check if there are any videos in
142
-		// store which is not present on post content, remove them if there are
143
-		// any
144
-		$this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos );
145
-
146
-		$embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos );
147
-
148
-		// Return early after removing all the videos.
149
-		if ( ! $embedded_videos ) {
150
-			return;
151
-		}
152
-
153
-		$videos = $this->get_data_for_videos( $embedded_videos );
154
-
155
-		if ( ! $videos ) {
156
-			return;
157
-		}
158
-
159
-		foreach ( $videos as $video ) {
160
-			$storage->add_video( $post_id, $video );
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * @param $storage Storage
166
-	 * @param $post_id int
167
-	 * @param $embedded_videos array<Embedded_Video>
168
-	 *
169
-	 * @return array<Embedded_Video> Return array of embedded videos which are not in store.
170
-	 */
171
-	private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) {
172
-		$videos_in_store     = $storage->get_all_videos( $post_id );
173
-		$video_urls_in_store = array_map(
174
-			function ( $video ) {
175
-				return $video->id;
176
-			},
177
-			$videos_in_store
178
-		);
179
-
180
-		$video_ids_in_store = $this->get_video_ids( $video_urls_in_store );
181
-
182
-		$that = $this;
183
-
184
-		return array_filter(
185
-			$embedded_videos,
186
-			function ( $embedded_video ) use ( $video_ids_in_store, $that ) {
187
-				/**
188
-				 * If the video id exist on content, not on storage then
189
-				 * we need to fetch the data.
190
-				 */
191
-				return count(
192
-					array_intersect(
193
-						$that->get_video_ids( array( $embedded_video->get_url() ) ),
194
-						$video_ids_in_store
195
-					)
196
-				) === 0;
197
-			}
198
-		);
199
-	}
200
-
201
-	/**
202
-	 * @param $embedded_videos
203
-	 *
204
-	 * @return array
205
-	 */
206
-	private function get_youtube_videos( $embedded_videos ) {
207
-		return array_filter(
208
-			$embedded_videos,
209
-			function ( $embedded_video ) {
210
-				/**
211
-				 * it should have youtube.com or youtu.be in the url
212
-				 *
213
-				 * @param $embedded_video Embedded_Video
214
-				 */
215
-				$video_url = $embedded_video->get_url();
216
-
217
-				return strpos( $video_url, 'youtube.com' ) !== false ||
218
-				   strpos( $video_url, 'youtu.be' ) !== false;
219
-			}
220
-		);
221
-	}
222
-
223
-	/**
224
-	 * @param $embedded_videos
225
-	 *
226
-	 * @return array
227
-	 */
228
-	private function get_vimeo_videos( $embedded_videos ) {
229
-		return array_filter(
230
-			$embedded_videos,
231
-			function ( $embedded_video ) {
232
-				/**
233
-				 * it should have vimeo.com in the url
234
-				 *
235
-				 * @param $embedded_video Embedded_Video
236
-				 */
237
-				$video_url = $embedded_video->get_url();
238
-
239
-				return strpos( $video_url, 'vimeo.com' ) !== false;
240
-			}
241
-		);
242
-	}
243
-
244
-	private function get_jw_player_videos( $embedded_videos ) {
245
-		return array_filter(
246
-			$embedded_videos,
247
-			function ( $embedded_video ) {
248
-				/**
249
-				 * it should have vimeo.com in the url
250
-				 *
251
-				 * @param $embedded_video Embedded_Video
252
-				 */
253
-				$video_url = $embedded_video->get_url();
254
-
255
-				return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false;
256
-			}
257
-		);
258
-	}
15
+    /**
16
+     * @var array<Client>
17
+     */
18
+    private $api_clients;
19
+
20
+    public function __construct() {
21
+        $this->api_clients = array(
22
+            Client_Factory::get_client( Client_Factory::YOUTUBE ),
23
+            Client_Factory::get_client( Client_Factory::VIMEO ),
24
+            Client_Factory::get_client( Client_Factory::JWPLAYER ),
25
+        );
26
+    }
27
+
28
+    private function get_data_for_videos( $embedded_videos ) {
29
+
30
+        $youtube_videos   = $this->get_youtube_videos( $embedded_videos );
31
+        $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE );
32
+        $youtube_videos   = $youtube_provider->get_videos_data( $youtube_videos );
33
+
34
+        $vimeo_videos   = $this->get_vimeo_videos( $embedded_videos );
35
+        $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO );
36
+        $vimeo_videos   = $vimeo_provider->get_videos_data( $vimeo_videos );
37
+
38
+        $jwplayer_videos   = $this->get_jw_player_videos( $embedded_videos );
39
+        $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER );
40
+        $jwplayer_videos   = $jwplayer_provider->get_videos_data( $jwplayer_videos );
41
+
42
+        return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos );
43
+
44
+    }
45
+
46
+    private function get_video_ids( $video_urls ) {
47
+        $clients   = $this->api_clients;
48
+        $video_ids = array();
49
+        foreach ( $clients as $client ) {
50
+            $ids = $client->get_video_ids( $video_urls );
51
+            if ( $ids ) {
52
+                $video_ids = array_merge( $video_ids, $ids );
53
+            }
54
+        }
55
+
56
+        return array_unique( $video_ids );
57
+    }
58
+
59
+    /**
60
+     * @param $storage Storage
61
+     * @param $post_id int
62
+     * @param $embedded_videos array<Embedded_Video>
63
+     */
64
+    private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) {
65
+
66
+        $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos );
67
+        $storage->remove_videos( $videos_to_be_deleted, $post_id );
68
+
69
+    }
70
+
71
+    /**
72
+     * @param Storage $storage
73
+     * @param $post_id
74
+     * @param array   $embedded_videos
75
+     *
76
+     * @return array An array of videos which exist on storage, not on post content.
77
+     */
78
+    private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) {
79
+        $videos_in_store     = $storage->get_all_videos( $post_id );
80
+        $embedded_video_urls = array_map(
81
+            function ( $embedded_video ) {
82
+                /**
83
+                 * @var $embedded_video Embedded_Video
84
+                 */
85
+                return $embedded_video->get_url();
86
+            },
87
+            $embedded_videos
88
+        );
89
+
90
+        /**
91
+         * Previously we are checking if the captured url is content_url to delete it from the storage
92
+         * but this might not work well if we want to support multiple URL formats, we extract the video
93
+         * ids for embedded URLs.
94
+         */
95
+        $embedded_video_ids = $this->get_video_ids( $embedded_video_urls );
96
+
97
+        $that = $this;
98
+
99
+        return array_filter(
100
+            $videos_in_store,
101
+            function ( $video ) use ( $embedded_video_ids, $that ) {
102
+                /**
103
+                 * If the video id doesn't exist on the content then we need to return it
104
+                 * in order to delete that video.
105
+                 */
106
+                return count(
107
+                    array_intersect(
108
+                        $that->get_video_ids( array( $video->id ) ),
109
+                        $embedded_video_ids
110
+                    )
111
+                ) === 0;
112
+
113
+            }
114
+        );
115
+    }
116
+
117
+    /**
118
+     * @param \WP_Post $post
119
+     * @param $post_id
120
+     */
121
+    public function process_video_urls( \WP_Post $post, $post_id ) {
122
+
123
+        $parser = Parser_Factory::get_parser_from_content( $post->post_content );
124
+
125
+        $embedded_videos = $parser->get_videos( $post_id );
126
+        /**
127
+         * Filters the embedded videos on post contet, custom plugins can add their video urls
128
+         * by constructing \Default_Embedded_Video or implement Embedded_Video class
129
+         *
130
+         * @param $embedded_videos array<Embedded_Video>
131
+         * @param $post_id int The post id for the videoobject is processed.
132
+         *
133
+         * @return array<Embedded_Video>
134
+         * @since 3.31.4
135
+         * Filter name : wl_videoobject_embedded_videos
136
+         */
137
+        $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id );
138
+
139
+        $storage = Video_Storage_Factory::get_storage();
140
+
141
+        // Before sending api requests we need to check if there are any videos in
142
+        // store which is not present on post content, remove them if there are
143
+        // any
144
+        $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos );
145
+
146
+        $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos );
147
+
148
+        // Return early after removing all the videos.
149
+        if ( ! $embedded_videos ) {
150
+            return;
151
+        }
152
+
153
+        $videos = $this->get_data_for_videos( $embedded_videos );
154
+
155
+        if ( ! $videos ) {
156
+            return;
157
+        }
158
+
159
+        foreach ( $videos as $video ) {
160
+            $storage->add_video( $post_id, $video );
161
+        }
162
+    }
163
+
164
+    /**
165
+     * @param $storage Storage
166
+     * @param $post_id int
167
+     * @param $embedded_videos array<Embedded_Video>
168
+     *
169
+     * @return array<Embedded_Video> Return array of embedded videos which are not in store.
170
+     */
171
+    private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) {
172
+        $videos_in_store     = $storage->get_all_videos( $post_id );
173
+        $video_urls_in_store = array_map(
174
+            function ( $video ) {
175
+                return $video->id;
176
+            },
177
+            $videos_in_store
178
+        );
179
+
180
+        $video_ids_in_store = $this->get_video_ids( $video_urls_in_store );
181
+
182
+        $that = $this;
183
+
184
+        return array_filter(
185
+            $embedded_videos,
186
+            function ( $embedded_video ) use ( $video_ids_in_store, $that ) {
187
+                /**
188
+                 * If the video id exist on content, not on storage then
189
+                 * we need to fetch the data.
190
+                 */
191
+                return count(
192
+                    array_intersect(
193
+                        $that->get_video_ids( array( $embedded_video->get_url() ) ),
194
+                        $video_ids_in_store
195
+                    )
196
+                ) === 0;
197
+            }
198
+        );
199
+    }
200
+
201
+    /**
202
+     * @param $embedded_videos
203
+     *
204
+     * @return array
205
+     */
206
+    private function get_youtube_videos( $embedded_videos ) {
207
+        return array_filter(
208
+            $embedded_videos,
209
+            function ( $embedded_video ) {
210
+                /**
211
+                 * it should have youtube.com or youtu.be in the url
212
+                 *
213
+                 * @param $embedded_video Embedded_Video
214
+                 */
215
+                $video_url = $embedded_video->get_url();
216
+
217
+                return strpos( $video_url, 'youtube.com' ) !== false ||
218
+                   strpos( $video_url, 'youtu.be' ) !== false;
219
+            }
220
+        );
221
+    }
222
+
223
+    /**
224
+     * @param $embedded_videos
225
+     *
226
+     * @return array
227
+     */
228
+    private function get_vimeo_videos( $embedded_videos ) {
229
+        return array_filter(
230
+            $embedded_videos,
231
+            function ( $embedded_video ) {
232
+                /**
233
+                 * it should have vimeo.com in the url
234
+                 *
235
+                 * @param $embedded_video Embedded_Video
236
+                 */
237
+                $video_url = $embedded_video->get_url();
238
+
239
+                return strpos( $video_url, 'vimeo.com' ) !== false;
240
+            }
241
+        );
242
+    }
243
+
244
+    private function get_jw_player_videos( $embedded_videos ) {
245
+        return array_filter(
246
+            $embedded_videos,
247
+            function ( $embedded_video ) {
248
+                /**
249
+                 * it should have vimeo.com in the url
250
+                 *
251
+                 * @param $embedded_video Embedded_Video
252
+                 */
253
+                $video_url = $embedded_video->get_url();
254
+
255
+                return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false;
256
+            }
257
+        );
258
+    }
259 259
 
260 260
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -19,41 +19,41 @@  discard block
 block discarded – undo
19 19
 
20 20
 	public function __construct() {
21 21
 		$this->api_clients = array(
22
-			Client_Factory::get_client( Client_Factory::YOUTUBE ),
23
-			Client_Factory::get_client( Client_Factory::VIMEO ),
24
-			Client_Factory::get_client( Client_Factory::JWPLAYER ),
22
+			Client_Factory::get_client(Client_Factory::YOUTUBE),
23
+			Client_Factory::get_client(Client_Factory::VIMEO),
24
+			Client_Factory::get_client(Client_Factory::JWPLAYER),
25 25
 		);
26 26
 	}
27 27
 
28
-	private function get_data_for_videos( $embedded_videos ) {
28
+	private function get_data_for_videos($embedded_videos) {
29 29
 
30
-		$youtube_videos   = $this->get_youtube_videos( $embedded_videos );
31
-		$youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE );
32
-		$youtube_videos   = $youtube_provider->get_videos_data( $youtube_videos );
30
+		$youtube_videos   = $this->get_youtube_videos($embedded_videos);
31
+		$youtube_provider = Provider_Factory::get_provider(Provider_Factory::YOUTUBE);
32
+		$youtube_videos   = $youtube_provider->get_videos_data($youtube_videos);
33 33
 
34
-		$vimeo_videos   = $this->get_vimeo_videos( $embedded_videos );
35
-		$vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO );
36
-		$vimeo_videos   = $vimeo_provider->get_videos_data( $vimeo_videos );
34
+		$vimeo_videos   = $this->get_vimeo_videos($embedded_videos);
35
+		$vimeo_provider = Provider_Factory::get_provider(Provider_Factory::VIMEO);
36
+		$vimeo_videos   = $vimeo_provider->get_videos_data($vimeo_videos);
37 37
 
38
-		$jwplayer_videos   = $this->get_jw_player_videos( $embedded_videos );
39
-		$jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER );
40
-		$jwplayer_videos   = $jwplayer_provider->get_videos_data( $jwplayer_videos );
38
+		$jwplayer_videos   = $this->get_jw_player_videos($embedded_videos);
39
+		$jwplayer_provider = Provider_Factory::get_provider(Provider_Factory::JWPLAYER);
40
+		$jwplayer_videos   = $jwplayer_provider->get_videos_data($jwplayer_videos);
41 41
 
42
-		return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos );
42
+		return array_merge($youtube_videos, $vimeo_videos, $jwplayer_videos);
43 43
 
44 44
 	}
45 45
 
46
-	private function get_video_ids( $video_urls ) {
46
+	private function get_video_ids($video_urls) {
47 47
 		$clients   = $this->api_clients;
48 48
 		$video_ids = array();
49
-		foreach ( $clients as $client ) {
50
-			$ids = $client->get_video_ids( $video_urls );
51
-			if ( $ids ) {
52
-				$video_ids = array_merge( $video_ids, $ids );
49
+		foreach ($clients as $client) {
50
+			$ids = $client->get_video_ids($video_urls);
51
+			if ($ids) {
52
+				$video_ids = array_merge($video_ids, $ids);
53 53
 			}
54 54
 		}
55 55
 
56
-		return array_unique( $video_ids );
56
+		return array_unique($video_ids);
57 57
 	}
58 58
 
59 59
 	/**
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
 	 * @param $post_id int
62 62
 	 * @param $embedded_videos array<Embedded_Video>
63 63
 	 */
64
-	private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) {
64
+	private function remove_videos_from_store_if_not_present_in_content($storage, $post_id, $embedded_videos) {
65 65
 
66
-		$videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos );
67
-		$storage->remove_videos( $videos_to_be_deleted, $post_id );
66
+		$videos_to_be_deleted = $this->get_videos_to_be_deleted($storage, $post_id, $embedded_videos);
67
+		$storage->remove_videos($videos_to_be_deleted, $post_id);
68 68
 
69 69
 	}
70 70
 
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return array An array of videos which exist on storage, not on post content.
77 77
 	 */
78
-	private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) {
79
-		$videos_in_store     = $storage->get_all_videos( $post_id );
78
+	private function get_videos_to_be_deleted(Storage $storage, $post_id, array $embedded_videos) {
79
+		$videos_in_store     = $storage->get_all_videos($post_id);
80 80
 		$embedded_video_urls = array_map(
81
-			function ( $embedded_video ) {
81
+			function($embedded_video) {
82 82
 				/**
83 83
 				 * @var $embedded_video Embedded_Video
84 84
 				 */
@@ -92,20 +92,20 @@  discard block
 block discarded – undo
92 92
 		 * but this might not work well if we want to support multiple URL formats, we extract the video
93 93
 		 * ids for embedded URLs.
94 94
 		 */
95
-		$embedded_video_ids = $this->get_video_ids( $embedded_video_urls );
95
+		$embedded_video_ids = $this->get_video_ids($embedded_video_urls);
96 96
 
97 97
 		$that = $this;
98 98
 
99 99
 		return array_filter(
100 100
 			$videos_in_store,
101
-			function ( $video ) use ( $embedded_video_ids, $that ) {
101
+			function($video) use ($embedded_video_ids, $that) {
102 102
 				/**
103 103
 				 * If the video id doesn't exist on the content then we need to return it
104 104
 				 * in order to delete that video.
105 105
 				 */
106 106
 				return count(
107 107
 					array_intersect(
108
-						$that->get_video_ids( array( $video->id ) ),
108
+						$that->get_video_ids(array($video->id)),
109 109
 						$embedded_video_ids
110 110
 					)
111 111
 				) === 0;
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 	 * @param \WP_Post $post
119 119
 	 * @param $post_id
120 120
 	 */
121
-	public function process_video_urls( \WP_Post $post, $post_id ) {
121
+	public function process_video_urls(\WP_Post $post, $post_id) {
122 122
 
123
-		$parser = Parser_Factory::get_parser_from_content( $post->post_content );
123
+		$parser = Parser_Factory::get_parser_from_content($post->post_content);
124 124
 
125
-		$embedded_videos = $parser->get_videos( $post_id );
125
+		$embedded_videos = $parser->get_videos($post_id);
126 126
 		/**
127 127
 		 * Filters the embedded videos on post contet, custom plugins can add their video urls
128 128
 		 * by constructing \Default_Embedded_Video or implement Embedded_Video class
@@ -134,30 +134,30 @@  discard block
 block discarded – undo
134 134
 		 * @since 3.31.4
135 135
 		 * Filter name : wl_videoobject_embedded_videos
136 136
 		 */
137
-		$embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id );
137
+		$embedded_videos = apply_filters('wl_videoobject_embedded_videos', $embedded_videos, $post_id);
138 138
 
139 139
 		$storage = Video_Storage_Factory::get_storage();
140 140
 
141 141
 		// Before sending api requests we need to check if there are any videos in
142 142
 		// store which is not present on post content, remove them if there are
143 143
 		// any
144
-		$this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos );
144
+		$this->remove_videos_from_store_if_not_present_in_content($storage, $post_id, $embedded_videos);
145 145
 
146
-		$embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos );
146
+		$embedded_videos = $this->get_videos_without_existing_data($storage, $post_id, $embedded_videos);
147 147
 
148 148
 		// Return early after removing all the videos.
149
-		if ( ! $embedded_videos ) {
149
+		if ( ! $embedded_videos) {
150 150
 			return;
151 151
 		}
152 152
 
153
-		$videos = $this->get_data_for_videos( $embedded_videos );
153
+		$videos = $this->get_data_for_videos($embedded_videos);
154 154
 
155
-		if ( ! $videos ) {
155
+		if ( ! $videos) {
156 156
 			return;
157 157
 		}
158 158
 
159
-		foreach ( $videos as $video ) {
160
-			$storage->add_video( $post_id, $video );
159
+		foreach ($videos as $video) {
160
+			$storage->add_video($post_id, $video);
161 161
 		}
162 162
 	}
163 163
 
@@ -168,29 +168,29 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return array<Embedded_Video> Return array of embedded videos which are not in store.
170 170
 	 */
171
-	private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) {
172
-		$videos_in_store     = $storage->get_all_videos( $post_id );
171
+	private function get_videos_without_existing_data($storage, $post_id, $embedded_videos) {
172
+		$videos_in_store     = $storage->get_all_videos($post_id);
173 173
 		$video_urls_in_store = array_map(
174
-			function ( $video ) {
174
+			function($video) {
175 175
 				return $video->id;
176 176
 			},
177 177
 			$videos_in_store
178 178
 		);
179 179
 
180
-		$video_ids_in_store = $this->get_video_ids( $video_urls_in_store );
180
+		$video_ids_in_store = $this->get_video_ids($video_urls_in_store);
181 181
 
182 182
 		$that = $this;
183 183
 
184 184
 		return array_filter(
185 185
 			$embedded_videos,
186
-			function ( $embedded_video ) use ( $video_ids_in_store, $that ) {
186
+			function($embedded_video) use ($video_ids_in_store, $that) {
187 187
 				/**
188 188
 				 * If the video id exist on content, not on storage then
189 189
 				 * we need to fetch the data.
190 190
 				 */
191 191
 				return count(
192 192
 					array_intersect(
193
-						$that->get_video_ids( array( $embedded_video->get_url() ) ),
193
+						$that->get_video_ids(array($embedded_video->get_url())),
194 194
 						$video_ids_in_store
195 195
 					)
196 196
 				) === 0;
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 	 *
204 204
 	 * @return array
205 205
 	 */
206
-	private function get_youtube_videos( $embedded_videos ) {
206
+	private function get_youtube_videos($embedded_videos) {
207 207
 		return array_filter(
208 208
 			$embedded_videos,
209
-			function ( $embedded_video ) {
209
+			function($embedded_video) {
210 210
 				/**
211 211
 				 * it should have youtube.com or youtu.be in the url
212 212
 				 *
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 				 */
215 215
 				$video_url = $embedded_video->get_url();
216 216
 
217
-				return strpos( $video_url, 'youtube.com' ) !== false ||
218
-				   strpos( $video_url, 'youtu.be' ) !== false;
217
+				return strpos($video_url, 'youtube.com') !== false ||
218
+				   strpos($video_url, 'youtu.be') !== false;
219 219
 			}
220 220
 		);
221 221
 	}
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 	 *
226 226
 	 * @return array
227 227
 	 */
228
-	private function get_vimeo_videos( $embedded_videos ) {
228
+	private function get_vimeo_videos($embedded_videos) {
229 229
 		return array_filter(
230 230
 			$embedded_videos,
231
-			function ( $embedded_video ) {
231
+			function($embedded_video) {
232 232
 				/**
233 233
 				 * it should have vimeo.com in the url
234 234
 				 *
@@ -236,15 +236,15 @@  discard block
 block discarded – undo
236 236
 				 */
237 237
 				$video_url = $embedded_video->get_url();
238 238
 
239
-				return strpos( $video_url, 'vimeo.com' ) !== false;
239
+				return strpos($video_url, 'vimeo.com') !== false;
240 240
 			}
241 241
 		);
242 242
 	}
243 243
 
244
-	private function get_jw_player_videos( $embedded_videos ) {
244
+	private function get_jw_player_videos($embedded_videos) {
245 245
 		return array_filter(
246 246
 			$embedded_videos,
247
-			function ( $embedded_video ) {
247
+			function($embedded_video) {
248 248
 				/**
249 249
 				 * it should have vimeo.com in the url
250 250
 				 *
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 				 */
253 253
 				$video_url = $embedded_video->get_url();
254 254
 
255
-				return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false;
255
+				return strpos($video_url, 'https://cdn.jwplayer.com/v2/media/', 0) !== false;
256 256
 			}
257 257
 		);
258 258
 	}
Please login to merge, or discard this patch.
src/wordlift/videoobject/ui/class-post-edit-screen.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -10,34 +10,34 @@
 block discarded – undo
10 10
 
11 11
 class Post_Edit_Screen {
12 12
 
13
-	public function init() {
14
-		$callback = array( $this, 'enqueue_scripts' );
15
-		add_action( 'enqueue_block_editor_assets', $callback );
16
-		add_action( 'admin_print_scripts-post.php', $callback );
17
-		add_action( 'admin_print_scripts-post-new.php', $callback );
18
-	}
13
+    public function init() {
14
+        $callback = array( $this, 'enqueue_scripts' );
15
+        add_action( 'enqueue_block_editor_assets', $callback );
16
+        add_action( 'admin_print_scripts-post.php', $callback );
17
+        add_action( 'admin_print_scripts-post-new.php', $callback );
18
+    }
19 19
 
20
-	public function enqueue_scripts() {
21
-		Scripts_Helper::enqueue_based_on_wordpress_version(
22
-			'wl-videoobject',
23
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject',
24
-			array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' )
25
-		);
26
-		wp_enqueue_style(
27
-			'wl-videoobject',
28
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css',
29
-			array(),
30
-			WORDLIFT_VERSION
31
-		);
32
-		wp_localize_script(
33
-			'wl-videoobject',
34
-			'_wlVideoobjectConfig',
35
-			array(
36
-				'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ),
37
-				'nonce'   => wp_create_nonce( 'wp_rest' ),
38
-				'postId'  => get_the_ID(),
39
-			)
40
-		);
41
-	}
20
+    public function enqueue_scripts() {
21
+        Scripts_Helper::enqueue_based_on_wordpress_version(
22
+            'wl-videoobject',
23
+            plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject',
24
+            array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' )
25
+        );
26
+        wp_enqueue_style(
27
+            'wl-videoobject',
28
+            plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css',
29
+            array(),
30
+            WORDLIFT_VERSION
31
+        );
32
+        wp_localize_script(
33
+            'wl-videoobject',
34
+            '_wlVideoobjectConfig',
35
+            array(
36
+                'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ),
37
+                'nonce'   => wp_create_nonce( 'wp_rest' ),
38
+                'postId'  => get_the_ID(),
39
+            )
40
+        );
41
+    }
42 42
 
43 43
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,21 +11,21 @@  discard block
 block discarded – undo
11 11
 class Post_Edit_Screen {
12 12
 
13 13
 	public function init() {
14
-		$callback = array( $this, 'enqueue_scripts' );
15
-		add_action( 'enqueue_block_editor_assets', $callback );
16
-		add_action( 'admin_print_scripts-post.php', $callback );
17
-		add_action( 'admin_print_scripts-post-new.php', $callback );
14
+		$callback = array($this, 'enqueue_scripts');
15
+		add_action('enqueue_block_editor_assets', $callback);
16
+		add_action('admin_print_scripts-post.php', $callback);
17
+		add_action('admin_print_scripts-post-new.php', $callback);
18 18
 	}
19 19
 
20 20
 	public function enqueue_scripts() {
21 21
 		Scripts_Helper::enqueue_based_on_wordpress_version(
22 22
 			'wl-videoobject',
23
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject',
24
-			array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' )
23
+			plugin_dir_url(dirname(dirname(__DIR__))).'/js/dist/videoobject',
24
+			array('react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill')
25 25
 		);
26 26
 		wp_enqueue_style(
27 27
 			'wl-videoobject',
28
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css',
28
+			plugin_dir_url(dirname(dirname(__DIR__))).'/js/dist/videoobject.css',
29 29
 			array(),
30 30
 			WORDLIFT_VERSION
31 31
 		);
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 			'wl-videoobject',
34 34
 			'_wlVideoobjectConfig',
35 35
 			array(
36
-				'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ),
37
-				'nonce'   => wp_create_nonce( 'wp_rest' ),
36
+				'restUrl' => get_rest_url(null, '/wordlift/v1/videos'),
37
+				'nonce'   => wp_create_nonce('wp_rest'),
38 38
 				'postId'  => get_the_ID(),
39 39
 			)
40 40
 		);
Please login to merge, or discard this patch.
src/wordlift/videoobject/tabs/class-settings-tab.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@
 block discarded – undo
7 7
 
8 8
 class Settings_Tab {
9 9
 
10
-	public function init() {
10
+    public function init() {
11 11
 
12
-		add_filter(
13
-			'wl_admin_page_tabs',
14
-			function ( $tabs ) {
15
-				$tabs[] = array(
16
-					'slug'  => 'videoobject-settings',
17
-					'title' => __( 'Video Settings', 'wordlift' ),
18
-				);
19
-				return $tabs;
20
-			}
21
-		);
12
+        add_filter(
13
+            'wl_admin_page_tabs',
14
+            function ( $tabs ) {
15
+                $tabs[] = array(
16
+                    'slug'  => 'videoobject-settings',
17
+                    'title' => __( 'Video Settings', 'wordlift' ),
18
+                );
19
+                return $tabs;
20
+            }
21
+        );
22 22
 
23
-	}
23
+    }
24 24
 
25 25
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@
 block discarded – undo
11 11
 
12 12
 		add_filter(
13 13
 			'wl_admin_page_tabs',
14
-			function ( $tabs ) {
14
+			function($tabs) {
15 15
 				$tabs[] = array(
16 16
 					'slug'  => 'videoobject-settings',
17
-					'title' => __( 'Video Settings', 'wordlift' ),
17
+					'title' => __('Video Settings', 'wordlift'),
18 18
 				);
19 19
 				return $tabs;
20 20
 			}
Please login to merge, or discard this patch.
src/wordlift/videoobject/api/class-rest-controller.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -12,165 +12,165 @@
 block discarded – undo
12 12
 use WP_REST_Server;
13 13
 
14 14
 class Rest_Controller {
15
-	/**
16
-	 * @var Videoobject_Background_Process
17
-	 */
18
-	private $background_process;
19
-
20
-	/**
21
-	 * Rest_Controller constructor.
22
-	 *
23
-	 * @param $background_process Videoobject_Background_Process
24
-	 */
25
-	public function __construct( $background_process ) {
26
-		$this->background_process = $background_process;
27
-	}
28
-
29
-	public function register_all_routes() {
30
-		$that = $this;
31
-		add_action(
32
-			'rest_api_init',
33
-			function () use ( $that ) {
34
-				$that->register_get_all_videos_route();
35
-				$that->register_save_all_videos_route();
36
-				$that->register_get_sync_state_endpoint();
37
-				$that->register_background_process_start_endpoint();
38
-				$that->register_background_process_stop_endpoint();
39
-			}
40
-		);
41
-	}
42
-
43
-	public function get_all_videos( $request ) {
44
-		$data    = $request->get_params();
45
-		$post_id = (int) $data['post_id'];
46
-		$storage = Video_Storage_Factory::get_storage();
47
-
48
-		return $storage->get_all_videos( $post_id );
49
-	}
50
-
51
-	public function save_all_videos( $request ) {
52
-		$data    = $request->get_params();
53
-		$post_id = (int) $data['post_id'];
54
-		$videos  = (array) $data['videos'];
55
-		if ( ! $videos ) {
56
-			return;
57
-		}
58
-		$storage = Video_Storage_Factory::get_storage();
59
-		$storage->remove_all_videos( $post_id );
60
-
61
-		foreach ( $videos as $video ) {
62
-			$video_obj = new Video();
63
-			$video_obj->from( (array) $video );
64
-			$storage->add_video( $post_id, $video_obj );
65
-		}
66
-
67
-	}
68
-
69
-	private function register_get_all_videos_route() {
70
-		register_rest_route(
71
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
72
-			'/videos',
73
-			array(
74
-				'methods'             => WP_REST_Server::CREATABLE,
75
-				'callback'            => array( $this, 'get_all_videos' ),
76
-				'permission_callback' => function () {
77
-					return current_user_can( 'manage_options' );
78
-				},
79
-				'args'                => array(
80
-					'post_id' => array(
81
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82
-						'validate_callback' => function ( $param, $request, $key ) {
83
-							return is_numeric( $param ) && $param;
84
-						},
85
-						'required'          => true,
86
-					),
87
-				),
88
-			)
89
-		);
90
-	}
91
-
92
-	private function register_save_all_videos_route() {
93
-		register_rest_route(
94
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
95
-			'/videos/save',
96
-			array(
97
-				'methods'             => WP_REST_Server::CREATABLE,
98
-				'callback'            => array( $this, 'save_all_videos' ),
99
-				'permission_callback' => function () {
100
-					return current_user_can( 'manage_options' );
101
-				},
102
-				'args'                => array(
103
-					'post_id' => array(
104
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
105
-						'validate_callback' => function ( $param, $request, $key ) {
106
-							return is_numeric( $param ) && $param;
107
-						},
108
-						'required'          => true,
109
-					),
110
-					'videos'  => array(
111
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
112
-						'validate_callback' => function ( $param, $request, $key ) {
113
-							return is_array( $param ) && $param;
114
-						},
115
-						'required'          => true,
116
-					),
117
-				),
118
-			)
119
-		);
120
-	}
121
-
122
-	public function register_get_sync_state_endpoint() {
123
-		$that = $this;
124
-		register_rest_route(
125
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
126
-			'/videos/background/get_state',
127
-			array(
128
-				'methods'             => WP_REST_Server::CREATABLE,
129
-				'callback'            => function () use ( $that ) {
130
-					return $that->background_process->get_state()->get_array();
131
-				},
132
-				'permission_callback' => function () {
133
-					return current_user_can( 'manage_options' );
134
-				},
135
-			)
136
-		);
137
-
138
-	}
139
-
140
-	public function register_background_process_start_endpoint() {
141
-		$that = $this;
142
-		register_rest_route(
143
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
144
-			'/videos/background/start',
145
-			array(
146
-				'methods'             => WP_REST_Server::CREATABLE,
147
-				'callback'            => function () use ( $that ) {
148
-					$that->background_process->start();
149
-				},
150
-				'permission_callback' => function () {
151
-					return current_user_can( 'manage_options' );
152
-				},
153
-			)
154
-		);
155
-
156
-	}
157
-
158
-	public function register_background_process_stop_endpoint() {
159
-		$that = $this;
160
-		register_rest_route(
161
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
162
-			'/videos/background/stop',
163
-			array(
164
-				'methods'             => WP_REST_Server::CREATABLE,
165
-				'callback'            => function () use ( $that ) {
166
-					$that->background_process->cancel();
167
-				},
168
-				'permission_callback' => function () {
169
-					return current_user_can( 'manage_options' );
170
-				},
171
-			)
172
-		);
173
-
174
-	}
15
+    /**
16
+     * @var Videoobject_Background_Process
17
+     */
18
+    private $background_process;
19
+
20
+    /**
21
+     * Rest_Controller constructor.
22
+     *
23
+     * @param $background_process Videoobject_Background_Process
24
+     */
25
+    public function __construct( $background_process ) {
26
+        $this->background_process = $background_process;
27
+    }
28
+
29
+    public function register_all_routes() {
30
+        $that = $this;
31
+        add_action(
32
+            'rest_api_init',
33
+            function () use ( $that ) {
34
+                $that->register_get_all_videos_route();
35
+                $that->register_save_all_videos_route();
36
+                $that->register_get_sync_state_endpoint();
37
+                $that->register_background_process_start_endpoint();
38
+                $that->register_background_process_stop_endpoint();
39
+            }
40
+        );
41
+    }
42
+
43
+    public function get_all_videos( $request ) {
44
+        $data    = $request->get_params();
45
+        $post_id = (int) $data['post_id'];
46
+        $storage = Video_Storage_Factory::get_storage();
47
+
48
+        return $storage->get_all_videos( $post_id );
49
+    }
50
+
51
+    public function save_all_videos( $request ) {
52
+        $data    = $request->get_params();
53
+        $post_id = (int) $data['post_id'];
54
+        $videos  = (array) $data['videos'];
55
+        if ( ! $videos ) {
56
+            return;
57
+        }
58
+        $storage = Video_Storage_Factory::get_storage();
59
+        $storage->remove_all_videos( $post_id );
60
+
61
+        foreach ( $videos as $video ) {
62
+            $video_obj = new Video();
63
+            $video_obj->from( (array) $video );
64
+            $storage->add_video( $post_id, $video_obj );
65
+        }
66
+
67
+    }
68
+
69
+    private function register_get_all_videos_route() {
70
+        register_rest_route(
71
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
72
+            '/videos',
73
+            array(
74
+                'methods'             => WP_REST_Server::CREATABLE,
75
+                'callback'            => array( $this, 'get_all_videos' ),
76
+                'permission_callback' => function () {
77
+                    return current_user_can( 'manage_options' );
78
+                },
79
+                'args'                => array(
80
+                    'post_id' => array(
81
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82
+                        'validate_callback' => function ( $param, $request, $key ) {
83
+                            return is_numeric( $param ) && $param;
84
+                        },
85
+                        'required'          => true,
86
+                    ),
87
+                ),
88
+            )
89
+        );
90
+    }
91
+
92
+    private function register_save_all_videos_route() {
93
+        register_rest_route(
94
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
95
+            '/videos/save',
96
+            array(
97
+                'methods'             => WP_REST_Server::CREATABLE,
98
+                'callback'            => array( $this, 'save_all_videos' ),
99
+                'permission_callback' => function () {
100
+                    return current_user_can( 'manage_options' );
101
+                },
102
+                'args'                => array(
103
+                    'post_id' => array(
104
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
105
+                        'validate_callback' => function ( $param, $request, $key ) {
106
+                            return is_numeric( $param ) && $param;
107
+                        },
108
+                        'required'          => true,
109
+                    ),
110
+                    'videos'  => array(
111
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
112
+                        'validate_callback' => function ( $param, $request, $key ) {
113
+                            return is_array( $param ) && $param;
114
+                        },
115
+                        'required'          => true,
116
+                    ),
117
+                ),
118
+            )
119
+        );
120
+    }
121
+
122
+    public function register_get_sync_state_endpoint() {
123
+        $that = $this;
124
+        register_rest_route(
125
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
126
+            '/videos/background/get_state',
127
+            array(
128
+                'methods'             => WP_REST_Server::CREATABLE,
129
+                'callback'            => function () use ( $that ) {
130
+                    return $that->background_process->get_state()->get_array();
131
+                },
132
+                'permission_callback' => function () {
133
+                    return current_user_can( 'manage_options' );
134
+                },
135
+            )
136
+        );
137
+
138
+    }
139
+
140
+    public function register_background_process_start_endpoint() {
141
+        $that = $this;
142
+        register_rest_route(
143
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
144
+            '/videos/background/start',
145
+            array(
146
+                'methods'             => WP_REST_Server::CREATABLE,
147
+                'callback'            => function () use ( $that ) {
148
+                    $that->background_process->start();
149
+                },
150
+                'permission_callback' => function () {
151
+                    return current_user_can( 'manage_options' );
152
+                },
153
+            )
154
+        );
155
+
156
+    }
157
+
158
+    public function register_background_process_stop_endpoint() {
159
+        $that = $this;
160
+        register_rest_route(
161
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
162
+            '/videos/background/stop',
163
+            array(
164
+                'methods'             => WP_REST_Server::CREATABLE,
165
+                'callback'            => function () use ( $that ) {
166
+                    $that->background_process->cancel();
167
+                },
168
+                'permission_callback' => function () {
169
+                    return current_user_can( 'manage_options' );
170
+                },
171
+            )
172
+        );
173
+
174
+    }
175 175
 
176 176
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param $background_process Videoobject_Background_Process
24 24
 	 */
25
-	public function __construct( $background_process ) {
25
+	public function __construct($background_process) {
26 26
 		$this->background_process = $background_process;
27 27
 	}
28 28
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 		$that = $this;
31 31
 		add_action(
32 32
 			'rest_api_init',
33
-			function () use ( $that ) {
33
+			function() use ($that) {
34 34
 				$that->register_get_all_videos_route();
35 35
 				$that->register_save_all_videos_route();
36 36
 				$that->register_get_sync_state_endpoint();
@@ -40,28 +40,28 @@  discard block
 block discarded – undo
40 40
 		);
41 41
 	}
42 42
 
43
-	public function get_all_videos( $request ) {
43
+	public function get_all_videos($request) {
44 44
 		$data    = $request->get_params();
45 45
 		$post_id = (int) $data['post_id'];
46 46
 		$storage = Video_Storage_Factory::get_storage();
47 47
 
48
-		return $storage->get_all_videos( $post_id );
48
+		return $storage->get_all_videos($post_id);
49 49
 	}
50 50
 
51
-	public function save_all_videos( $request ) {
51
+	public function save_all_videos($request) {
52 52
 		$data    = $request->get_params();
53 53
 		$post_id = (int) $data['post_id'];
54 54
 		$videos  = (array) $data['videos'];
55
-		if ( ! $videos ) {
55
+		if ( ! $videos) {
56 56
 			return;
57 57
 		}
58 58
 		$storage = Video_Storage_Factory::get_storage();
59
-		$storage->remove_all_videos( $post_id );
59
+		$storage->remove_all_videos($post_id);
60 60
 
61
-		foreach ( $videos as $video ) {
61
+		foreach ($videos as $video) {
62 62
 			$video_obj = new Video();
63
-			$video_obj->from( (array) $video );
64
-			$storage->add_video( $post_id, $video_obj );
63
+			$video_obj->from((array) $video);
64
+			$storage->add_video($post_id, $video_obj);
65 65
 		}
66 66
 
67 67
 	}
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 			'/videos',
73 73
 			array(
74 74
 				'methods'             => WP_REST_Server::CREATABLE,
75
-				'callback'            => array( $this, 'get_all_videos' ),
76
-				'permission_callback' => function () {
77
-					return current_user_can( 'manage_options' );
75
+				'callback'            => array($this, 'get_all_videos'),
76
+				'permission_callback' => function() {
77
+					return current_user_can('manage_options');
78 78
 				},
79 79
 				'args'                => array(
80 80
 					'post_id' => array(
81 81
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
82
-						'validate_callback' => function ( $param, $request, $key ) {
83
-							return is_numeric( $param ) && $param;
82
+						'validate_callback' => function($param, $request, $key) {
83
+							return is_numeric($param) && $param;
84 84
 						},
85 85
 						'required'          => true,
86 86
 					),
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
 			'/videos/save',
96 96
 			array(
97 97
 				'methods'             => WP_REST_Server::CREATABLE,
98
-				'callback'            => array( $this, 'save_all_videos' ),
99
-				'permission_callback' => function () {
100
-					return current_user_can( 'manage_options' );
98
+				'callback'            => array($this, 'save_all_videos'),
99
+				'permission_callback' => function() {
100
+					return current_user_can('manage_options');
101 101
 				},
102 102
 				'args'                => array(
103 103
 					'post_id' => array(
104 104
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
105
-						'validate_callback' => function ( $param, $request, $key ) {
106
-							return is_numeric( $param ) && $param;
105
+						'validate_callback' => function($param, $request, $key) {
106
+							return is_numeric($param) && $param;
107 107
 						},
108 108
 						'required'          => true,
109 109
 					),
110 110
 					'videos'  => array(
111 111
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
112
-						'validate_callback' => function ( $param, $request, $key ) {
113
-							return is_array( $param ) && $param;
112
+						'validate_callback' => function($param, $request, $key) {
113
+							return is_array($param) && $param;
114 114
 						},
115 115
 						'required'          => true,
116 116
 					),
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 			'/videos/background/get_state',
127 127
 			array(
128 128
 				'methods'             => WP_REST_Server::CREATABLE,
129
-				'callback'            => function () use ( $that ) {
129
+				'callback'            => function() use ($that) {
130 130
 					return $that->background_process->get_state()->get_array();
131 131
 				},
132
-				'permission_callback' => function () {
133
-					return current_user_can( 'manage_options' );
132
+				'permission_callback' => function() {
133
+					return current_user_can('manage_options');
134 134
 				},
135 135
 			)
136 136
 		);
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 			'/videos/background/start',
145 145
 			array(
146 146
 				'methods'             => WP_REST_Server::CREATABLE,
147
-				'callback'            => function () use ( $that ) {
147
+				'callback'            => function() use ($that) {
148 148
 					$that->background_process->start();
149 149
 				},
150
-				'permission_callback' => function () {
151
-					return current_user_can( 'manage_options' );
150
+				'permission_callback' => function() {
151
+					return current_user_can('manage_options');
152 152
 				},
153 153
 			)
154 154
 		);
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 			'/videos/background/stop',
163 163
 			array(
164 164
 				'methods'             => WP_REST_Server::CREATABLE,
165
-				'callback'            => function () use ( $that ) {
165
+				'callback'            => function() use ($that) {
166 166
 					$that->background_process->cancel();
167 167
 				},
168
-				'permission_callback' => function () {
169
-					return current_user_can( 'manage_options' );
168
+				'permission_callback' => function() {
169
+					return current_user_can('manage_options');
170 170
 				},
171 171
 			)
172 172
 		);
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-youtube.php 2 patches
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -11,134 +11,134 @@
 block discarded – undo
11 11
 
12 12
 class Youtube extends Api_Provider {
13 13
 
14
-	const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key';
15
-
16
-	private static function get_thumbnails( $api_thumbnail_data ) {
17
-		return array_map(
18
-			function ( $item ) {
19
-				return $item['url'];
20
-
21
-			},
22
-			$api_thumbnail_data
23
-		);
24
-	}
25
-
26
-	public function get_videos_data( $videos ) {
27
-		$urls = array_map(
28
-			function ( $video ) {
29
-				/**
30
-				 * @param $video Video
31
-				 */
32
-				return $video->get_url();
33
-			},
34
-			$videos
35
-		);
36
-
37
-		return $this->get_data( $urls );
38
-
39
-	}
40
-
41
-	/**
42
-	 * @param $video_urls
43
-	 *
44
-	 * @return bool | array<Video>
45
-	 */
46
-	public function get_data( $video_urls ) {
47
-		// extract ids from the url list.
48
-		if ( ! is_array( $video_urls ) ) {
49
-			return array();
50
-		}
51
-		$response_body = $this->api_client->get_data( $video_urls );
52
-
53
-		return $this->parse_youtube_video_data_from_response( $response_body );
54
-	}
55
-
56
-	/**
57
-	 * @param $response_body string
58
-	 *
59
-	 * @return array<Video>
60
-	 */
61
-	private function parse_youtube_video_data_from_response( $response_body ) {
62
-		$result = json_decode( $response_body, true );
63
-		if ( ! is_array( $result ) ) {
64
-			// Return empty array since the response body is invalid.
65
-			return array();
66
-		}
67
-		if ( ! array_key_exists( 'items', $result ) ) {
68
-			return array();
69
-		}
70
-		$videos_json_data = $result['items'];
71
-		$videos           = array();
72
-		foreach ( $videos_json_data as $single_video_json_data ) {
73
-			$videos[] = self::create_video_from_youtube_data( $single_video_json_data );
74
-		}
75
-
76
-		return $videos;
77
-	}
78
-
79
-	public static function create_video_from_youtube_data( $video_data ) {
80
-
81
-		$video = new Video();
82
-		if ( array_key_exists( 'contentDetails', $video_data ) ) {
83
-			$video->duration = $video_data['contentDetails']['duration'];
84
-		}
85
-
86
-		if ( array_key_exists( 'id', $video_data ) ) {
87
-			$video_id           = $video_data['id'];
88
-			$video->embed_url   = "https://www.youtube.com/embed/${video_id}";
89
-			$video->content_url = "https://www.youtube.com/watch?v=${video_id}";
90
-		}
91
-		if ( ! array_key_exists( 'snippet', $video_data ) ) {
92
-			return false;
93
-		}
94
-
95
-		$video->name        = $video_data['snippet']['title'];
96
-		$video->description = $video_data['snippet']['description'];
97
-
98
-		/**
99
-		 * @since 3.30.0
100
-		 * Use title as fallback if description is not present.
101
-		 */
102
-		if ( ! $video->description ) {
103
-			$video->description = $video->name;
104
-		}
105
-
106
-		$video->upload_date = $video_data['snippet']['publishedAt'];
107
-
108
-		if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) {
109
-			$api_thumbnail_data    = array_values( $video_data['snippet']['thumbnails'] );
110
-			$video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data );
111
-		}
112
-
113
-		if ( array_key_exists( 'statistics', $video_data )
114
-			 && array_key_exists( 'viewCount', $video_data['statistics'] ) ) {
115
-			$video->views = $video_data['statistics']['viewCount'];
116
-		}
117
-
118
-		if ( array_key_exists( 'liveStreamingDetails', $video_data ) &&
119
-			 array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) {
120
-			$video->is_live_video         = true;
121
-			$video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime'];
122
-			try {
123
-				$end_date = new \DateTime( $video->live_video_start_date );
124
-				/**
125
-				 * the google doc says :
126
-				 * It is required to provide the endDate once the video has finished and is no longer live.
127
-				 * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate.
128
-				 */
129
-				// we add 1 day to start date
130
-				$end_date->add( new DateInterval( 'P1D' ) );
131
-				$video->live_video_end_date = $end_date->format( 'c' );
132
-			// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
133
-			} catch ( \Exception $e ) {
134
-				// No need to do anything here.
135
-			}
136
-		}
137
-
138
-		$video->id = $video->content_url;
139
-
140
-		return $video;
141
-
142
-	}
14
+    const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key';
15
+
16
+    private static function get_thumbnails( $api_thumbnail_data ) {
17
+        return array_map(
18
+            function ( $item ) {
19
+                return $item['url'];
20
+
21
+            },
22
+            $api_thumbnail_data
23
+        );
24
+    }
25
+
26
+    public function get_videos_data( $videos ) {
27
+        $urls = array_map(
28
+            function ( $video ) {
29
+                /**
30
+                 * @param $video Video
31
+                 */
32
+                return $video->get_url();
33
+            },
34
+            $videos
35
+        );
36
+
37
+        return $this->get_data( $urls );
38
+
39
+    }
40
+
41
+    /**
42
+     * @param $video_urls
43
+     *
44
+     * @return bool | array<Video>
45
+     */
46
+    public function get_data( $video_urls ) {
47
+        // extract ids from the url list.
48
+        if ( ! is_array( $video_urls ) ) {
49
+            return array();
50
+        }
51
+        $response_body = $this->api_client->get_data( $video_urls );
52
+
53
+        return $this->parse_youtube_video_data_from_response( $response_body );
54
+    }
55
+
56
+    /**
57
+     * @param $response_body string
58
+     *
59
+     * @return array<Video>
60
+     */
61
+    private function parse_youtube_video_data_from_response( $response_body ) {
62
+        $result = json_decode( $response_body, true );
63
+        if ( ! is_array( $result ) ) {
64
+            // Return empty array since the response body is invalid.
65
+            return array();
66
+        }
67
+        if ( ! array_key_exists( 'items', $result ) ) {
68
+            return array();
69
+        }
70
+        $videos_json_data = $result['items'];
71
+        $videos           = array();
72
+        foreach ( $videos_json_data as $single_video_json_data ) {
73
+            $videos[] = self::create_video_from_youtube_data( $single_video_json_data );
74
+        }
75
+
76
+        return $videos;
77
+    }
78
+
79
+    public static function create_video_from_youtube_data( $video_data ) {
80
+
81
+        $video = new Video();
82
+        if ( array_key_exists( 'contentDetails', $video_data ) ) {
83
+            $video->duration = $video_data['contentDetails']['duration'];
84
+        }
85
+
86
+        if ( array_key_exists( 'id', $video_data ) ) {
87
+            $video_id           = $video_data['id'];
88
+            $video->embed_url   = "https://www.youtube.com/embed/${video_id}";
89
+            $video->content_url = "https://www.youtube.com/watch?v=${video_id}";
90
+        }
91
+        if ( ! array_key_exists( 'snippet', $video_data ) ) {
92
+            return false;
93
+        }
94
+
95
+        $video->name        = $video_data['snippet']['title'];
96
+        $video->description = $video_data['snippet']['description'];
97
+
98
+        /**
99
+         * @since 3.30.0
100
+         * Use title as fallback if description is not present.
101
+         */
102
+        if ( ! $video->description ) {
103
+            $video->description = $video->name;
104
+        }
105
+
106
+        $video->upload_date = $video_data['snippet']['publishedAt'];
107
+
108
+        if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) {
109
+            $api_thumbnail_data    = array_values( $video_data['snippet']['thumbnails'] );
110
+            $video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data );
111
+        }
112
+
113
+        if ( array_key_exists( 'statistics', $video_data )
114
+             && array_key_exists( 'viewCount', $video_data['statistics'] ) ) {
115
+            $video->views = $video_data['statistics']['viewCount'];
116
+        }
117
+
118
+        if ( array_key_exists( 'liveStreamingDetails', $video_data ) &&
119
+             array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) {
120
+            $video->is_live_video         = true;
121
+            $video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime'];
122
+            try {
123
+                $end_date = new \DateTime( $video->live_video_start_date );
124
+                /**
125
+                 * the google doc says :
126
+                 * It is required to provide the endDate once the video has finished and is no longer live.
127
+                 * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate.
128
+                 */
129
+                // we add 1 day to start date
130
+                $end_date->add( new DateInterval( 'P1D' ) );
131
+                $video->live_video_end_date = $end_date->format( 'c' );
132
+            // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
133
+            } catch ( \Exception $e ) {
134
+                // No need to do anything here.
135
+            }
136
+        }
137
+
138
+        $video->id = $video->content_url;
139
+
140
+        return $video;
141
+
142
+    }
143 143
 
144 144
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 	const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key';
15 15
 
16
-	private static function get_thumbnails( $api_thumbnail_data ) {
16
+	private static function get_thumbnails($api_thumbnail_data) {
17 17
 		return array_map(
18
-			function ( $item ) {
18
+			function($item) {
19 19
 				return $item['url'];
20 20
 
21 21
 			},
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 		);
24 24
 	}
25 25
 
26
-	public function get_videos_data( $videos ) {
26
+	public function get_videos_data($videos) {
27 27
 		$urls = array_map(
28
-			function ( $video ) {
28
+			function($video) {
29 29
 				/**
30 30
 				 * @param $video Video
31 31
 				 */
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 			$videos
35 35
 		);
36 36
 
37
-		return $this->get_data( $urls );
37
+		return $this->get_data($urls);
38 38
 
39 39
 	}
40 40
 
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @return bool | array<Video>
45 45
 	 */
46
-	public function get_data( $video_urls ) {
46
+	public function get_data($video_urls) {
47 47
 		// extract ids from the url list.
48
-		if ( ! is_array( $video_urls ) ) {
48
+		if ( ! is_array($video_urls)) {
49 49
 			return array();
50 50
 		}
51
-		$response_body = $this->api_client->get_data( $video_urls );
51
+		$response_body = $this->api_client->get_data($video_urls);
52 52
 
53
-		return $this->parse_youtube_video_data_from_response( $response_body );
53
+		return $this->parse_youtube_video_data_from_response($response_body);
54 54
 	}
55 55
 
56 56
 	/**
@@ -58,37 +58,37 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return array<Video>
60 60
 	 */
61
-	private function parse_youtube_video_data_from_response( $response_body ) {
62
-		$result = json_decode( $response_body, true );
63
-		if ( ! is_array( $result ) ) {
61
+	private function parse_youtube_video_data_from_response($response_body) {
62
+		$result = json_decode($response_body, true);
63
+		if ( ! is_array($result)) {
64 64
 			// Return empty array since the response body is invalid.
65 65
 			return array();
66 66
 		}
67
-		if ( ! array_key_exists( 'items', $result ) ) {
67
+		if ( ! array_key_exists('items', $result)) {
68 68
 			return array();
69 69
 		}
70 70
 		$videos_json_data = $result['items'];
71 71
 		$videos           = array();
72
-		foreach ( $videos_json_data as $single_video_json_data ) {
73
-			$videos[] = self::create_video_from_youtube_data( $single_video_json_data );
72
+		foreach ($videos_json_data as $single_video_json_data) {
73
+			$videos[] = self::create_video_from_youtube_data($single_video_json_data);
74 74
 		}
75 75
 
76 76
 		return $videos;
77 77
 	}
78 78
 
79
-	public static function create_video_from_youtube_data( $video_data ) {
79
+	public static function create_video_from_youtube_data($video_data) {
80 80
 
81 81
 		$video = new Video();
82
-		if ( array_key_exists( 'contentDetails', $video_data ) ) {
82
+		if (array_key_exists('contentDetails', $video_data)) {
83 83
 			$video->duration = $video_data['contentDetails']['duration'];
84 84
 		}
85 85
 
86
-		if ( array_key_exists( 'id', $video_data ) ) {
86
+		if (array_key_exists('id', $video_data)) {
87 87
 			$video_id           = $video_data['id'];
88 88
 			$video->embed_url   = "https://www.youtube.com/embed/${video_id}";
89 89
 			$video->content_url = "https://www.youtube.com/watch?v=${video_id}";
90 90
 		}
91
-		if ( ! array_key_exists( 'snippet', $video_data ) ) {
91
+		if ( ! array_key_exists('snippet', $video_data)) {
92 92
 			return false;
93 93
 		}
94 94
 
@@ -99,38 +99,38 @@  discard block
 block discarded – undo
99 99
 		 * @since 3.30.0
100 100
 		 * Use title as fallback if description is not present.
101 101
 		 */
102
-		if ( ! $video->description ) {
102
+		if ( ! $video->description) {
103 103
 			$video->description = $video->name;
104 104
 		}
105 105
 
106 106
 		$video->upload_date = $video_data['snippet']['publishedAt'];
107 107
 
108
-		if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) {
109
-			$api_thumbnail_data    = array_values( $video_data['snippet']['thumbnails'] );
110
-			$video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data );
108
+		if (array_key_exists('thumbnails', $video_data['snippet'])) {
109
+			$api_thumbnail_data    = array_values($video_data['snippet']['thumbnails']);
110
+			$video->thumbnail_urls = self::get_thumbnails($api_thumbnail_data);
111 111
 		}
112 112
 
113
-		if ( array_key_exists( 'statistics', $video_data )
114
-			 && array_key_exists( 'viewCount', $video_data['statistics'] ) ) {
113
+		if (array_key_exists('statistics', $video_data)
114
+			 && array_key_exists('viewCount', $video_data['statistics'])) {
115 115
 			$video->views = $video_data['statistics']['viewCount'];
116 116
 		}
117 117
 
118
-		if ( array_key_exists( 'liveStreamingDetails', $video_data ) &&
119
-			 array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) {
118
+		if (array_key_exists('liveStreamingDetails', $video_data) &&
119
+			 array_key_exists('scheduledStartTime', $video_data['liveStreamingDetails'])) {
120 120
 			$video->is_live_video         = true;
121 121
 			$video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime'];
122 122
 			try {
123
-				$end_date = new \DateTime( $video->live_video_start_date );
123
+				$end_date = new \DateTime($video->live_video_start_date);
124 124
 				/**
125 125
 				 * the google doc says :
126 126
 				 * It is required to provide the endDate once the video has finished and is no longer live.
127 127
 				 * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate.
128 128
 				 */
129 129
 				// we add 1 day to start date
130
-				$end_date->add( new DateInterval( 'P1D' ) );
131
-				$video->live_video_end_date = $end_date->format( 'c' );
130
+				$end_date->add(new DateInterval('P1D'));
131
+				$video->live_video_end_date = $end_date->format('c');
132 132
 			// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
133
-			} catch ( \Exception $e ) {
133
+			} catch (\Exception $e) {
134 134
 				// No need to do anything here.
135 135
 			}
136 136
 		}
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-provider-factory.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -10,21 +10,21 @@
 block discarded – undo
10 10
  */
11 11
 class Provider_Factory {
12 12
 
13
-	const YOUTUBE = 'youtube';
13
+    const YOUTUBE = 'youtube';
14 14
 
15
-	const VIMEO = 'vimeo';
15
+    const VIMEO = 'vimeo';
16 16
 
17
-	const JWPLAYER = 'jwplayer';
17
+    const JWPLAYER = 'jwplayer';
18 18
 
19
-	public static function get_provider( $provider_name ) {
20
-		if ( self::YOUTUBE === $provider_name ) {
21
-			return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) );
22
-		} elseif ( self::VIMEO === $provider_name ) {
23
-			return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) );
24
-		} elseif ( self::JWPLAYER === $provider_name ) {
25
-			return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) );
26
-		}
19
+    public static function get_provider( $provider_name ) {
20
+        if ( self::YOUTUBE === $provider_name ) {
21
+            return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) );
22
+        } elseif ( self::VIMEO === $provider_name ) {
23
+            return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) );
24
+        } elseif ( self::JWPLAYER === $provider_name ) {
25
+            return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) );
26
+        }
27 27
 
28
-	}
28
+    }
29 29
 
30 30
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@
 block discarded – undo
16 16
 
17 17
 	const JWPLAYER = 'jwplayer';
18 18
 
19
-	public static function get_provider( $provider_name ) {
20
-		if ( self::YOUTUBE === $provider_name ) {
21
-			return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) );
22
-		} elseif ( self::VIMEO === $provider_name ) {
23
-			return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) );
24
-		} elseif ( self::JWPLAYER === $provider_name ) {
25
-			return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) );
19
+	public static function get_provider($provider_name) {
20
+		if (self::YOUTUBE === $provider_name) {
21
+			return new Youtube(Client_Factory::get_client(Client_Factory::YOUTUBE));
22
+		} elseif (self::VIMEO === $provider_name) {
23
+			return new Vimeo(Client_Factory::get_client(Client_Factory::VIMEO));
24
+		} elseif (self::JWPLAYER === $provider_name) {
25
+			return new Jw_Player(Client_Factory::get_client(Client_Factory::JWPLAYER));
26 26
 		}
27 27
 
28 28
 	}
Please login to merge, or discard this patch.
src/wordlift/videoobject/provider/class-vimeo.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -15,97 +15,97 @@
 block discarded – undo
15 15
  */
16 16
 class Vimeo extends Api_Provider {
17 17
 
18
-	const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key';
19
-
20
-	public static function get_api_key() {
21
-		return get_option( self::API_FIELD_NAME, false );
22
-	}
23
-
24
-	public function get_videos_data( $videos ) {
25
-
26
-		$key = $this->get_api_key();
27
-
28
-		if ( ! $key ) {
29
-			return array();
30
-		}
31
-
32
-		$urls = array_map(
33
-			function ( $video ) {
34
-				return $video->get_url();
35
-			},
36
-			$videos
37
-		);
38
-
39
-		$response_body = $this->api_client->get_data( $urls );
40
-
41
-		if ( ! is_string( $response_body ) || ! $response_body ) {
42
-			return array();
43
-		}
44
-
45
-		$response = json_decode( $response_body, true );
46
-
47
-		$video_list = $response['data'];
48
-
49
-		if ( ! is_array( $video_list ) ) {
50
-			// Return if we cant parse the response.
51
-			return array();
52
-		}
53
-
54
-		return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) );
55
-
56
-	}
57
-
58
-	public function get_video_from_video_data( $vimeo_video_data ) {
59
-
60
-		if ( ! $vimeo_video_data ) {
61
-			// If valid data not supplied dont init the object.
62
-			return false;
63
-		}
64
-		$video              = new Video();
65
-		$video->name        = $vimeo_video_data['name'];
66
-		$video->description = $vimeo_video_data['description'];
67
-
68
-		$video->content_url = $vimeo_video_data['link'];
69
-		$video->embed_url   = 'https://player.vimeo.com/video/' . $this->get_id( $vimeo_video_data );
70
-		if ( is_numeric( $vimeo_video_data['duration'] ) ) {
71
-			$video->duration = 'PT' . $vimeo_video_data['duration'] . 'S';
72
-		}
73
-		$video->upload_date    = $vimeo_video_data['release_time'];
74
-		$video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data );
75
-		$video->id             = $video->content_url;
76
-
77
-		if ( array_key_exists( 'stats', $vimeo_video_data )
78
-			 && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) {
79
-			$video->views = (int) $vimeo_video_data['stats']['plays'];
80
-		}
81
-
82
-		return $video;
83
-	}
84
-
85
-	private function get_id( $api_response_data ) {
86
-		return str_replace( '/videos/', '', $api_response_data['uri'] );
87
-	}
88
-
89
-	private function set_thumbnail_urls( $api_response_data ) {
90
-
91
-		if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists(
92
-			'sizes',
93
-			$api_response_data['pictures']
94
-		) ) {
95
-			return array();
96
-		}
97
-		if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) {
98
-			return array();
99
-		}
100
-		$pictures = $api_response_data['pictures']['sizes'];
101
-
102
-		return array_map(
103
-			function ( $picture_data ) {
104
-				return $picture_data['link'];
105
-			},
106
-			$pictures
107
-		);
108
-
109
-	}
18
+    const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key';
19
+
20
+    public static function get_api_key() {
21
+        return get_option( self::API_FIELD_NAME, false );
22
+    }
23
+
24
+    public function get_videos_data( $videos ) {
25
+
26
+        $key = $this->get_api_key();
27
+
28
+        if ( ! $key ) {
29
+            return array();
30
+        }
31
+
32
+        $urls = array_map(
33
+            function ( $video ) {
34
+                return $video->get_url();
35
+            },
36
+            $videos
37
+        );
38
+
39
+        $response_body = $this->api_client->get_data( $urls );
40
+
41
+        if ( ! is_string( $response_body ) || ! $response_body ) {
42
+            return array();
43
+        }
44
+
45
+        $response = json_decode( $response_body, true );
46
+
47
+        $video_list = $response['data'];
48
+
49
+        if ( ! is_array( $video_list ) ) {
50
+            // Return if we cant parse the response.
51
+            return array();
52
+        }
53
+
54
+        return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) );
55
+
56
+    }
57
+
58
+    public function get_video_from_video_data( $vimeo_video_data ) {
59
+
60
+        if ( ! $vimeo_video_data ) {
61
+            // If valid data not supplied dont init the object.
62
+            return false;
63
+        }
64
+        $video              = new Video();
65
+        $video->name        = $vimeo_video_data['name'];
66
+        $video->description = $vimeo_video_data['description'];
67
+
68
+        $video->content_url = $vimeo_video_data['link'];
69
+        $video->embed_url   = 'https://player.vimeo.com/video/' . $this->get_id( $vimeo_video_data );
70
+        if ( is_numeric( $vimeo_video_data['duration'] ) ) {
71
+            $video->duration = 'PT' . $vimeo_video_data['duration'] . 'S';
72
+        }
73
+        $video->upload_date    = $vimeo_video_data['release_time'];
74
+        $video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data );
75
+        $video->id             = $video->content_url;
76
+
77
+        if ( array_key_exists( 'stats', $vimeo_video_data )
78
+             && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) {
79
+            $video->views = (int) $vimeo_video_data['stats']['plays'];
80
+        }
81
+
82
+        return $video;
83
+    }
84
+
85
+    private function get_id( $api_response_data ) {
86
+        return str_replace( '/videos/', '', $api_response_data['uri'] );
87
+    }
88
+
89
+    private function set_thumbnail_urls( $api_response_data ) {
90
+
91
+        if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists(
92
+            'sizes',
93
+            $api_response_data['pictures']
94
+        ) ) {
95
+            return array();
96
+        }
97
+        if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) {
98
+            return array();
99
+        }
100
+        $pictures = $api_response_data['pictures']['sizes'];
101
+
102
+        return array_map(
103
+            function ( $picture_data ) {
104
+                return $picture_data['link'];
105
+            },
106
+            $pictures
107
+        );
108
+
109
+    }
110 110
 
111 111
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@  discard block
 block discarded – undo
18 18
 	const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key';
19 19
 
20 20
 	public static function get_api_key() {
21
-		return get_option( self::API_FIELD_NAME, false );
21
+		return get_option(self::API_FIELD_NAME, false);
22 22
 	}
23 23
 
24
-	public function get_videos_data( $videos ) {
24
+	public function get_videos_data($videos) {
25 25
 
26 26
 		$key = $this->get_api_key();
27 27
 
28
-		if ( ! $key ) {
28
+		if ( ! $key) {
29 29
 			return array();
30 30
 		}
31 31
 
32 32
 		$urls = array_map(
33
-			function ( $video ) {
33
+			function($video) {
34 34
 				return $video->get_url();
35 35
 			},
36 36
 			$videos
37 37
 		);
38 38
 
39
-		$response_body = $this->api_client->get_data( $urls );
39
+		$response_body = $this->api_client->get_data($urls);
40 40
 
41
-		if ( ! is_string( $response_body ) || ! $response_body ) {
41
+		if ( ! is_string($response_body) || ! $response_body) {
42 42
 			return array();
43 43
 		}
44 44
 
45
-		$response = json_decode( $response_body, true );
45
+		$response = json_decode($response_body, true);
46 46
 
47 47
 		$video_list = $response['data'];
48 48
 
49
-		if ( ! is_array( $video_list ) ) {
49
+		if ( ! is_array($video_list)) {
50 50
 			// Return if we cant parse the response.
51 51
 			return array();
52 52
 		}
53 53
 
54
-		return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) );
54
+		return array_filter(array_map(array($this, 'get_video_from_video_data'), $video_list));
55 55
 
56 56
 	}
57 57
 
58
-	public function get_video_from_video_data( $vimeo_video_data ) {
58
+	public function get_video_from_video_data($vimeo_video_data) {
59 59
 
60
-		if ( ! $vimeo_video_data ) {
60
+		if ( ! $vimeo_video_data) {
61 61
 			// If valid data not supplied dont init the object.
62 62
 			return false;
63 63
 		}
@@ -66,41 +66,41 @@  discard block
 block discarded – undo
66 66
 		$video->description = $vimeo_video_data['description'];
67 67
 
68 68
 		$video->content_url = $vimeo_video_data['link'];
69
-		$video->embed_url   = 'https://player.vimeo.com/video/' . $this->get_id( $vimeo_video_data );
70
-		if ( is_numeric( $vimeo_video_data['duration'] ) ) {
71
-			$video->duration = 'PT' . $vimeo_video_data['duration'] . 'S';
69
+		$video->embed_url   = 'https://player.vimeo.com/video/'.$this->get_id($vimeo_video_data);
70
+		if (is_numeric($vimeo_video_data['duration'])) {
71
+			$video->duration = 'PT'.$vimeo_video_data['duration'].'S';
72 72
 		}
73 73
 		$video->upload_date    = $vimeo_video_data['release_time'];
74
-		$video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data );
74
+		$video->thumbnail_urls = $this->set_thumbnail_urls($vimeo_video_data);
75 75
 		$video->id             = $video->content_url;
76 76
 
77
-		if ( array_key_exists( 'stats', $vimeo_video_data )
78
-			 && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) {
77
+		if (array_key_exists('stats', $vimeo_video_data)
78
+			 && array_key_exists('plays', $vimeo_video_data['stats'])) {
79 79
 			$video->views = (int) $vimeo_video_data['stats']['plays'];
80 80
 		}
81 81
 
82 82
 		return $video;
83 83
 	}
84 84
 
85
-	private function get_id( $api_response_data ) {
86
-		return str_replace( '/videos/', '', $api_response_data['uri'] );
85
+	private function get_id($api_response_data) {
86
+		return str_replace('/videos/', '', $api_response_data['uri']);
87 87
 	}
88 88
 
89
-	private function set_thumbnail_urls( $api_response_data ) {
89
+	private function set_thumbnail_urls($api_response_data) {
90 90
 
91
-		if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists(
91
+		if ( ! array_key_exists('pictures', $api_response_data) || ! array_key_exists(
92 92
 			'sizes',
93 93
 			$api_response_data['pictures']
94
-		) ) {
94
+		)) {
95 95
 			return array();
96 96
 		}
97
-		if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) {
97
+		if ( ! is_array($api_response_data['pictures']['sizes'])) {
98 98
 			return array();
99 99
 		}
100 100
 		$pictures = $api_response_data['pictures']['sizes'];
101 101
 
102 102
 		return array_map(
103
-			function ( $picture_data ) {
103
+			function($picture_data) {
104 104
 				return $picture_data['link'];
105 105
 			},
106 106
 			$pictures
Please login to merge, or discard this patch.