| 1 |
<?php |
| 2 |
|
| 3 |
/* FV Player - HTML5 video player |
| 4 |
Copyright (C) 2013 Foliovision |
| 5 |
|
| 6 |
This program is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
|
| 24 |
/* |
| 25 |
* Video Checker support email |
| 26 |
*/ |
| 27 |
|
| 28 |
add_action('wp_ajax_fv_wp_flowplayer_support_mail', 'fv_wp_flowplayer_support_mail'); |
| 29 |
|
| 30 |
function fv_wp_flowplayer_support_mail() { |
| 31 |
if( isset( $_POST['notice'] ) && ! empty( $_POST['nonce'] && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'fv_player_frontend' ) ) ) { |
| 32 |
|
| 33 |
$current_user = wp_get_current_user(); |
| 34 |
$content = "<h1>Admin: " . esc_html( sanitize_text_field( $_POST['status'] ) ) . "</h1>\n"; |
| 35 |
$content .= '<p>User: '.$current_user->display_name." (".$current_user->user_email.")</p>\n"; |
| 36 |
$content .= '<p>User Agent: ' . esc_html( sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) ) . "</p>\n"; |
| 37 |
$content .= '<p>Referer: ' . esc_url( sanitize_url( $_SERVER['HTTP_REFERER'] ) ) . "</p>\n"; |
| 38 |
$content .= "<p>Comment:</p>\n" . wpautop( esc_html( sanitize_textarea_field( $_POST['comment'] ) ) ); |
| 39 |
$notice = str_replace( '<span class="value"', ': <span class="value"', wp_kses_post( $_POST['notice'] ) ); |
| 40 |
$notice .= str_replace( '<span class="value"', ': <span class="value"', wp_kses_post( $_POST['details'] ) ); |
| 41 |
|
| 42 |
$content .= "<p>Video analysis:</p>\n".$notice; |
| 43 |
|
| 44 |
global $fv_wp_flowplayer_support_mail_from, $fv_wp_flowplayer_support_mail_from_name; |
| 45 |
|
| 46 |
//$headers = "Reply-To: \"$current_user->display_name\" <$current_user->user_email>\r\n"; |
| 47 |
$fv_wp_flowplayer_support_mail_from_name = $current_user->display_name; |
| 48 |
$fv_wp_flowplayer_support_mail_from = $current_user->user_email; |
| 49 |
|
| 50 |
add_filter( 'wp_mail_content_type', 'fv_wp_flowplayer_support_mail_content_type' ); |
| 51 |
|
| 52 |
//add_action('phpmailer_init', 'fv_wp_flowplayer_support_mail_phpmailer_init' ); |
| 53 |
wp_mail( 'fvplayer@foliovision.com', 'FV Player Quick Support Submission', $content ); |
| 54 |
|
| 55 |
wp_send_json_success(); |
| 56 |
|
| 57 |
} else { |
| 58 |
wp_send_json_error(); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
function fv_wp_flowplayer_support_mail_content_type() { |
| 63 |
return 'text/html'; |
| 64 |
} |
| 65 |
|
| 66 |
function fv_wp_flowplayer_support_mail_phpmailer_init( $phpmailer ) { |
| 67 |
global $fv_wp_flowplayer_support_mail_from, $fv_wp_flowplayer_support_mail_from_name; |
| 68 |
|
| 69 |
if( $fv_wp_flowplayer_support_mail_from_name ) { |
| 70 |
$phpmailer->FromName = trim( $fv_wp_flowplayer_support_mail_from_name ); |
| 71 |
} |
| 72 |
if( $fv_wp_flowplayer_support_mail_from ) { |
| 73 |
if( strcmp( trim($phpmailer->From), trim($fv_wp_flowplayer_support_mail_from) ) != 0 && !trim($phpmailer->Sender) ) { |
| 74 |
$phpmailer->Sender = trim($phpmailer->From); |
| 75 |
} |
| 76 |
$phpmailer->From = trim( $fv_wp_flowplayer_support_mail_from ); |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
/* |
| 85 |
* Activating Extensions |
| 86 |
*/ |
| 87 |
add_action('wp_ajax_fv_wp_flowplayer_activate_extension', 'fv_wp_flowplayer_activate_extension'); |
| 88 |
|
| 89 |
function fv_wp_flowplayer_activate_extension() { |
| 90 |
check_ajax_referer( 'fv_wp_flowplayer_activate_extension', 'nonce' ); |
| 91 |
if( !isset( $_POST['plugin'] ) ) { |
| 92 |
die(); |
| 93 |
} |
| 94 |
|
| 95 |
$activate = activate_plugin( sanitize_text_field( $_POST['plugin'] ) ); |
| 96 |
if ( is_wp_error( $activate ) ) { |
| 97 |
echo "<FVFLOWPLAYER>".wp_json_encode( array( 'message' => $activate->get_error_message(), 'error' => $activate->get_error_message() ) )."</FVFLOWPLAYER>"; |
| 98 |
die(); |
| 99 |
} |
| 100 |
|
| 101 |
echo "<FVFLOWPLAYER>".wp_json_encode( array( 'message' => 'Success!', 'plugin' => esc_html( sanitize_textarea_field( $_POST['plugin'] ) ) ) )."</FVFLOWPLAYER>"; |
| 102 |
die(); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
/* |
| 109 |
* Template Check |
| 110 |
*/ |
| 111 |
add_action('wp_ajax_fv_wp_flowplayer_check_template', 'fv_wp_flowplayer_check_template'); |
| 112 |
|
| 113 |
function fv_wp_flowplayer_check_template() { |
| 114 |
|
| 115 |
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'fv_wp_flowplayer_check_template' ) ) { |
| 116 |
$output = array( 'errors' => array( 'Nonce verification failed' ), 'ok' => false ); |
| 117 |
echo '<FVFLOWPLAYER>' . wp_json_encode( $output ) . '</FVFLOWPLAYER>'; |
| 118 |
die(); |
| 119 |
} |
| 120 |
|
| 121 |
$ok = array(); |
| 122 |
$errors = array(); |
| 123 |
|
| 124 |
/** |
| 125 |
* The HTTP request below will have no login cookies, so lets make sure the nonce is created for non-logged in user. |
| 126 |
*/ |
| 127 |
wp_set_current_user( 0 ); |
| 128 |
unset( $_COOKIE[ LOGGED_IN_COOKIE ] ); |
| 129 |
|
| 130 |
$response = wp_remote_get( |
| 131 |
add_query_arg( 'fv_wp_flowplayer_check_template', wp_create_nonce( 'fv_wp_flowplayer_check_template' ), home_url() ) |
| 132 |
); |
| 133 |
|
| 134 |
$headers = ! is_wp_error( $response ) ? wp_remote_retrieve_headers( $response ) : array(); |
| 135 |
|
| 136 |
if( is_wp_error( $response ) ) { |
| 137 |
$error_message = $response->get_error_message(); |
| 138 |
$output = array( 'errors' => $error_message); |
| 139 |
} else if ($response['response']['code'] == 401){ |
| 140 |
$errors[] = 'You are using HTTP auth, we cannot check template.'; |
| 141 |
$output = array( 'errors' => $errors); |
| 142 |
|
| 143 |
} else if ( |
| 144 |
absint( $response['response']['code'] ) === 403 && |
| 145 |
'cloudflare' === strtolower( $headers['server'] ) && |
| 146 |
! empty( $headers['cf-mitigated'] ) && |
| 147 |
'challenge' === $headers['cf-mitigated'] |
| 148 |
) { |
| 149 |
$errors[] = 'Cloudflare is blocking our access to your website, we cannot check the template.'; |
| 150 |
$output = array( 'ok' => $errors); |
| 151 |
|
| 152 |
} else { |
| 153 |
|
| 154 |
$active_plugins = get_option( 'active_plugins' ); |
| 155 |
foreach( $active_plugins AS $plugin ) { |
| 156 |
if( stripos( $plugin, 'wp-minify' ) !== false ) { |
| 157 |
$errors[] = "You are using <strong>WP Minify</strong>, so the script checks would not be accurate. Please check your videos manually."; |
| 158 |
$output = array( 'errors' => $errors, 'ok' => $ok/*, 'html' => $response['body'] */); |
| 159 |
echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>'; |
| 160 |
die(); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
$combine_js_warning = false; |
| 165 |
|
| 166 |
if( function_exists( 'w3_instance' ) && $minify = w3_instance('W3_Plugin_Minify') ) { |
| 167 |
if( $minify->_config->get_boolean('minify.js.enable') ) { |
| 168 |
$errors[] = "You are using <strong>W3 Total Cache</strong> with JS Minify enabled. The template check might not be accurate. Please check your videos manually."; |
| 169 |
|
| 170 |
$combine_js_warning = true; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
if( class_exists( 'SiteGround_Optimizer\Options\Options' ) && method_exists( 'SiteGround_Optimizer\Options\Options', 'is_enabled' ) ) { |
| 175 |
|
| 176 |
// Avoiding PHP 5.2 lint errors |
| 177 |
if( call_user_func_array( array( 'SiteGround_Optimizer\Options\Options', 'is_enabled' ), array( 'siteground_optimizer_combine_javascript' ) ) ) { |
| 178 |
$errors[] = "You are using <strong>SiteGround Optimizer</strong> with \"Combine JavaScript Files\" enabled. The template check might not be accurate. Please check your videos manually."; |
| 179 |
|
| 180 |
$combine_js_warning = true; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
$ok[] = __( 'We also recommend you to open any of your videos on your site and see if you get a red warning message about JavaScript not working.', 'fv-player' ); |
| 185 |
|
| 186 |
$response['body'] = preg_replace( '$<!--[\s\S]+?-->$', '', $response['body'] ); // handle HTML comments |
| 187 |
|
| 188 |
// check Flowplayer scripts |
| 189 |
preg_match_all( '!<script[^>]*?src=[\'"]([^\'"]*?freedomplayer[0-9.-]*?(?:\.min)?\.js[^\'"]*?)[\'"][^>]*?>\s*?</script>!', $response['body'], $freedomplayer_scripts ); |
| 190 |
if( count($freedomplayer_scripts[1]) > 0 ) { |
| 191 |
if( count($freedomplayer_scripts[1]) > 1 ) { |
| 192 |
$errors[] = "It appears there are <strong>multiple</strong> FreedomPlayer scripts on your site, your videos might not be playing, please check. There might be some other plugin adding the script."; |
| 193 |
} |
| 194 |
foreach( $freedomplayer_scripts[1] AS $flowplayer_script ) { |
| 195 |
$check = fv_wp_flowplayer_check_script_version( $flowplayer_script ); |
| 196 |
if( $check == - 1 ) { |
| 197 |
$errors[] = "Flowplayer script <code>$flowplayer_script</code> is old version and won't play. You need to get rid of this script."; |
| 198 |
} else if( $check == 1 ) { |
| 199 |
$ok[] = __( 'FV Player script found: ', 'fv-player' ) . "<code>$flowplayer_script</code>!"; |
| 200 |
$fv_flowplayer_pos = strpos( $response['body'], $flowplayer_script ); |
| 201 |
} else if( $check == 0 ) { |
| 202 |
$errors[] = "<p>It appears there are <strong>stripping the query string versions</strong> as <code>$flowplayer_script</code> appears without the plugin version number.</p><p>Some site speed analysis tools recommend doing so, but it means you loose control over what version of plugin files is cached (in users' browsers and on CDN). That way users hang on to the old plugin files and might experience visual or functional issues with FV Player (and any other plugin).</p><p>You can read all the details in our article: <a href='https://foliovision.com/2017/06/wordpress-cdn-best-practices' target='_blank'>How to use WordPress with CDN<a>.</p>"; |
| 203 |
} |
| 204 |
} |
| 205 |
} else if( !$combine_js_warning && count($freedomplayer_scripts[1]) < 1 ) { |
| 206 |
$errors[] = "It appears there are <strong>no</strong> FreedomPlayer scripts on your site, your videos might not be playing, please check. Check your template's header.php file if it contains wp_head() function call and footer.php should contain wp_footer()!"; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
// check jQuery scripts |
| 211 |
preg_match_all( '!<script[^>]*?src=[\'"]([^\'"]*?/jquery[0-9.-]*?(?:\.min)?\.js[^\'"]*?)[\'"][^>]*?>\s*?</script>!', $response['body'], $jquery_scripts ); |
| 212 |
if( count($jquery_scripts[1]) > 0 ) { |
| 213 |
foreach( $jquery_scripts[1] AS $jkey => $jquery_script ) { |
| 214 |
$ok[] = __( 'jQuery library found: ', 'fv-player' ) . "<code>$jquery_script</code>!"; |
| 215 |
$jquery_pos = strpos( $response['body'], $jquery_script ); |
| 216 |
} |
| 217 |
|
| 218 |
if( count($jquery_scripts[1]) > 1 ) { |
| 219 |
$errors[] = "It appears there are <strong>multiple</strong> jQuery libraries on your site, your videos might not be playing or may play with defects, please check.\n"; |
| 220 |
} |
| 221 |
} else if( count($jquery_scripts[1]) < 1 ) { |
| 222 |
$errors[] = "It appears there are <strong>no</strong> jQuery library on your site, your videos might not be playing, please check.\n"; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
if( $fv_flowplayer_pos > 0 && $jquery_pos > 0 && $jquery_pos > $fv_flowplayer_pos && count($jquery_scripts[1]) < 1 ) { |
| 227 |
$errors[] = "It appears your Flowplayer JavaScript library is loading before jQuery. Your videos probably won't work. Please make sure your jQuery library is loading using the standard Wordpress function - wp_enqueue_scripts(), or move it above wp_head() in your header.php template."; |
| 228 |
} |
| 229 |
|
| 230 |
// check if Permissions-Policy header is set and has autoplay=() in it |
| 231 |
if( isset($headers['permissions-policy']) && strpos( $headers['permissions-policy'], 'autoplay=()' ) !== false ) { |
| 232 |
$errors[] = sprintf( |
| 233 |
__( 'You are using Permissions-Policy HTTP header to block video autoplay. This will force muted playback of YouTube videos too and viewers will have to un-mute the videos manually: <code>%s</code>', 'fv-player' ), |
| 234 |
esc_html( $headers['permissions-policy'] ) |
| 235 |
); |
| 236 |
} else if ( isset($headers['permissions-policy'] ) ) { |
| 237 |
$ok[] = sprintf( |
| 238 |
__( 'You are using Permissions-Policy HTTP header to adjust the autoplay permissions: <code>%s</code>', 'fv-player' ), |
| 239 |
esc_html( $headers['permissions-policy'] ) |
| 240 |
); |
| 241 |
} else { |
| 242 |
$ok[] = __( 'You are not using Permissions-Policy HTTP header to adjust the autoplay permissions.', 'fv-player' ); |
| 243 |
} |
| 244 |
|
| 245 |
$output = array( 'errors' => $errors, 'ok' => $ok/*, 'html' => $response['body'] */); |
| 246 |
} |
| 247 |
echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>'; |
| 248 |
die(); |
| 249 |
} |
| 250 |
|
| 251 |
// enter script URL, return false if it's not version 5 |
| 252 |
function fv_wp_flowplayer_check_script_version( $url ) { |
| 253 |
$url_mod = preg_replace( '!\?.+!', '', $url ); |
| 254 |
if( preg_match( '!flowplayer-([\d\.]+)!', $url_mod, $version ) && $version[1] ) { |
| 255 |
if( strpos( $version[1], '5' ) !== 0 ) { |
| 256 |
return -1; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
global $fv_wp_flowplayer_ver; |
| 261 |
if( strpos( $url, '/freedom-video-player/fv-player.min.js?ver='.$fv_wp_flowplayer_ver ) !== false ) { |
| 262 |
return 1; |
| 263 |
} |
| 264 |
|
| 265 |
// when using Google PageSpeed module |
| 266 |
if( strpos( $url, '/freedom-video-player/fv-player.min.js,qver='.$fv_wp_flowplayer_ver ) !== false ) { |
| 267 |
return 1; |
| 268 |
} |
| 269 |
|
| 270 |
// when using SCRIPT_DEBUG |
| 271 |
if( strpos( $url, '/freedom-video-player/freedomplayer.min.js?ver=' ) !== false ) { |
| 272 |
return 1; |
| 273 |
} |
| 274 |
|
| 275 |
// when using SCRIPT_DEBUG with Google PageSpeed module |
| 276 |
if( strpos( $url, '/freedom-video-player/freedomplayer.min.js,qver=' ) !== false ) { |
| 277 |
return 1; |
| 278 |
} |
| 279 |
|
| 280 |
return 0; |
| 281 |
} |
| 282 |
|
| 283 |
function fv_wp_flowplayer_check_jquery_version( $url, &$array, $key ) { |
| 284 |
$url_mod = preg_replace( '!\?.+!', '', $url ); |
| 285 |
if( preg_match( '!(\d+.[\d\.]+)!', $url_mod, $version ) && $version[1] ) { |
| 286 |
if( version_compare($version[1], '1.7.1') == -1 ) { |
| 287 |
return -1; |
| 288 |
} else { |
| 289 |
return 1; |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
// if jQuery is in the Wordpress install, we know that the ?ver= says what version it is |
| 294 |
if( strpos( $url, site_url().'/wp-includes/js/jquery/jquery.js' ) !== false ) { |
| 295 |
if( preg_match( '!(\d+.[\d\.]+)!', $url, $version ) && $version[1] ) { |
| 296 |
if( version_compare($version[1], '1.7.1') == -1 ) { |
| 297 |
return -1; |
| 298 |
} else { |
| 299 |
return 1; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
return 0; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
/* |
| 311 |
* Check video files |
| 312 |
*/ |
| 313 |
add_action('wp_ajax_fv_wp_flowplayer_check_files', 'fv_wp_flowplayer_check_files'); |
| 314 |
|
| 315 |
function fv_wp_flowplayer_check_files() { |
| 316 |
|
| 317 |
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'fv_wp_flowplayer_check_files' ) ) { |
| 318 |
$output = array( 'errors' => array( 'Nonce verification failed' ), 'ok' => false ); |
| 319 |
echo '<FVFLOWPLAYER>' . wp_json_encode( $output ) . '</FVFLOWPLAYER>'; |
| 320 |
die(); |
| 321 |
} |
| 322 |
|
| 323 |
global $wpdb; |
| 324 |
|
| 325 |
$bNotDone = false; |
| 326 |
$tStart = microtime(true); |
| 327 |
$tMax = ( @ini_get('max_execution_time') ) ? @ini_get('max_execution_time') - 5 : 25; |
| 328 |
|
| 329 |
$videos1 = $wpdb->get_results( "SELECT ID, post_content FROM $wpdb->posts WHERE post_type != 'revision' AND post_status != 'trash' AND post_content LIKE '%[flowplayer %'" ); |
| 330 |
$videos2 = $wpdb->get_results( "SELECT ID, post_content FROM $wpdb->posts WHERE post_type != 'revision' AND post_status != 'trash' AND post_content LIKE '%[fvplayer %'" ); |
| 331 |
|
| 332 |
$videos = array_merge( $videos1, $videos2 ); |
| 333 |
|
| 334 |
$source_servers = array(); |
| 335 |
|
| 336 |
$shortcodes_count = 0; |
| 337 |
$src_count = 0; |
| 338 |
if( count($videos) ) { |
| 339 |
foreach( $videos AS $post ) { |
| 340 |
|
| 341 |
$shortcodes_count += preg_match_all( '!\[(?:flowplayer|fvplayer)[^\]]+\]!', $post->post_content, $post_videos ); |
| 342 |
if( count($post_videos[0]) ) { |
| 343 |
foreach( $post_videos[0] AS $post_video ) { |
| 344 |
$post_video = preg_replace( '!popup=\'.*\'!', '', $post_video ); |
| 345 |
$src_count += preg_match_all( '!(?:src|src1|src2|src3|mp4|webm|ogv)=[\'"](.*?(?:mp4|m4v))[\'"]!', $post_video, $sources1 ); |
| 346 |
$src_count += preg_match_all( '!(?:src|src1|src2|src3|mp4|webm|ogv)=([^\'"].*?(?:mp4|m4v|flv))[\s\]]!', $post_video, $sources2 ); |
| 347 |
$sources = array_merge( $sources1[1], $sources2[1] ); |
| 348 |
if( count($sources) ) { |
| 349 |
foreach($sources AS $src ) { |
| 350 |
if( strpos( $src, '//' ) === 0 ) { |
| 351 |
$src = 'http:'.$src; |
| 352 |
} else if( strpos( $src, '/' ) === 0 ) { |
| 353 |
$src = home_url().$src; |
| 354 |
} |
| 355 |
|
| 356 |
$server = preg_replace( '!(.*?//.*?)/.+!', '$1', $src ); |
| 357 |
|
| 358 |
$source_servers[$server][] = array( 'src' => $src, 'post_id' => $post->ID ); |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
$ok = array(); |
| 368 |
$errors = array(); |
| 369 |
|
| 370 |
$count = 0; |
| 371 |
foreach( $source_servers AS $server => $videos ) { |
| 372 |
|
| 373 |
$tCurrent = microtime(true); |
| 374 |
if( $tCurrent - $tStart > $tMax ) { |
| 375 |
$bNotDone = true; |
| 376 |
break; |
| 377 |
} |
| 378 |
|
| 379 |
if( stripos( $videos[0]['src'], '.mp4' ) === FALSE /*&& stripos( $videos[0]['src'], '.m4v' ) === FALSE*/ ) { |
| 380 |
continue; |
| 381 |
} |
| 382 |
|
| 383 |
global $FV_Player_Checker; |
| 384 |
|
| 385 |
if( stripos( trim($videos[0]['src']), 'rtmp://' ) === false ) { |
| 386 |
list( $header, $message_out ) = $FV_Player_Checker->http_request( trim($videos[0]['src']), array( 'quick_check' => 10, 'size' => 65536 ) ); |
| 387 |
if( $header ) { |
| 388 |
$headers = WP_Http::processHeaders( $header ); |
| 389 |
list( $new_errors, $mime_type, $fatal ) = $FV_Player_Checker->check_headers( $headers, trim($videos[0]['src']), wp_rand(0,999), array( 'talk_bad_mime' => 'Server <code>'.$server.'</code> uses incorrect mime type for MP4 ', 'wrap' => false ) ); |
| 390 |
if( $fatal ) { |
| 391 |
continue; |
| 392 |
} |
| 393 |
if( $new_errors ) { |
| 394 |
$sPostsLinks = false; |
| 395 |
foreach( $videos AS $video ) { |
| 396 |
$sPostsLinks .= '<a href="'.home_url().'?p='.$video['post_id'].'">'.$video['post_id'].'</a> '; |
| 397 |
} |
| 398 |
$errors[] = implode( " ",$new_errors ).'(<a href="#" onclick="jQuery(\'#fv-flowplayer-warning-'.$count.'\').toggle(); return false">click to see a list of posts</a>) <div id="fv-flowplayer-warning-'.$count.'" style="display: none; ">'.$sPostsLinks.'</div>'; |
| 399 |
$count++; |
| 400 |
continue; |
| 401 |
} else { |
| 402 |
$ok[] = 'Server <code>'.$server.'</code> appears to serve correct mime type <code>'.$mime_type.'</code> for MP4 videos.'; |
| 403 |
} |
| 404 |
} |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
if( $bNotDone ) { |
| 409 |
$ok[] = '<strong>Not all the servers were checked as you use a lot of them, increase your PHP execution time or check your other videos by hand.</strong>'; |
| 410 |
} |
| 411 |
|
| 412 |
$output = array( 'errors' => $errors, 'ok' => $ok/*, 'html' => $response['body'] */); |
| 413 |
echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>'; |
| 414 |
die(); |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
/* |
| 421 |
* Apply Pro Upgrade button |
| 422 |
*/ |
| 423 |
add_action('wp_ajax_fv_wp_flowplayer_check_license', 'fv_wp_flowplayer_check_license'); |
| 424 |
|
| 425 |
function fv_wp_flowplayer_check_license() { |
| 426 |
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'fv_wp_flowplayer_check_license' ) ) { |
| 427 |
$output = array( 'errors' => array( 'Nonce verification failed' ), 'ok' => false ); |
| 428 |
|
| 429 |
} else if( fv_wp_flowplayer_admin_key_update() ) { |
| 430 |
$output = array( 'errors' => false, 'ok' => array(__( 'License key acquired successfully. <a href="">Reload</a>', 'fv-player' )) ); |
| 431 |
fv_wp_flowplayer_install_extension(); |
| 432 |
} else { |
| 433 |
$message = get_option('fv_wordpress_flowplayer_deferred_notices'); |
| 434 |
if( !$message ) $message = get_option('fv_wordpress_flowplayer_persistent_notices'); |
| 435 |
$output = array( 'errors' => array($message), 'ok' => false ); |
| 436 |
} |
| 437 |
echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>'; |
| 438 |
die(); |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
/* |
| 444 |
* Run this when new version is installed |
| 445 |
*/ |
| 446 |
add_action('admin_init', 'fv_player_admin_update'); |
| 447 |
|
| 448 |
function fv_player_admin_update() { |
| 449 |
global $fv_fp, $fv_wp_flowplayer_ver; |
| 450 |
|
| 451 |
$aOptions = get_option( 'fvwpflowplayer' ); |
| 452 |
if( !isset($aOptions['version']) || version_compare( $fv_wp_flowplayer_ver, $aOptions['version'] ) ) { |
| 453 |
do_action( 'fv_player_update' ); // trigger update actions |
| 454 |
|
| 455 |
//update_option( 'fv_wordpress_flowplayer_deferred_notices', 'FV Flowplayer upgraded - please click "Check template" and "Check videos" for automated check of your site at <a href="'.site_url().'/wp-admin/admin.php?page=fvplayer">the settings page</a> for automated checks!' ); |
| 456 |
|
| 457 |
if( !empty($aOptions['version']) && $aOptions['version'] == '6.0.5.20' && $aOptions['playlist_advance'] == 'true' ) { // version 6.0.5 used reverse logic for this option! |
| 458 |
$aOptions['playlist_advance'] = false; |
| 459 |
$fv_fp->_get_conf(); |
| 460 |
} |
| 461 |
|
| 462 |
if ( ! isset( $aOptions['autoplay_preload'] ) ) { |
| 463 |
if( $fv_fp->_get_option( 'autoplay' ) || $fv_fp->_get_option( array( 'pro' ,'autoplay_scroll' )) ) { |
| 464 |
$aOptions['autoplay_preload'] = 'viewport'; |
| 465 |
} else { |
| 466 |
$aOptions['autoplay_preload'] = false; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
if( empty($aOptions["interface"]['playlist_titles']) && !empty($aOptions["interface"]["playlist_captions"]) ) { |
| 471 |
$aOptions["interface"]['playlist_titles'] = $aOptions["interface"]["playlist_captions"]; |
| 472 |
} |
| 473 |
|
| 474 |
foreach( array( |
| 475 |
'ad' => 'overlay', |
| 476 |
'ad_css' => 'overlay_css', |
| 477 |
'ad_height' => 'overlay_height', |
| 478 |
'ad_show_after' => 'overlay_show_after', |
| 479 |
'ad_width' => 'overlay_width', |
| 480 |
'adTextColor' => 'overlayTextColor', |
| 481 |
'adLinksColor' => 'overlayLinksColor' |
| 482 |
) as $from => $to ) { |
| 483 |
if( empty($aOptions[ $to ]) && !empty($aOptions[ $from ]) ) { |
| 484 |
$aOptions[ $to ] = $aOptions[ $from ]; |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
$aOptions['version'] = $fv_wp_flowplayer_ver; |
| 489 |
update_option( 'fvwpflowplayer', $aOptions ); |
| 490 |
|
| 491 |
fv_wp_flowplayer_pro_settings_update_for_lightbox(); |
| 492 |
$fv_fp->css_writeout(); |
| 493 |
|
| 494 |
fv_wp_flowplayer_delete_extensions_transients(); |
| 495 |
delete_option('fv_flowplayer_extension_install'); |
| 496 |
} |
| 497 |
|
| 498 |
if( isset($_POST['fv-player-pro-release']) && isset($_POST['fv_player_pro_switch']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['fv_player_pro_switch'] ) ), 'fv_player_pro_switch') ) { |
| 499 |
$fv_fp->css_writeout(); |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
function fv_wp_flowplayer_pro_settings_update_for_lightbox(){ |
| 504 |
global $fv_fp; |
| 505 |
if(isset($fv_fp->conf['pro']) && isset($fv_fp->conf['pro']['interface']['lightbox']) && $fv_fp->conf['pro']['interface']['lightbox'] == true ){ |
| 506 |
$fv_fp->conf['interface']['lightbox'] = true; |
| 507 |
$fv_fp->conf['pro']['interface']['lightbox'] = false; |
| 508 |
$options = get_option('fvwpflowplayer'); |
| 509 |
unset($options['pro']['interface']['lightbox']); |
| 510 |
$options['interface']['lightbox'] = true; |
| 511 |
update_option('fvwpflowplayer', $options); |
| 512 |
} |
| 513 |
if(isset($fv_fp->conf['pro']) && isset($fv_fp->conf['pro']['lightbox_images']) && $fv_fp->conf['pro']['lightbox_images'] == true ){ |
| 514 |
$fv_fp->conf['lightbox_images'] = true; |
| 515 |
$fv_fp->conf['pro']['lightbox_images'] = false; |
| 516 |
$options = get_option('fvwpflowplayer'); |
| 517 |
unset($options['pro']['lightbox_images']); |
| 518 |
$options['lightbox_images'] = true; |
| 519 |
update_option('fvwpflowplayer', $options); |
| 520 |
} |
| 521 |
|
| 522 |
} |
| 523 |
|
| 524 |
function fv_wp_flowplayer_delete_extensions_transients( $delete_delay = false ){ |
| 525 |
$aTransientsLike = array('fv-player_license','fv-player-pro_license','fv-player-vast_license','fv-player-pro_fp-private-updates','fv-player-vast_fp-private-updates'); |
| 526 |
|
| 527 |
global $wpdb; |
| 528 |
$aWhere = array(); |
| 529 |
foreach( $aTransientsLike AS $sKey ) { |
| 530 |
$aWhere[] = $wpdb->prepare( 'option_name LIKE %s', '%' . $wpdb->esc_like( $sKey) . '%' ); |
| 531 |
} |
| 532 |
$sWhere = implode(" OR ", $aWhere); |
| 533 |
|
| 534 |
$aOptions = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%_transient_fv%' AND ( {$sWhere} )" ); |
| 535 |
|
| 536 |
foreach( $aOptions AS $sKey ) { |
| 537 |
if( !$delete_delay ){ |
| 538 |
delete_transient( str_replace('_transient_','',$sKey) ); |
| 539 |
} else { |
| 540 |
fv_wp_flowplayer_change_transient_expiration( str_replace('_transient_','',$sKey), $delete_delay ); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
$aUpdates = get_site_transient('update_plugins'); |
| 545 |
set_site_transient('update_plugins', $aUpdates ); |
| 546 |
|
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
add_action('admin_init', 'fv_player_lchecks'); |
| 551 |
|
| 552 |
function fv_player_lchecks() { |
| 553 |
$aCheck = get_transient( 'fv-player_license' ); |
| 554 |
|
| 555 |
if( isset($_REQUEST['nonce_fv_player_pro_install']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce_fv_player_pro_install'] ) ), 'fv_player_pro_install') ) { |
| 556 |
|
| 557 |
if ( ! $aCheck || empty( $aCheck->valid ) ) { |
| 558 |
global $fv_fp, $fv_wp_flowplayer_ver; |
| 559 |
$fv_fp->strPluginSlug = 'fv-player'; |
| 560 |
$fv_fp->version = $fv_wp_flowplayer_ver; |
| 561 |
$fv_fp->license_key = 'activation'; |
| 562 |
|
| 563 |
$fv_fp->check_license( true ); |
| 564 |
|
| 565 |
$aCheck = get_transient( 'fv-player_license' ); |
| 566 |
} |
| 567 |
|
| 568 |
if( isset($aCheck->valid) && $aCheck->valid){ |
| 569 |
fv_wp_flowplayer_install_extension('fv_player_pro'); |
| 570 |
|
| 571 |
} else if ( ! empty( $aCheck->message ) ) { |
| 572 |
add_action( 'admin_notices', 'fv_player_install_pro_license_notice' ); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
if( isset($aCheck->valid) && $aCheck->valid){ |
| 577 |
delete_option('fv_wordpress_flowplayer_persistent_notices'); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
function fv_wp_flowplayer_admin_key_update() { |
| 582 |
global $fv_fp; |
| 583 |
|
| 584 |
$data = fv_wp_flowplayer_license_check( array('action' => 'key_update') ); |
| 585 |
if( isset($data->domain) ) { // todo: test |
| 586 |
if( $data->domain && $data->key && stripos( home_url(), $data->domain ) !== false ) { |
| 587 |
$fv_fp->conf['key'] = $data->key; |
| 588 |
update_option( 'fvwpflowplayer', $fv_fp->conf ); |
| 589 |
update_option( 'fvwpflowplayer_core_ver', flowplayer::get_core_version() ); |
| 590 |
|
| 591 |
fv_wp_flowplayer_change_transient_expiration("fv-player_license",5); |
| 592 |
fv_wp_flowplayer_delete_extensions_transients(5); |
| 593 |
return true; |
| 594 |
} |
| 595 |
} else if( isset($data->expired) && $data->expired && isset($data->message) ){ |
| 596 |
update_option( 'fv_wordpress_flowplayer_persistent_notices', $data->message ); |
| 597 |
update_option( 'fvwpflowplayer_core_ver', flowplayer::get_core_version() ); |
| 598 |
return false; |
| 599 |
} else { |
| 600 |
update_option( 'fv_wordpress_flowplayer_deferred_notices', 'FV Player License upgrade failed - please check if you are running the plugin on your licensed domain or download FV Player Pro on <a href="https://foliovision.com/my-licenses" target="_blank">Your Foliovison.com Licenses page</a>' ); |
| 601 |
update_option( 'fvwpflowplayer_core_ver', flowplayer::get_core_version() ); |
| 602 |
return false; |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
function fv_wp_flowplayer_license_check( $aArgs ) { |
| 607 |
global $fv_wp_flowplayer_ver; |
| 608 |
|
| 609 |
$args = array( |
| 610 |
'body' => array( 'plugin' => 'fv-wordpress-flowplayer', 'version' => $fv_wp_flowplayer_ver, 'core_ver' => flowplayer::get_core_version(), 'type' => home_url(), 'action' => $aArgs['action'], 'admin-url' => admin_url() ), |
| 611 |
'timeout' => 10, |
| 612 |
'user-agent' => 'fv-wordpress-flowplayer-'.$fv_wp_flowplayer_ver.' ('.flowplayer::get_core_version().')' |
| 613 |
); |
| 614 |
$resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $args ); |
| 615 |
|
| 616 |
if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\S]*?<FVFLOWPLAYER>(.*?)</FVFLOWPLAYER>[\s\S]*?~', '$1', $resp['body'] ) ) ) { |
| 617 |
return $data; |
| 618 |
|
| 619 |
} else if( is_wp_error($resp) ) { |
| 620 |
$args['sslverify'] = false; |
| 621 |
$resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $args ); |
| 622 |
|
| 623 |
if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\S]*?<FVFLOWPLAYER>(.*?)</FVFLOWPLAYER>[\s\S]*?~', '$1', $resp['body'] ) ) ) { |
| 624 |
return $data; |
| 625 |
} |
| 626 |
|
| 627 |
} |
| 628 |
|
| 629 |
return false; |
| 630 |
} |
| 631 |
|
| 632 |
function fv_wp_flowplayer_change_transient_expiration( $transient_name, $time ){ |
| 633 |
$transient_val = get_transient($transient_name); |
| 634 |
if( $transient_val ){ |
| 635 |
set_transient($transient_name,$transient_val,$time); |
| 636 |
return true; |
| 637 |
} |
| 638 |
return false; |
| 639 |
} |
| 640 |
|
| 641 |
add_action('admin_notices', 'fv_wordpress_flowplayer_expired_license_update_notice'); |
| 642 |
|
| 643 |
function fv_wordpress_flowplayer_expired_license_update_notice() { |
| 644 |
if( get_current_screen()->base === 'update-core' && get_option('fv_wordpress_flowplayer_expired_license_update_notice') ) { |
| 645 |
echo '<div class="notice notice-error is-dismissible"><p>' . esc_html__( 'To update FV Player please either renew your license or disable FV Player Pro.', 'fv-player' ) . '</p></div>'; |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
add_action( 'after_plugin_row_fv-player/fv-player.php', 'fv_wordpress_flowplayer_expired_license_update_plugin_row', 0, 3 ); |
| 650 |
|
| 651 |
function fv_wordpress_flowplayer_expired_license_update_plugin_row($plugin_file, $plugin_data, $status) { |
| 652 |
if( get_option('fv_wordpress_flowplayer_expired_license_update_notice') ) { |
| 653 |
echo '<tr class="plugin-update-tr active" style="position: relative; top: -1px"><td colspan="4" class="plugin-update colspanchange"><div class="update-message notice inline notice-warning notice-alt"><p>' . esc_html__('To update FV Player please either renew your license or disable FV Player Pro.', 'fv-player') . '</p></div></td></tr>'; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
add_action('wp_ajax_flowplayer_conversion_script', 'flowplayer_conversion_script'); |
| 659 |
|
| 660 |
function flowplayer_conversion_script() { |
| 661 |
global $wpdb; |
| 662 |
|
| 663 |
$posts = $wpdb->get_results("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_type != 'revision'"); |
| 664 |
|
| 665 |
$old_shorttag = '[flowplayer'; |
| 666 |
$new_shorttag = '[fvplayer'; |
| 667 |
$counter = 0; |
| 668 |
|
| 669 |
echo '<ol>'; |
| 670 |
foreach($posts as $fv_post) { |
| 671 |
if ( stripos( $fv_post->post_content, $old_shorttag ) !== false ) { |
| 672 |
$update_post = array(); |
| 673 |
$update_post['ID'] = $fv_post->ID; |
| 674 |
$update_post['post_content'] = str_replace( $old_shorttag, $new_shorttag, $fv_post->post_content ); |
| 675 |
wp_update_post( $update_post ); |
| 676 |
echo '<li><a href="' . get_permalink($fv_post->ID) . '">' . get_the_title($fv_post->ID) . '</a> updated</li>'; |
| 677 |
$counter++; |
| 678 |
} |
| 679 |
} |
| 680 |
echo '</ol>'; |
| 681 |
|
| 682 |
echo '<strong>Conversion was succesful. Total number of converted posts: ' . intval( $counter ) . '</strong>'; |
| 683 |
|
| 684 |
delete_option('fvwpflowplayer_conversion'); |
| 685 |
|
| 686 |
die(); |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
add_action('admin_notices', 'fv_wp_flowplayer_admin_notice'); |
| 693 |
|
| 694 |
function fv_wp_flowplayer_admin_notice() { |
| 695 |
if( $notices = get_option('fv_wordpress_flowplayer_deferred_notices') ) { |
| 696 |
echo '<div class="updated inline"> |
| 697 |
<p>'.$notices.'</p> |
| 698 |
</div>'; |
| 699 |
delete_option('fv_wordpress_flowplayer_deferred_notices'); |
| 700 |
} |
| 701 |
|
| 702 |
$conversion = false; //(bool)get_option('fvwpflowplayer_conversion'); |
| 703 |
if ($conversion ) { |
| 704 |
echo '<div class="updated" id="fvwpflowplayer_conversion_notice"><p>'; |
| 705 |
printf( |
| 706 |
wp_kses( __( 'FV Player has found old shortcodes in the content of your posts. <a href="%1$s">Run the conversion script.</a>', 'fv-player' ), array( 'a' => array( 'href' => array() ) ) ), |
| 707 |
get_admin_url() . 'admin.php?page=fvplayer'); |
| 708 |
echo "</p></div>"; |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
/* |
| 719 |
* Check the extension info from plugin license transient and activate the plugin |
| 720 |
*/ |
| 721 |
function fv_wp_flowplayer_install_extension( $plugin_package = 'fv_player_pro' ) { |
| 722 |
|
| 723 |
$aInstalled = get_option( 'fv_flowplayer_extension_install', array() ); |
| 724 |
$aInstalled = array_merge( $aInstalled, array( $plugin_package => false ) ); |
| 725 |
update_option('fv_flowplayer_extension_install', $aInstalled ); |
| 726 |
|
| 727 |
$aPluginInfo = get_transient( 'fv-player_license' ); |
| 728 |
|
| 729 |
if ( ! $aPluginInfo || empty( $aPluginInfo->valid ) ) { |
| 730 |
global $fv_fp, $fv_wp_flowplayer_ver; |
| 731 |
$fv_fp->strPluginSlug = 'fv-player'; |
| 732 |
$fv_fp->version = $fv_wp_flowplayer_ver; |
| 733 |
$fv_fp->license_key = 'activation'; |
| 734 |
|
| 735 |
$fv_fp->check_license( true ); |
| 736 |
|
| 737 |
$aPluginInfo = get_transient( 'fv-player_license' ); |
| 738 |
} |
| 739 |
|
| 740 |
$plugin_basename = $aPluginInfo->{$plugin_package}->slug; |
| 741 |
$download_url = $aPluginInfo->{$plugin_package}->url; |
| 742 |
|
| 743 |
$result = FV_Wordpress_Flowplayer_Plugin_Private::install_plugin( |
| 744 |
"FV Player Pro", |
| 745 |
$plugin_package, |
| 746 |
$plugin_basename, |
| 747 |
$download_url, |
| 748 |
admin_url('admin.php?page=fvplayer&reload='.wp_rand()), |
| 749 |
'fv_wordpress_flowplayer_deferred_notices', |
| 750 |
'fv_player_pro_install' |
| 751 |
); |
| 752 |
|
| 753 |
$aInstalled = ( get_option('fv_flowplayer_extension_install' ) ) ? get_option('fv_flowplayer_extension_install' ) : array(); |
| 754 |
$aInstalled = array_merge( $aInstalled, array( $plugin_package => $result ) ); |
| 755 |
update_option('fv_flowplayer_extension_install', $aInstalled ); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
function flowplayer_deactivate() { |
| 762 |
if ( WP_Filesystem() ) { |
| 763 |
global $wp_filesystem; |
| 764 |
|
| 765 |
if( $wp_filesystem->exists( $wp_filesystem->wp_content_dir().'fv-player-tracking/' ) ) { |
| 766 |
$wp_filesystem->rmdir( $wp_filesystem->wp_content_dir().'fv-player-tracking/', true ); |
| 767 |
} |
| 768 |
|
| 769 |
if( $wp_filesystem->exists( $wp_filesystem->wp_content_dir().'fv-flowplayer-custom/' ) ) { |
| 770 |
$wp_filesystem->rmdir( $wp_filesystem->wp_content_dir().'fv-flowplayer-custom/', true ); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
delete_option( 'fv_flowplayer_extension_install' ); |
| 775 |
|
| 776 |
wp_clear_scheduled_hook( 'fv_flowplayer_checker_event' ); |
| 777 |
wp_clear_scheduled_hook( 'fv_player_stats' ); |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
/* |
| 784 |
* DB based player data saving |
| 785 |
*/ |
| 786 |
global $FV_Player_Db; |
| 787 |
|
| 788 |
// these have to be here, as using them in constructor doesn't work |
| 789 |
add_filter('heartbeat_received', array($FV_Player_Db, 'check_db_edit_lock'), 10, 2); |
| 790 |
|
| 791 |
|
| 792 |
add_action( 'admin_notices', 'fv_player_embedded_on_fix' ); |
| 793 |
|
| 794 |
function fv_player_embedded_on_fix() { |
| 795 |
if( current_user_can('install_plugins') && isset($_GET['action']) && sanitize_text_field( $_GET['action'] ) == 'fv-player-embedded-on-fix' && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'fv-player-embedded-on-fix' ) ) { |
| 796 |
|
| 797 |
global $wpdb; |
| 798 |
$players_with_no_posts = $wpdb->get_col( "SELECT p.id FROM {$wpdb->prefix}fv_player_players AS p LEFT JOIN {$wpdb->prefix}fv_player_playermeta AS m ON p.id = m.id_player AND m.meta_key = 'post_id' OR m.id IS NULL WHERE m.id IS NULL" ); |
| 799 |
|
| 800 |
echo "<h2>FV Player Embedded On Post Scan</h2>\n"; |
| 801 |
|
| 802 |
echo '<p>' . sprintf( 'It appears there are %d players which do not belong to any post.', count( $players_with_no_posts ) ) . "</p>\n"; |
| 803 |
|
| 804 |
if ( $players_with_no_posts ) { |
| 805 |
foreach ( $players_with_no_posts as $player_id ) { |
| 806 |
echo '<p>'; |
| 807 |
echo 'Player #' . intval( $player_id ) . '... '; |
| 808 |
|
| 809 |
$wild = '%'; |
| 810 |
$find = 'fvplayer id="'.$player_id.'"'; |
| 811 |
$like = $wild . $wpdb->esc_like( $find ) . $wild; |
| 812 |
|
| 813 |
$posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status != 'trash' AND post_type != 'revision' AND post_content LIKE %s", $like ) ); |
| 814 |
|
| 815 |
$post_meta = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS m JOIN $wpdb->posts AS p ON m.post_id = p.ID WHERE post_status != 'trash' AND post_type != 'revision' AND meta_value LIKE %s", $like ) ); |
| 816 |
|
| 817 |
$posts = array_merge( $posts, $post_meta ); |
| 818 |
|
| 819 |
$posts = array_unique( $posts ); |
| 820 |
|
| 821 |
if ( count($posts) > 0 ) { |
| 822 |
|
| 823 |
echo "Found in posts: " . implode( ', ', $posts ) . "\n"; |
| 824 |
|
| 825 |
foreach ( $posts AS $post_id ) { |
| 826 |
$meta = new FV_Player_Db_Player_Meta(null, array( |
| 827 |
'id_player' => $player_id, |
| 828 |
'meta_key' => 'post_id', |
| 829 |
'meta_value' => $post_id |
| 830 |
) ); |
| 831 |
|
| 832 |
$meta->save(); |
| 833 |
} |
| 834 |
|
| 835 |
} else { |
| 836 |
echo "Not found in any post.\n"; |
| 837 |
|
| 838 |
} |
| 839 |
|
| 840 |
echo "</p>\n"; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
die( 'Done!' ); |
| 845 |
|
| 846 |
} |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
add_action( 'admin_notices', 'fv_player_rollback' ); |
| 851 |
|
| 852 |
function fv_player_rollback() { |
| 853 |
if( current_user_can('install_plugins') && isset($_GET['action']) && sanitize_text_field( $_GET['action'] ) == 'fv-player-rollback' && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'fv-player-rollback' ) ) { |
| 854 |
|
| 855 |
ob_start(); // first check if we can perform the update automatically! |
| 856 |
$creds = request_filesystem_credentials( admin_url(), '', false, false, array() ); |
| 857 |
if( !WP_Filesystem($creds) ) { // if not, then don't try to do it at all |
| 858 |
ob_get_clean(); |
| 859 |
echo "<div class='error'><p>Unfortunately rollback is not supported as your site can't install plugins without FTP. Please login to your Foliovision.com account and download the previous plugin version there using the \"Show Previous Version\" button.</p></div>"; |
| 860 |
return; |
| 861 |
} |
| 862 |
|
| 863 |
echo ob_get_clean(); |
| 864 |
|
| 865 |
global $fv_fp, $fv_wp_flowplayer_ver; |
| 866 |
$fv_fp->pointer_boxes = array(); // no pointer boxes here! |
| 867 |
|
| 868 |
$plugin_slug = false; |
| 869 |
$active_plugins = get_option( 'active_plugins' ); |
| 870 |
foreach( $active_plugins AS $plugin ) { |
| 871 |
if( stripos($plugin,'fv-player') === 0 && stripos($plugin,'/fv-player.php') !== false ) { |
| 872 |
$plugin_slug = $plugin; |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
$plugin_transient = get_site_transient( 'update_plugins' ); |
| 877 |
$plugin_folder = plugin_basename( dirname( $plugin_slug ) ); |
| 878 |
$plugin_file = basename( $plugin_slug ); |
| 879 |
$version = isset($_GET['version']) ? sanitize_text_field( $_GET['version'] ) : '6.6.6'; |
| 880 |
$url = 'https://downloads.wordpress.org/plugin/fv-player.'.$version.'.zip'; |
| 881 |
$temp_array = array( |
| 882 |
'slug' => $plugin_folder, |
| 883 |
'new_version' => $version, |
| 884 |
'url' => 'https://foliovision.com', |
| 885 |
'package' => $url, |
| 886 |
); |
| 887 |
|
| 888 |
$temp_object = (object) $temp_array; |
| 889 |
$plugin_transient->response[ $plugin_folder . '/' . $plugin_file ] = $temp_object; |
| 890 |
set_site_transient( 'update_plugins', $plugin_transient ); |
| 891 |
|
| 892 |
add_filter( 'upgrader_pre_download', 'fv_player_rollback_message' ); |
| 893 |
|
| 894 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
| 895 |
$title = 'FV Player Rollback'; |
| 896 |
$nonce = 'upgrade-plugin_' . $plugin_slug; |
| 897 |
$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin_slug ); |
| 898 |
$upgrader_skin = new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ); |
| 899 |
$upgrader = new Plugin_Upgrader( $upgrader_skin ); |
| 900 |
$upgrader->upgrade( $plugin_slug ); |
| 901 |
|
| 902 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |
| 903 |
|
| 904 |
delete_option('fv-player-pro-release'); |
| 905 |
|
| 906 |
|
| 907 |
$active_plugins = get_option( 'active_plugins' ); |
| 908 |
foreach( $active_plugins AS $plugin ) { |
| 909 |
if( stripos( $plugin, 'fv-player-pro' ) === 0 ) { |
| 910 |
delete_plugins( array($plugin) ); // deleting the FV Player Pro plugin here means that he FV Player activation process in the iframe will already re-install it in the iframe, so in the iframe you will get the FV Player settings screen! |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
wp_die( '', 'FV Player Rollback', array( 'response' => 200 ) ); |
| 915 |
|
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
function fv_player_rollback_message( $val ) { |
| 920 |
echo "<div class='updated'>"; |
| 921 |
echo "<p>Please wait until the plugin download and reactivation is completed.</p>"; |
| 922 |
if( flowplayer::is_licensed() ) { |
| 923 |
echo "<p>We also rollback the FV Player Pro plugin in the process.</p>"; |
| 924 |
if( class_exists('FV_Player_Pro') ) echo "<style>#wpbody-content iframe[title=\"Update progress\"] { display: none; }</style>"; |
| 925 |
} |
| 926 |
echo "</div>"; |
| 927 |
return $val; |
| 928 |
} |
| 929 |
|
| 930 |
add_action( 'admin_notices', 'fv_player_pro_version_check' ); |
| 931 |
|
| 932 |
function fv_player_pro_version_check() { |
| 933 |
$version = '7.5.0.727'; |
| 934 |
|
| 935 |
global $FV_Player_Pro; |
| 936 |
|
| 937 |
if( !empty($FV_Player_Pro) && !fv_player_extension_version_is_min($version,'pro') ) : |
| 938 |
?> |
| 939 |
<div class="error"> |
| 940 |
<p><?php printf( esc_html__( 'FV Player: Please upgrade to FV Player Pro version %s or above!', 'fv-player' ), $version ); ?></p> |
| 941 |
</div> |
| 942 |
<?php |
| 943 |
endif; |
| 944 |
} |
| 945 |
|
| 946 |
add_action( 'admin_notices', 'fv_player_pay_per_view_version_check' ); |
| 947 |
|
| 948 |
function fv_player_pay_per_view_version_check() { |
| 949 |
$version = '7.5.3.727'; |
| 950 |
|
| 951 |
global $FV_Player_PayPerView; |
| 952 |
|
| 953 |
if( !empty($FV_Player_PayPerView) && !fv_player_extension_version_is_min($version,'ppv') ) : |
| 954 |
?> |
| 955 |
<div class="error"> |
| 956 |
<p><?php printf( esc_html__( 'FV Player: Please upgrade to FV Player Pay Per View version %s or above!', 'fv-player' ), $version ); ?></p> |
| 957 |
</div> |
| 958 |
<?php |
| 959 |
endif; |
| 960 |
} |
| 961 |
|
| 962 |
add_action( 'admin_notices', 'fv_player_pay_per_view_woocommerce_version_check' ); |
| 963 |
|
| 964 |
function fv_player_pay_per_view_woocommerce_version_check() { |
| 965 |
$version = '7.5.3.727'; |
| 966 |
|
| 967 |
global $FV_Player_PayPerView_WooCommerce; |
| 968 |
|
| 969 |
if( !empty($FV_Player_PayPerView_WooCommerce) && !fv_player_extension_version_is_min($version,'ppv-woocommerce') ) : |
| 970 |
?> |
| 971 |
<div class="error"> |
| 972 |
<p><?php printf( esc_html__( 'FV Player: Please upgrade to FV Player Pay Per View for WooCommerce version %s or above!', 'fv-player' ), $version ); ?></p> |
| 973 |
</div> |
| 974 |
<?php |
| 975 |
endif; |
| 976 |
} |
| 977 |
|
| 978 |
// lazy-load of video encoder libraries |
| 979 |
add_action( 'fv_player_load_video_encoder_libs', 'fv_player_load_video_encoder_libs' ); |
| 980 |
function fv_player_load_video_encoder_libs() { |
| 981 |
include_once( dirname( __FILE__ ).'/../models/video-encoder/video-encoder.php'); |
| 982 |
require_once( dirname(__FILE__).'/../includes/class.fv-player-wizard-base.php' ); |
| 983 |
require_once( dirname(__FILE__).'/../includes/class.fv-player-wizard-step-base.php' ); |
| 984 |
} |
| 985 |
|
| 986 |
/** |
| 987 |
* Attachment edit - show attached posts |
| 988 |
*/ |
| 989 |
add_action( 'attachment_submitbox_misc_actions', 'fv_player_submitbox_misc_actions' ); |
| 990 |
|
| 991 |
function fv_player_submitbox_misc_actions( $attachment ) { |
| 992 |
global $pagenow, $typenow; |
| 993 |
|
| 994 |
// We only want to run the code on a specific page |
| 995 |
if( $pagenow != 'post.php' || $typenow != 'attachment' ) { |
| 996 |
return; |
| 997 |
} |
| 998 |
|
| 999 |
global $fv_fp; |
| 1000 |
|
| 1001 |
$video_id = get_post_meta( $attachment->ID, 'fv_player_video_id', true ); |
| 1002 |
|
| 1003 |
if( !empty($video_id) ) { |
| 1004 |
$players = $fv_fp->get_players_by_video_ids( $video_id ); |
| 1005 |
|
| 1006 |
// Iterate players and create html with name and link to player |
| 1007 |
foreach( $players as $player ) { |
| 1008 |
?> |
| 1009 |
<div class="misc-pub-section misc-pub-attachment"> |
| 1010 |
FV Player splash screen: <strong><a href="<?php echo esc_url( admin_url( 'admin.php?page=fv_player&id='. $player->getId() ) ); ?>"><?php echo esc_html( $player->getPlayerNameWithFallback() ); ?></a></strong> |
| 1011 |
</div> |
| 1012 |
<?php |
| 1013 |
} |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
/** |
| 1018 |
* Append or update player row in wp-admin -> FV Player |
| 1019 |
*/ |
| 1020 |
add_action('wp_ajax_fv_player_table_new_row', 'fv_player_table_new_row'); |
| 1021 |
|
| 1022 |
function fv_player_table_new_row() { |
| 1023 |
if( isset($_POST['playerID']) && isset($_POST['nonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), "fv-player-table_new_row_nonce" ) ) { |
| 1024 |
$table = new FV_Player_List_Table( array( |
| 1025 |
'player_id' => intval($_POST['playerID']), |
| 1026 |
'per_page' => 25, |
| 1027 |
'screen' => 'toplevel_page_fv_player' |
| 1028 |
) |
| 1029 |
); |
| 1030 |
|
| 1031 |
$table->prepare_items(); |
| 1032 |
$table->views(); |
| 1033 |
$table->advanced_filters(); |
| 1034 |
$table->display(); |
| 1035 |
exit; |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
/** |
| 1040 |
* Update the player on the wp-admin -> Posts, Pages or CPT screen |
| 1041 |
* |
| 1042 |
* Gets the first video thumbnail only |
| 1043 |
*/ |
| 1044 |
add_action('wp_ajax_fv_player_edit_posts_cell', 'fv_player_edit_posts_cell'); |
| 1045 |
|
| 1046 |
function fv_player_edit_posts_cell() { |
| 1047 |
if( isset($_POST['nonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), "fv-player-edit_posts_cell_nonce" ) ) { |
| 1048 |
|
| 1049 |
$player_id = false; |
| 1050 |
|
| 1051 |
// New player, load from post meta field to ensure it saved |
| 1052 |
if ( ! empty( $_POST['post_id'] ) && ! empty( $_POST['meta_key'] ) ) { |
| 1053 |
$shortcode = get_post_meta( absint( $_POST['post_id'] ), sanitize_key( $_POST['meta_key'] ), true ); |
| 1054 |
$shortcode_atts = shortcode_parse_atts( trim( $shortcode, ']' ) ); |
| 1055 |
|
| 1056 |
if( ! empty($shortcode_atts['id']) ) { |
| 1057 |
$player_id = $shortcode_atts['id']; |
| 1058 |
} |
| 1059 |
|
| 1060 |
// Existing player, load by id |
| 1061 |
} else if ( ! empty( $_POST['playerID'] ) ) { |
| 1062 |
$player_id = absint( $_POST['playerID'] ); |
| 1063 |
} |
| 1064 |
|
| 1065 |
if ( $player_id ) { |
| 1066 |
global $FV_Player_Db; |
| 1067 |
$aPostListPlayers = $FV_Player_Db->getListPageData( array( |
| 1068 |
'player_id' => $player_id |
| 1069 |
) ); |
| 1070 |
|
| 1071 |
if( !empty($aPostListPlayers[0]->thumbs[0]) ) { |
| 1072 |
echo '<a href="#" class="fv-player-edit" data-player_id="' . intval($player_id) . '">' . $aPostListPlayers[0]->thumbs[0] . '</a>'; |
| 1073 |
|
| 1074 |
} else { |
| 1075 |
echo "Error: Player not found!"; |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
exit; |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* Get taxonomies registered for the post type. The core WordPress function |
| 1085 |
* to do this does not return taxonomy if it's enabled for multiple |
| 1086 |
* post types. So we do it properly here. |
| 1087 |
* |
| 1088 |
* @param string $post_type Post type to check |
| 1089 |
* @return array Taxonomy slugs |
| 1090 |
*/ |
| 1091 |
function fv_player_get_post_type_taxonomies( $post_type ) { |
| 1092 |
$taxonomies = get_taxonomies( array( |
| 1093 |
'public' => true, |
| 1094 |
'show_ui' => true, |
| 1095 |
), 'objects' ); |
| 1096 |
|
| 1097 |
$post_type_taxonomies = array(); |
| 1098 |
foreach( $taxonomies AS $taxonomy) { |
| 1099 |
if( in_array( $post_type, $taxonomy->object_type ) ) { |
| 1100 |
$post_type_taxonomies[] = $taxonomy->name; |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
return $post_type_taxonomies; |
| 1105 |
} |
| 1106 |
|
| 1107 |
function fv_player_setup_uninstall_script( $put_in_uninstall_php, $remove_uninstall_php ) { |
| 1108 |
|
| 1109 |
if ( 'direct' !== get_filesystem_method( array(), dirname( dirname( __FILE__ ) ) ) ) { |
| 1110 |
return false; |
| 1111 |
} |
| 1112 |
|
| 1113 |
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) { |
| 1114 |
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; |
| 1115 |
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; |
| 1116 |
} |
| 1117 |
|
| 1118 |
$plugin_folder = basename( dirname( dirname( __FILE__ ) ) ); |
| 1119 |
|
| 1120 |
$wp_filesystem = new WP_Filesystem_Direct( '' ); |
| 1121 |
$original_file = $wp_filesystem->wp_plugins_dir() . $plugin_folder . '/uninstall-script.php'; |
| 1122 |
$new_file = $wp_filesystem->wp_plugins_dir() . $plugin_folder . '/uninstall.php'; |
| 1123 |
|
| 1124 |
if ( $put_in_uninstall_php && ! $wp_filesystem->exists( $new_file ) ) { |
| 1125 |
return $wp_filesystem->copy( $original_file, $new_file ); |
| 1126 |
|
| 1127 |
} else if ( $remove_uninstall_php && $wp_filesystem->exists( $new_file ) ) { |
| 1128 |
return $wp_filesystem->delete( $new_file ); |
| 1129 |
} |
| 1130 |
|
| 1131 |
return false; |
| 1132 |
} |
| 1133 |
|
| 1134 |
function fv_player_install_pro_license_notice() { |
| 1135 |
$aCheck = get_transient( 'fv-player_license' ); |
| 1136 |
if ( ! empty( $aCheck->message ) ) { |
| 1137 |
echo "<div class='error'>" . wp_kses( $aCheck->message, 'post' ) . "</div>"; |
| 1138 |
} |
| 1139 |
} |
| 1140 |
|
| 1141 |
/** |
| 1142 |
* Paid FV Player extensions need to know what's the FV Player version. |
| 1143 |
*/ |
| 1144 |
add_filter( 'http_request_args', 'fv_player_license_checks_base_plugin_version', 10, 2 ); |
| 1145 |
|
| 1146 |
function fv_player_license_checks_base_plugin_version( $parsed_args, $url ) { |
| 1147 |
|
| 1148 |
global $fv_wp_flowplayer_ver; |
| 1149 |
if ( ( stripos( $url, '//foliovision.com/' ) !== false || stripos( $url, '.foliovision.com/' ) !== false ) && stripos( $url, 'fv_remote' ) !== false ) { |
| 1150 |
if ( is_array( $parsed_args['body'] ) ) { |
| 1151 |
$parsed_args['body']['fv_player_core_version'] = $fv_wp_flowplayer_ver; |
| 1152 |
|
| 1153 |
// No POST? It seems this adds to the URL query string which we need to actual plugin update downloads. |
| 1154 |
} else if ( empty( $parsed_args['body'] ) ) { |
| 1155 |
$parsed_args['body'] = array( 'fv_player_core_version' => $fv_wp_flowplayer_ver ); |
| 1156 |
} |
| 1157 |
} |
| 1158 |
|
| 1159 |
return $parsed_args; |
| 1160 |
} |
| 1161 |
|