@@ -10,21 +10,21 @@ |
||
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 | } |
@@ -16,13 +16,13 @@ |
||
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 | } |
@@ -15,97 +15,97 @@ |
||
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 | } |
@@ -18,46 +18,46 @@ discard block |
||
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 |
||
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 |
@@ -11,81 +11,81 @@ |
||
11 | 11 | |
12 | 12 | class Jw_Player extends Api_Provider { |
13 | 13 | |
14 | - /** |
|
15 | - * @param $videos array<Embedded_Video> |
|
16 | - * |
|
17 | - * @return array<Video> |
|
18 | - */ |
|
19 | - public function get_videos_data( $videos ) { |
|
20 | - |
|
21 | - $video_urls = array_map( |
|
22 | - function ( $video ) { |
|
23 | - return $video->get_url(); |
|
24 | - }, |
|
25 | - $videos |
|
26 | - ); |
|
27 | - |
|
28 | - $videos_data = $this->api_client->get_data( $video_urls ); |
|
29 | - |
|
30 | - return array_filter( |
|
31 | - array_map( |
|
32 | - function ( $video_data ) { |
|
33 | - |
|
34 | - if ( ! array_key_exists( 'playlist', $video_data ) |
|
35 | - |
|
36 | - || ! is_array( $video_data['playlist'] ) |
|
37 | - |
|
38 | - || count( $video_data['playlist'] ) === 0 ) { |
|
39 | - |
|
40 | - return false; |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - $video = new Video(); |
|
45 | - $video->id = $video_data['id']; |
|
46 | - $playlist_item_data = $video_data['playlist'][0]; |
|
47 | - $video->name = $playlist_item_data['title']; |
|
48 | - $video->description = $playlist_item_data['description']; |
|
49 | - $video->thumbnail_urls = array_filter( |
|
50 | - array_map( |
|
51 | - function ( $item ) { |
|
52 | - return $item['src']; |
|
53 | - }, |
|
54 | - $playlist_item_data['images'] |
|
55 | - ) |
|
56 | - ); |
|
57 | - |
|
58 | - $video->duration = 'PT' . (int) $playlist_item_data['duration'] . 'S'; |
|
59 | - $video->upload_date = gmdate( 'c', (int) $playlist_item_data['pubdate'] ); |
|
60 | - |
|
61 | - $video_content_urls_data = array_filter( |
|
62 | - $playlist_item_data['sources'], |
|
63 | - function ( $item ) { |
|
64 | - return strpos( $item['type'], 'video/' ) !== false; |
|
65 | - } |
|
66 | - ); |
|
67 | - |
|
68 | - $video_content_urls = array_map( |
|
69 | - function ( $item ) { |
|
70 | - return $item['file']; |
|
71 | - }, |
|
72 | - $video_content_urls_data |
|
73 | - ); |
|
74 | - |
|
75 | - // Content url is a single field, so we pick the video with |
|
76 | - // high resolution. |
|
77 | - $video->content_url = array_pop( $video_content_urls ); |
|
78 | - |
|
79 | - // We dont have embed url for JW Player. |
|
80 | - $video->embed_url = ''; |
|
81 | - |
|
82 | - return $video; |
|
83 | - |
|
84 | - }, |
|
85 | - $videos_data |
|
86 | - ) |
|
87 | - ); |
|
88 | - |
|
89 | - } |
|
14 | + /** |
|
15 | + * @param $videos array<Embedded_Video> |
|
16 | + * |
|
17 | + * @return array<Video> |
|
18 | + */ |
|
19 | + public function get_videos_data( $videos ) { |
|
20 | + |
|
21 | + $video_urls = array_map( |
|
22 | + function ( $video ) { |
|
23 | + return $video->get_url(); |
|
24 | + }, |
|
25 | + $videos |
|
26 | + ); |
|
27 | + |
|
28 | + $videos_data = $this->api_client->get_data( $video_urls ); |
|
29 | + |
|
30 | + return array_filter( |
|
31 | + array_map( |
|
32 | + function ( $video_data ) { |
|
33 | + |
|
34 | + if ( ! array_key_exists( 'playlist', $video_data ) |
|
35 | + |
|
36 | + || ! is_array( $video_data['playlist'] ) |
|
37 | + |
|
38 | + || count( $video_data['playlist'] ) === 0 ) { |
|
39 | + |
|
40 | + return false; |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + $video = new Video(); |
|
45 | + $video->id = $video_data['id']; |
|
46 | + $playlist_item_data = $video_data['playlist'][0]; |
|
47 | + $video->name = $playlist_item_data['title']; |
|
48 | + $video->description = $playlist_item_data['description']; |
|
49 | + $video->thumbnail_urls = array_filter( |
|
50 | + array_map( |
|
51 | + function ( $item ) { |
|
52 | + return $item['src']; |
|
53 | + }, |
|
54 | + $playlist_item_data['images'] |
|
55 | + ) |
|
56 | + ); |
|
57 | + |
|
58 | + $video->duration = 'PT' . (int) $playlist_item_data['duration'] . 'S'; |
|
59 | + $video->upload_date = gmdate( 'c', (int) $playlist_item_data['pubdate'] ); |
|
60 | + |
|
61 | + $video_content_urls_data = array_filter( |
|
62 | + $playlist_item_data['sources'], |
|
63 | + function ( $item ) { |
|
64 | + return strpos( $item['type'], 'video/' ) !== false; |
|
65 | + } |
|
66 | + ); |
|
67 | + |
|
68 | + $video_content_urls = array_map( |
|
69 | + function ( $item ) { |
|
70 | + return $item['file']; |
|
71 | + }, |
|
72 | + $video_content_urls_data |
|
73 | + ); |
|
74 | + |
|
75 | + // Content url is a single field, so we pick the video with |
|
76 | + // high resolution. |
|
77 | + $video->content_url = array_pop( $video_content_urls ); |
|
78 | + |
|
79 | + // We dont have embed url for JW Player. |
|
80 | + $video->embed_url = ''; |
|
81 | + |
|
82 | + return $video; |
|
83 | + |
|
84 | + }, |
|
85 | + $videos_data |
|
86 | + ) |
|
87 | + ); |
|
88 | + |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |
@@ -16,26 +16,26 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @return array<Video> |
18 | 18 | */ |
19 | - public function get_videos_data( $videos ) { |
|
19 | + public function get_videos_data($videos) { |
|
20 | 20 | |
21 | 21 | $video_urls = array_map( |
22 | - function ( $video ) { |
|
22 | + function($video) { |
|
23 | 23 | return $video->get_url(); |
24 | 24 | }, |
25 | 25 | $videos |
26 | 26 | ); |
27 | 27 | |
28 | - $videos_data = $this->api_client->get_data( $video_urls ); |
|
28 | + $videos_data = $this->api_client->get_data($video_urls); |
|
29 | 29 | |
30 | 30 | return array_filter( |
31 | 31 | array_map( |
32 | - function ( $video_data ) { |
|
32 | + function($video_data) { |
|
33 | 33 | |
34 | - if ( ! array_key_exists( 'playlist', $video_data ) |
|
34 | + if ( ! array_key_exists('playlist', $video_data) |
|
35 | 35 | |
36 | - || ! is_array( $video_data['playlist'] ) |
|
36 | + || ! is_array($video_data['playlist']) |
|
37 | 37 | |
38 | - || count( $video_data['playlist'] ) === 0 ) { |
|
38 | + || count($video_data['playlist']) === 0) { |
|
39 | 39 | |
40 | 40 | return false; |
41 | 41 | |
@@ -48,25 +48,25 @@ discard block |
||
48 | 48 | $video->description = $playlist_item_data['description']; |
49 | 49 | $video->thumbnail_urls = array_filter( |
50 | 50 | array_map( |
51 | - function ( $item ) { |
|
51 | + function($item) { |
|
52 | 52 | return $item['src']; |
53 | 53 | }, |
54 | 54 | $playlist_item_data['images'] |
55 | 55 | ) |
56 | 56 | ); |
57 | 57 | |
58 | - $video->duration = 'PT' . (int) $playlist_item_data['duration'] . 'S'; |
|
59 | - $video->upload_date = gmdate( 'c', (int) $playlist_item_data['pubdate'] ); |
|
58 | + $video->duration = 'PT'.(int) $playlist_item_data['duration'].'S'; |
|
59 | + $video->upload_date = gmdate('c', (int) $playlist_item_data['pubdate']); |
|
60 | 60 | |
61 | 61 | $video_content_urls_data = array_filter( |
62 | 62 | $playlist_item_data['sources'], |
63 | - function ( $item ) { |
|
64 | - return strpos( $item['type'], 'video/' ) !== false; |
|
63 | + function($item) { |
|
64 | + return strpos($item['type'], 'video/') !== false; |
|
65 | 65 | } |
66 | 66 | ); |
67 | 67 | |
68 | 68 | $video_content_urls = array_map( |
69 | - function ( $item ) { |
|
69 | + function($item) { |
|
70 | 70 | return $item['file']; |
71 | 71 | }, |
72 | 72 | $video_content_urls_data |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | // Content url is a single field, so we pick the video with |
76 | 76 | // high resolution. |
77 | - $video->content_url = array_pop( $video_content_urls ); |
|
77 | + $video->content_url = array_pop($video_content_urls); |
|
78 | 78 | |
79 | 79 | // We dont have embed url for JW Player. |
80 | 80 | $video->embed_url = ''; |
@@ -11,50 +11,50 @@ |
||
11 | 11 | */ |
12 | 12 | class Jw_Player_Client extends Singleton implements Client { |
13 | 13 | |
14 | - public function get_data( $video_urls ) { |
|
14 | + public function get_data( $video_urls ) { |
|
15 | 15 | |
16 | - $videos_data = array(); |
|
16 | + $videos_data = array(); |
|
17 | 17 | |
18 | - foreach ( $video_urls as $video_url ) { |
|
19 | - $data = wp_remote_get( $video_url ); |
|
20 | - if ( is_wp_error( $data ) ) { |
|
21 | - continue; |
|
22 | - } |
|
23 | - $json_body = wp_remote_retrieve_body( $data ); |
|
18 | + foreach ( $video_urls as $video_url ) { |
|
19 | + $data = wp_remote_get( $video_url ); |
|
20 | + if ( is_wp_error( $data ) ) { |
|
21 | + continue; |
|
22 | + } |
|
23 | + $json_body = wp_remote_retrieve_body( $data ); |
|
24 | 24 | |
25 | - $video_data = json_decode( $json_body, true ); |
|
26 | - if ( ! $video_data ) { |
|
27 | - continue; |
|
28 | - } |
|
29 | - $video_data['id'] = $video_url; |
|
30 | - $videos_data[] = $video_data; |
|
31 | - } |
|
25 | + $video_data = json_decode( $json_body, true ); |
|
26 | + if ( ! $video_data ) { |
|
27 | + continue; |
|
28 | + } |
|
29 | + $video_data['id'] = $video_url; |
|
30 | + $videos_data[] = $video_data; |
|
31 | + } |
|
32 | 32 | |
33 | - return $videos_data; |
|
33 | + return $videos_data; |
|
34 | 34 | |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - public function get_video_ids( $video_urls ) { |
|
37 | + public function get_video_ids( $video_urls ) { |
|
38 | 38 | |
39 | - return array_filter( |
|
40 | - $video_urls, |
|
41 | - function ( $item ) { |
|
42 | - return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
43 | - } |
|
44 | - ); |
|
39 | + return array_filter( |
|
40 | + $video_urls, |
|
41 | + function ( $item ) { |
|
42 | + return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
43 | + } |
|
44 | + ); |
|
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public static function get_api_key() { |
|
49 | - // Method not implemented, since we dont need api key |
|
50 | - } |
|
48 | + public static function get_api_key() { |
|
49 | + // Method not implemented, since we dont need api key |
|
50 | + } |
|
51 | 51 | |
52 | - public static function get_api_key_option_name() { |
|
53 | - // Method not implemented, since we dont need api key |
|
54 | - } |
|
52 | + public static function get_api_key_option_name() { |
|
53 | + // Method not implemented, since we dont need api key |
|
54 | + } |
|
55 | 55 | |
56 | - public function get_api_url() { |
|
57 | - // Method not implemented, since we dont need api key |
|
58 | - } |
|
56 | + public function get_api_url() { |
|
57 | + // Method not implemented, since we dont need api key |
|
58 | + } |
|
59 | 59 | |
60 | 60 | } |
@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class Jw_Player_Client extends Singleton implements Client { |
13 | 13 | |
14 | - public function get_data( $video_urls ) { |
|
14 | + public function get_data($video_urls) { |
|
15 | 15 | |
16 | 16 | $videos_data = array(); |
17 | 17 | |
18 | - foreach ( $video_urls as $video_url ) { |
|
19 | - $data = wp_remote_get( $video_url ); |
|
20 | - if ( is_wp_error( $data ) ) { |
|
18 | + foreach ($video_urls as $video_url) { |
|
19 | + $data = wp_remote_get($video_url); |
|
20 | + if (is_wp_error($data)) { |
|
21 | 21 | continue; |
22 | 22 | } |
23 | - $json_body = wp_remote_retrieve_body( $data ); |
|
23 | + $json_body = wp_remote_retrieve_body($data); |
|
24 | 24 | |
25 | - $video_data = json_decode( $json_body, true ); |
|
26 | - if ( ! $video_data ) { |
|
25 | + $video_data = json_decode($json_body, true); |
|
26 | + if ( ! $video_data) { |
|
27 | 27 | continue; |
28 | 28 | } |
29 | 29 | $video_data['id'] = $video_url; |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | |
35 | 35 | } |
36 | 36 | |
37 | - public function get_video_ids( $video_urls ) { |
|
37 | + public function get_video_ids($video_urls) { |
|
38 | 38 | |
39 | 39 | return array_filter( |
40 | 40 | $video_urls, |
41 | - function ( $item ) { |
|
42 | - return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
41 | + function($item) { |
|
42 | + return strpos($item, 'https://cdn.jwplayer.com/v2/media/', 0) !== false; |
|
43 | 43 | } |
44 | 44 | ); |
45 | 45 |
@@ -9,20 +9,20 @@ |
||
9 | 9 | */ |
10 | 10 | class Client_Factory { |
11 | 11 | |
12 | - const YOUTUBE = 'youtube'; |
|
12 | + const YOUTUBE = 'youtube'; |
|
13 | 13 | |
14 | - const VIMEO = 'vimeo'; |
|
14 | + const VIMEO = 'vimeo'; |
|
15 | 15 | |
16 | - const JWPLAYER = 'jwplayer'; |
|
16 | + const JWPLAYER = 'jwplayer'; |
|
17 | 17 | |
18 | - public static function get_client( $config ) { |
|
19 | - if ( self::YOUTUBE === $config ) { |
|
20 | - return Youtube_Client::get_instance(); |
|
21 | - } elseif ( self::VIMEO === $config ) { |
|
22 | - return Vimeo_Client::get_instance(); |
|
23 | - } elseif ( self::JWPLAYER === $config ) { |
|
24 | - return Jw_Player_Client::get_instance(); |
|
25 | - } |
|
18 | + public static function get_client( $config ) { |
|
19 | + if ( self::YOUTUBE === $config ) { |
|
20 | + return Youtube_Client::get_instance(); |
|
21 | + } elseif ( self::VIMEO === $config ) { |
|
22 | + return Vimeo_Client::get_instance(); |
|
23 | + } elseif ( self::JWPLAYER === $config ) { |
|
24 | + return Jw_Player_Client::get_instance(); |
|
25 | + } |
|
26 | 26 | |
27 | - } |
|
27 | + } |
|
28 | 28 | } |
@@ -15,12 +15,12 @@ |
||
15 | 15 | |
16 | 16 | const JWPLAYER = 'jwplayer'; |
17 | 17 | |
18 | - public static function get_client( $config ) { |
|
19 | - if ( self::YOUTUBE === $config ) { |
|
18 | + public static function get_client($config) { |
|
19 | + if (self::YOUTUBE === $config) { |
|
20 | 20 | return Youtube_Client::get_instance(); |
21 | - } elseif ( self::VIMEO === $config ) { |
|
21 | + } elseif (self::VIMEO === $config) { |
|
22 | 22 | return Vimeo_Client::get_instance(); |
23 | - } elseif ( self::JWPLAYER === $config ) { |
|
23 | + } elseif (self::JWPLAYER === $config) { |
|
24 | 24 | return Jw_Player_Client::get_instance(); |
25 | 25 | } |
26 | 26 |
@@ -11,75 +11,75 @@ |
||
11 | 11 | */ |
12 | 12 | class Youtube_Client extends Singleton implements Client { |
13 | 13 | |
14 | - const YOUTUBE_REGEX = '/(?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]+)/m'; |
|
14 | + const YOUTUBE_REGEX = '/(?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]+)/m'; |
|
15 | 15 | |
16 | - public static $requests_sent = 0; |
|
16 | + public static $requests_sent = 0; |
|
17 | 17 | |
18 | - public static function get_api_key_option_name() { |
|
19 | - return '__wl_video_object_youtube_api_key'; |
|
20 | - } |
|
18 | + public static function get_api_key_option_name() { |
|
19 | + return '__wl_video_object_youtube_api_key'; |
|
20 | + } |
|
21 | 21 | |
22 | - public static function get_api_key() { |
|
23 | - return get_option( self::get_api_key_option_name(), false ); |
|
24 | - } |
|
22 | + public static function get_api_key() { |
|
23 | + return get_option( self::get_api_key_option_name(), false ); |
|
24 | + } |
|
25 | 25 | |
26 | - public function get_api_url() { |
|
27 | - return 'https://www.googleapis.com/youtube/v3/videos'; |
|
28 | - } |
|
26 | + public function get_api_url() { |
|
27 | + return 'https://www.googleapis.com/youtube/v3/videos'; |
|
28 | + } |
|
29 | 29 | |
30 | - public function get_data( $video_urls ) { |
|
31 | - $video_ids = $this->get_video_ids_as_string( $video_urls ); |
|
32 | - $url = add_query_arg( |
|
33 | - array( |
|
34 | - 'part' => 'snippet,contentDetails,statistics,liveStreamingDetails', |
|
35 | - 'id' => $video_ids, |
|
36 | - 'key' => $this->get_api_key(), |
|
37 | - ), |
|
38 | - $this->get_api_url() |
|
39 | - ); |
|
30 | + public function get_data( $video_urls ) { |
|
31 | + $video_ids = $this->get_video_ids_as_string( $video_urls ); |
|
32 | + $url = add_query_arg( |
|
33 | + array( |
|
34 | + 'part' => 'snippet,contentDetails,statistics,liveStreamingDetails', |
|
35 | + 'id' => $video_ids, |
|
36 | + 'key' => $this->get_api_key(), |
|
37 | + ), |
|
38 | + $this->get_api_url() |
|
39 | + ); |
|
40 | 40 | |
41 | - $response = wp_remote_get( $url ); |
|
41 | + $response = wp_remote_get( $url ); |
|
42 | 42 | |
43 | - ++ self::$requests_sent; |
|
43 | + ++ self::$requests_sent; |
|
44 | 44 | |
45 | - return wp_remote_retrieve_body( $response ); |
|
46 | - } |
|
45 | + return wp_remote_retrieve_body( $response ); |
|
46 | + } |
|
47 | 47 | |
48 | - private function get_video_ids_as_string( $video_urls ) { |
|
49 | - // validate the urls. |
|
50 | - $video_urls = array_filter( |
|
51 | - $video_urls, |
|
52 | - function ( $url ) { |
|
53 | - return filter_var( $url, FILTER_VALIDATE_URL ); |
|
54 | - } |
|
55 | - ); |
|
48 | + private function get_video_ids_as_string( $video_urls ) { |
|
49 | + // validate the urls. |
|
50 | + $video_urls = array_filter( |
|
51 | + $video_urls, |
|
52 | + function ( $url ) { |
|
53 | + return filter_var( $url, FILTER_VALIDATE_URL ); |
|
54 | + } |
|
55 | + ); |
|
56 | 56 | |
57 | - // extract the video ids. |
|
58 | - return join( ',', $this->get_video_ids( $video_urls ) ); |
|
59 | - } |
|
57 | + // extract the video ids. |
|
58 | + return join( ',', $this->get_video_ids( $video_urls ) ); |
|
59 | + } |
|
60 | 60 | |
61 | - public function get_video_ids( $video_urls ) { |
|
61 | + public function get_video_ids( $video_urls ) { |
|
62 | 62 | |
63 | - $regex = self::YOUTUBE_REGEX; |
|
63 | + $regex = self::YOUTUBE_REGEX; |
|
64 | 64 | |
65 | - $video_ids = array_map( |
|
66 | - function ( $url ) use ( $regex ) { |
|
67 | - $matches = array(); |
|
68 | - preg_match( $regex, $url, $matches ); |
|
65 | + $video_ids = array_map( |
|
66 | + function ( $url ) use ( $regex ) { |
|
67 | + $matches = array(); |
|
68 | + preg_match( $regex, $url, $matches ); |
|
69 | 69 | |
70 | - // Return video id or return false. |
|
71 | - if ( isset( $matches[1] ) && is_string( $matches[1] ) ) { |
|
72 | - return $matches[1]; |
|
73 | - } |
|
70 | + // Return video id or return false. |
|
71 | + if ( isset( $matches[1] ) && is_string( $matches[1] ) ) { |
|
72 | + return $matches[1]; |
|
73 | + } |
|
74 | 74 | |
75 | - return false; |
|
75 | + return false; |
|
76 | 76 | |
77 | - }, |
|
78 | - $video_urls |
|
79 | - ); |
|
77 | + }, |
|
78 | + $video_urls |
|
79 | + ); |
|
80 | 80 | |
81 | - return array_values( array_filter( $video_ids ) ); |
|
81 | + return array_values( array_filter( $video_ids ) ); |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function get_api_key() { |
23 | - return get_option( self::get_api_key_option_name(), false ); |
|
23 | + return get_option(self::get_api_key_option_name(), false); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function get_api_url() { |
27 | 27 | return 'https://www.googleapis.com/youtube/v3/videos'; |
28 | 28 | } |
29 | 29 | |
30 | - public function get_data( $video_urls ) { |
|
31 | - $video_ids = $this->get_video_ids_as_string( $video_urls ); |
|
30 | + public function get_data($video_urls) { |
|
31 | + $video_ids = $this->get_video_ids_as_string($video_urls); |
|
32 | 32 | $url = add_query_arg( |
33 | 33 | array( |
34 | 34 | 'part' => 'snippet,contentDetails,statistics,liveStreamingDetails', |
@@ -38,37 +38,35 @@ discard block |
||
38 | 38 | $this->get_api_url() |
39 | 39 | ); |
40 | 40 | |
41 | - $response = wp_remote_get( $url ); |
|
41 | + $response = wp_remote_get($url);++ self::$requests_sent; |
|
42 | 42 | |
43 | - ++ self::$requests_sent; |
|
44 | - |
|
45 | - return wp_remote_retrieve_body( $response ); |
|
43 | + return wp_remote_retrieve_body($response); |
|
46 | 44 | } |
47 | 45 | |
48 | - private function get_video_ids_as_string( $video_urls ) { |
|
46 | + private function get_video_ids_as_string($video_urls) { |
|
49 | 47 | // validate the urls. |
50 | 48 | $video_urls = array_filter( |
51 | 49 | $video_urls, |
52 | - function ( $url ) { |
|
53 | - return filter_var( $url, FILTER_VALIDATE_URL ); |
|
50 | + function($url) { |
|
51 | + return filter_var($url, FILTER_VALIDATE_URL); |
|
54 | 52 | } |
55 | 53 | ); |
56 | 54 | |
57 | 55 | // extract the video ids. |
58 | - return join( ',', $this->get_video_ids( $video_urls ) ); |
|
56 | + return join(',', $this->get_video_ids($video_urls)); |
|
59 | 57 | } |
60 | 58 | |
61 | - public function get_video_ids( $video_urls ) { |
|
59 | + public function get_video_ids($video_urls) { |
|
62 | 60 | |
63 | 61 | $regex = self::YOUTUBE_REGEX; |
64 | 62 | |
65 | 63 | $video_ids = array_map( |
66 | - function ( $url ) use ( $regex ) { |
|
64 | + function($url) use ($regex) { |
|
67 | 65 | $matches = array(); |
68 | - preg_match( $regex, $url, $matches ); |
|
66 | + preg_match($regex, $url, $matches); |
|
69 | 67 | |
70 | 68 | // Return video id or return false. |
71 | - if ( isset( $matches[1] ) && is_string( $matches[1] ) ) { |
|
69 | + if (isset($matches[1]) && is_string($matches[1])) { |
|
72 | 70 | return $matches[1]; |
73 | 71 | } |
74 | 72 | |
@@ -78,7 +76,7 @@ discard block |
||
78 | 76 | $video_urls |
79 | 77 | ); |
80 | 78 | |
81 | - return array_values( array_filter( $video_ids ) ); |
|
79 | + return array_values(array_filter($video_ids)); |
|
82 | 80 | |
83 | 81 | } |
84 | 82 |
@@ -11,83 +11,83 @@ |
||
11 | 11 | */ |
12 | 12 | class Vimeo_Client extends Singleton implements Client { |
13 | 13 | |
14 | - public static $requests_sent = 0; |
|
14 | + public static $requests_sent = 0; |
|
15 | 15 | |
16 | - const VIMEO_URL_REGEX = '/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/'; |
|
16 | + const VIMEO_URL_REGEX = '/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/'; |
|
17 | 17 | |
18 | - public function get_data( $video_urls ) { |
|
18 | + public function get_data( $video_urls ) { |
|
19 | 19 | |
20 | - $vimeo_ids = $this->get_video_ids( $video_urls ); |
|
20 | + $vimeo_ids = $this->get_video_ids( $video_urls ); |
|
21 | 21 | |
22 | - $vimeo_api_ids = array_map( |
|
23 | - function ( $item ) { |
|
24 | - return '/videos/' . $item; |
|
25 | - }, |
|
26 | - $vimeo_ids |
|
27 | - ); |
|
22 | + $vimeo_api_ids = array_map( |
|
23 | + function ( $item ) { |
|
24 | + return '/videos/' . $item; |
|
25 | + }, |
|
26 | + $vimeo_ids |
|
27 | + ); |
|
28 | 28 | |
29 | - $ids = join( ',', $vimeo_api_ids ); |
|
29 | + $ids = join( ',', $vimeo_api_ids ); |
|
30 | 30 | |
31 | - if ( ! $ids ) { |
|
32 | - return array(); |
|
33 | - } |
|
31 | + if ( ! $ids ) { |
|
32 | + return array(); |
|
33 | + } |
|
34 | 34 | |
35 | - $api_url = $this->get_api_url() . '/videos/'; |
|
36 | - $api_url = add_query_arg( |
|
37 | - array( |
|
38 | - 'uris' => $ids, |
|
39 | - 'fields' => 'name,description,link,uri,duration,release_time,pictures,stats', |
|
40 | - ), |
|
41 | - $api_url |
|
42 | - ); |
|
35 | + $api_url = $this->get_api_url() . '/videos/'; |
|
36 | + $api_url = add_query_arg( |
|
37 | + array( |
|
38 | + 'uris' => $ids, |
|
39 | + 'fields' => 'name,description,link,uri,duration,release_time,pictures,stats', |
|
40 | + ), |
|
41 | + $api_url |
|
42 | + ); |
|
43 | 43 | |
44 | - $response = wp_remote_get( |
|
45 | - $api_url, |
|
46 | - array( |
|
47 | - 'headers' => array( |
|
48 | - 'Authorization' => 'bearer ' . $this->get_api_key(), |
|
49 | - ), |
|
50 | - ) |
|
51 | - ); |
|
44 | + $response = wp_remote_get( |
|
45 | + $api_url, |
|
46 | + array( |
|
47 | + 'headers' => array( |
|
48 | + 'Authorization' => 'bearer ' . $this->get_api_key(), |
|
49 | + ), |
|
50 | + ) |
|
51 | + ); |
|
52 | 52 | |
53 | - ++ self::$requests_sent; |
|
53 | + ++ self::$requests_sent; |
|
54 | 54 | |
55 | - return wp_remote_retrieve_body( $response ); |
|
56 | - } |
|
55 | + return wp_remote_retrieve_body( $response ); |
|
56 | + } |
|
57 | 57 | |
58 | - public static function get_api_key() { |
|
59 | - return get_option( self::get_api_key_option_name(), false ); |
|
60 | - } |
|
58 | + public static function get_api_key() { |
|
59 | + return get_option( self::get_api_key_option_name(), false ); |
|
60 | + } |
|
61 | 61 | |
62 | - public static function get_api_key_option_name() { |
|
63 | - return '_wl_videoobject_vimeo_api_key'; |
|
64 | - } |
|
62 | + public static function get_api_key_option_name() { |
|
63 | + return '_wl_videoobject_vimeo_api_key'; |
|
64 | + } |
|
65 | 65 | |
66 | - public function get_api_url() { |
|
67 | - return 'https://api.vimeo.com'; |
|
68 | - } |
|
66 | + public function get_api_url() { |
|
67 | + return 'https://api.vimeo.com'; |
|
68 | + } |
|
69 | 69 | |
70 | - public function get_video_ids( $video_urls ) { |
|
70 | + public function get_video_ids( $video_urls ) { |
|
71 | 71 | |
72 | - $that = $this; |
|
72 | + $that = $this; |
|
73 | 73 | |
74 | - return array_filter( |
|
75 | - array_map( |
|
76 | - function ( $video_url ) use ( $that ) { |
|
77 | - if ( ! $video_url ) { |
|
78 | - return false; |
|
79 | - } |
|
80 | - preg_match( $that::VIMEO_URL_REGEX, $video_url, $matches ); |
|
74 | + return array_filter( |
|
75 | + array_map( |
|
76 | + function ( $video_url ) use ( $that ) { |
|
77 | + if ( ! $video_url ) { |
|
78 | + return false; |
|
79 | + } |
|
80 | + preg_match( $that::VIMEO_URL_REGEX, $video_url, $matches ); |
|
81 | 81 | |
82 | - if ( ! array_key_exists( 3, $matches ) ) { |
|
83 | - return false; |
|
84 | - } |
|
82 | + if ( ! array_key_exists( 3, $matches ) ) { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | |
86 | - return $matches[3]; |
|
86 | + return $matches[3]; |
|
87 | 87 | |
88 | - }, |
|
89 | - $video_urls |
|
90 | - ) |
|
91 | - ); |
|
92 | - } |
|
88 | + }, |
|
89 | + $video_urls |
|
90 | + ) |
|
91 | + ); |
|
92 | + } |
|
93 | 93 | } |
@@ -15,24 +15,24 @@ discard block |
||
15 | 15 | |
16 | 16 | const VIMEO_URL_REGEX = '/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/'; |
17 | 17 | |
18 | - public function get_data( $video_urls ) { |
|
18 | + public function get_data($video_urls) { |
|
19 | 19 | |
20 | - $vimeo_ids = $this->get_video_ids( $video_urls ); |
|
20 | + $vimeo_ids = $this->get_video_ids($video_urls); |
|
21 | 21 | |
22 | 22 | $vimeo_api_ids = array_map( |
23 | - function ( $item ) { |
|
24 | - return '/videos/' . $item; |
|
23 | + function($item) { |
|
24 | + return '/videos/'.$item; |
|
25 | 25 | }, |
26 | 26 | $vimeo_ids |
27 | 27 | ); |
28 | 28 | |
29 | - $ids = join( ',', $vimeo_api_ids ); |
|
29 | + $ids = join(',', $vimeo_api_ids); |
|
30 | 30 | |
31 | - if ( ! $ids ) { |
|
31 | + if ( ! $ids) { |
|
32 | 32 | return array(); |
33 | 33 | } |
34 | 34 | |
35 | - $api_url = $this->get_api_url() . '/videos/'; |
|
35 | + $api_url = $this->get_api_url().'/videos/'; |
|
36 | 36 | $api_url = add_query_arg( |
37 | 37 | array( |
38 | 38 | 'uris' => $ids, |
@@ -45,18 +45,16 @@ discard block |
||
45 | 45 | $api_url, |
46 | 46 | array( |
47 | 47 | 'headers' => array( |
48 | - 'Authorization' => 'bearer ' . $this->get_api_key(), |
|
48 | + 'Authorization' => 'bearer '.$this->get_api_key(), |
|
49 | 49 | ), |
50 | 50 | ) |
51 | - ); |
|
52 | - |
|
53 | - ++ self::$requests_sent; |
|
51 | + );++ self::$requests_sent; |
|
54 | 52 | |
55 | - return wp_remote_retrieve_body( $response ); |
|
53 | + return wp_remote_retrieve_body($response); |
|
56 | 54 | } |
57 | 55 | |
58 | 56 | public static function get_api_key() { |
59 | - return get_option( self::get_api_key_option_name(), false ); |
|
57 | + return get_option(self::get_api_key_option_name(), false); |
|
60 | 58 | } |
61 | 59 | |
62 | 60 | public static function get_api_key_option_name() { |
@@ -67,19 +65,19 @@ discard block |
||
67 | 65 | return 'https://api.vimeo.com'; |
68 | 66 | } |
69 | 67 | |
70 | - public function get_video_ids( $video_urls ) { |
|
68 | + public function get_video_ids($video_urls) { |
|
71 | 69 | |
72 | 70 | $that = $this; |
73 | 71 | |
74 | 72 | return array_filter( |
75 | 73 | array_map( |
76 | - function ( $video_url ) use ( $that ) { |
|
77 | - if ( ! $video_url ) { |
|
74 | + function($video_url) use ($that) { |
|
75 | + if ( ! $video_url) { |
|
78 | 76 | return false; |
79 | 77 | } |
80 | - preg_match( $that::VIMEO_URL_REGEX, $video_url, $matches ); |
|
78 | + preg_match($that::VIMEO_URL_REGEX, $video_url, $matches); |
|
81 | 79 | |
82 | - if ( ! array_key_exists( 3, $matches ) ) { |
|
80 | + if ( ! array_key_exists(3, $matches)) { |
|
83 | 81 | return false; |
84 | 82 | } |
85 | 83 |
@@ -7,39 +7,39 @@ |
||
7 | 7 | * This acts as interface for api clients |
8 | 8 | */ |
9 | 9 | interface Client { |
10 | - /** |
|
11 | - * |
|
12 | - * @param $video_urls array<string> Array of urls. |
|
13 | - * |
|
14 | - * Response body or false if the request cant be made or failed. |
|
15 | - * @return string | false |
|
16 | - */ |
|
17 | - public function get_data( $video_urls ); |
|
10 | + /** |
|
11 | + * |
|
12 | + * @param $video_urls array<string> Array of urls. |
|
13 | + * |
|
14 | + * Response body or false if the request cant be made or failed. |
|
15 | + * @return string | false |
|
16 | + */ |
|
17 | + public function get_data( $video_urls ); |
|
18 | 18 | |
19 | - /** |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public static function get_api_key(); |
|
23 | - /** |
|
24 | - * Returns the option where the api key is stored. |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public static function get_api_key_option_name(); |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public static function get_api_key(); |
|
23 | + /** |
|
24 | + * Returns the option where the api key is stored. |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public static function get_api_key_option_name(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * The api base url. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function get_api_url(); |
|
30 | + /** |
|
31 | + * The api base url. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function get_api_url(); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get video ids from URLs. |
|
39 | - * |
|
40 | - * @param $video_urls array<string> |
|
41 | - * @return array<string> |
|
42 | - */ |
|
43 | - public function get_video_ids( $video_urls ); |
|
37 | + /** |
|
38 | + * Get video ids from URLs. |
|
39 | + * |
|
40 | + * @param $video_urls array<string> |
|
41 | + * @return array<string> |
|
42 | + */ |
|
43 | + public function get_video_ids( $video_urls ); |
|
44 | 44 | |
45 | 45 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * Response body or false if the request cant be made or failed. |
15 | 15 | * @return string | false |
16 | 16 | */ |
17 | - public function get_data( $video_urls ); |
|
17 | + public function get_data($video_urls); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @return string |
@@ -40,6 +40,6 @@ discard block |
||
40 | 40 | * @param $video_urls array<string> |
41 | 41 | * @return array<string> |
42 | 42 | */ |
43 | - public function get_video_ids( $video_urls ); |
|
43 | + public function get_video_ids($video_urls); |
|
44 | 44 | |
45 | 45 | } |
@@ -11,175 +11,175 @@ |
||
11 | 11 | use Wordlift\Videoobject\Data\Video_Storage\Storage; |
12 | 12 | |
13 | 13 | class Jsonld { |
14 | - /** |
|
15 | - * @var Storage |
|
16 | - */ |
|
17 | - private $video_storage; |
|
18 | - |
|
19 | - /** |
|
20 | - * Jsonld constructor. |
|
21 | - * |
|
22 | - * @param $video_storage Storage |
|
23 | - */ |
|
24 | - public function __construct( $video_storage ) { |
|
25 | - add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 ); |
|
26 | - add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
27 | - $this->video_storage = $video_storage; |
|
28 | - } |
|
29 | - |
|
30 | - public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
31 | - if ( 0 === count( $jsonld ) ) { |
|
32 | - return $jsonld; |
|
33 | - } |
|
34 | - $current_item = $jsonld[0]; |
|
35 | - |
|
36 | - if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) { |
|
37 | - // Cant determine type return early. |
|
38 | - return $jsonld; |
|
39 | - } |
|
40 | - |
|
41 | - $type = $current_item['@type']; |
|
42 | - if ( is_string( $type ) ) { |
|
43 | - $type = array( $type ); |
|
44 | - } |
|
45 | - // If its a article or descendant of article, then dont add the |
|
46 | - // videoobject in this hook, they will be already added to video property. |
|
47 | - if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) { |
|
48 | - return $jsonld; |
|
49 | - } |
|
50 | - |
|
51 | - $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
|
52 | - if ( 0 === count( $videos_jsonld ) ) { |
|
53 | - return $jsonld; |
|
54 | - } |
|
55 | - |
|
56 | - // check if we have @id in jsonld for first item. |
|
57 | - $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
|
58 | - |
|
59 | - foreach ( $videos_jsonld as &$video_jsonld ) { |
|
60 | - if ( ! $id ) { |
|
61 | - continue; |
|
62 | - } |
|
63 | - if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
|
64 | - $video_jsonld['mentions'] = array( '@id' => $id ); |
|
65 | - } else { |
|
66 | - $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
|
67 | - } |
|
68 | - } |
|
69 | - |
|
70 | - return array_merge( $jsonld, $videos_jsonld ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param $existing_video_data string | array associative or sequential array. |
|
75 | - * @param $new_video_data array Sequential array. |
|
76 | - * |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - private function merge_video_data( $existing_video_data, $new_video_data ) { |
|
80 | - if ( ! is_array( $existing_video_data ) ) { |
|
81 | - $new_video_data[] = $existing_video_data; |
|
82 | - |
|
83 | - return $new_video_data; |
|
84 | - } |
|
85 | - |
|
86 | - if ( $this->is_associative_array( $existing_video_data ) ) { |
|
87 | - $new_video_data[] = $existing_video_data; |
|
88 | - |
|
89 | - return $new_video_data; |
|
90 | - } |
|
91 | - |
|
92 | - return array_merge( $existing_video_data, $new_video_data ); |
|
93 | - } |
|
94 | - |
|
95 | - public function wl_post_jsonld( $jsonld, $post_id ) { |
|
96 | - |
|
97 | - $video_jsonld = $this->get_videos_jsonld( $post_id ); |
|
98 | - if ( count( $video_jsonld ) === 0 ) { |
|
99 | - return $jsonld; |
|
100 | - } |
|
101 | - // Before adding the video jsonld check if the key |
|
102 | - // is present and additional data might be present, |
|
103 | - // if not present just add the data and return early. |
|
104 | - if ( ! array_key_exists( 'video', $jsonld ) ) { |
|
105 | - $jsonld['video'] = $video_jsonld; |
|
106 | - |
|
107 | - return $jsonld; |
|
108 | - } |
|
109 | - |
|
110 | - // since key exists, we need to merge the data based on type. |
|
111 | - $previous_video_data = $jsonld['video']; |
|
112 | - $jsonld['video'] = $this->merge_video_data( $previous_video_data, $video_jsonld ); |
|
113 | - |
|
114 | - return $jsonld; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param $post_id int Post id. |
|
119 | - * |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_videos_jsonld( $post_id ) { |
|
123 | - |
|
124 | - $videos = $this->video_storage->get_all_videos( $post_id ); |
|
125 | - |
|
126 | - $jsonld = array(); |
|
127 | - |
|
128 | - foreach ( $videos as $video ) { |
|
129 | - /** |
|
130 | - * @var $video Video |
|
131 | - */ |
|
132 | - $description = $video->description; |
|
133 | - if ( ! $video->description ) { |
|
134 | - // If description is empty then use the video title as description |
|
135 | - $description = $video->name; |
|
136 | - } |
|
137 | - $single_jsonld = array( |
|
138 | - '@context' => 'http://schema.org', |
|
139 | - '@type' => 'VideoObject', |
|
140 | - 'name' => $video->name, |
|
141 | - 'description' => $description, |
|
142 | - 'contentUrl' => $video->content_url, |
|
143 | - 'uploadDate' => $video->upload_date, |
|
144 | - 'thumbnailUrl' => $video->thumbnail_urls, |
|
145 | - 'duration' => $video->duration, |
|
146 | - ); |
|
147 | - |
|
148 | - if ( $video->embed_url ) { |
|
149 | - $single_jsonld['embedUrl'] = $video->embed_url; |
|
150 | - } |
|
151 | - |
|
152 | - if ( $video->views ) { |
|
153 | - $single_jsonld['interactionStatistic'] = array( |
|
154 | - '@type' => 'InteractionCounter', |
|
155 | - 'interactionType' => array( |
|
156 | - '@type' => 'http://schema.org/WatchAction', |
|
157 | - ), |
|
158 | - 'userInteractionCount' => $video->views, |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - if ( $video->is_live_video ) { |
|
163 | - $single_jsonld['publication'] = array( |
|
164 | - '@type' => 'BroadcastEvent', |
|
165 | - 'isLiveBroadcast' => true, |
|
166 | - 'startDate' => $video->live_video_start_date, |
|
167 | - 'endDate' => $video->live_video_end_date, |
|
168 | - ); |
|
169 | - } |
|
170 | - |
|
171 | - $jsonld[] = $single_jsonld; |
|
172 | - } |
|
173 | - |
|
174 | - return $jsonld; |
|
175 | - } |
|
176 | - |
|
177 | - private function is_associative_array( $arr ) { |
|
178 | - if ( array() === $arr ) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - |
|
182 | - return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
183 | - } |
|
14 | + /** |
|
15 | + * @var Storage |
|
16 | + */ |
|
17 | + private $video_storage; |
|
18 | + |
|
19 | + /** |
|
20 | + * Jsonld constructor. |
|
21 | + * |
|
22 | + * @param $video_storage Storage |
|
23 | + */ |
|
24 | + public function __construct( $video_storage ) { |
|
25 | + add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 ); |
|
26 | + add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
27 | + $this->video_storage = $video_storage; |
|
28 | + } |
|
29 | + |
|
30 | + public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
31 | + if ( 0 === count( $jsonld ) ) { |
|
32 | + return $jsonld; |
|
33 | + } |
|
34 | + $current_item = $jsonld[0]; |
|
35 | + |
|
36 | + if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) { |
|
37 | + // Cant determine type return early. |
|
38 | + return $jsonld; |
|
39 | + } |
|
40 | + |
|
41 | + $type = $current_item['@type']; |
|
42 | + if ( is_string( $type ) ) { |
|
43 | + $type = array( $type ); |
|
44 | + } |
|
45 | + // If its a article or descendant of article, then dont add the |
|
46 | + // videoobject in this hook, they will be already added to video property. |
|
47 | + if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) { |
|
48 | + return $jsonld; |
|
49 | + } |
|
50 | + |
|
51 | + $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
|
52 | + if ( 0 === count( $videos_jsonld ) ) { |
|
53 | + return $jsonld; |
|
54 | + } |
|
55 | + |
|
56 | + // check if we have @id in jsonld for first item. |
|
57 | + $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
|
58 | + |
|
59 | + foreach ( $videos_jsonld as &$video_jsonld ) { |
|
60 | + if ( ! $id ) { |
|
61 | + continue; |
|
62 | + } |
|
63 | + if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
|
64 | + $video_jsonld['mentions'] = array( '@id' => $id ); |
|
65 | + } else { |
|
66 | + $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
|
67 | + } |
|
68 | + } |
|
69 | + |
|
70 | + return array_merge( $jsonld, $videos_jsonld ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param $existing_video_data string | array associative or sequential array. |
|
75 | + * @param $new_video_data array Sequential array. |
|
76 | + * |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + private function merge_video_data( $existing_video_data, $new_video_data ) { |
|
80 | + if ( ! is_array( $existing_video_data ) ) { |
|
81 | + $new_video_data[] = $existing_video_data; |
|
82 | + |
|
83 | + return $new_video_data; |
|
84 | + } |
|
85 | + |
|
86 | + if ( $this->is_associative_array( $existing_video_data ) ) { |
|
87 | + $new_video_data[] = $existing_video_data; |
|
88 | + |
|
89 | + return $new_video_data; |
|
90 | + } |
|
91 | + |
|
92 | + return array_merge( $existing_video_data, $new_video_data ); |
|
93 | + } |
|
94 | + |
|
95 | + public function wl_post_jsonld( $jsonld, $post_id ) { |
|
96 | + |
|
97 | + $video_jsonld = $this->get_videos_jsonld( $post_id ); |
|
98 | + if ( count( $video_jsonld ) === 0 ) { |
|
99 | + return $jsonld; |
|
100 | + } |
|
101 | + // Before adding the video jsonld check if the key |
|
102 | + // is present and additional data might be present, |
|
103 | + // if not present just add the data and return early. |
|
104 | + if ( ! array_key_exists( 'video', $jsonld ) ) { |
|
105 | + $jsonld['video'] = $video_jsonld; |
|
106 | + |
|
107 | + return $jsonld; |
|
108 | + } |
|
109 | + |
|
110 | + // since key exists, we need to merge the data based on type. |
|
111 | + $previous_video_data = $jsonld['video']; |
|
112 | + $jsonld['video'] = $this->merge_video_data( $previous_video_data, $video_jsonld ); |
|
113 | + |
|
114 | + return $jsonld; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param $post_id int Post id. |
|
119 | + * |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_videos_jsonld( $post_id ) { |
|
123 | + |
|
124 | + $videos = $this->video_storage->get_all_videos( $post_id ); |
|
125 | + |
|
126 | + $jsonld = array(); |
|
127 | + |
|
128 | + foreach ( $videos as $video ) { |
|
129 | + /** |
|
130 | + * @var $video Video |
|
131 | + */ |
|
132 | + $description = $video->description; |
|
133 | + if ( ! $video->description ) { |
|
134 | + // If description is empty then use the video title as description |
|
135 | + $description = $video->name; |
|
136 | + } |
|
137 | + $single_jsonld = array( |
|
138 | + '@context' => 'http://schema.org', |
|
139 | + '@type' => 'VideoObject', |
|
140 | + 'name' => $video->name, |
|
141 | + 'description' => $description, |
|
142 | + 'contentUrl' => $video->content_url, |
|
143 | + 'uploadDate' => $video->upload_date, |
|
144 | + 'thumbnailUrl' => $video->thumbnail_urls, |
|
145 | + 'duration' => $video->duration, |
|
146 | + ); |
|
147 | + |
|
148 | + if ( $video->embed_url ) { |
|
149 | + $single_jsonld['embedUrl'] = $video->embed_url; |
|
150 | + } |
|
151 | + |
|
152 | + if ( $video->views ) { |
|
153 | + $single_jsonld['interactionStatistic'] = array( |
|
154 | + '@type' => 'InteractionCounter', |
|
155 | + 'interactionType' => array( |
|
156 | + '@type' => 'http://schema.org/WatchAction', |
|
157 | + ), |
|
158 | + 'userInteractionCount' => $video->views, |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + if ( $video->is_live_video ) { |
|
163 | + $single_jsonld['publication'] = array( |
|
164 | + '@type' => 'BroadcastEvent', |
|
165 | + 'isLiveBroadcast' => true, |
|
166 | + 'startDate' => $video->live_video_start_date, |
|
167 | + 'endDate' => $video->live_video_end_date, |
|
168 | + ); |
|
169 | + } |
|
170 | + |
|
171 | + $jsonld[] = $single_jsonld; |
|
172 | + } |
|
173 | + |
|
174 | + return $jsonld; |
|
175 | + } |
|
176 | + |
|
177 | + private function is_associative_array( $arr ) { |
|
178 | + if ( array() === $arr ) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + |
|
182 | + return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | } |
@@ -21,53 +21,53 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param $video_storage Storage |
23 | 23 | */ |
24 | - public function __construct( $video_storage ) { |
|
25 | - add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 2 ); |
|
26 | - add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
24 | + public function __construct($video_storage) { |
|
25 | + add_action('wl_post_jsonld', array($this, 'wl_post_jsonld'), 10, 2); |
|
26 | + add_action('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2); |
|
27 | 27 | $this->video_storage = $video_storage; |
28 | 28 | } |
29 | 29 | |
30 | - public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
31 | - if ( 0 === count( $jsonld ) ) { |
|
30 | + public function wl_after_get_jsonld($jsonld, $post_id) { |
|
31 | + if (0 === count($jsonld)) { |
|
32 | 32 | return $jsonld; |
33 | 33 | } |
34 | 34 | $current_item = $jsonld[0]; |
35 | 35 | |
36 | - if ( ! is_array( $current_item ) || ! array_key_exists( '@type', $current_item ) ) { |
|
36 | + if ( ! is_array($current_item) || ! array_key_exists('@type', $current_item)) { |
|
37 | 37 | // Cant determine type return early. |
38 | 38 | return $jsonld; |
39 | 39 | } |
40 | 40 | |
41 | 41 | $type = $current_item['@type']; |
42 | - if ( is_string( $type ) ) { |
|
43 | - $type = array( $type ); |
|
42 | + if (is_string($type)) { |
|
43 | + $type = array($type); |
|
44 | 44 | } |
45 | 45 | // If its a article or descendant of article, then dont add the |
46 | 46 | // videoobject in this hook, they will be already added to video property. |
47 | - if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) { |
|
47 | + if (array_intersect(Jsonld_Article_Wrapper::$article_types, $type)) { |
|
48 | 48 | return $jsonld; |
49 | 49 | } |
50 | 50 | |
51 | - $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
|
52 | - if ( 0 === count( $videos_jsonld ) ) { |
|
51 | + $videos_jsonld = $this->get_videos_jsonld($post_id); |
|
52 | + if (0 === count($videos_jsonld)) { |
|
53 | 53 | return $jsonld; |
54 | 54 | } |
55 | 55 | |
56 | 56 | // check if we have @id in jsonld for first item. |
57 | - $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
|
57 | + $id = array_key_exists('@id', $current_item) ? $current_item['@id'] : ''; |
|
58 | 58 | |
59 | - foreach ( $videos_jsonld as &$video_jsonld ) { |
|
60 | - if ( ! $id ) { |
|
59 | + foreach ($videos_jsonld as &$video_jsonld) { |
|
60 | + if ( ! $id) { |
|
61 | 61 | continue; |
62 | 62 | } |
63 | - if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
|
64 | - $video_jsonld['mentions'] = array( '@id' => $id ); |
|
63 | + if ( ! array_key_exists('mentions', $video_jsonld)) { |
|
64 | + $video_jsonld['mentions'] = array('@id' => $id); |
|
65 | 65 | } else { |
66 | - $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
|
66 | + $video_jsonld['mentions'] = array_merge($video_jsonld['mentions'], array('@id' => $id)); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - return array_merge( $jsonld, $videos_jsonld ); |
|
70 | + return array_merge($jsonld, $videos_jsonld); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -76,32 +76,32 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - private function merge_video_data( $existing_video_data, $new_video_data ) { |
|
80 | - if ( ! is_array( $existing_video_data ) ) { |
|
79 | + private function merge_video_data($existing_video_data, $new_video_data) { |
|
80 | + if ( ! is_array($existing_video_data)) { |
|
81 | 81 | $new_video_data[] = $existing_video_data; |
82 | 82 | |
83 | 83 | return $new_video_data; |
84 | 84 | } |
85 | 85 | |
86 | - if ( $this->is_associative_array( $existing_video_data ) ) { |
|
86 | + if ($this->is_associative_array($existing_video_data)) { |
|
87 | 87 | $new_video_data[] = $existing_video_data; |
88 | 88 | |
89 | 89 | return $new_video_data; |
90 | 90 | } |
91 | 91 | |
92 | - return array_merge( $existing_video_data, $new_video_data ); |
|
92 | + return array_merge($existing_video_data, $new_video_data); |
|
93 | 93 | } |
94 | 94 | |
95 | - public function wl_post_jsonld( $jsonld, $post_id ) { |
|
95 | + public function wl_post_jsonld($jsonld, $post_id) { |
|
96 | 96 | |
97 | - $video_jsonld = $this->get_videos_jsonld( $post_id ); |
|
98 | - if ( count( $video_jsonld ) === 0 ) { |
|
97 | + $video_jsonld = $this->get_videos_jsonld($post_id); |
|
98 | + if (count($video_jsonld) === 0) { |
|
99 | 99 | return $jsonld; |
100 | 100 | } |
101 | 101 | // Before adding the video jsonld check if the key |
102 | 102 | // is present and additional data might be present, |
103 | 103 | // if not present just add the data and return early. |
104 | - if ( ! array_key_exists( 'video', $jsonld ) ) { |
|
104 | + if ( ! array_key_exists('video', $jsonld)) { |
|
105 | 105 | $jsonld['video'] = $video_jsonld; |
106 | 106 | |
107 | 107 | return $jsonld; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | // since key exists, we need to merge the data based on type. |
111 | 111 | $previous_video_data = $jsonld['video']; |
112 | - $jsonld['video'] = $this->merge_video_data( $previous_video_data, $video_jsonld ); |
|
112 | + $jsonld['video'] = $this->merge_video_data($previous_video_data, $video_jsonld); |
|
113 | 113 | |
114 | 114 | return $jsonld; |
115 | 115 | } |
@@ -119,18 +119,18 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_videos_jsonld( $post_id ) { |
|
122 | + public function get_videos_jsonld($post_id) { |
|
123 | 123 | |
124 | - $videos = $this->video_storage->get_all_videos( $post_id ); |
|
124 | + $videos = $this->video_storage->get_all_videos($post_id); |
|
125 | 125 | |
126 | 126 | $jsonld = array(); |
127 | 127 | |
128 | - foreach ( $videos as $video ) { |
|
128 | + foreach ($videos as $video) { |
|
129 | 129 | /** |
130 | 130 | * @var $video Video |
131 | 131 | */ |
132 | 132 | $description = $video->description; |
133 | - if ( ! $video->description ) { |
|
133 | + if ( ! $video->description) { |
|
134 | 134 | // If description is empty then use the video title as description |
135 | 135 | $description = $video->name; |
136 | 136 | } |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | 'duration' => $video->duration, |
146 | 146 | ); |
147 | 147 | |
148 | - if ( $video->embed_url ) { |
|
148 | + if ($video->embed_url) { |
|
149 | 149 | $single_jsonld['embedUrl'] = $video->embed_url; |
150 | 150 | } |
151 | 151 | |
152 | - if ( $video->views ) { |
|
152 | + if ($video->views) { |
|
153 | 153 | $single_jsonld['interactionStatistic'] = array( |
154 | 154 | '@type' => 'InteractionCounter', |
155 | 155 | 'interactionType' => array( |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | ); |
160 | 160 | } |
161 | 161 | |
162 | - if ( $video->is_live_video ) { |
|
162 | + if ($video->is_live_video) { |
|
163 | 163 | $single_jsonld['publication'] = array( |
164 | 164 | '@type' => 'BroadcastEvent', |
165 | 165 | 'isLiveBroadcast' => true, |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | return $jsonld; |
175 | 175 | } |
176 | 176 | |
177 | - private function is_associative_array( $arr ) { |
|
178 | - if ( array() === $arr ) { |
|
177 | + private function is_associative_array($arr) { |
|
178 | + if (array() === $arr) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | - return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
182 | + return array_keys($arr) !== range(0, count($arr) - 1); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | } |