Popups – WordPress Popup - Version 1.9.3.7

Version Description

  • Cookies in days/hours
  • Fix popup showing in search results
  • Fixed issue to make it compatible with WP3.6
  • Fixed iframes to work not only with youtube/vimeo
Download this release

Release Info

Developer timersys
Plugin Icon 128x128 Popups – WordPress Popup
Version 1.9.3.7
Comparing to
See all releases

Code changes from version 1.9.3.6 to 1.9.3.7

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: popup,twitter,google+,facebook,Popups,twitter follow,facebook like,mailchimp,Activecampaign,Mailpoet,Postmatic,Infusionsoft,mailerlite,constant contact,aweber,google plus,social boost,social splash,postmatic,mailpoet,facebook popup,scroll popups,popups,wordpress popup,wp popups,cf7,gf,gravity forms,contact form 7,ifs,infusion soft,subscribe,login popup,ajax login popups,popupmaker
5
  Requires at least: 3.6
6
  Tested up to: 5.1.1
7
- Stable tag: 1.9.3.6
8
  Requires PHP: 5.3
9
  Text Domain: popups
10
  License: GPLv2 or later
@@ -185,6 +185,12 @@ If you have cache be sure to enable AJAX mode in the plugin settings page
185
 
186
  == Changelog ==
187
 
 
 
 
 
 
 
188
  = 1.9.3.6 =
189
  * Disable Gutenberg entirely for popups premium full support
190
  * Added slovak language
4
  Tags: popup,twitter,google+,facebook,Popups,twitter follow,facebook like,mailchimp,Activecampaign,Mailpoet,Postmatic,Infusionsoft,mailerlite,constant contact,aweber,google plus,social boost,social splash,postmatic,mailpoet,facebook popup,scroll popups,popups,wordpress popup,wp popups,cf7,gf,gravity forms,contact form 7,ifs,infusion soft,subscribe,login popup,ajax login popups,popupmaker
5
  Requires at least: 3.6
6
  Tested up to: 5.1.1
7
+ Stable tag: 1.9.3.7
8
  Requires PHP: 5.3
9
  Text Domain: popups
10
  License: GPLv2 or later
185
 
186
  == Changelog ==
187
 
188
+ = 1.9.3.7 =
189
+ * Cookies in days/hours
190
+ * Fix popup showing in search results
191
+ * Fixed issue to make it compatible with WP3.6
192
+ * Fixed iframes to work not only with youtube/vimeo
193
+
194
  = 1.9.3.6 =
195
  * Disable Gutenberg entirely for popups premium full support
196
  * Added slovak language
