@@ -8,11 +8,11 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | interface Parser { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @param int $post_id Post id |
|
| 13 | - * |
|
| 14 | - * @return array<Embedded_Video> |
|
| 15 | - */ |
|
| 16 | - public function get_videos( $post_id ); |
|
| 11 | + /** |
|
| 12 | + * @param int $post_id Post id |
|
| 13 | + * |
|
| 14 | + * @return array<Embedded_Video> |
|
| 15 | + */ |
|
| 16 | + public function get_videos( $post_id ); |
|
| 17 | 17 | |
| 18 | 18 | } |
@@ -13,6 +13,6 @@ |
||
| 13 | 13 | * |
| 14 | 14 | * @return array<Embedded_Video> |
| 15 | 15 | */ |
| 16 | - public function get_videos( $post_id ); |
|
| 16 | + public function get_videos($post_id); |
|
| 17 | 17 | |
| 18 | 18 | } |
@@ -7,31 +7,31 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Parser_Factory { |
| 9 | 9 | |
| 10 | - const BLOCK_EDITOR = 'block-editor'; |
|
| 10 | + const BLOCK_EDITOR = 'block-editor'; |
|
| 11 | 11 | |
| 12 | - const CLASSIC_EDITOR = 'classic-editor'; |
|
| 12 | + const CLASSIC_EDITOR = 'classic-editor'; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param $parser_config |
|
| 16 | - * |
|
| 17 | - * @return Parser |
|
| 18 | - */ |
|
| 19 | - public static function get_parser( $parser_config ) { |
|
| 20 | - if ( self::BLOCK_EDITOR === $parser_config ) { |
|
| 21 | - return new Block_Editor_Parser(); |
|
| 22 | - } else if ( self::CLASSIC_EDITOR === $parser_config ) { |
|
| 23 | - return new Classic_Editor_Parser(); |
|
| 24 | - } |
|
| 14 | + /** |
|
| 15 | + * @param $parser_config |
|
| 16 | + * |
|
| 17 | + * @return Parser |
|
| 18 | + */ |
|
| 19 | + public static function get_parser( $parser_config ) { |
|
| 20 | + if ( self::BLOCK_EDITOR === $parser_config ) { |
|
| 21 | + return new Block_Editor_Parser(); |
|
| 22 | + } else if ( self::CLASSIC_EDITOR === $parser_config ) { |
|
| 23 | + return new Classic_Editor_Parser(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - } |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public static function get_parser_from_content( $post_content ) { |
|
| 29 | - if ( function_exists( 'has_blocks' ) |
|
| 30 | - && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) { |
|
| 31 | - return self::get_parser( self::BLOCK_EDITOR ); |
|
| 32 | - } else { |
|
| 33 | - return self::get_parser( self::CLASSIC_EDITOR ); |
|
| 34 | - } |
|
| 35 | - } |
|
| 28 | + public static function get_parser_from_content( $post_content ) { |
|
| 29 | + if ( function_exists( 'has_blocks' ) |
|
| 30 | + && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) { |
|
| 31 | + return self::get_parser( self::BLOCK_EDITOR ); |
|
| 32 | + } else { |
|
| 33 | + return self::get_parser( self::CLASSIC_EDITOR ); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -16,21 +16,21 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @return Parser |
| 18 | 18 | */ |
| 19 | - public static function get_parser( $parser_config ) { |
|
| 20 | - if ( self::BLOCK_EDITOR === $parser_config ) { |
|
| 19 | + public static function get_parser($parser_config) { |
|
| 20 | + if (self::BLOCK_EDITOR === $parser_config) { |
|
| 21 | 21 | return new Block_Editor_Parser(); |
| 22 | - } else if ( self::CLASSIC_EDITOR === $parser_config ) { |
|
| 22 | + } else if (self::CLASSIC_EDITOR === $parser_config) { |
|
| 23 | 23 | return new Classic_Editor_Parser(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public static function get_parser_from_content( $post_content ) { |
|
| 29 | - if ( function_exists( 'has_blocks' ) |
|
| 30 | - && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) { |
|
| 31 | - return self::get_parser( self::BLOCK_EDITOR ); |
|
| 28 | + public static function get_parser_from_content($post_content) { |
|
| 29 | + if (function_exists('has_blocks') |
|
| 30 | + && function_exists('parse_blocks') && has_blocks($post_content)) { |
|
| 31 | + return self::get_parser(self::BLOCK_EDITOR); |
|
| 32 | 32 | } else { |
| 33 | - return self::get_parser( self::CLASSIC_EDITOR ); |
|
| 33 | + return self::get_parser(self::CLASSIC_EDITOR); |
|
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
@@ -11,52 +11,52 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Meta_Storage implements Storage { |
| 13 | 13 | |
| 14 | - const META_KEY = '_wl_video_object_videos'; |
|
| 14 | + const META_KEY = '_wl_video_object_videos'; |
|
| 15 | 15 | |
| 16 | - public function add_video( $post_id, $video ) { |
|
| 17 | - /** |
|
| 18 | - * @since 3.31.0 |
|
| 19 | - * Fires when the video storage gets updated |
|
| 20 | - */ |
|
| 21 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
| 22 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 23 | - } |
|
| 16 | + public function add_video( $post_id, $video ) { |
|
| 17 | + /** |
|
| 18 | + * @since 3.31.0 |
|
| 19 | + * Fires when the video storage gets updated |
|
| 20 | + */ |
|
| 21 | + do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
| 22 | + add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - public function get_all_videos( $post_id ) { |
|
| 26 | + public function get_all_videos( $post_id ) { |
|
| 27 | 27 | |
| 28 | - return get_post_meta( $post_id, self::META_KEY ); |
|
| 28 | + return get_post_meta( $post_id, self::META_KEY ); |
|
| 29 | 29 | |
| 30 | - } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 33 | - /** |
|
| 34 | - * @since 3.31.0 |
|
| 35 | - * Fires when the video storage gets updated |
|
| 36 | - */ |
|
| 37 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
| 38 | - $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 39 | - return $video->id; |
|
| 40 | - }, $videos_to_be_removed ); |
|
| 32 | + public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 33 | + /** |
|
| 34 | + * @since 3.31.0 |
|
| 35 | + * Fires when the video storage gets updated |
|
| 36 | + */ |
|
| 37 | + do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
| 38 | + $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 39 | + return $video->id; |
|
| 40 | + }, $videos_to_be_removed ); |
|
| 41 | 41 | |
| 42 | - $present_videos = $this->get_all_videos( $post_id ); |
|
| 42 | + $present_videos = $this->get_all_videos( $post_id ); |
|
| 43 | 43 | |
| 44 | - $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 45 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 46 | - } ); |
|
| 44 | + $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 45 | + return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 46 | + } ); |
|
| 47 | 47 | |
| 48 | - // Remove all existing videos. |
|
| 49 | - $this->remove_all_videos( $post_id ); |
|
| 48 | + // Remove all existing videos. |
|
| 49 | + $this->remove_all_videos( $post_id ); |
|
| 50 | 50 | |
| 51 | - // Save the remaining videos. |
|
| 52 | - foreach ( $filtered_videos as $video ) { |
|
| 53 | - $this->add_video( $post_id, $video ); |
|
| 54 | - } |
|
| 51 | + // Save the remaining videos. |
|
| 52 | + foreach ( $filtered_videos as $video ) { |
|
| 53 | + $this->add_video( $post_id, $video ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function remove_all_videos( $post_id ) { |
|
| 60 | - delete_post_meta( $post_id, self::META_KEY ); |
|
| 61 | - } |
|
| 59 | + public function remove_all_videos( $post_id ) { |
|
| 60 | + delete_post_meta( $post_id, self::META_KEY ); |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -13,50 +13,50 @@ |
||
| 13 | 13 | |
| 14 | 14 | const META_KEY = '_wl_video_object_videos'; |
| 15 | 15 | |
| 16 | - public function add_video( $post_id, $video ) { |
|
| 16 | + public function add_video($post_id, $video) { |
|
| 17 | 17 | /** |
| 18 | 18 | * @since 3.31.0 |
| 19 | 19 | * Fires when the video storage gets updated |
| 20 | 20 | */ |
| 21 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
| 22 | - add_post_meta( $post_id, self::META_KEY, $video ); |
|
| 21 | + do_action('wordlift_videoobject_video_storage_updated'); |
|
| 22 | + add_post_meta($post_id, self::META_KEY, $video); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - public function get_all_videos( $post_id ) { |
|
| 26 | + public function get_all_videos($post_id) { |
|
| 27 | 27 | |
| 28 | - return get_post_meta( $post_id, self::META_KEY ); |
|
| 28 | + return get_post_meta($post_id, self::META_KEY); |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function remove_videos( $videos_to_be_removed, $post_id ) { |
|
| 32 | + public function remove_videos($videos_to_be_removed, $post_id) { |
|
| 33 | 33 | /** |
| 34 | 34 | * @since 3.31.0 |
| 35 | 35 | * Fires when the video storage gets updated |
| 36 | 36 | */ |
| 37 | - do_action( 'wordlift_videoobject_video_storage_updated' ); |
|
| 38 | - $videos_to_be_removed_ids = array_map( function ( $video ) { |
|
| 37 | + do_action('wordlift_videoobject_video_storage_updated'); |
|
| 38 | + $videos_to_be_removed_ids = array_map(function($video) { |
|
| 39 | 39 | return $video->id; |
| 40 | - }, $videos_to_be_removed ); |
|
| 40 | + }, $videos_to_be_removed); |
|
| 41 | 41 | |
| 42 | - $present_videos = $this->get_all_videos( $post_id ); |
|
| 42 | + $present_videos = $this->get_all_videos($post_id); |
|
| 43 | 43 | |
| 44 | - $filtered_videos = array_filter( $present_videos, function ( $video ) use ( $videos_to_be_removed_ids ) { |
|
| 45 | - return ! in_array( $video->id, $videos_to_be_removed_ids ); |
|
| 44 | + $filtered_videos = array_filter($present_videos, function($video) use ($videos_to_be_removed_ids) { |
|
| 45 | + return ! in_array($video->id, $videos_to_be_removed_ids); |
|
| 46 | 46 | } ); |
| 47 | 47 | |
| 48 | 48 | // Remove all existing videos. |
| 49 | - $this->remove_all_videos( $post_id ); |
|
| 49 | + $this->remove_all_videos($post_id); |
|
| 50 | 50 | |
| 51 | 51 | // Save the remaining videos. |
| 52 | - foreach ( $filtered_videos as $video ) { |
|
| 53 | - $this->add_video( $post_id, $video ); |
|
| 52 | + foreach ($filtered_videos as $video) { |
|
| 53 | + $this->add_video($post_id, $video); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function remove_all_videos( $post_id ) { |
|
| 60 | - delete_post_meta( $post_id, self::META_KEY ); |
|
| 59 | + public function remove_all_videos($post_id) { |
|
| 60 | + delete_post_meta($post_id, self::META_KEY); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -4,56 +4,56 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Sync_State { |
| 6 | 6 | |
| 7 | - public $started; |
|
| 8 | - public $index; |
|
| 9 | - public $count; |
|
| 10 | - public $last_update; |
|
| 11 | - public $state; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * Sync_Model constructor. |
|
| 15 | - * |
|
| 16 | - * @param $started |
|
| 17 | - * @param $index |
|
| 18 | - * @param $count |
|
| 19 | - * @param $last_update |
|
| 20 | - * @param $state |
|
| 21 | - */ |
|
| 22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
| 23 | - $this->started = $started; |
|
| 24 | - $this->index = $index; |
|
| 25 | - $this->count = (int) $count; |
|
| 26 | - $this->last_update = $last_update; |
|
| 27 | - $this->state = $state; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function increment_index( $count ) { |
|
| 31 | - $this->index += $count; |
|
| 32 | - $this->last_update = time(); |
|
| 33 | - |
|
| 34 | - return $this; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function set_state( $value ) { |
|
| 38 | - $this->state = $value; |
|
| 39 | - $this->last_update = time(); |
|
| 40 | - |
|
| 41 | - return $this; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function get_array() { |
|
| 45 | - return array( |
|
| 46 | - 'started' => $this->started, |
|
| 47 | - 'index' => $this->index, |
|
| 48 | - 'count' => $this->count, |
|
| 49 | - 'last_update' => $this->last_update, |
|
| 50 | - 'state' => $this->state |
|
| 51 | - ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public static function unknown() { |
|
| 55 | - |
|
| 56 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
| 57 | - } |
|
| 7 | + public $started; |
|
| 8 | + public $index; |
|
| 9 | + public $count; |
|
| 10 | + public $last_update; |
|
| 11 | + public $state; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * Sync_Model constructor. |
|
| 15 | + * |
|
| 16 | + * @param $started |
|
| 17 | + * @param $index |
|
| 18 | + * @param $count |
|
| 19 | + * @param $last_update |
|
| 20 | + * @param $state |
|
| 21 | + */ |
|
| 22 | + public function __construct( $started, $index, $count, $last_update, $state ) { |
|
| 23 | + $this->started = $started; |
|
| 24 | + $this->index = $index; |
|
| 25 | + $this->count = (int) $count; |
|
| 26 | + $this->last_update = $last_update; |
|
| 27 | + $this->state = $state; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function increment_index( $count ) { |
|
| 31 | + $this->index += $count; |
|
| 32 | + $this->last_update = time(); |
|
| 33 | + |
|
| 34 | + return $this; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function set_state( $value ) { |
|
| 38 | + $this->state = $value; |
|
| 39 | + $this->last_update = time(); |
|
| 40 | + |
|
| 41 | + return $this; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function get_array() { |
|
| 45 | + return array( |
|
| 46 | + 'started' => $this->started, |
|
| 47 | + 'index' => $this->index, |
|
| 48 | + 'count' => $this->count, |
|
| 49 | + 'last_update' => $this->last_update, |
|
| 50 | + 'state' => $this->state |
|
| 51 | + ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public static function unknown() { |
|
| 55 | + |
|
| 56 | + return new self( time(), 0, 0, time(), 'unknown' ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @param $last_update |
| 20 | 20 | * @param $state |
| 21 | 21 | */ |
| 22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
| 22 | + public function __construct($started, $index, $count, $last_update, $state) { |
|
| 23 | 23 | $this->started = $started; |
| 24 | 24 | $this->index = $index; |
| 25 | 25 | $this->count = (int) $count; |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | $this->state = $state; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function increment_index( $count ) { |
|
| 31 | - $this->index += $count; |
|
| 30 | + public function increment_index($count) { |
|
| 31 | + $this->index += $count; |
|
| 32 | 32 | $this->last_update = time(); |
| 33 | 33 | |
| 34 | 34 | return $this; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public function set_state( $value ) { |
|
| 37 | + public function set_state($value) { |
|
| 38 | 38 | $this->state = $value; |
| 39 | 39 | $this->last_update = time(); |
| 40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | public static function unknown() { |
| 45 | 45 | |
| 46 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
| 46 | + return new self(time(), 0, 0, time(), 'unknown'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | \ No newline at end of file |
@@ -17,33 +17,33 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Post_Filter { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var Video_Processor |
|
| 22 | - */ |
|
| 23 | - private $video_processor; |
|
| 20 | + /** |
|
| 21 | + * @var Video_Processor |
|
| 22 | + */ |
|
| 23 | + private $video_processor; |
|
| 24 | 24 | |
| 25 | - public function __construct($video_processor) { |
|
| 26 | - $this->video_processor = $video_processor; |
|
| 27 | - } |
|
| 25 | + public function __construct($video_processor) { |
|
| 26 | + $this->video_processor = $video_processor; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function init() { |
|
| 30 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 3 ); |
|
| 31 | - } |
|
| 29 | + public function init() { |
|
| 30 | + add_action( 'save_post', array( $this, 'save_post' ), 10, 3 ); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param $post_id int |
|
| 35 | - * @param $post \WP_Post |
|
| 36 | - * @param $update bool |
|
| 37 | - */ |
|
| 38 | - public function save_post( $post_id, $post, $update ) { |
|
| 33 | + /** |
|
| 34 | + * @param $post_id int |
|
| 35 | + * @param $post \WP_Post |
|
| 36 | + * @param $update bool |
|
| 37 | + */ |
|
| 38 | + public function save_post( $post_id, $post, $update ) { |
|
| 39 | 39 | |
| 40 | - if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { |
|
| 41 | - return; |
|
| 42 | - } |
|
| 40 | + if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { |
|
| 41 | + return; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $this->video_processor->process_video_urls( $post, $post_id ); |
|
| 44 | + $this->video_processor->process_video_urls( $post, $post_id ); |
|
| 45 | 45 | |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function init() { |
| 30 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 3 ); |
|
| 30 | + add_action('save_post', array($this, 'save_post'), 10, 3); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | * @param $post \WP_Post |
| 36 | 36 | * @param $update bool |
| 37 | 37 | */ |
| 38 | - public function save_post( $post_id, $post, $update ) { |
|
| 38 | + public function save_post($post_id, $post, $update) { |
|
| 39 | 39 | |
| 40 | - if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { |
|
| 40 | + if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) { |
|
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $this->video_processor->process_video_urls( $post, $post_id ); |
|
| 44 | + $this->video_processor->process_video_urls($post, $post_id); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
@@ -12,163 +12,163 @@ |
||
| 12 | 12 | use WP_REST_Server; |
| 13 | 13 | |
| 14 | 14 | class Rest_Controller { |
| 15 | - /** |
|
| 16 | - * @var Videoobject_Background_Process |
|
| 17 | - */ |
|
| 18 | - private $background_process; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Rest_Controller constructor. |
|
| 22 | - * |
|
| 23 | - * @param $background_process Videoobject_Background_Process |
|
| 24 | - */ |
|
| 25 | - public function __construct( $background_process ) { |
|
| 26 | - $this->background_process = $background_process; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function register_all_routes() { |
|
| 30 | - $that = $this; |
|
| 31 | - add_action( 'rest_api_init', function () use ( $that ) { |
|
| 32 | - $that->register_get_all_videos_route(); |
|
| 33 | - $that->register_save_all_videos_route(); |
|
| 34 | - $that->register_get_sync_state_endpoint(); |
|
| 35 | - $that->register_background_process_start_endpoint(); |
|
| 36 | - $that->register_background_process_stop_endpoint(); |
|
| 37 | - } ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function get_all_videos( $request ) { |
|
| 41 | - $data = $request->get_params(); |
|
| 42 | - $post_id = (int) $data['post_id']; |
|
| 43 | - $storage = Video_Storage_Factory::get_storage(); |
|
| 44 | - |
|
| 45 | - return $storage->get_all_videos( $post_id ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function save_all_videos( $request ) { |
|
| 49 | - $data = $request->get_params(); |
|
| 50 | - $post_id = (int) $data['post_id']; |
|
| 51 | - $videos = (array) $data['videos']; |
|
| 52 | - if ( ! $videos ) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - $storage = Video_Storage_Factory::get_storage(); |
|
| 56 | - $storage->remove_all_videos( $post_id ); |
|
| 57 | - |
|
| 58 | - foreach ( $videos as $video ) { |
|
| 59 | - $video_obj = new Video(); |
|
| 60 | - $video_obj->from( (array) $video ); |
|
| 61 | - $storage->add_video( $post_id, $video_obj ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - private function register_get_all_videos_route() { |
|
| 68 | - register_rest_route( |
|
| 69 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 70 | - '/videos', |
|
| 71 | - array( |
|
| 72 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 73 | - 'callback' => array( $this, 'get_all_videos' ), |
|
| 74 | - 'permission_callback' => function () { |
|
| 75 | - return current_user_can( 'manage_options' ); |
|
| 76 | - }, |
|
| 77 | - 'args' => array( |
|
| 78 | - 'post_id' => array( |
|
| 79 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
| 80 | - return is_numeric( $param ) && $param; |
|
| 81 | - }, |
|
| 82 | - 'required' => true, |
|
| 83 | - ), |
|
| 84 | - ), |
|
| 85 | - ) |
|
| 86 | - ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - private function register_save_all_videos_route() { |
|
| 90 | - register_rest_route( |
|
| 91 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 92 | - '/videos/save', |
|
| 93 | - array( |
|
| 94 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 95 | - 'callback' => array( $this, 'save_all_videos' ), |
|
| 96 | - 'permission_callback' => function () { |
|
| 97 | - return current_user_can( 'manage_options' ); |
|
| 98 | - }, |
|
| 99 | - 'args' => array( |
|
| 100 | - 'post_id' => array( |
|
| 101 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
| 102 | - return is_numeric( $param ) && $param; |
|
| 103 | - }, |
|
| 104 | - 'required' => true, |
|
| 105 | - ), |
|
| 106 | - 'videos' => array( |
|
| 107 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
| 108 | - return is_array( $param ) && $param; |
|
| 109 | - }, |
|
| 110 | - 'required' => true, |
|
| 111 | - ), |
|
| 112 | - ), |
|
| 113 | - ) |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - public function register_get_sync_state_endpoint() { |
|
| 119 | - $that = $this; |
|
| 120 | - register_rest_route( |
|
| 121 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 122 | - '/videos/background/get_state', |
|
| 123 | - array( |
|
| 124 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 125 | - 'callback' => function () use ( $that ) { |
|
| 126 | - return $that->background_process->get_state()->get_array(); |
|
| 127 | - }, |
|
| 128 | - 'permission_callback' => function () { |
|
| 129 | - return current_user_can( 'manage_options' ); |
|
| 130 | - }, |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 133 | - |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function register_background_process_start_endpoint() { |
|
| 137 | - $that = $this; |
|
| 138 | - register_rest_route( |
|
| 139 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 140 | - '/videos/background/start', |
|
| 141 | - array( |
|
| 142 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 143 | - 'callback' => function () use ( $that ) { |
|
| 144 | - $that->background_process->start(); |
|
| 145 | - }, |
|
| 146 | - 'permission_callback' => function () { |
|
| 147 | - return current_user_can( 'manage_options' ); |
|
| 148 | - }, |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - public function register_background_process_stop_endpoint() { |
|
| 156 | - $that = $this; |
|
| 157 | - register_rest_route( |
|
| 158 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 159 | - '/videos/background/stop', |
|
| 160 | - array( |
|
| 161 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 162 | - 'callback' => function () use ( $that ) { |
|
| 163 | - $that->background_process->cancel(); |
|
| 164 | - }, |
|
| 165 | - 'permission_callback' => function () { |
|
| 166 | - return current_user_can( 'manage_options' ); |
|
| 167 | - }, |
|
| 168 | - ) |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - } |
|
| 15 | + /** |
|
| 16 | + * @var Videoobject_Background_Process |
|
| 17 | + */ |
|
| 18 | + private $background_process; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Rest_Controller constructor. |
|
| 22 | + * |
|
| 23 | + * @param $background_process Videoobject_Background_Process |
|
| 24 | + */ |
|
| 25 | + public function __construct( $background_process ) { |
|
| 26 | + $this->background_process = $background_process; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function register_all_routes() { |
|
| 30 | + $that = $this; |
|
| 31 | + add_action( 'rest_api_init', function () use ( $that ) { |
|
| 32 | + $that->register_get_all_videos_route(); |
|
| 33 | + $that->register_save_all_videos_route(); |
|
| 34 | + $that->register_get_sync_state_endpoint(); |
|
| 35 | + $that->register_background_process_start_endpoint(); |
|
| 36 | + $that->register_background_process_stop_endpoint(); |
|
| 37 | + } ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function get_all_videos( $request ) { |
|
| 41 | + $data = $request->get_params(); |
|
| 42 | + $post_id = (int) $data['post_id']; |
|
| 43 | + $storage = Video_Storage_Factory::get_storage(); |
|
| 44 | + |
|
| 45 | + return $storage->get_all_videos( $post_id ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function save_all_videos( $request ) { |
|
| 49 | + $data = $request->get_params(); |
|
| 50 | + $post_id = (int) $data['post_id']; |
|
| 51 | + $videos = (array) $data['videos']; |
|
| 52 | + if ( ! $videos ) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + $storage = Video_Storage_Factory::get_storage(); |
|
| 56 | + $storage->remove_all_videos( $post_id ); |
|
| 57 | + |
|
| 58 | + foreach ( $videos as $video ) { |
|
| 59 | + $video_obj = new Video(); |
|
| 60 | + $video_obj->from( (array) $video ); |
|
| 61 | + $storage->add_video( $post_id, $video_obj ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + private function register_get_all_videos_route() { |
|
| 68 | + register_rest_route( |
|
| 69 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 70 | + '/videos', |
|
| 71 | + array( |
|
| 72 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 73 | + 'callback' => array( $this, 'get_all_videos' ), |
|
| 74 | + 'permission_callback' => function () { |
|
| 75 | + return current_user_can( 'manage_options' ); |
|
| 76 | + }, |
|
| 77 | + 'args' => array( |
|
| 78 | + 'post_id' => array( |
|
| 79 | + 'validate_callback' => function ( $param, $request, $key ) { |
|
| 80 | + return is_numeric( $param ) && $param; |
|
| 81 | + }, |
|
| 82 | + 'required' => true, |
|
| 83 | + ), |
|
| 84 | + ), |
|
| 85 | + ) |
|
| 86 | + ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + private function register_save_all_videos_route() { |
|
| 90 | + register_rest_route( |
|
| 91 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 92 | + '/videos/save', |
|
| 93 | + array( |
|
| 94 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 95 | + 'callback' => array( $this, 'save_all_videos' ), |
|
| 96 | + 'permission_callback' => function () { |
|
| 97 | + return current_user_can( 'manage_options' ); |
|
| 98 | + }, |
|
| 99 | + 'args' => array( |
|
| 100 | + 'post_id' => array( |
|
| 101 | + 'validate_callback' => function ( $param, $request, $key ) { |
|
| 102 | + return is_numeric( $param ) && $param; |
|
| 103 | + }, |
|
| 104 | + 'required' => true, |
|
| 105 | + ), |
|
| 106 | + 'videos' => array( |
|
| 107 | + 'validate_callback' => function ( $param, $request, $key ) { |
|
| 108 | + return is_array( $param ) && $param; |
|
| 109 | + }, |
|
| 110 | + 'required' => true, |
|
| 111 | + ), |
|
| 112 | + ), |
|
| 113 | + ) |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + public function register_get_sync_state_endpoint() { |
|
| 119 | + $that = $this; |
|
| 120 | + register_rest_route( |
|
| 121 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 122 | + '/videos/background/get_state', |
|
| 123 | + array( |
|
| 124 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 125 | + 'callback' => function () use ( $that ) { |
|
| 126 | + return $that->background_process->get_state()->get_array(); |
|
| 127 | + }, |
|
| 128 | + 'permission_callback' => function () { |
|
| 129 | + return current_user_can( 'manage_options' ); |
|
| 130 | + }, |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function register_background_process_start_endpoint() { |
|
| 137 | + $that = $this; |
|
| 138 | + register_rest_route( |
|
| 139 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 140 | + '/videos/background/start', |
|
| 141 | + array( |
|
| 142 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 143 | + 'callback' => function () use ( $that ) { |
|
| 144 | + $that->background_process->start(); |
|
| 145 | + }, |
|
| 146 | + 'permission_callback' => function () { |
|
| 147 | + return current_user_can( 'manage_options' ); |
|
| 148 | + }, |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + public function register_background_process_stop_endpoint() { |
|
| 156 | + $that = $this; |
|
| 157 | + register_rest_route( |
|
| 158 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 159 | + '/videos/background/stop', |
|
| 160 | + array( |
|
| 161 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 162 | + 'callback' => function () use ( $that ) { |
|
| 163 | + $that->background_process->cancel(); |
|
| 164 | + }, |
|
| 165 | + 'permission_callback' => function () { |
|
| 166 | + return current_user_can( 'manage_options' ); |
|
| 167 | + }, |
|
| 168 | + ) |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | } |
| 175 | 175 | \ No newline at end of file |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param $background_process Videoobject_Background_Process |
| 24 | 24 | */ |
| 25 | - public function __construct( $background_process ) { |
|
| 25 | + public function __construct($background_process) { |
|
| 26 | 26 | $this->background_process = $background_process; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function register_all_routes() { |
| 30 | 30 | $that = $this; |
| 31 | - add_action( 'rest_api_init', function () use ( $that ) { |
|
| 31 | + add_action('rest_api_init', function() use ($that) { |
|
| 32 | 32 | $that->register_get_all_videos_route(); |
| 33 | 33 | $that->register_save_all_videos_route(); |
| 34 | 34 | $that->register_get_sync_state_endpoint(); |
@@ -37,28 +37,28 @@ discard block |
||
| 37 | 37 | } ); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function get_all_videos( $request ) { |
|
| 40 | + public function get_all_videos($request) { |
|
| 41 | 41 | $data = $request->get_params(); |
| 42 | 42 | $post_id = (int) $data['post_id']; |
| 43 | 43 | $storage = Video_Storage_Factory::get_storage(); |
| 44 | 44 | |
| 45 | - return $storage->get_all_videos( $post_id ); |
|
| 45 | + return $storage->get_all_videos($post_id); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function save_all_videos( $request ) { |
|
| 48 | + public function save_all_videos($request) { |
|
| 49 | 49 | $data = $request->get_params(); |
| 50 | 50 | $post_id = (int) $data['post_id']; |
| 51 | 51 | $videos = (array) $data['videos']; |
| 52 | - if ( ! $videos ) { |
|
| 52 | + if ( ! $videos) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | $storage = Video_Storage_Factory::get_storage(); |
| 56 | - $storage->remove_all_videos( $post_id ); |
|
| 56 | + $storage->remove_all_videos($post_id); |
|
| 57 | 57 | |
| 58 | - foreach ( $videos as $video ) { |
|
| 58 | + foreach ($videos as $video) { |
|
| 59 | 59 | $video_obj = new Video(); |
| 60 | - $video_obj->from( (array) $video ); |
|
| 61 | - $storage->add_video( $post_id, $video_obj ); |
|
| 60 | + $video_obj->from((array) $video); |
|
| 61 | + $storage->add_video($post_id, $video_obj); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | '/videos', |
| 71 | 71 | array( |
| 72 | 72 | 'methods' => WP_REST_Server::CREATABLE, |
| 73 | - 'callback' => array( $this, 'get_all_videos' ), |
|
| 74 | - 'permission_callback' => function () { |
|
| 75 | - return current_user_can( 'manage_options' ); |
|
| 73 | + 'callback' => array($this, 'get_all_videos'), |
|
| 74 | + 'permission_callback' => function() { |
|
| 75 | + return current_user_can('manage_options'); |
|
| 76 | 76 | }, |
| 77 | 77 | 'args' => array( |
| 78 | 78 | 'post_id' => array( |
| 79 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
| 80 | - return is_numeric( $param ) && $param; |
|
| 79 | + 'validate_callback' => function($param, $request, $key) { |
|
| 80 | + return is_numeric($param) && $param; |
|
| 81 | 81 | }, |
| 82 | 82 | 'required' => true, |
| 83 | 83 | ), |
@@ -92,20 +92,20 @@ discard block |
||
| 92 | 92 | '/videos/save', |
| 93 | 93 | array( |
| 94 | 94 | 'methods' => WP_REST_Server::CREATABLE, |
| 95 | - 'callback' => array( $this, 'save_all_videos' ), |
|
| 96 | - 'permission_callback' => function () { |
|
| 97 | - return current_user_can( 'manage_options' ); |
|
| 95 | + 'callback' => array($this, 'save_all_videos'), |
|
| 96 | + 'permission_callback' => function() { |
|
| 97 | + return current_user_can('manage_options'); |
|
| 98 | 98 | }, |
| 99 | 99 | 'args' => array( |
| 100 | 100 | 'post_id' => array( |
| 101 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
| 102 | - return is_numeric( $param ) && $param; |
|
| 101 | + 'validate_callback' => function($param, $request, $key) { |
|
| 102 | + return is_numeric($param) && $param; |
|
| 103 | 103 | }, |
| 104 | 104 | 'required' => true, |
| 105 | 105 | ), |
| 106 | 106 | 'videos' => array( |
| 107 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
| 108 | - return is_array( $param ) && $param; |
|
| 107 | + 'validate_callback' => function($param, $request, $key) { |
|
| 108 | + return is_array($param) && $param; |
|
| 109 | 109 | }, |
| 110 | 110 | 'required' => true, |
| 111 | 111 | ), |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | '/videos/background/get_state', |
| 123 | 123 | array( |
| 124 | 124 | 'methods' => WP_REST_Server::CREATABLE, |
| 125 | - 'callback' => function () use ( $that ) { |
|
| 125 | + 'callback' => function() use ($that) { |
|
| 126 | 126 | return $that->background_process->get_state()->get_array(); |
| 127 | 127 | }, |
| 128 | - 'permission_callback' => function () { |
|
| 129 | - return current_user_can( 'manage_options' ); |
|
| 128 | + 'permission_callback' => function() { |
|
| 129 | + return current_user_can('manage_options'); |
|
| 130 | 130 | }, |
| 131 | 131 | ) |
| 132 | 132 | ); |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | '/videos/background/start', |
| 141 | 141 | array( |
| 142 | 142 | 'methods' => WP_REST_Server::CREATABLE, |
| 143 | - 'callback' => function () use ( $that ) { |
|
| 143 | + 'callback' => function() use ($that) { |
|
| 144 | 144 | $that->background_process->start(); |
| 145 | 145 | }, |
| 146 | - 'permission_callback' => function () { |
|
| 147 | - return current_user_can( 'manage_options' ); |
|
| 146 | + 'permission_callback' => function() { |
|
| 147 | + return current_user_can('manage_options'); |
|
| 148 | 148 | }, |
| 149 | 149 | ) |
| 150 | 150 | ); |
@@ -159,11 +159,11 @@ discard block |
||
| 159 | 159 | '/videos/background/stop', |
| 160 | 160 | array( |
| 161 | 161 | 'methods' => WP_REST_Server::CREATABLE, |
| 162 | - 'callback' => function () use ( $that ) { |
|
| 162 | + 'callback' => function() use ($that) { |
|
| 163 | 163 | $that->background_process->cancel(); |
| 164 | 164 | }, |
| 165 | - 'permission_callback' => function () { |
|
| 166 | - return current_user_can( 'manage_options' ); |
|
| 165 | + 'permission_callback' => function() { |
|
| 166 | + return current_user_can('manage_options'); |
|
| 167 | 167 | }, |
| 168 | 168 | ) |
| 169 | 169 | ); |
@@ -6,40 +6,40 @@ |
||
| 6 | 6 | use Wordlift\Videoobject\Video_Processor; |
| 7 | 7 | |
| 8 | 8 | class Videoobject_Background_Process extends Background_Process { |
| 9 | - /** |
|
| 10 | - * @var Video_Processor |
|
| 11 | - */ |
|
| 12 | - private $video_processor; |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Videoobject_Background_Process constructor. |
|
| 16 | - * |
|
| 17 | - * @param $video_processor Video_Processor |
|
| 18 | - * @param $data_source |
|
| 19 | - */ |
|
| 20 | - public function __construct( $video_processor, $data_source ) { |
|
| 21 | - $this->video_processor = $video_processor; |
|
| 22 | - parent::__construct( $data_source ); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - protected function get_state_storage_key() { |
|
| 26 | - return '__wl_videoobject_import_state'; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - protected function get_action_key() { |
|
| 30 | - return 'wl_videoobject_import_background_action'; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param $items |
|
| 35 | - * |
|
| 36 | - * @return bool|void |
|
| 37 | - */ |
|
| 38 | - protected function process_items( $items ) { |
|
| 39 | - foreach ( $items as $item ) { |
|
| 40 | - $this->video_processor->process_video_urls( get_post( $item ), $item ); |
|
| 41 | - } |
|
| 42 | - return true; |
|
| 43 | - } |
|
| 9 | + /** |
|
| 10 | + * @var Video_Processor |
|
| 11 | + */ |
|
| 12 | + private $video_processor; |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Videoobject_Background_Process constructor. |
|
| 16 | + * |
|
| 17 | + * @param $video_processor Video_Processor |
|
| 18 | + * @param $data_source |
|
| 19 | + */ |
|
| 20 | + public function __construct( $video_processor, $data_source ) { |
|
| 21 | + $this->video_processor = $video_processor; |
|
| 22 | + parent::__construct( $data_source ); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + protected function get_state_storage_key() { |
|
| 26 | + return '__wl_videoobject_import_state'; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + protected function get_action_key() { |
|
| 30 | + return 'wl_videoobject_import_background_action'; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param $items |
|
| 35 | + * |
|
| 36 | + * @return bool|void |
|
| 37 | + */ |
|
| 38 | + protected function process_items( $items ) { |
|
| 39 | + foreach ( $items as $item ) { |
|
| 40 | + $this->video_processor->process_video_urls( get_post( $item ), $item ); |
|
| 41 | + } |
|
| 42 | + return true; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | } |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | * @param $video_processor Video_Processor |
| 18 | 18 | * @param $data_source |
| 19 | 19 | */ |
| 20 | - public function __construct( $video_processor, $data_source ) { |
|
| 20 | + public function __construct($video_processor, $data_source) { |
|
| 21 | 21 | $this->video_processor = $video_processor; |
| 22 | - parent::__construct( $data_source ); |
|
| 22 | + parent::__construct($data_source); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | protected function get_state_storage_key() { |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return bool|void |
| 37 | 37 | */ |
| 38 | - protected function process_items( $items ) { |
|
| 39 | - foreach ( $items as $item ) { |
|
| 40 | - $this->video_processor->process_video_urls( get_post( $item ), $item ); |
|
| 38 | + protected function process_items($items) { |
|
| 39 | + foreach ($items as $item) { |
|
| 40 | + $this->video_processor->process_video_urls(get_post($item), $item); |
|
| 41 | 41 | } |
| 42 | 42 | return true; |
| 43 | 43 | } |
@@ -3,44 +3,44 @@ |
||
| 3 | 3 | |
| 4 | 4 | abstract class Data_Source { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * @var string The key which is provided to the background process |
|
| 8 | - * in order to retrieve its state, it should be the same as the one provided to |
|
| 9 | - * background process. |
|
| 10 | - */ |
|
| 11 | - private $state_storage_key; |
|
| 12 | - |
|
| 13 | - public function __construct( $state_storage_key ) { |
|
| 14 | - $this->state_storage_key = $state_storage_key; |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * A list of item ids. |
|
| 19 | - * @return int[] |
|
| 20 | - */ |
|
| 21 | - abstract public function next(); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The count of total items which needs to be processed. |
|
| 25 | - * @return int[] |
|
| 26 | - */ |
|
| 27 | - abstract public function count(); |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * A numerical value indicating how many items should be processed per |
|
| 31 | - * background call. |
|
| 32 | - * @return int |
|
| 33 | - */ |
|
| 34 | - abstract public function get_batch_size(); |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - public function get_state() { |
|
| 38 | - try { |
|
| 39 | - return get_option( $this->state_storage_key, Sync_State::unknown() ); |
|
| 40 | - } catch ( \Exception $e ) { |
|
| 41 | - return Sync_State::unknown(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - } |
|
| 6 | + /** |
|
| 7 | + * @var string The key which is provided to the background process |
|
| 8 | + * in order to retrieve its state, it should be the same as the one provided to |
|
| 9 | + * background process. |
|
| 10 | + */ |
|
| 11 | + private $state_storage_key; |
|
| 12 | + |
|
| 13 | + public function __construct( $state_storage_key ) { |
|
| 14 | + $this->state_storage_key = $state_storage_key; |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * A list of item ids. |
|
| 19 | + * @return int[] |
|
| 20 | + */ |
|
| 21 | + abstract public function next(); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The count of total items which needs to be processed. |
|
| 25 | + * @return int[] |
|
| 26 | + */ |
|
| 27 | + abstract public function count(); |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * A numerical value indicating how many items should be processed per |
|
| 31 | + * background call. |
|
| 32 | + * @return int |
|
| 33 | + */ |
|
| 34 | + abstract public function get_batch_size(); |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + public function get_state() { |
|
| 38 | + try { |
|
| 39 | + return get_option( $this->state_storage_key, Sync_State::unknown() ); |
|
| 40 | + } catch ( \Exception $e ) { |
|
| 41 | + return Sync_State::unknown(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | private $state_storage_key; |
| 12 | 12 | |
| 13 | - public function __construct( $state_storage_key ) { |
|
| 13 | + public function __construct($state_storage_key) { |
|
| 14 | 14 | $this->state_storage_key = $state_storage_key; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function get_state() { |
| 38 | 38 | try { |
| 39 | - return get_option( $this->state_storage_key, Sync_State::unknown() ); |
|
| 40 | - } catch ( \Exception $e ) { |
|
| 39 | + return get_option($this->state_storage_key, Sync_State::unknown()); |
|
| 40 | + } catch (\Exception $e) { |
|
| 41 | 41 | return Sync_State::unknown(); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -24,26 +24,26 @@ |
||
| 24 | 24 | |
| 25 | 25 | public function init_all_dependencies() { |
| 26 | 26 | $video_storage = Video_Storage_Factory::get_storage(); |
| 27 | - new Jsonld( $video_storage ); |
|
| 27 | + new Jsonld($video_storage); |
|
| 28 | 28 | |
| 29 | - $sitemap_cache = new Ttl_Cache( "wl_video_sitemap", 86400 ); |
|
| 29 | + $sitemap_cache = new Ttl_Cache("wl_video_sitemap", 86400); |
|
| 30 | 30 | |
| 31 | 31 | $video_processor = new Video_Processor(); |
| 32 | 32 | // Hook in to save_post to save the videos |
| 33 | - $post_filter = new Post_Filter( $video_processor ); |
|
| 33 | + $post_filter = new Post_Filter($video_processor); |
|
| 34 | 34 | $post_filter->init(); |
| 35 | 35 | // Add entry to wordlift admin tabs |
| 36 | 36 | $settings_tab = new Settings_Tab(); |
| 37 | 37 | $settings_tab->init(); |
| 38 | 38 | |
| 39 | 39 | |
| 40 | - $video_sitemap = new Video_Sitemap( $sitemap_cache ); |
|
| 40 | + $video_sitemap = new Video_Sitemap($sitemap_cache); |
|
| 41 | 41 | $video_sitemap->init(); |
| 42 | 42 | |
| 43 | - $background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' ); |
|
| 44 | - $background_process = new Videoobject_Background_Process( $video_processor, $background_process_data_source ); |
|
| 43 | + $background_process_data_source = new Videos_Data_Source('__wl_videoobject_import_state'); |
|
| 44 | + $background_process = new Videoobject_Background_Process($video_processor, $background_process_data_source); |
|
| 45 | 45 | |
| 46 | - $rest_controller = new Rest_Controller( $background_process ); |
|
| 46 | + $rest_controller = new Rest_Controller($background_process); |
|
| 47 | 47 | $rest_controller->register_all_routes(); |
| 48 | 48 | |
| 49 | 49 | $post_edit_screen = new Post_Edit_Screen(); |
@@ -24,57 +24,57 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Loader extends Default_Loader { |
| 26 | 26 | |
| 27 | - public function init_all_dependencies() { |
|
| 28 | - $video_storage = Video_Storage_Factory::get_storage(); |
|
| 29 | - new Jsonld( $video_storage ); |
|
| 27 | + public function init_all_dependencies() { |
|
| 28 | + $video_storage = Video_Storage_Factory::get_storage(); |
|
| 29 | + new Jsonld( $video_storage ); |
|
| 30 | 30 | |
| 31 | - $sitemap_cache = new Ttl_Cache( "wl_video_sitemap", 86400 ); |
|
| 31 | + $sitemap_cache = new Ttl_Cache( "wl_video_sitemap", 86400 ); |
|
| 32 | 32 | |
| 33 | - $video_processor = new Video_Processor(); |
|
| 34 | - // Hook in to save_post to save the videos |
|
| 35 | - $post_filter = new Post_Filter( $video_processor ); |
|
| 36 | - $post_filter->init(); |
|
| 37 | - // Add entry to wordlift admin tabs |
|
| 38 | - $settings_tab = new Settings_Tab(); |
|
| 39 | - $settings_tab->init(); |
|
| 33 | + $video_processor = new Video_Processor(); |
|
| 34 | + // Hook in to save_post to save the videos |
|
| 35 | + $post_filter = new Post_Filter( $video_processor ); |
|
| 36 | + $post_filter->init(); |
|
| 37 | + // Add entry to wordlift admin tabs |
|
| 38 | + $settings_tab = new Settings_Tab(); |
|
| 39 | + $settings_tab->init(); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - $video_sitemap = new Video_Sitemap( $sitemap_cache ); |
|
| 43 | - $video_sitemap->init(); |
|
| 42 | + $video_sitemap = new Video_Sitemap( $sitemap_cache ); |
|
| 43 | + $video_sitemap->init(); |
|
| 44 | 44 | |
| 45 | - $background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' ); |
|
| 46 | - $background_process = new Videoobject_Background_Process( $video_processor, $background_process_data_source ); |
|
| 45 | + $background_process_data_source = new Videos_Data_Source( '__wl_videoobject_import_state' ); |
|
| 46 | + $background_process = new Videoobject_Background_Process( $video_processor, $background_process_data_source ); |
|
| 47 | 47 | |
| 48 | - $rest_controller = new Rest_Controller( $background_process ); |
|
| 49 | - $rest_controller->register_all_routes(); |
|
| 48 | + $rest_controller = new Rest_Controller( $background_process ); |
|
| 49 | + $rest_controller->register_all_routes(); |
|
| 50 | 50 | |
| 51 | - $post_edit_screen = new Post_Edit_Screen(); |
|
| 52 | - $post_edit_screen->init(); |
|
| 51 | + $post_edit_screen = new Post_Edit_Screen(); |
|
| 52 | + $post_edit_screen->init(); |
|
| 53 | 53 | |
| 54 | - new Import_Videos_Page(); |
|
| 54 | + new Import_Videos_Page(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @since 3.32.0 |
|
| 58 | - * Allow videoobject to capture embed shortcode. |
|
| 59 | - */ |
|
| 60 | - $embed_shortcode_capture = new Embed_Shortcode_Capture(); |
|
| 61 | - $embed_shortcode_capture->init(); |
|
| 56 | + /** |
|
| 57 | + * @since 3.32.0 |
|
| 58 | + * Allow videoobject to capture embed shortcode. |
|
| 59 | + */ |
|
| 60 | + $embed_shortcode_capture = new Embed_Shortcode_Capture(); |
|
| 61 | + $embed_shortcode_capture->init(); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @since 3.32.0 |
|
| 66 | - * Get videos from jw player. |
|
| 67 | - */ |
|
| 68 | - $jw_player_capture_videos = new Jw_Player_Capture(); |
|
| 69 | - $jw_player_capture_videos->init(); |
|
| 64 | + /** |
|
| 65 | + * @since 3.32.0 |
|
| 66 | + * Get videos from jw player. |
|
| 67 | + */ |
|
| 68 | + $jw_player_capture_videos = new Jw_Player_Capture(); |
|
| 69 | + $jw_player_capture_videos->init(); |
|
| 70 | 70 | |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function get_feature_slug() { |
|
| 74 | - return 'videoobject'; |
|
| 75 | - } |
|
| 73 | + public function get_feature_slug() { |
|
| 74 | + return 'videoobject'; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function get_feature_default_value() { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 77 | + public function get_feature_default_value() { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | 80 | } |
| 81 | 81 | \ No newline at end of file |