PluginProbe
FV Player 8 / 8.1
FV Player 8 v8.1
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 / includes / fp-api-private.php

fp-api-private.php in FV Player 8 8.1, at includes/fp-api-private.php

904 lines 34.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FV_Wordpress_Flowplayer_Plugin_Private
4 {
5
6 var $_wp_using_ext_object_cache_prev;
7
8 var $class_name;
9
10 var $license_key;
11
12 var $pointer_boxes;
13
14 var $readme_URL;
15
16 var $strPluginName;
17
18 var $strPluginPath;
19
20 var $strPluginSlug;
21
22 var $strPrivateAPI;
23
24 function __construct(){
25 $this->class_name = sanitize_title( get_class($this) );
26
27 // get plugin slug based on directory
28 if( empty( $this->strPluginSlug ) ) {
29 $this->strPluginSlug = basename( dirname( __FILE__ ) );
30 }
31
32 if( empty( $this->strPluginName ) ) {
33 $this->strPluginName = $this->strPluginSlug;
34 }
35
36 if( empty( $this->strPluginPath ) ) {
37 $this->strPluginPath = basename(dirname(__FILE__)).'/plugin.php';
38 if( !file_exists( WP_PLUGIN_DIR.'/'.$this->strPluginPath ) ) {
39 $this->strPluginPath = basename(dirname(__FILE__)).'/'.$this->strPluginSlug.'.php';
40 }
41 }
42
43 add_action( 'admin_enqueue_scripts', array( $this, 'pointers_enqueue' ) );
44
45 // store cookie for each dimissed notice first
46 add_action( 'wp_ajax_fv_foliopress_ajax_pointers', array( $this, 'pointers_ajax_cookie' ), 0 );
47 // TODO: What about the actual processing of the Ajax? Does it have to be in the plugin for real?
48 add_action( 'wp_ajax_fv_foliopress_ajax_pointers', array( $this, 'pointers_ajax' ), 999 );
49
50 add_filter( 'plugins_api_result', array( $this, 'changelog_filter' ), 5, 3 );
51
52 add_filter( 'pre_set_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
53 add_filter( 'pre_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
54 add_action( 'delete_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
55 add_action( 'set_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
56 add_filter( 'transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_enable' ) );
57 add_action( 'deleted_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
58
59 //add_action('admin_head', array($this, 'welcome_screen_remove_menus'));
60 }
61
62 function object_cache_disable($value=null){
63 global $_wp_using_ext_object_cache;
64 $this->_wp_using_ext_object_cache_prev = $_wp_using_ext_object_cache;
65 $_wp_using_ext_object_cache = false;
66 return $value;
67 }
68
69 function object_cache_enable($value=null){
70 global $_wp_using_ext_object_cache;
71 $_wp_using_ext_object_cache = $this->_wp_using_ext_object_cache_prev;
72 return $value;
73 }
74
75 function http_request_args( $params ) {
76 $aArgs = func_get_args();
77 $url = $aArgs[1];
78
79 if( stripos($url,'foliovision.com') === false ) {
80 return $params;
81 }
82
83 add_filter( 'https_ssl_verify', '__return_false' );
84 return $params;
85 }
86
87 function is_min_wp( $version ) {
88 return version_compare( $GLOBALS['wp_version'], $version. 'alpha', '>=' );
89 }
90
91
92 public static function get_plugin_path( $slug ){
93 $aPluginSlugs = get_transient('plugin_slugs');
94 $aPluginSlugs = is_array($aPluginSlugs) ? $aPluginSlugs : array( $slug.'/'.$slug.'.php');
95 $aActivePlugins = get_option('active_plugins');
96 $aInactivePlugins = array_diff($aPluginSlugs,$aActivePlugins);
97
98 if( !$aPluginSlugs )
99 return false;
100
101 foreach( $aActivePlugins as $item ){
102 if( stripos($item,$slug.'.php') !== false && !is_wp_error(validate_plugin($item)) )
103 return $item;
104 }
105
106 $sPluginFolder = plugin_dir_path( dirname( dirname(__FILE__) ) );
107 foreach( $aInactivePlugins as $item ){
108 if( stripos($item,$slug.'.php') !== false && file_exists($sPluginFolder.$item) )
109 return $item;
110 }
111
112 return false;
113 }
114
115
116 private function check_license_remote( $args = array() ) {
117
118 if( !isset($this->strPluginSlug) || empty($this->strPluginSlug)
119 || !isset($this->version) || empty($this->version)
120 || !isset($this->license_key) || $this->license_key === FALSE ) {
121 return false;
122 }
123
124 $defaults = array(
125 'action' => 'check',
126 'core_ver' => false,
127 'key' => !empty( $this->license_key) ? $this->license_key : false,
128 'plugin' => $this->strPluginSlug,
129 'type' => home_url(),
130 'version' => $this->version,
131 );
132 $body_args = wp_parse_args( $args, $defaults );
133
134 $post = array(
135 'body' => $body_args,
136 'timeout' => 20,
137 'user-agent' => $this->strPluginSlug.'-'.$this->version
138 );
139 $resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $post );
140 if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\s]*?<FVFLOWPLAYER>(.*?)</FVFLOWPLAYER>[\s\s]*?~', '$1', $resp['body'] ) ) ) {
141 return $data;
142
143 } else if( is_wp_error($resp) ) {
144 $post['sslverify'] = false;
145 $resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $post );
146
147 if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\S]*?<FVFLOWPLAYER>(.*?)</FVFLOWPLAYER>[\s\S]*?~', '$1', $resp['body'] ) ) ) {
148 return $data;
149 }
150
151 }
152
153 return false;
154 }
155
156 // set force = true to delete transient and recheck license
157 function setLicenseTransient( $force = false ){
158 $strTransient = $this->strPluginSlug . '_license';
159
160 if( $force )
161 delete_transient( $strTransient );
162
163 //is transiet set?
164 if ( false !== ( $aCheck = get_transient( $strTransient ) ) )
165 return;
166
167 $aCheck = $this->check_license_remote( );
168 if( $aCheck ) {
169 set_transient( $strTransient, $aCheck, 60*60*24 );
170 } else {
171 set_transient( $strTransient, json_decode( wp_json_encode( array('error' => 'Error checking license') ), FALSE ), 60*10 );
172 }
173 }
174
175
176 function checkLicenseTransient(){
177 $aCheck = get_transient( $this->strPluginSlug . '_license' );
178 return isset($aCheck->valid) && $aCheck->valid;
179 }
180
181 function getUpgradeUrl(){
182 $aCheck = get_transient( $this->strPluginSlug . '_license' );
183 if( isset($aCheck->upgrade) && !empty($aCheck->upgrade) ) {
184 return $aCheck->upgrade;
185 } else {
186 return false;
187 }
188 }
189
190
191 /// ================================================================================================
192 /// Custom plugin repository
193 /// ================================================================================================
194
195 /*
196 Uses:
197 $this->strPluginSlug - this has to be in plugin object
198 $this->strPrivateAPI - also
199
200 */
201
202 private function PrepareRequest( $action, $args ){
203 global $wp_version;
204
205 return array(
206 'body' => array(
207 'action' => $action,
208 'request' => serialize($args),
209 'api-key' => md5(get_bloginfo('url'))
210 ),
211 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
212 );
213 }
214
215 public function CheckPluginUpdate( $checked_data ){
216 $plugin_path = $this->strPluginPath;
217 $request_args = array( 'slug' => $this->strPluginSlug );
218 if( !empty( $checked_data->checked ) && empty($this->version) ){
219 $request_args['version'] = isset($checked_data->checked[$plugin_path]) ? $checked_data->checked[$plugin_path] : '0.1';
220 }
221 else{
222 if( !function_exists('get_plugins') ) return $checked_data;
223
224 $cache_plugins = get_plugins();
225
226 if( empty($cache_plugins[$plugin_path]['Version']) ){
227 return $checked_data;
228 }
229 $request_args['version'] = $this->version ? $this->version : $cache_plugins[$plugin_path]['Version'];
230 }
231
232 $request = $this->PrepareRequest( 'basic_check', $request_args );
233
234 $sTransient = $this->strPluginSlug.'_fp-private-updates-api-'.sanitize_title($request_args['version']);
235 $response = get_transient( $sTransient );
236
237 if( !$response ){
238 if( stripos($this->strPrivateAPI,'plugins.trac.wordpress.org') === false ) {
239 $raw_response = wp_remote_post( $this->strPrivateAPI, $request );
240 if( is_wp_error($raw_response) ) {
241 $request['sslverify'] = false;
242 $raw_response = wp_remote_post( $this->strPrivateAPI, $request );
243 }
244 } else {
245 $raw_response = wp_remote_get( $this->strPrivateAPI );
246 }
247
248 if( !is_wp_error( $raw_response ) && ( $raw_response['response']['code'] == 200 ) ) {
249 $response = @unserialize( preg_replace( '~^/\*[\s\S]*?\*/\s+~', '', $raw_response['body'] ) );
250 if( !$response ) $response = $raw_response['body'];
251 }
252
253 set_transient( $sTransient, $response, 3600 );
254 }
255
256 if( isset($response->version) && version_compare( $response->version, $request_args['version'] ) == 1 ){
257 if( is_object( $response ) && !empty( $response ) ) // Feed the update data into WP updater
258 $checked_data->response[ $plugin_path ] = $response;
259 }
260
261 return $checked_data;
262 }
263
264 public function CheckPluginUpdateOld( $aData = null ){
265 $aData = get_transient( "update_plugins" );
266 $aData = $this->CheckPluginUpdate( $aData );
267 set_transient( "update_plugins", $aData );
268
269 if( function_exists( "set_site_transient" ) ) set_site_transient( "update_plugins", $aData );
270 }
271
272 public function PluginAPICall( $def, $action, $args ){
273 if( !isset($args->slug) || $args->slug != $this->strPluginSlug ) return $def;
274
275 // Get the current version
276 $plugin_info = get_site_transient( 'update_plugins' );
277 $current_version = ( isset($plugin_info->response[$this->strPluginPath]) ) ? $plugin_info->response[$this->strPluginPath] : false;
278 $args->version = $current_version;
279
280 $request_string = $this->PrepareRequest( $action, $args );
281
282 $request = wp_remote_post( $this->strPrivateAPI, $request_string );
283
284 if( is_wp_error( $request ) ) {
285 $res = new WP_Error( 'plugins_api_failed', __( 'An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>' ), $request->get_error_message() );
286 }else{
287 $res = unserialize( preg_replace( '~^/\*[\s\S]*?\*/\s+~', '', $request['body'] ) );
288 if( $res === false ) $res = new WP_Error( 'plugins_api_failed', __( 'An unknown error occurred' ), $request['body'] );
289 }
290
291 return $res;
292 }
293
294
295 public function plugin_update_message() {
296 if( $this->readme_URL ) {
297 $data = $this->get_readme_url_remote( $this->readme_URL );
298 if( $data ) {
299 $matches = null; /// not sure if this works for more than one last changelog
300 //if (preg_match('~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*[0-9.]+\s*=|$)~Uis', $data, $matches)) {
301 if (preg_match('~==\s*Upgrade Notice\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*[0-9.]+\s*=|$)~Uis', $data, $matches)) {
302 $changelog = (array) preg_split('~[\r\n]+~', trim($matches[1]));
303
304 $ul = false;
305 foreach ($changelog as $index => $line) {
306 if (preg_match('~^\s*\*\s*~', $line) && 1<0 ) {
307 if (!$ul) {
308 //echo '<ul style="list-style: disc; margin-left: 20px;">';
309 $ul = true;
310 }
311 $line = preg_replace('~^\s*\*\s*~', '', htmlspecialchars($line));
312 echo '<li style="width: 50%; margin: 0; float: left; ' . ($index % 2 == 0 ? 'clear: left;' : '') . '">' . $line . '</li>';
313 } else {
314 if ($ul) {
315 //echo '</ul><div style="clear: left;"></div>';
316 $ul = false;
317 }
318 $line = preg_replace('~^\s*\*\s*~', '', htmlspecialchars($line));
319 echo '<br /><br />' . htmlspecialchars($line)."\n";
320 }
321 }
322
323 if ($ul) {
324 //echo '</ul><div style="clear: left;"></div>';
325 }
326 }
327 }
328 }
329 }
330
331
332 function pointers_ajax() {
333 if( $this->pointer_boxes ) {
334 foreach( $this->pointer_boxes AS $sKey => $aPopup ) {
335 if( sanitize_key( $_POST['key'] ) == $sKey ) {
336 check_ajax_referer($sKey);
337 }
338 }
339 }
340 }
341
342
343 function pointers_ajax_cookie() {
344 $cookie = $this->pointers_get_cookie();
345
346 $cookie[ sanitize_key( $_POST['key'] ) ] = !empty($_POST['value']) ? sanitize_text_field( $_POST['value'] ) : true;
347
348 $secure = ( 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ) );
349 setcookie( $this->class_name.'_store_answer', wp_json_encode($cookie), time() + YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN, $secure );
350 }
351
352
353 function pointers_enqueue() {
354 global $wp_version;
355 if( ! current_user_can( 'manage_options' ) || ( isset($this->pointer_boxes) && count( $this->pointer_boxes ) == 0 ) || version_compare( $wp_version, '3.4', '<' ) ) {
356 return;
357 }
358
359 wp_enqueue_style( 'wp-pointer' );
360 wp_enqueue_script( 'jquery-ui' );
361 wp_enqueue_script( 'wp-pointer' );
362 wp_enqueue_script( 'utils' );
363
364 add_action( 'admin_print_footer_scripts', array( $this, 'pointers_init_scripts' ) );
365 }
366
367
368 /**
369 * Get a cookie storing which pointers were already dimissed
370 * The cookie uses JSON so we decode it too
371 *
372 * @return array
373 */
374 function pointers_get_cookie() {
375 $cookie_name = $this->class_name.'_store_answer';
376
377 $cookie = false;
378 if( !empty($_COOKIE[$cookie_name]) ) {
379 $cookie = sanitize_text_field( $_COOKIE[$cookie_name] );
380 }
381
382 $cookie = (array) json_decode( stripslashes($cookie) );
383
384 $json_error = json_last_error();
385 if( $json_error !== JSON_ERROR_NONE ) {
386 $cookie = array();
387 }
388
389 return $cookie;
390 }
391
392
393 private function get_readme_url_remote( $url = false ) { // todo: caching
394 $output = false;
395
396 if( $url ) {
397 $response = wp_remote_get( $url );
398 if( !is_wp_error($response) ) {
399 $output = $response['body'];
400 }
401 } else {
402 if( !isset($this->strPluginSlug) || empty($this->strPluginSlug) || !isset($this->version) || empty($this->version) )
403 return false;
404
405 $args = array(
406 'body' => array( 'plugin' => $this->strPluginSlug, 'version' => $this->version, 'type' => home_url() ),
407 'timeout' => 20,
408 'user-agent' => $this->strPluginSlug.'-'.$this->version
409 );
410 $resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true&readme=1', $args );
411
412 if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] ) {
413 $output = $resp['body'];
414
415 } else if( is_wp_error($resp) ) {
416 $args['sslverify'] = false;
417 $resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $args );
418
419 if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] ) {
420 $output = $resp['body'];
421 }
422
423 }
424 }
425
426 return $output;
427 }
428
429
430 function changelog_filter( $res, $action, $args ){
431
432 if( !isset( $args->slug ) || $args->slug != $this->strPluginSlug )
433 return $res;
434
435 if(isset($args->fv_readme_file)){
436 global $wp_filesystem;
437 $data = $wp_filesystem->get_contents( $args->fv_readme_file );
438 } else if( $this->readme_URL ) {
439 $data = $this->get_readme_url_remote( $this->readme_URL );
440 } else {
441 $data = $this->get_readme_url_remote();
442 }
443 if( !$data )
444 return $res;
445
446 /**
447 * Some users run into issue that the function was not defined.
448 * Did some other plugin run plugins_api_result in front end? Seems like security-malware-firewall.
449 * Let's just give up in such case.
450 */
451 if ( ! function_exists( 'get_plugin_data' ) ) {
452 return $res;
453 }
454
455 $plugin_data = get_plugin_data($this->strPluginPath);
456
457 $pluginReq = preg_match( '~Requires at least:\s*([0-9.]*)~', $data, $reqMatch ) ? $reqMatch[1] : false;
458 $pluginUpto = preg_match( '~Tested up to:\s*([0-9.]*)~', $data, $uptoMatch ) ? $uptoMatch[1] : false;
459
460 $changelogOut = '';
461 if( preg_match('~==\s*Changelog\s*==(.*)~si', $data, $match) ){
462 $changelogPart = preg_replace('~==.*~','',$match[1]);
463 $version = preg_match('~=\s*([0-9.]+).*=~', $changelogPart, $verMatch ) ? $verMatch[1] : false;
464
465 $changelog = (array) preg_split('~[\r\n]+~', trim($changelogPart));
466 $ul = false;
467 $changelogFinish = false;
468 $changelogCounter = 0;
469 foreach ($changelog as $index => $line) {
470 if (preg_match('~^\s*\*\s*~', $line)) {
471 if (!$ul) {
472 $changelogOut .= '<ul style="list-style: disc; margin-left: 20px;">';
473 $ul = true;
474 }
475 $line = preg_replace('~^\s*\*\s*~', '', htmlspecialchars($line));
476 $changelogOut .= '<li style="width: 50%; margin: 0; float: left; ' . ($index % 2 == 0 ? 'clear: left;' : '') . '">' . $line . '</li>';
477 } else {
478 if ($ul) {
479 $changelogOut .= '</ul><div style="clear: left;"></div>';
480 $ul = false;
481 }
482
483 $strong = $strongEnd = '';
484 if( preg_match('~^=(.*)=$~', $line ) ){
485 $strong = '<strong>';
486 $strongEnd = '</strong>';
487 $line = preg_replace('~^=(.*)=$~', '$1', $line );
488 if(isset($args->fv_prev_ver)){
489 if(($args->fv_prev_ver == false || $args->fv_prev_ver === $this->version ) ){
490 if(++$changelogCounter > 3){
491 $changelogFinish = true;
492 }
493 }elseif(strpos($line,str_replace('.beta','',$args->fv_prev_ver . ' ')) !== false){
494 $changelogFinish = true;
495 }
496 }
497 }
498 if ($changelogFinish) {
499 break;
500 }
501 $changelogOut .= '<p style="margin: 5px 0;">' .$strong. htmlspecialchars($line) .$strongEnd. '</p>';
502
503 }
504
505 }
506 if ($ul) {
507 $changelogOut .= '</ul><div style="clear: left;"></div>';
508 }
509 $changelogOut .= '</div>';
510 }
511
512 $res = (object) array(
513 'name' => $plugin_data['Name'],
514 'slug' => false,
515 'version' => $version,
516 'author' => $plugin_data['Author'],
517 'requires' => $pluginReq,
518 'tested' => $pluginUpto,
519 'homepage' => $plugin_data['PluginURI'],
520 'sections' =>
521 array (
522 'support' => 'Use support forum at <a href="https://foliovision.com/support/">foliovison.com/support</a>',
523 'changelog' => $changelogOut,
524 ),
525 'donate_link' => NULL
526 );
527
528 return $res;
529
530 }
531
532
533 //notification boxes
534 function pointers_init_scripts() {
535 if( !isset($this->pointer_boxes) || !$this->pointer_boxes ) {
536 return;
537 }
538
539 ?>
540 <script type="text/javascript">
541 //<![CDATA[
542 function <?php echo esc_attr( $this->class_name ); ?>_store_answer(key, input, nonce) {
543 jQuery.post(ajaxurl, { action : 'fv_foliopress_ajax_pointers', key : key, value : input, _ajax_nonce : nonce }, function () {
544 jQuery('#wp-pointer-0').remove(); // there must only be a single pointer at once. Or perhaps it removes them all, but the ones which were not dismissed by Ajax by storing the option will turn up again?
545 });
546 }
547
548 /*! js-cookie v3.0.1 | MIT */
549 !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var n=e.Cookies,o=e.Cookies=t();o.noConflict=function(){return e.Cookies=n,o}}())}(this,(function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}return function t(n,o){function r(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n.write(r,t)+c}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},r=0;r<t.length;r++){var i=t[r].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(o[u]=n.read(c,u),e===u)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){r(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}));
550
551 //]]>
552 </script>
553 <?php
554 $cookie = $this->pointers_get_cookie();
555
556 foreach( $this->pointer_boxes AS $key => $args ) {
557 // Some users are experiencing issues when dismissing the notices
558 // So we use cookies as a backup to not show the same notice twice
559 if( !empty($cookie[$key]) ) {
560 continue;
561 }
562
563 $nonce = wp_create_nonce( $key );
564
565 $args = wp_parse_args( $args, array(
566 'button1' => false, // req
567 'button2' => false,
568 'function1' => $this->class_name.'_store_answer("'.$key.'", "' . ( ! empty( $args['value1'] ) ? esc_js( $args['value1'] ) : 'true' ) . '","' . $nonce . '")',
569 'function2' => $this->class_name.'_store_answer("'.$key.'", "false","' . $nonce . '")',
570 'heading' => false, // req
571 'id' => false, // req
572 'content' => false, // req
573 'position' => array( 'edge' => 'top', 'align' => 'center' ),
574 ) );
575
576 extract($args);
577
578 $html = '<h3>'.$heading.'</h3>';
579 if( stripos( $content, '</p>' ) !== false ) {
580 $html .= $content;
581 } else {
582 $html .= '<p>'.$content.'</p>';
583 }
584
585 ?>
586 <script type="text/javascript">
587 //<![CDATA[
588 (function ($) {
589 store_cookie_js = function(value , key) {
590 var cookie_name = '<?php echo esc_attr( $this->class_name ) . '_store_answer'; ?>';
591 var pointer_cookies = JSON.parse( Cookies.get(cookie_name) );
592 pointer_cookies[key] = value;
593 Cookies.set(cookie_name, JSON.stringify(pointer_cookies) , { secure: location.protocol == 'https:', expires: 365 } )
594 jQuery('#wp-pointer-0').remove();
595 }
596
597 var pointer_options = <?php echo wp_json_encode( array( 'pointerClass' => $key, 'content' => $html, 'position' => $position ) ); ?>,
598 key = '<?php echo esc_attr( $key ); ?>',
599
600 setup = function () {
601 $('<?php echo esc_attr( $id ); ?>').pointer(pointer_options).pointer('open');
602 var buttons = $('.<?php echo esc_attr( $key ); ?> .wp-pointer-buttons').html('');
603 buttons.append( $('<a style="margin-left:5px" class="button-primary">' + '<?php echo addslashes($button1); ?>' + '</a>').on('click.pointer', function () { <?php echo wp_kses_post( $function1 ); ?>; store_cookie_js('true' , key); }));
604 <?php if ( $button2 ) { ?>
605 buttons.append( $('<a class="button-secondary">' + '<?php echo addslashes($button2); ?>' + '</a>').on('click.pointer', function () { <?php echo wp_kses_post( $function2 ); ?>; store_cookie_js('false', key); }));
606 <?php } ?>
607 };
608
609 if(pointer_options.position && pointer_options.position.defer_loading)
610 $(window).bind('load.wp-pointers', setup);
611 else
612 $(document).ready(setup);
613 })(jQuery);
614 //]]>
615 </script>
616 <?php
617 }
618 }
619
620 function change_transient_expiration( $transient_name, $time ){
621 $transient_val = get_transient($transient_name);
622 if( $transient_val ){
623 set_transient($transient_name,$transient_val,$time);
624 return true;
625 }
626 return false;
627 }
628
629
630 function domain_key_update() {
631
632 $data = $this->check_license_remote( array('action' => 'key_update') );
633
634 if( isset($data->domain) ) { // todo: test
635 if( $data->domain && $data->key && stripos( home_url(), $data->domain ) !== false ) {
636 $this->license_key = $data->key;
637 do_action( $this->strPluginSlug.'_admin_key_update', $this->license_key );
638
639 $this->change_transient_expiration( $this->strPluginSlug."_license", 1 );
640 // change the expiration to license renew by: $this->setLicenseTransient( true );
641
642 //fv_wp_flowplayer_delete_extensions_transients(5);
643 return $data->key;
644 }
645 } else if( isset($data->expired) && $data->expired && isset($data->message) ){
646
647 update_option( 'fv_'.$this->strPluginSlug.'_deferred_notices', $data->message );
648 return false;
649 } else {
650 $message = 'FV Player License upgrade failed - please check if you are running the plugin on your licensed domain.';
651 update_option( 'fv_'.$this->strPluginSlug.'_deferred_notices', $message );
652 return false;
653 }
654 }
655
656 function pro_install_talk( $content, $url ) {
657 $content = preg_replace( '~<h3.*?</h3>~', '<h3>'.$this->strPluginName.' auto-installation</h3><p>As a license holder, we would like to automatically install our Pro extension for you.</p>', $content );
658 $content = preg_replace( '~(<input[^>]*?type="submit"[^>]*?>)~', '$1 <a href="'.$url.'">Skip the Pro addon install</a>', $content );
659 return $content;
660 }
661
662 //search for plugin path with {slug}.php
663 function get_extension_path( $slug ){
664 $aPluginSlugs = get_transient('plugin_slugs');
665 $aPluginSlugs = is_array($aPluginSlugs) ? $aPluginSlugs : array( 'fv-player-pro/fv-player-pro.php');
666 $aActivePlugins = get_option('active_plugins');
667 $aInactivePlugins = array_diff($aPluginSlugs,$aActivePlugins);
668
669 if( !$aPluginSlugs )
670 return false;
671 foreach( $aActivePlugins as $item ){
672 if( stripos($item,$slug.'.php') !== false )
673 return $item;
674 }
675
676 foreach( $aInactivePlugins as $item ){
677 if( stripos($item,$slug.'.php') !== false )
678 return $item;
679 }
680
681 return false;
682 }
683
684
685 public static function install_form_text( $html, $name ) {
686 $tag = stripos($html,'</h3>') !== false ? 'h3' : 'h2';
687 $html = preg_replace( '~<'.$tag.'.*?</'.$tag.'>~', '<'.$tag.'>'.$name.' auto-installation</'.$tag.'>', $html );
688 $html = preg_replace( '~(<input[^>]*?type="submit"[^>]*?>)~', '$1 <a href="'.admin_url('admin.php?page=fvplayer').'">Skip the '.$name.' install</a>', $html );
689 return $html;
690 }
691
692
693 public static function install_plugin( $name, $plugin_package, $plugin_basename, $download_url, $settings_url, $option, $nonce ) { // 'FV Player Pro', 'fv-player-pro', '/wp-admin/admin.php?page=fvplayer', download URL (perhaps from the license), settings URL (use admin_url(...), should also contain some GET which will make it install the extension if present) and option where result message should be stored and a nonce which should be passed
694 global $hook_suffix;
695
696 $plugin_path = self::get_plugin_path( str_replace( '_', '-', $plugin_package ) );
697 if( !defined('PHPUnitTestMode') && $plugin_path ) {
698 $result = activate_plugin( $plugin_path, $settings_url );
699 if ( is_wp_error( $result ) ) {
700 update_option( $option, $name.' extension activation error: '.$result->get_error_message() );
701 return false;
702 } else {
703 update_option( $option, $name.' extension activated' );
704 return true; // already installed
705 }
706 }
707
708 $plugin_basename = $plugin_path ? $plugin_path : $plugin_basename;
709
710 $url = wp_nonce_url( $settings_url, $nonce, 'nonce_'.$nonce );
711
712 set_current_screen();
713
714 ob_start();
715 if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, false ) ) ) {
716 $form = ob_get_clean();
717 include( ABSPATH . 'wp-admin/admin-header.php' );
718 echo self::install_form_text($form, $name);
719 include( ABSPATH . 'wp-admin/admin-footer.php' );
720 die;
721 }
722
723 if ( ! WP_Filesystem( $creds ) ) {
724 ob_start();
725 request_filesystem_credentials( $url, $method, true, false, false );
726 $form = ob_get_clean();
727 include( ABSPATH . 'wp-admin/admin-header.php' );
728 echo self::install_form_text($form, $name);
729 include( ABSPATH . 'wp-admin/admin-footer.php' );
730 die;
731 }
732
733 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
734
735 $result = true;
736
737 if( !$plugin_path || is_wp_error(validate_plugin($plugin_basename)) ) {
738 $sTaskDone = $name.__( ' extension installed successfully!', 'fv-player' );
739
740 echo '<div style="display: none;">';
741 $objInstaller = new Plugin_Upgrader();
742 $objInstaller->install( $download_url );
743 echo '</div>';
744 wp_cache_flush();
745
746 if ( is_wp_error( $objInstaller->skin->result ) ) {
747 update_option( $option, $name.__( ' extension install failed - ', 'fv-player' ) . $objInstaller->skin->result->get_error_message() );
748 $result = false;
749 } else {
750 if ( $objInstaller->plugin_info() ) {
751 $plugin_basename = $objInstaller->plugin_info();
752 }
753
754 $activate = activate_plugin( $plugin_basename );
755 if ( is_wp_error( $activate ) ) {
756 update_option( $option, $name.__( ' extension install failed - ', 'fv-player' ) . $activate->get_error_message());
757 $result = false;
758 }
759 }
760
761 } else if( $plugin_path ) {
762 $sTaskDone = $name.__( ' extension upgraded successfully!', 'fv-player' );
763
764 echo '<div style="display: none;">';
765 $objInstaller = new Plugin_Upgrader();
766 $objInstaller->upgrade( $plugin_path );
767 echo '</div></div>'; // explanation: extra closing tag just to be safe (in case of "The plugin is at the latest version.")
768 wp_cache_flush();
769
770 if ( is_wp_error( $objInstaller->skin->result ) ) {
771 update_option( $option, $name.' extension upgrade failed - '.$objInstaller->skin->result->get_error_message() );
772 $result = false;
773 } else {
774 if ( $objInstaller->plugin_info() ) {
775 $plugin_basename = $objInstaller->plugin_info();
776 }
777
778 $activate = activate_plugin( $plugin_basename );
779 if ( is_wp_error( $activate ) ) {
780 update_option( $option, $name.' Pro extension upgrade failed - '.$activate->get_error_message() );
781 $result = false;
782 }
783 }
784
785 }
786
787 if( $result ) {
788 update_option( $option, $sTaskDone );
789 echo "<script>location.href='" . esc_html( sanitize_url( $settings_url ) ) . "';</script>";
790 }
791
792 return $result;
793 }
794
795
796 function install_pro_version( $plugin_package = false, $target_url = false ) {
797
798 $aPluginInfo = get_transient( $this->strPluginSlug.'_license' );
799 if( $plugin_package && isset( $aPluginInfo->{$plugin_package} ) ) {
800 $plugin_basename = $aPluginInfo->{$plugin_package}->slug;
801 $download_url = $aPluginInfo->{$plugin_package}->url;
802 }
803 else {
804 $plugin_basename = file_exists( WP_PLUGIN_DIR.'/'.$this->strPluginSlug.'/plugin.php' ) ? $this->strPluginSlug.'/plugin.php' : $this->strPluginSlug.'/'.$this->strPluginSlug.'.php';
805 $download_url = $aPluginInfo->url;
806 $plugin_package = $this->strPluginSlug;
807 }
808
809 $aInstalled = get_option( $this->strPluginSlug.'_extension_install', array() );
810 $aInstalled = array_merge( $aInstalled, array( $plugin_package => false ) );
811 update_option( $this->strPluginSlug.'_extension_install', $aInstalled );
812
813 $sPluginBasenameReal = $this->get_extension_path( str_replace( '_', '-', $plugin_package ) );
814 $plugin_basename = $sPluginBasenameReal ? $sPluginBasenameReal : $plugin_basename;
815
816 $url = ( $target_url ) ? $target_url : site_url().'/wp-admin/plugins.php';
817 $url = wp_nonce_url( $url );
818
819 set_current_screen();
820
821 ob_start();
822 if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, false ) ) ) {
823 $form = ob_get_clean();
824 include( ABSPATH . 'wp-admin/admin-header.php' );
825 echo wp_kses_post( $this->pro_install_talk( $form, $target_url ) );
826 include( ABSPATH . 'wp-admin/admin-footer.php' );
827 die;
828 }
829
830 if ( ! WP_Filesystem( $creds ) ) {
831 ob_start();
832 request_filesystem_credentials( $url, $method, true, false, false );
833 $form = ob_get_clean();
834 include( ABSPATH . 'wp-admin/admin-header.php' );
835 echo wp_kses_post( $this->pro_install_talk( $form, $target_url ) );
836 include( ABSPATH . 'wp-admin/admin-footer.php' );
837 die;
838 }
839
840 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
841
842 if( !$sPluginBasenameReal || is_wp_error(validate_plugin($plugin_basename)) ) {
843 $sTaskDone = $this->strPluginName.' has been installed!';
844 echo '<div style="display: none;">';
845 $objInstaller = new Plugin_Upgrader();
846 $objInstaller->install( $download_url );
847 echo '</div>';
848 wp_cache_flush();
849
850 if ( is_wp_error( $objInstaller->skin->result ) ) {
851
852 update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' install failed - '. $objInstaller->skin->result->get_error_message() );
853 $bResult = false;
854 }
855 else {
856 if ( $objInstaller->plugin_info() ) {
857 $plugin_basename = $objInstaller->plugin_info();
858 }
859
860 $activate = activate_plugin( $plugin_basename );
861 if ( is_wp_error( $activate ) ) {
862 update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' install failed - '. $activate->get_error_message() );
863 $bResult = false;
864 }
865 }
866 }
867 else if( $sPluginBasenameReal ) {
868 $sTaskDone = $this->strPluginName.' upgraded successfully!';
869 echo '<div style="display: none;">';
870 $objInstaller = new Plugin_Upgrader();
871 $objInstaller->upgrade( $sPluginBasenameReal );
872 echo '</div></div>'; // explanation: extra closing tag just to be safe (in case of "The plugin is at the latest version.")
873 wp_cache_flush();
874
875 if ( is_wp_error( $objInstaller->skin->result ) ) {
876 update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' extension upgrade failed - '.$objInstaller->skin->result->get_error_message() );
877 $bResult = false;
878 }
879 else {
880 if ( $objInstaller->plugin_info() ) {
881 $plugin_basename = $objInstaller->plugin_info();
882 }
883
884 $activate = activate_plugin( $plugin_basename );
885 if ( is_wp_error( $activate ) ) {
886 update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' extension upgrade failed - '.$activate->get_error_message() );
887 $bResult = false;
888 }
889 }
890 }
891
892 if( empty( $bResult ) ) {
893 update_option( $this->strPluginSlug.'_deferred_notices', $sTaskDone );
894 $bResult = true;
895 }
896
897 $aInstalled = array_merge( $aInstalled, array( $plugin_package => $bResult ) );
898 update_option( $this->strPluginSlug.'_extension_install', $aInstalled );
899
900 return $bResult;
901 }
902
903 }
904