PluginProbe
FV Player 8 / 8.0.21
FV Player 8 v8.0.21
trunk 8.0.18 8.0.19 8.0.20 8.0.21 8.0.25 8.0.27 8.1 8.1.3
fv-player / controller / backend.php

backend.php in FV Player 8 8.0.21, at controller/backend.php

1,148 lines 43.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 if( is_wp_error( $response ) ) {
135 $error_message = $response->get_error_message();
136 $output = array( 'errors' => $error_message);
137 } else if ($response['response']['code'] == 401){
138 $errors[] = 'You are using http auth, we cannot check template.';
139 $output = array( 'errors' => $errors);
140 } else {
141
142 $active_plugins = get_option( 'active_plugins' );
143 foreach( $active_plugins AS $plugin ) {
144 if( stripos( $plugin, 'wp-minify' ) !== false ) {
145 $errors[] = "You are using <strong>WP Minify</strong>, so the script checks would not be accurate. Please check your videos manually.";
146 $output = array( 'errors' => $errors, 'ok' => $ok/*, 'html' => $response['body'] */);
147 echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>';
148 die();
149 }
150 }
151
152 $combine_js_warning = false;
153
154 if( function_exists( 'w3_instance' ) && $minify = w3_instance('W3_Plugin_Minify') ) {
155 if( $minify->_config->get_boolean('minify.js.enable') ) {
156 $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.";
157
158 $combine_js_warning = true;
159 }
160 }
161
162 if( class_exists( 'SiteGround_Optimizer\Options\Options' ) && method_exists( 'SiteGround_Optimizer\Options\Options', 'is_enabled' ) ) {
163
164 // Avoiding PHP 5.2 lint errors
165 if( call_user_func_array( array( 'SiteGround_Optimizer\Options\Options', 'is_enabled' ), array( 'siteground_optimizer_combine_javascript' ) ) ) {
166 $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.";
167
168 $combine_js_warning = true;
169 }
170 }
171
172 $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' );
173
174 $response['body'] = preg_replace( '$<!--[\s\S]+?-->$', '', $response['body'] ); // handle HTML comments
175
176 // check Flowplayer scripts
177 preg_match_all( '!<script[^>]*?src=[\'"]([^\'"]*?freedomplayer[0-9.-]*?(?:\.min)?\.js[^\'"]*?)[\'"][^>]*?>\s*?</script>!', $response['body'], $freedomplayer_scripts );
178 if( count($freedomplayer_scripts[1]) > 0 ) {
179 if( count($freedomplayer_scripts[1]) > 1 ) {
180 $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.";
181 }
182 foreach( $freedomplayer_scripts[1] AS $flowplayer_script ) {
183 $check = fv_wp_flowplayer_check_script_version( $flowplayer_script );
184 if( $check == - 1 ) {
185 $errors[] = "Flowplayer script <code>$flowplayer_script</code> is old version and won't play. You need to get rid of this script.";
186 } else if( $check == 1 ) {
187 $ok[] = __( 'FV Player script found: ', 'fv-player' ) . "<code>$flowplayer_script</code>!";
188 $fv_flowplayer_pos = strpos( $response['body'], $flowplayer_script );
189 } else if( $check == 0 ) {
190 $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>";
191 }
192 }
193 } else if( !$combine_js_warning && count($freedomplayer_scripts[1]) < 1 ) {
194 $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()!";
195 }
196
197
198 // check jQuery scripts
199 preg_match_all( '!<script[^>]*?src=[\'"]([^\'"]*?/jquery[0-9.-]*?(?:\.min)?\.js[^\'"]*?)[\'"][^>]*?>\s*?</script>!', $response['body'], $jquery_scripts );
200 if( count($jquery_scripts[1]) > 0 ) {
201 foreach( $jquery_scripts[1] AS $jkey => $jquery_script ) {
202 $ok[] = __( 'jQuery library found: ', 'fv-player' ) . "<code>$jquery_script</code>!";
203 $jquery_pos = strpos( $response['body'], $jquery_script );
204 }
205
206 if( count($jquery_scripts[1]) > 1 ) {
207 $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";
208 }
209 } else if( count($jquery_scripts[1]) < 1 ) {
210 $errors[] = "It appears there are <strong>no</strong> jQuery library on your site, your videos might not be playing, please check.\n";
211 }
212
213
214 if( $fv_flowplayer_pos > 0 && $jquery_pos > 0 && $jquery_pos > $fv_flowplayer_pos && count($jquery_scripts[1]) < 1 ) {
215 $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.";
216 }
217
218 // check if Permissions-Policy header is set and has autoplay=() in it
219 $headers = wp_remote_retrieve_headers( $response );
220 if( isset($headers['permissions-policy']) && strpos( $headers['permissions-policy'], 'autoplay=()' ) !== false ) {
221 $errors[] = sprintf(
222 __( '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' ),
223 esc_html( $headers['permissions-policy'] )
224 );
225 } else if ( isset($headers['permissions-policy'] ) ) {
226 $ok[] = sprintf(
227 __( 'You are using Permissions-Policy HTTP header to adjust the autoplay permissions: <code>%s</code>', 'fv-player' ),
228 esc_html( $headers['permissions-policy'] )
229 );
230 } else {
231 $ok[] = __( 'You are not using Permissions-Policy HTTP header to adjust the autoplay permissions.', 'fv-player' );
232 }
233
234 $output = array( 'errors' => $errors, 'ok' => $ok/*, 'html' => $response['body'] */);
235 }
236 echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>';
237 die();
238 }
239
240 // enter script URL, return false if it's not version 5
241 function fv_wp_flowplayer_check_script_version( $url ) {
242 $url_mod = preg_replace( '!\?.+!', '', $url );
243 if( preg_match( '!flowplayer-([\d\.]+)!', $url_mod, $version ) && $version[1] ) {
244 if( strpos( $version[1], '5' ) !== 0 ) {
245 return -1;
246 }
247 }
248
249 global $fv_wp_flowplayer_ver;
250 if( strpos( $url, '/freedom-video-player/fv-player.min.js?ver='.$fv_wp_flowplayer_ver ) !== false ) {
251 return 1;
252 }
253
254 // when using Google PageSpeed module
255 if( strpos( $url, '/freedom-video-player/fv-player.min.js,qver='.$fv_wp_flowplayer_ver ) !== false ) {
256 return 1;
257 }
258
259 // when using SCRIPT_DEBUG
260 if( strpos( $url, '/freedom-video-player/freedomplayer.min.js?ver=' ) !== false ) {
261 return 1;
262 }
263
264 // when using SCRIPT_DEBUG with Google PageSpeed module
265 if( strpos( $url, '/freedom-video-player/freedomplayer.min.js,qver=' ) !== false ) {
266 return 1;
267 }
268
269 return 0;
270 }
271
272 function fv_wp_flowplayer_check_jquery_version( $url, &$array, $key ) {
273 $url_mod = preg_replace( '!\?.+!', '', $url );
274 if( preg_match( '!(\d+.[\d\.]+)!', $url_mod, $version ) && $version[1] ) {
275 if( version_compare($version[1], '1.7.1') == -1 ) {
276 return -1;
277 } else {
278 return 1;
279 }
280 }
281
282 // if jQuery is in the Wordpress install, we know that the ?ver= says what version it is
283 if( strpos( $url, site_url().'/wp-includes/js/jquery/jquery.js' ) !== false ) {
284 if( preg_match( '!(\d+.[\d\.]+)!', $url, $version ) && $version[1] ) {
285 if( version_compare($version[1], '1.7.1') == -1 ) {
286 return -1;
287 } else {
288 return 1;
289 }
290 }
291 }
292
293 return 0;
294 }
295
296
297
298
299 /*
300 * Check video files
301 */
302 add_action('wp_ajax_fv_wp_flowplayer_check_files', 'fv_wp_flowplayer_check_files');
303
304 function fv_wp_flowplayer_check_files() {
305
306 if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'fv_wp_flowplayer_check_files' ) ) {
307 $output = array( 'errors' => array( 'Nonce verification failed' ), 'ok' => false );
308 echo '<FVFLOWPLAYER>' . wp_json_encode( $output ) . '</FVFLOWPLAYER>';
309 die();
310 }
311
312 global $wpdb;
313
314 $bNotDone = false;
315 $tStart = microtime(true);
316 $tMax = ( @ini_get('max_execution_time') ) ? @ini_get('max_execution_time') - 5 : 25;
317
318 $videos1 = $wpdb->get_results( "SELECT ID, post_content FROM $wpdb->posts WHERE post_type != 'revision' AND post_status != 'trash' AND post_content LIKE '%[flowplayer %'" );
319 $videos2 = $wpdb->get_results( "SELECT ID, post_content FROM $wpdb->posts WHERE post_type != 'revision' AND post_status != 'trash' AND post_content LIKE '%[fvplayer %'" );
320
321 $videos = array_merge( $videos1, $videos2 );
322
323 $source_servers = array();
324
325 $shortcodes_count = 0;
326 $src_count = 0;
327 if( count($videos) ) {
328 foreach( $videos AS $post ) {
329
330 $shortcodes_count += preg_match_all( '!\[(?:flowplayer|fvplayer)[^\]]+\]!', $post->post_content, $post_videos );
331 if( count($post_videos[0]) ) {
332 foreach( $post_videos[0] AS $post_video ) {
333 $post_video = preg_replace( '!popup=\'.*\'!', '', $post_video );
334 $src_count += preg_match_all( '!(?:src|src1|src2|src3|mp4|webm|ogv)=[\'"](.*?(?:mp4|m4v))[\'"]!', $post_video, $sources1 );
335 $src_count += preg_match_all( '!(?:src|src1|src2|src3|mp4|webm|ogv)=([^\'"].*?(?:mp4|m4v|flv))[\s\]]!', $post_video, $sources2 );
336 $sources = array_merge( $sources1[1], $sources2[1] );
337 if( count($sources) ) {
338 foreach($sources AS $src ) {
339 if( strpos( $src, '//' ) === 0 ) {
340 $src = 'http:'.$src;
341 } else if( strpos( $src, '/' ) === 0 ) {
342 $src = home_url().$src;
343 }
344
345 $server = preg_replace( '!(.*?//.*?)/.+!', '$1', $src );
346
347 $source_servers[$server][] = array( 'src' => $src, 'post_id' => $post->ID );
348 }
349 }
350 }
351 }
352
353 }
354 }
355
356 $ok = array();
357 $errors = array();
358
359 $count = 0;
360 foreach( $source_servers AS $server => $videos ) {
361
362 $tCurrent = microtime(true);
363 if( $tCurrent - $tStart > $tMax ) {
364 $bNotDone = true;
365 break;
366 }
367
368 if( stripos( $videos[0]['src'], '.mp4' ) === FALSE /*&& stripos( $videos[0]['src'], '.m4v' ) === FALSE*/ ) {
369 continue;
370 }
371
372 global $FV_Player_Checker;
373
374 if( stripos( trim($videos[0]['src']), 'rtmp://' ) === false ) {
375 list( $header, $message_out ) = $FV_Player_Checker->http_request( trim($videos[0]['src']), array( 'quick_check' => 10, 'size' => 65536 ) );
376 if( $header ) {
377 $headers = WP_Http::processHeaders( $header );
378 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 ) );
379 if( $fatal ) {
380 continue;
381 }
382 if( $new_errors ) {
383 $sPostsLinks = false;
384 foreach( $videos AS $video ) {
385 $sPostsLinks .= '<a href="'.home_url().'?p='.$video['post_id'].'">'.$video['post_id'].'</a> ';
386 }
387 $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>';
388 $count++;
389 continue;
390 } else {
391 $ok[] = 'Server <code>'.$server.'</code> appears to serve correct mime type <code>'.$mime_type.'</code> for MP4 videos.';
392 }
393 }
394 }
395 }
396
397 if( $bNotDone ) {
398 $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>';
399 }
400
401 $output = array( 'errors' => $errors, 'ok' => $ok/*, 'html' => $response['body'] */);
402 echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>';
403 die();
404 }
405
406
407
408
409 /*
410 * Apply Pro Upgrade button
411 */
412 add_action('wp_ajax_fv_wp_flowplayer_check_license', 'fv_wp_flowplayer_check_license');
413
414 function fv_wp_flowplayer_check_license() {
415 if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'fv_wp_flowplayer_check_license' ) ) {
416 $output = array( 'errors' => array( 'Nonce verification failed' ), 'ok' => false );
417
418 } else if( fv_wp_flowplayer_admin_key_update() ) {
419 $output = array( 'errors' => false, 'ok' => array(__( 'License key acquired successfully. <a href="">Reload</a>', 'fv-player' )) );
420 fv_wp_flowplayer_install_extension();
421 } else {
422 $message = get_option('fv_wordpress_flowplayer_deferred_notices');
423 if( !$message ) $message = get_option('fv_wordpress_flowplayer_persistent_notices');
424 $output = array( 'errors' => array($message), 'ok' => false );
425 }
426 echo '<FVFLOWPLAYER>'.wp_json_encode($output).'</FVFLOWPLAYER>';
427 die();
428 }
429
430
431
432 /*
433 * Run this when new version is installed
434 */
435 add_action('admin_init', 'fv_player_admin_update');
436
437 function fv_player_admin_update() {
438 global $fv_fp, $fv_wp_flowplayer_ver;
439
440 $aOptions = get_option( 'fvwpflowplayer' );
441 if( !isset($aOptions['version']) || version_compare( $fv_wp_flowplayer_ver, $aOptions['version'] ) ) {
442 do_action( 'fv_player_update' ); // trigger update actions
443
444 //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!' );
445
446 if( !empty($aOptions['version']) && $aOptions['version'] == '6.0.5.20' && $aOptions['playlist_advance'] == 'true' ) { // version 6.0.5 used reverse logic for this option!
447 $aOptions['playlist_advance'] = false;
448 $fv_fp->_get_conf();
449 }
450
451 if( $fv_fp->_get_option( 'autoplay' ) || $fv_fp->_get_option( array( 'pro' ,'autoplay_scroll' )) ) {
452 $aOptions['autoplay_preload'] = 'viewport';
453 } else {
454 $aOptions['autoplay_preload'] = false;
455 }
456
457 if( empty($aOptions["interface"]['playlist_titles']) && !empty($aOptions["interface"]["playlist_captions"]) ) {
458 $aOptions["interface"]['playlist_titles'] = $aOptions["interface"]["playlist_captions"];
459 }
460
461 foreach( array(
462 'ad' => 'overlay',
463 'ad_css' => 'overlay_css',
464 'ad_height' => 'overlay_height',
465 'ad_show_after' => 'overlay_show_after',
466 'ad_width' => 'overlay_width',
467 'adTextColor' => 'overlayTextColor',
468 'adLinksColor' => 'overlayLinksColor'
469 ) as $from => $to ) {
470 if( empty($aOptions[ $to ]) && !empty($aOptions[ $from ]) ) {
471 $aOptions[ $to ] = $aOptions[ $from ];
472 }
473 }
474
475 $aOptions['version'] = $fv_wp_flowplayer_ver;
476 update_option( 'fvwpflowplayer', $aOptions );
477
478 fv_wp_flowplayer_pro_settings_update_for_lightbox();
479 $fv_fp->css_writeout();
480
481 fv_wp_flowplayer_delete_extensions_transients();
482 delete_option('fv_flowplayer_extension_install');
483 }
484
485 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') ) {
486 $fv_fp->css_writeout();
487 }
488 }
489
490 function fv_wp_flowplayer_pro_settings_update_for_lightbox(){
491 global $fv_fp;
492 if(isset($fv_fp->conf['pro']) && isset($fv_fp->conf['pro']['interface']['lightbox']) && $fv_fp->conf['pro']['interface']['lightbox'] == true ){
493 $fv_fp->conf['interface']['lightbox'] = true;
494 $fv_fp->conf['pro']['interface']['lightbox'] = false;
495 $options = get_option('fvwpflowplayer');
496 unset($options['pro']['interface']['lightbox']);
497 $options['interface']['lightbox'] = true;
498 update_option('fvwpflowplayer', $options);
499 }
500 if(isset($fv_fp->conf['pro']) && isset($fv_fp->conf['pro']['lightbox_images']) && $fv_fp->conf['pro']['lightbox_images'] == true ){
501 $fv_fp->conf['lightbox_images'] = true;
502 $fv_fp->conf['pro']['lightbox_images'] = false;
503 $options = get_option('fvwpflowplayer');
504 unset($options['pro']['lightbox_images']);
505 $options['lightbox_images'] = true;
506 update_option('fvwpflowplayer', $options);
507 }
508
509 }
510
511 function fv_wp_flowplayer_delete_extensions_transients( $delete_delay = false ){
512 $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');
513
514 global $wpdb;
515 $aWhere = array();
516 foreach( $aTransientsLike AS $sKey ) {
517 $aWhere[] = $wpdb->prepare( 'option_name LIKE %s', '%' . $wpdb->esc_like( $sKey) . '%' );
518 }
519 $sWhere = implode(" OR ", $aWhere);
520
521 $aOptions = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%_transient_fv%' AND ( {$sWhere} )" );
522
523 foreach( $aOptions AS $sKey ) {
524 if( !$delete_delay ){
525 delete_transient( str_replace('_transient_','',$sKey) );
526 } else {
527 fv_wp_flowplayer_change_transient_expiration( str_replace('_transient_','',$sKey), $delete_delay );
528 }
529 }
530
531 $aUpdates = get_site_transient('update_plugins');
532 set_site_transient('update_plugins', $aUpdates );
533
534 }
535
536
537 add_action('admin_init', 'fv_player_lchecks');
538
539 function fv_player_lchecks() {
540 $aCheck = get_transient( 'fv-player_license' );
541
542 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') ) {
543
544 if ( ! $aCheck || empty( $aCheck->valid ) ) {
545 global $fv_fp, $fv_wp_flowplayer_ver;
546 $fv_fp->strPluginSlug = 'fv-player';
547 $fv_fp->version = $fv_wp_flowplayer_ver;
548 $fv_fp->license_key = 'activation';
549
550 $fv_fp->check_license( true );
551
552 $aCheck = get_transient( 'fv-player_license' );
553 }
554
555 if( isset($aCheck->valid) && $aCheck->valid){
556 fv_wp_flowplayer_install_extension('fv_player_pro');
557
558 } else if ( ! empty( $aCheck->message ) ) {
559 add_action( 'admin_notices', 'fv_player_install_pro_license_notice' );
560 }
561 }
562
563 if( isset($aCheck->valid) && $aCheck->valid){
564 delete_option('fv_wordpress_flowplayer_persistent_notices');
565 }
566 }
567
568 function fv_wp_flowplayer_admin_key_update() {
569 global $fv_fp;
570
571 $data = fv_wp_flowplayer_license_check( array('action' => 'key_update') );
572 if( isset($data->domain) ) { // todo: test
573 if( $data->domain && $data->key && stripos( home_url(), $data->domain ) !== false ) {
574 $fv_fp->conf['key'] = $data->key;
575 update_option( 'fvwpflowplayer', $fv_fp->conf );
576 update_option( 'fvwpflowplayer_core_ver', flowplayer::get_core_version() );
577
578 fv_wp_flowplayer_change_transient_expiration("fv-player_license",5);
579 fv_wp_flowplayer_delete_extensions_transients(5);
580 return true;
581 }
582 } else if( isset($data->expired) && $data->expired && isset($data->message) ){
583 update_option( 'fv_wordpress_flowplayer_persistent_notices', $data->message );
584 update_option( 'fvwpflowplayer_core_ver', flowplayer::get_core_version() );
585 return false;
586 } else {
587 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>' );
588 update_option( 'fvwpflowplayer_core_ver', flowplayer::get_core_version() );
589 return false;
590 }
591 }
592
593 function fv_wp_flowplayer_license_check( $aArgs ) {
594 global $fv_wp_flowplayer_ver;
595
596 $args = array(
597 '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() ),
598 'timeout' => 10,
599 'user-agent' => 'fv-wordpress-flowplayer-'.$fv_wp_flowplayer_ver.' ('.flowplayer::get_core_version().')'
600 );
601 $resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $args );
602
603 if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\S]*?<FVFLOWPLAYER>(.*?)</FVFLOWPLAYER>[\s\S]*?~', '$1', $resp['body'] ) ) ) {
604 return $data;
605
606 } else if( is_wp_error($resp) ) {
607 $args['sslverify'] = false;
608 $resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $args );
609
610 if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\S]*?<FVFLOWPLAYER>(.*?)</FVFLOWPLAYER>[\s\S]*?~', '$1', $resp['body'] ) ) ) {
611 return $data;
612 }
613
614 }
615
616 return false;
617 }
618
619 function fv_wp_flowplayer_change_transient_expiration( $transient_name, $time ){
620 $transient_val = get_transient($transient_name);
621 if( $transient_val ){
622 set_transient($transient_name,$transient_val,$time);
623 return true;
624 }
625 return false;
626 }
627
628 add_action('admin_notices', 'fv_wordpress_flowplayer_expired_license_update_notice');
629
630 function fv_wordpress_flowplayer_expired_license_update_notice() {
631 if( get_current_screen()->base === 'update-core' && get_option('fv_wordpress_flowplayer_expired_license_update_notice') ) {
632 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>';
633 }
634 }
635
636 add_action( 'after_plugin_row_fv-player/fv-player.php', 'fv_wordpress_flowplayer_expired_license_update_plugin_row', 0, 3 );
637
638 function fv_wordpress_flowplayer_expired_license_update_plugin_row($plugin_file, $plugin_data, $status) {
639 if( get_option('fv_wordpress_flowplayer_expired_license_update_notice') ) {
640 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>';
641 }
642 }
643
644
645 add_action('wp_ajax_flowplayer_conversion_script', 'flowplayer_conversion_script');
646
647 function flowplayer_conversion_script() {
648 global $wpdb;
649
650 $posts = $wpdb->get_results("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_type != 'revision'");
651
652 $old_shorttag = '[flowplayer';
653 $new_shorttag = '[fvplayer';
654 $counter = 0;
655
656 echo '<ol>';
657 foreach($posts as $fv_post) {
658 if ( stripos( $fv_post->post_content, $old_shorttag ) !== false ) {
659 $update_post = array();
660 $update_post['ID'] = $fv_post->ID;
661 $update_post['post_content'] = str_replace( $old_shorttag, $new_shorttag, $fv_post->post_content );
662 wp_update_post( $update_post );
663 echo '<li><a href="' . get_permalink($fv_post->ID) . '">' . get_the_title($fv_post->ID) . '</a> updated</li>';
664 $counter++;
665 }
666 }
667 echo '</ol>';
668
669 echo '<strong>Conversion was succesful. Total number of converted posts: ' . intval( $counter ) . '</strong>';
670
671 delete_option('fvwpflowplayer_conversion');
672
673 die();
674 }
675
676
677
678
679 add_action('admin_notices', 'fv_wp_flowplayer_admin_notice');
680
681 function fv_wp_flowplayer_admin_notice() {
682 if( $notices = get_option('fv_wordpress_flowplayer_deferred_notices') ) {
683 echo '<div class="updated inline">
684 <p>'.$notices.'</p>
685 </div>';
686 delete_option('fv_wordpress_flowplayer_deferred_notices');
687 }
688
689 $conversion = false; //(bool)get_option('fvwpflowplayer_conversion');
690 if ($conversion ) {
691 echo '<div class="updated" id="fvwpflowplayer_conversion_notice"><p>';
692 printf(
693 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() ) ) ),
694 get_admin_url() . 'admin.php?page=fvplayer');
695 echo "</p></div>";
696 }
697 }
698
699
700
701
702
703
704
705 /*
706 * Check the extension info from plugin license transient and activate the plugin
707 */
708 function fv_wp_flowplayer_install_extension( $plugin_package = 'fv_player_pro' ) {
709
710 $aInstalled = get_option( 'fv_flowplayer_extension_install', array() );
711 $aInstalled = array_merge( $aInstalled, array( $plugin_package => false ) );
712 update_option('fv_flowplayer_extension_install', $aInstalled );
713
714 $aPluginInfo = get_transient( 'fv-player_license' );
715
716 if ( ! $aPluginInfo || empty( $aPluginInfo->valid ) ) {
717 global $fv_fp, $fv_wp_flowplayer_ver;
718 $fv_fp->strPluginSlug = 'fv-player';
719 $fv_fp->version = $fv_wp_flowplayer_ver;
720 $fv_fp->license_key = 'activation';
721
722 $fv_fp->check_license( true );
723
724 $aPluginInfo = get_transient( 'fv-player_license' );
725 }
726
727 $plugin_basename = $aPluginInfo->{$plugin_package}->slug;
728 $download_url = $aPluginInfo->{$plugin_package}->url;
729
730 $result = FV_Wordpress_Flowplayer_Plugin_Private::install_plugin(
731 "FV Player Pro",
732 $plugin_package,
733 $plugin_basename,
734 $download_url,
735 admin_url('admin.php?page=fvplayer&reload='.wp_rand()),
736 'fv_wordpress_flowplayer_deferred_notices',
737 'fv_player_pro_install'
738 );
739
740 $aInstalled = ( get_option('fv_flowplayer_extension_install' ) ) ? get_option('fv_flowplayer_extension_install' ) : array();
741 $aInstalled = array_merge( $aInstalled, array( $plugin_package => $result ) );
742 update_option('fv_flowplayer_extension_install', $aInstalled );
743 }
744
745
746
747
748 function flowplayer_deactivate() {
749 if ( WP_Filesystem() ) {
750 global $wp_filesystem;
751
752 if( $wp_filesystem->exists( $wp_filesystem->wp_content_dir().'fv-player-tracking/' ) ) {
753 $wp_filesystem->rmdir( $wp_filesystem->wp_content_dir().'fv-player-tracking/', true );
754 }
755
756 if( $wp_filesystem->exists( $wp_filesystem->wp_content_dir().'fv-flowplayer-custom/' ) ) {
757 $wp_filesystem->rmdir( $wp_filesystem->wp_content_dir().'fv-flowplayer-custom/', true );
758 }
759 }
760
761 delete_option( 'fv_flowplayer_extension_install' );
762
763 wp_clear_scheduled_hook( 'fv_flowplayer_checker_event' );
764 wp_clear_scheduled_hook( 'fv_player_stats' );
765 }
766
767
768
769
770 /*
771 * DB based player data saving
772 */
773 global $FV_Player_Db;
774
775 // these have to be here, as using them in constructor doesn't work
776 add_filter('heartbeat_received', array($FV_Player_Db, 'check_db_edit_lock'), 10, 2);
777
778
779 add_action( 'admin_notices', 'fv_player_embedded_on_fix' );
780
781 function fv_player_embedded_on_fix() {
782 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' ) ) {
783
784 global $wpdb;
785 $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" );
786
787 echo "<h2>FV Player Embedded On Post Scan</h2>\n";
788
789 echo '<p>' . sprintf( 'It appears there are %d players which do not belong to any post.', count( $players_with_no_posts ) ) . "</p>\n";
790
791 if ( $players_with_no_posts ) {
792 foreach ( $players_with_no_posts as $player_id ) {
793 echo '<p>';
794 echo 'Player #' . intval( $player_id ) . '... ';
795
796 $wild = '%';
797 $find = 'fvplayer id="'.$player_id.'"';
798 $like = $wild . $wpdb->esc_like( $find ) . $wild;
799
800 $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 ) );
801
802 $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 ) );
803
804 $posts = array_merge( $posts, $post_meta );
805
806 $posts = array_unique( $posts );
807
808 if ( count($posts) > 0 ) {
809
810 echo "Found in posts: " . implode( ', ', $posts ) . "\n";
811
812 foreach ( $posts AS $post_id ) {
813 $meta = new FV_Player_Db_Player_Meta(null, array(
814 'id_player' => $player_id,
815 'meta_key' => 'post_id',
816 'meta_value' => $post_id
817 ) );
818
819 $meta->save();
820 }
821
822 } else {
823 echo "Not found in any post.\n";
824
825 }
826
827 echo "</p>\n";
828 }
829 }
830
831 die( 'Done!' );
832
833 }
834 }
835
836
837 add_action( 'admin_notices', 'fv_player_rollback' );
838
839 function fv_player_rollback() {
840 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' ) ) {
841
842 ob_start(); // first check if we can perform the update automatically!
843 $creds = request_filesystem_credentials( admin_url(), '', false, false, array() );
844 if( !WP_Filesystem($creds) ) { // if not, then don't try to do it at all
845 ob_get_clean();
846 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>";
847 return;
848 }
849
850 echo ob_get_clean();
851
852 global $fv_fp, $fv_wp_flowplayer_ver;
853 $fv_fp->pointer_boxes = array(); // no pointer boxes here!
854
855 $plugin_slug = false;
856 $active_plugins = get_option( 'active_plugins' );
857 foreach( $active_plugins AS $plugin ) {
858 if( stripos($plugin,'fv-player') === 0 && stripos($plugin,'/fv-player.php') !== false ) {
859 $plugin_slug = $plugin;
860 }
861 }
862
863 $plugin_transient = get_site_transient( 'update_plugins' );
864 $plugin_folder = plugin_basename( dirname( $plugin_slug ) );
865 $plugin_file = basename( $plugin_slug );
866 $version = isset($_GET['version']) ? sanitize_text_field( $_GET['version'] ) : '6.6.6';
867 $url = 'https://downloads.wordpress.org/plugin/fv-player.'.$version.'.zip';
868 $temp_array = array(
869 'slug' => $plugin_folder,
870 'new_version' => $version,
871 'url' => 'https://foliovision.com',
872 'package' => $url,
873 );
874
875 $temp_object = (object) $temp_array;
876 $plugin_transient->response[ $plugin_folder . '/' . $plugin_file ] = $temp_object;
877 set_site_transient( 'update_plugins', $plugin_transient );
878
879 add_filter( 'upgrader_pre_download', 'fv_player_rollback_message' );
880
881 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
882 $title = 'FV Player Rollback';
883 $nonce = 'upgrade-plugin_' . $plugin_slug;
884 $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin_slug );
885 $upgrader_skin = new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) );
886 $upgrader = new Plugin_Upgrader( $upgrader_skin );
887 $upgrader->upgrade( $plugin_slug );
888
889 include( ABSPATH . 'wp-admin/admin-footer.php' );
890
891 delete_option('fv-player-pro-release');
892
893
894 $active_plugins = get_option( 'active_plugins' );
895 foreach( $active_plugins AS $plugin ) {
896 if( stripos( $plugin, 'fv-player-pro' ) === 0 ) {
897 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!
898 }
899 }
900
901 wp_die( '', 'FV Player Rollback', array( 'response' => 200 ) );
902
903 }
904 }
905
906 function fv_player_rollback_message( $val ) {
907 echo "<div class='updated'>";
908 echo "<p>Please wait until the plugin download and reactivation is completed.</p>";
909 if( flowplayer::is_licensed() ) {
910 echo "<p>We also rollback the FV Player Pro plugin in the process.</p>";
911 if( class_exists('FV_Player_Pro') ) echo "<style>#wpbody-content iframe[title=\"Update progress\"] { display: none; }</style>";
912 }
913 echo "</div>";
914 return $val;
915 }
916
917 add_action( 'admin_notices', 'fv_player_pro_version_check' );
918
919 function fv_player_pro_version_check() {
920 $version = '7.5.0.727';
921
922 global $FV_Player_Pro;
923
924 if( !empty($FV_Player_Pro) && !fv_player_extension_version_is_min($version,'pro') ) :
925 ?>
926 <div class="error">
927 <p><?php printf( esc_html__( 'FV Player: Please upgrade to FV Player Pro version %s or above!', 'fv-player' ), $version ); ?></p>
928 </div>
929 <?php
930 endif;
931 }
932
933 add_action( 'admin_notices', 'fv_player_pay_per_view_version_check' );
934
935 function fv_player_pay_per_view_version_check() {
936 $version = '7.5.3.727';
937
938 global $FV_Player_PayPerView;
939
940 if( !empty($FV_Player_PayPerView) && !fv_player_extension_version_is_min($version,'ppv') ) :
941 ?>
942 <div class="error">
943 <p><?php printf( esc_html__( 'FV Player: Please upgrade to FV Player Pay Per View version %s or above!', 'fv-player' ), $version ); ?></p>
944 </div>
945 <?php
946 endif;
947 }
948
949 add_action( 'admin_notices', 'fv_player_pay_per_view_woocommerce_version_check' );
950
951 function fv_player_pay_per_view_woocommerce_version_check() {
952 $version = '7.5.3.727';
953
954 global $FV_Player_PayPerView_WooCommerce;
955
956 if( !empty($FV_Player_PayPerView_WooCommerce) && !fv_player_extension_version_is_min($version,'ppv-woocommerce') ) :
957 ?>
958 <div class="error">
959 <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>
960 </div>
961 <?php
962 endif;
963 }
964
965 // lazy-load of video encoder libraries
966 add_action( 'fv_player_load_video_encoder_libs', 'fv_player_load_video_encoder_libs' );
967 function fv_player_load_video_encoder_libs() {
968 include_once( dirname( __FILE__ ).'/../models/video-encoder/video-encoder.php');
969 require_once( dirname(__FILE__).'/../includes/class.fv-player-wizard-base.php' );
970 require_once( dirname(__FILE__).'/../includes/class.fv-player-wizard-step-base.php' );
971 }
972
973 /**
974 * Attachment edit - show attached posts
975 */
976 add_action( 'attachment_submitbox_misc_actions', 'fv_player_submitbox_misc_actions' );
977
978 function fv_player_submitbox_misc_actions( $attachment ) {
979 global $pagenow, $typenow;
980
981 // We only want to run the code on a specific page
982 if( $pagenow != 'post.php' || $typenow != 'attachment' ) {
983 return;
984 }
985
986 global $fv_fp;
987
988 $video_id = get_post_meta( $attachment->ID, 'fv_player_video_id', true );
989
990 if( !empty($video_id) ) {
991 $players = $fv_fp->get_players_by_video_ids( $video_id );
992
993 // Iterate players and create html with name and link to player
994 foreach( $players as $player ) {
995 ?>
996 <div class="misc-pub-section misc-pub-attachment">
997 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>
998 </div>
999 <?php
1000 }
1001 }
1002 }
1003
1004 /**
1005 * Append or update player row in wp-admin -> FV Player
1006 */
1007 add_action('wp_ajax_fv_player_table_new_row', 'fv_player_table_new_row');
1008
1009 function fv_player_table_new_row() {
1010 if( isset($_POST['playerID']) && isset($_POST['nonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), "fv-player-table_new_row_nonce" ) ) {
1011 $table = new FV_Player_List_Table( array(
1012 'player_id' => intval($_POST['playerID']),
1013 'per_page' => 25,
1014 'screen' => 'toplevel_page_fv_player'
1015 )
1016 );
1017
1018 $table->prepare_items();
1019 $table->views();
1020 $table->advanced_filters();
1021 $table->display();
1022 exit;
1023 }
1024 }
1025
1026 /**
1027 * Update the player on the wp-admin -> Posts, Pages or CPT screen
1028 *
1029 * Gets the first video thumbnail only
1030 */
1031 add_action('wp_ajax_fv_player_edit_posts_cell', 'fv_player_edit_posts_cell');
1032
1033 function fv_player_edit_posts_cell() {
1034 if( isset($_POST['nonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), "fv-player-edit_posts_cell_nonce" ) ) {
1035
1036 $player_id = false;
1037
1038 // New player, load from post meta field to ensure it saved
1039 if ( ! empty( $_POST['post_id'] ) && ! empty( $_POST['meta_key'] ) ) {
1040 $shortcode = get_post_meta( absint( $_POST['post_id'] ), sanitize_key( $_POST['meta_key'] ), true );
1041 $shortcode_atts = shortcode_parse_atts( trim( $shortcode, ']' ) );
1042
1043 if( ! empty($shortcode_atts['id']) ) {
1044 $player_id = $shortcode_atts['id'];
1045 }
1046
1047 // Existing player, load by id
1048 } else if ( ! empty( $_POST['playerID'] ) ) {
1049 $player_id = absint( $_POST['playerID'] );
1050 }
1051
1052 if ( $player_id ) {
1053 global $FV_Player_Db;
1054 $aPostListPlayers = $FV_Player_Db->getListPageData( array(
1055 'player_id' => $player_id
1056 ) );
1057
1058 if( !empty($aPostListPlayers[0]->thumbs[0]) ) {
1059 echo '<a href="#" class="fv-player-edit" data-player_id="' . intval($player_id) . '">' . $aPostListPlayers[0]->thumbs[0] . '</a>';
1060
1061 } else {
1062 echo "Error: Player not found!";
1063 }
1064 }
1065
1066 exit;
1067 }
1068 }
1069
1070 /**
1071 * Get taxonomies registered for the post type. The core WordPress function
1072 * to do this does not return taxonomy if it's enabled for multiple
1073 * post types. So we do it properly here.
1074 *
1075 * @param string $post_type Post type to check
1076 * @return array Taxonomy slugs
1077 */
1078 function fv_player_get_post_type_taxonomies( $post_type ) {
1079 $taxonomies = get_taxonomies( array(
1080 'public' => true,
1081 'show_ui' => true,
1082 ), 'objects' );
1083
1084 $post_type_taxonomies = array();
1085 foreach( $taxonomies AS $taxonomy) {
1086 if( in_array( $post_type, $taxonomy->object_type ) ) {
1087 $post_type_taxonomies[] = $taxonomy->name;
1088 }
1089 }
1090
1091 return $post_type_taxonomies;
1092 }
1093
1094 function fv_player_setup_uninstall_script( $put_in_uninstall_php, $remove_uninstall_php ) {
1095
1096 if ( 'direct' !== get_filesystem_method( array(), dirname( dirname( __FILE__ ) ) ) ) {
1097 return false;
1098 }
1099
1100 if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
1101 require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
1102 require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
1103 }
1104
1105 $plugin_folder = basename( dirname( dirname( __FILE__ ) ) );
1106
1107 $wp_filesystem = new WP_Filesystem_Direct( '' );
1108 $original_file = $wp_filesystem->wp_plugins_dir() . $plugin_folder . '/uninstall-script.php';
1109 $new_file = $wp_filesystem->wp_plugins_dir() . $plugin_folder . '/uninstall.php';
1110
1111 if ( $put_in_uninstall_php && ! $wp_filesystem->exists( $new_file ) ) {
1112 return $wp_filesystem->copy( $original_file, $new_file );
1113
1114 } else if ( $remove_uninstall_php && $wp_filesystem->exists( $new_file ) ) {
1115 return $wp_filesystem->delete( $new_file );
1116 }
1117
1118 return false;
1119 }
1120
1121 function fv_player_install_pro_license_notice() {
1122 $aCheck = get_transient( 'fv-player_license' );
1123 if ( ! empty( $aCheck->message ) ) {
1124 echo "<div class='error'>" . wp_kses( $aCheck->message, 'post' ) . "</div>";
1125 }
1126 }
1127
1128 /**
1129 * Paid FV Player extensions need to know what's the FV Player version.
1130 */
1131 add_filter( 'http_request_args', 'fv_player_license_checks_base_plugin_version', 10, 2 );
1132
1133 function fv_player_license_checks_base_plugin_version( $parsed_args, $url ) {
1134
1135 global $fv_wp_flowplayer_ver;
1136 if ( ( stripos( $url, '//foliovision.com/' ) !== false || stripos( $url, '.foliovision.com/' ) !== false ) && stripos( $url, 'fv_remote' ) !== false ) {
1137 if ( is_array( $parsed_args['body'] ) ) {
1138 $parsed_args['body']['fv_player_core_version'] = $fv_wp_flowplayer_ver;
1139
1140 // No POST? It seems this adds to the URL query string which we need to actual plugin update downloads.
1141 } else if ( empty( $parsed_args['body'] ) ) {
1142 $parsed_args['body'] = array( 'fv_player_core_version' => $fv_wp_flowplayer_ver );
1143 }
1144 }
1145
1146 return $parsed_args;
1147 }
1148