@@ -7,45 +7,45 @@ |
||
7 | 7 | |
8 | 8 | class Classic_Editor_Parser implements Parser { |
9 | 9 | |
10 | - public function get_videos( $post_id ) { |
|
11 | - |
|
12 | - $post = get_post( $post_id ); |
|
13 | - |
|
14 | - $content = $post->post_content; |
|
15 | - |
|
16 | - $line_matches = array(); |
|
17 | - $paragraph_matches = array(); |
|
18 | - |
|
19 | - /** |
|
20 | - * This replicates the wp autoembed function, instead of replacing we capture |
|
21 | - * all the urls. |
|
22 | - */ |
|
23 | - if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) { |
|
24 | - // Find URLs on their own line. |
|
25 | - preg_match_all( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', $content, $line_matches, PREG_SET_ORDER ); |
|
26 | - // Find URLs in their own paragraph. |
|
27 | - preg_match_all( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', $content, $paragraph_matches, PREG_SET_ORDER ); |
|
28 | - } |
|
29 | - |
|
30 | - $regex_matches = array_merge( $line_matches, $paragraph_matches ); |
|
31 | - $matches = array_map( array( $this, 'get_url_from_match' ), $regex_matches ); |
|
32 | - |
|
33 | - $matches = array_values( array_unique( array_filter( $matches ) ) ); |
|
34 | - |
|
35 | - return array_map( array( $this, 'url_to_embedded_video_object' ), $matches ); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param $url |
|
40 | - * |
|
41 | - * @return Embedded_Video |
|
42 | - */ |
|
43 | - private static function url_to_embedded_video_object( $url ) { |
|
44 | - return Embedded_Video_Factory::get_embedded_video( trim( $url ) ); |
|
45 | - } |
|
46 | - |
|
47 | - public static function get_url_from_match( $match ) { |
|
48 | - return array_key_exists( 0, $match ) ? $match[0] : false; |
|
49 | - } |
|
10 | + public function get_videos( $post_id ) { |
|
11 | + |
|
12 | + $post = get_post( $post_id ); |
|
13 | + |
|
14 | + $content = $post->post_content; |
|
15 | + |
|
16 | + $line_matches = array(); |
|
17 | + $paragraph_matches = array(); |
|
18 | + |
|
19 | + /** |
|
20 | + * This replicates the wp autoembed function, instead of replacing we capture |
|
21 | + * all the urls. |
|
22 | + */ |
|
23 | + if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) { |
|
24 | + // Find URLs on their own line. |
|
25 | + preg_match_all( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', $content, $line_matches, PREG_SET_ORDER ); |
|
26 | + // Find URLs in their own paragraph. |
|
27 | + preg_match_all( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', $content, $paragraph_matches, PREG_SET_ORDER ); |
|
28 | + } |
|
29 | + |
|
30 | + $regex_matches = array_merge( $line_matches, $paragraph_matches ); |
|
31 | + $matches = array_map( array( $this, 'get_url_from_match' ), $regex_matches ); |
|
32 | + |
|
33 | + $matches = array_values( array_unique( array_filter( $matches ) ) ); |
|
34 | + |
|
35 | + return array_map( array( $this, 'url_to_embedded_video_object' ), $matches ); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param $url |
|
40 | + * |
|
41 | + * @return Embedded_Video |
|
42 | + */ |
|
43 | + private static function url_to_embedded_video_object( $url ) { |
|
44 | + return Embedded_Video_Factory::get_embedded_video( trim( $url ) ); |
|
45 | + } |
|
46 | + |
|
47 | + public static function get_url_from_match( $match ) { |
|
48 | + return array_key_exists( 0, $match ) ? $match[0] : false; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -7,9 +7,9 @@ discard block |
||
7 | 7 | |
8 | 8 | class Classic_Editor_Parser implements Parser { |
9 | 9 | |
10 | - public function get_videos( $post_id ) { |
|
10 | + public function get_videos($post_id) { |
|
11 | 11 | |
12 | - $post = get_post( $post_id ); |
|
12 | + $post = get_post($post_id); |
|
13 | 13 | |
14 | 14 | $content = $post->post_content; |
15 | 15 | |
@@ -20,19 +20,19 @@ discard block |
||
20 | 20 | * This replicates the wp autoembed function, instead of replacing we capture |
21 | 21 | * all the urls. |
22 | 22 | */ |
23 | - if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) { |
|
23 | + if (preg_match('#(^|\s|>)https?://#i', $content)) { |
|
24 | 24 | // Find URLs on their own line. |
25 | - preg_match_all( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', $content, $line_matches, PREG_SET_ORDER ); |
|
25 | + preg_match_all('|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', $content, $line_matches, PREG_SET_ORDER); |
|
26 | 26 | // Find URLs in their own paragraph. |
27 | - preg_match_all( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', $content, $paragraph_matches, PREG_SET_ORDER ); |
|
27 | + preg_match_all('|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', $content, $paragraph_matches, PREG_SET_ORDER); |
|
28 | 28 | } |
29 | 29 | |
30 | - $regex_matches = array_merge( $line_matches, $paragraph_matches ); |
|
31 | - $matches = array_map( array( $this, 'get_url_from_match' ), $regex_matches ); |
|
30 | + $regex_matches = array_merge($line_matches, $paragraph_matches); |
|
31 | + $matches = array_map(array($this, 'get_url_from_match'), $regex_matches); |
|
32 | 32 | |
33 | - $matches = array_values( array_unique( array_filter( $matches ) ) ); |
|
33 | + $matches = array_values(array_unique(array_filter($matches))); |
|
34 | 34 | |
35 | - return array_map( array( $this, 'url_to_embedded_video_object' ), $matches ); |
|
35 | + return array_map(array($this, 'url_to_embedded_video_object'), $matches); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return Embedded_Video |
42 | 42 | */ |
43 | - private static function url_to_embedded_video_object( $url ) { |
|
44 | - return Embedded_Video_Factory::get_embedded_video( trim( $url ) ); |
|
43 | + private static function url_to_embedded_video_object($url) { |
|
44 | + return Embedded_Video_Factory::get_embedded_video(trim($url)); |
|
45 | 45 | } |
46 | 46 | |
47 | - public static function get_url_from_match( $match ) { |
|
48 | - return array_key_exists( 0, $match ) ? $match[0] : false; |
|
47 | + public static function get_url_from_match($match) { |
|
48 | + return array_key_exists(0, $match) ? $match[0] : false; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | } |
@@ -8,8 +8,8 @@ |
||
8 | 8 | */ |
9 | 9 | class Embedded_Video_Factory { |
10 | 10 | |
11 | - public static function get_embedded_video( $video_url ) { |
|
12 | - return new Default_Embedded_Video( $video_url ); |
|
13 | - } |
|
11 | + public static function get_embedded_video( $video_url ) { |
|
12 | + return new Default_Embedded_Video( $video_url ); |
|
13 | + } |
|
14 | 14 | |
15 | 15 | } |
@@ -8,8 +8,8 @@ |
||
8 | 8 | */ |
9 | 9 | class Embedded_Video_Factory { |
10 | 10 | |
11 | - public static function get_embedded_video( $video_url ) { |
|
12 | - return new Default_Embedded_Video( $video_url ); |
|
11 | + public static function get_embedded_video($video_url) { |
|
12 | + return new Default_Embedded_Video($video_url); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | } |
@@ -12,8 +12,8 @@ |
||
12 | 12 | */ |
13 | 13 | interface Embedded_Video { |
14 | 14 | |
15 | - public function get_api_provider(); |
|
15 | + public function get_api_provider(); |
|
16 | 16 | |
17 | - public function get_url(); |
|
17 | + public function get_url(); |
|
18 | 18 | |
19 | 19 | } |
@@ -10,8 +10,8 @@ |
||
10 | 10 | |
11 | 11 | class Video_Storage_Factory { |
12 | 12 | |
13 | - public static function get_storage() { |
|
14 | - return new Meta_Storage(); |
|
15 | - } |
|
13 | + public static function get_storage() { |
|
14 | + return new Meta_Storage(); |
|
15 | + } |
|
16 | 16 | |
17 | 17 | } |
@@ -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 | } |
@@ -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 | } |
@@ -8,57 +8,57 @@ |
||
8 | 8 | |
9 | 9 | class Meta_Storage implements Storage { |
10 | 10 | |
11 | - const META_KEY = '_wl_video_object_videos'; |
|
11 | + const META_KEY = '_wl_video_object_videos'; |
|
12 | 12 | |
13 | - public function add_video( $post_id, $video ) { |
|
14 | - /** |
|
15 | - * @since 3.31.0 |
|
16 | - * Fires when the video storage gets updated |
|
17 | - */ |
|
18 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
19 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
20 | - } |
|
13 | + public function add_video( $post_id, $video ) { |
|
14 | + /** |
|
15 | + * @since 3.31.0 |
|
16 | + * Fires when the video storage gets updated |
|
17 | + */ |
|
18 | + do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
19 | + add_post_meta( $post_id, self::META_KEY, $video ); |
|
20 | + } |
|
21 | 21 | |
22 | - public function get_all_videos( $post_id ) { |
|
22 | + public function get_all_videos( $post_id ) { |
|
23 | 23 | |
24 | - return get_post_meta( $post_id, self::META_KEY ); |
|
24 | + return get_post_meta( $post_id, self::META_KEY ); |
|
25 | 25 | |
26 | - } |
|
26 | + } |
|
27 | 27 | |
28 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
29 | - /** |
|
30 | - * @since 3.31.0 |
|
31 | - * Fires when the video storage gets updated |
|
32 | - */ |
|
33 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
34 | - $videos_to_be_removed_ids = array_map( |
|
35 | - function ( $video ) { |
|
36 | - return $video->id; |
|
37 | - }, |
|
38 | - $videos_to_be_removed |
|
39 | - ); |
|
28 | + public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
29 | + /** |
|
30 | + * @since 3.31.0 |
|
31 | + * Fires when the video storage gets updated |
|
32 | + */ |
|
33 | + do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
34 | + $videos_to_be_removed_ids = array_map( |
|
35 | + function ( $video ) { |
|
36 | + return $video->id; |
|
37 | + }, |
|
38 | + $videos_to_be_removed |
|
39 | + ); |
|
40 | 40 | |
41 | - $present_videos = $this->get_all_videos( $post_id ); |
|
41 | + $present_videos = $this->get_all_videos( $post_id ); |
|
42 | 42 | |
43 | - $filtered_videos = array_filter( |
|
44 | - $present_videos, |
|
45 | - function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
46 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
|
47 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
48 | - } |
|
49 | - ); |
|
43 | + $filtered_videos = array_filter( |
|
44 | + $present_videos, |
|
45 | + function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
46 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
|
47 | + return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
48 | + } |
|
49 | + ); |
|
50 | 50 | |
51 | - // Remove all existing videos. |
|
52 | - $this->remove_all_videos( $post_id ); |
|
51 | + // Remove all existing videos. |
|
52 | + $this->remove_all_videos( $post_id ); |
|
53 | 53 | |
54 | - // Save the remaining videos. |
|
55 | - foreach ( $filtered_videos as $video ) { |
|
56 | - $this->add_video( $post_id, $video ); |
|
57 | - } |
|
54 | + // Save the remaining videos. |
|
55 | + foreach ( $filtered_videos as $video ) { |
|
56 | + $this->add_video( $post_id, $video ); |
|
57 | + } |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - public function remove_all_videos( $post_id ) { |
|
62 | - delete_post_meta( $post_id, self::META_KEY ); |
|
63 | - } |
|
61 | + public function remove_all_videos( $post_id ) { |
|
62 | + delete_post_meta( $post_id, self::META_KEY ); |
|
63 | + } |
|
64 | 64 | } |
@@ -10,55 +10,55 @@ |
||
10 | 10 | |
11 | 11 | const META_KEY = '_wl_video_object_videos'; |
12 | 12 | |
13 | - public function add_video( $post_id, $video ) { |
|
13 | + public function add_video($post_id, $video) { |
|
14 | 14 | /** |
15 | 15 | * @since 3.31.0 |
16 | 16 | * Fires when the video storage gets updated |
17 | 17 | */ |
18 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
19 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
18 | + do_action('wordlift_videoobject_video_storage_updated'); |
|
19 | + add_post_meta($post_id, self::META_KEY, $video); |
|
20 | 20 | } |
21 | 21 | |
22 | - public function get_all_videos( $post_id ) { |
|
22 | + public function get_all_videos($post_id) { |
|
23 | 23 | |
24 | - return get_post_meta( $post_id, self::META_KEY ); |
|
24 | + return get_post_meta($post_id, self::META_KEY); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
28 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
28 | + public function remove_videos($videos_to_be_removed, $post_id) { |
|
29 | 29 | /** |
30 | 30 | * @since 3.31.0 |
31 | 31 | * Fires when the video storage gets updated |
32 | 32 | */ |
33 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
33 | + do_action('wordlift_videoobject_video_storage_updated'); |
|
34 | 34 | $videos_to_be_removed_ids = array_map( |
35 | - function ( $video ) { |
|
35 | + function($video) { |
|
36 | 36 | return $video->id; |
37 | 37 | }, |
38 | 38 | $videos_to_be_removed |
39 | 39 | ); |
40 | 40 | |
41 | - $present_videos = $this->get_all_videos( $post_id ); |
|
41 | + $present_videos = $this->get_all_videos($post_id); |
|
42 | 42 | |
43 | 43 | $filtered_videos = array_filter( |
44 | 44 | $present_videos, |
45 | - function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
45 | + function($video) use ($videos_to_be_removed_ids) { |
|
46 | 46 | // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
47 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
47 | + return ! in_array($video->id, $videos_to_be_removed_ids); |
|
48 | 48 | } |
49 | 49 | ); |
50 | 50 | |
51 | 51 | // Remove all existing videos. |
52 | - $this->remove_all_videos( $post_id ); |
|
52 | + $this->remove_all_videos($post_id); |
|
53 | 53 | |
54 | 54 | // Save the remaining videos. |
55 | - foreach ( $filtered_videos as $video ) { |
|
56 | - $this->add_video( $post_id, $video ); |
|
55 | + foreach ($filtered_videos as $video) { |
|
56 | + $this->add_video($post_id, $video); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | - public function remove_all_videos( $post_id ) { |
|
62 | - delete_post_meta( $post_id, self::META_KEY ); |
|
61 | + public function remove_all_videos($post_id) { |
|
62 | + delete_post_meta($post_id, self::META_KEY); |
|
63 | 63 | } |
64 | 64 | } |
@@ -12,111 +12,111 @@ discard block |
||
12 | 12 | |
13 | 13 | class Xml_Generator { |
14 | 14 | |
15 | - private static function iso8601_to_seconds( $iso8601_interval_string ) { |
|
16 | - try { |
|
17 | - $interval = new \DateInterval( $iso8601_interval_string ); |
|
18 | - } catch ( \Exception $e ) { |
|
19 | - return 0; |
|
20 | - } |
|
21 | - |
|
22 | - $days_to_seconds = $interval->d * 60 * 60 * 24; |
|
23 | - $hours_to_seconds = $interval->h * 60 * 60; |
|
24 | - $minutes_to_seconds = $interval->i * 60; |
|
25 | - $seconds = $interval->s; |
|
26 | - |
|
27 | - return $days_to_seconds + $hours_to_seconds + $minutes_to_seconds + $seconds; |
|
28 | - |
|
29 | - } |
|
30 | - |
|
31 | - public static function get_xml_for_all_posts_with_videos() { |
|
32 | - /** |
|
33 | - * @since 3.31.6 |
|
34 | - * Filter the query args, add support for all custom public post types. |
|
35 | - */ |
|
36 | - $video_sitemap_query_args = apply_filters( |
|
37 | - 'wl_videoobject_sitemap_query_args', |
|
38 | - array( |
|
39 | - 'fields' => 'ids', |
|
40 | - 'numberposts' => - 1, |
|
41 | - 'post_type' => get_post_types( array( 'public' => true ) ), |
|
42 | - 'meta_query' => array( |
|
43 | - array( |
|
44 | - 'key' => Meta_Storage::META_KEY, |
|
45 | - 'compare' => 'EXISTS', |
|
46 | - ), |
|
47 | - ), |
|
48 | - ) |
|
49 | - ); |
|
50 | - |
|
51 | - $posts = get_posts( $video_sitemap_query_args ); |
|
52 | - |
|
53 | - $all_posts_xml = ''; |
|
54 | - |
|
55 | - if ( ! $posts ) { |
|
56 | - return $all_posts_xml; |
|
57 | - } |
|
58 | - |
|
59 | - foreach ( $posts as $post_id ) { |
|
60 | - $all_posts_xml .= self::get_xml_for_single_post( $post_id ); |
|
61 | - } |
|
62 | - |
|
63 | - return $all_posts_xml; |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @param $post_id |
|
69 | - * |
|
70 | - * @return string XML string for single post. |
|
71 | - */ |
|
72 | - public static function get_xml_for_single_post( $post_id ) { |
|
73 | - $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id ); |
|
74 | - if ( ! $videos ) { |
|
75 | - return ''; |
|
76 | - } |
|
77 | - $single_post_xml = ''; |
|
78 | - foreach ( $videos as $video ) { |
|
79 | - $single_post_xml .= self::get_xml_for_single_video( $video, $post_id ); |
|
80 | - } |
|
81 | - |
|
82 | - return $single_post_xml; |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param $video Video |
|
88 | - * @param $post_id int |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function get_xml_for_single_video( $video, $post_id ) { |
|
93 | - |
|
94 | - $permalink = get_permalink( $post_id ); |
|
95 | - $title = esc_html( $video->name ); |
|
96 | - $description = esc_html( $video->description ); |
|
97 | - $thumbnail_url = $video->thumbnail_urls[0]; |
|
98 | - |
|
99 | - // If description is empty use title. |
|
100 | - if ( ! $description ) { |
|
101 | - $description = $title; |
|
102 | - } |
|
103 | - |
|
104 | - $optional_fields = array( |
|
105 | - 'content_loc' => $video->content_url, |
|
106 | - 'player_loc' => $video->embed_url, |
|
107 | - 'duration' => self::iso8601_to_seconds( $video->duration ), |
|
108 | - 'view_count' => $video->views, |
|
109 | - 'live' => $video->is_live_video ? 'yes' : 'no', |
|
110 | - ); |
|
111 | - |
|
112 | - $optional_data = ''; |
|
113 | - foreach ( $optional_fields as $xml_key => $xml_value ) { |
|
114 | - if ( $xml_value ) { |
|
115 | - $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>"; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return " |
|
15 | + private static function iso8601_to_seconds( $iso8601_interval_string ) { |
|
16 | + try { |
|
17 | + $interval = new \DateInterval( $iso8601_interval_string ); |
|
18 | + } catch ( \Exception $e ) { |
|
19 | + return 0; |
|
20 | + } |
|
21 | + |
|
22 | + $days_to_seconds = $interval->d * 60 * 60 * 24; |
|
23 | + $hours_to_seconds = $interval->h * 60 * 60; |
|
24 | + $minutes_to_seconds = $interval->i * 60; |
|
25 | + $seconds = $interval->s; |
|
26 | + |
|
27 | + return $days_to_seconds + $hours_to_seconds + $minutes_to_seconds + $seconds; |
|
28 | + |
|
29 | + } |
|
30 | + |
|
31 | + public static function get_xml_for_all_posts_with_videos() { |
|
32 | + /** |
|
33 | + * @since 3.31.6 |
|
34 | + * Filter the query args, add support for all custom public post types. |
|
35 | + */ |
|
36 | + $video_sitemap_query_args = apply_filters( |
|
37 | + 'wl_videoobject_sitemap_query_args', |
|
38 | + array( |
|
39 | + 'fields' => 'ids', |
|
40 | + 'numberposts' => - 1, |
|
41 | + 'post_type' => get_post_types( array( 'public' => true ) ), |
|
42 | + 'meta_query' => array( |
|
43 | + array( |
|
44 | + 'key' => Meta_Storage::META_KEY, |
|
45 | + 'compare' => 'EXISTS', |
|
46 | + ), |
|
47 | + ), |
|
48 | + ) |
|
49 | + ); |
|
50 | + |
|
51 | + $posts = get_posts( $video_sitemap_query_args ); |
|
52 | + |
|
53 | + $all_posts_xml = ''; |
|
54 | + |
|
55 | + if ( ! $posts ) { |
|
56 | + return $all_posts_xml; |
|
57 | + } |
|
58 | + |
|
59 | + foreach ( $posts as $post_id ) { |
|
60 | + $all_posts_xml .= self::get_xml_for_single_post( $post_id ); |
|
61 | + } |
|
62 | + |
|
63 | + return $all_posts_xml; |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @param $post_id |
|
69 | + * |
|
70 | + * @return string XML string for single post. |
|
71 | + */ |
|
72 | + public static function get_xml_for_single_post( $post_id ) { |
|
73 | + $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id ); |
|
74 | + if ( ! $videos ) { |
|
75 | + return ''; |
|
76 | + } |
|
77 | + $single_post_xml = ''; |
|
78 | + foreach ( $videos as $video ) { |
|
79 | + $single_post_xml .= self::get_xml_for_single_video( $video, $post_id ); |
|
80 | + } |
|
81 | + |
|
82 | + return $single_post_xml; |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param $video Video |
|
88 | + * @param $post_id int |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function get_xml_for_single_video( $video, $post_id ) { |
|
93 | + |
|
94 | + $permalink = get_permalink( $post_id ); |
|
95 | + $title = esc_html( $video->name ); |
|
96 | + $description = esc_html( $video->description ); |
|
97 | + $thumbnail_url = $video->thumbnail_urls[0]; |
|
98 | + |
|
99 | + // If description is empty use title. |
|
100 | + if ( ! $description ) { |
|
101 | + $description = $title; |
|
102 | + } |
|
103 | + |
|
104 | + $optional_fields = array( |
|
105 | + 'content_loc' => $video->content_url, |
|
106 | + 'player_loc' => $video->embed_url, |
|
107 | + 'duration' => self::iso8601_to_seconds( $video->duration ), |
|
108 | + 'view_count' => $video->views, |
|
109 | + 'live' => $video->is_live_video ? 'yes' : 'no', |
|
110 | + ); |
|
111 | + |
|
112 | + $optional_data = ''; |
|
113 | + foreach ( $optional_fields as $xml_key => $xml_value ) { |
|
114 | + if ( $xml_value ) { |
|
115 | + $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>"; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return " |
|
120 | 120 | <url> |
121 | 121 | <loc>${permalink}</loc> |
122 | 122 | <video:video> |
@@ -128,6 +128,6 @@ discard block |
||
128 | 128 | </url> |
129 | 129 | "; |
130 | 130 | |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | |
13 | 13 | class Xml_Generator { |
14 | 14 | |
15 | - private static function iso8601_to_seconds( $iso8601_interval_string ) { |
|
15 | + private static function iso8601_to_seconds($iso8601_interval_string) { |
|
16 | 16 | try { |
17 | - $interval = new \DateInterval( $iso8601_interval_string ); |
|
18 | - } catch ( \Exception $e ) { |
|
17 | + $interval = new \DateInterval($iso8601_interval_string); |
|
18 | + } catch (\Exception $e) { |
|
19 | 19 | return 0; |
20 | 20 | } |
21 | 21 | |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | 'wl_videoobject_sitemap_query_args', |
38 | 38 | array( |
39 | 39 | 'fields' => 'ids', |
40 | - 'numberposts' => - 1, |
|
41 | - 'post_type' => get_post_types( array( 'public' => true ) ), |
|
40 | + 'numberposts' => -1, |
|
41 | + 'post_type' => get_post_types(array('public' => true)), |
|
42 | 42 | 'meta_query' => array( |
43 | 43 | array( |
44 | 44 | 'key' => Meta_Storage::META_KEY, |
@@ -48,16 +48,16 @@ discard block |
||
48 | 48 | ) |
49 | 49 | ); |
50 | 50 | |
51 | - $posts = get_posts( $video_sitemap_query_args ); |
|
51 | + $posts = get_posts($video_sitemap_query_args); |
|
52 | 52 | |
53 | 53 | $all_posts_xml = ''; |
54 | 54 | |
55 | - if ( ! $posts ) { |
|
55 | + if ( ! $posts) { |
|
56 | 56 | return $all_posts_xml; |
57 | 57 | } |
58 | 58 | |
59 | - foreach ( $posts as $post_id ) { |
|
60 | - $all_posts_xml .= self::get_xml_for_single_post( $post_id ); |
|
59 | + foreach ($posts as $post_id) { |
|
60 | + $all_posts_xml .= self::get_xml_for_single_post($post_id); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | return $all_posts_xml; |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return string XML string for single post. |
71 | 71 | */ |
72 | - public static function get_xml_for_single_post( $post_id ) { |
|
73 | - $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id ); |
|
74 | - if ( ! $videos ) { |
|
72 | + public static function get_xml_for_single_post($post_id) { |
|
73 | + $videos = Video_Storage_Factory::get_storage()->get_all_videos($post_id); |
|
74 | + if ( ! $videos) { |
|
75 | 75 | return ''; |
76 | 76 | } |
77 | 77 | $single_post_xml = ''; |
78 | - foreach ( $videos as $video ) { |
|
79 | - $single_post_xml .= self::get_xml_for_single_video( $video, $post_id ); |
|
78 | + foreach ($videos as $video) { |
|
79 | + $single_post_xml .= self::get_xml_for_single_video($video, $post_id); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return $single_post_xml; |
@@ -89,29 +89,29 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - public static function get_xml_for_single_video( $video, $post_id ) { |
|
92 | + public static function get_xml_for_single_video($video, $post_id) { |
|
93 | 93 | |
94 | - $permalink = get_permalink( $post_id ); |
|
95 | - $title = esc_html( $video->name ); |
|
96 | - $description = esc_html( $video->description ); |
|
94 | + $permalink = get_permalink($post_id); |
|
95 | + $title = esc_html($video->name); |
|
96 | + $description = esc_html($video->description); |
|
97 | 97 | $thumbnail_url = $video->thumbnail_urls[0]; |
98 | 98 | |
99 | 99 | // If description is empty use title. |
100 | - if ( ! $description ) { |
|
100 | + if ( ! $description) { |
|
101 | 101 | $description = $title; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $optional_fields = array( |
105 | 105 | 'content_loc' => $video->content_url, |
106 | 106 | 'player_loc' => $video->embed_url, |
107 | - 'duration' => self::iso8601_to_seconds( $video->duration ), |
|
107 | + 'duration' => self::iso8601_to_seconds($video->duration), |
|
108 | 108 | 'view_count' => $video->views, |
109 | 109 | 'live' => $video->is_live_video ? 'yes' : 'no', |
110 | 110 | ); |
111 | 111 | |
112 | 112 | $optional_data = ''; |
113 | - foreach ( $optional_fields as $xml_key => $xml_value ) { |
|
114 | - if ( $xml_value ) { |
|
113 | + foreach ($optional_fields as $xml_key => $xml_value) { |
|
114 | + if ($xml_value) { |
|
115 | 115 | $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>"; |
116 | 116 | } |
117 | 117 | } |
@@ -12,249 +12,249 @@ |
||
12 | 12 | |
13 | 13 | class Video_Processor { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array<Client> |
|
17 | - */ |
|
18 | - private $api_clients; |
|
19 | - |
|
20 | - public function __construct() { |
|
21 | - $this->api_clients = array( |
|
22 | - Client_Factory::get_client( Client_Factory::YOUTUBE ), |
|
23 | - Client_Factory::get_client( Client_Factory::VIMEO ), |
|
24 | - Client_Factory::get_client( Client_Factory::JWPLAYER ), |
|
25 | - ); |
|
26 | - } |
|
27 | - |
|
28 | - private function get_data_for_videos( $embedded_videos ) { |
|
29 | - |
|
30 | - $youtube_videos = $this->get_youtube_videos( $embedded_videos ); |
|
31 | - $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE ); |
|
32 | - $youtube_videos = $youtube_provider->get_videos_data( $youtube_videos ); |
|
33 | - |
|
34 | - $vimeo_videos = $this->get_vimeo_videos( $embedded_videos ); |
|
35 | - $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO ); |
|
36 | - $vimeo_videos = $vimeo_provider->get_videos_data( $vimeo_videos ); |
|
37 | - |
|
38 | - $jwplayer_videos = $this->get_jw_player_videos( $embedded_videos ); |
|
39 | - $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER ); |
|
40 | - $jwplayer_videos = $jwplayer_provider->get_videos_data( $jwplayer_videos ); |
|
41 | - |
|
42 | - return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos ); |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - private function get_video_ids( $video_urls ) { |
|
47 | - $clients = $this->api_clients; |
|
48 | - $video_ids = array(); |
|
49 | - foreach ( $clients as $client ) { |
|
50 | - $ids = $client->get_video_ids( $video_urls ); |
|
51 | - if ( $ids ) { |
|
52 | - $video_ids = array_merge( $video_ids, $ids ); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - return array_unique( $video_ids ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param $storage Storage |
|
61 | - * @param $post_id int |
|
62 | - * @param $embedded_videos array<Embedded_Video> |
|
63 | - */ |
|
64 | - private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) { |
|
65 | - |
|
66 | - $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos ); |
|
67 | - $storage->remove_videos( $videos_to_be_deleted, $post_id ); |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param Storage $storage |
|
73 | - * @param $post_id |
|
74 | - * @param array $embedded_videos |
|
75 | - * |
|
76 | - * @return array An array of videos which exist on storage, not on post content. |
|
77 | - */ |
|
78 | - private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) { |
|
79 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
80 | - $embedded_video_urls = array_map( |
|
81 | - function ( $embedded_video ) { |
|
82 | - /** |
|
83 | - * @var $embedded_video Embedded_Video |
|
84 | - */ |
|
85 | - return $embedded_video->get_url(); |
|
86 | - }, |
|
87 | - $embedded_videos |
|
88 | - ); |
|
89 | - |
|
90 | - /** |
|
91 | - * Previously we are checking if the captured url is content_url to delete it from the storage |
|
92 | - * but this might not work well if we want to support multiple URL formats, we extract the video |
|
93 | - * ids for embedded URLs. |
|
94 | - */ |
|
95 | - $embedded_video_ids = $this->get_video_ids( $embedded_video_urls ); |
|
96 | - |
|
97 | - $that = $this; |
|
98 | - |
|
99 | - return array_filter( |
|
100 | - $videos_in_store, |
|
101 | - function ( $video ) use ( $embedded_video_ids, $that ) { |
|
102 | - /** |
|
103 | - * If the video id doesn't exist on the content then we need to return it |
|
104 | - * in order to delete that video. |
|
105 | - */ |
|
106 | - return count( |
|
107 | - array_intersect( |
|
108 | - $that->get_video_ids( array( $video->id ) ), |
|
109 | - $embedded_video_ids |
|
110 | - ) |
|
111 | - ) === 0; |
|
112 | - |
|
113 | - } |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param \WP_Post $post |
|
119 | - * @param $post_id |
|
120 | - */ |
|
121 | - public function process_video_urls( \WP_Post $post, $post_id ) { |
|
122 | - |
|
123 | - $parser = Parser_Factory::get_parser_from_content( $post->post_content ); |
|
124 | - |
|
125 | - $embedded_videos = $parser->get_videos( $post_id ); |
|
126 | - /** |
|
127 | - * Filters the embedded videos on post contet, custom plugins can add their video urls |
|
128 | - * by constructing \Default_Embedded_Video or implement Embedded_Video class |
|
129 | - * |
|
130 | - * @param $embedded_videos array<Embedded_Video> |
|
131 | - * @param $post_id int The post id for the videoobject is processed. |
|
132 | - * |
|
133 | - * @return array<Embedded_Video> |
|
134 | - * @since 3.31.4 |
|
135 | - * Filter name : wl_videoobject_embedded_videos |
|
136 | - */ |
|
137 | - $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id ); |
|
138 | - |
|
139 | - $storage = Video_Storage_Factory::get_storage(); |
|
140 | - |
|
141 | - // Before sending api requests we need to check if there are any videos in |
|
142 | - // store which is not present on post content, remove them if there are |
|
143 | - // any |
|
144 | - $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ); |
|
145 | - |
|
146 | - $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos ); |
|
147 | - |
|
148 | - // Return early after removing all the videos. |
|
149 | - if ( ! $embedded_videos ) { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - $videos = $this->get_data_for_videos( $embedded_videos ); |
|
154 | - |
|
155 | - if ( ! $videos ) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - foreach ( $videos as $video ) { |
|
160 | - $storage->add_video( $post_id, $video ); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param $storage Storage |
|
166 | - * @param $post_id int |
|
167 | - * @param $embedded_videos array<Embedded_Video> |
|
168 | - * |
|
169 | - * @return array<Embedded_Video> Return array of embedded videos which are not in store. |
|
170 | - */ |
|
171 | - private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) { |
|
172 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
173 | - $video_urls_in_store = array_map( |
|
174 | - function ( $video ) { |
|
175 | - return $video->id; |
|
176 | - }, |
|
177 | - $videos_in_store |
|
178 | - ); |
|
179 | - |
|
180 | - $video_ids_in_store = $this->get_video_ids( $video_urls_in_store ); |
|
181 | - |
|
182 | - $that = $this; |
|
183 | - |
|
184 | - return array_filter( |
|
185 | - $embedded_videos, |
|
186 | - function ( $embedded_video ) use ( $video_ids_in_store, $that ) { |
|
187 | - /** |
|
188 | - * If the video id exist on content, not on storage then |
|
189 | - * we need to fetch the data. |
|
190 | - */ |
|
191 | - return count( |
|
192 | - array_intersect( |
|
193 | - $that->get_video_ids( array( $embedded_video->get_url() ) ), |
|
194 | - $video_ids_in_store |
|
195 | - ) |
|
196 | - ) === 0; |
|
197 | - } |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param $embedded_videos |
|
203 | - * |
|
204 | - * @return array |
|
205 | - */ |
|
206 | - private function get_youtube_videos( $embedded_videos ) { |
|
207 | - return array_filter( |
|
208 | - $embedded_videos, |
|
209 | - function ( $embedded_video ) { |
|
210 | - /** |
|
211 | - * it should have youtube.com or youtu.be in the url |
|
212 | - * |
|
213 | - * @param $embedded_video Embedded_Video |
|
214 | - */ |
|
215 | - $video_url = $embedded_video->get_url(); |
|
216 | - |
|
217 | - return strpos( $video_url, 'youtube.com' ) !== false || |
|
218 | - strpos( $video_url, 'youtu.be' ) !== false; |
|
219 | - } |
|
220 | - ); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param $embedded_videos |
|
225 | - * |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - private function get_vimeo_videos( $embedded_videos ) { |
|
229 | - return array_filter( |
|
230 | - $embedded_videos, |
|
231 | - function ( $embedded_video ) { |
|
232 | - /** |
|
233 | - * it should have vimeo.com in the url |
|
234 | - * |
|
235 | - * @param $embedded_video Embedded_Video |
|
236 | - */ |
|
237 | - $video_url = $embedded_video->get_url(); |
|
238 | - |
|
239 | - return strpos( $video_url, 'vimeo.com' ) !== false; |
|
240 | - } |
|
241 | - ); |
|
242 | - } |
|
243 | - |
|
244 | - private function get_jw_player_videos( $embedded_videos ) { |
|
245 | - return array_filter( |
|
246 | - $embedded_videos, |
|
247 | - function ( $embedded_video ) { |
|
248 | - /** |
|
249 | - * it should have vimeo.com in the url |
|
250 | - * |
|
251 | - * @param $embedded_video Embedded_Video |
|
252 | - */ |
|
253 | - $video_url = $embedded_video->get_url(); |
|
254 | - |
|
255 | - return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
256 | - } |
|
257 | - ); |
|
258 | - } |
|
15 | + /** |
|
16 | + * @var array<Client> |
|
17 | + */ |
|
18 | + private $api_clients; |
|
19 | + |
|
20 | + public function __construct() { |
|
21 | + $this->api_clients = array( |
|
22 | + Client_Factory::get_client( Client_Factory::YOUTUBE ), |
|
23 | + Client_Factory::get_client( Client_Factory::VIMEO ), |
|
24 | + Client_Factory::get_client( Client_Factory::JWPLAYER ), |
|
25 | + ); |
|
26 | + } |
|
27 | + |
|
28 | + private function get_data_for_videos( $embedded_videos ) { |
|
29 | + |
|
30 | + $youtube_videos = $this->get_youtube_videos( $embedded_videos ); |
|
31 | + $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE ); |
|
32 | + $youtube_videos = $youtube_provider->get_videos_data( $youtube_videos ); |
|
33 | + |
|
34 | + $vimeo_videos = $this->get_vimeo_videos( $embedded_videos ); |
|
35 | + $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO ); |
|
36 | + $vimeo_videos = $vimeo_provider->get_videos_data( $vimeo_videos ); |
|
37 | + |
|
38 | + $jwplayer_videos = $this->get_jw_player_videos( $embedded_videos ); |
|
39 | + $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER ); |
|
40 | + $jwplayer_videos = $jwplayer_provider->get_videos_data( $jwplayer_videos ); |
|
41 | + |
|
42 | + return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos ); |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + private function get_video_ids( $video_urls ) { |
|
47 | + $clients = $this->api_clients; |
|
48 | + $video_ids = array(); |
|
49 | + foreach ( $clients as $client ) { |
|
50 | + $ids = $client->get_video_ids( $video_urls ); |
|
51 | + if ( $ids ) { |
|
52 | + $video_ids = array_merge( $video_ids, $ids ); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + return array_unique( $video_ids ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param $storage Storage |
|
61 | + * @param $post_id int |
|
62 | + * @param $embedded_videos array<Embedded_Video> |
|
63 | + */ |
|
64 | + private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) { |
|
65 | + |
|
66 | + $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos ); |
|
67 | + $storage->remove_videos( $videos_to_be_deleted, $post_id ); |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param Storage $storage |
|
73 | + * @param $post_id |
|
74 | + * @param array $embedded_videos |
|
75 | + * |
|
76 | + * @return array An array of videos which exist on storage, not on post content. |
|
77 | + */ |
|
78 | + private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) { |
|
79 | + $videos_in_store = $storage->get_all_videos( $post_id ); |
|
80 | + $embedded_video_urls = array_map( |
|
81 | + function ( $embedded_video ) { |
|
82 | + /** |
|
83 | + * @var $embedded_video Embedded_Video |
|
84 | + */ |
|
85 | + return $embedded_video->get_url(); |
|
86 | + }, |
|
87 | + $embedded_videos |
|
88 | + ); |
|
89 | + |
|
90 | + /** |
|
91 | + * Previously we are checking if the captured url is content_url to delete it from the storage |
|
92 | + * but this might not work well if we want to support multiple URL formats, we extract the video |
|
93 | + * ids for embedded URLs. |
|
94 | + */ |
|
95 | + $embedded_video_ids = $this->get_video_ids( $embedded_video_urls ); |
|
96 | + |
|
97 | + $that = $this; |
|
98 | + |
|
99 | + return array_filter( |
|
100 | + $videos_in_store, |
|
101 | + function ( $video ) use ( $embedded_video_ids, $that ) { |
|
102 | + /** |
|
103 | + * If the video id doesn't exist on the content then we need to return it |
|
104 | + * in order to delete that video. |
|
105 | + */ |
|
106 | + return count( |
|
107 | + array_intersect( |
|
108 | + $that->get_video_ids( array( $video->id ) ), |
|
109 | + $embedded_video_ids |
|
110 | + ) |
|
111 | + ) === 0; |
|
112 | + |
|
113 | + } |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param \WP_Post $post |
|
119 | + * @param $post_id |
|
120 | + */ |
|
121 | + public function process_video_urls( \WP_Post $post, $post_id ) { |
|
122 | + |
|
123 | + $parser = Parser_Factory::get_parser_from_content( $post->post_content ); |
|
124 | + |
|
125 | + $embedded_videos = $parser->get_videos( $post_id ); |
|
126 | + /** |
|
127 | + * Filters the embedded videos on post contet, custom plugins can add their video urls |
|
128 | + * by constructing \Default_Embedded_Video or implement Embedded_Video class |
|
129 | + * |
|
130 | + * @param $embedded_videos array<Embedded_Video> |
|
131 | + * @param $post_id int The post id for the videoobject is processed. |
|
132 | + * |
|
133 | + * @return array<Embedded_Video> |
|
134 | + * @since 3.31.4 |
|
135 | + * Filter name : wl_videoobject_embedded_videos |
|
136 | + */ |
|
137 | + $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id ); |
|
138 | + |
|
139 | + $storage = Video_Storage_Factory::get_storage(); |
|
140 | + |
|
141 | + // Before sending api requests we need to check if there are any videos in |
|
142 | + // store which is not present on post content, remove them if there are |
|
143 | + // any |
|
144 | + $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ); |
|
145 | + |
|
146 | + $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos ); |
|
147 | + |
|
148 | + // Return early after removing all the videos. |
|
149 | + if ( ! $embedded_videos ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + $videos = $this->get_data_for_videos( $embedded_videos ); |
|
154 | + |
|
155 | + if ( ! $videos ) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + foreach ( $videos as $video ) { |
|
160 | + $storage->add_video( $post_id, $video ); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param $storage Storage |
|
166 | + * @param $post_id int |
|
167 | + * @param $embedded_videos array<Embedded_Video> |
|
168 | + * |
|
169 | + * @return array<Embedded_Video> Return array of embedded videos which are not in store. |
|
170 | + */ |
|
171 | + private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) { |
|
172 | + $videos_in_store = $storage->get_all_videos( $post_id ); |
|
173 | + $video_urls_in_store = array_map( |
|
174 | + function ( $video ) { |
|
175 | + return $video->id; |
|
176 | + }, |
|
177 | + $videos_in_store |
|
178 | + ); |
|
179 | + |
|
180 | + $video_ids_in_store = $this->get_video_ids( $video_urls_in_store ); |
|
181 | + |
|
182 | + $that = $this; |
|
183 | + |
|
184 | + return array_filter( |
|
185 | + $embedded_videos, |
|
186 | + function ( $embedded_video ) use ( $video_ids_in_store, $that ) { |
|
187 | + /** |
|
188 | + * If the video id exist on content, not on storage then |
|
189 | + * we need to fetch the data. |
|
190 | + */ |
|
191 | + return count( |
|
192 | + array_intersect( |
|
193 | + $that->get_video_ids( array( $embedded_video->get_url() ) ), |
|
194 | + $video_ids_in_store |
|
195 | + ) |
|
196 | + ) === 0; |
|
197 | + } |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param $embedded_videos |
|
203 | + * |
|
204 | + * @return array |
|
205 | + */ |
|
206 | + private function get_youtube_videos( $embedded_videos ) { |
|
207 | + return array_filter( |
|
208 | + $embedded_videos, |
|
209 | + function ( $embedded_video ) { |
|
210 | + /** |
|
211 | + * it should have youtube.com or youtu.be in the url |
|
212 | + * |
|
213 | + * @param $embedded_video Embedded_Video |
|
214 | + */ |
|
215 | + $video_url = $embedded_video->get_url(); |
|
216 | + |
|
217 | + return strpos( $video_url, 'youtube.com' ) !== false || |
|
218 | + strpos( $video_url, 'youtu.be' ) !== false; |
|
219 | + } |
|
220 | + ); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param $embedded_videos |
|
225 | + * |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + private function get_vimeo_videos( $embedded_videos ) { |
|
229 | + return array_filter( |
|
230 | + $embedded_videos, |
|
231 | + function ( $embedded_video ) { |
|
232 | + /** |
|
233 | + * it should have vimeo.com in the url |
|
234 | + * |
|
235 | + * @param $embedded_video Embedded_Video |
|
236 | + */ |
|
237 | + $video_url = $embedded_video->get_url(); |
|
238 | + |
|
239 | + return strpos( $video_url, 'vimeo.com' ) !== false; |
|
240 | + } |
|
241 | + ); |
|
242 | + } |
|
243 | + |
|
244 | + private function get_jw_player_videos( $embedded_videos ) { |
|
245 | + return array_filter( |
|
246 | + $embedded_videos, |
|
247 | + function ( $embedded_video ) { |
|
248 | + /** |
|
249 | + * it should have vimeo.com in the url |
|
250 | + * |
|
251 | + * @param $embedded_video Embedded_Video |
|
252 | + */ |
|
253 | + $video_url = $embedded_video->get_url(); |
|
254 | + |
|
255 | + return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
256 | + } |
|
257 | + ); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | } |
@@ -19,41 +19,41 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct() { |
21 | 21 | $this->api_clients = array( |
22 | - Client_Factory::get_client( Client_Factory::YOUTUBE ), |
|
23 | - Client_Factory::get_client( Client_Factory::VIMEO ), |
|
24 | - Client_Factory::get_client( Client_Factory::JWPLAYER ), |
|
22 | + Client_Factory::get_client(Client_Factory::YOUTUBE), |
|
23 | + Client_Factory::get_client(Client_Factory::VIMEO), |
|
24 | + Client_Factory::get_client(Client_Factory::JWPLAYER), |
|
25 | 25 | ); |
26 | 26 | } |
27 | 27 | |
28 | - private function get_data_for_videos( $embedded_videos ) { |
|
28 | + private function get_data_for_videos($embedded_videos) { |
|
29 | 29 | |
30 | - $youtube_videos = $this->get_youtube_videos( $embedded_videos ); |
|
31 | - $youtube_provider = Provider_Factory::get_provider( Provider_Factory::YOUTUBE ); |
|
32 | - $youtube_videos = $youtube_provider->get_videos_data( $youtube_videos ); |
|
30 | + $youtube_videos = $this->get_youtube_videos($embedded_videos); |
|
31 | + $youtube_provider = Provider_Factory::get_provider(Provider_Factory::YOUTUBE); |
|
32 | + $youtube_videos = $youtube_provider->get_videos_data($youtube_videos); |
|
33 | 33 | |
34 | - $vimeo_videos = $this->get_vimeo_videos( $embedded_videos ); |
|
35 | - $vimeo_provider = Provider_Factory::get_provider( Provider_Factory::VIMEO ); |
|
36 | - $vimeo_videos = $vimeo_provider->get_videos_data( $vimeo_videos ); |
|
34 | + $vimeo_videos = $this->get_vimeo_videos($embedded_videos); |
|
35 | + $vimeo_provider = Provider_Factory::get_provider(Provider_Factory::VIMEO); |
|
36 | + $vimeo_videos = $vimeo_provider->get_videos_data($vimeo_videos); |
|
37 | 37 | |
38 | - $jwplayer_videos = $this->get_jw_player_videos( $embedded_videos ); |
|
39 | - $jwplayer_provider = Provider_Factory::get_provider( Provider_Factory::JWPLAYER ); |
|
40 | - $jwplayer_videos = $jwplayer_provider->get_videos_data( $jwplayer_videos ); |
|
38 | + $jwplayer_videos = $this->get_jw_player_videos($embedded_videos); |
|
39 | + $jwplayer_provider = Provider_Factory::get_provider(Provider_Factory::JWPLAYER); |
|
40 | + $jwplayer_videos = $jwplayer_provider->get_videos_data($jwplayer_videos); |
|
41 | 41 | |
42 | - return array_merge( $youtube_videos, $vimeo_videos, $jwplayer_videos ); |
|
42 | + return array_merge($youtube_videos, $vimeo_videos, $jwplayer_videos); |
|
43 | 43 | |
44 | 44 | } |
45 | 45 | |
46 | - private function get_video_ids( $video_urls ) { |
|
46 | + private function get_video_ids($video_urls) { |
|
47 | 47 | $clients = $this->api_clients; |
48 | 48 | $video_ids = array(); |
49 | - foreach ( $clients as $client ) { |
|
50 | - $ids = $client->get_video_ids( $video_urls ); |
|
51 | - if ( $ids ) { |
|
52 | - $video_ids = array_merge( $video_ids, $ids ); |
|
49 | + foreach ($clients as $client) { |
|
50 | + $ids = $client->get_video_ids($video_urls); |
|
51 | + if ($ids) { |
|
52 | + $video_ids = array_merge($video_ids, $ids); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | - return array_unique( $video_ids ); |
|
56 | + return array_unique($video_ids); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param $post_id int |
62 | 62 | * @param $embedded_videos array<Embedded_Video> |
63 | 63 | */ |
64 | - private function remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ) { |
|
64 | + private function remove_videos_from_store_if_not_present_in_content($storage, $post_id, $embedded_videos) { |
|
65 | 65 | |
66 | - $videos_to_be_deleted = $this->get_videos_to_be_deleted( $storage, $post_id, $embedded_videos ); |
|
67 | - $storage->remove_videos( $videos_to_be_deleted, $post_id ); |
|
66 | + $videos_to_be_deleted = $this->get_videos_to_be_deleted($storage, $post_id, $embedded_videos); |
|
67 | + $storage->remove_videos($videos_to_be_deleted, $post_id); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return array An array of videos which exist on storage, not on post content. |
77 | 77 | */ |
78 | - private function get_videos_to_be_deleted( Storage $storage, $post_id, array $embedded_videos ) { |
|
79 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
78 | + private function get_videos_to_be_deleted(Storage $storage, $post_id, array $embedded_videos) { |
|
79 | + $videos_in_store = $storage->get_all_videos($post_id); |
|
80 | 80 | $embedded_video_urls = array_map( |
81 | - function ( $embedded_video ) { |
|
81 | + function($embedded_video) { |
|
82 | 82 | /** |
83 | 83 | * @var $embedded_video Embedded_Video |
84 | 84 | */ |
@@ -92,20 +92,20 @@ discard block |
||
92 | 92 | * but this might not work well if we want to support multiple URL formats, we extract the video |
93 | 93 | * ids for embedded URLs. |
94 | 94 | */ |
95 | - $embedded_video_ids = $this->get_video_ids( $embedded_video_urls ); |
|
95 | + $embedded_video_ids = $this->get_video_ids($embedded_video_urls); |
|
96 | 96 | |
97 | 97 | $that = $this; |
98 | 98 | |
99 | 99 | return array_filter( |
100 | 100 | $videos_in_store, |
101 | - function ( $video ) use ( $embedded_video_ids, $that ) { |
|
101 | + function($video) use ($embedded_video_ids, $that) { |
|
102 | 102 | /** |
103 | 103 | * If the video id doesn't exist on the content then we need to return it |
104 | 104 | * in order to delete that video. |
105 | 105 | */ |
106 | 106 | return count( |
107 | 107 | array_intersect( |
108 | - $that->get_video_ids( array( $video->id ) ), |
|
108 | + $that->get_video_ids(array($video->id)), |
|
109 | 109 | $embedded_video_ids |
110 | 110 | ) |
111 | 111 | ) === 0; |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | * @param \WP_Post $post |
119 | 119 | * @param $post_id |
120 | 120 | */ |
121 | - public function process_video_urls( \WP_Post $post, $post_id ) { |
|
121 | + public function process_video_urls(\WP_Post $post, $post_id) { |
|
122 | 122 | |
123 | - $parser = Parser_Factory::get_parser_from_content( $post->post_content ); |
|
123 | + $parser = Parser_Factory::get_parser_from_content($post->post_content); |
|
124 | 124 | |
125 | - $embedded_videos = $parser->get_videos( $post_id ); |
|
125 | + $embedded_videos = $parser->get_videos($post_id); |
|
126 | 126 | /** |
127 | 127 | * Filters the embedded videos on post contet, custom plugins can add their video urls |
128 | 128 | * by constructing \Default_Embedded_Video or implement Embedded_Video class |
@@ -134,30 +134,30 @@ discard block |
||
134 | 134 | * @since 3.31.4 |
135 | 135 | * Filter name : wl_videoobject_embedded_videos |
136 | 136 | */ |
137 | - $embedded_videos = apply_filters( 'wl_videoobject_embedded_videos', $embedded_videos, $post_id ); |
|
137 | + $embedded_videos = apply_filters('wl_videoobject_embedded_videos', $embedded_videos, $post_id); |
|
138 | 138 | |
139 | 139 | $storage = Video_Storage_Factory::get_storage(); |
140 | 140 | |
141 | 141 | // Before sending api requests we need to check if there are any videos in |
142 | 142 | // store which is not present on post content, remove them if there are |
143 | 143 | // any |
144 | - $this->remove_videos_from_store_if_not_present_in_content( $storage, $post_id, $embedded_videos ); |
|
144 | + $this->remove_videos_from_store_if_not_present_in_content($storage, $post_id, $embedded_videos); |
|
145 | 145 | |
146 | - $embedded_videos = $this->get_videos_without_existing_data( $storage, $post_id, $embedded_videos ); |
|
146 | + $embedded_videos = $this->get_videos_without_existing_data($storage, $post_id, $embedded_videos); |
|
147 | 147 | |
148 | 148 | // Return early after removing all the videos. |
149 | - if ( ! $embedded_videos ) { |
|
149 | + if ( ! $embedded_videos) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - $videos = $this->get_data_for_videos( $embedded_videos ); |
|
153 | + $videos = $this->get_data_for_videos($embedded_videos); |
|
154 | 154 | |
155 | - if ( ! $videos ) { |
|
155 | + if ( ! $videos) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | - foreach ( $videos as $video ) { |
|
160 | - $storage->add_video( $post_id, $video ); |
|
159 | + foreach ($videos as $video) { |
|
160 | + $storage->add_video($post_id, $video); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -168,29 +168,29 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return array<Embedded_Video> Return array of embedded videos which are not in store. |
170 | 170 | */ |
171 | - private function get_videos_without_existing_data( $storage, $post_id, $embedded_videos ) { |
|
172 | - $videos_in_store = $storage->get_all_videos( $post_id ); |
|
171 | + private function get_videos_without_existing_data($storage, $post_id, $embedded_videos) { |
|
172 | + $videos_in_store = $storage->get_all_videos($post_id); |
|
173 | 173 | $video_urls_in_store = array_map( |
174 | - function ( $video ) { |
|
174 | + function($video) { |
|
175 | 175 | return $video->id; |
176 | 176 | }, |
177 | 177 | $videos_in_store |
178 | 178 | ); |
179 | 179 | |
180 | - $video_ids_in_store = $this->get_video_ids( $video_urls_in_store ); |
|
180 | + $video_ids_in_store = $this->get_video_ids($video_urls_in_store); |
|
181 | 181 | |
182 | 182 | $that = $this; |
183 | 183 | |
184 | 184 | return array_filter( |
185 | 185 | $embedded_videos, |
186 | - function ( $embedded_video ) use ( $video_ids_in_store, $that ) { |
|
186 | + function($embedded_video) use ($video_ids_in_store, $that) { |
|
187 | 187 | /** |
188 | 188 | * If the video id exist on content, not on storage then |
189 | 189 | * we need to fetch the data. |
190 | 190 | */ |
191 | 191 | return count( |
192 | 192 | array_intersect( |
193 | - $that->get_video_ids( array( $embedded_video->get_url() ) ), |
|
193 | + $that->get_video_ids(array($embedded_video->get_url())), |
|
194 | 194 | $video_ids_in_store |
195 | 195 | ) |
196 | 196 | ) === 0; |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return array |
205 | 205 | */ |
206 | - private function get_youtube_videos( $embedded_videos ) { |
|
206 | + private function get_youtube_videos($embedded_videos) { |
|
207 | 207 | return array_filter( |
208 | 208 | $embedded_videos, |
209 | - function ( $embedded_video ) { |
|
209 | + function($embedded_video) { |
|
210 | 210 | /** |
211 | 211 | * it should have youtube.com or youtu.be in the url |
212 | 212 | * |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | */ |
215 | 215 | $video_url = $embedded_video->get_url(); |
216 | 216 | |
217 | - return strpos( $video_url, 'youtube.com' ) !== false || |
|
218 | - strpos( $video_url, 'youtu.be' ) !== false; |
|
217 | + return strpos($video_url, 'youtube.com') !== false || |
|
218 | + strpos($video_url, 'youtu.be') !== false; |
|
219 | 219 | } |
220 | 220 | ); |
221 | 221 | } |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return array |
227 | 227 | */ |
228 | - private function get_vimeo_videos( $embedded_videos ) { |
|
228 | + private function get_vimeo_videos($embedded_videos) { |
|
229 | 229 | return array_filter( |
230 | 230 | $embedded_videos, |
231 | - function ( $embedded_video ) { |
|
231 | + function($embedded_video) { |
|
232 | 232 | /** |
233 | 233 | * it should have vimeo.com in the url |
234 | 234 | * |
@@ -236,15 +236,15 @@ discard block |
||
236 | 236 | */ |
237 | 237 | $video_url = $embedded_video->get_url(); |
238 | 238 | |
239 | - return strpos( $video_url, 'vimeo.com' ) !== false; |
|
239 | + return strpos($video_url, 'vimeo.com') !== false; |
|
240 | 240 | } |
241 | 241 | ); |
242 | 242 | } |
243 | 243 | |
244 | - private function get_jw_player_videos( $embedded_videos ) { |
|
244 | + private function get_jw_player_videos($embedded_videos) { |
|
245 | 245 | return array_filter( |
246 | 246 | $embedded_videos, |
247 | - function ( $embedded_video ) { |
|
247 | + function($embedded_video) { |
|
248 | 248 | /** |
249 | 249 | * it should have vimeo.com in the url |
250 | 250 | * |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | $video_url = $embedded_video->get_url(); |
254 | 254 | |
255 | - return strpos( $video_url, 'https://cdn.jwplayer.com/v2/media/', 0 ) !== false; |
|
255 | + return strpos($video_url, 'https://cdn.jwplayer.com/v2/media/', 0) !== false; |
|
256 | 256 | } |
257 | 257 | ); |
258 | 258 | } |
@@ -10,34 +10,34 @@ |
||
10 | 10 | |
11 | 11 | class Post_Edit_Screen { |
12 | 12 | |
13 | - public function init() { |
|
14 | - $callback = array( $this, 'enqueue_scripts' ); |
|
15 | - add_action( 'enqueue_block_editor_assets', $callback ); |
|
16 | - add_action( 'admin_print_scripts-post.php', $callback ); |
|
17 | - add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
18 | - } |
|
13 | + public function init() { |
|
14 | + $callback = array( $this, 'enqueue_scripts' ); |
|
15 | + add_action( 'enqueue_block_editor_assets', $callback ); |
|
16 | + add_action( 'admin_print_scripts-post.php', $callback ); |
|
17 | + add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
18 | + } |
|
19 | 19 | |
20 | - public function enqueue_scripts() { |
|
21 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
22 | - 'wl-videoobject', |
|
23 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject', |
|
24 | - array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' ) |
|
25 | - ); |
|
26 | - wp_enqueue_style( |
|
27 | - 'wl-videoobject', |
|
28 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css', |
|
29 | - array(), |
|
30 | - WORDLIFT_VERSION |
|
31 | - ); |
|
32 | - wp_localize_script( |
|
33 | - 'wl-videoobject', |
|
34 | - '_wlVideoobjectConfig', |
|
35 | - array( |
|
36 | - 'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ), |
|
37 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
38 | - 'postId' => get_the_ID(), |
|
39 | - ) |
|
40 | - ); |
|
41 | - } |
|
20 | + public function enqueue_scripts() { |
|
21 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
22 | + 'wl-videoobject', |
|
23 | + plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject', |
|
24 | + array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' ) |
|
25 | + ); |
|
26 | + wp_enqueue_style( |
|
27 | + 'wl-videoobject', |
|
28 | + plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css', |
|
29 | + array(), |
|
30 | + WORDLIFT_VERSION |
|
31 | + ); |
|
32 | + wp_localize_script( |
|
33 | + 'wl-videoobject', |
|
34 | + '_wlVideoobjectConfig', |
|
35 | + array( |
|
36 | + 'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ), |
|
37 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
38 | + 'postId' => get_the_ID(), |
|
39 | + ) |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
@@ -11,21 +11,21 @@ discard block |
||
11 | 11 | class Post_Edit_Screen { |
12 | 12 | |
13 | 13 | public function init() { |
14 | - $callback = array( $this, 'enqueue_scripts' ); |
|
15 | - add_action( 'enqueue_block_editor_assets', $callback ); |
|
16 | - add_action( 'admin_print_scripts-post.php', $callback ); |
|
17 | - add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
14 | + $callback = array($this, 'enqueue_scripts'); |
|
15 | + add_action('enqueue_block_editor_assets', $callback); |
|
16 | + add_action('admin_print_scripts-post.php', $callback); |
|
17 | + add_action('admin_print_scripts-post-new.php', $callback); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function enqueue_scripts() { |
21 | 21 | Scripts_Helper::enqueue_based_on_wordpress_version( |
22 | 22 | 'wl-videoobject', |
23 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject', |
|
24 | - array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' ) |
|
23 | + plugin_dir_url(dirname(dirname(__DIR__))).'/js/dist/videoobject', |
|
24 | + array('react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill') |
|
25 | 25 | ); |
26 | 26 | wp_enqueue_style( |
27 | 27 | 'wl-videoobject', |
28 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css', |
|
28 | + plugin_dir_url(dirname(dirname(__DIR__))).'/js/dist/videoobject.css', |
|
29 | 29 | array(), |
30 | 30 | WORDLIFT_VERSION |
31 | 31 | ); |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | 'wl-videoobject', |
34 | 34 | '_wlVideoobjectConfig', |
35 | 35 | array( |
36 | - 'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ), |
|
37 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
36 | + 'restUrl' => get_rest_url(null, '/wordlift/v1/videos'), |
|
37 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
38 | 38 | 'postId' => get_the_ID(), |
39 | 39 | ) |
40 | 40 | ); |