PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.25
Advanced Ads – Ad Manager & AdSense v1.8.25
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / classes / EDD_SL_Plugin_Updater.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 8 years ago ad-ajax.php 9 years ago ad-debug.php 8 years ago ad-model.php 9 years ago ad-select.php 9 years ago ad.php 8 years ago ad_ajax_callbacks.php 8 years ago ad_group.php 8 years ago ad_placements.php 8 years ago ad_type_abstract.php 8 years ago ad_type_content.php 8 years ago ad_type_dummy.php 8 years ago ad_type_group.php 8 years ago ad_type_image.php 8 years ago ad_type_plain.php 8 years ago checks.php 8 years ago display-conditions.php 8 years ago filesystem.php 8 years ago frontend_checks.php 8 years ago plugin.php 8 years ago upgrades.php 9 years ago utils.php 8 years ago visitor-conditions.php 8 years ago widget.php 8 years ago
EDD_SL_Plugin_Updater.php
492 lines
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 /**
7 * Allows plugins to use their own update API.
8 *
9 * @author Easy Digital Downloads
10 * @version 1.6.13
11 */
12 class ADVADS_SL_Plugin_Updater {
13
14 private $api_url = '';
15 private $api_data = array();
16 private $name = '';
17 private $slug = '';
18 private $version = '';
19 private $wp_override = false;
20 private $cache_key = '';
21
22 /**
23 * Class constructor.
24 *
25 * @uses plugin_basename()
26 * @uses hook()
27 *
28 * @param string $_api_url The URL pointing to the custom API endpoint.
29 * @param string $_plugin_file Path to the plugin file.
30 * @param array $_api_data Optional data to send with API calls.
31 */
32 public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
33
34 global $edd_plugin_data;
35
36 $this->api_url = trailingslashit( $_api_url );
37 $this->api_data = $_api_data;
38 $this->name = plugin_basename( $_plugin_file );
39 $this->slug = basename( $_plugin_file, '.php' );
40 $this->version = $_api_data['version'];
41 $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
42 $this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
43 $this->cache_key = md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
44
45 $edd_plugin_data[ $this->slug ] = $this->api_data;
46
47 // Set up hooks.
48 $this->init();
49
50 }
51
52 /**
53 * Set up WordPress filters to hook into WP's update process.
54 *
55 * @uses add_filter()
56 *
57 * @return void
58 */
59 public function init() {
60
61 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
62 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
63 remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
64 add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
65 add_action( 'admin_init', array( $this, 'show_changelog' ) );
66
67 }
68
69 /**
70 * Check for Updates at the defined API endpoint and modify the update array.
71 *
72 * This function dives into the update API just when WordPress creates its update array,
73 * then adds a custom API call and injects the custom plugin data retrieved from the API.
74 * It is reassembled from parts of the native WordPress plugin update code.
75 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
76 *
77 * @uses api_request()
78 *
79 * @param array $_transient_data Update array build by WordPress.
80 * @return array Modified update array with custom plugin data.
81 */
82 public function check_update( $_transient_data ) {
83
84 global $pagenow;
85
86 if ( ! is_object( $_transient_data ) ) {
87 $_transient_data = new stdClass;
88 }
89
90 if ( 'plugins.php' == $pagenow && is_multisite() ) {
91 return $_transient_data;
92 }
93
94 if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
95 return $_transient_data;
96 }
97
98 $version_info = $this->get_cached_version_info();
99
100 if ( false === $version_info ) {
101 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
102
103 $this->set_version_info_cache( $version_info );
104
105 }
106
107 if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
108
109 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
110
111 $_transient_data->response[ $this->name ] = $version_info;
112
113 }
114
115 $_transient_data->last_checked = current_time( 'timestamp' );
116 $_transient_data->checked[ $this->name ] = $this->version;
117
118 }
119
120 return $_transient_data;
121 }
122
123 /**
124 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
125 *
126 * @param string $file
127 * @param array $plugin
128 */
129 public function show_update_notification( $file, $plugin ) {
130
131 if ( is_network_admin() ) {
132 return;
133 }
134
135 if( ! current_user_can( 'update_plugins' ) ) {
136 return;
137 }
138
139 if( ! is_multisite() ) {
140 return;
141 }
142
143 if ( $this->name != $file ) {
144 return;
145 }
146
147 // Remove our filter on the site transient
148 remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
149
150 $update_cache = get_site_transient( 'update_plugins' );
151
152 $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
153
154 if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
155
156 $version_info = $this->get_cached_version_info();
157
158 if ( false === $version_info ) {
159 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
160
161 $this->set_version_info_cache( $version_info );
162 }
163
164 if ( ! is_object( $version_info ) ) {
165 return;
166 }
167
168 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
169
170 $update_cache->response[ $this->name ] = $version_info;
171
172 }
173
174 $update_cache->last_checked = current_time( 'timestamp' );
175 $update_cache->checked[ $this->name ] = $this->version;
176
177 set_site_transient( 'update_plugins', $update_cache );
178
179 } else {
180
181 $version_info = $update_cache->response[ $this->name ];
182
183 }
184
185 // Restore our filter
186 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
187
188 if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
189
190 // build a plugin list row, with update notification
191 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
192 # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
193 echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
194 echo '<td colspan="3" class="plugin-update colspanchange">';
195 echo '<div class="update-message notice inline notice-warning notice-alt">';
196
197 $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' );
198
199 if ( empty( $version_info->download_link ) ) {
200 printf(
201 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'advanced-ads' ),
202 esc_html( $version_info->name ),
203 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
204 esc_html( $version_info->new_version ),
205 '</a>'
206 );
207 } else {
208 printf(
209 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'advanced-ads' ),
210 esc_html( $version_info->name ),
211 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
212 esc_html( $version_info->new_version ),
213 '</a>',
214 '<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) .'">',
215 '</a>'
216 );
217 }
218
219 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
220
221 echo '</div></td></tr>';
222 }
223 }
224
225 /**
226 * Updates information on the "View version x.x details" page with custom data.
227 *
228 * @uses api_request()
229 *
230 * @param mixed $_data
231 * @param string $_action
232 * @param object $_args
233 * @return object $_data
234 */
235 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
236
237 if ( $_action != 'plugin_information' ) {
238
239 return $_data;
240
241 }
242
243 if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
244
245 return $_data;
246
247 }
248
249 $to_send = array(
250 'slug' => $this->slug,
251 'is_ssl' => is_ssl(),
252 'fields' => array(
253 'banners' => array(),
254 'reviews' => false
255 )
256 );
257
258 $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
259
260 // Get the transient where we store the api request for this plugin for 24 hours
261 $edd_api_request_transient = $this->get_cached_version_info( $cache_key );
262
263 //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.
264 if ( empty( $edd_api_request_transient ) ) {
265
266 $api_response = $this->api_request( 'plugin_information', $to_send );
267
268 // Expires in 3 hours
269 $this->set_version_info_cache( $api_response, $cache_key );
270
271 if ( false !== $api_response ) {
272 $_data = $api_response;
273 }
274
275 } else {
276 $_data = $edd_api_request_transient;
277 }
278
279 // Convert sections into an associative array, since we're getting an object, but Core expects an array.
280 if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
281 $new_sections = array();
282 foreach ( $_data->sections as $key => $value ) {
283 $new_sections[ $key ] = $value;
284 }
285
286 $_data->sections = $new_sections;
287 }
288
289 // Convert banners into an associative array, since we're getting an object, but Core expects an array.
290 if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
291 $new_banners = array();
292 foreach ( $_data->banners as $key => $value ) {
293 $new_banners[ $key ] = $value;
294 }
295
296 $_data->banners = $new_banners;
297 }
298
299 return $_data;
300 }
301
302 /**
303 * Disable SSL verification in order to prevent download update failures
304 *
305 * @param array $args
306 * @param string $url
307 * @return object $array
308 */
309 public function http_request_args( $args, $url ) {
310
311 $verify_ssl = $this->verify_ssl();
312 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
313 $args['sslverify'] = $verify_ssl;
314 }
315 return $args;
316
317 }
318
319 /**
320 * Calls the API and, if successfull, returns the object delivered by the API.
321 *
322 * @uses get_bloginfo()
323 * @uses wp_remote_post()
324 * @uses is_wp_error()
325 *
326 * @param string $_action The requested action.
327 * @param array $_data Parameters for the API action.
328 * @return false|object
329 */
330 private function api_request( $_action, $_data ) {
331
332 global $wp_version;
333
334 $data = array_merge( $this->api_data, $_data );
335
336 if ( $data['slug'] != $this->slug ) {
337 return;
338 }
339
340 if( $this->api_url == trailingslashit (home_url() ) ) {
341 return false; // Don't allow a plugin to ping itself
342 }
343
344 $api_params = array(
345 'edd_action' => 'get_version',
346 'license' => ! empty( $data['license'] ) ? $data['license'] : '',
347 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
348 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
349 'version' => isset( $data['version'] ) ? $data['version'] : false,
350 'slug' => $data['slug'],
351 'author' => $data['author'],
352 'url' => home_url(),
353 'beta' => ! empty( $data['beta'] ),
354 );
355
356 $verify_ssl = $this->verify_ssl();
357 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
358
359 if ( ! is_wp_error( $request ) ) {
360 $request = json_decode( wp_remote_retrieve_body( $request ) );
361 }
362
363 if ( $request && isset( $request->sections ) ) {
364 $request->sections = maybe_unserialize( $request->sections );
365 } else {
366 $request = false;
367 }
368
369 if ( $request && isset( $request->banners ) ) {
370 $request->banners = maybe_unserialize( $request->banners );
371 }
372
373 if( ! empty( $request->sections ) ) {
374 foreach( $request->sections as $key => $section ) {
375 $request->$key = (array) $section;
376 }
377 }
378
379 return $request;
380 }
381
382 public function show_changelog() {
383
384 global $edd_plugin_data;
385
386 if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
387 return;
388 }
389
390 if( empty( $_REQUEST['plugin'] ) ) {
391 return;
392 }
393
394 if( empty( $_REQUEST['slug'] ) ) {
395 return;
396 }
397
398 if( ! current_user_can( 'update_plugins' ) ) {
399 wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
400 }
401
402 $data = $edd_plugin_data[ $_REQUEST['slug'] ];
403 $beta = ! empty( $data['beta'] ) ? true : false;
404 $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
405 $version_info = $this->get_cached_version_info( $cache_key );
406
407 if( false === $version_info ) {
408
409 $api_params = array(
410 'edd_action' => 'get_version',
411 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
412 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
413 'slug' => $_REQUEST['slug'],
414 'author' => $data['author'],
415 'url' => home_url(),
416 'beta' => ! empty( $data['beta'] )
417 );
418
419 $verify_ssl = $this->verify_ssl();
420 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
421
422 if ( ! is_wp_error( $request ) ) {
423 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
424 }
425
426
427 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
428 $version_info->sections = maybe_unserialize( $version_info->sections );
429 } else {
430 $version_info = false;
431 }
432
433 if( ! empty( $version_info ) ) {
434 foreach( $version_info->sections as $key => $section ) {
435 $version_info->$key = (array) $section;
436 }
437 }
438
439 $this->set_version_info_cache( $version_info, $cache_key );
440
441 }
442
443 if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
444 echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
445 }
446
447 exit;
448 }
449
450 public function get_cached_version_info( $cache_key = '' ) {
451
452 if( empty( $cache_key ) ) {
453 $cache_key = $this->cache_key;
454 }
455
456 $cache = get_option( $cache_key );
457
458 if( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) {
459 return false; // Cache is expired
460 }
461
462 return json_decode( $cache['value'] );
463
464 }
465
466 public function set_version_info_cache( $value = '', $cache_key = '' ) {
467
468 if( empty( $cache_key ) ) {
469 $cache_key = $this->cache_key;
470 }
471
472 $data = array(
473 'timeout' => strtotime( '+3 hours', current_time( 'timestamp' ) ),
474 'value' => json_encode( $value )
475 );
476
477 update_option( $cache_key, $data );
478
479 }
480
481 /**
482 * Returns if the SSL of the store should be verified.
483 *
484 * @since 1.6.13
485 * @return bool
486 */
487 private function verify_ssl() {
488 return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
489 }
490
491 }
492