@@ -12,179 +12,179 @@ |
||
| 12 | 12 | use Wordlift\Videoobject\Data\Video_Storage\Storage; |
| 13 | 13 | |
| 14 | 14 | class Jsonld { |
| 15 | - /** |
|
| 16 | - * @var Storage |
|
| 17 | - */ |
|
| 18 | - private $video_storage; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Jsonld constructor. |
|
| 22 | - * |
|
| 23 | - * @param $video_storage Storage |
|
| 24 | - */ |
|
| 25 | - public function __construct( $video_storage ) { |
|
| 26 | - add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 3 ); |
|
| 27 | - add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 3 ); |
|
| 28 | - $this->video_storage = $video_storage; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - public function wl_after_get_jsonld( $jsonld, $post_id, $context ) { |
|
| 33 | - if ( 0 === count( $jsonld ) ) { |
|
| 34 | - return $jsonld; |
|
| 35 | - } |
|
| 36 | - $current_item = $jsonld[0]; |
|
| 37 | - |
|
| 38 | - if ( ! array_key_exists( '@type', $current_item ) ) { |
|
| 39 | - // Cant determine type return early. |
|
| 40 | - return $jsonld; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $type = $current_item['@type']; |
|
| 44 | - if ( is_string( $type ) ) { |
|
| 45 | - $type = array( $type ); |
|
| 46 | - } |
|
| 47 | - // If its a article or descendant of article, then dont add the |
|
| 48 | - // videoobject in this hook, they will be already added to video property. |
|
| 49 | - if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) { |
|
| 50 | - return $jsonld; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
|
| 54 | - if ( 0 === count( $videos_jsonld ) ) { |
|
| 55 | - return $jsonld; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // check if we have @id in jsonld for first item. |
|
| 59 | - $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
|
| 60 | - |
|
| 61 | - foreach ( $videos_jsonld as &$video_jsonld ) { |
|
| 62 | - if ( ! $id ) { |
|
| 63 | - continue; |
|
| 64 | - } |
|
| 65 | - if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
|
| 66 | - $video_jsonld['mentions'] = array( '@id' => $id ); |
|
| 67 | - } else { |
|
| 68 | - $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return array_merge( $jsonld, $videos_jsonld ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param $existing_video_data string | array associative or sequential array. |
|
| 77 | - * @param $new_video_data array Sequential array. |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - private function merge_video_data( $existing_video_data, $new_video_data ) { |
|
| 82 | - if ( ! is_array( $existing_video_data ) ) { |
|
| 83 | - $new_video_data[] = $existing_video_data; |
|
| 84 | - |
|
| 85 | - return $new_video_data; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - if ( $this->is_associative_array( $existing_video_data ) ) { |
|
| 89 | - $new_video_data[] = $existing_video_data; |
|
| 90 | - |
|
| 91 | - return $new_video_data; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return array_merge( $existing_video_data, $new_video_data ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function wl_post_jsonld( $jsonld, $post_id, $references ) { |
|
| 98 | - |
|
| 99 | - $video_jsonld = $this->get_videos_jsonld( $post_id ); |
|
| 100 | - if ( count( $video_jsonld ) === 0 ) { |
|
| 101 | - return $jsonld; |
|
| 102 | - } |
|
| 103 | - // Before adding the video jsonld check if the key |
|
| 104 | - // is present and additional data might be present, |
|
| 105 | - // if not present just add the data and return early. |
|
| 106 | - if ( ! array_key_exists( 'video', $jsonld ) ) { |
|
| 107 | - $jsonld['video'] = $video_jsonld; |
|
| 108 | - |
|
| 109 | - return $jsonld; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // since key exists, we need to merge the data based on type. |
|
| 113 | - $previous_video_data = $jsonld['video']; |
|
| 114 | - $jsonld['video'] = $this->merge_video_data( $previous_video_data, $video_jsonld ); |
|
| 115 | - |
|
| 116 | - return $jsonld; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param $post_id int Post id. |
|
| 122 | - * |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function get_videos_jsonld( $post_id ) { |
|
| 126 | - |
|
| 127 | - $videos = $this->video_storage->get_all_videos( $post_id ); |
|
| 128 | - |
|
| 129 | - $jsonld = array(); |
|
| 130 | - |
|
| 131 | - foreach ( $videos as $video ) { |
|
| 132 | - /** |
|
| 133 | - * @var $video Video |
|
| 134 | - */ |
|
| 135 | - $description = $video->description; |
|
| 136 | - if ( ! $video->description ) { |
|
| 137 | - // If description is empty then use the video title as description |
|
| 138 | - $description = $video->name; |
|
| 139 | - } |
|
| 140 | - $single_jsonld = array( |
|
| 141 | - '@context' => 'http://schema.org', |
|
| 142 | - '@type' => 'VideoObject', |
|
| 143 | - 'name' => $video->name, |
|
| 144 | - 'description' => $description, |
|
| 145 | - 'contentUrl' => $video->content_url, |
|
| 146 | - 'uploadDate' => $video->upload_date, |
|
| 147 | - 'thumbnailUrl' => $video->thumbnail_urls, |
|
| 148 | - 'duration' => $video->duration, |
|
| 149 | - ); |
|
| 150 | - |
|
| 151 | - if ( $video->embed_url ) { |
|
| 152 | - $single_jsonld['embedUrl'] = $video->embed_url; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ( $video->views ) { |
|
| 156 | - $single_jsonld['interactionStatistic'] = array( |
|
| 157 | - '@type' => 'InteractionCounter', |
|
| 158 | - 'interactionType' => array( |
|
| 159 | - '@type' => 'http://schema.org/WatchAction' |
|
| 160 | - ), |
|
| 161 | - 'userInteractionCount' => $video->views |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - if ( $video->is_live_video ) { |
|
| 166 | - $single_jsonld['publication'] = array( |
|
| 167 | - '@type' => 'BroadcastEvent', |
|
| 168 | - 'isLiveBroadcast' => true, |
|
| 169 | - 'startDate' => $video->live_video_start_date, |
|
| 170 | - 'endDate' => $video->live_video_end_date |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $jsonld[] = $single_jsonld; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $jsonld; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - private function is_associative_array( $arr ) { |
|
| 182 | - if ( array() === $arr ) { |
|
| 183 | - return false; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
| 187 | - } |
|
| 15 | + /** |
|
| 16 | + * @var Storage |
|
| 17 | + */ |
|
| 18 | + private $video_storage; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Jsonld constructor. |
|
| 22 | + * |
|
| 23 | + * @param $video_storage Storage |
|
| 24 | + */ |
|
| 25 | + public function __construct( $video_storage ) { |
|
| 26 | + add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 3 ); |
|
| 27 | + add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 3 ); |
|
| 28 | + $this->video_storage = $video_storage; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + public function wl_after_get_jsonld( $jsonld, $post_id, $context ) { |
|
| 33 | + if ( 0 === count( $jsonld ) ) { |
|
| 34 | + return $jsonld; |
|
| 35 | + } |
|
| 36 | + $current_item = $jsonld[0]; |
|
| 37 | + |
|
| 38 | + if ( ! array_key_exists( '@type', $current_item ) ) { |
|
| 39 | + // Cant determine type return early. |
|
| 40 | + return $jsonld; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $type = $current_item['@type']; |
|
| 44 | + if ( is_string( $type ) ) { |
|
| 45 | + $type = array( $type ); |
|
| 46 | + } |
|
| 47 | + // If its a article or descendant of article, then dont add the |
|
| 48 | + // videoobject in this hook, they will be already added to video property. |
|
| 49 | + if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) { |
|
| 50 | + return $jsonld; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
|
| 54 | + if ( 0 === count( $videos_jsonld ) ) { |
|
| 55 | + return $jsonld; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // check if we have @id in jsonld for first item. |
|
| 59 | + $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
|
| 60 | + |
|
| 61 | + foreach ( $videos_jsonld as &$video_jsonld ) { |
|
| 62 | + if ( ! $id ) { |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | + if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
|
| 66 | + $video_jsonld['mentions'] = array( '@id' => $id ); |
|
| 67 | + } else { |
|
| 68 | + $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return array_merge( $jsonld, $videos_jsonld ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param $existing_video_data string | array associative or sequential array. |
|
| 77 | + * @param $new_video_data array Sequential array. |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + private function merge_video_data( $existing_video_data, $new_video_data ) { |
|
| 82 | + if ( ! is_array( $existing_video_data ) ) { |
|
| 83 | + $new_video_data[] = $existing_video_data; |
|
| 84 | + |
|
| 85 | + return $new_video_data; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + if ( $this->is_associative_array( $existing_video_data ) ) { |
|
| 89 | + $new_video_data[] = $existing_video_data; |
|
| 90 | + |
|
| 91 | + return $new_video_data; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return array_merge( $existing_video_data, $new_video_data ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function wl_post_jsonld( $jsonld, $post_id, $references ) { |
|
| 98 | + |
|
| 99 | + $video_jsonld = $this->get_videos_jsonld( $post_id ); |
|
| 100 | + if ( count( $video_jsonld ) === 0 ) { |
|
| 101 | + return $jsonld; |
|
| 102 | + } |
|
| 103 | + // Before adding the video jsonld check if the key |
|
| 104 | + // is present and additional data might be present, |
|
| 105 | + // if not present just add the data and return early. |
|
| 106 | + if ( ! array_key_exists( 'video', $jsonld ) ) { |
|
| 107 | + $jsonld['video'] = $video_jsonld; |
|
| 108 | + |
|
| 109 | + return $jsonld; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // since key exists, we need to merge the data based on type. |
|
| 113 | + $previous_video_data = $jsonld['video']; |
|
| 114 | + $jsonld['video'] = $this->merge_video_data( $previous_video_data, $video_jsonld ); |
|
| 115 | + |
|
| 116 | + return $jsonld; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param $post_id int Post id. |
|
| 122 | + * |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function get_videos_jsonld( $post_id ) { |
|
| 126 | + |
|
| 127 | + $videos = $this->video_storage->get_all_videos( $post_id ); |
|
| 128 | + |
|
| 129 | + $jsonld = array(); |
|
| 130 | + |
|
| 131 | + foreach ( $videos as $video ) { |
|
| 132 | + /** |
|
| 133 | + * @var $video Video |
|
| 134 | + */ |
|
| 135 | + $description = $video->description; |
|
| 136 | + if ( ! $video->description ) { |
|
| 137 | + // If description is empty then use the video title as description |
|
| 138 | + $description = $video->name; |
|
| 139 | + } |
|
| 140 | + $single_jsonld = array( |
|
| 141 | + '@context' => 'http://schema.org', |
|
| 142 | + '@type' => 'VideoObject', |
|
| 143 | + 'name' => $video->name, |
|
| 144 | + 'description' => $description, |
|
| 145 | + 'contentUrl' => $video->content_url, |
|
| 146 | + 'uploadDate' => $video->upload_date, |
|
| 147 | + 'thumbnailUrl' => $video->thumbnail_urls, |
|
| 148 | + 'duration' => $video->duration, |
|
| 149 | + ); |
|
| 150 | + |
|
| 151 | + if ( $video->embed_url ) { |
|
| 152 | + $single_jsonld['embedUrl'] = $video->embed_url; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ( $video->views ) { |
|
| 156 | + $single_jsonld['interactionStatistic'] = array( |
|
| 157 | + '@type' => 'InteractionCounter', |
|
| 158 | + 'interactionType' => array( |
|
| 159 | + '@type' => 'http://schema.org/WatchAction' |
|
| 160 | + ), |
|
| 161 | + 'userInteractionCount' => $video->views |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + if ( $video->is_live_video ) { |
|
| 166 | + $single_jsonld['publication'] = array( |
|
| 167 | + '@type' => 'BroadcastEvent', |
|
| 168 | + 'isLiveBroadcast' => true, |
|
| 169 | + 'startDate' => $video->live_video_start_date, |
|
| 170 | + 'endDate' => $video->live_video_end_date |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $jsonld[] = $single_jsonld; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $jsonld; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + private function is_associative_array( $arr ) { |
|
| 182 | + if ( array() === $arr ) { |
|
| 183 | + return false; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | } |
@@ -22,54 +22,54 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param $video_storage Storage |
| 24 | 24 | */ |
| 25 | - public function __construct( $video_storage ) { |
|
| 26 | - add_action( 'wl_post_jsonld', array( $this, 'wl_post_jsonld' ), 10, 3 ); |
|
| 27 | - add_action( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 3 ); |
|
| 25 | + public function __construct($video_storage) { |
|
| 26 | + add_action('wl_post_jsonld', array($this, 'wl_post_jsonld'), 10, 3); |
|
| 27 | + add_action('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 3); |
|
| 28 | 28 | $this->video_storage = $video_storage; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - public function wl_after_get_jsonld( $jsonld, $post_id, $context ) { |
|
| 33 | - if ( 0 === count( $jsonld ) ) { |
|
| 32 | + public function wl_after_get_jsonld($jsonld, $post_id, $context) { |
|
| 33 | + if (0 === count($jsonld)) { |
|
| 34 | 34 | return $jsonld; |
| 35 | 35 | } |
| 36 | 36 | $current_item = $jsonld[0]; |
| 37 | 37 | |
| 38 | - if ( ! array_key_exists( '@type', $current_item ) ) { |
|
| 38 | + if ( ! array_key_exists('@type', $current_item)) { |
|
| 39 | 39 | // Cant determine type return early. |
| 40 | 40 | return $jsonld; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $type = $current_item['@type']; |
| 44 | - if ( is_string( $type ) ) { |
|
| 45 | - $type = array( $type ); |
|
| 44 | + if (is_string($type)) { |
|
| 45 | + $type = array($type); |
|
| 46 | 46 | } |
| 47 | 47 | // If its a article or descendant of article, then dont add the |
| 48 | 48 | // videoobject in this hook, they will be already added to video property. |
| 49 | - if ( array_intersect( Jsonld_Article_Wrapper::$article_types, $type ) ) { |
|
| 49 | + if (array_intersect(Jsonld_Article_Wrapper::$article_types, $type)) { |
|
| 50 | 50 | return $jsonld; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
|
| 54 | - if ( 0 === count( $videos_jsonld ) ) { |
|
| 53 | + $videos_jsonld = $this->get_videos_jsonld($post_id); |
|
| 54 | + if (0 === count($videos_jsonld)) { |
|
| 55 | 55 | return $jsonld; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // check if we have @id in jsonld for first item. |
| 59 | - $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
|
| 59 | + $id = array_key_exists('@id', $current_item) ? $current_item['@id'] : ''; |
|
| 60 | 60 | |
| 61 | - foreach ( $videos_jsonld as &$video_jsonld ) { |
|
| 62 | - if ( ! $id ) { |
|
| 61 | + foreach ($videos_jsonld as &$video_jsonld) { |
|
| 62 | + if ( ! $id) { |
|
| 63 | 63 | continue; |
| 64 | 64 | } |
| 65 | - if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
|
| 66 | - $video_jsonld['mentions'] = array( '@id' => $id ); |
|
| 65 | + if ( ! array_key_exists('mentions', $video_jsonld)) { |
|
| 66 | + $video_jsonld['mentions'] = array('@id' => $id); |
|
| 67 | 67 | } else { |
| 68 | - $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
|
| 68 | + $video_jsonld['mentions'] = array_merge($video_jsonld['mentions'], array('@id' => $id)); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - return array_merge( $jsonld, $videos_jsonld ); |
|
| 72 | + return array_merge($jsonld, $videos_jsonld); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,32 +78,32 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | - private function merge_video_data( $existing_video_data, $new_video_data ) { |
|
| 82 | - if ( ! is_array( $existing_video_data ) ) { |
|
| 81 | + private function merge_video_data($existing_video_data, $new_video_data) { |
|
| 82 | + if ( ! is_array($existing_video_data)) { |
|
| 83 | 83 | $new_video_data[] = $existing_video_data; |
| 84 | 84 | |
| 85 | 85 | return $new_video_data; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( $this->is_associative_array( $existing_video_data ) ) { |
|
| 88 | + if ($this->is_associative_array($existing_video_data)) { |
|
| 89 | 89 | $new_video_data[] = $existing_video_data; |
| 90 | 90 | |
| 91 | 91 | return $new_video_data; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - return array_merge( $existing_video_data, $new_video_data ); |
|
| 94 | + return array_merge($existing_video_data, $new_video_data); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function wl_post_jsonld( $jsonld, $post_id, $references ) { |
|
| 97 | + public function wl_post_jsonld($jsonld, $post_id, $references) { |
|
| 98 | 98 | |
| 99 | - $video_jsonld = $this->get_videos_jsonld( $post_id ); |
|
| 100 | - if ( count( $video_jsonld ) === 0 ) { |
|
| 99 | + $video_jsonld = $this->get_videos_jsonld($post_id); |
|
| 100 | + if (count($video_jsonld) === 0) { |
|
| 101 | 101 | return $jsonld; |
| 102 | 102 | } |
| 103 | 103 | // Before adding the video jsonld check if the key |
| 104 | 104 | // is present and additional data might be present, |
| 105 | 105 | // if not present just add the data and return early. |
| 106 | - if ( ! array_key_exists( 'video', $jsonld ) ) { |
|
| 106 | + if ( ! array_key_exists('video', $jsonld)) { |
|
| 107 | 107 | $jsonld['video'] = $video_jsonld; |
| 108 | 108 | |
| 109 | 109 | return $jsonld; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | // since key exists, we need to merge the data based on type. |
| 113 | 113 | $previous_video_data = $jsonld['video']; |
| 114 | - $jsonld['video'] = $this->merge_video_data( $previous_video_data, $video_jsonld ); |
|
| 114 | + $jsonld['video'] = $this->merge_video_data($previous_video_data, $video_jsonld); |
|
| 115 | 115 | |
| 116 | 116 | return $jsonld; |
| 117 | 117 | } |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return array |
| 124 | 124 | */ |
| 125 | - public function get_videos_jsonld( $post_id ) { |
|
| 125 | + public function get_videos_jsonld($post_id) { |
|
| 126 | 126 | |
| 127 | - $videos = $this->video_storage->get_all_videos( $post_id ); |
|
| 127 | + $videos = $this->video_storage->get_all_videos($post_id); |
|
| 128 | 128 | |
| 129 | 129 | $jsonld = array(); |
| 130 | 130 | |
| 131 | - foreach ( $videos as $video ) { |
|
| 131 | + foreach ($videos as $video) { |
|
| 132 | 132 | /** |
| 133 | 133 | * @var $video Video |
| 134 | 134 | */ |
| 135 | 135 | $description = $video->description; |
| 136 | - if ( ! $video->description ) { |
|
| 136 | + if ( ! $video->description) { |
|
| 137 | 137 | // If description is empty then use the video title as description |
| 138 | 138 | $description = $video->name; |
| 139 | 139 | } |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | 'duration' => $video->duration, |
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - if ( $video->embed_url ) { |
|
| 151 | + if ($video->embed_url) { |
|
| 152 | 152 | $single_jsonld['embedUrl'] = $video->embed_url; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if ( $video->views ) { |
|
| 155 | + if ($video->views) { |
|
| 156 | 156 | $single_jsonld['interactionStatistic'] = array( |
| 157 | 157 | '@type' => 'InteractionCounter', |
| 158 | 158 | 'interactionType' => array( |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if ( $video->is_live_video ) { |
|
| 165 | + if ($video->is_live_video) { |
|
| 166 | 166 | $single_jsonld['publication'] = array( |
| 167 | 167 | '@type' => 'BroadcastEvent', |
| 168 | 168 | 'isLiveBroadcast' => true, |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
| 181 | - private function is_associative_array( $arr ) { |
|
| 182 | - if ( array() === $arr ) { |
|
| 181 | + private function is_associative_array($arr) { |
|
| 182 | + if (array() === $arr) { |
|
| 183 | 183 | return false; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
| 186 | + return array_keys($arr) !== range(0, count($arr) - 1); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -13,31 +13,31 @@ |
||
| 13 | 13 | |
| 14 | 14 | class Jw_Player_Capture { |
| 15 | 15 | |
| 16 | - public function init() { |
|
| 17 | - add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 ); |
|
| 18 | - } |
|
| 16 | + public function init() { |
|
| 17 | + add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 ); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) { |
|
| 22 | - // we cant reliably determine count for external plugin without |
|
| 23 | - // this method. |
|
| 24 | - global $wpdb; |
|
| 25 | - $post_meta_table_name = $wpdb->postmeta; |
|
| 26 | - $query_template = <<<EOF |
|
| 21 | + public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) { |
|
| 22 | + // we cant reliably determine count for external plugin without |
|
| 23 | + // this method. |
|
| 24 | + global $wpdb; |
|
| 25 | + $post_meta_table_name = $wpdb->postmeta; |
|
| 26 | + $query_template = <<<EOF |
|
| 27 | 27 | SELECT meta_value FROM $post_meta_table_name WHERE meta_key LIKE '_jwppp-video-url-%' AND post_id=%d |
| 28 | 28 | EOF; |
| 29 | - $query = $wpdb->prepare( $query_template, $post_id ); |
|
| 30 | - $video_ids = $wpdb->get_col( $query ); |
|
| 31 | - if ( ! $video_ids ) { |
|
| 32 | - return array(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - $jw_player_videos = array_map( function ( $video_id ) { |
|
| 36 | - return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id ); |
|
| 37 | - }, $video_ids ); |
|
| 38 | - |
|
| 39 | - return array_merge( $embedded_videos, $jw_player_videos ); |
|
| 40 | - } |
|
| 29 | + $query = $wpdb->prepare( $query_template, $post_id ); |
|
| 30 | + $video_ids = $wpdb->get_col( $query ); |
|
| 31 | + if ( ! $video_ids ) { |
|
| 32 | + return array(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + $jw_player_videos = array_map( function ( $video_id ) { |
|
| 36 | + return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id ); |
|
| 37 | + }, $video_ids ); |
|
| 38 | + |
|
| 39 | + return array_merge( $embedded_videos, $jw_player_videos ); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | } |
| 44 | 44 | \ No newline at end of file |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | class Jw_Player_Capture { |
| 15 | 15 | |
| 16 | 16 | public function init() { |
| 17 | - add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 ); |
|
| 17 | + add_filter('wl_videoobject_embedded_videos', array($this, 'wl_videoobject_embedded_videos'), 10, 2); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) { |
|
| 21 | + public function wl_videoobject_embedded_videos($embedded_videos, $post_id) { |
|
| 22 | 22 | // we cant reliably determine count for external plugin without |
| 23 | 23 | // this method. |
| 24 | 24 | global $wpdb; |
@@ -26,17 +26,17 @@ discard block |
||
| 26 | 26 | $query_template = <<<EOF |
| 27 | 27 | SELECT meta_value FROM $post_meta_table_name WHERE meta_key LIKE '_jwppp-video-url-%' AND post_id=%d |
| 28 | 28 | EOF; |
| 29 | - $query = $wpdb->prepare( $query_template, $post_id ); |
|
| 30 | - $video_ids = $wpdb->get_col( $query ); |
|
| 31 | - if ( ! $video_ids ) { |
|
| 29 | + $query = $wpdb->prepare($query_template, $post_id); |
|
| 30 | + $video_ids = $wpdb->get_col($query); |
|
| 31 | + if ( ! $video_ids) { |
|
| 32 | 32 | return array(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - $jw_player_videos = array_map( function ( $video_id ) { |
|
| 36 | - return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id ); |
|
| 37 | - }, $video_ids ); |
|
| 35 | + $jw_player_videos = array_map(function($video_id) { |
|
| 36 | + return new Default_Embedded_Video('https://cdn.jwplayer.com/v2/media/'.$video_id); |
|
| 37 | + }, $video_ids); |
|
| 38 | 38 | |
| 39 | - return array_merge( $embedded_videos, $jw_player_videos ); |
|
| 39 | + return array_merge($embedded_videos, $jw_player_videos); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -14,227 +14,227 @@ |
||
| 14 | 14 | |
| 15 | 15 | class Video_Processor { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array<Client> |
|
| 19 | - */ |
|
| 20 | - private $api_clients; |
|
| 21 | - |
|
| 22 | - public function __construct() { |
|
| 23 | - $this->api_clients = array( |
|
| 24 | - Client_Factory::get_client( Client_Factory::YOUTUBE ), |
|
| 25 | - Client_Factory::get_client( Client_Factory::VIMEO ), |
|
| 26 | - Client_Factory::get_client( Client_Factory::JWPLAYER ) |
|
| 27 | - ); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - private function get_data_for_videos( $embedded_videos, $post_id ) { |
|
| 31 | - |
|
| 32 | - $youtube_videos = $this->get_youtube_videos( $embedded_videos ); |
|
| 33 | - $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE ); |
|
| 34 | - $youtube_videos = $youtube_provider->get_videos_data( $youtube_videos ); |
|
| 35 | - |
|
| 36 | - $vimeo_videos = $this->get_vimeo_videos( $embedded_videos ); |
|
| 37 | - $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO ); |
|
| 38 | - $vimeo_videos = $vimeo_provider->get_videos_data( $vimeo_videos ); |
|
| 39 | - |
|
| 40 | - $jwplayer_videos = $this->get_jw_player_videos( $embedded_videos ); |
|
| 41 | - $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER ); |
|
| 42 | - $jwplayer_videos = $jwplayer_provider->get_videos_data( $jwplayer_videos ); |
|
| 43 | - |
|
| 44 | - return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos ); |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - private function get_video_ids( $video_urls ) { |
|
| 50 | - $clients = $this->api_clients; |
|
| 51 | - $video_ids = array(); |
|
| 52 | - foreach ( $clients as $client ) { |
|
| 53 | - $ids = $client->get_video_ids( $video_urls ); |
|
| 54 | - if ( $ids ) { |
|
| 55 | - $video_ids = array_merge( $video_ids, $ids ); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return array_unique( $video_ids ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param $storage Storage |
|
| 65 | - * @param $post_id int |
|
| 66 | - * @param $embedded_videos array<Embedded_Video> |
|
| 67 | - */ |
|
| 68 | - private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) { |
|
| 69 | - |
|
| 70 | - $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos ); |
|
| 71 | - $storage->remove_videos( $videos_to_be_deleted, $post_id ); |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param Storage $storage |
|
| 77 | - * @param $post_id |
|
| 78 | - * @param array $embedded_videos |
|
| 79 | - * |
|
| 80 | - * @return array An array of videos which exist on storage, not on post content. |
|
| 81 | - */ |
|
| 82 | - private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) { |
|
| 83 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
| 84 | - $embedded_video_urls = array_map( function ( $embedded_video ) { |
|
| 85 | - /** |
|
| 86 | - * @var $embedded_video Embedded_Video |
|
| 87 | - */ |
|
| 88 | - return $embedded_video->get_url(); |
|
| 89 | - }, $embedded_videos ); |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Previously we are checking if the captured url is content_url to delete it from the storage |
|
| 93 | - * but this might not work well if we want to support multiple URL formats, we extract the video |
|
| 94 | - * ids for embedded URLs. |
|
| 95 | - */ |
|
| 96 | - $embedded_video_ids = $this->get_video_ids( $embedded_video_urls ); |
|
| 97 | - |
|
| 98 | - $that = $this; |
|
| 99 | - |
|
| 100 | - return array_filter( $videos_in_store, function ( $video ) use ( $embedded_video_ids, $embedded_video_urls, $that ) { |
|
| 101 | - /** |
|
| 102 | - * If the video id doesnt exist on the content then we need to return it |
|
| 103 | - * in order to delete that video. |
|
| 104 | - */ |
|
| 105 | - return count( array_intersect( |
|
| 106 | - $that->get_video_ids( array( $video->id ) ), |
|
| 107 | - $embedded_video_ids |
|
| 108 | - ) ) === 0; |
|
| 109 | - |
|
| 110 | - } ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param \WP_Post $post |
|
| 115 | - * @param $post_id |
|
| 116 | - */ |
|
| 117 | - public function process_video_urls( \WP_Post $post, $post_id ) { |
|
| 118 | - |
|
| 119 | - $parser = Parser_Factory::get_parser_from_content( $post->post_content ); |
|
| 120 | - |
|
| 121 | - $embedded_videos = $parser->get_videos( $post_id ); |
|
| 122 | - /** |
|
| 123 | - * Filters the embedded videos on post contet, custom plugins can add their video urls |
|
| 124 | - * by constructing \Default_Embedded_Video or implement Embedded_Video class |
|
| 125 | - * |
|
| 126 | - * @param $embedded_videos array<Embedded_Video> |
|
| 127 | - * @param $post_id int The post id for the videoobject is processed. |
|
| 128 | - * |
|
| 129 | - * @return array<Embedded_Video> |
|
| 130 | - * @since 3.31.4 |
|
| 131 | - * Filter name : wl_videoobject_embedded_videos |
|
| 132 | - */ |
|
| 133 | - $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id ); |
|
| 134 | - |
|
| 135 | - $storage = Video_Storage_Factory::get_storage(); |
|
| 136 | - |
|
| 137 | - // Before sending api requests we need to check if there are any videos in |
|
| 138 | - // store which is not present on post content, remove them if there are |
|
| 139 | - // any |
|
| 140 | - $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ); |
|
| 141 | - |
|
| 142 | - $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos ); |
|
| 143 | - |
|
| 144 | - // Return early after removing all the videos. |
|
| 145 | - if ( ! $embedded_videos ) { |
|
| 146 | - return; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $videos = $this->get_data_for_videos( $embedded_videos, $post_id ); |
|
| 150 | - |
|
| 151 | - if ( ! $videos ) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - foreach ( $videos as $video ) { |
|
| 156 | - $storage->add_video( $post_id, $video ); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param $storage Storage |
|
| 162 | - * @param $post_id int |
|
| 163 | - * @param $embedded_videos array<Embedded_Video> |
|
| 164 | - * |
|
| 165 | - * @return array<Embedded_Video> Return array of embedded videos which are not in store. |
|
| 166 | - */ |
|
| 167 | - private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) { |
|
| 168 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
| 169 | - $video_urls_in_store = array_map( function ( $video ) { |
|
| 170 | - return $video->id; |
|
| 171 | - }, $videos_in_store ); |
|
| 172 | - |
|
| 173 | - $video_ids_in_store = $this->get_video_ids( $video_urls_in_store ); |
|
| 174 | - |
|
| 175 | - $that = $this; |
|
| 176 | - |
|
| 177 | - return array_filter( $embedded_videos, function ( $embedded_video ) use ( $video_ids_in_store, $that ) { |
|
| 178 | - /** |
|
| 179 | - * If the video id exist on content, not on storage then |
|
| 180 | - * we need to fetch the data. |
|
| 181 | - */ |
|
| 182 | - return count( array_intersect( |
|
| 183 | - $that->get_video_ids( array( $embedded_video->get_url() ) ), |
|
| 184 | - $video_ids_in_store |
|
| 185 | - ) ) === 0; |
|
| 186 | - } ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @param $embedded_videos |
|
| 191 | - * |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - private function get_youtube_videos( $embedded_videos ) { |
|
| 195 | - return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 196 | - /** |
|
| 197 | - * it should have youtube.com or youtu.be in the url |
|
| 198 | - * |
|
| 199 | - * @param $embedded_video Embedded_Video |
|
| 200 | - */ |
|
| 201 | - $video_url = $embedded_video->get_url(); |
|
| 202 | - |
|
| 203 | - return strpos( $video_url, "youtube.com" ) !== false || |
|
| 204 | - strpos( $video_url, "youtu.be" ) !== false; |
|
| 205 | - } ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param $embedded_videos |
|
| 210 | - * |
|
| 211 | - * @return array |
|
| 212 | - */ |
|
| 213 | - private function get_vimeo_videos( $embedded_videos ) { |
|
| 214 | - return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 215 | - /** |
|
| 216 | - * it should have vimeo.com in the url |
|
| 217 | - * |
|
| 218 | - * @param $embedded_video Embedded_Video |
|
| 219 | - */ |
|
| 220 | - $video_url = $embedded_video->get_url(); |
|
| 221 | - |
|
| 222 | - return strpos( $video_url, "vimeo.com" ) !== false; |
|
| 223 | - } ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - private function get_jw_player_videos( $embedded_videos ) { |
|
| 227 | - return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 228 | - /** |
|
| 229 | - * it should have vimeo.com in the url |
|
| 230 | - * |
|
| 231 | - * @param $embedded_video Embedded_Video |
|
| 232 | - */ |
|
| 233 | - $video_url = $embedded_video->get_url(); |
|
| 234 | - |
|
| 235 | - return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
| 236 | - } ); |
|
| 237 | - } |
|
| 17 | + /** |
|
| 18 | + * @var array<Client> |
|
| 19 | + */ |
|
| 20 | + private $api_clients; |
|
| 21 | + |
|
| 22 | + public function __construct() { |
|
| 23 | + $this->api_clients = array( |
|
| 24 | + Client_Factory::get_client( Client_Factory::YOUTUBE ), |
|
| 25 | + Client_Factory::get_client( Client_Factory::VIMEO ), |
|
| 26 | + Client_Factory::get_client( Client_Factory::JWPLAYER ) |
|
| 27 | + ); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + private function get_data_for_videos( $embedded_videos, $post_id ) { |
|
| 31 | + |
|
| 32 | + $youtube_videos = $this->get_youtube_videos( $embedded_videos ); |
|
| 33 | + $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE ); |
|
| 34 | + $youtube_videos = $youtube_provider->get_videos_data( $youtube_videos ); |
|
| 35 | + |
|
| 36 | + $vimeo_videos = $this->get_vimeo_videos( $embedded_videos ); |
|
| 37 | + $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO ); |
|
| 38 | + $vimeo_videos = $vimeo_provider->get_videos_data( $vimeo_videos ); |
|
| 39 | + |
|
| 40 | + $jwplayer_videos = $this->get_jw_player_videos( $embedded_videos ); |
|
| 41 | + $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER ); |
|
| 42 | + $jwplayer_videos = $jwplayer_provider->get_videos_data( $jwplayer_videos ); |
|
| 43 | + |
|
| 44 | + return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos ); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + private function get_video_ids( $video_urls ) { |
|
| 50 | + $clients = $this->api_clients; |
|
| 51 | + $video_ids = array(); |
|
| 52 | + foreach ( $clients as $client ) { |
|
| 53 | + $ids = $client->get_video_ids( $video_urls ); |
|
| 54 | + if ( $ids ) { |
|
| 55 | + $video_ids = array_merge( $video_ids, $ids ); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return array_unique( $video_ids ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param $storage Storage |
|
| 65 | + * @param $post_id int |
|
| 66 | + * @param $embedded_videos array<Embedded_Video> |
|
| 67 | + */ |
|
| 68 | + private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) { |
|
| 69 | + |
|
| 70 | + $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos ); |
|
| 71 | + $storage->remove_videos( $videos_to_be_deleted, $post_id ); |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param Storage $storage |
|
| 77 | + * @param $post_id |
|
| 78 | + * @param array $embedded_videos |
|
| 79 | + * |
|
| 80 | + * @return array An array of videos which exist on storage, not on post content. |
|
| 81 | + */ |
|
| 82 | + private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) { |
|
| 83 | + $videos_in_store = $storage->get_all_videos( $post_id ); |
|
| 84 | + $embedded_video_urls = array_map( function ( $embedded_video ) { |
|
| 85 | + /** |
|
| 86 | + * @var $embedded_video Embedded_Video |
|
| 87 | + */ |
|
| 88 | + return $embedded_video->get_url(); |
|
| 89 | + }, $embedded_videos ); |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Previously we are checking if the captured url is content_url to delete it from the storage |
|
| 93 | + * but this might not work well if we want to support multiple URL formats, we extract the video |
|
| 94 | + * ids for embedded URLs. |
|
| 95 | + */ |
|
| 96 | + $embedded_video_ids = $this->get_video_ids( $embedded_video_urls ); |
|
| 97 | + |
|
| 98 | + $that = $this; |
|
| 99 | + |
|
| 100 | + return array_filter( $videos_in_store, function ( $video ) use ( $embedded_video_ids, $embedded_video_urls, $that ) { |
|
| 101 | + /** |
|
| 102 | + * If the video id doesnt exist on the content then we need to return it |
|
| 103 | + * in order to delete that video. |
|
| 104 | + */ |
|
| 105 | + return count( array_intersect( |
|
| 106 | + $that->get_video_ids( array( $video->id ) ), |
|
| 107 | + $embedded_video_ids |
|
| 108 | + ) ) === 0; |
|
| 109 | + |
|
| 110 | + } ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param \WP_Post $post |
|
| 115 | + * @param $post_id |
|
| 116 | + */ |
|
| 117 | + public function process_video_urls( \WP_Post $post, $post_id ) { |
|
| 118 | + |
|
| 119 | + $parser = Parser_Factory::get_parser_from_content( $post->post_content ); |
|
| 120 | + |
|
| 121 | + $embedded_videos = $parser->get_videos( $post_id ); |
|
| 122 | + /** |
|
| 123 | + * Filters the embedded videos on post contet, custom plugins can add their video urls |
|
| 124 | + * by constructing \Default_Embedded_Video or implement Embedded_Video class |
|
| 125 | + * |
|
| 126 | + * @param $embedded_videos array<Embedded_Video> |
|
| 127 | + * @param $post_id int The post id for the videoobject is processed. |
|
| 128 | + * |
|
| 129 | + * @return array<Embedded_Video> |
|
| 130 | + * @since 3.31.4 |
|
| 131 | + * Filter name : wl_videoobject_embedded_videos |
|
| 132 | + */ |
|
| 133 | + $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id ); |
|
| 134 | + |
|
| 135 | + $storage = Video_Storage_Factory::get_storage(); |
|
| 136 | + |
|
| 137 | + // Before sending api requests we need to check if there are any videos in |
|
| 138 | + // store which is not present on post content, remove them if there are |
|
| 139 | + // any |
|
| 140 | + $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ); |
|
| 141 | + |
|
| 142 | + $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos ); |
|
| 143 | + |
|
| 144 | + // Return early after removing all the videos. |
|
| 145 | + if ( ! $embedded_videos ) { |
|
| 146 | + return; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $videos = $this->get_data_for_videos( $embedded_videos, $post_id ); |
|
| 150 | + |
|
| 151 | + if ( ! $videos ) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + foreach ( $videos as $video ) { |
|
| 156 | + $storage->add_video( $post_id, $video ); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param $storage Storage |
|
| 162 | + * @param $post_id int |
|
| 163 | + * @param $embedded_videos array<Embedded_Video> |
|
| 164 | + * |
|
| 165 | + * @return array<Embedded_Video> Return array of embedded videos which are not in store. |
|
| 166 | + */ |
|
| 167 | + private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) { |
|
| 168 | + $videos_in_store = $storage->get_all_videos( $post_id ); |
|
| 169 | + $video_urls_in_store = array_map( function ( $video ) { |
|
| 170 | + return $video->id; |
|
| 171 | + }, $videos_in_store ); |
|
| 172 | + |
|
| 173 | + $video_ids_in_store = $this->get_video_ids( $video_urls_in_store ); |
|
| 174 | + |
|
| 175 | + $that = $this; |
|
| 176 | + |
|
| 177 | + return array_filter( $embedded_videos, function ( $embedded_video ) use ( $video_ids_in_store, $that ) { |
|
| 178 | + /** |
|
| 179 | + * If the video id exist on content, not on storage then |
|
| 180 | + * we need to fetch the data. |
|
| 181 | + */ |
|
| 182 | + return count( array_intersect( |
|
| 183 | + $that->get_video_ids( array( $embedded_video->get_url() ) ), |
|
| 184 | + $video_ids_in_store |
|
| 185 | + ) ) === 0; |
|
| 186 | + } ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @param $embedded_videos |
|
| 191 | + * |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + private function get_youtube_videos( $embedded_videos ) { |
|
| 195 | + return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 196 | + /** |
|
| 197 | + * it should have youtube.com or youtu.be in the url |
|
| 198 | + * |
|
| 199 | + * @param $embedded_video Embedded_Video |
|
| 200 | + */ |
|
| 201 | + $video_url = $embedded_video->get_url(); |
|
| 202 | + |
|
| 203 | + return strpos( $video_url, "youtube.com" ) !== false || |
|
| 204 | + strpos( $video_url, "youtu.be" ) !== false; |
|
| 205 | + } ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param $embedded_videos |
|
| 210 | + * |
|
| 211 | + * @return array |
|
| 212 | + */ |
|
| 213 | + private function get_vimeo_videos( $embedded_videos ) { |
|
| 214 | + return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 215 | + /** |
|
| 216 | + * it should have vimeo.com in the url |
|
| 217 | + * |
|
| 218 | + * @param $embedded_video Embedded_Video |
|
| 219 | + */ |
|
| 220 | + $video_url = $embedded_video->get_url(); |
|
| 221 | + |
|
| 222 | + return strpos( $video_url, "vimeo.com" ) !== false; |
|
| 223 | + } ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + private function get_jw_player_videos( $embedded_videos ) { |
|
| 227 | + return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 228 | + /** |
|
| 229 | + * it should have vimeo.com in the url |
|
| 230 | + * |
|
| 231 | + * @param $embedded_video Embedded_Video |
|
| 232 | + */ |
|
| 233 | + $video_url = $embedded_video->get_url(); |
|
| 234 | + |
|
| 235 | + return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
| 236 | + } ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | \ No newline at end of file |
@@ -21,42 +21,42 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function __construct() { |
| 23 | 23 | $this->api_clients = array( |
| 24 | - Client_Factory::get_client( Client_Factory::YOUTUBE ), |
|
| 25 | - Client_Factory::get_client( Client_Factory::VIMEO ), |
|
| 26 | - Client_Factory::get_client( Client_Factory::JWPLAYER ) |
|
| 24 | + Client_Factory::get_client(Client_Factory::YOUTUBE), |
|
| 25 | + Client_Factory::get_client(Client_Factory::VIMEO), |
|
| 26 | + Client_Factory::get_client(Client_Factory::JWPLAYER) |
|
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - private function get_data_for_videos( $embedded_videos, $post_id ) { |
|
| 30 | + private function get_data_for_videos($embedded_videos, $post_id) { |
|
| 31 | 31 | |
| 32 | - $youtube_videos = $this->get_youtube_videos( $embedded_videos ); |
|
| 33 | - $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE ); |
|
| 34 | - $youtube_videos = $youtube_provider->get_videos_data( $youtube_videos ); |
|
| 32 | + $youtube_videos = $this->get_youtube_videos($embedded_videos); |
|
| 33 | + $youtube_provider = Provider_Factory::get_provider(Provider_Factory::YOUTUBE); |
|
| 34 | + $youtube_videos = $youtube_provider->get_videos_data($youtube_videos); |
|
| 35 | 35 | |
| 36 | - $vimeo_videos = $this->get_vimeo_videos( $embedded_videos ); |
|
| 37 | - $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO ); |
|
| 38 | - $vimeo_videos = $vimeo_provider->get_videos_data( $vimeo_videos ); |
|
| 36 | + $vimeo_videos = $this->get_vimeo_videos($embedded_videos); |
|
| 37 | + $vimeo_provider = Provider_Factory::get_provider(Provider_Factory::VIMEO); |
|
| 38 | + $vimeo_videos = $vimeo_provider->get_videos_data($vimeo_videos); |
|
| 39 | 39 | |
| 40 | - $jwplayer_videos = $this->get_jw_player_videos( $embedded_videos ); |
|
| 41 | - $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER ); |
|
| 42 | - $jwplayer_videos = $jwplayer_provider->get_videos_data( $jwplayer_videos ); |
|
| 40 | + $jwplayer_videos = $this->get_jw_player_videos($embedded_videos); |
|
| 41 | + $jwplayer_provider = Provider_Factory::get_provider(Provider_Factory::JWPLAYER); |
|
| 42 | + $jwplayer_videos = $jwplayer_provider->get_videos_data($jwplayer_videos); |
|
| 43 | 43 | |
| 44 | - return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos ); |
|
| 44 | + return array_merge($youtube_videos, $vimeo_videos, $jwplayer_videos); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
| 49 | - private function get_video_ids( $video_urls ) { |
|
| 49 | + private function get_video_ids($video_urls) { |
|
| 50 | 50 | $clients = $this->api_clients; |
| 51 | 51 | $video_ids = array(); |
| 52 | - foreach ( $clients as $client ) { |
|
| 53 | - $ids = $client->get_video_ids( $video_urls ); |
|
| 54 | - if ( $ids ) { |
|
| 55 | - $video_ids = array_merge( $video_ids, $ids ); |
|
| 52 | + foreach ($clients as $client) { |
|
| 53 | + $ids = $client->get_video_ids($video_urls); |
|
| 54 | + if ($ids) { |
|
| 55 | + $video_ids = array_merge($video_ids, $ids); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - return array_unique( $video_ids ); |
|
| 59 | + return array_unique($video_ids); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | * @param $post_id int |
| 66 | 66 | * @param $embedded_videos array<Embedded_Video> |
| 67 | 67 | */ |
| 68 | - private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) { |
|
| 68 | + private function remove_videos_from_store_if_not_present_in_content($storage, $post_id, $embedded_videos) { |
|
| 69 | 69 | |
| 70 | - $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos ); |
|
| 71 | - $storage->remove_videos( $videos_to_be_deleted, $post_id ); |
|
| 70 | + $videos_to_be_deleted = $this->get_videos_to_be_deleted($storage, $post_id, $embedded_videos); |
|
| 71 | + $storage->remove_videos($videos_to_be_deleted, $post_id); |
|
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | |
@@ -79,33 +79,33 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return array An array of videos which exist on storage, not on post content. |
| 81 | 81 | */ |
| 82 | - private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) { |
|
| 83 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
| 84 | - $embedded_video_urls = array_map( function ( $embedded_video ) { |
|
| 82 | + private function get_videos_to_be_deleted(Storage $storage, $post_id, array $embedded_videos) { |
|
| 83 | + $videos_in_store = $storage->get_all_videos($post_id); |
|
| 84 | + $embedded_video_urls = array_map(function($embedded_video) { |
|
| 85 | 85 | /** |
| 86 | 86 | * @var $embedded_video Embedded_Video |
| 87 | 87 | */ |
| 88 | 88 | return $embedded_video->get_url(); |
| 89 | - }, $embedded_videos ); |
|
| 89 | + }, $embedded_videos); |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Previously we are checking if the captured url is content_url to delete it from the storage |
| 93 | 93 | * but this might not work well if we want to support multiple URL formats, we extract the video |
| 94 | 94 | * ids for embedded URLs. |
| 95 | 95 | */ |
| 96 | - $embedded_video_ids = $this->get_video_ids( $embedded_video_urls ); |
|
| 96 | + $embedded_video_ids = $this->get_video_ids($embedded_video_urls); |
|
| 97 | 97 | |
| 98 | 98 | $that = $this; |
| 99 | 99 | |
| 100 | - return array_filter( $videos_in_store, function ( $video ) use ( $embedded_video_ids, $embedded_video_urls, $that ) { |
|
| 100 | + return array_filter($videos_in_store, function($video) use ($embedded_video_ids, $embedded_video_urls, $that) { |
|
| 101 | 101 | /** |
| 102 | 102 | * If the video id doesnt exist on the content then we need to return it |
| 103 | 103 | * in order to delete that video. |
| 104 | 104 | */ |
| 105 | - return count( array_intersect( |
|
| 106 | - $that->get_video_ids( array( $video->id ) ), |
|
| 105 | + return count(array_intersect( |
|
| 106 | + $that->get_video_ids(array($video->id)), |
|
| 107 | 107 | $embedded_video_ids |
| 108 | - ) ) === 0; |
|
| 108 | + )) === 0; |
|
| 109 | 109 | |
| 110 | 110 | } ); |
| 111 | 111 | } |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | * @param \WP_Post $post |
| 115 | 115 | * @param $post_id |
| 116 | 116 | */ |
| 117 | - public function process_video_urls( \WP_Post $post, $post_id ) { |
|
| 117 | + public function process_video_urls(\WP_Post $post, $post_id) { |
|
| 118 | 118 | |
| 119 | - $parser = Parser_Factory::get_parser_from_content( $post->post_content ); |
|
| 119 | + $parser = Parser_Factory::get_parser_from_content($post->post_content); |
|
| 120 | 120 | |
| 121 | - $embedded_videos = $parser->get_videos( $post_id ); |
|
| 121 | + $embedded_videos = $parser->get_videos($post_id); |
|
| 122 | 122 | /** |
| 123 | 123 | * Filters the embedded videos on post contet, custom plugins can add their video urls |
| 124 | 124 | * by constructing \Default_Embedded_Video or implement Embedded_Video class |
@@ -130,30 +130,30 @@ discard block |
||
| 130 | 130 | * @since 3.31.4 |
| 131 | 131 | * Filter name : wl_videoobject_embedded_videos |
| 132 | 132 | */ |
| 133 | - $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id ); |
|
| 133 | + $embedded_videos = apply_filters('wl_videoobject_embedded_videos', $embedded_videos, $post_id); |
|
| 134 | 134 | |
| 135 | 135 | $storage = Video_Storage_Factory::get_storage(); |
| 136 | 136 | |
| 137 | 137 | // Before sending api requests we need to check if there are any videos in |
| 138 | 138 | // store which is not present on post content, remove them if there are |
| 139 | 139 | // any |
| 140 | - $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ); |
|
| 140 | + $this->remove_videos_from_store_if_not_present_in_content($storage, $post_id, $embedded_videos); |
|
| 141 | 141 | |
| 142 | - $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos ); |
|
| 142 | + $embedded_videos = $this->get_videos_without_existing_data($storage, $post_id, $embedded_videos); |
|
| 143 | 143 | |
| 144 | 144 | // Return early after removing all the videos. |
| 145 | - if ( ! $embedded_videos ) { |
|
| 145 | + if ( ! $embedded_videos) { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $videos = $this->get_data_for_videos( $embedded_videos, $post_id ); |
|
| 149 | + $videos = $this->get_data_for_videos($embedded_videos, $post_id); |
|
| 150 | 150 | |
| 151 | - if ( ! $videos ) { |
|
| 151 | + if ( ! $videos) { |
|
| 152 | 152 | return; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - foreach ( $videos as $video ) { |
|
| 156 | - $storage->add_video( $post_id, $video ); |
|
| 155 | + foreach ($videos as $video) { |
|
| 156 | + $storage->add_video($post_id, $video); |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
@@ -164,25 +164,25 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @return array<Embedded_Video> Return array of embedded videos which are not in store. |
| 166 | 166 | */ |
| 167 | - private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) { |
|
| 168 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
| 169 | - $video_urls_in_store = array_map( function ( $video ) { |
|
| 167 | + private function get_videos_without_existing_data($storage, $post_id, $embedded_videos) { |
|
| 168 | + $videos_in_store = $storage->get_all_videos($post_id); |
|
| 169 | + $video_urls_in_store = array_map(function($video) { |
|
| 170 | 170 | return $video->id; |
| 171 | - }, $videos_in_store ); |
|
| 171 | + }, $videos_in_store); |
|
| 172 | 172 | |
| 173 | - $video_ids_in_store = $this->get_video_ids( $video_urls_in_store ); |
|
| 173 | + $video_ids_in_store = $this->get_video_ids($video_urls_in_store); |
|
| 174 | 174 | |
| 175 | 175 | $that = $this; |
| 176 | 176 | |
| 177 | - return array_filter( $embedded_videos, function ( $embedded_video ) use ( $video_ids_in_store, $that ) { |
|
| 177 | + return array_filter($embedded_videos, function($embedded_video) use ($video_ids_in_store, $that) { |
|
| 178 | 178 | /** |
| 179 | 179 | * If the video id exist on content, not on storage then |
| 180 | 180 | * we need to fetch the data. |
| 181 | 181 | */ |
| 182 | - return count( array_intersect( |
|
| 183 | - $that->get_video_ids( array( $embedded_video->get_url() ) ), |
|
| 182 | + return count(array_intersect( |
|
| 183 | + $that->get_video_ids(array($embedded_video->get_url())), |
|
| 184 | 184 | $video_ids_in_store |
| 185 | - ) ) === 0; |
|
| 185 | + )) === 0; |
|
| 186 | 186 | } ); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | - private function get_youtube_videos( $embedded_videos ) { |
|
| 195 | - return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 194 | + private function get_youtube_videos($embedded_videos) { |
|
| 195 | + return array_filter($embedded_videos, function($embedded_video) { |
|
| 196 | 196 | /** |
| 197 | 197 | * it should have youtube.com or youtu.be in the url |
| 198 | 198 | * |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | $video_url = $embedded_video->get_url(); |
| 202 | 202 | |
| 203 | - return strpos( $video_url, "youtube.com" ) !== false || |
|
| 204 | - strpos( $video_url, "youtu.be" ) !== false; |
|
| 203 | + return strpos($video_url, "youtube.com") !== false || |
|
| 204 | + strpos($video_url, "youtu.be") !== false; |
|
| 205 | 205 | } ); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @return array |
| 212 | 212 | */ |
| 213 | - private function get_vimeo_videos( $embedded_videos ) { |
|
| 214 | - return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 213 | + private function get_vimeo_videos($embedded_videos) { |
|
| 214 | + return array_filter($embedded_videos, function($embedded_video) { |
|
| 215 | 215 | /** |
| 216 | 216 | * it should have vimeo.com in the url |
| 217 | 217 | * |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | $video_url = $embedded_video->get_url(); |
| 221 | 221 | |
| 222 | - return strpos( $video_url, "vimeo.com" ) !== false; |
|
| 222 | + return strpos($video_url, "vimeo.com") !== false; |
|
| 223 | 223 | } ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - private function get_jw_player_videos( $embedded_videos ) { |
|
| 227 | - return array_filter( $embedded_videos, function ( $embedded_video ) { |
|
| 226 | + private function get_jw_player_videos($embedded_videos) { |
|
| 227 | + return array_filter($embedded_videos, function($embedded_video) { |
|
| 228 | 228 | /** |
| 229 | 229 | * it should have vimeo.com in the url |
| 230 | 230 | * |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | $video_url = $embedded_video->get_url(); |
| 234 | 234 | |
| 235 | - return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
| 235 | + return strpos($video_url, 'https://cdn.jwplayer.com/v2/media/', 0) !== false; |
|
| 236 | 236 | } ); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -24,57 +24,57 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Loader extends Default_Loader { |
| 26 | 26 | |
| 27 | - public function init_all_dependencies() { |
|
| 28 | - $video_storage = Video_Storage_Factory::get_storage(); |
|
| 29 | - new Jsonld( $video_storage ); |
|
| 27 | + public function init_all_dependencies() { |
|
| 28 | + $video_storage = Video_Storage_Factory::get_storage(); |
|
| 29 | + new Jsonld( $video_storage ); |
|
| 30 | 30 | |
| 31 | - $sitemap_cache = new Ttl_Cache( "wl_video_sitemap", 86400 ); |
|
| 31 | + $sitemap_cache = new Ttl_Cache( "wl_video_sitemap", 86400 ); |
|
| 32 | 32 | |
| 33 | - $video_processor = new Video_Processor(); |
|
| 34 | - // Hook in to save_post to save the videos |
|
| 35 | - $post_filter = new Post_Filter( $video_processor ); |
|
| 36 | - $post_filter->init(); |
|
| 37 | - // Add entry to wordlift admin tabs |
|
| 38 | - $settings_tab = new Settings_Tab(); |
|
| 39 | - $settings_tab->init(); |
|
| 33 | + $video_processor = new Video_Processor(); |
|
| 34 | + // Hook in to save_post to save the videos |
|
| 35 | + $post_filter = new Post_Filter( $video_processor ); |
|
| 36 | + $post_filter->init(); |
|
| 37 | + // Add entry to wordlift admin tabs |
|
| 38 | + $settings_tab = new Settings_Tab(); |
|
| 39 | + $settings_tab->init(); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - $video_sitemap = new Video_Sitemap( $sitemap_cache ); |
|
| 43 | - $video_sitemap->init(); |
|
| 42 | + $video_sitemap = new Video_Sitemap( $sitemap_cache ); |
|
| 43 | + $video_sitemap->init(); |
|
| 44 | 44 | |
| 45 | - $background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' ); |
|
| 46 | - $background_process = new Videoobject_Background_Process( $video_processor, $background_process_data_source ); |
|
| 45 | + $background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' ); |
|
| 46 | + $background_process = new Videoobject_Background_Process( $video_processor, $background_process_data_source ); |
|
| 47 | 47 | |
| 48 | - $rest_controller = new Rest_Controller( $background_process ); |
|
| 49 | - $rest_controller->register_all_routes(); |
|
| 48 | + $rest_controller = new Rest_Controller( $background_process ); |
|
| 49 | + $rest_controller->register_all_routes(); |
|
| 50 | 50 | |
| 51 | - $post_edit_screen = new Post_Edit_Screen(); |
|
| 52 | - $post_edit_screen->init(); |
|
| 51 | + $post_edit_screen = new Post_Edit_Screen(); |
|
| 52 | + $post_edit_screen->init(); |
|
| 53 | 53 | |
| 54 | - new Import_Videos_Page(); |
|
| 54 | + new Import_Videos_Page(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @since 3.32.0 |
|
| 58 | - * Allow videoobject to capture embed shortcode. |
|
| 59 | - */ |
|
| 60 | - $embed_shortcode_capture = new Embed_Shortcode_Capture(); |
|
| 61 | - $embed_shortcode_capture->init(); |
|
| 56 | + /** |
|
| 57 | + * @since 3.32.0 |
|
| 58 | + * Allow videoobject to capture embed shortcode. |
|
| 59 | + */ |
|
| 60 | + $embed_shortcode_capture = new Embed_Shortcode_Capture(); |
|
| 61 | + $embed_shortcode_capture->init(); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @since 3.32.0 |
|
| 66 | - * Get videos from jw player. |
|
| 67 | - */ |
|
| 68 | - $jw_player_capture_videos = new Jw_Player_Capture(); |
|
| 69 | - $jw_player_capture_videos->init(); |
|
| 64 | + /** |
|
| 65 | + * @since 3.32.0 |
|
| 66 | + * Get videos from jw player. |
|
| 67 | + */ |
|
| 68 | + $jw_player_capture_videos = new Jw_Player_Capture(); |
|
| 69 | + $jw_player_capture_videos->init(); |
|
| 70 | 70 | |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function get_feature_slug() { |
|
| 74 | - return 'videoobject'; |
|
| 75 | - } |
|
| 73 | + public function get_feature_slug() { |
|
| 74 | + return 'videoobject'; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function get_feature_default_value() { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 77 | + public function get_feature_default_value() { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | 80 | } |
| 81 | 81 | \ No newline at end of file |
@@ -11,48 +11,48 @@ |
||
| 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( $video_urls, function ( $item ) { |
|
| 40 | - return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ); |
|
| 41 | - } ); |
|
| 39 | + return array_filter( $video_urls, function ( $item ) { |
|
| 40 | + return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ); |
|
| 41 | + } ); |
|
| 42 | 42 | |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public static function get_api_key() { |
|
| 46 | - // Method not implemented, since we dont need api key |
|
| 47 | - } |
|
| 45 | + public static function get_api_key() { |
|
| 46 | + // Method not implemented, since we dont need api key |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public static function get_api_key_option_name() { |
|
| 50 | - // Method not implemented, since we dont need api key |
|
| 51 | - } |
|
| 49 | + public static function get_api_key_option_name() { |
|
| 50 | + // Method not implemented, since we dont need api key |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function get_api_url() { |
|
| 54 | - // Method not implemented, since we dont need api key |
|
| 55 | - } |
|
| 53 | + public function get_api_url() { |
|
| 54 | + // Method not implemented, since we dont need api key |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | } |
| 59 | 59 | \ No newline at end of file |
@@ -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,10 +34,10 @@ 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 | - return array_filter( $video_urls, function ( $item ) { |
|
| 40 | - return strpos( $item, 'https://cdn.jwplayer.com/v2/media/', 0 ); |
|
| 39 | + return array_filter($video_urls, function($item) { |
|
| 40 | + return strpos($item, 'https://cdn.jwplayer.com/v2/media/', 0); |
|
| 41 | 41 | } ); |
| 42 | 42 | |
| 43 | 43 | } |
@@ -8,21 +8,21 @@ |
||
| 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 | - const JWPLAYER = 'jwplayer'; |
|
| 15 | + const JWPLAYER = 'jwplayer'; |
|
| 16 | 16 | |
| 17 | - public static function get_client( $config ) { |
|
| 18 | - if ( self::YOUTUBE === $config ) { |
|
| 19 | - return Youtube_Client::get_instance(); |
|
| 20 | - } else if ( self::VIMEO === $config ) { |
|
| 21 | - return Vimeo_Client::get_instance(); |
|
| 22 | - } |
|
| 23 | - else if ( self::JWPLAYER === $config ) { |
|
| 24 | - return Jw_Player_Client::get_instance(); |
|
| 25 | - } |
|
| 17 | + public static function get_client( $config ) { |
|
| 18 | + if ( self::YOUTUBE === $config ) { |
|
| 19 | + return Youtube_Client::get_instance(); |
|
| 20 | + } else if ( self::VIMEO === $config ) { |
|
| 21 | + return Vimeo_Client::get_instance(); |
|
| 22 | + } |
|
| 23 | + else if ( self::JWPLAYER === $config ) { |
|
| 24 | + return Jw_Player_Client::get_instance(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | } |
| 29 | 29 | \ No newline at end of file |
@@ -14,13 +14,13 @@ |
||
| 14 | 14 | |
| 15 | 15 | const JWPLAYER = 'jwplayer'; |
| 16 | 16 | |
| 17 | - public static function get_client( $config ) { |
|
| 18 | - if ( self::YOUTUBE === $config ) { |
|
| 17 | + public static function get_client($config) { |
|
| 18 | + if (self::YOUTUBE === $config) { |
|
| 19 | 19 | return Youtube_Client::get_instance(); |
| 20 | - } else if ( self::VIMEO === $config ) { |
|
| 20 | + } else if (self::VIMEO === $config) { |
|
| 21 | 21 | return Vimeo_Client::get_instance(); |
| 22 | 22 | } |
| 23 | - else if ( self::JWPLAYER === $config ) { |
|
| 23 | + else if (self::JWPLAYER === $config) { |
|
| 24 | 24 | return Jw_Player_Client::get_instance(); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | return Youtube_Client::get_instance(); |
| 20 | 20 | } else if ( self::VIMEO === $config ) { |
| 21 | 21 | return Vimeo_Client::get_instance(); |
| 22 | - } |
|
| 23 | - else if ( self::JWPLAYER === $config ) { |
|
| 22 | + } else if ( self::JWPLAYER === $config ) { |
|
| 24 | 23 | return Jw_Player_Client::get_instance(); |
| 25 | 24 | } |
| 26 | 25 | |
@@ -12,62 +12,62 @@ |
||
| 12 | 12 | class Jw_Player extends Api_Provider { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param $videos array<Embedded_Video> |
|
| 17 | - * |
|
| 18 | - * @return array<Video> |
|
| 19 | - */ |
|
| 20 | - public function get_videos_data( $videos ) { |
|
| 15 | + /** |
|
| 16 | + * @param $videos array<Embedded_Video> |
|
| 17 | + * |
|
| 18 | + * @return array<Video> |
|
| 19 | + */ |
|
| 20 | + public function get_videos_data( $videos ) { |
|
| 21 | 21 | |
| 22 | - $video_urls = array_map( function ( $video ) { |
|
| 23 | - return $video->get_url(); |
|
| 24 | - }, $videos ); |
|
| 22 | + $video_urls = array_map( function ( $video ) { |
|
| 23 | + return $video->get_url(); |
|
| 24 | + }, $videos ); |
|
| 25 | 25 | |
| 26 | - $videos_data = $this->api_client->get_data( $video_urls ); |
|
| 26 | + $videos_data = $this->api_client->get_data( $video_urls ); |
|
| 27 | 27 | |
| 28 | - return array_filter( array_map( function ( $video_data ) { |
|
| 28 | + return array_filter( array_map( function ( $video_data ) { |
|
| 29 | 29 | |
| 30 | - if ( ! array_key_exists( 'playlist', $video_data ) |
|
| 30 | + if ( ! array_key_exists( 'playlist', $video_data ) |
|
| 31 | 31 | |
| 32 | - || ! is_array( $video_data['playlist'] ) |
|
| 32 | + || ! is_array( $video_data['playlist'] ) |
|
| 33 | 33 | |
| 34 | - || count( $video_data['playlist'] ) === 0 ) { |
|
| 34 | + || count( $video_data['playlist'] ) === 0 ) { |
|
| 35 | 35 | |
| 36 | - return false; |
|
| 36 | + return false; |
|
| 37 | 37 | |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $video = new Video(); |
|
| 41 | - $video->id = $video_data['id']; |
|
| 42 | - $playlist_item_data = $video_data['playlist'][0]; |
|
| 43 | - $video->name = $playlist_item_data['title']; |
|
| 44 | - $video->description = $playlist_item_data['description']; |
|
| 45 | - $video->thumbnail_urls = array_filter( array_map( function ( $item ) { |
|
| 46 | - return $item['src']; |
|
| 47 | - }, $playlist_item_data['images'] ) ); |
|
| 40 | + $video = new Video(); |
|
| 41 | + $video->id = $video_data['id']; |
|
| 42 | + $playlist_item_data = $video_data['playlist'][0]; |
|
| 43 | + $video->name = $playlist_item_data['title']; |
|
| 44 | + $video->description = $playlist_item_data['description']; |
|
| 45 | + $video->thumbnail_urls = array_filter( array_map( function ( $item ) { |
|
| 46 | + return $item['src']; |
|
| 47 | + }, $playlist_item_data['images'] ) ); |
|
| 48 | 48 | |
| 49 | - $video->duration = "PT" . (int) $playlist_item_data['duration'] . "S"; |
|
| 50 | - $video->upload_date = date( 'c', (int) $playlist_item_data['pubdate'] ); |
|
| 49 | + $video->duration = "PT" . (int) $playlist_item_data['duration'] . "S"; |
|
| 50 | + $video->upload_date = date( 'c', (int) $playlist_item_data['pubdate'] ); |
|
| 51 | 51 | |
| 52 | - $video_content_urls_data = array_filter( $playlist_item_data['sources'], function ( $item ) { |
|
| 53 | - return strpos( $item['type'], 'video/' ) !== false; |
|
| 54 | - } ); |
|
| 52 | + $video_content_urls_data = array_filter( $playlist_item_data['sources'], function ( $item ) { |
|
| 53 | + return strpos( $item['type'], 'video/' ) !== false; |
|
| 54 | + } ); |
|
| 55 | 55 | |
| 56 | - $video_content_urls = array_map( function ( $item ) { |
|
| 57 | - return $item['file']; |
|
| 58 | - }, $video_content_urls_data ); |
|
| 56 | + $video_content_urls = array_map( function ( $item ) { |
|
| 57 | + return $item['file']; |
|
| 58 | + }, $video_content_urls_data ); |
|
| 59 | 59 | |
| 60 | - // Content url is a single field, so we pick the video with |
|
| 61 | - // high resolution. |
|
| 62 | - $video->content_url = array_pop( $video_content_urls ); |
|
| 60 | + // Content url is a single field, so we pick the video with |
|
| 61 | + // high resolution. |
|
| 62 | + $video->content_url = array_pop( $video_content_urls ); |
|
| 63 | 63 | |
| 64 | - // We dont have embed url for JW Player. |
|
| 65 | - $video->embed_url = ''; |
|
| 64 | + // We dont have embed url for JW Player. |
|
| 65 | + $video->embed_url = ''; |
|
| 66 | 66 | |
| 67 | - return $video; |
|
| 67 | + return $video; |
|
| 68 | 68 | |
| 69 | - }, $videos_data ) ); |
|
| 69 | + }, $videos_data ) ); |
|
| 70 | 70 | |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | } |
@@ -17,21 +17,21 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @return array<Video> |
| 19 | 19 | */ |
| 20 | - public function get_videos_data( $videos ) { |
|
| 20 | + public function get_videos_data($videos) { |
|
| 21 | 21 | |
| 22 | - $video_urls = array_map( function ( $video ) { |
|
| 22 | + $video_urls = array_map(function($video) { |
|
| 23 | 23 | return $video->get_url(); |
| 24 | - }, $videos ); |
|
| 24 | + }, $videos); |
|
| 25 | 25 | |
| 26 | - $videos_data = $this->api_client->get_data( $video_urls ); |
|
| 26 | + $videos_data = $this->api_client->get_data($video_urls); |
|
| 27 | 27 | |
| 28 | - return array_filter( array_map( function ( $video_data ) { |
|
| 28 | + return array_filter(array_map(function($video_data) { |
|
| 29 | 29 | |
| 30 | - if ( ! array_key_exists( 'playlist', $video_data ) |
|
| 30 | + if ( ! array_key_exists('playlist', $video_data) |
|
| 31 | 31 | |
| 32 | - || ! is_array( $video_data['playlist'] ) |
|
| 32 | + || ! is_array($video_data['playlist']) |
|
| 33 | 33 | |
| 34 | - || count( $video_data['playlist'] ) === 0 ) { |
|
| 34 | + || count($video_data['playlist']) === 0) { |
|
| 35 | 35 | |
| 36 | 36 | return false; |
| 37 | 37 | |
@@ -42,31 +42,31 @@ discard block |
||
| 42 | 42 | $playlist_item_data = $video_data['playlist'][0]; |
| 43 | 43 | $video->name = $playlist_item_data['title']; |
| 44 | 44 | $video->description = $playlist_item_data['description']; |
| 45 | - $video->thumbnail_urls = array_filter( array_map( function ( $item ) { |
|
| 45 | + $video->thumbnail_urls = array_filter(array_map(function($item) { |
|
| 46 | 46 | return $item['src']; |
| 47 | - }, $playlist_item_data['images'] ) ); |
|
| 47 | + }, $playlist_item_data['images'])); |
|
| 48 | 48 | |
| 49 | - $video->duration = "PT" . (int) $playlist_item_data['duration'] . "S"; |
|
| 50 | - $video->upload_date = date( 'c', (int) $playlist_item_data['pubdate'] ); |
|
| 49 | + $video->duration = "PT".(int) $playlist_item_data['duration']."S"; |
|
| 50 | + $video->upload_date = date('c', (int) $playlist_item_data['pubdate']); |
|
| 51 | 51 | |
| 52 | - $video_content_urls_data = array_filter( $playlist_item_data['sources'], function ( $item ) { |
|
| 53 | - return strpos( $item['type'], 'video/' ) !== false; |
|
| 52 | + $video_content_urls_data = array_filter($playlist_item_data['sources'], function($item) { |
|
| 53 | + return strpos($item['type'], 'video/') !== false; |
|
| 54 | 54 | } ); |
| 55 | 55 | |
| 56 | - $video_content_urls = array_map( function ( $item ) { |
|
| 56 | + $video_content_urls = array_map(function($item) { |
|
| 57 | 57 | return $item['file']; |
| 58 | - }, $video_content_urls_data ); |
|
| 58 | + }, $video_content_urls_data); |
|
| 59 | 59 | |
| 60 | 60 | // Content url is a single field, so we pick the video with |
| 61 | 61 | // high resolution. |
| 62 | - $video->content_url = array_pop( $video_content_urls ); |
|
| 62 | + $video->content_url = array_pop($video_content_urls); |
|
| 63 | 63 | |
| 64 | 64 | // We dont have embed url for JW Player. |
| 65 | 65 | $video->embed_url = ''; |
| 66 | 66 | |
| 67 | 67 | return $video; |
| 68 | 68 | |
| 69 | - }, $videos_data ) ); |
|
| 69 | + }, $videos_data)); |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -10,23 +10,23 @@ |
||
| 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 | 19 | |
| 20 | - public static function get_provider( $provider_name ) { |
|
| 21 | - if ( self::YOUTUBE === $provider_name ) { |
|
| 22 | - return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) ); |
|
| 23 | - } else if ( self::VIMEO === $provider_name ) { |
|
| 24 | - return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) ); |
|
| 25 | - } |
|
| 26 | - else if ( self::JWPLAYER === $provider_name ) { |
|
| 27 | - return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) ); |
|
| 28 | - } |
|
| 20 | + public static function get_provider( $provider_name ) { |
|
| 21 | + if ( self::YOUTUBE === $provider_name ) { |
|
| 22 | + return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) ); |
|
| 23 | + } else if ( self::VIMEO === $provider_name ) { |
|
| 24 | + return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) ); |
|
| 25 | + } |
|
| 26 | + else if ( self::JWPLAYER === $provider_name ) { |
|
| 27 | + return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) ); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -17,14 +17,14 @@ |
||
| 17 | 17 | const JWPLAYER = 'jwplayer'; |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public static function get_provider( $provider_name ) { |
|
| 21 | - if ( self::YOUTUBE === $provider_name ) { |
|
| 22 | - return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) ); |
|
| 23 | - } else if ( self::VIMEO === $provider_name ) { |
|
| 24 | - return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) ); |
|
| 20 | + public static function get_provider($provider_name) { |
|
| 21 | + if (self::YOUTUBE === $provider_name) { |
|
| 22 | + return new Youtube(Client_Factory::get_client(Client_Factory::YOUTUBE)); |
|
| 23 | + } else if (self::VIMEO === $provider_name) { |
|
| 24 | + return new Vimeo(Client_Factory::get_client(Client_Factory::VIMEO)); |
|
| 25 | 25 | } |
| 26 | - else if ( self::JWPLAYER === $provider_name ) { |
|
| 27 | - return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) ); |
|
| 26 | + else if (self::JWPLAYER === $provider_name) { |
|
| 27 | + return new Jw_Player(Client_Factory::get_client(Client_Factory::JWPLAYER)); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | } |
@@ -22,8 +22,7 @@ |
||
| 22 | 22 | return new Youtube( Client_Factory::get_client( Client_Factory::YOUTUBE ) ); |
| 23 | 23 | } else if ( self::VIMEO === $provider_name ) { |
| 24 | 24 | return new Vimeo( Client_Factory::get_client( Client_Factory::VIMEO ) ); |
| 25 | - } |
|
| 26 | - else if ( self::JWPLAYER === $provider_name ) { |
|
| 25 | + } else if ( self::JWPLAYER === $provider_name ) { |
|
| 27 | 26 | return new Jw_Player( Client_Factory::get_client( Client_Factory::JWPLAYER ) ); |
| 28 | 27 | } |
| 29 | 28 | |