PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.3
Advanced Ads – Ad Manager & AdSense v1.8.3
2.0.26 2.0.25 2.0.24 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 / admin / includes / class-licenses.php
advanced-ads / admin / includes Last commit date
class-ad-groups-list.php 9 years ago class-ad-type.php 9 years ago class-licenses.php 9 years ago class-menu.php 9 years ago class-meta-box.php 9 years ago class-notices.php 9 years ago class-options.php 9 years ago class-overview-widgets.php 9 years ago class-settings.php 9 years ago class-shortcode-creator.php 9 years ago notices.php 9 years ago shortcode-creator-l10n.php 10 years ago
class-licenses.php
506 lines
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 /**
5 * handle add-on licenses
6 */
7 class Advanced_Ads_Admin_Licenses {
8 /**
9 * Instance of this class.
10 *
11 * @var object
12 */
13 protected static $instance = null;
14
15 private function __construct() {
16 if ( ! defined( 'DOING_AJAX' ) ) {
17 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
18 add_action( 'load-plugins.php', array( $this, 'check_plugin_licenses' ) );
19 }
20
21 // todo: check if this is loaded late enough and all add-ons are registered already
22 add_filter( 'upgrader_pre_download', array( $this, 'addon_upgrade_filter' ), 10, 3 );
23 }
24
25 /**
26 * actions and filter available after all plugins are initialized
27 */
28 public function wp_plugins_loaded() {
29
30 // check for add-on updates
31 add_action( 'admin_init', array($this, 'add_on_updater'), 1 );
32 }
33
34 /**
35 * Return an instance of this class.
36 *
37 * @return object A single instance of this class.
38 */
39 public static function get_instance() {
40 // If the single instance hasn't been set, set it now.
41 if ( null == self::$instance ) {
42 self::$instance = new self;
43 }
44
45 return self::$instance;
46 }
47
48 /**
49 * initiate plugin checks
50 *
51 * @since 1.7.12
52 */
53 public function check_plugin_licenses(){
54
55 if( is_multisite() ){
56 return;
57 }
58
59 // gather all add-on plugin files
60 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
61 foreach( $add_ons as $_add_on ){
62
63 // check license status
64 if( $this->get_license_status( $_add_on['options_slug'] ) !== 'valid' ) {
65 // register warning
66 $plugin_file = plugin_basename( $_add_on['path'] );
67 add_action( 'after_plugin_row_' . $plugin_file, array( $this, 'add_plugin_list_license_notice'), 10, 3 );
68 }
69 }
70 }
71
72 /**
73 * add a row below add-ons with an invalid license on the plugin list
74 *
75 * @since 1.7.12
76 * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
77 * @param array $plugin_data An array of plugin data.
78 * @param string $status Status of the plugin. Defaults are 'All', 'Active',
79 * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
80 * 'Drop-ins', 'Search'.
81 * @todo make this work on multisite as well
82 */
83 public function add_plugin_list_license_notice( $plugin_file, $plugin_data, $status ){
84
85 echo '<tr class="advads-plugin-update-tr plugin-update-tr active"><td class="plugin-update colspanchange" colspan="3"><div class="update-message notice inline notice-warning notice-alt"><p>'
86 . sprintf( __( 'There might be a new version of %1$s. Please <strong>provide a valid license key</strong> in order to receive updates and support <a href="%2$s">on this page</a>.', 'advanced-ads' ), $plugin_data['Title'], admin_url( 'admin.php?page=advanced-ads-settings#top#licenses' ) )
87 . '</p></div></td></tr>';
88
89 }
90
91
92 /**
93 * save license key
94 *
95 * @since 1.2.0
96 * @param string $addon string with addon identifier
97 */
98 public function activate_license( $addon = '', $plugin_name = '', $options_slug = '', $license_key = '' ) {
99
100 if ( '' === $addon || '' === $plugin_name || '' === $options_slug ) {
101 return __( 'Error while trying to register the license. Please contact support.', 'advanced-ads' );
102 }
103
104 $license_key = esc_attr( trim( $license_key ) );
105 if ( '' == $license_key ) {
106 return __( 'Please enter a valid license key', 'advanced-ads' );
107 }
108
109 if ( has_filter( 'advanced_ads_license_'. $options_slug ) ) {
110 return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
111 }
112
113 $api_params = array(
114 'edd_action'=> 'activate_license',
115 'license' => $license_key,
116 'item_name' => urlencode( $plugin_name ),
117 'url' => home_url()
118 );
119 // Call the custom API.
120 $response = wp_remote_post( ADVADS_URL, array(
121 'timeout' => 15,
122 'sslverify' => false,
123 'body' => $api_params
124 ) );
125
126 if ( is_wp_error( $response ) ) {
127 $body = wp_remote_retrieve_body( $response );
128 if ( $body ){
129 return $body;
130 } else {
131 // return print_r($response, true);
132 return __( 'License couldn’t be activated. Please try again later.', 'advanced-ads' );
133 }
134 }
135
136 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
137 // save license status
138 update_option($options_slug . '-license-status', $license_data->license, false);
139 if( !empty( $license_data->expires ) ){
140 update_option($options_slug . '-license-expires', $license_data->expires, false);
141 }
142
143 // display activation problem
144 if( !empty( $license_data->error )) {
145 // user friendly texts for errors
146 $errors = array(
147 'license_not_activable' => __( 'This is the bundle license key.', 'advanced-ads' ),
148 'item_name_mismatch' => __( 'This is not the correct key for this add-on.', 'advanced-ads' ),
149 'no_activations_left' => __( 'There are no activations left.', 'advanced-ads' )
150 );
151 $error = isset( $errors[ $license_data->error ] ) ? $errors[ $license_data->error ] : $license_data->error;
152 if( 'expired' === $license_data->error ){
153 return 'ex';
154 } else {
155 if( isset($errors[ $license_data->error ] ) ) {
156 return $error;
157 } else {
158 return sprintf( __( 'License is invalid. Reason: %s', 'advanced-ads' ), $error);
159 }
160 }
161 } else {
162 // reset license_expires admin notification
163 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_expires' );
164 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_expired' );
165 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_invalid' );
166 // save license key
167 $licenses = $this->get_licenses();
168 $licenses[ $addon ] = $license_key;
169 $this->save_licenses( $licenses );
170 }
171
172 return 1;
173 }
174
175 /**
176 * check if a specific license key was already activated for the current page
177 *
178 * @since 1.6.17
179 * @return bool true if already activated
180 * @deprecated since version 1.7.2 because it only checks if a key is valid, not if the url registered with that key
181 */
182 public function check_license( $license_key = '', $plugin_name = '', $options_slug = '' ){
183
184 if ( has_filter( 'advanced_ads_license_'. $options_slug ) ) {
185 return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
186 }
187
188 $api_params = array(
189 'edd_action' => 'check_license',
190 'license' => $license_key,
191 'item_name' => urlencode( $plugin_name )
192 );
193 $response = wp_remote_get( add_query_arg( $api_params, ADVADS_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
194 if ( is_wp_error( $response ) ) {
195 return false;
196 }
197 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
198
199 // if this license is still valid
200 if( $license_data->license == 'valid' ) {
201 update_option($options_slug . '-license-expires', $license_data->expires, false);
202 update_option($options_slug . '-license-status', $license_data->license, false);
203
204 return true;
205 }
206 return false;
207 }
208
209 /**
210 * deactivate license key
211 *
212 * @since 1.6.11
213 * @param string $addon string with addon identifier
214 */
215 public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ) {
216
217 if ( '' === $addon || '' === $plugin_name || '' === $options_slug ) {
218 return __( 'Error while trying to disable the license. Please contact support.', 'advanced-ads' );
219 }
220
221 $licenses = $this->get_licenses();
222 $license_key = isset($licenses[$addon]) ? $licenses[$addon] : '';
223
224 if ( has_filter( 'advanced_ads_license_'. $options_slug ) ) {
225 return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
226 }
227
228 $api_params = array(
229 'edd_action' => 'deactivate_license',
230 'license' => $license_key,
231 'item_name' => urlencode( $plugin_name )
232 );
233 // Send the remote request
234 $response = wp_remote_post( ADVADS_URL, array(
235 'body' => $api_params,
236 'timeout' => 15,
237 'sslverify' => false,
238 ) );
239
240 if ( is_wp_error( $response ) ) {
241 $body = wp_remote_retrieve_body( $response );
242 if ( $body ){
243 return $body;
244 } else {
245 return __( 'License couldn’t be deactivated. Please try again later.', 'advanced-ads' );
246 }
247 }
248
249 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
250
251 // save license status
252
253 // remove data
254 if( 'deactivated' === $license_data->license ) {
255 delete_option( $options_slug . '-license-status' );
256 delete_option( $options_slug . '-license-expires' );
257 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'license_expires' );
258 } elseif( 'failed' === $license_data->license ) {
259 update_option($options_slug . '-license-expires', $license_data->expires, false);
260 update_option($options_slug . '-license-status', $license_data->license, false);
261 return 'ex';
262 } else {
263 return __( 'License couldn’t be deactivated. Please try again later.', 'advanced-ads' );
264 }
265
266 return 1;
267 }
268
269 /**
270 * get license keys for all add-ons
271 *
272 * @since 1.6.15
273 * @return arr $licenses licenses
274 */
275 public function get_licenses(){
276
277 $licenses = array();
278
279 if( is_multisite() ){
280 // if multisite, get option from main blog
281 global $current_site;
282 $licenses = get_blog_option( $current_site->blog_id, ADVADS_SLUG . '-licenses', array() );
283
284 } else {
285 $licenses = get_option( ADVADS_SLUG . '-licenses', array() );
286 }
287
288 return $licenses;
289 }
290
291 /**
292 * save license keys for all add-ons
293 *
294 * @since 1.7.2
295 * @return arr $licenses licenses
296 */
297 public function save_licenses( $licenses = array() ){
298
299 if( is_multisite() ){
300 // if multisite, get option from main blog
301 global $current_site;
302 update_blog_option( $current_site->blog_id, ADVADS_SLUG . '-licenses', $licenses );
303 } else {
304 update_option( ADVADS_SLUG . '-licenses', $licenses );
305 }
306 }
307
308 /**
309 * get license status of an add-on
310 *
311 * @since 1.6.15
312 * @param str $slug slug of the add-on
313 * @return str $status license status, e.g. "valid" or "invalid"
314 */
315 public function get_license_status( $slug = '' ){
316
317 $status = false;
318
319 if( is_multisite() ){
320 // if multisite, get option from main blog
321 global $current_site;
322 $status = get_blog_option( $current_site->blog_id, $slug . '-license-status', false);
323 } else {
324 $status = get_option( $slug . '-license-status', false);
325 }
326
327 return $status;
328 }
329
330 /**
331 * get license expired value of an add-on
332 *
333 * @since 1.6.15
334 * @param str $slug slug of the add-on
335 * @return str $date expiry date of an add-on
336 */
337 public function get_license_expires( $slug = '' ){
338
339 $date = false;
340
341 if( is_multisite() ){
342 // if multisite, get option from main blog
343 global $current_site;
344 $date = get_blog_option( $current_site->blog_id, $slug . '-license-expires', false);
345 } else {
346 $date = get_option( $slug . '-license-expires', false);
347 }
348
349 return $date;
350 }
351
352
353 /*
354 * add-on updater
355 *
356 * @since 1.5.7
357 */
358 public function add_on_updater(){
359
360 // ignore, if not main blog or is ajax
361 if( ( is_multisite() && ! is_main_site() ) ){
362 return;
363 }
364
365 /**
366 * list of registered add ons
367 * contains:
368 * name
369 * version
370 * path
371 * options_slug
372 * short option slug (=key)
373 */
374 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
375
376 if( $add_ons === array() ) {
377 return;
378 }
379
380 // load license keys
381 $licenses = get_option(ADVADS_SLUG . '-licenses', array());
382
383 foreach( $add_ons as $_add_on_key => $_add_on ){
384
385 // check if a license expired over time
386 $expiry_date = $this->get_license_expires( $_add_on['options_slug'] );
387 $now = time();
388 if( $expiry_date && 'lifetime' !== $expiry_date && strtotime( $expiry_date ) < $now ){
389 // remove license status
390 delete_option( $_add_on['options_slug'] . '-license-status' );
391 continue;
392 }
393
394 // check status
395 if( $this->get_license_status( $_add_on['options_slug'] ) !== 'valid' ) {
396 continue;
397 }
398
399 // retrieve our license key
400 $license_key = isset($licenses[$_add_on_key]) ? $licenses[$_add_on_key] : '';
401
402 // setup the updater
403 if( $license_key ){
404
405 // register filter to set EDD transient to 86,400 seconds (day) instead of 3,600 (hours)
406 $slug = basename( $_add_on['path'], '.php' );
407 $transient_key = md5( serialize( $slug . $license_key ) );
408
409 // add_filter( 'expiration_of_transient_' . $transient_key, array( $this, 'set_expiration_of_update_transient' ) );
410 add_filter( 'pre_update_option_' . $transient_key, array( $this, 'set_expiration_of_update_option' ) );
411
412 new EDD_SL_Plugin_Updater( ADVADS_URL, $_add_on['path'], array(
413 'version' => $_add_on['version'],
414 'license' => $license_key,
415 'item_name' => $_add_on['name'],
416 'author' => 'Thomas Maier'
417 )
418 );
419 }
420 }
421 }
422
423 /**
424 * set the expiration of the updater transient key to 1 day instead of 1 hour to prevent too many update checks
425 *
426 * @deprecated since version 1.7.14 – not using transient anymore, but option
427 */
428 public function set_expiration_of_update_transient( $expiration ){
429
430 return 86400;
431 }
432
433 /**
434 * set the expiration of the updater transient key to 1 day instead of 1 hour to prevent too many update checks
435 *
436 * @since 1.7.14
437 */
438 public function set_expiration_of_update_option( $value ){
439
440 $value['timeout'] = time() + 86400;
441
442 return $value;
443 }
444
445 /**
446 * add custom messages to plugin updater
447 *
448 * @param type $reply
449 * @param type $package
450 * @param type $updater
451 * @return type
452 */
453 public function addon_upgrade_filter( $reply, $package, $updater ) {
454
455 if( isset( $updater->skin->plugin ) ){
456 $plugin_file = $updater->skin->plugin;
457 } elseif ( isset( $updater->skin->plugin_info['Name'] ) ){
458 $add_on = $this->get_installed_add_on_by_name( $updater->skin->plugin_info['Name'] );
459 $plugin_file = plugin_basename( $add_on['path'] );
460 }
461
462 if( isset( $plugin_file ) && $plugin_file ){
463 // hides the download url, but makes debugging harder
464 // $updater->strings['downloading_package'] = __( 'Downloading updated version...', 'advanced-ads' );
465 //$updater->skin->feedback( 'downloading_package' );
466
467 // if AJAX; show direct update link as first possible solution
468 if( defined( 'DOING_AJAX' ) ){
469 $update_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $plugin_file, 'upgrade-plugin_' . $plugin_file );
470 $updater->strings['download_failed'] = sprintf(__( 'Download failed. <a href="%s">Click here to try another method</a>.', 'advanced-ads' ), $update_link );
471 } else {
472 $updater->strings['download_failed'] = sprintf(__( 'Download failed. <a href="%s" target="_blank">Click here to learn why</a>.', 'advanced-ads' ), ADVADS_URL . 'manual/download-failed-updating-add-ons/#utm_source=advanced-ads&utm_medium=link&utm_campaign=download-failed' );
473 }
474
475 }
476
477 /*$res = $updater->fs_connect( array( WP_CONTENT_DIR ) );
478 if ( ! $res ) {
479 return new WP_Error( 'no_credentials', __( "Error! Can't connect to filesystem", 'advanced-ads' ) );
480 }*/
481
482 return $reply;
483 }
484
485 /**
486 * search if a name is in the add-on array and return the add-on data of it
487 *
488 * @param str $name name of an add-on
489 * @return arr array with the add-on data
490 */
491 private function get_installed_add_on_by_name( $name = '' ){
492
493 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
494
495 if( is_array( $add_ons ) ) {
496 foreach ( $add_ons as $key => $_add_on ) {
497 if ($_add_on['name'] === $name ) {
498 return $_add_on;
499 }
500 }
501 }
502 return null;
503 }
504
505
506 }