PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.5.6
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.5.6
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / includes / plugin.updates.php
folders / includes Last commit date
class-affiliate.php 5 years ago class-polylang.php 5 years ago class-review-box.php 5 years ago class-wpml.php 5 years ago folders.class.php 5 years ago form.class.php 5 years ago plugin.updates.php 5 years ago tree.class.php 5 years ago
plugin.updates.php
566 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 // Exit if accessed directly
6
7 /**
8 * Allows plugins to use their own update API.
9 *
10 * @author Easy Digital Downloads
11 * @version 1.6.17
12 */
13 class Folder_Plugin_Updater {
14
15 private $api_url = '';
16 private $api_data = array();
17 private $name = '';
18 private $slug = '';
19 private $version = '';
20 private $wp_override = false;
21 private $cache_key = '';
22
23 private $health_check_timeout = 5;
24
25 /**
26 * Class constructor.
27 *
28 * @uses plugin_basename()
29 * @uses hook()
30 *
31 * @param string $_api_url The URL pointing to the custom API endpoint.
32 * @param string $_plugin_file Path to the plugin file.
33 * @param array $_api_data Optional data to send with API calls.
34 */
35 public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
36
37 global $edd_plugin_data;
38
39 $this->api_url = trailingslashit( $_api_url );
40 $this->api_data = $_api_data;
41 $this->name = plugin_basename( $_plugin_file );
42 $this->slug = basename( $_plugin_file, '.php' );
43 $this->version = $_api_data['version'];
44 $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
45 $this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
46 $this->cache_key = 'edd_sl_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
47
48 $edd_plugin_data[ $this->slug ] = $this->api_data;
49
50 /**
51 * Fires after the $edd_plugin_data is setup.
52 *
53 * @since x.x.x
54 *
55 * @param array $edd_plugin_data Array of EDD SL plugin data.
56 */
57 do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
58
59 // Set up hooks.
60 $this->init();
61
62 }
63
64 /**
65 * Set up WordPress filters to hook into WP's update process.
66 *
67 * @uses add_filter()
68 *
69 * @return void
70 */
71 public function init() {
72
73 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
74 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
75 remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
76 add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
77 add_action( 'admin_init', array( $this, 'show_changelog' ) );
78
79 }
80
81 /**
82 * Check for Updates at the defined API endpoint and modify the update array.
83 *
84 * This function dives into the update API just when WordPress creates its update array,
85 * then adds a custom API call and injects the custom plugin data retrieved from the API.
86 * It is reassembled from parts of the native WordPress plugin update code.
87 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
88 *
89 * @uses api_request()
90 *
91 * @param array $_transient_data Update array build by WordPress.
92 * @return array Modified update array with custom plugin data.
93 */
94 public function check_update( $_transient_data ) {
95
96 global $pagenow;
97
98 if ( ! is_object( $_transient_data ) ) {
99 $_transient_data = new stdClass;
100 }
101
102 if ( 'plugins.php' == $pagenow && is_multisite() ) {
103 return $_transient_data;
104 }
105
106 if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
107 return $_transient_data;
108 }
109
110 $version_info = $this->get_cached_version_info();
111
112 if ( false === $version_info ) {
113 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
114
115 $this->set_version_info_cache( $version_info );
116
117 }
118
119 if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
120
121 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
122
123 $_transient_data->response[ $this->name ] = $version_info;
124
125 }
126
127 $_transient_data->last_checked = time();
128 $_transient_data->checked[ $this->name ] = $this->version;
129
130 }
131
132 return $_transient_data;
133 }
134
135 /**
136 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
137 *
138 * @param string $file
139 * @param array $plugin
140 */
141 public function show_update_notification( $file, $plugin ) {
142
143 if ( is_network_admin() ) {
144 return;
145 }
146
147 if( ! current_user_can( 'update_plugins' ) ) {
148 return;
149 }
150
151 if( ! is_multisite() ) {
152 return;
153 }
154
155 if ( $this->name != $file ) {
156 return;
157 }
158
159 // Remove our filter on the site transient
160 remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
161
162 $update_cache = get_site_transient( 'update_plugins' );
163
164 $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
165
166 if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
167
168 $version_info = $this->get_cached_version_info();
169
170 if ( false === $version_info ) {
171 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
172
173 // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now:
174 if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) {
175 $version_info->banners = $this->convert_object_to_array( $version_info->banners );
176 }
177
178 if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) {
179 $version_info->sections = $this->convert_object_to_array( $version_info->sections );
180 }
181
182 if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
183 $version_info->icons = $this->convert_object_to_array( $version_info->icons );
184 }
185
186 $this->set_version_info_cache( $version_info );
187 }
188
189 if ( ! is_object( $version_info ) ) {
190 return;
191 }
192
193 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
194
195 $update_cache->response[ $this->name ] = $version_info;
196
197 }
198
199 $update_cache->last_checked = time();
200 $update_cache->checked[ $this->name ] = $this->version;
201
202 set_site_transient( 'update_plugins', $update_cache );
203
204 } else {
205
206 $version_info = $update_cache->response[ $this->name ];
207
208 }
209
210 // Restore our filter
211 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
212
213 if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
214
215 // build a plugin list row, with update notification
216 # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
217 ?>
218 <tr class="plugin-update-tr" id="<?php echo esc_attr($this->slug) ?>-update" data-slug="<?php echo esc_attr($this->slug) ?>" data-plugin="<?php echo esc_attr($this->slug) ?>/' . $file . '">
219 <td colspan="3" class="plugin-update colspanchange">
220 <div class="update-message notice inline notice-warning notice-alt">
221 <?php
222 $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
223
224 if ( empty( $version_info->download_link ) ) {
225 printf(
226 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'easy-digital-downloads' ),
227 esc_html( $version_info->name ),
228 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
229 esc_html( $version_info->new_version ),
230 '</a>'
231 );
232 } else {
233 printf(
234 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'easy-digital-downloads' ),
235 esc_html( $version_info->name ),
236 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
237 esc_html( $version_info->new_version ),
238 '</a>',
239 '<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) .'">',
240 '</a>'
241 );
242 }
243
244 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
245
246 echo '</div></td></tr>';
247 }
248 }
249
250 /**
251 * Updates information on the "View version x.x details" page with custom data.
252 *
253 * @uses api_request()
254 *
255 * @param mixed $_data
256 * @param string $_action
257 * @param object $_args
258 * @return object $_data
259 */
260 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
261
262 if ( $_action != 'plugin_information' ) {
263
264 return $_data;
265
266 }
267
268 if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
269
270 return $_data;
271
272 }
273
274 $to_send = array(
275 'slug' => $this->slug,
276 'is_ssl' => is_ssl(),
277 'fields' => array(
278 'banners' => array(),
279 'reviews' => false,
280 'icons' => array(),
281 )
282 );
283
284 $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
285
286 // Get the transient where we store the api request for this plugin for 24 hours
287 $edd_api_request_transient = $this->get_cached_version_info( $cache_key );
288
289 //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
290 if ( empty( $edd_api_request_transient ) ) {
291
292 $api_response = $this->api_request( 'plugin_information', $to_send );
293
294 // Expires in 3 hours
295 $this->set_version_info_cache( $api_response, $cache_key );
296
297 if ( false !== $api_response ) {
298 $_data = $api_response;
299 }
300
301 } else {
302 $_data = $edd_api_request_transient;
303 }
304
305 // Convert sections into an associative array, since we're getting an object, but Core expects an array.
306 if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
307 $_data->sections = $this->convert_object_to_array( $_data->sections );
308 }
309
310 // Convert banners into an associative array, since we're getting an object, but Core expects an array.
311 if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
312 $_data->banners = $this->convert_object_to_array( $_data->banners );
313 }
314
315 // Convert icons into an associative array, since we're getting an object, but Core expects an array.
316 if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
317 $_data->icons = $this->convert_object_to_array( $_data->icons );
318 }
319
320 return $_data;
321 }
322
323 /**
324 * Convert some objects to arrays when injecting data into the update API
325 *
326 * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
327 * decoding, they are objects. This method allows us to pass in the object and return an associative array.
328 *
329 * @since 3.6.5
330 *
331 * @param stdClass $data
332 *
333 * @return array
334 */
335 private function convert_object_to_array( $data ) {
336 $new_data = array();
337 foreach ( $data as $key => $value ) {
338 $new_data[ $key ] = $value;
339 }
340
341 return $new_data;
342 }
343
344 /**
345 * Disable SSL verification in order to prevent download update failures
346 *
347 * @param array $args
348 * @param string $url
349 * @return object $array
350 */
351 public function http_request_args( $args, $url ) {
352
353 $verify_ssl = $this->verify_ssl();
354 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
355 $args['sslverify'] = $verify_ssl;
356 }
357 return $args;
358
359 }
360
361 /**
362 * Calls the API and, if successfull, returns the object delivered by the API.
363 *
364 * @uses get_bloginfo()
365 * @uses wp_remote_post()
366 * @uses is_wp_error()
367 *
368 * @param string $_action The requested action.
369 * @param array $_data Parameters for the API action.
370 * @return false|object
371 */
372 private function api_request( $_action, $_data ) {
373
374 global $wp_version, $edd_plugin_url_available;
375
376 // Do a quick status check on this domain if we haven't already checked it.
377 $store_hash = md5( $this->api_url );
378 if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) {
379 $test_url_parts = parse_url( $this->api_url );
380
381 $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http';
382 $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : '';
383 $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : '';
384
385 if ( empty( $host ) ) {
386 $edd_plugin_url_available[ $store_hash ] = false;
387 } else {
388 $test_url = $scheme . '://' . $host . $port;
389 $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => true ) );
390 $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true;
391 }
392 }
393
394 if ( false === $edd_plugin_url_available[ $store_hash ] ) {
395 return;
396 }
397
398 $data = array_merge( $this->api_data, $_data );
399
400 if ( $data['slug'] != $this->slug ) {
401 return;
402 }
403
404 if( $this->api_url == trailingslashit ( home_url() ) ) {
405 return false; // Don't allow a plugin to ping itself
406 }
407
408 $api_params = array(
409 'edd_action' => 'get_version',
410 'license' => ! empty( $data['license'] ) ? $data['license'] : '',
411 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
412 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
413 'version' => isset( $data['version'] ) ? $data['version'] : false,
414 'slug' => $data['slug'],
415 'author' => $data['author'],
416 'url' => home_url(),
417 'beta' => ! empty( $data['beta'] ),
418 );
419
420 $verify_ssl = $this->verify_ssl();
421 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
422
423 if ( ! is_wp_error( $request ) ) {
424 $request = json_decode( wp_remote_retrieve_body( $request ) );
425 }
426
427 if ( $request && isset( $request->sections ) ) {
428 $request->sections = maybe_unserialize( $request->sections );
429 } else {
430 $request = false;
431 }
432
433 if ( $request && isset( $request->banners ) ) {
434 $request->banners = maybe_unserialize( $request->banners );
435 }
436
437 if ( $request && isset( $request->icons ) ) {
438 $request->icons = maybe_unserialize( $request->icons );
439 }
440
441 if( ! empty( $request->sections ) ) {
442 foreach( $request->sections as $key => $section ) {
443 $request->$key = (array) $section;
444 }
445 }
446
447 return $request;
448 }
449
450 public function show_changelog() {
451
452 global $edd_plugin_data;
453
454 if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
455 return;
456 }
457
458 if( empty( $_REQUEST['plugin'] ) ) {
459 return;
460 }
461
462 if( empty( $_REQUEST['slug'] ) ) {
463 return;
464 }
465
466 if( ! current_user_can( 'update_plugins' ) ) {
467 wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
468 }
469
470 $data = $edd_plugin_data[ $_REQUEST['slug'] ];
471 $beta = ! empty( $data['beta'] ) ? true : false;
472 $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
473 $version_info = $this->get_cached_version_info( $cache_key );
474
475 if( false === $version_info ) {
476
477 $api_params = array(
478 'edd_action' => 'get_version',
479 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
480 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
481 'slug' => $_REQUEST['slug'],
482 'author' => $data['author'],
483 'url' => home_url(),
484 'beta' => ! empty( $data['beta'] )
485 );
486
487 $verify_ssl = $this->verify_ssl();
488 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
489
490 if ( ! is_wp_error( $request ) ) {
491 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
492 }
493
494
495 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
496 $version_info->sections = maybe_unserialize( $version_info->sections );
497 } else {
498 $version_info = false;
499 }
500
501 if( ! empty( $version_info ) ) {
502 foreach( $version_info->sections as $key => $section ) {
503 $version_info->$key = (array) $section;
504 }
505 }
506
507 $this->set_version_info_cache( $version_info, $cache_key );
508
509 }
510
511 if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
512 echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
513 }
514
515 exit;
516 }
517
518 public function get_cached_version_info( $cache_key = '' ) {
519
520 if( empty( $cache_key ) ) {
521 $cache_key = $this->cache_key;
522 }
523
524 $cache = get_option( $cache_key );
525
526 if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
527 return false; // Cache is expired
528 }
529
530 // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
531 $cache['value'] = json_decode( $cache['value'] );
532 if ( ! empty( $cache['value']->icons ) ) {
533 $cache['value']->icons = (array) $cache['value']->icons;
534 }
535
536 return $cache['value'];
537
538 }
539
540 public function set_version_info_cache( $value = '', $cache_key = '' ) {
541
542 if( empty( $cache_key ) ) {
543 $cache_key = $this->cache_key;
544 }
545
546 $data = array(
547 'timeout' => strtotime( '+3 hours', time() ),
548 'value' => json_encode( $value )
549 );
550
551 update_option( $cache_key, $data, 'no' );
552
553 }
554
555 /**
556 * Returns if the SSL of the store should be verified.
557 *
558 * @since 1.6.13
559 * @return bool
560 */
561 private function verify_ssl() {
562 return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
563 }
564
565 }
566