@@ -12,106 +12,106 @@ 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( 'wl_videoobject_sitemap_query_args', array( |
|
| 37 | - 'fields' => 'ids', |
|
| 38 | - 'numberposts' => - 1, |
|
| 39 | - 'post_type' => get_post_types( array( 'public' => true ) ), |
|
| 40 | - 'meta_query' => array( |
|
| 41 | - array( |
|
| 42 | - 'key' => Meta_Storage::META_KEY, |
|
| 43 | - 'compare' => 'EXISTS' |
|
| 44 | - ) |
|
| 45 | - ) |
|
| 46 | - ) ); |
|
| 47 | - |
|
| 48 | - $posts = get_posts( $video_sitemap_query_args ); |
|
| 49 | - |
|
| 50 | - $all_posts_xml = ""; |
|
| 51 | - |
|
| 52 | - if ( ! $posts ) { |
|
| 53 | - return $all_posts_xml; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - foreach ( $posts as $post_id ) { |
|
| 57 | - $all_posts_xml .= self::get_xml_for_single_post( $post_id ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $all_posts_xml; |
|
| 61 | - |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param $post_id |
|
| 67 | - * |
|
| 68 | - * @return string XML string for single post. |
|
| 69 | - */ |
|
| 70 | - public static function get_xml_for_single_post( $post_id ) { |
|
| 71 | - $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id ); |
|
| 72 | - if ( ! $videos ) { |
|
| 73 | - return ""; |
|
| 74 | - } |
|
| 75 | - $single_post_xml = ""; |
|
| 76 | - foreach ( $videos as $video ) { |
|
| 77 | - $single_post_xml .= self::get_xml_for_single_video( $video, $post_id ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $single_post_xml; |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param $video Video |
|
| 87 | - * @param $post_id int |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public static function get_xml_for_single_video( $video, $post_id ) { |
|
| 92 | - |
|
| 93 | - $permalink = get_permalink( $post_id ); |
|
| 94 | - $title = esc_html( $video->name ); |
|
| 95 | - $description = esc_html( $video->description ); |
|
| 96 | - $thumbnail_url = $video->thumbnail_urls[0]; |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - $optional_fields = array( |
|
| 100 | - 'content_loc' => $video->content_url, |
|
| 101 | - 'player_loc' => $video->embed_url, |
|
| 102 | - 'duration' => self::iso8601_to_seconds( $video->duration ), |
|
| 103 | - 'view_count' => $video->views, |
|
| 104 | - 'live' => $video->is_live_video ? 'yes' : 'no' |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - $optional_data = ""; |
|
| 108 | - foreach ( $optional_fields as $xml_key => $xml_value ) { |
|
| 109 | - if ( $xml_value ) { |
|
| 110 | - $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>"; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return <<<EOF |
|
| 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( 'wl_videoobject_sitemap_query_args', array( |
|
| 37 | + 'fields' => 'ids', |
|
| 38 | + 'numberposts' => - 1, |
|
| 39 | + 'post_type' => get_post_types( array( 'public' => true ) ), |
|
| 40 | + 'meta_query' => array( |
|
| 41 | + array( |
|
| 42 | + 'key' => Meta_Storage::META_KEY, |
|
| 43 | + 'compare' => 'EXISTS' |
|
| 44 | + ) |
|
| 45 | + ) |
|
| 46 | + ) ); |
|
| 47 | + |
|
| 48 | + $posts = get_posts( $video_sitemap_query_args ); |
|
| 49 | + |
|
| 50 | + $all_posts_xml = ""; |
|
| 51 | + |
|
| 52 | + if ( ! $posts ) { |
|
| 53 | + return $all_posts_xml; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + foreach ( $posts as $post_id ) { |
|
| 57 | + $all_posts_xml .= self::get_xml_for_single_post( $post_id ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $all_posts_xml; |
|
| 61 | + |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param $post_id |
|
| 67 | + * |
|
| 68 | + * @return string XML string for single post. |
|
| 69 | + */ |
|
| 70 | + public static function get_xml_for_single_post( $post_id ) { |
|
| 71 | + $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id ); |
|
| 72 | + if ( ! $videos ) { |
|
| 73 | + return ""; |
|
| 74 | + } |
|
| 75 | + $single_post_xml = ""; |
|
| 76 | + foreach ( $videos as $video ) { |
|
| 77 | + $single_post_xml .= self::get_xml_for_single_video( $video, $post_id ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $single_post_xml; |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param $video Video |
|
| 87 | + * @param $post_id int |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public static function get_xml_for_single_video( $video, $post_id ) { |
|
| 92 | + |
|
| 93 | + $permalink = get_permalink( $post_id ); |
|
| 94 | + $title = esc_html( $video->name ); |
|
| 95 | + $description = esc_html( $video->description ); |
|
| 96 | + $thumbnail_url = $video->thumbnail_urls[0]; |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + $optional_fields = array( |
|
| 100 | + 'content_loc' => $video->content_url, |
|
| 101 | + 'player_loc' => $video->embed_url, |
|
| 102 | + 'duration' => self::iso8601_to_seconds( $video->duration ), |
|
| 103 | + 'view_count' => $video->views, |
|
| 104 | + 'live' => $video->is_live_video ? 'yes' : 'no' |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + $optional_data = ""; |
|
| 108 | + foreach ( $optional_fields as $xml_key => $xml_value ) { |
|
| 109 | + if ( $xml_value ) { |
|
| 110 | + $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>"; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return <<<EOF |
|
| 115 | 115 | <url> |
| 116 | 116 | <loc>${permalink}</loc> |
| 117 | 117 | <video:video> |
@@ -123,6 +123,6 @@ discard block |
||
| 123 | 123 | </url> |
| 124 | 124 | EOF; |
| 125 | 125 | |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | } |
| 129 | 129 | \ No newline at end of file |
@@ -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 | |
@@ -33,28 +33,28 @@ discard block |
||
| 33 | 33 | * @since 3.31.6 |
| 34 | 34 | * Filter the query args, add support for all custom public post types. |
| 35 | 35 | */ |
| 36 | - $video_sitemap_query_args = apply_filters( 'wl_videoobject_sitemap_query_args', array( |
|
| 36 | + $video_sitemap_query_args = apply_filters('wl_videoobject_sitemap_query_args', array( |
|
| 37 | 37 | 'fields' => 'ids', |
| 38 | - 'numberposts' => - 1, |
|
| 39 | - 'post_type' => get_post_types( array( 'public' => true ) ), |
|
| 38 | + 'numberposts' => -1, |
|
| 39 | + 'post_type' => get_post_types(array('public' => true)), |
|
| 40 | 40 | 'meta_query' => array( |
| 41 | 41 | array( |
| 42 | 42 | 'key' => Meta_Storage::META_KEY, |
| 43 | 43 | 'compare' => 'EXISTS' |
| 44 | 44 | ) |
| 45 | 45 | ) |
| 46 | - ) ); |
|
| 46 | + )); |
|
| 47 | 47 | |
| 48 | - $posts = get_posts( $video_sitemap_query_args ); |
|
| 48 | + $posts = get_posts($video_sitemap_query_args); |
|
| 49 | 49 | |
| 50 | 50 | $all_posts_xml = ""; |
| 51 | 51 | |
| 52 | - if ( ! $posts ) { |
|
| 52 | + if ( ! $posts) { |
|
| 53 | 53 | return $all_posts_xml; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - foreach ( $posts as $post_id ) { |
|
| 57 | - $all_posts_xml .= self::get_xml_for_single_post( $post_id ); |
|
| 56 | + foreach ($posts as $post_id) { |
|
| 57 | + $all_posts_xml .= self::get_xml_for_single_post($post_id); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $all_posts_xml; |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @return string XML string for single post. |
| 69 | 69 | */ |
| 70 | - public static function get_xml_for_single_post( $post_id ) { |
|
| 71 | - $videos = Video_Storage_Factory::get_storage()->get_all_videos( $post_id ); |
|
| 72 | - if ( ! $videos ) { |
|
| 70 | + public static function get_xml_for_single_post($post_id) { |
|
| 71 | + $videos = Video_Storage_Factory::get_storage()->get_all_videos($post_id); |
|
| 72 | + if ( ! $videos) { |
|
| 73 | 73 | return ""; |
| 74 | 74 | } |
| 75 | 75 | $single_post_xml = ""; |
| 76 | - foreach ( $videos as $video ) { |
|
| 77 | - $single_post_xml .= self::get_xml_for_single_video( $video, $post_id ); |
|
| 76 | + foreach ($videos as $video) { |
|
| 77 | + $single_post_xml .= self::get_xml_for_single_video($video, $post_id); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | return $single_post_xml; |
@@ -88,25 +88,25 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public static function get_xml_for_single_video( $video, $post_id ) { |
|
| 91 | + public static function get_xml_for_single_video($video, $post_id) { |
|
| 92 | 92 | |
| 93 | - $permalink = get_permalink( $post_id ); |
|
| 94 | - $title = esc_html( $video->name ); |
|
| 95 | - $description = esc_html( $video->description ); |
|
| 93 | + $permalink = get_permalink($post_id); |
|
| 94 | + $title = esc_html($video->name); |
|
| 95 | + $description = esc_html($video->description); |
|
| 96 | 96 | $thumbnail_url = $video->thumbnail_urls[0]; |
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | $optional_fields = array( |
| 100 | 100 | 'content_loc' => $video->content_url, |
| 101 | 101 | 'player_loc' => $video->embed_url, |
| 102 | - 'duration' => self::iso8601_to_seconds( $video->duration ), |
|
| 102 | + 'duration' => self::iso8601_to_seconds($video->duration), |
|
| 103 | 103 | 'view_count' => $video->views, |
| 104 | 104 | 'live' => $video->is_live_video ? 'yes' : 'no' |
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | $optional_data = ""; |
| 108 | - foreach ( $optional_fields as $xml_key => $xml_value ) { |
|
| 109 | - if ( $xml_value ) { |
|
| 108 | + foreach ($optional_fields as $xml_key => $xml_value) { |
|
| 109 | + if ($xml_value) { |
|
| 110 | 110 | $optional_data .= "<video:${xml_key}>${xml_value}</video:${xml_key}>"; |
| 111 | 111 | } |
| 112 | 112 | } |