PluginProbe ʕ •ᴥ•ʔ
PixelYourSite – Your smart PIXEL (TAG) & API Manager / 9.5.1
PixelYourSite – Your smart PIXEL (TAG) & API Manager v9.5.1
11.2.0.6 trunk 1.0 1.01 1.02 1.03 1.04 1.05 1.05.1 10.0.0 10.0.1 10.0.1.1 10.0.1.2 10.0.2 10.0.3 10.0.3.1 10.0.4 10.1.0 10.1.1 10.1.1.1 10.1.1.2 10.1.2.1 10.1.3 10.2.0 10.2.0.1 10.2.0.2 10.2.1 11.0.0 11.0.0.1 11.0.0.2 11.0.0.3 11.0.0.4 11.0.1 11.0.1.1 11.0.1.2 11.0.2 11.1.0 11.1.1 11.1.2 11.1.3 11.1.4 11.1.4.1 11.1.4.2 11.1.5 11.1.5.1 11.1.5.2 11.2.0 11.2.0.1 11.2.0.2 11.2.0.3 11.2.0.4 11.2.0.5 2.0 2.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.7 2.8.10 2.8.9 3.0 3.0.1 3.0.2 3.0.3 3.1.0 4.0.0 4.0.1 4.0.2 4.0.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5.2 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.2.0 5.2.1 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 7.0.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1.0 7.1.1 7.1.10 7.1.11 7.1.12 7.1.13 7.1.14 7.1.2 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.1.8 7.1.9 7.2.0 7.2.1 7.2.1.1 7.3.0 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.0.9 8.1.0 8.1.1 8.2.0 8.2.1 8.2.10 8.2.11 8.2.12 8.2.13 8.2.14 8.2.15 8.2.16 8.2.17 8.2.18 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.2.7 8.2.8 9.0.0 9.1.0 9.1.1 9.2.0 9.2.1 9.2.2 9.3.0 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.3.6 9.3.7 9.3.8 9.3.8.1 9.3.9 9.4.0 9.4.0.1 9.4.1 9.4.2 9.4.3 9.4.5 9.4.5.1 9.4.6 9.4.7 9.4.7.1 9.5.0 9.5.0.1 9.5.1 9.5.1.1 9.5.3 9.5.4 9.5.5 9.6.0 9.6.0.1 9.6.1 9.6.1.1 9.6.2 9.7.0 9.7.0.1 9.7.1 9.7.2
pixelyoursite / includes / class-plugin-updater.php
pixelyoursite / includes Last commit date
enrich 2 years ago events 2 years ago formEvents 2 years ago logger 2 years ago views 2 years ago class-custom-event-factory.php 7 years ago class-custom-event.php 2 years ago class-event-id-generator.php 5 years ago class-events-manager-ajax_hook.php 2 years ago class-events-manager.php 2 years ago class-fixed-notices.php 2 years ago class-pixel.php 7 years ago class-plugin-updater.php 2 years ago class-plugin.php 7 years ago class-pys.php 2 years ago class-settings.php 2 years ago functions-admin.php 2 years ago functions-common.php 2 years ago functions-custom-event.php 3 years ago functions-edd.php 2 years ago functions-gdpr.php 2 years ago functions-license.php 2 years ago functions-migrate.php 3 years ago functions-optin.php 2 years ago functions-promo-notices.php 3 years ago functions-system-report.php 7 years ago functions-update-plugin.php 6 years ago functions-woo.php 2 years ago options_defaults.json 2 years ago options_fields.json 2 years ago
class-plugin-updater.php
545 lines
1 <?php
2
3 namespace PixelYourSite;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 // uncomment this line for testing
10 //set_site_transient( 'update_plugins', null );
11
12 /**
13 * Allows plugins to use their own update API.
14 *
15 * This is used strictly for add-on updates, NOT for updating the core plugin itself (PixelYourSite).
16 * If you decide to download and install free or paid add-ons from our site (Pinterest Tag, Bing Tag), we will perform checks for updates.
17 * If you hold a valid license for the add-on, we will download the update from our server.
18 *
19 *
20 * @author Easy Digital Downloads
21 * @version 1.6.14
22 *
23 */
24 class Plugin_Updater {
25
26 private $api_url = '';
27 private $api_data = array();
28 private $name = '';
29 private $slug = '';
30 private $version = '';
31 private $wp_override = false;
32 private $cache_key = '';
33
34 private $beta = false;
35 /**
36 * Class constructor.
37 *
38 * @uses plugin_basename()
39 * @uses hook()
40 *
41 * @param string $_api_url The URL pointing to the custom API endpoint.
42 * @param string $_plugin_file Path to the plugin file.
43 * @param array $_api_data Optional data to send with API calls.
44 */
45 public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
46
47 global $edd_plugin_data;
48
49 $this->api_url = trailingslashit( $_api_url );
50 $this->api_data = $_api_data;
51 $this->name = plugin_basename( $_plugin_file );
52 $this->slug = basename( $_plugin_file, '.php' );
53 $this->version = $_api_data['version'];
54 $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
55 $this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
56 $this->cache_key = md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
57
58 $edd_plugin_data[ $this->slug ] = $this->api_data;
59
60 // Set up hooks.
61 $this->init();
62
63 }
64
65 /**
66 * Set up WordPress filters to hook into WP's update process.
67 *
68 * @uses add_filter()
69 *
70 * @return void
71 */
72 public function init() {
73
74 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
75 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
76 remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
77 add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
78 add_action( 'admin_init', array( $this, 'show_changelog' ) );
79
80 }
81
82 /**
83 * Check for Updates at the defined API endpoint and modify the update array.
84 *
85 * This function dives into the update API just when WordPress creates its update array,
86 * then adds a custom API call and injects the custom plugin data retrieved from the API.
87 * It is reassembled from parts of the native WordPress plugin update code.
88 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
89 *
90 * @uses api_request()
91 *
92 * @param array $_transient_data Update array build by WordPress.
93 *
94 * @return array Modified update array with custom plugin data.
95 */
96 public function check_update( $_transient_data ) {
97
98 global $pagenow;
99
100 if ( ! is_object( $_transient_data ) ) {
101 $_transient_data = new \stdClass;
102 }
103
104 if ( 'plugins.php' == $pagenow && is_multisite() ) {
105 return $_transient_data;
106 }
107
108 if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
109 return $_transient_data;
110 }
111
112 $version_info = $this->get_cached_version_info();
113
114 if ( $this->is_cache_expired() ) {
115 $version_info = $this->api_request( 'plugin_latest_version',
116 array( 'slug' => $this->slug, 'beta' => $this->beta ) );
117
118 if($this->slug == "pixelyoursite-pinterest") {
119 $timeout = strtotime( '+48 hours', current_time( 'timestamp' ) );
120 } else {
121 $timeout = strtotime( '+24 hours', current_time( 'timestamp' ) );
122 }
123 $this->set_version_info_cache( $version_info,"",$timeout );
124
125 }
126
127 if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
128
129 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
130
131 $_transient_data->response[ $this->name ] = $version_info;
132
133 }
134
135 $_transient_data->last_checked = current_time( 'timestamp' );
136 $_transient_data->checked[ $this->name ] = $this->version;
137
138 }
139
140 return $_transient_data;
141 }
142
143 /**
144 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
145 *
146 * @param string $file
147 * @param array $plugin
148 */
149 public function show_update_notification( $file, $plugin ) {
150
151 if ( is_network_admin() ) {
152 return;
153 }
154
155 if ( ! current_user_can( 'update_plugins' ) ) {
156 return;
157 }
158
159 if ( ! is_multisite() ) {
160 return;
161 }
162
163 if ( $this->name != $file ) {
164 return;
165 }
166
167 // Remove our filter on the site transient
168 remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
169
170 $update_cache = get_site_transient( 'update_plugins' );
171
172 $update_cache = is_object( $update_cache ) ? $update_cache : new \stdClass();
173
174 if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
175
176 $version_info = $this->get_cached_version_info();
177
178 if ( $this->is_cache_expired() ) {
179 $version_info = $this->api_request( 'plugin_latest_version',
180 array( 'slug' => $this->slug, 'beta' => $this->beta ) );
181 if($this->slug == "pixelyoursite-pinterest") {
182 $timeout = strtotime( '+48 hours', current_time( 'timestamp' ) );
183 } else {
184 $timeout = strtotime( '+24 hours', current_time( 'timestamp' ) );
185 }
186 $this->set_version_info_cache( $version_info,"",$timeout );
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 = current_time( 'timestamp' );
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,
214 $version_info->new_version, '<' ) ) {
215
216 // build a plugin list row, with update notification
217 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
218 # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
219 echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
220 echo '<td colspan="3" class="plugin-update colspanchange">';
221 echo '<div class="update-message notice inline notice-warning notice-alt">';
222
223 $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' );
224
225 if ( empty( $version_info->download_link ) ) {
226 printf(
227 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.',
228 'easy-digital-downloads' ),
229 esc_html( $version_info->name ),
230 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
231 esc_html( $version_info->new_version ),
232 '</a>'
233 );
234 } else {
235 printf(
236 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.',
237 'easy-digital-downloads' ),
238 esc_html( $version_info->name ),
239 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
240 esc_html( $version_info->new_version ),
241 '</a>',
242 '<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name,
243 'upgrade-plugin_' . $this->name ) ) . '">',
244 '</a>'
245 );
246 }
247
248 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
249
250 echo '</div></td></tr>';
251 }
252 }
253
254 /**
255 * Updates information on the "View version x.x details" page with custom data.
256 *
257 * @uses api_request()
258 *
259 * @param mixed $_data
260 * @param string $_action
261 * @param object $_args
262 *
263 * @return object $_data
264 */
265 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
266
267 if ( $_action != 'plugin_information' ) {
268
269 return $_data;
270
271 }
272
273 if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
274
275 return $_data;
276
277 }
278
279 $to_send = array(
280 'slug' => $this->slug,
281 'is_ssl' => is_ssl(),
282 'fields' => array(
283 'banners' => array(),
284 'reviews' => false
285 )
286 );
287
288 $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
289
290 // Get the transient where we store the api request for this plugin for 24 hours
291 $edd_api_request_transient = $this->get_cached_version_info( $cache_key );
292
293 //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.
294 if ( empty( $edd_api_request_transient ) ) {
295
296 $api_response = $this->api_request( 'plugin_information', $to_send );
297
298 // Expires in 3 hours
299 if($this->slug == "pixelyoursite-pinterest") {
300 $timeout = strtotime( '+48 hours', current_time( 'timestamp' ) );
301 } else {
302 $timeout = strtotime( '+24 hours', current_time( 'timestamp' ) );
303 }
304 $this->set_version_info_cache( $api_response, $cache_key,$timeout );
305
306 if ( false !== $api_response ) {
307 $_data = $api_response;
308 }
309
310 } else {
311 $_data = $edd_api_request_transient;
312 }
313
314 // Convert sections into an associative array, since we're getting an object, but Core expects an array.
315 if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
316 $new_sections = array();
317 foreach ( $_data->sections as $key => $value ) {
318 $new_sections[ $key ] = $value;
319 }
320
321 $_data->sections = $new_sections;
322 }
323
324 // Convert banners into an associative array, since we're getting an object, but Core expects an array.
325 if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
326 $new_banners = array();
327 foreach ( $_data->banners as $key => $value ) {
328 $new_banners[ $key ] = $value;
329 }
330
331 $_data->banners = $new_banners;
332 }
333
334 return $_data;
335 }
336
337 /**
338 * Disable SSL verification in order to prevent download update failures
339 *
340 * @param array $args
341 * @param string $url
342 *
343 * @return object $array
344 */
345 public function http_request_args( $args, $url ) {
346
347 $verify_ssl = $this->verify_ssl();
348 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
349 $args['sslverify'] = $verify_ssl;
350 }
351
352 return $args;
353
354 }
355
356 /**
357 * Calls the API and, if successfull, returns the object delivered by the API.
358 *
359 * @uses get_bloginfo()
360 * @uses wp_remote_post()
361 * @uses is_wp_error()
362 *
363 * @param string $_action The requested action.
364 * @param array $_data Parameters for the API action.
365 *
366 * @return false|object
367 */
368 private function api_request( $_action, $_data ) {
369
370 global $wp_version;
371
372 $data = array_merge( $this->api_data, $_data );
373
374 if ( $data['slug'] != $this->slug ) {
375 return;
376 }
377
378 if ( $this->api_url == trailingslashit( home_url() ) ) {
379 return false; // Don't allow a plugin to ping itself
380 }
381
382 $api_params = array(
383 'edd_action' => 'get_version',
384 'license' => ! empty( $data['license'] ) ? $data['license'] : '',
385 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
386 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
387 'version' => isset( $data['version'] ) ? $data['version'] : false,
388 'slug' => $data['slug'],
389 'author' => $data['author'],
390 'url' => home_url(),
391 'beta' => ! empty( $data['beta'] ),
392 );
393
394 $verify_ssl = $this->verify_ssl();
395 $request = wp_remote_post( $this->api_url,
396 array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
397
398 if ( ! is_wp_error( $request ) ) {
399 $request = json_decode( wp_remote_retrieve_body( $request ) );
400 }
401
402 if ( $request && isset( $request->sections ) ) {
403 $request->sections = maybe_unserialize( $request->sections );
404 }
405
406 if ( $request && isset( $request->banners ) ) {
407 $request->banners = maybe_unserialize( $request->banners );
408 }
409
410 if ( ! empty( $request->sections ) ) {
411 foreach ( $request->sections as $key => $section ) {
412 $request->$key = (array) $section;
413 }
414 }
415
416 return $request;
417 }
418
419 public function show_changelog() {
420
421 global $edd_plugin_data;
422
423 if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
424 return;
425 }
426
427 if ( empty( $_REQUEST['plugin'] ) ) {
428 return;
429 }
430
431 if ( empty( $_REQUEST['slug'] ) ) {
432 return;
433 }
434
435 if ( ! current_user_can( 'update_plugins' ) ) {
436 wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ),
437 __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
438 }
439 $slag = sanitize_title($_REQUEST['slug']);
440 $data = $edd_plugin_data[ $slag ];
441 $beta = ! empty( $data['beta'] ) ? true : false;
442 $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
443 $version_info = $this->get_cached_version_info( $cache_key );
444
445 if ( false === $version_info ) {
446
447 $api_params = array(
448 'edd_action' => 'get_version',
449 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
450 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
451 'slug' => $slag,
452 'author' => $data['author'],
453 'url' => home_url(),
454 'beta' => ! empty( $data['beta'] )
455 );
456
457 $verify_ssl = $this->verify_ssl();
458 $request = wp_remote_post( $this->api_url,
459 array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
460
461 if ( ! is_wp_error( $request ) ) {
462 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
463 }
464
465
466 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
467 $version_info->sections = maybe_unserialize( $version_info->sections );
468 } else {
469 $version_info = false;
470 }
471
472 if ( ! empty( $version_info ) ) {
473 foreach ( $version_info->sections as $key => $section ) {
474 $version_info->$key = (array) $section;
475 }
476 }
477 if($slag == "pixelyoursite-pinterest") {
478 $timeout = strtotime( '+48 hours', current_time( 'timestamp' ) );
479 } else {
480 $timeout = strtotime( '+24 hours', current_time( 'timestamp' ) );
481 }
482 $this->set_version_info_cache( $version_info, $cache_key,$timeout );
483
484 }
485
486 if ( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
487 echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
488 }
489
490 exit;
491 }
492
493 public function is_cache_expired( $cache_key = '' ){
494 if ( empty( $cache_key ) ) {
495 $cache_key = $this->cache_key;
496 }
497
498 $cache = get_option( $cache_key );
499
500 if ( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) {
501 return true; // Cache is expired
502 }
503 return false;
504 }
505 public function get_cached_version_info( $cache_key = '' ) {
506
507 if ( empty( $cache_key ) ) {
508 $cache_key = $this->cache_key;
509 }
510
511 $cache = get_option( $cache_key );
512
513 return json_decode( $cache['value'] );
514
515 }
516
517 public function set_version_info_cache( $value = '', $cache_key = '',$timeout = null ) {
518
519 if ( empty( $cache_key ) ) {
520 $cache_key = $this->cache_key;
521 }
522
523 if($timeout == null) {
524 $timeout = strtotime( '+24 hours', current_time( 'timestamp' ) );
525 }
526 $data = array(
527 'timeout' => $timeout,
528 'value' => json_encode( $value )
529 );
530
531 update_option( $cache_key, $data, 'no' );
532
533 }
534
535 /**
536 * Returns if the SSL of the store should be verified.
537 *
538 * @since 1.6.13
539 * @return bool
540 */
541 private function verify_ssl() {
542 return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
543 }
544
545 }