@@ -10,25 +10,25 @@ |
||
| 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( 'wl-videoobject', |
|
| 22 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject', |
|
| 23 | - array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' ) |
|
| 24 | - ); |
|
| 25 | - wp_enqueue_style( 'wl-videoobject', |
|
| 26 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css' ); |
|
| 27 | - wp_localize_script( 'wl-videoobject', '_wlVideoobjectConfig', array( |
|
| 28 | - 'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ), |
|
| 29 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 30 | - 'postId' => get_the_ID(), |
|
| 31 | - ) ); |
|
| 32 | - } |
|
| 20 | + public function enqueue_scripts() { |
|
| 21 | + Scripts_Helper::enqueue_based_on_wordpress_version( 'wl-videoobject', |
|
| 22 | + plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject', |
|
| 23 | + array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' ) |
|
| 24 | + ); |
|
| 25 | + wp_enqueue_style( 'wl-videoobject', |
|
| 26 | + plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css' ); |
|
| 27 | + wp_localize_script( 'wl-videoobject', '_wlVideoobjectConfig', array( |
|
| 28 | + 'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ), |
|
| 29 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 30 | + 'postId' => get_the_ID(), |
|
| 31 | + ) ); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -11,24 +11,24 @@ |
||
| 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 | - Scripts_Helper::enqueue_based_on_wordpress_version( 'wl-videoobject', |
|
| 22 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject', |
|
| 23 | - array( 'react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill' ) |
|
| 21 | + Scripts_Helper::enqueue_based_on_wordpress_version('wl-videoobject', |
|
| 22 | + plugin_dir_url(dirname(dirname(__DIR__))).'/js/dist/videoobject', |
|
| 23 | + array('react', 'react-dom', 'wp-hooks', 'wp-i18n', 'wp-polyfill') |
|
| 24 | 24 | ); |
| 25 | - wp_enqueue_style( 'wl-videoobject', |
|
| 26 | - plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . '/js/dist/videoobject.css' ); |
|
| 27 | - wp_localize_script( 'wl-videoobject', '_wlVideoobjectConfig', array( |
|
| 28 | - 'restUrl' => get_rest_url( null, '/wordlift/v1/videos' ), |
|
| 29 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 25 | + wp_enqueue_style('wl-videoobject', |
|
| 26 | + plugin_dir_url(dirname(dirname(__DIR__))).'/js/dist/videoobject.css'); |
|
| 27 | + wp_localize_script('wl-videoobject', '_wlVideoobjectConfig', array( |
|
| 28 | + 'restUrl' => get_rest_url(null, '/wordlift/v1/videos'), |
|
| 29 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
| 30 | 30 | 'postId' => get_the_ID(), |
| 31 | - ) ); |
|
| 31 | + )); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Video_Storage_Factory { |
| 11 | 11 | |
| 12 | - public static function get_storage() { |
|
| 13 | - return new Meta_Storage(); |
|
| 14 | - } |
|
| 12 | + public static function get_storage() { |
|
| 13 | + return new Meta_Storage(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -9,44 +9,44 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Meta_Storage implements Storage { |
| 11 | 11 | |
| 12 | - const META_KEY = '_wl_video_object_videos'; |
|
| 12 | + const META_KEY = '_wl_video_object_videos'; |
|
| 13 | 13 | |
| 14 | - public function add_video( $post_id, $video ) { |
|
| 14 | + public function add_video( $post_id, $video ) { |
|
| 15 | 15 | |
| 16 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 17 | - } |
|
| 16 | + add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function get_all_videos( $post_id ) { |
|
| 20 | + public function get_all_videos( $post_id ) { |
|
| 21 | 21 | |
| 22 | - return get_post_meta( $post_id, self::META_KEY ); |
|
| 22 | + return get_post_meta( $post_id, self::META_KEY ); |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 26 | + public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 27 | 27 | |
| 28 | - $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 29 | - return $video->id; |
|
| 30 | - }, $videos_to_be_removed ); |
|
| 28 | + $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 29 | + return $video->id; |
|
| 30 | + }, $videos_to_be_removed ); |
|
| 31 | 31 | |
| 32 | - $present_videos = $this->get_all_videos( $post_id ); |
|
| 32 | + $present_videos = $this->get_all_videos( $post_id ); |
|
| 33 | 33 | |
| 34 | - $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 35 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 36 | - } ); |
|
| 34 | + $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 35 | + return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 36 | + } ); |
|
| 37 | 37 | |
| 38 | - // Remove all existing videos. |
|
| 39 | - $this->remove_all_videos( $post_id ); |
|
| 38 | + // Remove all existing videos. |
|
| 39 | + $this->remove_all_videos( $post_id ); |
|
| 40 | 40 | |
| 41 | - // Save the videos. |
|
| 42 | - foreach ( $filtered_videos as $video ) { |
|
| 43 | - $this->add_video( $post_id, $video ); |
|
| 44 | - } |
|
| 41 | + // Save the videos. |
|
| 42 | + foreach ( $filtered_videos as $video ) { |
|
| 43 | + $this->add_video( $post_id, $video ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function remove_all_videos( $post_id ) { |
|
| 50 | - delete_post_meta( $post_id, self::META_KEY ); |
|
| 51 | - } |
|
| 49 | + public function remove_all_videos( $post_id ) { |
|
| 50 | + delete_post_meta( $post_id, self::META_KEY ); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -11,42 +11,42 @@ |
||
| 11 | 11 | |
| 12 | 12 | const META_KEY = '_wl_video_object_videos'; |
| 13 | 13 | |
| 14 | - public function add_video( $post_id, $video ) { |
|
| 14 | + public function add_video($post_id, $video) { |
|
| 15 | 15 | |
| 16 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 16 | + add_post_meta($post_id, self::META_KEY, $video); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function get_all_videos( $post_id ) { |
|
| 20 | + public function get_all_videos($post_id) { |
|
| 21 | 21 | |
| 22 | - return get_post_meta( $post_id, self::META_KEY ); |
|
| 22 | + return get_post_meta($post_id, self::META_KEY); |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 26 | + public function remove_videos($videos_to_be_removed, $post_id) { |
|
| 27 | 27 | |
| 28 | - $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 28 | + $videos_to_be_removed_ids = array_map(function($video) { |
|
| 29 | 29 | return $video->id; |
| 30 | - }, $videos_to_be_removed ); |
|
| 30 | + }, $videos_to_be_removed); |
|
| 31 | 31 | |
| 32 | - $present_videos = $this->get_all_videos( $post_id ); |
|
| 32 | + $present_videos = $this->get_all_videos($post_id); |
|
| 33 | 33 | |
| 34 | - $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 35 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 34 | + $filtered_videos = array_filter($present_videos, function($video) use ($videos_to_be_removed_ids) { |
|
| 35 | + return ! in_array($video->id, $videos_to_be_removed_ids); |
|
| 36 | 36 | } ); |
| 37 | 37 | |
| 38 | 38 | // Remove all existing videos. |
| 39 | - $this->remove_all_videos( $post_id ); |
|
| 39 | + $this->remove_all_videos($post_id); |
|
| 40 | 40 | |
| 41 | 41 | // Save the videos. |
| 42 | - foreach ( $filtered_videos as $video ) { |
|
| 43 | - $this->add_video( $post_id, $video ); |
|
| 42 | + foreach ($filtered_videos as $video) { |
|
| 43 | + $this->add_video($post_id, $video); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function remove_all_videos( $post_id ) { |
|
| 50 | - delete_post_meta( $post_id, self::META_KEY ); |
|
| 49 | + public function remove_all_videos($post_id) { |
|
| 50 | + delete_post_meta($post_id, self::META_KEY); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -10,41 +10,41 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | interface Storage { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param $post_id int Post id to add video. |
|
| 15 | - * @param $video Video The video object which needs to be saved. |
|
| 16 | - * |
|
| 17 | - * @return bool true if video is added, false otherwise. |
|
| 18 | - */ |
|
| 19 | - public function add_video( $post_id, $video ); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Return all video objects for the post |
|
| 23 | - * |
|
| 24 | - * @param $post_id int Post id to get all videos. |
|
| 25 | - * |
|
| 26 | - * @return array<Video> |
|
| 27 | - */ |
|
| 28 | - public function get_all_videos( $post_id ); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Remove the Video Object. |
|
| 32 | - * |
|
| 33 | - * @param $videos_to_be_removed array<Video> |
|
| 34 | - * |
|
| 35 | - * @param $post_id int |
|
| 36 | - * |
|
| 37 | - * @return bool return true if removed or false |
|
| 38 | - */ |
|
| 39 | - public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Remove all videos present for post id |
|
| 43 | - * |
|
| 44 | - * @param $post_id |
|
| 45 | - * |
|
| 46 | - * @return true if removed else false. |
|
| 47 | - */ |
|
| 48 | - public function remove_all_videos( $post_id ); |
|
| 13 | + /** |
|
| 14 | + * @param $post_id int Post id to add video. |
|
| 15 | + * @param $video Video The video object which needs to be saved. |
|
| 16 | + * |
|
| 17 | + * @return bool true if video is added, false otherwise. |
|
| 18 | + */ |
|
| 19 | + public function add_video( $post_id, $video ); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Return all video objects for the post |
|
| 23 | + * |
|
| 24 | + * @param $post_id int Post id to get all videos. |
|
| 25 | + * |
|
| 26 | + * @return array<Video> |
|
| 27 | + */ |
|
| 28 | + public function get_all_videos( $post_id ); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Remove the Video Object. |
|
| 32 | + * |
|
| 33 | + * @param $videos_to_be_removed array<Video> |
|
| 34 | + * |
|
| 35 | + * @param $post_id int |
|
| 36 | + * |
|
| 37 | + * @return bool return true if removed or false |
|
| 38 | + */ |
|
| 39 | + public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Remove all videos present for post id |
|
| 43 | + * |
|
| 44 | + * @param $post_id |
|
| 45 | + * |
|
| 46 | + * @return true if removed else false. |
|
| 47 | + */ |
|
| 48 | + public function remove_all_videos( $post_id ); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return bool true if video is added, false otherwise. |
| 18 | 18 | */ |
| 19 | - public function add_video( $post_id, $video ); |
|
| 19 | + public function add_video($post_id, $video); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Return all video objects for the post |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @return array<Video> |
| 27 | 27 | */ |
| 28 | - public function get_all_videos( $post_id ); |
|
| 28 | + public function get_all_videos($post_id); |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Remove the Video Object. |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return bool return true if removed or false |
| 38 | 38 | */ |
| 39 | - public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 39 | + public function remove_videos($videos_to_be_removed, $post_id); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Remove all videos present for post id |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return true if removed else false. |
| 47 | 47 | */ |
| 48 | - public function remove_all_videos( $post_id ); |
|
| 48 | + public function remove_all_videos($post_id); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | interface Embedded_Video { |
| 13 | 13 | |
| 14 | - public function get_api_provider(); |
|
| 14 | + public function get_api_provider(); |
|
| 15 | 15 | |
| 16 | - public function get_url(); |
|
| 16 | + public function get_url(); |
|
| 17 | 17 | |
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Embedded_Video_Factory { |
| 9 | 9 | |
| 10 | - public static function get_embedded_video( $video_url ) { |
|
| 11 | - return new Default_Embedded_Video( $video_url ); |
|
| 12 | - } |
|
| 10 | + public static function get_embedded_video( $video_url ) { |
|
| 11 | + return new Default_Embedded_Video( $video_url ); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Embedded_Video_Factory { |
| 9 | 9 | |
| 10 | - public static function get_embedded_video( $video_url ) { |
|
| 11 | - return new Default_Embedded_Video( $video_url ); |
|
| 10 | + public static function get_embedded_video($video_url) { |
|
| 11 | + return new Default_Embedded_Video($video_url); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -7,20 +7,20 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Default_Embedded_Video implements Embedded_Video { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var string The url of the video which got embedded. |
|
| 12 | - */ |
|
| 13 | - private $video_url; |
|
| 10 | + /** |
|
| 11 | + * @var string The url of the video which got embedded. |
|
| 12 | + */ |
|
| 13 | + private $video_url; |
|
| 14 | 14 | |
| 15 | - public function __construct( $video_url ) { |
|
| 16 | - $this->video_url = $video_url; |
|
| 17 | - } |
|
| 15 | + public function __construct( $video_url ) { |
|
| 16 | + $this->video_url = $video_url; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function get_api_provider() { |
|
| 20 | - // TODO: Implement get_api_provider() method. |
|
| 21 | - } |
|
| 19 | + public function get_api_provider() { |
|
| 20 | + // TODO: Implement get_api_provider() method. |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function get_url() { |
|
| 24 | - return $this->video_url; |
|
| 25 | - } |
|
| 23 | + public function get_url() { |
|
| 24 | + return $this->video_url; |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | private $video_url; |
| 14 | 14 | |
| 15 | - public function __construct( $video_url ) { |
|
| 15 | + public function __construct($video_url) { |
|
| 16 | 16 | $this->video_url = $video_url; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -7,91 +7,91 @@ |
||
| 7 | 7 | namespace Wordlift\Videoobject\Data\Video; |
| 8 | 8 | |
| 9 | 9 | class Video { |
| 10 | - /** |
|
| 11 | - * @var string The title of the video. |
|
| 12 | - */ |
|
| 13 | - public $name; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * @var string The video description. |
|
| 17 | - */ |
|
| 18 | - public $description; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var array Thumbnail urls. |
|
| 22 | - */ |
|
| 23 | - public $thumbnail_urls; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string Published date. |
|
| 27 | - */ |
|
| 28 | - public $upload_date; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string Video url. |
|
| 32 | - */ |
|
| 33 | - public $content_url; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string Video duration in IS08601 format. |
|
| 37 | - */ |
|
| 38 | - public $duration; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - public $embed_url; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string An unique identifier, usually the video url. |
|
| 47 | - */ |
|
| 48 | - public $id; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var int The number of views for the video. |
|
| 52 | - */ |
|
| 53 | - public $views; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * All the live video properties. |
|
| 58 | - */ |
|
| 59 | - /** |
|
| 60 | - * @var bool |
|
| 61 | - */ |
|
| 62 | - public $is_live_video; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string Live video start date |
|
| 66 | - */ |
|
| 67 | - public $live_video_start_date; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var string Live video end date |
|
| 71 | - */ |
|
| 72 | - public $live_video_end_date; |
|
| 73 | - |
|
| 74 | - public function from( $data ) { |
|
| 75 | - $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 76 | - // Loop through the keys and set the value from array |
|
| 77 | - foreach ( $keys as $key ) { |
|
| 78 | - $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function get_data() { |
|
| 83 | - |
|
| 84 | - return array( |
|
| 85 | - '@type' => 'VideoObject', |
|
| 86 | - 'name' => $this->name, |
|
| 87 | - 'description' => $this->description, |
|
| 88 | - 'contentUrl' => $this->content_url, |
|
| 89 | - 'embedUrl' => $this->embed_url, |
|
| 90 | - 'uploadDate' => $this->upload_date, |
|
| 91 | - 'thumbnailUrl' => $this->thumbnail_urls, |
|
| 92 | - 'duration' => $this->duration |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - } |
|
| 10 | + /** |
|
| 11 | + * @var string The title of the video. |
|
| 12 | + */ |
|
| 13 | + public $name; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * @var string The video description. |
|
| 17 | + */ |
|
| 18 | + public $description; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var array Thumbnail urls. |
|
| 22 | + */ |
|
| 23 | + public $thumbnail_urls; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string Published date. |
|
| 27 | + */ |
|
| 28 | + public $upload_date; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string Video url. |
|
| 32 | + */ |
|
| 33 | + public $content_url; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string Video duration in IS08601 format. |
|
| 37 | + */ |
|
| 38 | + public $duration; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + public $embed_url; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string An unique identifier, usually the video url. |
|
| 47 | + */ |
|
| 48 | + public $id; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var int The number of views for the video. |
|
| 52 | + */ |
|
| 53 | + public $views; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * All the live video properties. |
|
| 58 | + */ |
|
| 59 | + /** |
|
| 60 | + * @var bool |
|
| 61 | + */ |
|
| 62 | + public $is_live_video; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string Live video start date |
|
| 66 | + */ |
|
| 67 | + public $live_video_start_date; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @var string Live video end date |
|
| 71 | + */ |
|
| 72 | + public $live_video_end_date; |
|
| 73 | + |
|
| 74 | + public function from( $data ) { |
|
| 75 | + $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 76 | + // Loop through the keys and set the value from array |
|
| 77 | + foreach ( $keys as $key ) { |
|
| 78 | + $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function get_data() { |
|
| 83 | + |
|
| 84 | + return array( |
|
| 85 | + '@type' => 'VideoObject', |
|
| 86 | + 'name' => $this->name, |
|
| 87 | + 'description' => $this->description, |
|
| 88 | + 'contentUrl' => $this->content_url, |
|
| 89 | + 'embedUrl' => $this->embed_url, |
|
| 90 | + 'uploadDate' => $this->upload_date, |
|
| 91 | + 'thumbnailUrl' => $this->thumbnail_urls, |
|
| 92 | + 'duration' => $this->duration |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | \ No newline at end of file |
@@ -71,11 +71,11 @@ |
||
| 71 | 71 | */ |
| 72 | 72 | public $live_video_end_date; |
| 73 | 73 | |
| 74 | - public function from( $data ) { |
|
| 75 | - $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 74 | + public function from($data) { |
|
| 75 | + $keys = array_keys(get_class_vars(get_class($this))); |
|
| 76 | 76 | // Loop through the keys and set the value from array |
| 77 | - foreach ( $keys as $key ) { |
|
| 78 | - $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 77 | + foreach ($keys as $key) { |
|
| 78 | + $this->$key = array_key_exists($key, $data) ? $data[$key] : null; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -8,48 +8,48 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Video_Sitemap { |
| 10 | 10 | |
| 11 | - const CRON_ACTION_HOOK = 'wl_video_sitemap_generation'; |
|
| 11 | + const CRON_ACTION_HOOK = 'wl_video_sitemap_generation'; |
|
| 12 | 12 | |
| 13 | - public function init() { |
|
| 13 | + public function init() { |
|
| 14 | 14 | |
| 15 | - add_action( 'wordlift_generate_video_sitemap_on', array( $this, 'schedule_generation' ) ); |
|
| 15 | + add_action( 'wordlift_generate_video_sitemap_on', array( $this, 'schedule_generation' ) ); |
|
| 16 | 16 | |
| 17 | - add_action( self::CRON_ACTION_HOOK, array( $this, 'generate_video_sitemap' ) ); |
|
| 17 | + add_action( self::CRON_ACTION_HOOK, array( $this, 'generate_video_sitemap' ) ); |
|
| 18 | 18 | |
| 19 | - add_action( 'wordlift_generate_video_sitemap_off', array( $this, 'remove_scheduled_generation' ) ); |
|
| 19 | + add_action( 'wordlift_generate_video_sitemap_off', array( $this, 'remove_scheduled_generation' ) ); |
|
| 20 | 20 | |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function schedule_generation() { |
|
| 24 | - if ( ! wp_next_scheduled( self::CRON_ACTION_HOOK ) ) { |
|
| 25 | - wp_schedule_event( time(), 'daily', self::CRON_ACTION_HOOK ); |
|
| 26 | - } |
|
| 27 | - } |
|
| 23 | + public function schedule_generation() { |
|
| 24 | + if ( ! wp_next_scheduled( self::CRON_ACTION_HOOK ) ) { |
|
| 25 | + wp_schedule_event( time(), 'daily', self::CRON_ACTION_HOOK ); |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function generate_video_sitemap() { |
|
| 29 | + public function generate_video_sitemap() { |
|
| 30 | 30 | |
| 31 | - $sitemap_start_tag = <<<EOF |
|
| 31 | + $sitemap_start_tag = <<<EOF |
|
| 32 | 32 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" |
| 33 | 33 | xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> |
| 34 | 34 | EOF; |
| 35 | - $sitemap_body = Xml_Generator::get_xml_for_all_posts_with_videos(); |
|
| 35 | + $sitemap_body = Xml_Generator::get_xml_for_all_posts_with_videos(); |
|
| 36 | 36 | |
| 37 | - $sitemap_end_tag = "</urlset>"; |
|
| 37 | + $sitemap_end_tag = "</urlset>"; |
|
| 38 | 38 | |
| 39 | - $xml = $sitemap_start_tag . $sitemap_body . $sitemap_end_tag; |
|
| 39 | + $xml = $sitemap_start_tag . $sitemap_body . $sitemap_end_tag; |
|
| 40 | 40 | |
| 41 | - if ( ! defined( 'ABSPATH' ) ) { |
|
| 42 | - return; |
|
| 43 | - } |
|
| 41 | + if ( ! defined( 'ABSPATH' ) ) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - file_put_contents( ABSPATH . 'wl-video-sitemap.xml', $xml ); |
|
| 45 | + file_put_contents( ABSPATH . 'wl-video-sitemap.xml', $xml ); |
|
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function remove_scheduled_generation() { |
|
| 50 | - if ( wp_next_scheduled( self::CRON_ACTION_HOOK ) ) { |
|
| 51 | - wp_clear_scheduled_hook( self::CRON_ACTION_HOOK ); |
|
| 52 | - } |
|
| 53 | - } |
|
| 49 | + public function remove_scheduled_generation() { |
|
| 50 | + if ( wp_next_scheduled( self::CRON_ACTION_HOOK ) ) { |
|
| 51 | + wp_clear_scheduled_hook( self::CRON_ACTION_HOOK ); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -12,17 +12,17 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function init() { |
| 14 | 14 | |
| 15 | - add_action( 'wordlift_generate_video_sitemap_on', array( $this, 'schedule_generation' ) ); |
|
| 15 | + add_action('wordlift_generate_video_sitemap_on', array($this, 'schedule_generation')); |
|
| 16 | 16 | |
| 17 | - add_action( self::CRON_ACTION_HOOK, array( $this, 'generate_video_sitemap' ) ); |
|
| 17 | + add_action(self::CRON_ACTION_HOOK, array($this, 'generate_video_sitemap')); |
|
| 18 | 18 | |
| 19 | - add_action( 'wordlift_generate_video_sitemap_off', array( $this, 'remove_scheduled_generation' ) ); |
|
| 19 | + add_action('wordlift_generate_video_sitemap_off', array($this, 'remove_scheduled_generation')); |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function schedule_generation() { |
| 24 | - if ( ! wp_next_scheduled( self::CRON_ACTION_HOOK ) ) { |
|
| 25 | - wp_schedule_event( time(), 'daily', self::CRON_ACTION_HOOK ); |
|
| 24 | + if ( ! wp_next_scheduled(self::CRON_ACTION_HOOK)) { |
|
| 25 | + wp_schedule_event(time(), 'daily', self::CRON_ACTION_HOOK); |
|
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,23 +32,23 @@ discard block |
||
| 32 | 32 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" |
| 33 | 33 | xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> |
| 34 | 34 | EOF; |
| 35 | - $sitemap_body = Xml_Generator::get_xml_for_all_posts_with_videos(); |
|
| 35 | + $sitemap_body = Xml_Generator::get_xml_for_all_posts_with_videos(); |
|
| 36 | 36 | |
| 37 | 37 | $sitemap_end_tag = "</urlset>"; |
| 38 | 38 | |
| 39 | - $xml = $sitemap_start_tag . $sitemap_body . $sitemap_end_tag; |
|
| 39 | + $xml = $sitemap_start_tag.$sitemap_body.$sitemap_end_tag; |
|
| 40 | 40 | |
| 41 | - if ( ! defined( 'ABSPATH' ) ) { |
|
| 41 | + if ( ! defined('ABSPATH')) { |
|
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - file_put_contents( ABSPATH . 'wl-video-sitemap.xml', $xml ); |
|
| 45 | + file_put_contents(ABSPATH.'wl-video-sitemap.xml', $xml); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public function remove_scheduled_generation() { |
| 50 | - if ( wp_next_scheduled( self::CRON_ACTION_HOOK ) ) { |
|
| 51 | - wp_clear_scheduled_hook( self::CRON_ACTION_HOOK ); |
|
| 50 | + if (wp_next_scheduled(self::CRON_ACTION_HOOK)) { |
|
| 51 | + wp_clear_scheduled_hook(self::CRON_ACTION_HOOK); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |