diff --git a/controller/settings.php b/controller/settings.php index 3f0916952..eb6b2f9f3 100644 --- a/controller/settings.php +++ b/controller/settings.php @@ -63,10 +63,10 @@ function fv_wp_flowplayer_after_plugin_row( $arg) { if( apply_filters('fv_player_skip_ads',false) ) { return; } - + $args = func_get_args(); - - if( $args[1]['Name'] == 'FV Player' ) { + + if( $args[1]['Name'] == 'FV Player' ) { $options = get_option( 'fvwpflowplayer' ); if( $options['key'] == 'false' || $options['key'] == '' ) : ?> @@ -143,13 +143,13 @@ function fv_player_settings_save() { $_GET['post_mime_type'] = 'image'; } } - + if( isset($_POST['fv-wp-flowplayer-submit']) ) { check_admin_referer('fv_flowplayer_settings_nonce','fv_flowplayer_settings_nonce'); - + global $fv_fp; if( method_exists($fv_fp,'_set_conf') ) { - if( + if( // pro not installed or !function_exists('FV_Player_Pro') || // pro installed and version is at least 7.5.25.728 @@ -189,9 +189,9 @@ function fv_player_handle_secrets($new, $old) { } } } else if($v == '1') { // single value, 1 - keep original, 0 - use new - $new[$key] = $old[$key]; + $new[$key] = $old[$key]; } - } + } unset($new[$k]); // remove _is_secret_ } @@ -206,12 +206,27 @@ function fv_player_handle_secrets($new, $old) { /* * Pointer boxes */ -add_action('admin_init', 'fv_player_admin_pointer_boxes'); +add_action('admin_footer', 'fv_player_admin_pointer_boxes'); function fv_player_admin_pointer_boxes() { global $fv_fp; global $fv_wp_flowplayer_ver, $fv_wp_flowplayer_core_ver; + if( + $fv_fp->_get_option('video_position_save_enable') && + ! $fv_fp->_get_option('notice_user_video_positions_conversion') + ) { + $fv_fp->pointer_boxes['fv_flowplayer_video_positions_conversion'] = array( + 'id' => '#wp-admin-bar-new-content', + 'pointerClass' => 'fv_flowplayer_video_positions_conversion', + 'heading' => __('FV Player Video Position Conversion', 'fv-wordpress-flowplayer'), + 'content' => __("
In this new version of FV Player the user video positions are stored in separate table. This avoids slowing down the user database (wp_usermeta).
Please run the tool to migrate the video positions to the new table.
"), + 'position' => array( 'edge' => 'top', 'align' => 'left' ), + 'button1' => __('Migrate', 'fv-wordpress-flowplayer'), + 'function1' => 'location.href = "' . admin_url('admin.php?page=fv_player_conversion_positions_meta2table') . '"', + ); + } + if( isset($fv_fp->conf['disable_videochecker']) && $fv_fp->conf['disable_videochecker'] == 'false' && ( !isset($fv_fp->conf['video_checker_agreement']) || $fv_fp->conf['video_checker_agreement'] != 'true' ) @@ -226,7 +241,7 @@ function fv_player_admin_pointer_boxes() { 'button2' => __('Disable the video checker', 'fv-wordpress-flowplayer') ); } - + if( !$fv_fp->_get_option('notice_7_5') ) { $fv_fp->pointer_boxes['fv_flowplayer_notice_7_5'] = array( 'id' => '#wp-admin-bar-new-content', @@ -244,7 +259,7 @@ function fv_player_admin_pointer_boxes() { 'button1' => __('Thanks for letting me know!', 'fv-wordpress-flowplayer') ); } - + if( !$fv_fp->_get_option('notice_new_lightbox') ) { $fv_fp->pointer_boxes['fv_flowplayer_new_lightbox'] = array( 'id' => '#wp-admin-bar-new-content', @@ -255,7 +270,7 @@ function fv_player_admin_pointer_boxes() { 'button1' => __('Thanks for letting me know!', 'fv-wordpress-flowplayer') ); } - + if( !$fv_fp->_get_option('notice_db') ) { $fv_fp->pointer_boxes['fv_flowplayer_db'] = array( 'id' => '#wp-admin-bar-new-content', @@ -266,7 +281,7 @@ function fv_player_admin_pointer_boxes() { 'button1' => __('Thanks for letting me know!', 'fv-wordpress-flowplayer') ); } - + if( $fv_fp->_get_option('video_sitemap') && !$fv_fp->_get_option('disableembedding') && !$fv_fp->_get_option('notice_xml_sitemap_iframes') ) { $fv_fp->pointer_boxes['fv_flowplayer_notice_xml_sitemap_iframes'] = array( 'id' => '#wp-admin-bar-new-content', @@ -278,8 +293,8 @@ function fv_player_admin_pointer_boxes() { 'button2' => __('Go to setting', 'fv-wordpress-flowplayer'), 'function2' => 'location.href = "'.admin_url('options-general.php?page=fvplayer').'#fv_flowplayer_seo"', ); - } - + } + if( !$fv_fp->_get_option('notice_db') && !$fv_fp->_get_option('nag_fv_player_7') ) { $fv_fp->pointer_boxes['fv_flowplayer_fv_player_7'] = array( 'id' => '#wp-admin-bar-new-content', @@ -297,11 +312,11 @@ function fv_player_admin_pointer_boxes() { 'button1' => __('Thanks for letting me know!', 'fv-wordpress-flowplayer'), ); } - - if( - (stripos( $_SERVER['REQUEST_URI'], '/plugins.php') !== false ||fv_player_is_admin_screen() ) - && $pnotices = get_option('fv_wordpress_flowplayer_persistent_notices') - ) { + + if( + (stripos( $_SERVER['REQUEST_URI'], '/plugins.php') !== false ||fv_player_is_admin_screen() ) + && $pnotices = get_option('fv_wordpress_flowplayer_persistent_notices') + ) { $fv_fp->pointer_boxes['fv_flowplayer_license_expired'] = array( 'id' => '#wp-admin-bar-new-content', 'pointerClass' => 'fv_flowplayer_license_expired', @@ -311,9 +326,9 @@ function fv_player_admin_pointer_boxes() { 'position' => array( 'edge' => 'top', 'align' => 'center' ), 'button1' => __('Hide this notice', 'fv-wordpress-flowplayer'), 'button2' => __('I\'ll check this later', 'fv-wordpress-flowplayer') - ); + ); } - + /*if( !$fv_fp->_get_option('disable_video_hash_links') && !$fv_fp->_get_option('notification_video_links') ) { $fv_fp->pointer_boxes['fv_player_notification_video_links'] = array( 'id' => '#wp-admin-bar-new-content', @@ -324,7 +339,7 @@ function fv_player_admin_pointer_boxes() { 'button1' => __('Open Settings', 'fv-wordpress-flowplayer'), 'button2' => __('Dismiss', 'fv-wordpress-flowplayer') ); - + add_action( 'admin_print_footer_scripts', 'fv_player_pointer_scripts' ); }*/ } @@ -335,7 +350,7 @@ function fv_player_admin_pointer_boxes() { add_action( 'wp_ajax_fv_foliopress_ajax_pointers', 'fv_wp_flowplayer_pointers_ajax' ); function fv_wp_flowplayer_pointers_ajax() { - + if( isset($_POST['key']) && $_POST['key'] == 'fv_flowplayer_video_checker_service' && isset($_POST['value']) ) { check_ajax_referer('fv_flowplayer_video_checker_service'); $conf = get_option( 'fvwpflowplayer' ); @@ -350,13 +365,23 @@ function fv_wp_flowplayer_pointers_ajax() { } die(); } - + + if( isset($_POST['key']) && $_POST['key'] == 'fv_flowplayer_video_positions_conversion' && isset($_POST['value']) ) { + check_ajax_referer('fv_flowplayer_video_positions_conversion'); + $conf = get_option( 'fvwpflowplayer' ); + if( $conf ) { + $conf['notice_user_video_positions_conversion'] = $_POST['value']; + update_option( 'fvwpflowplayer', $conf ); + } + die(); + } + if( isset($_POST['key']) && $_POST['key'] == 'fv_flowplayer_license_expired' && isset($_POST['value']) && $_POST['value'] === 'true' ) { check_ajax_referer('fv_flowplayer_license_expired'); delete_option("fv_wordpress_flowplayer_persistent_notices"); die(); - } - + } + $notices = array( 'fv_flowplayer_notice_7_5' => 'notice_7_5', 'fv_flowplayer_new_lightbox' => 'notice_new_lightbox', @@ -365,7 +390,7 @@ function fv_wp_flowplayer_pointers_ajax() { 'fv_flowplayer_fv_player_7' => 'nag_fv_player_7', 'fv_player_notification_video_links' => 'notification_video_links', ); - + if( isset($_POST['key']) && isset($_POST['value']) && in_array($_POST['key'], array_keys($notices) ) ) { check_ajax_referer($_POST['key']); $conf = get_option( 'fvwpflowplayer' ); @@ -375,7 +400,7 @@ function fv_wp_flowplayer_pointers_ajax() { } die(); } - + } @@ -390,7 +415,7 @@ function fv_player_pointer_scripts() { window.location = '#playlist_advance'; }); }); - })(jQuery); + })(jQuery); + ?> set_live ; } -} \ No newline at end of file +} diff --git a/models/conversion/positionsMeta2Table.php b/models/conversion/positionsMeta2Table.php new file mode 100644 index 000000000..1b651c526 --- /dev/null +++ b/models/conversion/positionsMeta2Table.php @@ -0,0 +1,384 @@ + 'FV Player PositionsMeta2Table Conversion', + 'slug' => 'positions_meta2table', + 'matchers' => array( + + ), + 'help' => __("This converts position values from usermeta to fv_player_user_video_positions table", 'fv-wordpress-flowplayer') + ) ); + + $this->conversion_limit = 2500; + $this->make_chages_button = false; // disable make changes button + + $this->start_warning_text = __('This will convert positions from usermeta to new tables. Please make sure you have a backup of your database before continuing.', 'fv-wordpress-flowplayer'); + + $this->conversion_done_details = __('The conversion has finished. The usermeta table will be purged of the FV Player video position data in 4 weeks.', 'fv-wordpress-flowplayer'); + + $this->screen_fields = array( + 'User ID', + 'Video ID', + 'Result', + 'Error', + ); + + add_action('admin_init', array($this, 'set_pointer_checked')); + } + + /** + * Override parent method + * + * @return int + */ + function get_count() { + global $wpdb; + return (int) $wpdb->get_var( "SELECT COUNT(*) AS count FROM `$wpdb->usermeta` WHERE meta_key LIKE 'fv_wp_flowplayer_%'" ); + } + + function get_items( $offset, $limit ) { + global $wpdb; + + // select umeta_id to prevent using filesort + $ids = $wpdb->get_results( "SELECT umeta_id FROM `$wpdb->usermeta` WHERE meta_key LIKE 'fv_wp_flowplayer_%' ORDER BY umeta_id ASC LIMIT {$offset},{$limit}" ); + + // select all meta data fields by ids + $meta_data = $wpdb->get_results( "SELECT * FROM `$wpdb->usermeta` WHERE umeta_id IN (". implode(',', wp_list_pluck($ids, 'umeta_id') ) .") ORDER BY umeta_id ASC" ); + + return $meta_data; + } + + function convert_one($meta) { + $output_data = array(); // output for html + $errors = array(); // all errors for export + + // get meta data + $meta_key = $meta->meta_key; + $meta_value = $meta->meta_value; + $user_id = $meta->user_id; + + $type = ''; + + if( strpos($meta_key, 'fv_wp_flowplayer_position') !== false ) { // last + $type = 'last_position'; + } else if ( strpos($meta_key, 'fv_wp_flowplayer_saw') !== false ) { // finished + $type = 'finished'; + } else if ( strpos($meta_key, 'fv_wp_flowplayer_top_position') !== false ) { // top + $type = 'top_position'; + } else if ( strpos($meta_key, 'fv_wp_flowplayer_player_playlist') !== false ) { // playlist + $type = 'playlist'; + } + + if( $type == 'playlist' ) { + preg_match('/fv_wp_flowplayer_player_playlist_(\d+)/', $meta_key, $matches); + if( isset( $matches[1] ) ) { + $playlist_id = $matches[1]; + + // check if its db video or external + $row_exitst = $this->position_row_exists( $user_id, $playlist_id, 'playlist' ); + + $result = $this->insert_update_playlist_row( $user_id, $playlist_id, $meta_value, $row_exitst ); + + if( $result ) { + $output_data[] = array( + 'ID' => $user_id, + 'Name' => $meta_key, + 'output' => $row_exitst ? 'Playlist position updated' : 'Playlist position inserted', + 'error' => '' + ); + } else { // failed to update + $output_data[] = array( + 'ID' => $user_id, + 'Name' => $meta_key, + 'output' => 'Playlist position failed to update', + 'error' => 'Failed to update playlist position' + ); + + $errors[] = array( + 'ID' => $user_id, + 'Name' => $meta_key + ); + } + + } else { + // failed to get playlist id + $output_data[] = array( + 'ID' => $user_id, + 'Name' => $meta_key, + 'output' => 'Playlist position failed to update', + 'error' => 'Cannot get playlist id' + ); + + $errors[] = array( + 'ID' => $user_id, + 'Name' => $meta_key + ); + } + + } else { + preg_match('/fv_wp_flowplayer_\w+_(.*)/', $meta_key, $matches); + if( isset( $matches[1] ) ) { + $video_id = $matches[1]; + + // check if video exitst in db + $video_exists = $this->video_exists( $video_id ); + $row_exitst = $this->position_row_exists( $user_id, $video_id, 'position', $video_exists ); + + $result = $this->insert_update_video_row( $user_id, $video_id, $type, $meta_value, $row_exitst, $video_exists ); + + if( $result ) { + $output_data[] = array( + 'ID' => $user_id, + 'Name' => $meta_key, + 'output' => $row_exitst ? 'Video position updated' : 'Video position inserted', + 'error' => '' + ); + } else { + $output_data[] = array( + 'ID' => $user_id, + 'Name' => $meta_key, + 'output' => 'Video position failed to update', + 'error' => 'Failed to update position' + ); + + $errors[] = array( + 'ID' => $user_id, + 'Name' => $meta_key + ); + } + + } else { + $output_data[] = array( + 'ID' => $user_id, + 'Name' => $meta_key, + 'output' => 'Video position failed to update', + 'error' => 'Cannot get video id' + ); + + // failed to get video id + $errors[] = array( + 'ID' => $user_id, + 'Name' => $meta_key + ); + } + + } + + return array( + 'output_data' => $output_data, + 'errors' => $errors + ); + + } + + /** + * Insert or update video row + * + * @param int $user_id + * @param int $video_id + * @param string $type + * @param int $value + * @param boolean $row_exitst + * @param boolean $video_exists + * + * @return boolean $res result of insert or update + */ + function insert_update_video_row( $user_id, $video_id, $type, $value, $row_exitst, $video_exists ) { + global $wpdb; + + if( !$video_exists ) { // non db video + $legacy_id = $video_id; + $video_id = 0; + } else { // db video + $legacy_id = ''; + $video_id = intval($video_id); + } + + if( $row_exitst ) { + $res = $wpdb->update( + $wpdb->prefix . 'fv_player_user_video_positions', + array( + $type => $value + ), + array( + 'user_id' => $user_id, + 'video_id' => $video_id, + 'legacy_video_id' => $legacy_id + ) + ); + + $res = is_numeric($res); + } else { + $res = $wpdb->insert( + $wpdb->prefix . 'fv_player_user_video_positions', + array( + $type => $value, + 'user_id' => $user_id, + 'video_id' => $video_id, + 'legacy_video_id' => $legacy_id + ) + ); + + $res = !empty($res); + } + + return $res; + } + + /** + * Insert or update playlist row + * + * @param int $user_id + * @param int $playlist_id + * @param int $value + * @param boolean $exitst + * + * @return boolean $res result of insert or update + */ + function insert_update_playlist_row( $user_id, $playlist_id, $value, $exitst ) { + global $wpdb; + + if( $exitst ) { + $res = $wpdb->update( + $wpdb->prefix . 'fv_player_user_playlist_positions', + array( + 'item_index' => $value + ), + array( + 'user_id' => $user_id, + 'player_id' => $playlist_id + ) + ); + + $res = is_numeric($res); + } else { + $res = $wpdb->insert( + $wpdb->prefix . 'fv_player_user_playlist_positions', + array( + 'user_id' => $user_id, + 'player_id' => $playlist_id, + 'item_index' => $value + ) + ); + + $res = !empty($res); + } + + return $res; + } + + /** + * Check if video exitst in db + * + * @param int $video_id + * + * @return object|null + */ + function video_exists( $video_id ) { + global $wpdb; + + $row = $wpdb->get_row( "SELECT * FROM `{$wpdb->prefix}fv_player_videos` WHERE id = {$video_id}" ); + + return $row; + } + + /** + * Check if position or playlist row exitst + * + * @param int $user_id + * @param int|string $id + * @param string $type + * @param boolean $video_exists + * + * @return object|null + */ + function position_row_exists( $user_id, $id, $type, $video_exists = false ) { + global $wpdb; + + if( $type == 'position' ) { + + if( $video_exists ) { // db video + $row = $wpdb->get_row( "SELECT * FROM `{$wpdb->prefix}fv_player_user_video_positions` WHERE user_id = {$user_id} AND video_id = {$id}" ); + } else { // legacy video + $row = $wpdb->get_row( "SELECT * FROM `{$wpdb->prefix}fv_player_user_video_positions` WHERE user_id = {$user_id} AND legacy_video_id = {$id}" ); + } + + } + + if( $type == 'playlist' ) { + $row = $wpdb->get_row( "SELECT * FROM `{$wpdb->prefix}fv_player_user_playlist_positions` WHERE user_id = {$user_id} AND player_id = {$id}" ); + } + + return $row; + } + + function conversion_button() { + ?> ++ +
+[fvplayer src=...] and [flowplayer src=...] shortcodes into database [fvplayer id=...] shortcodes.", 'fv-wordpress-flowplayer')
) );
+ $this->conversion_limit = 1;
+
+ $this->start_warning_text = __('Please make sure you backup your database before continuing. You can use post revisions to get back to previous version of your posts as well.', 'fv-wordpress-flowplayer');
+
// atts for video that are supported
$this->supported_video_atts = array(
'src',
@@ -50,16 +54,19 @@ function __construct() {
);
$this->supported_atts = array_merge( $this->supported_video_atts, $this->supported_player_atts );
- }
- /**
- * Count posts with old shortcode
- *
- * @return int $count
- */
- function get_count() {
- global $wpdb;
- return $wpdb->get_var( "SELECT FOUND_ROWS()" );
+ $this->screen_fields = array(
+ 'ID',
+ 'Title',
+ 'Post Type',
+ 'Shortcode',
+ 'Result',
+ 'Error'
+ );
+
+ if( isset($_GET['fv-conversion-export']) && !empty($_GET['page']) && $_GET['page'] === $this->screen ) {
+ add_action('admin_init', array( $this, 'csv_export' ) );
+ }
}
/**
@@ -67,7 +74,7 @@ function get_count() {
*
* @return object|null $result
*/
- function get_posts_with_shortcode($offset, $limit) {
+ function get_items($offset, $limit) {
global $wpdb;
// Each row is the matching wp_posts row or wp_posts row with matching meta_value
@@ -226,7 +233,7 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) {
$video_index = 0;
$import_video_atts[$video_index] = array();
// add video atts
- foreach( $this->supported_video_atts as $video_att ) {
+ foreach( $this->supported_video_atts as $video_att ) {
if( isset( $import_atts[$video_att] ) ) {
$import_video_atts[$video_index][$video_att] = $import_atts[$video_att];
}
@@ -334,7 +341,7 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) {
} else {
$import_player_atts[$player_att] = $import_atts[$player_att];
}
-
+
} else if(strcmp( $player_att, 'speed' ) == 0) { // subtitles
if( $import_atts[$player_att] == 'buttons' ) {
$import_player_atts[$player_att] = 'yes';
@@ -349,7 +356,7 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) {
}
// add metadata
- $import_player_atts['meta'] = array(
+ $import_player_atts['meta'] = array(
array(
'meta_key' => 'post_id',
'meta_value' => $post->ID
@@ -406,7 +413,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.'';
@@ -427,7 +434,92 @@ function worker( $shortcode, $post, $new_content, $meta_key = false ) {
);
}
+ function build_output_html($data, $percent_done) {
+ $html = array();
+
+ foreach( $data as $output_data ) {
+ $html[] = "'.__('Related videos','fv-player-ppv') .'
' . $related_videos_html . '