From bfea0ad014bfc0748002df077305453894ec3584 Mon Sep 17 00:00:00 2001 From: Michal Date: Wed, 21 Dec 2022 14:30:16 +0100 Subject: [PATCH 1/6] editor: convert links & shortcodes to db --- controller/editor.php | 66 +++- controller/shortcodes.php | 342 ++++++++++---------- models/conversion/conversion-base.class.php | 4 +- models/conversion/shortcode2DB.class.php | 3 +- view/admin.php | 1 + 5 files changed, 234 insertions(+), 182 deletions(-) diff --git a/controller/editor.php b/controller/editor.php index a2c83e208..019ed4982 100755 --- a/controller/editor.php +++ b/controller/editor.php @@ -533,18 +533,74 @@ function getTitleFromUrl($url) { ); } - header('Content-Type: application/json'); + header('Content-Type: application/json'); echo json_encode($jsonReturn); - wp_die(); + wp_die(); } -/* -Elementor support -*/ +add_filter( 'save_post', 'fv_wp_flowplayer_convert_to_db', 9, 3 ); + +/** + * Convert shortcodes and links to DB on save + * + * @param int $post_id + * @param WP_Post $post + * @param bool $update + * + * @return void + */ +function fv_wp_flowplayer_convert_to_db($post_id, $post, $update) { + global $wp_embed, $fv_fp, $FV_Player_Shortcode2Database_Conversion; + + // check if not quick edit + if( !isset($_POST['action']) || (isset($_POST['action']) && $_POST['action'] != 'editpost') ) return; + + // check if option is enabled + if( !$fv_fp->_get_option('convert_db_save') ) return; + + // ignore revision + if ( wp_is_post_revision( $post_id ) ) return; + + // ignore trash + if ( $post->post_status === 'trash' ) return; + + $new_content = $post->post_content; + + // if( is_serialized($new_content) ) return; // TODO: is something serializing content? + + // convert links to embed + $new_content = $wp_embed->autoembed( $new_content ); + + // convert iframe/video tags to src shortcodes + $new_content = fv_player_handle_video_tags($new_content); + $new_content = fv_player_handle_youtube_links($new_content); + $new_content = fv_player_handle_vimeo_links($new_content); + + $post->post_content = $new_content; + + $FV_Player_Shortcode2Database_Conversion->set_live = true; + + // convert src shortcodes to db + $new_content_data = $FV_Player_Shortcode2Database_Conversion->convert_one($post); + if( $new_content_data['content_updated'] ) { + $new_content = $new_content_data['new_content']; + } + + // remove current action to prevent infinite loop when using wp_update_post + remove_action( 'save_post', 'fv_wp_flowplayer_convert_to_db', 9 ); + wp_update_post( array( 'ID' => $post->ID, 'post_content' => $new_content ) ); +} + + + + +/** + * Elementor support + */ add_action( 'elementor/editor/wp_head', 'fv_player_shortcode_editor_scripts_enqueue' ); add_action( 'elementor/editor/wp_head', 'fv_wp_flowplayer_edit_form_after_editor' ); add_action( 'elementor/editor/wp_head', 'flowplayer_prepare_scripts' ); diff --git a/controller/shortcodes.php b/controller/shortcodes.php index 0bff12748..eb4152464 100644 --- a/controller/shortcodes.php +++ b/controller/shortcodes.php @@ -311,7 +311,7 @@ function fv_flowplayer_optimizepress_bridge( $input ) { function fv_player_time( $args = array() ) { global $post, $fv_fp; - + if( !empty($args['id']) ) { $player = new FV_Player_Db_Player($args['id']); if( $player->getIsValid() ) { @@ -331,210 +331,202 @@ function fv_player_time( $args = array() ) { } -global $fv_fp; -if( ( empty($_POST['action']) || $_POST['action'] != 'parse-media-shortcode' ) && ( empty($_GET['action']) || $_GET['action'] != 'edit' ) && !empty($fv_fp->conf['integrations']['wp_core_video']) && $fv_fp->conf['integrations']['wp_core_video'] == 'true' ) { - - function fv_flowplayer_shortcode_video( $output ) { - $aArgs = func_get_args(); - $atts = $aArgs[1]; - - $bridge_atts = array(); - if( isset($atts['src']) ) { - $bridge_atts['src'] = $atts['src']; - } - - $count = 0; - foreach( array('mp4','webm','ogv','mov','flv','wmv','m4v','mp3') AS $key => $value ) { - if( !empty($atts[$value]) ) { - $src = 'src'.(( $count > 0 ) ? $count : ''); - $bridge_atts[$src] = $atts[$value]; - $count++; - } - } - - if( isset($atts['poster']) ) { - $bridge_atts['splash'] = $atts['poster']; - } - - if( isset($atts['loop']) && $atts['loop'] == 'on' ) { - $bridge_atts['loop'] = 'true'; - } else if( isset($atts['loop']) && $atts['loop'] == 'off' ) { - $bridge_atts['loop'] = 'false'; - } - - if( isset($atts['autoplay']) && $atts['autoplay'] == 'on' ) { - $bridge_atts['autoplay'] = 'true'; - } else if( isset($atts['loop']) && $atts['loop'] == 'off' ) { - $bridge_atts['autoplay'] = 'false'; - } - - if( isset($atts['width']) ) { - $bridge_atts['width'] = $atts['width']; - } - if( isset($atts['height']) ) { - $bridge_atts['height'] = $atts['height']; - } - - if( count($bridge_atts) == 0 ) { - return ""; +function fv_player_handle_vimeo_links( $html ) { + $html = preg_replace( '~]*?vimeo\.com/video/(\d+)[^>]*?(\?h=[a-z0-9]+)?[^>]*?>~', '[fvplayer src="http://vimeo.com/$1$2"]', $html ); + return $html; +} + +function fv_player_handle_youtube_links( $html ) { + $html = preg_replace( '~]*?youtube(?:-nocookie)?\.com/(?:embed|v)/(.*?)[\'"&#\?][^>]*?>~', '[fvplayer src="http://youtube.com/watch?v=$1"]', $html ); + return $html; +} + +function fv_player_handle_video_tags( $html ) { + $html = preg_replace( '~
]*?src\s*=\s*"(.+?)"[^>]*?>
~', '
[fvplayer src="$1"]
' , $html); + return $html; +} + +function fv_flowplayer_shortcode_video( $output ) { + $aArgs = func_get_args(); + $atts = $aArgs[1]; + + $bridge_atts = array(); + if( isset($atts['src']) ) { + $bridge_atts['src'] = $atts['src']; + } + + $count = 0; + foreach( array('mp4','webm','ogv','mov','flv','wmv','m4v','mp3') AS $key => $value ) { + if( !empty($atts[$value]) ) { + $src = 'src'.(( $count > 0 ) ? $count : ''); + $bridge_atts[$src] = $atts[$value]; + $count++; } - return flowplayer_content_handle( $bridge_atts, false, 'video' ); } - add_filter( 'wp_video_shortcode_override', 'fv_flowplayer_shortcode_video', 10, 4 ); - add_filter( 'wp_audio_shortcode_override', 'fv_flowplayer_shortcode_video', 10, 4 ); + if( isset($atts['poster']) ) { + $bridge_atts['splash'] = $atts['poster']; + } + if( isset($atts['loop']) && $atts['loop'] == 'on' ) { + $bridge_atts['loop'] = 'true'; + } else if( isset($atts['loop']) && $atts['loop'] == 'off' ) { + $bridge_atts['loop'] = 'false'; + } + if( isset($atts['autoplay']) && $atts['autoplay'] == 'on' ) { + $bridge_atts['autoplay'] = 'true'; + } else if( isset($atts['loop']) && $atts['loop'] == 'off' ) { + $bridge_atts['autoplay'] = 'false'; + } + if( isset($atts['width']) ) { + $bridge_atts['width'] = $atts['width']; + } + if( isset($atts['height']) ) { + $bridge_atts['height'] = $atts['height']; + } - function fv_flowplayer_shortcode_playlist( $output ) { - $aArgs = func_get_args(); - $atts = $aArgs[1]; + if( count($bridge_atts) == 0 ) { + return ""; + } + return flowplayer_content_handle( $bridge_atts, false, 'video' ); +} - // copy from wp-includes/media.php wp_playlist_shortcode() - global $post; - if ( ! empty( $attr['ids'] ) ) { - // 'ids' is explicitly ordered, unless you specify otherwise. - if ( empty( $attr['orderby'] ) ) { - $attr['orderby'] = 'post__in'; - } - $attr['include'] = $attr['ids']; - } - - $atts = shortcode_atts( array( - 'type' => 'audio', - 'order' => 'ASC', - 'orderby' => 'menu_order ID', - 'id' => $post ? $post->ID : 0, - 'include' => '', - 'exclude' => '', - 'style' => 'light', - 'tracklist' => true, - 'tracknumbers' => true, - 'images' => true, - 'artists' => true - ), $atts, 'playlist' ); - - $args = array( - 'post_status' => 'inherit', - 'post_type' => 'attachment', - 'post_mime_type' => $atts['type'], - 'order' => $atts['order'], - 'orderby' => $atts['orderby'] - ); +function fv_flowplayer_shortcode_playlist( $output ) { + $aArgs = func_get_args(); + $atts = $aArgs[1]; + + // copy from wp-includes/media.php wp_playlist_shortcode() + global $post; + if ( ! empty( $attr['ids'] ) ) { + // 'ids' is explicitly ordered, unless you specify otherwise. + if ( empty( $attr['orderby'] ) ) { + $attr['orderby'] = 'post__in'; + } + $attr['include'] = $attr['ids']; + } + + $atts = shortcode_atts( array( + 'type' => 'audio', + 'order' => 'ASC', + 'orderby' => 'menu_order ID', + 'id' => $post ? $post->ID : 0, + 'include' => '', + 'exclude' => '', + 'style' => 'light', + 'tracklist' => true, + 'tracknumbers' => true, + 'images' => true, + 'artists' => true + ), $atts, 'playlist' ); - if( !empty($atts['include']) ) { - $args['include'] = $atts['include']; - $_attachments = get_posts( $args ); - if( !count($_attachments) ) { - return false; - } + $args = array( + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => $atts['type'], + 'order' => $atts['order'], + 'orderby' => $atts['orderby'] + ); - $attachments = array(); - foreach( $_attachments as $key => $val ) { - $attachments[$val->ID] = $_attachments[$key]; - } - } else { + if( !empty($atts['include']) ) { + $args['include'] = $atts['include']; + $_attachments = get_posts( $args ); + if( !count($_attachments) ) { return false; } - - - $bridge_atts = array(); - $aPlaylistItems = array(); - $aPlaylistImages = array(); - $aPlaylistCaptions = array(); - $aPlaylistDurations = array(); - $i = 0; - foreach ( $attachments as $attachment ) { - $i++; - - $url = wp_get_attachment_url( $attachment->ID ); - if( $i == 1 ) { - $bridge_atts['src'] = $url; - } else { - $aPlaylistItems[] = $url; - } - - $thumb_id = get_post_thumbnail_id( $attachment->ID ); - $src = false; - if( !empty( $thumb_id ) ) { - list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); - } - if( $i == 1 ) { - $bridge_atts['splash'] = $src; - } else { - $aPlaylistImages[] = $src; - } - - $aPlaylistCaptions[] = str_replace( array('"',';'), '', flowplayer::esc_caption($attachment->post_title) ); - - $meta = wp_get_attachment_metadata( $attachment->ID ); - if( !empty($meta) ) { - if( !empty($meta['length']) ) { - $aPlaylistDurations[] = $meta['length']; - } - } + $attachments = array(); + foreach( $_attachments as $key => $val ) { + $attachments[$val->ID] = $_attachments[$key]; } + } else { + return false; + } + + $bridge_atts = array(); + $aPlaylistItems = array(); + $aPlaylistImages = array(); + $aPlaylistCaptions = array(); + $aPlaylistDurations = array(); + $i = 0; + foreach ( $attachments as $attachment ) { + $i++; - - $bridge_atts['playlist'] = ''; - foreach( $aPlaylistItems AS $key => $src ) { - $bridge_atts['playlist'] .= $src; - if( $aPlaylistImages[$key] ) { - $bridge_atts['playlist'] .= ','.$aPlaylistImages[$key]; - } - $bridge_atts['playlist'] .= ';'; + $url = wp_get_attachment_url( $attachment->ID ); + if( $i == 1 ) { + $bridge_atts['src'] = $url; + } else { + $aPlaylistItems[] = $url; } - $bridge_atts['playlist'] = trim($bridge_atts['playlist'],';'); - if( count($aPlaylistCaptions) > 1 || $atts['tracklist'] ) $bridge_atts['caption'] = implode(';',$aPlaylistCaptions); - $bridge_atts['durations'] = implode(';',$aPlaylistDurations); - - if( $atts['tracklist'] ) { - $bridge_atts['listshow'] = true; + + $thumb_id = get_post_thumbnail_id( $attachment->ID ); + $src = false; + if( !empty( $thumb_id ) ) { + list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); } + if( $i == 1 ) { + $bridge_atts['splash'] = $src; + } else { + $aPlaylistImages[] = $src; + } - if( isset($atts['width']) ) { - $bridge_atts['width'] = $atts['width']; - } - if( isset($atts['height']) ) { - $bridge_atts['height'] = $atts['height']; - } + $aPlaylistCaptions[] = str_replace( array('"',';'), '', flowplayer::esc_caption($attachment->post_title) ); - if( count($bridge_atts) == 0 ) { - return ""; + $meta = wp_get_attachment_metadata( $attachment->ID ); + if( !empty($meta) ) { + if( !empty($meta['length']) ) { + $aPlaylistDurations[] = $meta['length']; + } } - - if( !empty($atts['type']) && $atts['type'] == 'audio' ) { - $bridge_atts['liststyle'] = 'horizontal'; + + } + + + $bridge_atts['playlist'] = ''; + foreach( $aPlaylistItems AS $key => $src ) { + $bridge_atts['playlist'] .= $src; + if( $aPlaylistImages[$key] ) { + $bridge_atts['playlist'] .= ','.$aPlaylistImages[$key]; } - - return flowplayer_content_handle( $bridge_atts, false, 'video' ); + $bridge_atts['playlist'] .= ';'; + } + $bridge_atts['playlist'] = trim($bridge_atts['playlist'],';'); + if( count($aPlaylistCaptions) > 1 || $atts['tracklist'] ) $bridge_atts['caption'] = implode(';',$aPlaylistCaptions); + $bridge_atts['durations'] = implode(';',$aPlaylistDurations); + + if( $atts['tracklist'] ) { + $bridge_atts['listshow'] = true; } - add_filter( 'post_playlist', 'fv_flowplayer_shortcode_playlist', 10, 2 ); + if( isset($atts['width']) ) { + $bridge_atts['width'] = $atts['width']; + } + if( isset($atts['height']) ) { + $bridge_atts['height'] = $atts['height']; + } + if( count($bridge_atts) == 0 ) { + return ""; + } + + if( !empty($atts['type']) && $atts['type'] == 'audio' ) { + $bridge_atts['liststyle'] = 'horizontal'; + } + return flowplayer_content_handle( $bridge_atts, false, 'video' ); +} + +global $fv_fp; +if( ( empty($_POST['action']) || $_POST['action'] != 'parse-media-shortcode' ) && ( empty($_GET['action']) || $_GET['action'] != 'edit' ) && !empty($fv_fp->conf['integrations']['wp_core_video']) && $fv_fp->conf['integrations']['wp_core_video'] == 'true' ) { + add_filter( 'wp_video_shortcode_override', 'fv_flowplayer_shortcode_video', 10, 4 ); + add_filter( 'wp_audio_shortcode_override', 'fv_flowplayer_shortcode_video', 10, 4 ); + add_filter( 'post_playlist', 'fv_flowplayer_shortcode_playlist', 10, 2 ); add_filter( 'the_content', 'fv_player_handle_youtube_links' ); add_filter( 'the_content', 'fv_player_handle_vimeo_links' ); add_filter( 'embed_oembed_html', 'fv_player_handle_vimeo_links' ); add_filter( 'embed_oembed_html', 'fv_player_handle_youtube_links' ); - - function fv_player_handle_vimeo_links( $html ) { - $html = preg_replace( '~]*?vimeo\.com/video/(\d+)[^>]*?(\?h=[a-z0-9]+)?[^>]*?>~', '[fvplayer src="http://vimeo.com/$1$2"]', $html ); - return $html; - } - - function fv_player_handle_youtube_links( $html ) { - $html = preg_replace( '~]*?youtube(?:-nocookie)?\.com/(?:embed|v)/(.*?)[\'"&#\?][^>]*?>~', '[fvplayer src="http://youtube.com/watch?v=$1"]', $html ); - return $html; - } - add_filter( 'the_content', 'fv_player_handle_video_tags' ); - function fv_player_handle_video_tags( $html ) { - $html = preg_replace( '~
]*?src\s*=\s*"(.+?)"[^>]*?>
~', '
[fvplayer src="$1"]
' , $html); - return $html; - } } diff --git a/models/conversion/conversion-base.class.php b/models/conversion/conversion-base.class.php index 8957c593b..9630748d6 100644 --- a/models/conversion/conversion-base.class.php +++ b/models/conversion/conversion-base.class.php @@ -2,6 +2,8 @@ abstract class FV_Player_Conversion_Base { + public $set_live = false; + protected $matchers = array(); protected $title = 'Conversion'; protected $slug = 'conversion-slug'; @@ -215,7 +217,7 @@ function conversion_screen() { } function is_live() { - return !empty($_POST['make-changes']) && $_POST['make-changes'] == 'true'; + return (!empty($_POST['make-changes']) && $_POST['make-changes'] == 'true') || $this->set_live ; } } \ No newline at end of file diff --git a/models/conversion/shortcode2DB.class.php b/models/conversion/shortcode2DB.class.php index b19969b5d..fc71db469 100644 --- a/models/conversion/shortcode2DB.class.php +++ b/models/conversion/shortcode2DB.class.php @@ -403,4 +403,5 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) { } -new FV_Player_Shortcode2Database_Conversion; \ No newline at end of file +global $FV_Player_Shortcode2Database_Conversion; +$FV_Player_Shortcode2Database_Conversion = new FV_Player_Shortcode2Database_Conversion; \ No newline at end of file diff --git a/view/admin.php b/view/admin.php index bcae91842..68e4f46f9 100644 --- a/view/admin.php +++ b/view/admin.php @@ -586,6 +586,7 @@ function fv_flowplayer_admin_integrations() {

+ _get_checkbox(__('Convert to DB on save', 'fv-wordpress-flowplayer'), 'convert_db_save', __('Enable to convert links and shortcodes to [fv_player id="..."] shortcode when post is saved.', 'fv-wordpress-flowplayer') ); ?> _get_checkbox(__('Always use fixed size player', 'fv-wordpress-flowplayer'), 'fixed_size', __('Enable to force video size at cost of loosing the video responsiveness.', 'fv-wordpress-flowplayer') ); ?> _get_checkbox(__('Disable saving skin CSS to a static file', 'fv-wordpress-flowplayer'), 'css_disable', __('Normally the player CSS configuration is stored in wp-content/fv-player-custom/style-{blog_id}.css.', 'fv-wordpress-flowplayer'), __('We do this to avoid a big style tag in your site <head>. Don\'t edit this file though, as it will be overwritten by plugin update or saving its options!','fv-wordpress-flowplayer' )); ?> From 3bec6f2bbef015afb24ae73881c7206c311a7c6f Mon Sep 17 00:00:00 2001 From: Michal Date: Fri, 20 Jan 2023 13:28:57 +0100 Subject: [PATCH 2/6] conversion: fix $errors default value --- models/conversion/shortcode2DB.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/conversion/shortcode2DB.class.php b/models/conversion/shortcode2DB.class.php index 434e7e6bd..a3d424267 100644 --- a/models/conversion/shortcode2DB.class.php +++ b/models/conversion/shortcode2DB.class.php @@ -179,8 +179,8 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) { $atts = shortcode_parse_atts( trim(rtrim($shortcode,']')) ); $import_video_atts = array(); $import_player_atts = array(); - $import_atts = array(); + $errors = array(); unset( $atts[0] ); // remove [fvplayer or [flowplayer From d34a702e791d00f3582c7afb98f060f672afb74e Mon Sep 17 00:00:00 2001 From: fvmartin Date: Fri, 3 Feb 2023 11:11:58 +0100 Subject: [PATCH 3/6] editor: convert links & shortcodes to db: Gutenberg --- controller/editor.php | 10 +++++++--- flowplayer.php | 3 ++- view/admin.php | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/controller/editor.php b/controller/editor.php index 019ed4982..4d2e47a30 100755 --- a/controller/editor.php +++ b/controller/editor.php @@ -554,10 +554,14 @@ function getTitleFromUrl($url) { * @return void */ function fv_wp_flowplayer_convert_to_db($post_id, $post, $update) { - global $wp_embed, $fv_fp, $FV_Player_Shortcode2Database_Conversion; + global $wp, $wp_embed, $fv_fp, $FV_Player_Shortcode2Database_Conversion; - // check if not quick edit - if( !isset($_POST['action']) || (isset($_POST['action']) && $_POST['action'] != 'editpost') ) return; + $is_classic_editor_save = !empty($_POST['action']) && $_POST['action'] != 'editpost' && !empty($_POST['post_ID']) && $_POST['post_ID'] == $post_id; + $is_gutenberg_post_save = !empty($wp->query_vars['rest_route']) && $wp->query_vars['rest_route'] == '/wp/v2/posts/'.$post_id; + + if( !$is_classic_editor_save && !$is_gutenberg_post_save ) { + return; + } // check if option is enabled if( !$fv_fp->_get_option('convert_db_save') ) return; diff --git a/flowplayer.php b/flowplayer.php index 2c2445211..e1e9052d9 100644 --- a/flowplayer.php +++ b/flowplayer.php @@ -81,7 +81,8 @@ global $fv_fp; $fv_fp = new flowplayer_frontend(); -if( is_admin() ) { +// If it's in wp-admin or if it's Gutenberg post saving +if( is_admin() || $_SERVER['REQUEST_METHOD'] == "POST" && preg_match( '~/wp-json/wp/v2/posts/\d+~', $_SERVER['REQUEST_URI'] ) ) { include_once( dirname( __FILE__ ) . '/controller/backend.php' ); include_once( dirname( __FILE__ ) . '/controller/editor.php' ); include_once( dirname( __FILE__ ) . '/controller/settings.php' ); diff --git a/view/admin.php b/view/admin.php index aa47bfbd5..63ae8cffc 100644 --- a/view/admin.php +++ b/view/admin.php @@ -598,8 +598,8 @@ function fv_flowplayer_admin_integrations() {

- _get_checkbox(__('Convert to DB on save', 'fv-wordpress-flowplayer'), 'convert_db_save', __('Enable to convert links and shortcodes to [fv_player id="..."] shortcode when post is saved.', 'fv-wordpress-flowplayer') ); ?> _get_checkbox(__('Always use fixed size player', 'fv-wordpress-flowplayer'), 'fixed_size', __('Enable to force video size at cost of loosing the video responsiveness.', 'fv-wordpress-flowplayer') ); ?> + _get_checkbox(__('Database conversion', 'fv-wordpress-flowplayer'), 'convert_db_save', __('Convert [fvplayer src="..."] shortcodes, [video] shortcodes, Vimeo and YouTube links to database-driven FV Player when post is saved.', 'fv-wordpress-flowplayer') ); ?> _get_checkbox(__('Disable saving skin CSS to a static file', 'fv-wordpress-flowplayer'), 'css_disable', __('Normally the player CSS configuration is stored in wp-content/fv-player-custom/style-{blog_id}.css.', 'fv-wordpress-flowplayer'), __('We do this to avoid a big style tag in your site <head>. Don\'t edit this file though, as it will be overwritten by plugin update or saving its options!','fv-wordpress-flowplayer' )); ?> From b88c9f72e0643dfab04a16c205a07bfad76c04c6 Mon Sep 17 00:00:00 2001 From: fvmartin Date: Fri, 3 Feb 2023 11:12:34 +0100 Subject: [PATCH 4/6] Conversion: Shortcode2DB: Fix date for new posts --- models/conversion/shortcode2DB.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/conversion/shortcode2DB.class.php b/models/conversion/shortcode2DB.class.php index 434e7e6bd..b4e6bec1e 100644 --- a/models/conversion/shortcode2DB.class.php +++ b/models/conversion/shortcode2DB.class.php @@ -179,6 +179,7 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) { $atts = shortcode_parse_atts( trim(rtrim($shortcode,']')) ); $import_video_atts = array(); $import_player_atts = array(); + $errors = array(); $import_atts = array(); @@ -347,7 +348,7 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) { $import_player_atts['status'] = 'published'; // add date_created - $import_player_atts['date_created'] = $post->post_date_gmt; + $import_player_atts['date_created'] = strtotime($post->post_date_gmt) > 0 ? $post->post_date_gmt : current_time( 'mysql' ); // add player_name // $import_player_atts['player_name'] = 'player_name'; @@ -386,7 +387,7 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) { $output_msg = "Would create new FV Player"; } } - + $type = $post->post_type; if( $meta_key ) { $type .= '
meta_key: '.$meta_key.''; From b705a6789618fce947c71618deeb1ccbcd9938b5 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 7 Mar 2023 11:20:32 +0100 Subject: [PATCH 5/6] conversion: fix check for classic editor --- controller/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/editor.php b/controller/editor.php index 4d2e47a30..d9a2443df 100755 --- a/controller/editor.php +++ b/controller/editor.php @@ -556,7 +556,7 @@ function getTitleFromUrl($url) { function fv_wp_flowplayer_convert_to_db($post_id, $post, $update) { global $wp, $wp_embed, $fv_fp, $FV_Player_Shortcode2Database_Conversion; - $is_classic_editor_save = !empty($_POST['action']) && $_POST['action'] != 'editpost' && !empty($_POST['post_ID']) && $_POST['post_ID'] == $post_id; + $is_classic_editor_save = !empty($_POST['action']) && $_POST['action'] === 'editpost' && !empty($_POST['post_ID']) && $_POST['post_ID'] == $post_id; $is_gutenberg_post_save = !empty($wp->query_vars['rest_route']) && $wp->query_vars['rest_route'] == '/wp/v2/posts/'.$post_id; if( !$is_classic_editor_save && !$is_gutenberg_post_save ) { From c2b33603dfb4a87f05c94f7cdac141cffe8bb6e9 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 7 Mar 2023 11:35:36 +0100 Subject: [PATCH 6/6] conversion: convert transcript and formatting --- models/conversion/shortcode2DB.class.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/models/conversion/shortcode2DB.class.php b/models/conversion/shortcode2DB.class.php index 7fb5a0817..fb023553d 100644 --- a/models/conversion/shortcode2DB.class.php +++ b/models/conversion/shortcode2DB.class.php @@ -36,6 +36,8 @@ function __construct() { 'playlist', 'caption', 'subtitles', + 'transcript', + 'original_formatting', 'ab', 'chapters', 'controlbar', @@ -308,6 +310,19 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) { $video_index++; } + } else if(strcmp( $player_att, 'transcript' ) == 0) { // transcript text + $transcript_text = $import_atts[$player_att]; + if( !empty($transcript_text) ) { + $import_video_atts[$video_index]['meta'][] = array( 'meta_key' => 'transcript_text', 'meta_value' => $transcript_text ); + } + + } else if(strcmp( $player_att, 'original_formatting' ) == 0) { // transcript original formatting + $transcript_original_formatting = $import_atts[$player_att]; + + if( $transcript_original_formatting === 'true' ) { + $import_video_atts[$video_index]['meta'][] = array( 'meta_key' => 'transcript_original_formatting', 'meta_value' => $transcript_original_formatting ); + } + } else if(strcmp( $player_att, 'ab' ) == 0) { // subtitles if( $import_atts[$player_att] == 'true' ) { $import_player_atts[$player_att] = 'on';