@@ -8,31 +8,31 @@ |
||
8 | 8 | */ |
9 | 9 | class Parser_Factory { |
10 | 10 | |
11 | - const BLOCK_EDITOR = 'block-editor'; |
|
12 | - |
|
13 | - const CLASSIC_EDITOR = 'classic-editor'; |
|
14 | - |
|
15 | - /** |
|
16 | - * @param $parser_config |
|
17 | - * |
|
18 | - * @return Parser |
|
19 | - */ |
|
20 | - public static function get_parser( $parser_config ) { |
|
21 | - if ( self::BLOCK_EDITOR === $parser_config ) { |
|
22 | - return new Block_Editor_Parser(); |
|
23 | - } elseif ( self::CLASSIC_EDITOR === $parser_config ) { |
|
24 | - return new Classic_Editor_Parser(); |
|
25 | - } |
|
26 | - |
|
27 | - } |
|
28 | - |
|
29 | - public static function get_parser_from_content( $post_content ) { |
|
30 | - if ( function_exists( 'has_blocks' ) |
|
31 | - && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) { |
|
32 | - return self::get_parser( self::BLOCK_EDITOR ); |
|
33 | - } else { |
|
34 | - return self::get_parser( self::CLASSIC_EDITOR ); |
|
35 | - } |
|
36 | - } |
|
11 | + const BLOCK_EDITOR = 'block-editor'; |
|
12 | + |
|
13 | + const CLASSIC_EDITOR = 'classic-editor'; |
|
14 | + |
|
15 | + /** |
|
16 | + * @param $parser_config |
|
17 | + * |
|
18 | + * @return Parser |
|
19 | + */ |
|
20 | + public static function get_parser( $parser_config ) { |
|
21 | + if ( self::BLOCK_EDITOR === $parser_config ) { |
|
22 | + return new Block_Editor_Parser(); |
|
23 | + } elseif ( self::CLASSIC_EDITOR === $parser_config ) { |
|
24 | + return new Classic_Editor_Parser(); |
|
25 | + } |
|
26 | + |
|
27 | + } |
|
28 | + |
|
29 | + public static function get_parser_from_content( $post_content ) { |
|
30 | + if ( function_exists( 'has_blocks' ) |
|
31 | + && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) { |
|
32 | + return self::get_parser( self::BLOCK_EDITOR ); |
|
33 | + } else { |
|
34 | + return self::get_parser( self::CLASSIC_EDITOR ); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -17,21 +17,21 @@ |
||
17 | 17 | * |
18 | 18 | * @return Parser |
19 | 19 | */ |
20 | - public static function get_parser( $parser_config ) { |
|
21 | - if ( self::BLOCK_EDITOR === $parser_config ) { |
|
20 | + public static function get_parser($parser_config) { |
|
21 | + if (self::BLOCK_EDITOR === $parser_config) { |
|
22 | 22 | return new Block_Editor_Parser(); |
23 | - } elseif ( self::CLASSIC_EDITOR === $parser_config ) { |
|
23 | + } elseif (self::CLASSIC_EDITOR === $parser_config) { |
|
24 | 24 | return new Classic_Editor_Parser(); |
25 | 25 | } |
26 | 26 | |
27 | 27 | } |
28 | 28 | |
29 | - public static function get_parser_from_content( $post_content ) { |
|
30 | - if ( function_exists( 'has_blocks' ) |
|
31 | - && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) { |
|
32 | - return self::get_parser( self::BLOCK_EDITOR ); |
|
29 | + public static function get_parser_from_content($post_content) { |
|
30 | + if (function_exists('has_blocks') |
|
31 | + && function_exists('parse_blocks') && has_blocks($post_content)) { |
|
32 | + return self::get_parser(self::BLOCK_EDITOR); |
|
33 | 33 | } else { |
34 | - return self::get_parser( self::CLASSIC_EDITOR ); |
|
34 | + return self::get_parser(self::CLASSIC_EDITOR); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 |
@@ -11,32 +11,32 @@ |
||
11 | 11 | */ |
12 | 12 | class Block_Editor_Parser implements Parser { |
13 | 13 | |
14 | - public function get_videos( $post_id ) { |
|
15 | - $post = get_post( $post_id ); |
|
16 | - $content = $post->post_content; |
|
17 | - $video_blocks = array_filter( parse_blocks( $content ), array( $this, 'filter_blocks' ) ); |
|
18 | - return array_map( array( $this, 'block_to_video' ), $video_blocks ); |
|
19 | - } |
|
14 | + public function get_videos( $post_id ) { |
|
15 | + $post = get_post( $post_id ); |
|
16 | + $content = $post->post_content; |
|
17 | + $video_blocks = array_filter( parse_blocks( $content ), array( $this, 'filter_blocks' ) ); |
|
18 | + return array_map( array( $this, 'block_to_video' ), $video_blocks ); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param $block |
|
23 | - * |
|
24 | - * @return Embedded_Video |
|
25 | - */ |
|
26 | - public function block_to_video( $block ) { |
|
27 | - return Embedded_Video_Factory::get_embedded_video( $block['attrs']['url'] ); |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param $block |
|
23 | + * |
|
24 | + * @return Embedded_Video |
|
25 | + */ |
|
26 | + public function block_to_video( $block ) { |
|
27 | + return Embedded_Video_Factory::get_embedded_video( $block['attrs']['url'] ); |
|
28 | + } |
|
29 | 29 | |
30 | - public function filter_blocks( $block ) { |
|
31 | - return array_key_exists( 'blockName', $block ) |
|
32 | - && ( 'core/embed' === $block['blockName'] || 'core-embed/youtube' === $block['blockName'] |
|
33 | - || 'core-embed/vimeo' === $block['blockName'] ) |
|
34 | - // Check if attributes present |
|
35 | - && array_key_exists( 'attrs', $block ) |
|
36 | - && is_array( $block['attrs'] ) |
|
37 | - // check if valid url present. |
|
38 | - && array_key_exists( 'url', $block['attrs'] ) |
|
39 | - && is_string( $block['attrs']['url'] ); |
|
40 | - } |
|
30 | + public function filter_blocks( $block ) { |
|
31 | + return array_key_exists( 'blockName', $block ) |
|
32 | + && ( 'core/embed' === $block['blockName'] || 'core-embed/youtube' === $block['blockName'] |
|
33 | + || 'core-embed/vimeo' === $block['blockName'] ) |
|
34 | + // Check if attributes present |
|
35 | + && array_key_exists( 'attrs', $block ) |
|
36 | + && is_array( $block['attrs'] ) |
|
37 | + // check if valid url present. |
|
38 | + && array_key_exists( 'url', $block['attrs'] ) |
|
39 | + && is_string( $block['attrs']['url'] ); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class Block_Editor_Parser implements Parser { |
13 | 13 | |
14 | - public function get_videos( $post_id ) { |
|
15 | - $post = get_post( $post_id ); |
|
14 | + public function get_videos($post_id) { |
|
15 | + $post = get_post($post_id); |
|
16 | 16 | $content = $post->post_content; |
17 | - $video_blocks = array_filter( parse_blocks( $content ), array( $this, 'filter_blocks' ) ); |
|
18 | - return array_map( array( $this, 'block_to_video' ), $video_blocks ); |
|
17 | + $video_blocks = array_filter(parse_blocks($content), array($this, 'filter_blocks')); |
|
18 | + return array_map(array($this, 'block_to_video'), $video_blocks); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,20 +23,20 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return Embedded_Video |
25 | 25 | */ |
26 | - public function block_to_video( $block ) { |
|
27 | - return Embedded_Video_Factory::get_embedded_video( $block['attrs']['url'] ); |
|
26 | + public function block_to_video($block) { |
|
27 | + return Embedded_Video_Factory::get_embedded_video($block['attrs']['url']); |
|
28 | 28 | } |
29 | 29 | |
30 | - public function filter_blocks( $block ) { |
|
31 | - return array_key_exists( 'blockName', $block ) |
|
32 | - && ( 'core/embed' === $block['blockName'] || 'core-embed/youtube' === $block['blockName'] |
|
33 | - || 'core-embed/vimeo' === $block['blockName'] ) |
|
30 | + public function filter_blocks($block) { |
|
31 | + return array_key_exists('blockName', $block) |
|
32 | + && ('core/embed' === $block['blockName'] || 'core-embed/youtube' === $block['blockName'] |
|
33 | + || 'core-embed/vimeo' === $block['blockName']) |
|
34 | 34 | // Check if attributes present |
35 | - && array_key_exists( 'attrs', $block ) |
|
36 | - && is_array( $block['attrs'] ) |
|
35 | + && array_key_exists('attrs', $block) |
|
36 | + && is_array($block['attrs']) |
|
37 | 37 | // check if valid url present. |
38 | - && array_key_exists( 'url', $block['attrs'] ) |
|
39 | - && is_string( $block['attrs']['url'] ); |
|
38 | + && array_key_exists('url', $block['attrs']) |
|
39 | + && is_string($block['attrs']['url']); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -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 | } |