PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.4
Advanced Ads – Ad Manager & AdSense v1.8.4
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 / visitor-conditions.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 8 years ago ad-ajax.php 8 years ago ad-debug.php 8 years ago ad-model.php 8 years ago ad-select.php 9 years ago ad.php 8 years ago ad_ajax_callbacks.php 8 years ago ad_group.php 8 years ago ad_placements.php 8 years ago ad_type_abstract.php 11 years ago ad_type_content.php 8 years ago ad_type_dummy.php 8 years ago ad_type_group.php 8 years ago ad_type_image.php 8 years ago ad_type_plain.php 8 years ago checks.php 8 years ago display-conditions.php 8 years ago filesystem.php 8 years ago frontend_checks.php 8 years ago plugin.php 8 years ago upgrades.php 8 years ago utils.php 8 years ago visitor-conditions.php 8 years ago widget.php 8 years ago
visitor-conditions.php
373 lines
1 <?php
2
3 /**
4 * visitor conditions under which to (not) show an ad
5 *
6 * @since 1.5.4
7 *
8 */
9 class Advanced_Ads_Visitor_Conditions {
10
11 /**
12 *
13 * @var Advanced_Ads_Visitor_Conditions
14 */
15 protected static $instance;
16
17 /**
18 * registered visitor conditions
19 */
20 public $conditions;
21
22 /**
23 * start of name in form elements
24 */
25 const FORM_NAME = 'advanced_ad[visitors]';
26
27 public function __construct() {
28
29 // register conditions
30 $this->conditions = apply_filters( 'advanced-ads-visitor-conditions', array(
31 'mobile' => array( // type of the condition
32 'label' => __( 'device', 'advanced-ads' ),
33 'description' => __( 'Display ads only on mobile devices or hide them.', 'advanced-ads' ),
34 'metabox' => array( 'Advanced_Ads_Visitor_Conditions', 'mobile_is_or_not' ), // callback to generate the metabox
35 'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_mobile' ), // callback for frontend check
36 'helplink' => ADVADS_URL . 'manual/display-ads-either-on-mobile-or-desktop/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor-mobile' // link to help section
37 ),
38 'loggedin' => array(
39 'label' => __( 'logged in visitor', 'advanced-ads' ),
40 'description' => __( 'Whether the visitor has to be logged in or not in order to see the ads.', 'advanced-ads' ),
41 'metabox' => array( 'Advanced_Ads_Visitor_Conditions', 'metabox_is_or_not' ), // callback to generate the metabox
42 'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_logged_in' ) // callback for frontend check
43 ),
44 ));
45
46 ksort( $this->conditions );
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 * callback to render the mobile condition using the "is not" condition
64 *
65 * @param arr $options options of the condition
66 * @param int $index index of the condition
67 */
68 static function mobile_is_or_not( $options, $index = 0 ){
69
70 if ( ! isset ( $options['type'] ) || '' === $options['type'] ) { return; }
71
72 $type_options = self::get_instance()->conditions;
73
74 if ( ! isset( $type_options[ $options['type'] ] ) ) {
75 return;
76 }
77
78 // form name basis
79 $name = self::FORM_NAME . '[' . $index . ']';
80
81 // options
82 $operator = isset( $options['operator'] ) ? $options['operator'] : 'is';
83
84 ?><input type="hidden" name="<?php echo $name; ?>[type]" value="<?php echo $options['type']; ?>"/>
85 <select name="<?php echo $name; ?>[operator]">
86 <option value="is" <?php selected( 'is', $operator ); ?>><?php _e( 'Mobile (including tablets)', 'advanced-ads' ); ?></option>
87 <option value="is_not" <?php selected( 'is_not', $operator ); ?>><?php _e( 'Desktop', 'advanced-ads' ); ?></option>
88 </select>
89 <p class="description"><?php echo $type_options[ $options['type'] ]['description'];
90 if( isset( $type_options[ $options['type'] ]['helplink'] ) ) : ?>
91 <a href="<?php echo $type_options[ $options['type'] ]['helplink']; ?>" target="_blank"><?php
92 _e( 'Manual and Troubleshooting', 'advanced-ads' );
93 ?></a><?php endif; ?></p><?php
94
95 if ( ! isset ( $options['type'] ) || '' === $options['type'] ) { return; }
96
97 if( ! defined( 'AAR_SLUG' ) ){
98 echo '<p>' . sprintf(__( 'Display ads by the available space on the device or target tablets with the <a href="%s" target="_blank">Responsive add-on</a>', 'advanced-ads' ), ADVADS_URL . 'add-ons/responsive-ads/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor-responsive') . '</p>';
99 }
100 }
101
102 /**
103 * callback to display the "is not" condition
104 *
105 * @param arr $options options of the condition
106 * @param int $index index of the condition
107 */
108 static function metabox_is_or_not( $options, $index = 0 ){
109
110 if ( ! isset ( $options['type'] ) || '' === $options['type'] ) { return; }
111
112 $type_options = self::get_instance()->conditions;
113
114 if ( ! isset( $type_options[ $options['type'] ] ) ) {
115 return;
116 }
117
118 // form name basis
119 $name = self::FORM_NAME . '[' . $index . ']';
120
121 // options
122 $operator = isset( $options['operator'] ) ? $options['operator'] : 'is';
123
124 ?><input type="hidden" name="<?php echo $name; ?>[type]" value="<?php echo $options['type']; ?>"/>
125 <select name="<?php echo $name; ?>[operator]">
126 <option value="is" <?php selected( 'is', $operator ); ?>><?php _e( 'is', 'advanced-ads' ); ?></option>
127 <option value="is_not" <?php selected( 'is_not', $operator ); ?>><?php _e( 'is not', 'advanced-ads' ); ?></option>
128 </select>
129 <p class="description"><?php echo $type_options[ $options['type'] ]['description'];
130 if( isset( $type_options[ $options['type'] ]['helplink'] ) ) : ?>
131 <a href="<?php echo $type_options[ $options['type'] ]['helplink']; ?>" target="_blank"><?php
132 _e( 'Manual and Troubleshooting', 'advanced-ads' );
133 ?></a><?php endif; ?></p><?php
134 }
135
136 /**
137 * callback to display the any condition based on a number
138 *
139 * @param arr $options options of the condition
140 * @param int $index index of the condition
141 */
142 static function metabox_number( $options, $index = 0 ){
143
144 if ( ! isset ( $options['type'] ) || '' === $options['type'] ) { return; }
145
146 $type_options = self::get_instance()->conditions;
147
148 if ( ! isset( $type_options[ $options['type'] ] ) ) {
149 return;
150 }
151
152 // form name basis
153 $name = self::FORM_NAME . '[' . $index . ']';
154
155 // options
156 $value = isset( $options['value'] ) ? $options['value'] : 0;
157 $operator = isset( $options['operator'] ) ? $options['operator'] : 'is_equal';
158
159 ?><input type="hidden" name="<?php echo $name; ?>[type]" value="<?php echo $options['type']; ?>"/>
160 <select name="<?php echo $name; ?>[operator]">
161 <option value="is_equal" <?php selected( 'is_equal', $operator ); ?>><?php _e( 'equal', 'advanced-ads' ); ?></option>
162 <option value="is_higher" <?php selected( 'is_higher', $operator ); ?>><?php _e( 'equal or higher', 'advanced-ads' ); ?></option>
163 <option value="is_lower" <?php selected( 'is_lower', $operator ); ?>><?php _e( 'equal or lower', 'advanced-ads' ); ?></option>
164 </select><input type="number" name="<?php echo $name; ?>[value]" value="<?php echo absint( $value ); ?>"/>
165 <p class="description"><?php echo $type_options[ $options['type'] ]['description']; ?></p><?php
166 }
167
168 /**
169 * callback to display the any condition based on a number
170 *
171 * @param arr $options options of the condition
172 * @param int $index index of the condition
173 */
174 static function metabox_string( $options, $index = 0 ){
175
176 if ( ! isset ( $options['type'] ) || '' === $options['type'] ) { return; }
177
178 $type_options = self::get_instance()->conditions;
179
180 if ( ! isset( $type_options[ $options['type'] ] ) ) {
181 return;
182 }
183
184 // form name basis
185 $name = self::FORM_NAME . '[' . $index . ']';
186
187 // options
188 $value = isset( $options['value'] ) ? $options['value'] : '';
189 $operator = isset( $options['operator'] ) ? $options['operator'] : 'contains';
190
191 ?><input type="hidden" name="<?php echo $name; ?>[type]" value="<?php echo $options['type']; ?>"/>
192 <div class="advads-condition-line-wrap">
193 <select name="<?php echo $name; ?>[operator]">
194 <option value="contain" <?php selected( 'contain', $operator ); ?>><?php _e( 'contains', 'advanced-ads' ); ?></option>
195 <option value="start" <?php selected( 'start', $operator ); ?>><?php _e( 'starts with', 'advanced-ads' ); ?></option>
196 <option value="end" <?php selected( 'end', $operator ); ?>><?php _e( 'ends with', 'advanced-ads' ); ?></option>
197 <option value="match" <?php selected( 'match', $operator ); ?>><?php _e( 'matches', 'advanced-ads' ); ?></option>
198 <option value="regex" <?php selected( 'regex', $operator ); ?>><?php _e( 'matches regex', 'advanced-ads' ); ?></option>
199 <option value="contain_not" <?php selected( 'contain_not', $operator ); ?>><?php _e( 'does not contain', 'advanced-ads' ); ?></option>
200 <option value="start_not" <?php selected( 'start_not', $operator ); ?>><?php _e( 'does not start with', 'advanced-ads' ); ?></option>
201 <option value="end_not" <?php selected( 'end_not', $operator ); ?>><?php _e( 'does not end with', 'advanced-ads' ); ?></option>
202 <option value="match_not" <?php selected( 'match_not', $operator ); ?>><?php _e( 'does not match', 'advanced-ads' ); ?></option>
203 <option value="regex_not" <?php selected( 'regex_not', $operator ); ?>><?php _e( 'does not match regex', 'advanced-ads' ); ?></option>
204 </select><input type="text" name="<?php echo $name; ?>[value]" value="<?php echo $value; ?>"/>
205 </div>
206 <p class="description"><?php echo $type_options[ $options['type'] ]['description']; ?></p><?php
207 }
208
209 /**
210 * controls frontend checks for conditions
211 *
212 * @param arr $options options of the condition
213 * @param ob $ad Advanced_Ads_Ad
214 * @return bool false, if ad can’t be delivered
215 */
216 static function frontend_check( $options = array(), $ad = false ){
217 $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
218
219 if ( is_array( $options ) && isset( $visitor_conditions[ $options['type'] ]['check'] ) ) {
220 $check = $visitor_conditions[ $options['type'] ]['check'];
221 } else {
222 return true;
223 }
224
225 // call frontend check callback
226 if ( method_exists( $check[0], $check[1] ) ) {
227 return call_user_func( array( $check[0], $check[1] ), $options, $ad );
228 }
229
230 return true;
231 }
232
233 /**
234 * render connector option
235 *
236 * @since 1.7.0.4
237 * @param int $index
238 */
239 static function render_connector_option( $index = 0, $value = 'or' ){
240
241 $label = ( $value === 'or' ) ? __( 'or', 'advanced-ads' ) : __( 'and', 'advanced-ads' );
242
243 return '<input type="checkbox" name="' . self::FORM_NAME . '[' . $index . '][connector]' . '" value="or" id="advads-visitor-conditions-' .
244 $index . '-connector"' .
245 checked( 'or', $value, false )
246 .'><label for="advads-visitor-conditions-' . $index . '-connector">' . $label . '</label>';
247 }
248
249 /**
250 * check mobile visitor condition in frontend
251 *
252 * @param arr $options options of the condition
253 * @return bool true if can be displayed
254 */
255 static function check_mobile( $options = array() ){
256
257 if ( ! isset( $options['operator'] ) ) {
258 return true;
259 }
260
261 switch ( $options['operator'] ){
262 case 'is' :
263 if ( ! wp_is_mobile() ) { return false; }
264 break;
265 case 'is_not' :
266 if ( wp_is_mobile() ) { return false; }
267 break;
268 }
269
270 return true;
271 }
272
273 /**
274 * check mobile visitor condition in frontend
275 *
276 * @since 1.6.3
277 * @param arr $options options of the condition
278 * @return bool true if can be displayed
279 */
280 static function check_logged_in( $options = array() ){
281
282 if ( ! isset( $options['operator'] ) ) {
283 return true;
284 }
285
286 switch ( $options['operator'] ){
287 case 'is' :
288 if ( ! is_user_logged_in() ) { return false; }
289 break;
290 case 'is_not' :
291 if ( is_user_logged_in() ) { return false; }
292 break;
293 }
294
295 return true;
296 }
297
298 /**
299 * helper for check with strings
300 *
301 * @since 1.6.3
302 * @param str $string string that is going to be checked
303 * @return bool true if ad can be displayed
304 */
305 static function helper_check_string( $string = '', $options = array() ){
306
307 if ( ! isset( $options['operator'] ) || ! isset( $options['value'] ) || '' === $options['value'] ){
308 return true;
309 }
310
311 $operator = $options['operator'];
312 $value = $options['value'];
313
314 // check the condition by mode and bool
315 $condition = true;
316 switch ( $operator ){
317 // referrer contains string on any position
318 case 'contain' :
319 $condition = stripos( $string, $value ) !== false;
320 break;
321 // referrer does not contain string on any position
322 case 'contain_not' :
323 $condition = stripos( $string, $value ) === false;
324 break;
325 // referrer starts with the string
326 case 'start' :
327 $condition = stripos( $string, $value ) === 0;
328 break;
329 // referrer does not start with the string
330 case 'start_not' :
331 $condition = stripos( $string, $value ) !== 0;
332 break;
333 // referrer ends with the string
334 case 'end' :
335 $condition = $value === substr( $string, -strlen( $value ) );
336 break;
337 // referrer does not end with the string
338 case 'end_not' :
339 $condition = $value !== substr( $string, -strlen( $value ) );
340 break;
341 // referrer is equal to the string
342 case 'match' :
343 // strings do match, but should not or not match but should
344 $condition = strcasecmp($value, $string) === 0;
345 break;
346 // referrer is not equal to the string
347 case 'match_not' :
348 // strings do match, but should not or not match but should
349 $condition = strcasecmp($value, $string) !== 0;
350 break;
351 // string is a regular expression
352 case 'regex' :
353 // check regular expression first
354 if( @preg_match( $value, null ) === false ){
355 Advanced_Ads::log( "Advanced Ads: regular expression '$value' in visitor condition is broken." );
356 } else {
357 $condition = preg_match( $value, $string );
358 }
359 break;
360 // string is not a regular expression
361 case 'regex_not' :
362 if( @preg_match( $value, null ) === false ){
363 Advanced_Ads::log( "Advanced Ads: regular expression '$value' in visitor condition is broken." );
364 } else {
365 $condition = ! preg_match( $value, $string );
366 }
367 break;
368 }
369
370 return $condition;
371 }
372 }
373