@@ -9,8 +9,8 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Video_Storage_Factory { |
| 11 | 11 | |
| 12 | - public static function get_storage() { |
|
| 13 | - return new Meta_Storage(); |
|
| 14 | - } |
|
| 12 | + public static function get_storage() { |
|
| 13 | + return new Meta_Storage(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -9,44 +9,44 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Meta_Storage implements Storage { |
| 11 | 11 | |
| 12 | - const META_KEY = '_wl_video_object_videos'; |
|
| 12 | + const META_KEY = '_wl_video_object_videos'; |
|
| 13 | 13 | |
| 14 | - public function add_video( $post_id, $video ) { |
|
| 14 | + public function add_video( $post_id, $video ) { |
|
| 15 | 15 | |
| 16 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 17 | - } |
|
| 16 | + add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function get_all_videos( $post_id ) { |
|
| 20 | + public function get_all_videos( $post_id ) { |
|
| 21 | 21 | |
| 22 | - return get_post_meta( $post_id, self::META_KEY ); |
|
| 22 | + return get_post_meta( $post_id, self::META_KEY ); |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 26 | + public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 27 | 27 | |
| 28 | - $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 29 | - return $video->id; |
|
| 30 | - }, $videos_to_be_removed ); |
|
| 28 | + $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 29 | + return $video->id; |
|
| 30 | + }, $videos_to_be_removed ); |
|
| 31 | 31 | |
| 32 | - $present_videos = $this->get_all_videos( $post_id ); |
|
| 32 | + $present_videos = $this->get_all_videos( $post_id ); |
|
| 33 | 33 | |
| 34 | - $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 35 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 36 | - } ); |
|
| 34 | + $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 35 | + return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 36 | + } ); |
|
| 37 | 37 | |
| 38 | - // Remove all existing videos. |
|
| 39 | - $this->remove_all_videos( $post_id ); |
|
| 38 | + // Remove all existing videos. |
|
| 39 | + $this->remove_all_videos( $post_id ); |
|
| 40 | 40 | |
| 41 | - // Save the videos. |
|
| 42 | - foreach ( $filtered_videos as $video ) { |
|
| 43 | - $this->add_video( $post_id, $video ); |
|
| 44 | - } |
|
| 41 | + // Save the videos. |
|
| 42 | + foreach ( $filtered_videos as $video ) { |
|
| 43 | + $this->add_video( $post_id, $video ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function remove_all_videos( $post_id ) { |
|
| 50 | - delete_post_meta( $post_id, self::META_KEY ); |
|
| 51 | - } |
|
| 49 | + public function remove_all_videos( $post_id ) { |
|
| 50 | + delete_post_meta( $post_id, self::META_KEY ); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -11,42 +11,42 @@ |
||
| 11 | 11 | |
| 12 | 12 | const META_KEY = '_wl_video_object_videos'; |
| 13 | 13 | |
| 14 | - public function add_video( $post_id, $video ) { |
|
| 14 | + public function add_video($post_id, $video) { |
|
| 15 | 15 | |
| 16 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 16 | + add_post_meta($post_id, self::META_KEY, $video); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function get_all_videos( $post_id ) { |
|
| 20 | + public function get_all_videos($post_id) { |
|
| 21 | 21 | |
| 22 | - return get_post_meta( $post_id, self::META_KEY ); |
|
| 22 | + return get_post_meta($post_id, self::META_KEY); |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 26 | + public function remove_videos($videos_to_be_removed, $post_id) { |
|
| 27 | 27 | |
| 28 | - $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 28 | + $videos_to_be_removed_ids = array_map(function($video) { |
|
| 29 | 29 | return $video->id; |
| 30 | - }, $videos_to_be_removed ); |
|
| 30 | + }, $videos_to_be_removed); |
|
| 31 | 31 | |
| 32 | - $present_videos = $this->get_all_videos( $post_id ); |
|
| 32 | + $present_videos = $this->get_all_videos($post_id); |
|
| 33 | 33 | |
| 34 | - $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 35 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 34 | + $filtered_videos = array_filter($present_videos, function($video) use ($videos_to_be_removed_ids) { |
|
| 35 | + return ! in_array($video->id, $videos_to_be_removed_ids); |
|
| 36 | 36 | } ); |
| 37 | 37 | |
| 38 | 38 | // Remove all existing videos. |
| 39 | - $this->remove_all_videos( $post_id ); |
|
| 39 | + $this->remove_all_videos($post_id); |
|
| 40 | 40 | |
| 41 | 41 | // Save the videos. |
| 42 | - foreach ( $filtered_videos as $video ) { |
|
| 43 | - $this->add_video( $post_id, $video ); |
|
| 42 | + foreach ($filtered_videos as $video) { |
|
| 43 | + $this->add_video($post_id, $video); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function remove_all_videos( $post_id ) { |
|
| 50 | - delete_post_meta( $post_id, self::META_KEY ); |
|
| 49 | + public function remove_all_videos($post_id) { |
|
| 50 | + delete_post_meta($post_id, self::META_KEY); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -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 |