admin/class-social-popup-admin.php CHANGED
@@ -94,7 +94,7 @@ class SocialPopup_Admin {
94
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
95
 
96
  //Save metaboxes
97
- add_action( 'save_post_spucpt', array( $this, 'save_meta_options' ), 20 );
98
 
99
  // Load admin style sheet and JavaScript.
100
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
@@ -377,9 +377,12 @@ class SocialPopup_Admin {
377
  *
378
  * @return mixed
379
  */
380
- public function save_meta_options( $post_id ) {
381
  static $spu_save = 0;
382
 
 
 
 
383
  // For some reason sometimes this hook run twice, until I can find the reason and reproduce error
384
  // let's use a static var to prevent this
385
  if( $spu_save > 0 )
@@ -443,6 +446,8 @@ class SocialPopup_Admin {
443
 
444
  $opts['name-convert-cookie'] = sanitize_text_field( $opts['name-convert-cookie'] ) ;
445
  $opts['name-close-cookie'] = sanitize_text_field( $opts['name-close-cookie'] );
 
 
446
  $opts['duration-convert-cookie'] = absint( sanitize_text_field( $opts['duration-convert-cookie'] ) );
447
  $opts['duration-close-cookie'] = absint( sanitize_text_field( $opts['duration-close-cookie'] ) );
448
  // add popup ID to make the unique
94
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
95
 
96
  //Save metaboxes
97
+ add_action( 'save_post', array( $this, 'save_meta_options' ), 20, 2 );
98
 
99
  // Load admin style sheet and JavaScript.
100
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
377
  *
378
  * @return mixed
379
  */
380
+ public function save_meta_options( $post_id, $post ) {
381
  static $spu_save = 0;
382
 
383
+ if ( $post->post_type != 'spucpt' )
384
+ return $post_id;
385
+
386
  // For some reason sometimes this hook run twice, until I can find the reason and reproduce error
387
  // let's use a static var to prevent this
388
  if( $spu_save > 0 )
446
 
447
  $opts['name-convert-cookie'] = sanitize_text_field( $opts['name-convert-cookie'] ) ;
448
  $opts['name-close-cookie'] = sanitize_text_field( $opts['name-close-cookie'] );
449
+ $opts['type-convert-cookie'] = sanitize_text_field( $opts['type-convert-cookie'] ) ;
450
+ $opts['type-close-cookie'] = sanitize_text_field( $opts['type-close-cookie'] );
451
  $opts['duration-convert-cookie'] = absint( sanitize_text_field( $opts['duration-convert-cookie'] ) );
452
  $opts['duration-close-cookie'] = absint( sanitize_text_field( $opts['duration-close-cookie'] ) );
453
  // add popup ID to make the unique
admin/views/metaboxes/metabox-options.php CHANGED
@@ -64,7 +64,11 @@ if ( !defined( 'ABSPATH' ) ) exit;?>
64
  <th><label for="spu_duration_conversion_cookie"><?php _e( 'Conversion cookie Duration', 'popups' ); ?></label></th>
65
  <td colspan="3">
66
  <input type="number" id="spu_duration_conversion_cookie" name="spu[duration-convert-cookie]" min="0" value="<?php echo esc_attr($opts['duration-convert-cookie']); ?>" />
67
- <p class="help"><?php _e( 'When a user do a conversion like for example a click or form submission, how many days should it stay hidden?', 'popups' ); ?></p>
 
 
 
 
68
  </td>
69
  </tr>
70
  <tr valign="top">
@@ -78,7 +82,11 @@ if ( !defined( 'ABSPATH' ) ) exit;?>
78
  <th><label for="spu_duration_close_cookie"><?php _e( 'Closing cookie duration', 'popups' ); ?></label></th>
79
  <td colspan="3">
80
  <input type="number" id="spu_duration_close_cookie" name="spu[duration-close-cookie]" min="0" value="<?php echo isset( $opts['duration-close-cookie'] ) ? esc_attr($opts['duration-close-cookie']) : esc_attr($opts['duration-convert-cookie']); ?>" />
81
- <p class="help"><?php _e( 'After closing the popup, how many days should it stay hidden?', 'popups' ); ?></p>
 
 
 
 
82
  </td>
83
  </tr>
84
  <?php do_action( 'spu/metaboxes/after_cookie_options', $opts );?>
64
  <th><label for="spu_duration_conversion_cookie"><?php _e( 'Conversion cookie Duration', 'popups' ); ?></label></th>
65
  <td colspan="3">
66
  <input type="number" id="spu_duration_conversion_cookie" name="spu[duration-convert-cookie]" min="0" value="<?php echo esc_attr($opts['duration-convert-cookie']); ?>" />
67
+ <select name="spu[type-convert-cookie]">
68
+ <option value="h" <?php selected(esc_attr($opts['type-convert-cookie']),'h'); ?>><?php _e('Hours','popups'); ?></option>
69
+ <option value="d" <?php selected(esc_attr($opts['type-convert-cookie']),'d'); ?>><?php _e('Days','popups'); ?></option>
70
+ </select>
71
+ <p class="help"><?php _e( 'When a user do a conversion like for example a click or form submission, how many days/hours should it stay hidden?', 'popups' ); ?></p>
72
  </td>
73
  </tr>
74
  <tr valign="top">
82
  <th><label for="spu_duration_close_cookie"><?php _e( 'Closing cookie duration', 'popups' ); ?></label></th>
83
  <td colspan="3">
84
  <input type="number" id="spu_duration_close_cookie" name="spu[duration-close-cookie]" min="0" value="<?php echo isset( $opts['duration-close-cookie'] ) ? esc_attr($opts['duration-close-cookie']) : esc_attr($opts['duration-convert-cookie']); ?>" />
85
+ <select name="spu[type-close-cookie]">
86
+ <option value="h" <?php selected(esc_attr($opts['type-close-cookie']),'h'); ?>><?php _e('Hours','popups'); ?></option>
87
+ <option value="d" <?php selected(esc_attr($opts['type-close-cookie']),'d'); ?>><?php _e('Days','popups'); ?></option>
88
+ </select>
89
+ <p class="help"><?php _e( 'After closing the popup, how many days/hours should it stay hidden?', 'popups' ); ?></p>
90
  </td>
91
  </tr>
92
  <?php do_action( 'spu/metaboxes/after_cookie_options', $opts );?>
includes/class-spu-helper.php CHANGED
@@ -454,17 +454,19 @@ class Spu_Helper {
454
  'close_shadow_color'=> '#fff',
455
  'position' => 'centered',
456
  ),
457
- 'trigger' => 'seconds',
458
- 'trigger_number' => '5',
459
- 'animation' => 'fade',
460
- 'duration-convert-cookie' => '999',
461
- 'duration-close-cookie' => '30',
462
- 'name-convert-cookie' => 'spu_conversion',
463
- 'name-close-cookie' => 'spu_closing',
464
- 'auto_hide' => 0,
465
- 'test_mode' => 0,
466
- 'conversion_close' => '1',
467
- 'powered_link' => '0',
 
 
468
  );
469
 
470
  $opts = apply_filters( 'spu/metaboxes/box_options', get_post_meta( $id, 'spu_options', true ), $id );
454
  'close_shadow_color'=> '#fff',
455
  'position' => 'centered',
456
  ),
457
+ 'trigger' => 'seconds',
458
+ 'trigger_number' => '5',
459
+ 'animation' => 'fade',
460
+ 'duration-convert-cookie' => '999',
461
+ 'type-convert-cookie' => 'd',
462
+ 'duration-close-cookie' => '30',
463
+ 'type-close-cookie' => 'd',
464
+ 'name-convert-cookie' => 'spu_conversion',
465
+ 'name-close-cookie' => 'spu_closing',
466
+ 'auto_hide' => 0,
467
+ 'test_mode' => 0,
468
+ 'conversion_close' => '1',
469
+ 'powered_link' => '0',
470
  );
471
 
472
  $opts = apply_filters( 'spu/metaboxes/box_options', get_post_meta( $id, 'spu_options', true ), $id );
languages/{popups-fr_FR%20.po → popups-fr_FR .po} RENAMED
File without changes
popups.php CHANGED
@@ -11,7 +11,7 @@
11
  * @socialpopup
12
  * Plugin Name: Popups - WordPress Popup
13
  * Plugin URI: http://www.timersys.com/free-plugins/social-popup/
14
- * Version: 1.9.3.6
15
  * Description: Most complete free Popups plugin, scroll triggered popups, compatible with social networks, Gravity Forms, Ninja Forms, Contact form 7, Mailpoet, Mailchimp for WP, Postmatic, etc
16
  * Author: timersys
17
  * Author URI: https://timersys.com
11
  * @socialpopup
12
  * Plugin Name: Popups - WordPress Popup
13
  * Plugin URI: http://www.timersys.com/free-plugins/social-popup/
14
+ * Version: 1.9.3.7
15
  * Description: Most complete free Popups plugin, scroll triggered popups, compatible with social networks, Gravity Forms, Ninja Forms, Contact form 7, Mailpoet, Mailchimp for WP, Postmatic, etc
16
  * Author: timersys
17
  * Author URI: https://timersys.com
public/assets/js/public.js CHANGED
@@ -51,7 +51,7 @@ var SPU_master = function() {
51
  facebookFix( $box );
52
 
53
  // search for youtube, vimeo videos
54
- var iframe = $box.find('iframe[src*="vimeo"],iframe[src*="youtube"],iframe[src*="youtu.be"]');
55
  if( iframe && iframe.length) {
56
  iframe.each(function () {
57
  $(this).attr('spusrc',$(this).attr('src'));
@@ -498,17 +498,18 @@ var SPU_master = function() {
498
  //if we are closing , set cookie
499
  if( show === false) {
500
  // set cookie
501
- //var days = parseFloat( $box.data('close-cookie') );
502
- var days = parseFloat( $box.data('dclose-cookie') );
503
  var ncookie = $box.data('nclose-cookie');
504
 
505
  if( conversion === true ) {
506
- days = parseFloat( $box.data('dconvert-cookie') );
 
507
  ncookie = $box.data('nconvert-cookie');
508
  }
509
 
510
- if( days > 0 ) {
511
- spuCreateCookie( ncookie, true, days );
512
  }
513
  $box.trigger('spu.box_close', [id]);
514
  // check for videos inside and destroy it
@@ -675,10 +676,15 @@ if( spuvar.ajax_mode ) {
675
  /**
676
  * Cookie functions
677
  */
678
- function spuCreateCookie(name, value, days) {
679
- if (days) {
680
  var date = new Date();
681
- date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
 
 
 
 
 
682
  var expires = "; expires=" + date.toGMTString();
683
  } else var expires = "";
684
  document.cookie = name + "=" + value + expires + "; path=/";
51
  facebookFix( $box );
52
 
53
  // search for youtube, vimeo videos
54
+ var iframe = $box.find('iframe');
55
  if( iframe && iframe.length) {
56
  iframe.each(function () {
57
  $(this).attr('spusrc',$(this).attr('src'));
498
  //if we are closing , set cookie
499
  if( show === false) {
500
  // set cookie
501
+ var tcookie = $box.data('tclose-cookie');
502
+ var dcookie = parseFloat( $box.data('dclose-cookie') );
503
  var ncookie = $box.data('nclose-cookie');
504
 
505
  if( conversion === true ) {
506
+ tcookie = $box.data('tconvert-cookie');
507
+ dcookie = parseFloat( $box.data('dconvert-cookie') );
508
  ncookie = $box.data('nconvert-cookie');
509
  }
510
 
511
+ if( dcookie > 0 ) {
512
+ spuCreateCookie( ncookie, true, tcookie, dcookie );
513
  }
514
  $box.trigger('spu.box_close', [id]);
515
  // check for videos inside and destroy it
676
  /**
677
  * Cookie functions
678
  */
679
+ function spuCreateCookie(name, value, type, duration) {
680
+ if (duration) {
681
  var date = new Date();
682
+
683
+ if( type == 'h' )
684
+ date.setTime(date.getTime() + (duration * 60 * 60 * 1000));
685
+ else
686
+ date.setTime(date.getTime() + (duration * 24 * 60 * 60 * 1000));
687
+
688
  var expires = "; expires=" + date.toGMTString();
689
  } else var expires = "";
690
  document.cookie = name + "=" + value + expires + "; path=/";
public/class-social-popup.php CHANGED
@@ -287,6 +287,7 @@ class SocialPopup {
287
  'show_ui' => true,
288
  'show_in_menu' => true,
289
  'query_var' => true,
 
290
  'rewrite' => array( 'slug' => 'spucpt' ),
291
  'capability_type' => 'post',
292
  'capabilities' => array(
287
  'show_ui' => true,
288
  'show_in_menu' => true,
289
  'query_var' => true,
290
+ 'exclude_from_search' => true,
291
  'rewrite' => array( 'slug' => 'spucpt' ),
292
  'capability_type' => 'post',
293
  'capabilities' => array(
public/includes/class-spu-rules.php CHANGED
@@ -1,1151 +1,1151 @@
1
- <?php
2
- use Jaybizzle\CrawlerDetect\CrawlerDetect;
3
- /*
4
- * Spu Rules
5
- * Class that will compare rules and determine if popup needs to show
6
- * @since: 2.0
7
- */
8
- class Spu_Rules
9
- {
10
- /**
11
- * post id used to check rules
12
- * @var int
13
- */
14
- protected $post_id;
15
-
16
- /**
17
- * referrer using in ajax calls
18
- * @var string
19
- */
20
- protected $referrer;
21
-
22
- /**
23
- * Is category using in ajax calls
24
- * @var boolean
25
- */
26
- protected $is_category = false;
27
-
28
- /**
29
- * Is archive using in ajax calls
30
- * @var boolean
31
- */
32
- protected $is_archive = false;
33
-
34
- /**
35
- * Is searchu sed in ajax calls
36
- * @var boolean
37
- */
38
- protected $is_search = false;
39
-
40
- /**
41
- * Holds current url
42
- * @var string
43
- */
44
- protected $current_url;
45
-
46
- /**
47
- * Holds query string
48
- * @var
49
- */
50
- protected $query_string;
51
-
52
- /*
53
- * __construct
54
- * Add all the filters to use later
55
- */
56
-
57
- function __construct()
58
- {
59
- global $post;
60
-
61
- // User
62
- add_filter('spu/rules/rule_match/user_type', array($this, 'rule_match_user_type'), 10, 2);
63
- add_filter('spu/rules/rule_match/logged_user', array($this, 'rule_match_logged_user'), 10, 2);
64
- add_filter('spu/rules/rule_match/left_comment', array($this, 'rule_match_left_comment'), 10, 2);
65
- add_filter('spu/rules/rule_match/search_engine', array($this, 'rule_match_search_engine'), 10, 2);
66
- add_filter('spu/rules/rule_match/same_site', array($this, 'rule_match_same_site'), 10, 2);
67
-
68
- // Post
69
- add_filter('spu/rules/rule_match/post_type', array($this, 'rule_match_post_type'), 10, 2);
70
- add_filter('spu/rules/rule_match/post_id', array($this, 'rule_match_post'), 10, 2);
71
- add_filter('spu/rules/rule_match/post', array($this, 'rule_match_post'), 10, 2);
72
- add_filter('spu/rules/rule_match/post_category', array($this, 'rule_match_post_category'), 10, 2);
73
- add_filter('spu/rules/rule_match/post_format', array($this, 'rule_match_post_format'), 10, 2);
74
- add_filter('spu/rules/rule_match/post_status', array($this, 'rule_match_post_status'), 10, 2);
75
- add_filter('spu/rules/rule_match/taxonomy', array($this, 'rule_match_taxonomy'), 10, 2);
76
-
77
- // Page
78
- add_filter('spu/rules/rule_match/page', array($this, 'rule_match_post'), 10, 2);
79
- add_filter('spu/rules/rule_match/page_type', array($this, 'rule_match_page_type'), 10, 2);
80
- add_filter('spu/rules/rule_match/page_parent', array($this, 'rule_match_page_parent'), 10, 2);
81
- add_filter('spu/rules/rule_match/page_template', array($this, 'rule_match_page_template'), 10, 2);
82
-
83
- //Other
84
- add_filter('spu/rules/rule_match/mobiles', array($this, 'rule_match_mobiles'), 10, 2);
85
- add_filter('spu/rules/rule_match/tablets', array($this, 'rule_match_tablets'), 10, 2);
86
- add_filter('spu/rules/rule_match/desktop', array($this, 'rule_match_desktop'), 10, 2);
87
- add_filter('spu/rules/rule_match/referrer', array($this, 'rule_match_referrer'), 10, 2);
88
- add_filter('spu/rules/rule_match/crawlers', array($this, 'rule_match_crawlers'), 10, 2);
89
- add_filter('spu/rules/rule_match/browser', array($this, 'rule_match_browser'), 10, 2);
90
- add_filter('spu/rules/rule_match/query_string', array($this, 'rule_match_query_string'), 10, 2);
91
- add_filter('spu/rules/rule_match/custom_url', array($this, 'rule_match_custom_url'), 10, 2);
92
- add_filter('spu/rules/rule_match/keyword_url', array($this, 'rule_match_keyword_url'), 10, 2);
93
-
94
- $this->post_id = get_queried_object_id();
95
- $this->referrer = isset($_SERVER['HTTP_REFERER']) && !defined('DOING_AJAX') ? $_SERVER['HTTP_REFERER'] : '';
96
- $this->query_string = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
97
- $this->current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
98
-
99
-
100
- if( defined('DOING_AJAX') ) {
101
-
102
- if( isset( $_REQUEST['pid'] ) ) {
103
- $this->post_id = $_REQUEST['pid'];
104
- }
105
- if( !empty( $_REQUEST['referrer'] ) ) {
106
- $this->referrer = $_REQUEST['referrer'];
107
- }
108
- if( !empty( $_REQUEST['current_url'] ) ) {
109
- $this->current_url = $_REQUEST['current_url'];
110
- }
111
- if( !empty( $_REQUEST['query_string'] ) ) {
112
- $this->query_string = $_REQUEST['query_string'];
113
- }
114
- if( !empty( $_REQUEST['is_category'] ) ) {
115
- $this->is_category = true;
116
- }
117
- if( !empty( $_REQUEST['is_archive'] ) ) {
118
- $this->is_archive = true;
119
- }
120
- if( !empty( $_REQUEST['is_search'] ) ) {
121
- $this->is_search = true;
122
- }
123
- }
124
-
125
- }
126
-
127
-
128
- /*
129
- * check_rules
130
- *
131
- * @since 1.0.0
132
- */
133
-
134
- function check_rules( $rules = '' )
135
- {
136
-
137
- //if no rules, add the box
138
- $add_box = true;
139
-
140
- if( !empty( $rules ) ) {
141
- // vars
142
- $add_box = false;
143
-
144
-
145
- foreach( $rules as $group_id => $group ) {
146
- // start of as true, this way, any rule that doesn't match will cause this varaible to false
147
- $match_group = true;
148
-
149
- if( is_array($group) )
150
- {
151
-
152
- foreach( $group as $rule_id => $rule )
153
- {
154
-
155
- // $match = true / false
156
- $match = apply_filters( 'spu/rules/rule_match/' . $rule['param'] , false, $rule );
157
-
158
- if( !$match )
159
- {
160
- $match_group = false;
161
- // if one rule fails we don't need to check the rest of the rules in the group
162
- // that way if we add geo rules down it won't get executed and will save credits
163
- break;
164
- }
165
-
166
- }
167
- }
168
-
169
-
170
- // all rules must havematched!
171
- if( $match_group )
172
- {
173
- $add_box = true;
174
- }
175
-
176
- }
177
-
178
-
179
- }
180
-
181
-
182
- return $add_box;
183
- }
184
-
185
- /**
186
- * [rule_match_logged_user description]
187
- * @param bool $match false default
188
- * @param array $rule rule to compare
189
- * @return boolean true if match
190
- */
191
- function rule_match_logged_user( $match, $rule ) {
192
-
193
- if ( $rule['operator'] == "==" ) {
194
-
195
- return is_user_logged_in();
196
-
197
- } else {
198
-
199
- return !is_user_logged_in();
200
-
201
- }
202
-
203
- }
204
-
205
- /**
206
- * [rule_match_mobiles description]
207
- * @param bool $match false default
208
- * @param array $rule rule to compare
209
- * @return boolean true if match
210
- */
211
- function rule_match_mobiles( $match, $rule ) {
212
-
213
- $detect = new Mobile_Detect;
214
-
215
- if ( $rule['operator'] == "==" ) {
216
-
217
- return $detect->isMobile();
218
-
219
- } else {
220
-
221
- return !$detect->isMobile();
222
-
223
- }
224
-
225
- }
226
- /**
227
- * [rule_match_browser description]
228
- * @param bool $match false default
229
- * @param array $rule rule to compare
230
- * @return boolean true if match
231
- */
232
- function rule_match_browser( $match, $rule ) {
233
-
234
- $detect = new Browser();
235
-
236
- //check $detect $browsers for valid keys
237
- if ( $rule['operator'] == "==" ) {
238
-
239
- return $detect->getBrowser() == $rule['value'];
240
-
241
- } else {
242
-
243
- return $detect->getBrowser() != $rule['value'];
244
-
245
- }
246
-
247
- }
248
- /**
249
- * [rule_match_tablets description]
250
- * @param bool $match false default
251
- * @param array $rule rule to compare
252
- * @return boolean true if match
253
- */
254
- function rule_match_tablets( $match, $rule ) {
255
-
256
- $detect = new Mobile_Detect;
257
-
258
- if ( $rule['operator'] == "==" ) {
259
-
260
- return $detect->isTablet();
261
-
262
- } else {
263
-
264
- return !$detect->isTablet();
265
-
266
- }
267
-
268
- }
269
- /**
270
- * [rule_match_desktop description]
271
- * @param bool $match false default
272
- * @param array $rule rule to compare
273
- * @return boolean true if match
274
- */
275
- function rule_match_desktop( $match, $rule ) {
276
-
277
- $detect = new Mobile_Detect;
278
-
279
- if ( $rule['operator'] == "==" ) {
280
-
281
- return ( ! $detect->isTablet() && ! $detect->isMobile() );
282
-
283
- } else {
284
-
285
- return ( $detect->isTablet() || $detect->isMobile() );
286
-
287
- }
288
-
289
- }
290
-
291
- /**
292
- * [rule_match_left_comment description]
293
- * @param bool $match false default
294
- * @param array $rule rule to compare
295
- * @return boolean true if match
296
- */
297
- function rule_match_left_comment( $match, $rule ) {
298
-
299
- if ( $rule['operator'] == "==" ) {
300
-
301
- return !empty( $_COOKIE['comment_author_'.COOKIEHASH] );
302
-
303
- } else {
304
-
305
- return empty( $_COOKIE['comment_author_'.COOKIEHASH] );
306
-
307
- }
308
-
309
- }
310
- /**
311
- * [rule_match_search_engine description]
312
- * @param bool $match false default
313
- * @param array $rule rule to compare
314
- * @return boolean true if match
315
- */
316
- function rule_match_search_engine( $match, $rule ) {
317
-
318
- $ref = $this->referrer;
319
-
320
- $SE = apply_filters( 'spu/rules/search_engines', array('/search?', '.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.', '.bing.' ) );
321
-
322
- foreach ($SE as $url) {
323
- if ( strpos( $ref,$url ) !==false ){
324
-
325
- return $rule['operator'] == "==" ? true : false;
326
- }
327
- }
328
-
329
- return $rule['operator'] == "==" ? false : true;
330
-
331
- }
332
-
333
- /**
334
- * Check for user referrer
335
- * @param bool $match false default
336
- * @param array $rule rule to compare
337
- * @return boolean true if match
338
- */
339
- function rule_match_referrer( $match, $rule ) {
340
-
341
- $ref = $this->referrer;
342
-
343
- if ( strpos( $ref,$rule['value'] ) !==false ){
344
- return $rule['operator'] == "==" ? true : false;
345
- }
346
-
347
- return $rule['operator'] == "==" ? false : true;
348
-
349
- }
350
-
351
- /**
352
- * Check for crawlers / bots
353
- * @param bool $match false default
354
- * @param array $rule rule to compare
355
- * @return boolean true if match
356
- */
357
- function rule_match_crawlers( $match, $rule ) {
358
-
359
- $detect = new CrawlerDetect;
360
-
361
- if ( $rule['operator'] == "==" ) {
362
-
363
- return $detect->isCrawler();
364
-
365
- } else {
366
-
367
- return !$detect->isCrawler();
368
-
369
- }
370
-
371
- }
372
-
373
- /**
374
- * Check for query string to see if matchs all given ones
375
- * @param bool $match false default
376
- * @param array $rule rule to compare
377
- * @return boolean true if match
378
- */
379
- function rule_match_query_string( $match, $rule ) {
380
-
381
-
382
- $found = strpos($this->query_string, str_replace('?','', $rule['value'] ) ) > -1 ? true: false;
383
-
384
-
385
- if ( $rule['operator'] == "==" )
386
- return $found;
387
-
388
- return ! $found;
389
-
390
- }
391
-
392
- /**
393
- * [rule_match_same_site description]
394
- * @param bool $match false default
395
- * @param array $rule rule to compare
396
- * @return boolean true if match
397
- */
398
- function rule_match_same_site( $match, $rule ) {
399
-
400
-
401
- $ref = $this->referrer;
402
-
403
- $internal = str_replace( array( 'http://','https://' ), '', home_url() );
404
-
405
- if( $rule['operator'] == "==" ) {
406
-
407
- return !preg_match( '~' . $internal . '~i', $ref );
408
-
409
- } else {
410
- return preg_match( '~' . $internal . '~i', $ref );
411
-
412
- }
413
-
414
- }
415
-
416
- /*
417
- * rule_match_post_type
418
- *
419
- * @since 1.0.0
420
- */
421
-
422
- function rule_match_post_type( $match, $rule )
423
- {
424
-
425
-
426
- $post_type = $this->get_post_type();
427
-
428
-
429
- if( $rule['operator'] == "==" )
430
- {
431
- $match = ( $post_type === $rule['value'] );
432
- }
433
- elseif( $rule['operator'] == "!=" )
434
- {
435
- $match = ( $post_type !== $rule['value'] );
436
- }
437
-
438
-
439
- return $match;
440
- }
441
-
442
-
443
- /*
444
- * rule_match_post
445
- *
446
- * @since 1.0.0
447
- */
448
-
449
- function rule_match_post( $match, $rule )
450
- {
451
-
452
- $post_id = $this->post_id;
453
- // in case multiple ids are passed
454
- $ids = array_map('trim',explode(',',$rule['value']));
455
-
456
- if($rule['operator'] == "==")
457
- {
458
- $match = in_array($post_id, $ids );
459
- }
460
- elseif($rule['operator'] == "!=")
461
- {
462
- $match = ! in_array($post_id, $ids );
463
- }
464
-
465
- return $match;
466
-
467
- }
468
-
469
-
470
- /*
471
- * rule_match_page_type
472
- *
473
- * @since 1.0.0
474
- */
475
-
476
- function rule_match_page_type( $match, $rule )
477
- {
478
-
479
-
480
- $post_id = $this->post_id;
481
-
482
- $post = get_post( $post_id );
483
-
484
- $post_parent = isset( $post->post_parent ) ? $post->post_parent : '';
485
-
486
- $post_type = $this->get_post_type();
487
-
488
- if( $rule['value'] == 'front_page') {
489
-
490
- $front_page = (int) get_option('page_on_front');
491
-
492
- if( $front_page !== 0 ) {
493
-
494
- if($rule['operator'] == "==") {
495
-
496
- $match = ( $front_page == $post_id );
497
-
498
- } elseif($rule['operator'] == "!=") {
499
-
500
- $match = ( $front_page != $post_id );
501
-
502
- }
503
- } else {
504
- // if doing ajax is_home won't work so we do a workaround
505
- if( defined( 'DOING_AJAX') ) {
506
-
507
- $front_page = get_option( 'show_on_front' );
508
-
509
- if($rule['operator'] == "==") {
510
-
511
- $match = ( 'posts' == $front_page && $post_id == 0 );
512
-
513
- } elseif($rule['operator'] == "!=") {
514
-
515
- $match = !( 'posts' == $front_page && $post_id == 0 );
516
-
517
- }
518
-
519
-
520
- } else {
521
-
522
- if($rule['operator'] == "==") {
523
-
524
- $match = is_home();
525
-
526
- } elseif($rule['operator'] == "!=") {
527
-
528
- $match = !is_home();
529
-
530
- }
531
- }
532
-
533
- }
534
-
535
- }
536
- elseif( $rule['value'] == 'category_page') {
537
-
538
- if( defined( 'DOING_AJAX') ) {
539
- if($rule['operator'] == "==") {
540
-
541
- $match = $this->is_category;
542
-
543
- } elseif($rule['operator'] == "!=") {
544
-
545
- $match = !$this->is_category;
546
-
547
- }
548
- } else {
549
- if ( $rule['operator'] == "==" ) {
550
-
551
- $match = is_category();
552
-
553
- } elseif ( $rule['operator'] == "!=" ) {
554
-
555
- $match = ! is_category();
556
-
557
- }
558
- }
559
- }
560
- elseif( $rule['value'] == 'archive_page') {
561
- if( defined( 'DOING_AJAX') ) {
562
- if($rule['operator'] == "==") {
563
-
564
- $match = $this->is_archive;
565
-
566
- } elseif($rule['operator'] == "!=") {
567
-
568
- $match = !$this->is_archive;
569
-
570
- }
571
- } else {
572
- if ( $rule['operator'] == "==" ) {
573
-
574
- $match = is_archive();
575
-
576
- } elseif ( $rule['operator'] == "!=" ) {
577
-
578
- $match = ! is_archive();
579
-
580
- }
581
- }
582
- }
583
- elseif( $rule['value'] == 'search_page') {
584
- if( defined( 'DOING_AJAX') ) {
585
- if($rule['operator'] == "==") {
586
-
587
- $match = $this->is_search;
588
-
589
- } elseif($rule['operator'] == "!=") {
590
-
591
- $match = !$this->is_search;
592
-
593
- }
594
- } else {
595
- if ( $rule['operator'] == "==" ) {
596
-
597
- $match = is_search();
598
-
599
- } elseif ( $rule['operator'] == "!=" ) {
600
-
601
- $match = ! is_search();
602
-
603
- }
604
- }
605
- }
606
- elseif( $rule['value'] == 'posts_page') {
607
-
608
- $posts_page = (int) get_option('page_for_posts');
609
-
610
- if( $posts_page !== 0 ) {
611
- if($rule['operator'] == "==") {
612
-
613
- $match = ( $posts_page == $post_id );
614
-
615
- } elseif($rule['operator'] == "!=") {
616
-
617
- $match = ( $posts_page != $post_id );
618
-
619
- }
620
- } else {
621
- // if doing ajax is_home won't work so we do a workaround
622
- if( defined( 'DOING_AJAX') ) {
623
-
624
-
625
- if($rule['operator'] == "==") {
626
-
627
- $match = ( 0 === $posts_page && $post_id == 0 );
628
-
629
- } elseif($rule['operator'] == "!=") {
630
-
631
- $match = !( 0 === $posts_page && $post_id == 0 );
632
-
633
- }
634
-
635
-
636
- } else {
637
- if($rule['operator'] == "==") {
638
-
639
- $match = is_home();
640
-
641
- } elseif($rule['operator'] == "!=") {
642
-
643
- $match = !is_home();
644
-
645
- }
646
- }
647
- }
648
-
649
- }
650
- elseif( $rule['value'] == 'top_level') {
651
-
652
-
653
- if($rule['operator'] == "==")
654
- {
655
- $match = ( $post_parent == 0 );
656
- }
657
- elseif($rule['operator'] == "!=")
658
- {
659
- $match = ( $post_parent != 0 );
660
- }
661
-
662
- }
663
- elseif( $rule['value'] == 'parent') {
664
-
665
- $children = get_pages(array(
666
- 'post_type' => $post_type,
667
- 'child_of' => $post_id,
668
- ));
669
-
670
-
671
- if($rule['operator'] == "==") {
672
- $match = ( count($children) > 0 );
673
- }
674
- elseif($rule['operator'] == "!=")
675
- {
676
- $match = ( count($children) == 0 );
677
- }
678
-
679
- }
680
- elseif( $rule['value'] == 'child') {
681
-
682
-
683
-
684
- if($rule['operator'] == "==")
685
- {
686
- $match = ( $post_parent != 0 );
687
- }
688
- elseif($rule['operator'] == "!=")
689
- {
690
- $match = ( $post_parent == 0 );
691
- }
692
-
693
- } elseif( $rule['value'] == 'all_pages') {
694
-
695
- $match = true;
696
-
697
- }
698
-
699
- return $match;
700
-
701
- }
702
-
703
-
704
- /*
705
- * rule_match_page_parent
706
- *
707
- * @since 1.0.0
708
- */
709
-
710
- function rule_match_page_parent( $match, $rule )
711
- {
712
-
713
- // validation
714
- if( !$this->post_id )
715
- {
716
- return false;
717
- }
718
-
719
- // vars
720
- $post = get_post( $this->post_id );
721
-
722
- $post_parent = $post->post_parent;
723
-
724
- if($rule['operator'] == "==")
725
- {
726
- $match = ( $post_parent == $rule['value'] );
727
- }
728
- elseif($rule['operator'] == "!=")
729
- {
730
- $match = ( $post_parent != $rule['value'] );
731
- }
732
-
733
-
734
- return $match;
735
-
736
- }
737
-
738
-
739
- /*
740
- * rule_match_page_template
741
- *
742
- * @since 1.0.0
743
- */
744
-
745
- function rule_match_page_template( $match, $rule )
746
- {
747
-
748
-
749
- $page_template = get_post_meta( $this->post_id, '_wp_page_template', true );
750
-
751
-
752
- if( ! $page_template ) {
753
-
754
- if( 'page' == get_post_type( $this->post_id ) ) {
755
-
756
- $page_template = "default";
757
-
758
- }
759
- }
760
-
761
-
762
- if($rule['operator'] == "==")
763
- {
764
- $match = ( $page_template === $rule['value'] );
765
- }
766
- elseif($rule['operator'] == "!=")
767
- {
768
- $match = ( $page_template !== $rule['value'] );
769
- }
770
-
771
- return $match;
772
-
773
- }
774
-
775
-
776
- /*
777
- * rule_match_post_category
778
- *
779
- * @since 1.0.0
780
- */
781
-
782
- function rule_match_post_category( $match, $rule )
783
- {
784
-
785
-
786
- // validate
787
- if( !$this->post_id )
788
- {
789
- return false;
790
- }
791
- //check if we are in category page
792
- if( ($cat = get_category($this->post_id) ) ) {
793
- if($rule['operator'] == "==")
794
- return $rule['value'] == $this->post_id;
795
- return !($rule['value'] == $this->post_id);
796
- }// otherwise think this of a single post page
797
-
798
-
799
- // post type
800
- $post_type = $this->get_post_type();
801
-
802
- // vars
803
- $taxonomies = get_object_taxonomies( $post_type );
804
-
805
- $all_terms = get_the_terms( $this->post_id, 'category' );
806
- if($all_terms)
807
- {
808
- foreach($all_terms as $all_term)
809
- {
810
- $terms[] = $all_term->term_id;
811
- }
812
- }
813
-
814
- // no terms at all?
815
- if( empty($terms) )
816
- {
817
- // If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
818
- if( is_array($taxonomies) && in_array('category', $taxonomies) )
819
- {
820
- $terms[] = '1';
821
- }
822
- }
823
-
824
-
825
- if($rule['operator'] == "==")
826
- {
827
- $match = false;
828
-
829
- if(!empty($terms))
830
- {
831
- if( in_array($rule['value'], $terms) )
832
- {
833
- $match = true;
834
- }
835
- }
836
-
837
- }
838
- elseif($rule['operator'] == "!=")
839
- {
840
- $match = true;
841
-
842
- if($terms)
843
- {
844
- if( in_array($rule['value'], $terms) )
845
- {
846
- $match = false;
847
- }
848
- }
849
-
850
- }
851
-
852
-
853
- return $match;
854
-
855
- }
856
-
857
-
858
- /*
859
- * rule_match_user_type
860
- *
861
- * @since 1.0.0
862
- */
863
-
864
- function rule_match_user_type( $match, $rule )
865
- {
866
- $user = wp_get_current_user();
867
-
868
- if( $rule['operator'] == "==" )
869
- {
870
- if( $rule['value'] == 'super_admin' )
871
- {
872
- $match = is_super_admin( $user->ID );
873
- }
874
- else
875
- {
876
- $match = in_array( $rule['value'], $user->roles );
877
- }
878
-
879
- }
880
- elseif( $rule['operator'] == "!=" )
881
- {
882
- if( $rule['value'] == 'super_admin' )
883
- {
884
- $match = !is_super_admin( $user->ID );
885
- }
886
- else
887
- {
888
- $match = ( ! in_array( $rule['value'], $user->roles ) );
889
- }
890
- }
891
-
892
- return $match;
893
-
894
- }
895
-
896
-
897
-
898
-
899
- /*
900
- * rule_match_post_format
901
- *
902
- * @since 1.0.0
903
- */
904
-
905
- function rule_match_post_format( $match, $rule )
906
- {
907
-
908
-
909
- // validate
910
- if( !$this->post_id )
911
- {
912
- return false;
913
- }
914
-
915
- $post_type = $this->get_post_type();
916
-
917
-
918
- // does post_type support 'post-format'
919
- if( post_type_supports( $post_type, 'post-formats' ) )
920
- {
921
- $post_format = get_post_format( $this->post_id );
922
-
923
- if( $post_format === false )
924
- {
925
- $post_format = 'standard';
926
- }
927
- }
928
-
929
-
930
-
931
- if($rule['operator'] == "==")
932
- {
933
- $match = ( $post_format === $rule['value'] );
934
-
935
- }
936
- elseif($rule['operator'] == "!=")
937
- {
938
- $match = ( $post_format !== $rule['value'] );
939
- }
940
-
941
-
942
-
943
- return $match;
944
-
945
- }
946
-
947
-
948
- /*
949
- * rule_match_post_status
950
- *
951
- * @since 1.0.0
952
- */
953
-
954
- function rule_match_post_status( $match, $rule )
955
- {
956
-
957
-
958
- // validate
959
- if( !$this->post_id )
960
- {
961
- return false;
962
- }
963
-
964
-
965
- // vars
966
- $post_status = get_post_status( $this->post_id );
967
-
968
-
969
- // auto-draft = draft
970
- if( $post_status == 'auto-draft' )
971
- {
972
- $post_status = 'draft';
973
- }
974
-
975
-
976
- // match
977
- if($rule['operator'] == "==")
978
- {
979
- $match = ( $post_status === $rule['value'] );
980
-
981
- }
982
- elseif($rule['operator'] == "!=")
983
- {
984
- $match = ( $post_status !== $rule['value'] );
985
- }
986
-
987
-
988
- // return
989
- return $match;
990
-
991
- }
992
-
993
-
994
- /*
995
- * rule_match_taxonomy
996
- *
997
- * @since 1.0.0
998
- */
999
-
1000
- function rule_match_taxonomy( $match, $rule )
1001
- {
1002
-
1003
- // validate
1004
- if( !$this->post_id )
1005
- {
1006
- return false;
1007
- }
1008
- // if we are inside taxonomy archive page (Ajax mode)
1009
- if( $this->is_archive ){
1010
- if($rule['operator'] == "==")
1011
- return $rule['value'] == $this->post_id;
1012
- else
1013
- return $rule['value'] != $this->post_id;
1014
- }
1015
-
1016
- $qo = get_queried_object();
1017
-
1018
- // if we are inside taxonomy archive page
1019
- if( isset($qo->term_id) && $qo->term_id == $this->post_id ){
1020
- if($rule['operator'] == "==")
1021
- return $rule['value'] == $qo->term_id;
1022
- else
1023
- return $rule['value'] != $qo->term_id;
1024
- } else {
1025
- // post type
1026
- $post_type = $this->get_post_type();
1027
- // vars
1028
- $taxonomies = get_object_taxonomies( $post_type );
1029
- }
1030
-
1031
- $terms = array();
1032
-
1033
-
1034
- if( is_array($taxonomies) )
1035
- {
1036
- foreach( $taxonomies as $tax )
1037
- {
1038
- $all_terms = get_the_terms( $this->post_id, $tax );
1039
- if($all_terms)
1040
- {
1041
- foreach($all_terms as $all_term)
1042
- {
1043
- $terms[] = $all_term->term_id;
1044
- }
1045
- }
1046
- }
1047
- }
1048
-
1049
- // no terms at all?
1050
- if( empty($terms) )
1051
- {
1052
- // If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
1053
- if( is_array($taxonomies) && in_array('category', $taxonomies) )
1054
- {
1055
- $terms[] = '1';
1056
- }
1057
- }
1058
-
1059
-
1060
-
1061
- if($rule['operator'] == "==")
1062
- {
1063
- $match = false;
1064
-
1065
- if($terms)
1066
- {
1067
- if( in_array($rule['value'], $terms) )
1068
- {
1069
- $match = true;
1070
- }
1071
- }
1072
-
1073
- }
1074
- elseif($rule['operator'] == "!=")
1075
- {
1076
- $match = true;
1077
-
1078
- if($terms)
1079
- {
1080
- if( in_array($rule['value'], $terms) )
1081
- {
1082
- $match = false;
1083
- }
1084
- }
1085
-
1086
- }
1087
-
1088
-
1089
- return $match;
1090
-
1091
- }
1092
-
1093
- /**
1094
- * Helper function to get post type
1095
- * @since 1.2.3
1096
- * @return string
1097
- *
1098
- */
1099
- function get_post_type(){
1100
- global $wp_query;
1101
-
1102
- $post_type = isset( $wp_query->query_vars['post_type'] ) ? $wp_query->query_vars['post_type'] : '';
1103
-
1104
- $post_type = empty( $post_type ) ? get_post_type($this->post_id) : get_post_type();
1105
-
1106
- return $post_type;
1107
- }
1108
-
1109
- /**
1110
- * Check for custom url
1111
- *
1112
- * @param array $rule rule to compare
1113
- *
1114
- * @return boolean true if match
1115
- */
1116
- public function rule_match_custom_url( $match, $rule ) {
1117
-
1118
- $wide_search = strpos($rule['value'],'*') !== false ? true : false;
1119
-
1120
- if( $wide_search ) {
1121
- if( strpos( $this->current_url, trim($rule['value'],'*') ) === 0 ) {
1122
- return ( $rule['operator'] == "==" );
1123
- }
1124
- return ! ( $rule['operator'] == "==" );
1125
- }
1126
-
1127
- if( $rule['operator'] == "==" )
1128
- return ($this->current_url == $rule['value']);
1129
-
1130
- return ! ($this->current_url == $rule['value']);
1131
-
1132
- }
1133
-
1134
- /**
1135
- * Check for keyword url
1136
- *
1137
- * @param array $rule rule to compare
1138
- *
1139
- * @return boolean true if match
1140
- */
1141
- function rule_match_keyword_url($match, $rule) {
1142
-
1143
- $search_url = str_replace(site_url(), '', $this->current_url);
1144
-
1145
- if( strlen($search_url) > 0 && strpos($search_url, trim($rule['value'])) !== false )
1146
- return ($rule['operator'] == "==");
1147
- else
1148
- return !($rule['operator'] == "==");
1149
-
1150
- }
1151
  }
1
+ <?php
2
+ use Jaybizzle\CrawlerDetect\CrawlerDetect;
3
+ /*
4
+ * Spu Rules
5
+ * Class that will compare rules and determine if popup needs to show
6
+ * @since: 2.0
7
+ */
8
+ class Spu_Rules
9
+ {
10
+ /**
11
+ * post id used to check rules
12
+ * @var int
13
+ */
14
+ protected $post_id;
15
+
16
+ /**
17
+ * referrer using in ajax calls
18
+ * @var string
19
+ */
20
+ protected $referrer;
21
+
22
+ /**
23
+ * Is category using in ajax calls
24
+ * @var boolean
25
+ */
26
+ protected $is_category = false;
27
+
28
+ /**
29
+ * Is archive using in ajax calls
30
+ * @var boolean
31
+ */
32
+ protected $is_archive = false;
33
+
34
+ /**
35
+ * Is searchu sed in ajax calls
36
+ * @var boolean
37
+ */
38
+ protected $is_search = false;
39
+
40
+ /**
41
+ * Holds current url
42
+ * @var string
43
+ */
44
+ protected $current_url;
45
+
46
+ /**
47
+ * Holds query string
48
+ * @var
49
+ */
50
+ protected $query_string;
51
+
52
+ /*
53
+ * __construct
54
+ * Add all the filters to use later
55
+ */
56
+
57
+ function __construct()
58
+ {
59
+ global $post;
60
+
61
+ // User
62
+ add_filter('spu/rules/rule_match/user_type', array($this, 'rule_match_user_type'), 10, 2);
63
+ add_filter('spu/rules/rule_match/logged_user', array($this, 'rule_match_logged_user'), 10, 2);
64
+ add_filter('spu/rules/rule_match/left_comment', array($this, 'rule_match_left_comment'), 10, 2);
65
+ add_filter('spu/rules/rule_match/search_engine', array($this, 'rule_match_search_engine'), 10, 2);
66
+ add_filter('spu/rules/rule_match/same_site', array($this, 'rule_match_same_site'), 10, 2);
67
+
68
+ // Post
69
+ add_filter('spu/rules/rule_match/post_type', array($this, 'rule_match_post_type'), 10, 2);
70
+ add_filter('spu/rules/rule_match/post_id', array($this, 'rule_match_post'), 10, 2);
71
+ add_filter('spu/rules/rule_match/post', array($this, 'rule_match_post'), 10, 2);
72
+ add_filter('spu/rules/rule_match/post_category', array($this, 'rule_match_post_category'), 10, 2);
73
+ add_filter('spu/rules/rule_match/post_format', array($this, 'rule_match_post_format'), 10, 2);
74
+ add_filter('spu/rules/rule_match/post_status', array($this, 'rule_match_post_status'), 10, 2);
75
+ add_filter('spu/rules/rule_match/taxonomy', array($this, 'rule_match_taxonomy'), 10, 2);
76
+
77
+ // Page
78
+ add_filter('spu/rules/rule_match/page', array($this, 'rule_match_post'), 10, 2);
79
+ add_filter('spu/rules/rule_match/page_type', array($this, 'rule_match_page_type'), 10, 2);
80
+ add_filter('spu/rules/rule_match/page_parent', array($this, 'rule_match_page_parent'), 10, 2);
81
+ add_filter('spu/rules/rule_match/page_template', array($this, 'rule_match_page_template'), 10, 2);
82
+
83
+ //Other
84
+ add_filter('spu/rules/rule_match/mobiles', array($this, 'rule_match_mobiles'), 10, 2);
85
+ add_filter('spu/rules/rule_match/tablets', array($this, 'rule_match_tablets'), 10, 2);
86
+ add_filter('spu/rules/rule_match/desktop', array($this, 'rule_match_desktop'), 10, 2);
87
+ add_filter('spu/rules/rule_match/referrer', array($this, 'rule_match_referrer'), 10, 2);
88
+ add_filter('spu/rules/rule_match/crawlers', array($this, 'rule_match_crawlers'), 10, 2);
89
+ add_filter('spu/rules/rule_match/browser', array($this, 'rule_match_browser'), 10, 2);
90
+ add_filter('spu/rules/rule_match/query_string', array($this, 'rule_match_query_string'), 10, 2);
91
+ add_filter('spu/rules/rule_match/custom_url', array($this, 'rule_match_custom_url'), 10, 2);
92
+ add_filter('spu/rules/rule_match/keyword_url', array($this, 'rule_match_keyword_url'), 10, 2);
93
+
94
+ $this->post_id = get_queried_object_id();
95
+ $this->referrer = isset($_SERVER['HTTP_REFERER']) && !defined('DOING_AJAX') ? $_SERVER['HTTP_REFERER'] : '';
96
+ $this->query_string = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
97
+ $this->current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
98
+
99
+
100
+ if( defined('DOING_AJAX') ) {
101
+
102
+ if( isset( $_REQUEST['pid'] ) ) {
103
+ $this->post_id = $_REQUEST['pid'];
104
+ }
105
+ if( !empty( $_REQUEST['referrer'] ) ) {
106
+ $this->referrer = $_REQUEST['referrer'];
107
+ }
108
+ if( !empty( $_REQUEST['current_url'] ) ) {
109
+ $this->current_url = $_REQUEST['current_url'];
110
+ }
111
+ if( !empty( $_REQUEST['query_string'] ) ) {
112
+ $this->query_string = $_REQUEST['query_string'];
113
+ }
114
+ if( !empty( $_REQUEST['is_category'] ) ) {
115
+ $this->is_category = true;
116
+ }
117
+ if( !empty( $_REQUEST['is_archive'] ) ) {
118
+ $this->is_archive = true;
119
+ }
120
+ if( !empty( $_REQUEST['is_search'] ) ) {
121
+ $this->is_search = true;
122
+ }
123
+ }
124
+
125
+ }
126
+
127
+
128
+ /*
129
+ * check_rules
130
+ *
131
+ * @since 1.0.0
132
+ */
133
+
134
+ function check_rules( $rules = '' )
135
+ {
136
+
137
+ //if no rules, add the box
138
+ $add_box = true;
139
+
140
+ if( !empty( $rules ) ) {
141
+ // vars
142
+ $add_box = false;
143
+
144
+
145
+ foreach( $rules as $group_id => $group ) {
146
+ // start of as true, this way, any rule that doesn't match will cause this varaible to false
147
+ $match_group = true;
148
+
149
+ if( is_array($group) )
150
+ {
151
+
152
+ foreach( $group as $rule_id => $rule )
153
+ {
154
+
155
+ // $match = true / false
156
+ $match = apply_filters( 'spu/rules/rule_match/' . $rule['param'] , false, $rule );
157
+
158
+ if( !$match )
159
+ {
160
+ $match_group = false;
161
+ // if one rule fails we don't need to check the rest of the rules in the group
162
+ // that way if we add geo rules down it won't get executed and will save credits
163
+ break;
164
+ }
165
+
166
+ }
167
+ }
168
+
169
+
170
+ // all rules must havematched!
171
+ if( $match_group )
172
+ {
173
+ $add_box = true;
174
+ }
175
+
176
+ }
177
+
178
+
179
+ }
180
+
181
+
182
+ return $add_box;
183
+ }
184
+
185
+ /**
186
+ * [rule_match_logged_user description]
187
+ * @param bool $match false default
188
+ * @param array $rule rule to compare
189
+ * @return boolean true if match
190
+ */
191
+ function rule_match_logged_user( $match, $rule ) {
192
+
193
+ if ( $rule['operator'] == "==" ) {
194
+
195
+ return is_user_logged_in();
196
+
197
+ } else {
198
+
199
+ return !is_user_logged_in();
200
+
201
+ }
202
+
203
+ }
204
+
205
+ /**
206
+ * [rule_match_mobiles description]
207
+ * @param bool $match false default
208
+ * @param array $rule rule to compare
209
+ * @return boolean true if match
210
+ */
211
+ function rule_match_mobiles( $match, $rule ) {
212
+
213
+ $detect = new Mobile_Detect;
214
+
215
+ if ( $rule['operator'] == "==" ) {
216
+
217
+ return $detect->isMobile();
218
+
219
+ } else {
220
+
221
+ return !$detect->isMobile();
222
+
223
+ }
224
+
225
+ }
226
+ /**
227
+ * [rule_match_browser description]
228
+ * @param bool $match false default
229
+ * @param array $rule rule to compare
230
+ * @return boolean true if match
231
+ */
232
+ function rule_match_browser( $match, $rule ) {
233
+
234
+ $detect = new Browser();
235
+
236
+ //check $detect $browsers for valid keys
237
+ if ( $rule['operator'] == "==" ) {
238
+
239
+ return $detect->getBrowser() == $rule['value'];
240
+
241
+ } else {
242
+
243
+ return $detect->getBrowser() != $rule['value'];
244
+
245
+ }
246
+
247
+ }
248
+ /**
249
+ * [rule_match_tablets description]
250
+ * @param bool $match false default
251
+ * @param array $rule rule to compare
252
+ * @return boolean true if match
253
+ */
254
+ function rule_match_tablets( $match, $rule ) {
255
+
256
+ $detect = new Mobile_Detect;
257
+
258
+ if ( $rule['operator'] == "==" ) {
259
+
260
+ return $detect->isTablet();
261
+
262
+ } else {
263
+
264
+ return !$detect->isTablet();
265
+
266
+ }
267
+
268
+ }
269
+ /**
270
+ * [rule_match_desktop description]
271
+ * @param bool $match false default
272
+ * @param array $rule rule to compare
273
+ * @return boolean true if match
274
+ */
275
+ function rule_match_desktop( $match, $rule ) {
276
+
277
+ $detect = new Mobile_Detect;
278
+
279
+ if ( $rule['operator'] == "==" ) {
280
+
281
+ return ( ! $detect->isTablet() && ! $detect->isMobile() );
282
+
283
+ } else {
284
+
285
+ return ( $detect->isTablet() || $detect->isMobile() );
286
+
287
+ }
288
+
289
+ }
290
+
291
+ /**
292
+ * [rule_match_left_comment description]
293
+ * @param bool $match false default
294
+ * @param array $rule rule to compare
295
+ * @return boolean true if match
296
+ */
297
+ function rule_match_left_comment( $match, $rule ) {
298
+
299
+ if ( $rule['operator'] == "==" ) {
300
+
301
+ return !empty( $_COOKIE['comment_author_'.COOKIEHASH] );
302
+
303
+ } else {
304
+
305
+ return empty( $_COOKIE['comment_author_'.COOKIEHASH] );
306
+
307
+ }
308
+
309
+ }
310
+ /**
311
+ * [rule_match_search_engine description]
312
+ * @param bool $match false default
313
+ * @param array $rule rule to compare
314
+ * @return boolean true if match
315
+ */
316
+ function rule_match_search_engine( $match, $rule ) {
317
+
318
+ $ref = $this->referrer;
319
+
320
+ $SE = apply_filters( 'spu/rules/search_engines', array('/search?', '.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.', '.bing.' ) );
321
+
322
+ foreach ($SE as $url) {
323
+ if ( strpos( $ref,$url ) !==false ){
324
+
325
+ return $rule['operator'] == "==" ? true : false;
326
+ }
327
+ }
328
+
329
+ return $rule['operator'] == "==" ? false : true;
330
+
331
+ }
332
+
333
+ /**
334
+ * Check for user referrer
335
+ * @param bool $match false default
336
+ * @param array $rule rule to compare
337
+ * @return boolean true if match
338
+ */
339
+ function rule_match_referrer( $match, $rule ) {
340
+
341
+ $ref = $this->referrer;
342
+
343
+ if ( strpos( $ref,$rule['value'] ) !==false ){
344
+ return $rule['operator'] == "==" ? true : false;
345
+ }
346
+
347
+ return $rule['operator'] == "==" ? false : true;
348
+
349
+ }
350
+
351
+ /**
352
+ * Check for crawlers / bots
353
+ * @param bool $match false default
354
+ * @param array $rule rule to compare
355
+ * @return boolean true if match
356
+ */
357
+ function rule_match_crawlers( $match, $rule ) {
358
+
359
+ $detect = new CrawlerDetect;
360
+
361
+ if ( $rule['operator'] == "==" ) {
362
+
363
+ return $detect->isCrawler();
364
+
365
+ } else {
366
+
367
+ return !$detect->isCrawler();
368
+
369
+ }
370
+
371
+ }
372
+
373
+ /**
374
+ * Check for query string to see if matchs all given ones
375
+ * @param bool $match false default
376
+ * @param array $rule rule to compare
377
+ * @return boolean true if match
378
+ */
379
+ function rule_match_query_string( $match, $rule ) {
380
+
381
+
382
+ $found = strpos($this->query_string, str_replace('?','', $rule['value'] ) ) > -1 ? true: false;
383
+
384
+
385
+ if ( $rule['operator'] == "==" )
386
+ return $found;
387
+
388
+ return ! $found;
389
+
390
+ }
391
+
392
+ /**
393
+ * [rule_match_same_site description]
394
+ * @param bool $match false default
395
+ * @param array $rule rule to compare
396
+ * @return boolean true if match
397
+ */
398
+ function rule_match_same_site( $match, $rule ) {
399
+
400
+
401
+ $ref = $this->referrer;
402
+
403
+ $internal = str_replace( array( 'http://','https://' ), '', home_url() );
404
+
405
+ if( $rule['operator'] == "==" ) {
406
+
407
+ return !preg_match( '~' . $internal . '~i', $ref );
408
+
409
+ } else {
410
+ return preg_match( '~' . $internal . '~i', $ref );
411
+
412
+ }
413
+
414
+ }
415
+
416
+ /*
417
+ * rule_match_post_type
418
+ *
419
+ * @since 1.0.0
420
+ */
421
+
422
+ function rule_match_post_type( $match, $rule )
423
+ {
424
+
425
+
426
+ $post_type = $this->get_post_type();
427
+
428
+
429
+ if( $rule['operator'] == "==" )
430
+ {
431
+ $match = ( $post_type === $rule['value'] );
432
+ }
433
+ elseif( $rule['operator'] == "!=" )
434
+ {
435
+ $match = ( $post_type !== $rule['value'] );
436
+ }
437
+
438
+
439
+ return $match;
440
+ }
441
+
442
+
443
+ /*
444
+ * rule_match_post
445
+ *
446
+ * @since 1.0.0
447
+ */
448
+
449
+ function rule_match_post( $match, $rule )
450
+ {
451
+
452
+ $post_id = $this->post_id;
453
+ // in case multiple ids are passed
454
+ $ids = array_map('trim',explode(',',$rule['value']));
455
+
456
+ if($rule['operator'] == "==")
457
+ {
458
+ $match = in_array($post_id, $ids );
459
+ }
460
+ elseif($rule['operator'] == "!=")
461
+ {
462
+ $match = ! in_array($post_id, $ids );
463
+ }
464
+
465
+ return $match;
466
+
467
+ }
468
+
469
+
470
+ /*
471
+ * rule_match_page_type
472
+ *
473
+ * @since 1.0.0
474
+ */
475
+
476
+ function rule_match_page_type( $match, $rule )
477
+ {
478
+
479
+
480
+ $post_id = $this->post_id;
481
+
482
+ $post = get_post( $post_id );
483
+
484
+ $post_parent = isset( $post->post_parent ) ? $post->post_parent : '';
485
+
486
+ $post_type = $this->get_post_type();
487
+
488
+ if( $rule['value'] == 'front_page') {
489
+
490
+ $front_page = (int) get_option('page_on_front');
491
+
492
+ if( $front_page !== 0 ) {
493
+
494
+ if($rule['operator'] == "==") {
495
+
496
+ $match = ( $front_page == $post_id );
497
+
498
+ } elseif($rule['operator'] == "!=") {
499
+
500
+ $match = ( $front_page != $post_id );
501
+
502
+ }
503
+ } else {
504
+ // if doing ajax is_home won't work so we do a workaround
505
+ if( defined( 'DOING_AJAX') ) {
506
+
507
+ $front_page = get_option( 'show_on_front' );
508
+
509
+ if($rule['operator'] == "==") {
510
+
511
+ $match = ( 'posts' == $front_page && $post_id == 0 );
512
+
513
+ } elseif($rule['operator'] == "!=") {
514
+
515
+ $match = !( 'posts' == $front_page && $post_id == 0 );
516
+
517
+ }
518
+
519
+
520
+ } else {
521
+
522
+ if($rule['operator'] == "==") {
523
+
524
+ $match = is_home();
525
+
526
+ } elseif($rule['operator'] == "!=") {
527
+
528
+ $match = !is_home();
529
+
530
+ }
531
+ }
532
+
533
+ }
534
+
535
+ }
536
+ elseif( $rule['value'] == 'category_page') {
537
+
538
+ if( defined( 'DOING_AJAX') ) {
539
+ if($rule['operator'] == "==") {
540
+
541
+ $match = $this->is_category;
542
+
543
+ } elseif($rule['operator'] == "!=") {
544
+
545
+ $match = !$this->is_category;
546
+
547
+ }
548
+ } else {
549
+ if ( $rule['operator'] == "==" ) {
550
+
551
+ $match = is_category();
552
+
553
+ } elseif ( $rule['operator'] == "!=" ) {
554
+
555
+ $match = ! is_category();
556
+
557
+ }
558
+ }
559
+ }
560
+ elseif( $rule['value'] == 'archive_page') {
561
+ if( defined( 'DOING_AJAX') ) {
562
+ if($rule['operator'] == "==") {
563
+
564
+ $match = $this->is_archive;
565
+
566
+ } elseif($rule['operator'] == "!=") {
567
+
568
+ $match = !$this->is_archive;
569
+
570
+ }
571
+ } else {
572
+ if ( $rule['operator'] == "==" ) {
573
+
574
+ $match = is_archive();
575
+
576
+ } elseif ( $rule['operator'] == "!=" ) {
577
+
578
+ $match = ! is_archive();
579
+
580
+ }
581
+ }
582
+ }
583
+ elseif( $rule['value'] == 'search_page') {
584
+ if( defined( 'DOING_AJAX') ) {
585
+ if($rule['operator'] == "==") {
586
+
587
+ $match = $this->is_search;
588
+
589
+ } elseif($rule['operator'] == "!=") {
590
+
591
+ $match = !$this->is_search;
592
+
593
+ }
594
+ } else {
595
+ if ( $rule['operator'] == "==" ) {
596
+
597
+ $match = is_search();
598
+
599
+ } elseif ( $rule['operator'] == "!=" ) {
600
+
601
+ $match = ! is_search();
602
+
603
+ }
604
+ }
605
+ }
606
+ elseif( $rule['value'] == 'posts_page') {
607
+
608
+ $posts_page = (int) get_option('page_for_posts');
609
+
610
+ if( $posts_page !== 0 ) {
611
+ if($rule['operator'] == "==") {
612
+
613
+ $match = ( $posts_page == $post_id );
614
+
615
+ } elseif($rule['operator'] == "!=") {
616
+
617
+ $match = ( $posts_page != $post_id );
618
+
619
+ }
620
+ } else {
621
+ // if doing ajax is_home won't work so we do a workaround
622
+ if( defined( 'DOING_AJAX') ) {
623
+
624
+
625
+ if($rule['operator'] == "==") {
626
+
627
+ $match = ( 0 === $posts_page && $post_id == 0 );
628
+
629
+ } elseif($rule['operator'] == "!=") {
630
+
631
+ $match = !( 0 === $posts_page && $post_id == 0 );
632
+
633
+ }
634
+
635
+
636
+ } else {
637
+ if($rule['operator'] == "==") {
638
+
639
+ $match = is_home();
640
+
641
+ } elseif($rule['operator'] == "!=") {
642
+
643
+ $match = !is_home();
644
+
645
+ }
646
+ }
647
+ }
648
+
649
+ }
650
+ elseif( $rule['value'] == 'top_level') {
651
+
652
+
653
+ if($rule['operator'] == "==")
654
+ {
655
+ $match = ( $post_parent == 0 );
656
+ }
657
+ elseif($rule['operator'] == "!=")
658
+ {
659
+ $match = ( $post_parent != 0 );
660
+ }
661
+
662
+ }
663
+ elseif( $rule['value'] == 'parent') {
664
+
665
+ $children = get_pages(array(
666
+ 'post_type' => $post_type,
667
+ 'child_of' => $post_id,
668
+ ));
669
+
670
+
671
+ if($rule['operator'] == "==") {
672
+ $match = ( count($children) > 0 );
673
+ }
674
+ elseif($rule['operator'] == "!=")
675
+ {
676
+ $match = ( count($children) == 0 );
677
+ }
678
+
679
+ }
680
+ elseif( $rule['value'] == 'child') {
681
+
682
+
683
+
684
+ if($rule['operator'] == "==")
685
+ {
686
+ $match = ( $post_parent != 0 );
687
+ }
688
+ elseif($rule['operator'] == "!=")
689
+ {
690
+ $match = ( $post_parent == 0 );
691
+ }
692
+
693
+ } elseif( $rule['value'] == 'all_pages') {
694
+
695
+ $match = true;
696
+
697
+ }
698
+
699
+ return $match;
700
+
701
+ }
702
+
703
+
704
+ /*
705
+ * rule_match_page_parent
706
+ *
707
+ * @since 1.0.0
708
+ */
709
+
710
+ function rule_match_page_parent( $match, $rule )
711
+ {
712
+
713
+ // validation
714
+ if( !$this->post_id )
715
+ {
716
+ return false;
717
+ }
718
+
719
+ // vars
720
+ $post = get_post( $this->post_id );
721
+
722
+ $post_parent = $post->post_parent;
723
+
724
+ if($rule['operator'] == "==")
725
+ {
726
+ $match = ( $post_parent == $rule['value'] );
727
+ }
728
+ elseif($rule['operator'] == "!=")
729
+ {
730
+ $match = ( $post_parent != $rule['value'] );
731
+ }
732
+
733
+
734
+ return $match;
735
+
736
+ }
737
+
738
+
739
+ /*
740
+ * rule_match_page_template
741
+ *
742
+ * @since 1.0.0
743
+ */
744
+
745
+ function rule_match_page_template( $match, $rule )
746
+ {
747
+
748
+
749
+ $page_template = get_post_meta( $this->post_id, '_wp_page_template', true );
750
+
751
+
752
+ if( ! $page_template ) {
753
+
754
+ if( 'page' == get_post_type( $this->post_id ) ) {
755
+
756
+ $page_template = "default";
757
+
758
+ }
759
+ }
760
+
761
+
762
+ if($rule['operator'] == "==")
763
+ {
764
+ $match = ( $page_template === $rule['value'] );
765
+ }
766
+ elseif($rule['operator'] == "!=")
767
+ {
768
+ $match = ( $page_template !== $rule['value'] );
769
+ }
770
+
771
+ return $match;
772
+
773
+ }
774
+
775
+
776
+ /*
777
+ * rule_match_post_category
778
+ *
779
+ * @since 1.0.0
780
+ */
781
+
782
+ function rule_match_post_category( $match, $rule )
783
+ {
784
+
785
+
786
+ // validate
787
+ if( !$this->post_id )
788
+ {
789
+ return false;
790
+ }
791
+ //check if we are in category page
792
+ if( ($cat = get_category($this->post_id) ) ) {
793
+ if($rule['operator'] == "==")
794
+ return $rule['value'] == $this->post_id;
795
+ return !($rule['value'] == $this->post_id);
796
+ }// otherwise think this of a single post page
797
+
798
+
799
+ // post type
800
+ $post_type = $this->get_post_type();
801
+
802
+ // vars
803
+ $taxonomies = get_object_taxonomies( $post_type );
804
+
805
+ $all_terms = get_the_terms( $this->post_id, 'category' );
806
+ if($all_terms)
807
+ {
808
+ foreach($all_terms as $all_term)
809
+ {
810
+ $terms[] = $all_term->term_id;
811
+ }
812
+ }
813
+
814
+ // no terms at all?
815
+ if( empty($terms) )
816
+ {
817
+ // If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
818
+ if( is_array($taxonomies) && in_array('category', $taxonomies) )
819
+ {
820
+ $terms[] = '1';
821
+ }
822
+ }
823
+
824
+
825
+ if($rule['operator'] == "==")
826
+ {
827
+ $match = false;
828
+
829
+ if(!empty($terms))
830
+ {
831
+ if( in_array($rule['value'], $terms) )
832
+ {
833
+ $match = true;
834
+ }
835
+ }
836
+
837
+ }
838
+ elseif($rule['operator'] == "!=")
839
+ {
840
+ $match = true;
841
+
842
+ if($terms)
843
+ {
844
+ if( in_array($rule['value'], $terms) )
845
+ {
846
+ $match = false;
847
+ }
848
+ }
849
+
850
+ }
851
+
852
+
853
+ return $match;
854
+
855
+ }
856
+
857
+
858
+ /*
859
+ * rule_match_user_type
860
+ *
861
+ * @since 1.0.0
862
+ */
863
+
864
+ function rule_match_user_type( $match, $rule )
865
+ {
866
+ $user = wp_get_current_user();
867
+
868
+ if( $rule['operator'] == "==" )
869
+ {
870
+ if( $rule['value'] == 'super_admin' )
871
+ {
872
+ $match = is_super_admin( $user->ID );
873
+ }
874
+ else
875
+ {
876
+ $match = in_array( $rule['value'], $user->roles );
877
+ }
878
+
879
+ }
880
+ elseif( $rule['operator'] == "!=" )
881
+ {
882
+ if( $rule['value'] == 'super_admin' )
883
+ {
884
+ $match = !is_super_admin( $user->ID );
885
+ }
886
+ else
887
+ {
888
+ $match = ( ! in_array( $rule['value'], $user->roles ) );
889
+ }
890
+ }
891
+
892
+ return $match;
893
+
894
+ }
895
+
896
+
897
+
898
+
899
+ /*
900
+ * rule_match_post_format
901
+ *
902
+ * @since 1.0.0
903
+ */
904
+
905
+ function rule_match_post_format( $match, $rule )
906
+ {
907
+
908
+
909
+ // validate
910
+ if( !$this->post_id )
911
+ {
912
+ return false;
913
+ }
914
+
915
+ $post_type = $this->get_post_type();
916
+
917
+
918
+ // does post_type support 'post-format'
919
+ if( post_type_supports( $post_type, 'post-formats' ) )
920
+ {
921
+ $post_format = get_post_format( $this->post_id );
922
+
923
+ if( $post_format === false )
924
+ {
925
+ $post_format = 'standard';
926
+ }
927
+ }
928
+
929
+
930
+
931
+ if($rule['operator'] == "==")
932
+ {
933
+ $match = ( $post_format === $rule['value'] );
934
+
935
+ }
936
+ elseif($rule['operator'] == "!=")
937
+ {
938
+ $match = ( $post_format !== $rule['value'] );
939
+ }
940
+
941
+
942
+
943
+ return $match;
944
+
945
+ }
946
+
947
+
948
+ /*
949
+ * rule_match_post_status
950
+ *
951
+ * @since 1.0.0
952
+ */
953
+
954
+ function rule_match_post_status( $match, $rule )
955
+ {
956
+
957
+
958
+ // validate
959
+ if( !$this->post_id )
960
+ {
961
+ return false;
962
+ }
963
+
964
+
965
+ // vars
966
+ $post_status = get_post_status( $this->post_id );
967
+
968
+
969
+ // auto-draft = draft
970
+ if( $post_status == 'auto-draft' )
971
+ {
972
+ $post_status = 'draft';
973
+ }
974
+
975
+
976
+ // match
977
+ if($rule['operator'] == "==")
978
+ {
979
+ $match = ( $post_status === $rule['value'] );
980
+
981
+ }
982
+ elseif($rule['operator'] == "!=")
983
+ {
984
+ $match = ( $post_status !== $rule['value'] );
985
+ }
986
+
987
+
988
+ // return
989
+ return $match;
990
+
991
+ }
992
+
993
+
994
+ /*
995
+ * rule_match_taxonomy
996
+ *
997
+ * @since 1.0.0
998
+ */
999
+
1000
+ function rule_match_taxonomy( $match, $rule )
1001
+ {
1002
+
1003
+ // validate
1004
+ if( !$this->post_id )
1005
+ {
1006
+ return false;
1007
+ }
1008
+ // if we are inside taxonomy archive page (Ajax mode)
1009
+ if( $this->is_archive ){
1010
+ if($rule['operator'] == "==")
1011
+ return $rule['value'] == $this->post_id;
1012
+ else
1013
+ return $rule['value'] != $this->post_id;
1014
+ }
1015
+
1016
+ $qo = get_queried_object();
1017
+
1018
+ // if we are inside taxonomy archive page
1019
+ if( isset($qo->term_id) && $qo->term_id == $this->post_id ){
1020
+ if($rule['operator'] == "==")
1021
+ return $rule['value'] == $qo->term_id;
1022
+ else
1023
+ return $rule['value'] != $qo->term_id;
1024
+ } else {
1025
+ // post type
1026
+ $post_type = $this->get_post_type();
1027
+ // vars
1028
+ $taxonomies = get_object_taxonomies( $post_type );
1029
+ }
1030
+
1031
+ $terms = array();
1032
+
1033
+
1034
+ if( is_array($taxonomies) )
1035
+ {
1036
+ foreach( $taxonomies as $tax )
1037
+ {
1038
+ $all_terms = get_the_terms( $this->post_id, $tax );
1039
+ if($all_terms)
1040
+ {
1041
+ foreach($all_terms as $all_term)
1042
+ {
1043
+ $terms[] = $all_term->term_id;
1044
+ }
1045
+ }
1046
+ }
1047
+ }
1048
+
1049
+ // no terms at all?
1050
+ if( empty($terms) )
1051
+ {
1052
+ // If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
1053
+ if( is_array($taxonomies) && in_array('category', $taxonomies) )
1054
+ {
1055
+ $terms[] = '1';
1056
+ }
1057
+ }
1058
+
1059
+
1060
+
1061
+ if($rule['operator'] == "==")
1062
+ {
1063
+ $match = false;
1064
+
1065
+ if($terms)
1066
+ {
1067
+ if( in_array($rule['value'], $terms) )
1068
+ {
1069
+ $match = true;
1070
+ }
1071
+ }
1072
+
1073
+ }
1074
+ elseif($rule['operator'] == "!=")
1075
+ {
1076
+ $match = true;
1077
+
1078
+ if($terms)
1079
+ {
1080
+ if( in_array($rule['value'], $terms) )
1081
+ {
1082
+ $match = false;
1083
+ }
1084
+ }
1085
+
1086
+ }
1087
+
1088
+
1089
+ return $match;
1090
+
1091
+ }
1092
+
1093
+ /**
1094
+ * Helper function to get post type
1095
+ * @since 1.2.3
1096
+ * @return string
1097
+ *
1098
+ */
1099
+ function get_post_type(){
1100
+ global $wp_query;
1101
+
1102
+ $post_type = isset( $wp_query->query_vars['post_type'] ) ? $wp_query->query_vars['post_type'] : '';
1103
+
1104
+ $post_type = empty( $post_type ) ? get_post_type($this->post_id) : get_post_type();
1105
+
1106
+ return $post_type;
1107
+ }
1108
+
1109
+ /**
1110
+ * Check for custom url
1111
+ *
1112
+ * @param array $rule rule to compare
1113
+ *
1114
+ * @return boolean true if match
1115
+ */
1116
+ public function rule_match_custom_url( $match, $rule ) {
1117
+
1118
+ $wide_search = strpos($rule['value'],'*') !== false ? true : false;
1119
+
1120
+ if( $wide_search ) {
1121
+ if( strpos( $this->current_url, trim($rule['value'],'*') ) === 0 ) {
1122
+ return ( $rule['operator'] == "==" );
1123
+ }
1124
+ return ! ( $rule['operator'] == "==" );
1125
+ }
1126
+
1127
+ if( $rule['operator'] == "==" )
1128
+ return ($this->current_url == $rule['value']);
1129
+
1130
+ return ! ($this->current_url == $rule['value']);
1131
+
1132
+ }
1133
+
1134
+ /**
1135
+ * Check for keyword url
1136
+ *
1137
+ * @param array $rule rule to compare
1138
+ *
1139
+ * @return boolean true if match
1140
+ */
1141
+ function rule_match_keyword_url($match, $rule) {
1142
+
1143
+ $search_url = str_replace(site_url(), '', $this->current_url);
1144
+
1145
+ if( strlen($search_url) > 0 && strpos($search_url, trim($rule['value'])) !== false )
1146
+ return ($rule['operator'] == "==");
1147
+ else
1148
+ return !($rule['operator'] == "==");
1149
+
1150
+ }
1151
  }
public/views/popup.php CHANGED
@@ -76,7 +76,7 @@ do_action( 'spu/popup/before_popup', $box, $opts, $css);
76
  <div class="spu-box <?php echo apply_filters( 'spu/popup/box_class', $box_class, $opts, $css, $box );?> spu-<?php echo esc_attr( $opts['css']['position'] ); ?> spu-total-<?php echo get_post_meta($box->ID, 'spu_social',true);?> <?php echo get_post_meta($box->ID, 'spu_google',true) ? 'spu-gogl' : '';?>" id="spu-<?php echo $box->ID; ?>"
77
  data-box-id="<?php echo $box->ID ; ?>" data-trigger="<?php echo esc_attr( $opts['trigger'] ); ?>"
78
  data-trigger-number="<?php echo esc_attr( absint( $opts['trigger_number'] ) ); ?>"
79
- data-spuanimation="<?php echo esc_attr($opts['animation']); ?>" data-dconvert-cookie="<?php echo esc_attr( absint ( $opts['duration-convert-cookie'] ) ); ?>" data-dclose-cookie="<?php echo esc_attr( absint ( $opts['duration-close-cookie'] ) ); ?>" data-nconvert-cookie="<?php echo esc_attr( $opts['name-convert-cookie'] ); ?>" data-nclose-cookie="<?php echo esc_attr( $opts['name-close-cookie'] ); ?>" data-test-mode="<?php echo esc_attr($opts['test_mode']); ?>"
80
  data-auto-hide="<?php echo esc_attr($opts['auto_hide']); ?>" data-close-on-conversion="<?php echo $opts['conversion_close'] == 1 ?'1':''; ?>" data-bgopa="<?php echo esc_attr($css['bgopacity']);?>" data-total="<?php echo get_post_meta($box->ID, 'spu_social',true);?>"
81
  style="left:-99999px !important;right:auto;" data-width="<?php echo esc_attr(str_replace('px', '', $width)); ?>" <?php echo apply_filters( 'spu/popup/data_attrs', $data_attrs, $opts, $box );?>>
82
  <div class="spu-content"><?php echo $content; ?></div>
76
  <div class="spu-box <?php echo apply_filters( 'spu/popup/box_class', $box_class, $opts, $css, $box );?> spu-<?php echo esc_attr( $opts['css']['position'] ); ?> spu-total-<?php echo get_post_meta($box->ID, 'spu_social',true);?> <?php echo get_post_meta($box->ID, 'spu_google',true) ? 'spu-gogl' : '';?>" id="spu-<?php echo $box->ID; ?>"
77
  data-box-id="<?php echo $box->ID ; ?>" data-trigger="<?php echo esc_attr( $opts['trigger'] ); ?>"
78
  data-trigger-number="<?php echo esc_attr( absint( $opts['trigger_number'] ) ); ?>"
79
+ data-spuanimation="<?php echo esc_attr($opts['animation']); ?>" data-tconvert-cookie="<?php echo esc_attr( $opts['type-convert-cookie'] ); ?>" data-tclose-cookie="<?php echo esc_attr( $opts['type-close-cookie'] ); ?>" data-dconvert-cookie="<?php echo esc_attr( absint ( $opts['duration-convert-cookie'] ) ); ?>" data-dclose-cookie="<?php echo esc_attr( absint ( $opts['duration-close-cookie'] ) ); ?>" data-nconvert-cookie="<?php echo esc_attr( $opts['name-convert-cookie'] ); ?>" data-nclose-cookie="<?php echo esc_attr( $opts['name-close-cookie'] ); ?>" data-test-mode="<?php echo esc_attr($opts['test_mode']); ?>"
80
  data-auto-hide="<?php echo esc_attr($opts['auto_hide']); ?>" data-close-on-conversion="<?php echo $opts['conversion_close'] == 1 ?'1':''; ?>" data-bgopa="<?php echo esc_attr($css['bgopacity']);?>" data-total="<?php echo get_post_meta($box->ID, 'spu_social',true);?>"
81
  style="left:-99999px !important;right:auto;" data-width="<?php echo esc_attr(str_replace('px', '', $width)); ?>" <?php echo apply_filters( 'spu/popup/data_attrs', $data_attrs, $opts, $box );?>>
82
  <div class="spu-content"><?php echo $content; ?></div>