PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.6.7
Advanced Ads – Ad Manager & AdSense v1.6.7
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 / plugin.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 11 years ago ad-ajax.php 10 years ago ad-model.php 11 years ago ad-select.php 11 years ago ad.php 10 years ago ad_ajax_callbacks.php 11 years ago ad_group.php 10 years ago ad_placements.php 10 years ago ad_type_abstract.php 11 years ago ad_type_content.php 11 years ago ad_type_plain.php 10 years ago plugin.php 10 years ago visitor-conditions.php 10 years ago widget.php 10 years ago
plugin.php
550 lines
1 <?php
2
3 /**
4 * Wordpress integration and definitions:
5 *
6 * - posttypes
7 * - taxonomy
8 * - textdomain
9 *
10 * @since 1.5.0
11 */
12 class Advanced_Ads_Plugin {
13
14 /**
15 *
16 * @var Advanced_Ads_Plugin
17 */
18 protected static $instance;
19
20 /**
21 *
22 * @var Advanced_Ads_Model
23 */
24 protected $model;
25
26 /**
27 * plugin options
28 *
29 * @since 1.0.1
30 * @var array (if loaded)
31 */
32 protected $options;
33
34 /**
35 * interal plugin options – set by the plugin
36 *
37 * @since 1.4.5
38 * @var array (if loaded)
39 */
40 protected $internal_options;
41
42 private function __construct() {
43 register_activation_hook( dirname( __FILE__ ), array( $this, 'activate' ) );
44 register_deactivation_hook( dirname( __FILE__ ), array( $this, 'deactivate' ) );
45
46 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
47 }
48
49 /**
50 *
51 * @return Advanced_Ads_Plugin
52 */
53 public static function get_instance() {
54 // If the single instance hasn't been set, set it now.
55 if ( null === self::$instance ) {
56 self::$instance = new self;
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 *
64 * @param Advanced_Ads_Model $model
65 */
66 public function set_model(Advanced_Ads_Model $model) {
67 $this->model = $model;
68 }
69
70 public function wp_plugins_loaded() {
71 // Load plugin text domain
72 $this->load_plugin_textdomain();
73
74 // activate plugin when new blog is added on multisites // -TODO this is admin-only
75 add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
76
77 // Load public-facing style sheet and JavaScript.
78 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
79 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
80
81 // add short codes
82 add_shortcode( 'the_ad', array( $this, 'shortcode_display_ad' ) );
83 add_shortcode( 'the_ad_group', array( $this, 'shortcode_display_ad_group' ) );
84 add_shortcode( 'the_ad_placement', array( $this, 'shortcode_display_ad_placement' ) );
85
86 // remove default ad group menu item // -TODO only for admin
87 add_action( 'admin_menu', array( $this, 'remove_taxonomy_menu_item' ) );
88 // load widgets
89 add_action( 'widgets_init', array( $this, 'widget_init' ) );
90
91 // update add-ons
92 add_action( 'admin_init', array($this, 'add_on_updater'), 1 );
93
94 }
95
96 /**
97 * Register and enqueue public-facing style sheet.
98 *
99 * @since 1.0.0
100 */
101 public function enqueue_styles() {
102 // wp_enqueue_style( $this->get_plugin_slug() . '-plugin-styles', plugins_url('assets/css/public.css', __FILE__), array(), ADVADS_VERSION);
103 }
104
105 /**
106 * Return the plugin slug.
107 *
108 * @since 1.0.0
109 * @return Plugin slug variable.
110 */
111 public function get_plugin_slug() {
112 return ADVADS_SLUG;
113 }
114
115 /**
116 * Register and enqueues public-facing JavaScript files.
117 *
118 * @since 1.0.0
119 */
120 public function enqueue_scripts() {
121 // wp_enqueue_script( $this->get_plugin_slug() . '-plugin-script', plugins_url('assets/js/public.js', __FILE__), array('jquery'), ADVADS_VERSION);
122 $options = $this->options();
123 $activated_js = apply_filters( 'advanced-ads-activate-advanced-js', isset( $options['advanced-js'] ) );
124 if ( $activated_js ){
125 wp_enqueue_script( $this->get_plugin_slug() . '-advanced-js', ADVADS_BASE_URL . 'public/assets/js/advanced.js', array( 'jquery' ), ADVADS_VERSION );
126 }
127 }
128
129 public function widget_init() {
130 register_widget( 'Advanced_Ads_Widget' );
131 }
132
133 /**
134 * Fired when a new site is activated with a WPMU environment.
135 *
136 * @since 1.0.0
137 * @param int $blog_id ID of the new blog.
138 */
139 public function activate_new_site($blog_id) {
140
141 if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
142 return;
143 }
144
145 switch_to_blog( $blog_id );
146 $this->single_activate();
147 restore_current_blog();
148 }
149
150 /**
151 * Fired for each blog when the plugin is activated.
152 *
153 * @since 1.0.0
154 */
155 protected function single_activate() {
156 $this->post_types_rewrite_flush();
157 // -TODO inform modules
158 }
159
160 /**
161 * Fired for each blog when the plugin is deactivated.
162 *
163 * @since 1.0.0
164 */
165 protected function single_deactivate() {
166 // -TODO inform modules
167 }
168
169 /**
170 * Load the plugin text domain for translation.
171 *
172 * @since 1.0.0
173 */
174 public function load_plugin_textdomain() {
175 // $locale = apply_filters('advanced-ads-plugin-locale', get_locale(), $domain);
176 load_plugin_textdomain( ADVADS_SLUG, false, ADVADS_BASE_DIR . '/languages' );
177 }
178
179 /**
180 * Fired when the plugin is activated.
181 *
182 * @since 1.0.0
183 * @param boolean $network_wide True if WPMU superadmin uses
184 * "Network Activate" action, false if
185 * WPMU is disabled or plugin is
186 * activated on an individual blog.
187 */
188 public function activate($network_wide) {
189
190 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
191
192 if ( $network_wide ) {
193
194 // Get all blog ids
195 $blog_ids = $this->model->get_blog_ids();
196
197 foreach ( $blog_ids as $blog_id ) {
198
199 switch_to_blog( $blog_id );
200 $this->single_activate();
201 }
202
203 restore_current_blog();
204 } else {
205 $this->single_activate();
206 }
207 } else {
208 $this->single_activate();
209 }
210 }
211
212 /**
213 * Fired when the plugin is deactivated.
214 *
215 * @since 1.0.0
216 * @param boolean $network_wide
217 *
218 * True if WPMU superadmin uses
219 * "Network Deactivate" action, false if
220 * WPMU is disabled or plugin is
221 * deactivated on an individual blog.
222 */
223 public function deactivate($network_wide) {
224
225 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
226
227 if ( $network_wide ) {
228
229 // Get all blog ids
230 $blog_ids = $this->model->get_blog_ids();
231
232 foreach ( $blog_ids as $blog_id ) {
233
234 switch_to_blog( $blog_id );
235 $this->single_deactivate();
236 }
237
238 restore_current_blog();
239 } else {
240 $this->single_deactivate();
241 }
242 } else {
243 $this->single_deactivate();
244 }
245 }
246
247 /**
248 * flush rewrites on plugin activation so permalinks for them work from the beginning on
249 *
250 * @since 1.0.0
251 * @link http://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation
252 */
253 public function post_types_rewrite_flush(){
254 // load custom post type
255 Advanced_Ads::get_instance()->create_post_types();
256 // flush rewrite rules
257 flush_rewrite_rules();
258 }
259
260 /**
261 * remove WP tag edit page for the ad group taxonomy
262 * needed, because we can’t remove it with `show_ui` without also removing the meta box
263 *
264 * @since 1.0.0
265 */
266 public function remove_taxonomy_menu_item() {
267 remove_submenu_page( 'edit.php?post_type=advanced_ads', 'edit-tags.php?taxonomy=advanced_ads_groups&amp;post_type=advanced_ads' );
268 }
269
270 /**
271 * shortcode to include ad in frontend
272 *
273 * @since 1.0.0
274 * @param arr $atts
275 */
276 public function shortcode_display_ad($atts){
277 $id = isset($atts['id']) ? (int) $atts['id'] : 0;
278
279 // use the public available function here
280 return get_ad( $id );
281 }
282
283 /**
284 * shortcode to include ad from an ad group in frontend
285 *
286 * @since 1.0.0
287 * @param arr $atts
288 */
289 public function shortcode_display_ad_group($atts){
290 $id = isset($atts['id']) ? (int) $atts['id'] : 0;
291
292 // use the public available function here
293 return get_ad_group( $id );
294 }
295
296 /**
297 * shortcode to display content of an ad placement in frontend
298 *
299 * @since 1.1.0
300 * @param arr $atts
301 */
302 public function shortcode_display_ad_placement($atts){
303 $id = isset($atts['id']) ? (string) $atts['id'] : '';
304
305 // use the public available function here
306 return get_ad_placement( $id );
307 }
308
309 /**
310 * return plugin options
311 * these are the options updated by the user
312 *
313 * @since 1.0.1
314 * @return array $options
315 * @todo parse default options
316 */
317 public function options() {
318 if ( ! isset( $this->options ) ) {
319 $this->options = get_option( ADVADS_SLUG, array() );
320 }
321
322 return $this->options;
323 }
324
325 /**
326 * update plugin options (not for settings page, but if automatic options are needed)
327 *
328 * @since 1.5.1
329 * @param array $options new options
330 */
331 public function update_options( array $options ) {
332 // do not allow to clear options
333 if ( $options === array() ) {
334 return;
335 }
336
337 $this->options = $options;
338 update_option( ADVADS_SLUG, $options );
339 }
340
341 /**
342 * return internal plugin options
343 * these are options set by the plugin
344 *
345 * @since 1.0.1
346 * @return array $options
347 * @todo parse default options
348 */
349 public function internal_options() {
350 if ( ! isset( $this->internal_options ) ) {
351 $defaults = array(
352 'version' => ADVADS_VERSION,
353 'installed' => time(), // when was this installed
354 );
355 $this->internal_options = get_option( ADVADS_SLUG . '-internal', array() );
356
357 // save defaults
358 if($this->internal_options === array()){
359 $this->internal_options = $defaults;
360 $this->update_internal_options($this->internal_options);
361 }
362
363 // for versions installed prior to 1.5.3 set installed date for now
364 if( ! isset( $this->internal_options['installed'] )){
365 $this->internal_options['installed'] = time();
366 $this->update_internal_options($this->internal_options);
367 }
368 }
369
370 return $this->internal_options;
371 }
372
373 /**
374 * update internal plugin options
375 *
376 * @since 1.5.1
377 * @param array $options new internal options
378 */
379 public function update_internal_options( array $options ) {
380 // do not allow to clear options
381 if ( $options === array() ) {
382 return;
383 }
384
385 $this->internal_options = $options;
386 update_option( ADVADS_SLUG . '-internal', $options );
387 }
388
389 /*
390 * add-on updater
391 *
392 * @since 1.5.7
393 *
394 */
395 public function add_on_updater(){
396
397 /**
398 * list of registered add ons
399 * contains:
400 * name
401 * version
402 * path
403 * options_slug
404 * short option slug (=key)
405 */
406 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
407
408 if( $add_ons === array() ) {
409 return;
410 }
411
412 foreach( $add_ons as $_add_on_key => $_add_on ){
413
414 // check if a license expired over time
415 $expiry_date = get_option($_add_on['options_slug'] . '-license-expires', false);
416 $now = time();
417 if( $expiry_date && strtotime( $expiry_date ) < $now ){
418 // remove license status
419 delete_option( $_add_on['options_slug'] . '-license-status' );
420 continue;
421 }
422
423 // check status
424 if( get_option($_add_on['options_slug'] . '-license-status', false) !== 'valid' ) {
425 continue;
426 }
427
428 // retrieve our license key from the DB
429 $licenses = get_option(ADVADS_SLUG . '-licenses', array());
430 $license_key = isset($licenses[$_add_on_key]) ? $licenses[$_add_on_key] : '';
431
432 // setup the updater
433 if( $license_key ){
434 new EDD_SL_Plugin_Updater( ADVADS_URL, $_add_on['path'], array(
435 'version' => $_add_on['version'],
436 'license' => $license_key,
437 'item_name' => $_add_on['name'],
438 'author' => 'Thomas Maier'
439 )
440 );
441 }
442 }
443 }
444
445 /**
446 * check if license keys are missing or invalid
447 *
448 * @since 1.6.6
449 * @return true if there are missing licenses
450 */
451 static function check_licenses_invalid(){
452
453 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
454
455 if( $add_ons === array() ) {
456 return false;
457 }
458
459 foreach( $add_ons as $_add_on_key => $_add_on ){
460 $status = get_option($_add_on['options_slug'] . '-license-status', false);
461
462 // don’t check if license is valid
463 if( $status === 'valid' ) {
464 continue;
465 }
466
467 // retrieve our license key from the DB
468 $licenses = get_option(ADVADS_SLUG . '-licenses', array());
469
470 $license_key = isset($licenses[$_add_on_key]) ? $licenses[$_add_on_key] : false;
471
472 if( ! $license_key || $status !== 'valid' ){
473 return true;
474 }
475 }
476
477 return false;
478 }
479
480 /**
481 * check if license keys are going to expire within next 14 days
482 *
483 * @since 1.6.6
484 * @return true if there are expiring licenses
485 */
486 static function check_licenses_expire(){
487
488 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
489
490 if( $add_ons === array() ) {
491 return false;
492 }
493
494 $now = time();
495
496 foreach( $add_ons as $_add_on_key => $_add_on ){
497 // don’t display error for invalid licenses
498 if( get_option($_add_on['options_slug'] . '-license-status', false) === 'invalid' ) {
499 continue;
500 }
501
502 $expiry_date = get_option($_add_on['options_slug'] . '-license-expires', false);
503
504 if( $expiry_date ){
505 $expiry_date_t = strtotime( $expiry_date );
506 $in_two_weeks = time() + ( WEEK_IN_SECONDS * 2) ;
507 // check if expiry date is within next comming 2 weeks
508 if( $expiry_date_t < $in_two_weeks && $expiry_date_t >= $now ){
509 return true;
510 }
511
512 }
513 }
514
515 return false;
516 }
517
518 /**
519 * check if license keys are already expired
520 *
521 * @since 1.6.6
522 * @return true if there are expired licenses
523 */
524 static function check_licenses_expired(){
525
526 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
527
528 if( $add_ons === array() ) {
529 return false;
530 }
531
532 $now = time();
533
534 foreach( $add_ons as $_add_on_key => $_add_on ){
535 // don’t display error for invalid licenses
536 if( get_option($_add_on['options_slug'] . '-license-status', false) === 'invalid' ) {
537 continue;
538 }
539
540 $expiry_date = get_option($_add_on['options_slug'] . '-license-expires', false);
541
542 if( $expiry_date && strtotime( $expiry_date ) < $now ){
543 return true;
544 }
545 }
546
547 return false;
548 }
549 }
550