@@ -10,41 +10,41 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | interface Storage { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param $post_id int Post id to add video. |
|
| 15 | - * @param $video Video The video object which needs to be saved. |
|
| 16 | - * |
|
| 17 | - * @return bool true if video is added, false otherwise. |
|
| 18 | - */ |
|
| 19 | - public function add_video( $post_id, $video ); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Return all video objects for the post |
|
| 23 | - * |
|
| 24 | - * @param $post_id int Post id to get all videos. |
|
| 25 | - * |
|
| 26 | - * @return array<Video> |
|
| 27 | - */ |
|
| 28 | - public function get_all_videos( $post_id ); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Remove the Video Object. |
|
| 32 | - * |
|
| 33 | - * @param $videos_to_be_removed array<Video> |
|
| 34 | - * |
|
| 35 | - * @param $post_id int |
|
| 36 | - * |
|
| 37 | - * @return bool return true if removed or false |
|
| 38 | - */ |
|
| 39 | - public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Remove all videos present for post id |
|
| 43 | - * |
|
| 44 | - * @param $post_id |
|
| 45 | - * |
|
| 46 | - * @return true if removed else false. |
|
| 47 | - */ |
|
| 48 | - public function remove_all_videos( $post_id ); |
|
| 13 | + /** |
|
| 14 | + * @param $post_id int Post id to add video. |
|
| 15 | + * @param $video Video The video object which needs to be saved. |
|
| 16 | + * |
|
| 17 | + * @return bool true if video is added, false otherwise. |
|
| 18 | + */ |
|
| 19 | + public function add_video( $post_id, $video ); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Return all video objects for the post |
|
| 23 | + * |
|
| 24 | + * @param $post_id int Post id to get all videos. |
|
| 25 | + * |
|
| 26 | + * @return array<Video> |
|
| 27 | + */ |
|
| 28 | + public function get_all_videos( $post_id ); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Remove the Video Object. |
|
| 32 | + * |
|
| 33 | + * @param $videos_to_be_removed array<Video> |
|
| 34 | + * |
|
| 35 | + * @param $post_id int |
|
| 36 | + * |
|
| 37 | + * @return bool return true if removed or false |
|
| 38 | + */ |
|
| 39 | + public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Remove all videos present for post id |
|
| 43 | + * |
|
| 44 | + * @param $post_id |
|
| 45 | + * |
|
| 46 | + * @return true if removed else false. |
|
| 47 | + */ |
|
| 48 | + public function remove_all_videos( $post_id ); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return bool true if video is added, false otherwise. |
| 18 | 18 | */ |
| 19 | - public function add_video( $post_id, $video ); |
|
| 19 | + public function add_video($post_id, $video); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Return all video objects for the post |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @return array<Video> |
| 27 | 27 | */ |
| 28 | - public function get_all_videos( $post_id ); |
|
| 28 | + public function get_all_videos($post_id); |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Remove the Video Object. |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return bool return true if removed or false |
| 38 | 38 | */ |
| 39 | - public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 39 | + public function remove_videos($videos_to_be_removed, $post_id); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Remove all videos present for post id |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return true if removed else false. |
| 47 | 47 | */ |
| 48 | - public function remove_all_videos( $post_id ); |
|
| 48 | + public function remove_all_videos($post_id); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | interface Embedded_Video { |
| 13 | 13 | |
| 14 | - public function get_api_provider(); |
|
| 14 | + public function get_api_provider(); |
|
| 15 | 15 | |
| 16 | - public function get_url(); |
|
| 16 | + public function get_url(); |
|
| 17 | 17 | |
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Embedded_Video_Factory { |
| 9 | 9 | |
| 10 | - public static function get_embedded_video( $video_url ) { |
|
| 11 | - return new Default_Embedded_Video( $video_url ); |
|
| 12 | - } |
|
| 10 | + public static function get_embedded_video( $video_url ) { |
|
| 11 | + return new Default_Embedded_Video( $video_url ); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Embedded_Video_Factory { |
| 9 | 9 | |
| 10 | - public static function get_embedded_video( $video_url ) { |
|
| 11 | - return new Default_Embedded_Video( $video_url ); |
|
| 10 | + public static function get_embedded_video($video_url) { |
|
| 11 | + return new Default_Embedded_Video($video_url); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -7,20 +7,20 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Default_Embedded_Video implements Embedded_Video { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var string The url of the video which got embedded. |
|
| 12 | - */ |
|
| 13 | - private $video_url; |
|
| 10 | + /** |
|
| 11 | + * @var string The url of the video which got embedded. |
|
| 12 | + */ |
|
| 13 | + private $video_url; |
|
| 14 | 14 | |
| 15 | - public function __construct( $video_url ) { |
|
| 16 | - $this->video_url = $video_url; |
|
| 17 | - } |
|
| 15 | + public function __construct( $video_url ) { |
|
| 16 | + $this->video_url = $video_url; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function get_api_provider() { |
|
| 20 | - // TODO: Implement get_api_provider() method. |
|
| 21 | - } |
|
| 19 | + public function get_api_provider() { |
|
| 20 | + // TODO: Implement get_api_provider() method. |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function get_url() { |
|
| 24 | - return $this->video_url; |
|
| 25 | - } |
|
| 23 | + public function get_url() { |
|
| 24 | + return $this->video_url; |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | private $video_url; |
| 14 | 14 | |
| 15 | - public function __construct( $video_url ) { |
|
| 15 | + public function __construct($video_url) { |
|
| 16 | 16 | $this->video_url = $video_url; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -7,91 +7,91 @@ |
||
| 7 | 7 | namespace Wordlift\Videoobject\Data\Video; |
| 8 | 8 | |
| 9 | 9 | class Video { |
| 10 | - /** |
|
| 11 | - * @var string The title of the video. |
|
| 12 | - */ |
|
| 13 | - public $name; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * @var string The video description. |
|
| 17 | - */ |
|
| 18 | - public $description; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var array Thumbnail urls. |
|
| 22 | - */ |
|
| 23 | - public $thumbnail_urls; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string Published date. |
|
| 27 | - */ |
|
| 28 | - public $upload_date; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string Video url. |
|
| 32 | - */ |
|
| 33 | - public $content_url; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string Video duration in IS08601 format. |
|
| 37 | - */ |
|
| 38 | - public $duration; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - public $embed_url; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string An unique identifier, usually the video url. |
|
| 47 | - */ |
|
| 48 | - public $id; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var int The number of views for the video. |
|
| 52 | - */ |
|
| 53 | - public $views; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * All the live video properties. |
|
| 58 | - */ |
|
| 59 | - /** |
|
| 60 | - * @var bool |
|
| 61 | - */ |
|
| 62 | - public $is_live_video; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string Live video start date |
|
| 66 | - */ |
|
| 67 | - public $live_video_start_date; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var string Live video end date |
|
| 71 | - */ |
|
| 72 | - public $live_video_end_date; |
|
| 73 | - |
|
| 74 | - public function from( $data ) { |
|
| 75 | - $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 76 | - // Loop through the keys and set the value from array |
|
| 77 | - foreach ( $keys as $key ) { |
|
| 78 | - $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function get_data() { |
|
| 83 | - |
|
| 84 | - return array( |
|
| 85 | - '@type' => 'VideoObject', |
|
| 86 | - 'name' => $this->name, |
|
| 87 | - 'description' => $this->description, |
|
| 88 | - 'contentUrl' => $this->content_url, |
|
| 89 | - 'embedUrl' => $this->embed_url, |
|
| 90 | - 'uploadDate' => $this->upload_date, |
|
| 91 | - 'thumbnailUrl' => $this->thumbnail_urls, |
|
| 92 | - 'duration' => $this->duration |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - } |
|
| 10 | + /** |
|
| 11 | + * @var string The title of the video. |
|
| 12 | + */ |
|
| 13 | + public $name; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * @var string The video description. |
|
| 17 | + */ |
|
| 18 | + public $description; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var array Thumbnail urls. |
|
| 22 | + */ |
|
| 23 | + public $thumbnail_urls; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string Published date. |
|
| 27 | + */ |
|
| 28 | + public $upload_date; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string Video url. |
|
| 32 | + */ |
|
| 33 | + public $content_url; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string Video duration in IS08601 format. |
|
| 37 | + */ |
|
| 38 | + public $duration; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + public $embed_url; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string An unique identifier, usually the video url. |
|
| 47 | + */ |
|
| 48 | + public $id; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var int The number of views for the video. |
|
| 52 | + */ |
|
| 53 | + public $views; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * All the live video properties. |
|
| 58 | + */ |
|
| 59 | + /** |
|
| 60 | + * @var bool |
|
| 61 | + */ |
|
| 62 | + public $is_live_video; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string Live video start date |
|
| 66 | + */ |
|
| 67 | + public $live_video_start_date; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @var string Live video end date |
|
| 71 | + */ |
|
| 72 | + public $live_video_end_date; |
|
| 73 | + |
|
| 74 | + public function from( $data ) { |
|
| 75 | + $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 76 | + // Loop through the keys and set the value from array |
|
| 77 | + foreach ( $keys as $key ) { |
|
| 78 | + $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function get_data() { |
|
| 83 | + |
|
| 84 | + return array( |
|
| 85 | + '@type' => 'VideoObject', |
|
| 86 | + 'name' => $this->name, |
|
| 87 | + 'description' => $this->description, |
|
| 88 | + 'contentUrl' => $this->content_url, |
|
| 89 | + 'embedUrl' => $this->embed_url, |
|
| 90 | + 'uploadDate' => $this->upload_date, |
|
| 91 | + 'thumbnailUrl' => $this->thumbnail_urls, |
|
| 92 | + 'duration' => $this->duration |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | \ No newline at end of file |
@@ -71,11 +71,11 @@ |
||
| 71 | 71 | */ |
| 72 | 72 | public $live_video_end_date; |
| 73 | 73 | |
| 74 | - public function from( $data ) { |
|
| 75 | - $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 74 | + public function from($data) { |
|
| 75 | + $keys = array_keys(get_class_vars(get_class($this))); |
|
| 76 | 76 | // Loop through the keys and set the value from array |
| 77 | - foreach ( $keys as $key ) { |
|
| 78 | - $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 77 | + foreach ($keys as $key) { |
|
| 78 | + $this->$key = array_key_exists($key, $data) ? $data[$key] : null; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -11,72 +11,72 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Vimeo_Client extends Singleton implements Client { |
| 13 | 13 | |
| 14 | - static $requests_sent = 0; |
|
| 14 | + 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 | - /** |
|
| 19 | - * @param $url string Vimeo url |
|
| 20 | - */ |
|
| 21 | - public function vimeo_url_to_id( $url ) { |
|
| 22 | - if ( ! $url ) { |
|
| 23 | - return false; |
|
| 24 | - } |
|
| 25 | - preg_match( self::VIMEO_URL_REGEX, $url, $matches ); |
|
| 18 | + /** |
|
| 19 | + * @param $url string Vimeo url |
|
| 20 | + */ |
|
| 21 | + public function vimeo_url_to_id( $url ) { |
|
| 22 | + if ( ! $url ) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 25 | + preg_match( self::VIMEO_URL_REGEX, $url, $matches ); |
|
| 26 | 26 | |
| 27 | - if ( ! array_key_exists( 3, $matches ) ) { |
|
| 28 | - return false; |
|
| 29 | - } |
|
| 27 | + if ( ! array_key_exists( 3, $matches ) ) { |
|
| 28 | + return false; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return '/videos/' . $matches[3]; |
|
| 32 | - } |
|
| 31 | + return '/videos/' . $matches[3]; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param $vimeo_urls |
|
| 36 | - * @param $post_id |
|
| 37 | - * |
|
| 38 | - * @return string[] |
|
| 39 | - */ |
|
| 40 | - public function get_video_ids_for_api( $vimeo_urls ) { |
|
| 34 | + /** |
|
| 35 | + * @param $vimeo_urls |
|
| 36 | + * @param $post_id |
|
| 37 | + * |
|
| 38 | + * @return string[] |
|
| 39 | + */ |
|
| 40 | + public function get_video_ids_for_api( $vimeo_urls ) { |
|
| 41 | 41 | |
| 42 | - return array_filter( array_map( array( $this, 'vimeo_url_to_id' ), $vimeo_urls ) ); |
|
| 43 | - } |
|
| 42 | + return array_filter( array_map( array( $this, 'vimeo_url_to_id' ), $vimeo_urls ) ); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - public function get_data( $video_urls ) { |
|
| 47 | - $ids = join( ",", $this->get_video_ids_for_api( $video_urls ) ); |
|
| 46 | + public function get_data( $video_urls ) { |
|
| 47 | + $ids = join( ",", $this->get_video_ids_for_api( $video_urls ) ); |
|
| 48 | 48 | |
| 49 | - if ( ! $ids ) { |
|
| 50 | - return array(); |
|
| 51 | - } |
|
| 49 | + if ( ! $ids ) { |
|
| 50 | + return array(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $api_url = $this->get_api_url() . "/videos/"; |
|
| 54 | - $api_url = add_query_arg( array( |
|
| 55 | - 'uris' => $ids, |
|
| 56 | - 'fields' => 'name,description,link,uri,duration,release_time,pictures,stats' |
|
| 57 | - ), $api_url ); |
|
| 53 | + $api_url = $this->get_api_url() . "/videos/"; |
|
| 54 | + $api_url = add_query_arg( array( |
|
| 55 | + 'uris' => $ids, |
|
| 56 | + 'fields' => 'name,description,link,uri,duration,release_time,pictures,stats' |
|
| 57 | + ), $api_url ); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - $response = wp_remote_get( $api_url, array( |
|
| 61 | - 'headers' => array( |
|
| 62 | - 'Authorization' => 'bearer ' . $this->get_api_key() |
|
| 63 | - ) |
|
| 64 | - ) ); |
|
| 60 | + $response = wp_remote_get( $api_url, array( |
|
| 61 | + 'headers' => array( |
|
| 62 | + 'Authorization' => 'bearer ' . $this->get_api_key() |
|
| 63 | + ) |
|
| 64 | + ) ); |
|
| 65 | 65 | |
| 66 | - self::$requests_sent += 1; |
|
| 66 | + self::$requests_sent += 1; |
|
| 67 | 67 | |
| 68 | - return wp_remote_retrieve_body( $response ); |
|
| 69 | - } |
|
| 68 | + return wp_remote_retrieve_body( $response ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public static function get_api_key() { |
|
| 72 | - return get_option( self::get_api_key_option_name(), false ); |
|
| 73 | - } |
|
| 71 | + public static function get_api_key() { |
|
| 72 | + return get_option( self::get_api_key_option_name(), false ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public static function get_api_key_option_name() { |
|
| 76 | - return '_wl_videoobject_vimeo_api_key'; |
|
| 77 | - } |
|
| 75 | + public static function get_api_key_option_name() { |
|
| 76 | + return '_wl_videoobject_vimeo_api_key'; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function get_api_url() { |
|
| 80 | - return 'https://api.vimeo.com'; |
|
| 81 | - } |
|
| 79 | + public function get_api_url() { |
|
| 80 | + return 'https://api.vimeo.com'; |
|
| 81 | + } |
|
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @param $url string Vimeo url |
| 20 | 20 | */ |
| 21 | - public function vimeo_url_to_id( $url ) { |
|
| 22 | - if ( ! $url ) { |
|
| 21 | + public function vimeo_url_to_id($url) { |
|
| 22 | + if ( ! $url) { |
|
| 23 | 23 | return false; |
| 24 | 24 | } |
| 25 | - preg_match( self::VIMEO_URL_REGEX, $url, $matches ); |
|
| 25 | + preg_match(self::VIMEO_URL_REGEX, $url, $matches); |
|
| 26 | 26 | |
| 27 | - if ( ! array_key_exists( 3, $matches ) ) { |
|
| 27 | + if ( ! array_key_exists(3, $matches)) { |
|
| 28 | 28 | return false; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - return '/videos/' . $matches[3]; |
|
| 31 | + return '/videos/'.$matches[3]; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -37,39 +37,39 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return string[] |
| 39 | 39 | */ |
| 40 | - public function get_video_ids_for_api( $vimeo_urls ) { |
|
| 40 | + public function get_video_ids_for_api($vimeo_urls) { |
|
| 41 | 41 | |
| 42 | - return array_filter( array_map( array( $this, 'vimeo_url_to_id' ), $vimeo_urls ) ); |
|
| 42 | + return array_filter(array_map(array($this, 'vimeo_url_to_id'), $vimeo_urls)); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - public function get_data( $video_urls ) { |
|
| 47 | - $ids = join( ",", $this->get_video_ids_for_api( $video_urls ) ); |
|
| 46 | + public function get_data($video_urls) { |
|
| 47 | + $ids = join(",", $this->get_video_ids_for_api($video_urls)); |
|
| 48 | 48 | |
| 49 | - if ( ! $ids ) { |
|
| 49 | + if ( ! $ids) { |
|
| 50 | 50 | return array(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $api_url = $this->get_api_url() . "/videos/"; |
|
| 54 | - $api_url = add_query_arg( array( |
|
| 53 | + $api_url = $this->get_api_url()."/videos/"; |
|
| 54 | + $api_url = add_query_arg(array( |
|
| 55 | 55 | 'uris' => $ids, |
| 56 | 56 | 'fields' => 'name,description,link,uri,duration,release_time,pictures,stats' |
| 57 | - ), $api_url ); |
|
| 57 | + ), $api_url); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - $response = wp_remote_get( $api_url, array( |
|
| 60 | + $response = wp_remote_get($api_url, array( |
|
| 61 | 61 | 'headers' => array( |
| 62 | - 'Authorization' => 'bearer ' . $this->get_api_key() |
|
| 62 | + 'Authorization' => 'bearer '.$this->get_api_key() |
|
| 63 | 63 | ) |
| 64 | - ) ); |
|
| 64 | + )); |
|
| 65 | 65 | |
| 66 | 66 | self::$requests_sent += 1; |
| 67 | 67 | |
| 68 | - return wp_remote_retrieve_body( $response ); |
|
| 68 | + return wp_remote_retrieve_body($response); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public static function get_api_key() { |
| 72 | - return get_option( self::get_api_key_option_name(), false ); |
|
| 72 | + return get_option(self::get_api_key_option_name(), false); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public static function get_api_key_option_name() { |
@@ -7,28 +7,28 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | interface Client { |
| 9 | 9 | |
| 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 | - * @return string |
|
| 26 | - */ |
|
| 27 | - 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 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public static function get_api_key_option_name(); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The api base url. |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - public function get_api_url(); |
|
| 29 | + /** |
|
| 30 | + * The api base url. |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + public function get_api_url(); |
|
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -14,7 +14,7 @@ |
||
| 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 |
@@ -11,77 +11,77 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Youtube_Client extends Singleton implements Client { |
| 13 | 13 | |
| 14 | - static $requests_sent = 0; |
|
| 14 | + static $requests_sent = 0; |
|
| 15 | 15 | |
| 16 | - public static function get_api_key_option_name() { |
|
| 17 | - return "__wl_video_object_youtube_api_key"; |
|
| 18 | - } |
|
| 16 | + public static function get_api_key_option_name() { |
|
| 17 | + return "__wl_video_object_youtube_api_key"; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public static function get_api_key() { |
|
| 21 | - return get_option( self::get_api_key_option_name(), false ); |
|
| 22 | - } |
|
| 20 | + public static function get_api_key() { |
|
| 21 | + return get_option( self::get_api_key_option_name(), false ); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function get_api_url() { |
|
| 25 | - return 'https://www.googleapis.com/youtube/v3/videos'; |
|
| 26 | - } |
|
| 24 | + public function get_api_url() { |
|
| 25 | + return 'https://www.googleapis.com/youtube/v3/videos'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - public function get_data( $video_urls ) { |
|
| 30 | - $video_ids = $this->get_video_ids_as_string( $video_urls ); |
|
| 31 | - $url = add_query_arg( array( |
|
| 32 | - 'part' => 'snippet,contentDetails,statistics,liveStreamingDetails', |
|
| 33 | - 'id' => $video_ids, |
|
| 34 | - 'key' => $this->get_api_key() |
|
| 35 | - ), $this->get_api_url() ); |
|
| 29 | + public function get_data( $video_urls ) { |
|
| 30 | + $video_ids = $this->get_video_ids_as_string( $video_urls ); |
|
| 31 | + $url = add_query_arg( array( |
|
| 32 | + 'part' => 'snippet,contentDetails,statistics,liveStreamingDetails', |
|
| 33 | + 'id' => $video_ids, |
|
| 34 | + 'key' => $this->get_api_key() |
|
| 35 | + ), $this->get_api_url() ); |
|
| 36 | 36 | |
| 37 | - $response = wp_remote_get( $url ); |
|
| 37 | + $response = wp_remote_get( $url ); |
|
| 38 | 38 | |
| 39 | - self::$requests_sent += 1; |
|
| 39 | + self::$requests_sent += 1; |
|
| 40 | 40 | |
| 41 | - return wp_remote_retrieve_body( $response ); |
|
| 42 | - } |
|
| 41 | + return wp_remote_retrieve_body( $response ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - private function get_video_ids_as_string( $video_urls ) { |
|
| 46 | - // validate the urls. |
|
| 47 | - $video_urls = array_filter( $video_urls, function ( $url ) { |
|
| 48 | - return filter_var( $url, FILTER_VALIDATE_URL ); |
|
| 49 | - } ); |
|
| 45 | + private function get_video_ids_as_string( $video_urls ) { |
|
| 46 | + // validate the urls. |
|
| 47 | + $video_urls = array_filter( $video_urls, function ( $url ) { |
|
| 48 | + return filter_var( $url, FILTER_VALIDATE_URL ); |
|
| 49 | + } ); |
|
| 50 | 50 | |
| 51 | - // extract the video ids. |
|
| 52 | - return join( ",", self::get_video_ids( $video_urls ) ); |
|
| 53 | - } |
|
| 51 | + // extract the video ids. |
|
| 52 | + return join( ",", self::get_video_ids( $video_urls ) ); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - private static function get_video_ids( $video_urls ) { |
|
| 56 | + private static function get_video_ids( $video_urls ) { |
|
| 57 | 57 | |
| 58 | - $video_ids = array_map( function ( $url ) { |
|
| 58 | + $video_ids = array_map( function ( $url ) { |
|
| 59 | 59 | |
| 60 | - $parsed_url_data = parse_url( $url ); |
|
| 60 | + $parsed_url_data = parse_url( $url ); |
|
| 61 | 61 | |
| 62 | - if ( ( ! is_array( $parsed_url_data ) || ! array_key_exists( 'query', $parsed_url_data ) ) |
|
| 63 | - && strpos( $url, "youtu.be" ) === false ) { |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - // For youtu.be urls, the video id is present in path. |
|
| 67 | - if ( strpos( $url, "youtu.be" ) !== false ) { |
|
| 68 | - $parsed_url_data['query'] = "v=" . substr( $parsed_url_data['path'], 1 ); |
|
| 69 | - } |
|
| 62 | + if ( ( ! is_array( $parsed_url_data ) || ! array_key_exists( 'query', $parsed_url_data ) ) |
|
| 63 | + && strpos( $url, "youtu.be" ) === false ) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + // For youtu.be urls, the video id is present in path. |
|
| 67 | + if ( strpos( $url, "youtu.be" ) !== false ) { |
|
| 68 | + $parsed_url_data['query'] = "v=" . substr( $parsed_url_data['path'], 1 ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $query_data_result = array(); |
|
| 72 | - parse_str( $parsed_url_data['query'], $query_data_result ); |
|
| 71 | + $query_data_result = array(); |
|
| 72 | + parse_str( $parsed_url_data['query'], $query_data_result ); |
|
| 73 | 73 | |
| 74 | - if ( ! array_key_exists( 'v', $query_data_result ) ) { |
|
| 75 | - return false; |
|
| 76 | - } |
|
| 74 | + if ( ! array_key_exists( 'v', $query_data_result ) ) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - return $query_data_result['v']; |
|
| 78 | + return $query_data_result['v']; |
|
| 79 | 79 | |
| 80 | - }, $video_urls ); |
|
| 80 | + }, $video_urls ); |
|
| 81 | 81 | |
| 82 | - return array_values( array_filter( $video_ids ) ); |
|
| 82 | + return array_values( array_filter( $video_ids ) ); |
|
| 83 | 83 | |
| 84 | - } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | \ No newline at end of file |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public static function get_api_key() { |
| 21 | - return get_option( self::get_api_key_option_name(), false ); |
|
| 21 | + return get_option(self::get_api_key_option_name(), false); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function get_api_url() { |
@@ -26,60 +26,60 @@ discard block |
||
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - public function get_data( $video_urls ) { |
|
| 30 | - $video_ids = $this->get_video_ids_as_string( $video_urls ); |
|
| 31 | - $url = add_query_arg( array( |
|
| 29 | + public function get_data($video_urls) { |
|
| 30 | + $video_ids = $this->get_video_ids_as_string($video_urls); |
|
| 31 | + $url = add_query_arg(array( |
|
| 32 | 32 | 'part' => 'snippet,contentDetails,statistics,liveStreamingDetails', |
| 33 | 33 | 'id' => $video_ids, |
| 34 | 34 | 'key' => $this->get_api_key() |
| 35 | - ), $this->get_api_url() ); |
|
| 35 | + ), $this->get_api_url()); |
|
| 36 | 36 | |
| 37 | - $response = wp_remote_get( $url ); |
|
| 37 | + $response = wp_remote_get($url); |
|
| 38 | 38 | |
| 39 | 39 | self::$requests_sent += 1; |
| 40 | 40 | |
| 41 | - return wp_remote_retrieve_body( $response ); |
|
| 41 | + return wp_remote_retrieve_body($response); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - private function get_video_ids_as_string( $video_urls ) { |
|
| 45 | + private function get_video_ids_as_string($video_urls) { |
|
| 46 | 46 | // validate the urls. |
| 47 | - $video_urls = array_filter( $video_urls, function ( $url ) { |
|
| 48 | - return filter_var( $url, FILTER_VALIDATE_URL ); |
|
| 47 | + $video_urls = array_filter($video_urls, function($url) { |
|
| 48 | + return filter_var($url, FILTER_VALIDATE_URL); |
|
| 49 | 49 | } ); |
| 50 | 50 | |
| 51 | 51 | // extract the video ids. |
| 52 | - return join( ",", self::get_video_ids( $video_urls ) ); |
|
| 52 | + return join(",", self::get_video_ids($video_urls)); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - private static function get_video_ids( $video_urls ) { |
|
| 56 | + private static function get_video_ids($video_urls) { |
|
| 57 | 57 | |
| 58 | - $video_ids = array_map( function ( $url ) { |
|
| 58 | + $video_ids = array_map(function($url) { |
|
| 59 | 59 | |
| 60 | - $parsed_url_data = parse_url( $url ); |
|
| 60 | + $parsed_url_data = parse_url($url); |
|
| 61 | 61 | |
| 62 | - if ( ( ! is_array( $parsed_url_data ) || ! array_key_exists( 'query', $parsed_url_data ) ) |
|
| 63 | - && strpos( $url, "youtu.be" ) === false ) { |
|
| 62 | + if (( ! is_array($parsed_url_data) || ! array_key_exists('query', $parsed_url_data)) |
|
| 63 | + && strpos($url, "youtu.be") === false) { |
|
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | 66 | // For youtu.be urls, the video id is present in path. |
| 67 | - if ( strpos( $url, "youtu.be" ) !== false ) { |
|
| 68 | - $parsed_url_data['query'] = "v=" . substr( $parsed_url_data['path'], 1 ); |
|
| 67 | + if (strpos($url, "youtu.be") !== false) { |
|
| 68 | + $parsed_url_data['query'] = "v=".substr($parsed_url_data['path'], 1); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $query_data_result = array(); |
| 72 | - parse_str( $parsed_url_data['query'], $query_data_result ); |
|
| 72 | + parse_str($parsed_url_data['query'], $query_data_result); |
|
| 73 | 73 | |
| 74 | - if ( ! array_key_exists( 'v', $query_data_result ) ) { |
|
| 74 | + if ( ! array_key_exists('v', $query_data_result)) { |
|
| 75 | 75 | return false; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return $query_data_result['v']; |
| 79 | 79 | |
| 80 | - }, $video_urls ); |
|
| 80 | + }, $video_urls); |
|
| 81 | 81 | |
| 82 | - return array_values( array_filter( $video_ids ) ); |
|
| 82 | + return array_values(array_filter($video_ids)); |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -8,15 +8,15 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Client_Factory { |
| 10 | 10 | |
| 11 | - const YOUTUBE = 'youtube'; |
|
| 11 | + const YOUTUBE = 'youtube'; |
|
| 12 | 12 | |
| 13 | - const VIMEO = 'vimeo'; |
|
| 13 | + const VIMEO = 'vimeo'; |
|
| 14 | 14 | |
| 15 | - public static function get_client( $config ) { |
|
| 16 | - if ( self::YOUTUBE === $config ) { |
|
| 17 | - return Youtube_Client::get_instance(); |
|
| 18 | - } else if ( self::VIMEO === $config ) { |
|
| 19 | - return Vimeo_Client::get_instance(); |
|
| 20 | - } |
|
| 21 | - } |
|
| 15 | + public static function get_client( $config ) { |
|
| 16 | + if ( self::YOUTUBE === $config ) { |
|
| 17 | + return Youtube_Client::get_instance(); |
|
| 18 | + } else if ( self::VIMEO === $config ) { |
|
| 19 | + return Vimeo_Client::get_instance(); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | |
| 13 | 13 | const VIMEO = 'vimeo'; |
| 14 | 14 | |
| 15 | - public static function get_client( $config ) { |
|
| 16 | - if ( self::YOUTUBE === $config ) { |
|
| 15 | + public static function get_client($config) { |
|
| 16 | + if (self::YOUTUBE === $config) { |
|
| 17 | 17 | return Youtube_Client::get_instance(); |
| 18 | - } else if ( self::VIMEO === $config ) { |
|
| 18 | + } else if (self::VIMEO === $config) { |
|
| 19 | 19 | return Vimeo_Client::get_instance(); |
| 20 | 20 | } |
| 21 | 21 | } |