PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 4.4.4
Hustle – Email Marketing, Lead Generation, Optins, Popups v4.4.4
7.8.14.2 7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / popoverincludes / classes / popoverajax.php
wordpress-popup / popoverincludes / classes Last commit date
popover.help.php 13 years ago popoveradmin.php 13 years ago popoverajax.php 13 years ago popoverpublic.php 13 years ago
popoverajax.php
499 lines
1 <?php
2 /*
3 * The processing part of the popover plugin
4 * - was previously in popoverpublic.php
5 */
6
7 if(!class_exists('popoverajax')) {
8
9 class popoverajax {
10
11 var $mylocation = '';
12 var $build = 5;
13 var $db;
14
15 var $tables = array( 'popover', 'popover_ip_cache' );
16 var $popover;
17 var $popover_ip_cache;
18
19 var $activepopover = false;
20
21 function __construct() {
22
23 global $wpdb;
24
25 $this->db =& $wpdb;
26
27 foreach($this->tables as $table) {
28 $this->$table = popover_db_prefix($this->db, $table);
29 }
30
31 add_action('init', array(&$this, 'initialise_ajax'), 99);
32
33 add_action( 'plugins_loaded', array(&$this, 'load_textdomain'));
34
35 $directories = explode(DIRECTORY_SEPARATOR,dirname(__FILE__));
36 $this->mylocation = $directories[count($directories)-1];
37
38 }
39
40 function popoverajax() {
41 $this->__construct();
42 }
43
44 function initialise_ajax() {
45
46 $settings = get_popover_option('popover-settings', array( 'loadingmethod' => 'external'));
47
48 switch( $settings['loadingmethod'] ) {
49
50 case 'external': add_action( 'wp_ajax_popover_selective_ajax', array(&$this,'ajax_selective_message_display') );
51 add_action( 'wp_ajax_nopriv_popover_selective_ajax', array(&$this,'ajax_selective_message_display') );
52 break;
53
54 }
55
56 }
57
58 function load_textdomain() {
59
60 $locale = apply_filters( 'popover_locale', get_locale() );
61 $mofile = popover_dir( "popoverincludes/languages/popover-$locale.mo" );
62
63 if ( file_exists( $mofile ) )
64 load_textdomain( 'popover', $mofile );
65
66 }
67
68 function get_active_popovers() {
69 $sql = $this->db->prepare( "SELECT * FROM {$this->popover} WHERE popover_active = %d ORDER BY popover_order ASC", 1 );
70
71 return $this->db->get_results( $sql );
72 }
73
74 function ajax_selective_message_display() {
75
76 if(isset($_GET['callback'])) {
77 $data = $this->selective_message_display();
78 echo $_GET['callback'] . "(" . json_encode($data) . ")";
79 }
80
81 exit;
82
83 }
84
85 function selective_message_display() {
86
87 if(function_exists('get_site_option') && defined('PO_GLOBAL') && PO_GLOBAL == true) {
88 $updateoption = 'update_site_option';
89 $getoption = 'get_site_option';
90 } else {
91 $updateoption = 'update_option';
92 $getoption = 'get_option';
93 }
94
95 $popovers = $this->get_active_popovers();
96
97 if(!empty($popovers)) {
98
99 foreach( (array) $popovers as $popover ) {
100
101 // We have an active popover so extract the information and test it
102 $popover_title = stripslashes($popover->popover_title);
103 $popover_content = stripslashes($popover->popover_content);
104 $popover->popover_settings = unserialize($popover->popover_settings);
105
106 $popover_size = $popover->popover_settings['popover_size'];
107 $popover_location = $popover->popover_settings['popover_location'];
108 $popover_colour = $popover->popover_settings['popover_colour'];
109 $popover_margin = $popover->popover_settings['popover_margin'];
110
111 $popover_size = $this->sanitise_array($popover_size);
112 $popover_location = $this->sanitise_array($popover_location);
113 $popover_colour = $this->sanitise_array($popover_colour);
114 $popover_margin = $this->sanitise_array($popover_margin);
115
116 $popover_check = $popover->popover_settings['popover_check'];
117 $popover_ereg = $popover->popover_settings['popover_ereg'];
118 $popover_count = $popover->popover_settings['popover_count'];
119
120 $popover_usejs = $popover->popover_settings['popover_usejs'];
121
122 $popoverstyle = (isset($popover->popover_settings['popover_style'])) ? $popover->popover_settings['popover_style'] : '';
123
124 $popover_hideforever = (isset($popover->popover_settings['popoverhideforeverlink'])) ? $popover->popover_settings['popoverhideforeverlink'] : '';
125
126 $popover_delay = (isset($popover->popover_settings['popoverdelay'])) ? $popover->popover_settings['popoverdelay'] : '';
127
128 $popover_onurl = (isset($popover->popover_settings['onurl'])) ? $popover->popover_settings['onurl'] : '';
129 $popover_notonurl = (isset($popover->popover_settings['notonurl'])) ? $popover->popover_settings['notonurl'] : '';
130
131 $popover_incountry = (isset($popover->popover_settings['incountry'])) ? $popover->popover_settings['incountry'] : '';
132 $popover_notincountry = (isset($popover->popover_settings['notincountry'])) ? $popover->popover_settings['notincountry'] : '';
133
134 $popover_onurl = $this->sanitise_array($popover_onurl);
135 $popover_notonurl = $this->sanitise_array($popover_notonurl);
136
137 $show = true;
138
139 if(!empty($popover_check)) {
140
141 $order = explode(',', $popover_check['order']);
142
143 foreach($order as $key) {
144
145 switch ($key) {
146
147 case "supporter":
148 if(function_exists('is_pro_site') && is_pro_site()) {
149 $show = false;
150 }
151 break;
152
153 case "loggedin": if($this->is_loggedin()) {
154 $show = false;
155 }
156 break;
157
158 case "isloggedin": if(!$this->is_loggedin()) {
159 $show = false;
160 }
161 break;
162
163 case "commented": if($this->has_commented()) {
164 $show = false;
165 }
166 break;
167
168 case "searchengine":
169 if(!$this->is_fromsearchengine( $_REQUEST['thereferrer'] )) {
170 $show = false;
171 }
172 break;
173
174 case "internal": $internal = str_replace('^http://','',get_option('home'));
175 if($this->referrer_matches(addcslashes($internal,"/"), $_REQUEST['thereferrer'] )) {
176 $show = false;
177 }
178 break;
179
180 case "referrer": $match = $popover_ereg;
181 if(!$this->referrer_matches(addcslashes($match,"/"), $_REQUEST['thereferrer'])) {
182 $show = false;
183 }
184 break;
185
186 case "count": if($this->has_reached_limit($popover_count)) {
187 $show = false;
188 }
189 break;
190
191 case 'onurl': if(!$this->onurl( $popover_onurl, $_REQUEST['thefrom'] )) {
192 $show = false;
193 }
194 break;
195
196 case 'notonurl': if($this->onurl( $popover_notonurl, $_REQUEST['thefrom'] )) {
197 $show = false;
198 }
199 break;
200
201 case 'incountry': $incountry = $this->incountry( $popover_incountry );
202 if(!$incountry || $incountry === 'XX') {
203 $show = false;
204 }
205 break;
206
207 case 'notincountry':
208 $incountry = $this->incountry( $popover_notincountry );
209 if($incountry || $incountry === 'XX') {
210 $show = false;
211 }
212 break;
213
214 default: if(has_filter('popover_process_rule_' . $key)) {
215 if(!apply_filters( 'popover_process_rule_' . $key, false )) {
216 $show = false;
217 }
218 }
219 break;
220
221 }
222 }
223
224 // Check for forced popover and if set then output that one instead of any other
225 if(isset($_REQUEST['active_popover']) && (int) $_REQUEST['active_popover'] != 0) {
226 if($popover->id == (int) $_REQUEST['active_popover']) {
227 $show = true;
228 } else {
229 $show = false;
230 }
231 }
232 }
233
234 if($show == true) {
235
236 if($this->clear_forever()) {
237 $show = false;
238 }
239
240 }
241
242 if($show == true) {
243
244 // return the popover to the calling function
245
246 $popover = array();
247
248 $popover['name'] = 'a' . md5(date('d')) . '-po';
249
250 // Show the advert
251 if(!empty($popover_delay) && $popover_delay != 'immediate') {
252 // Set the delay
253 $popover['delay'] = $popover_delay * 1000;
254 } else {
255 $popover['delay'] = 0;
256 }
257
258 if($popover_usejs == 'yes') {
259 $popover['usejs'] = 'yes';
260 } else {
261 $popover['usejs'] = 'no';
262 }
263
264 $style = '';
265 $backgroundstyle = '';
266
267 if($popover_usejs == 'yes') {
268 $style = 'z-index:999999;';
269 $box = 'color: #' . $popover_colour['fore'] . '; background: #' . $popover_colour['back'] . ';';
270 $style .= 'left: -1000px; top: =100px;';
271 } else {
272 $style = 'left: ' . $popover_location['left'] . '; top: ' . $popover_location['top'] . ';' . ' z-index:999999;';
273 $style .= 'margin-top: ' . $popover_margin['top'] . '; margin-bottom: ' . $popover_margin['bottom'] . '; margin-right: ' . $popover_margin['right'] . '; margin-left: ' . $popover_margin['left'] . ';';
274
275 $box = 'width: ' . $popover_size['width'] . '; height: ' . $popover_size['height'] . '; color: #' . $popover_colour['fore'] . '; background: #' . $popover_colour['back'] . ';';
276
277 }
278
279 if(!empty($popover_delay) && $popover_delay != 'immediate') {
280 // Hide the popover initially
281 $style .= ' visibility: hidden;';
282 $backgroundstyle .= ' visibility: hidden;';
283 }
284
285 $availablestyles = apply_filters( 'popover_available_styles_directory', array() );
286
287 $popover['html'] = '';
288 if( in_array($popoverstyle, array_keys($availablestyles)) ) {
289 $popover_messagebox = 'a' . md5(date('d')) . '-po';
290
291 if(file_exists(trailingslashit($availablestyles[$popoverstyle]) . 'popover.php')) {
292 ob_start();
293 include_once( trailingslashit($availablestyles[$popoverstyle]) . 'popover.php' );
294 $popover['html'] = ob_get_contents();
295 ob_end_clean();
296 }
297 }
298
299 $availablestylesurl = apply_filters( 'popover_available_styles_url', array() );
300
301 $popover['style'] = '';
302 if( in_array($popoverstyle, array_keys($availablestyles)) ) {
303 // Add the styles
304 if(file_exists(trailingslashit($availablestyles[$popoverstyle]) . 'style.css')) {
305 ob_start();
306 include_once( trailingslashit($availablestyles[$popoverstyle]) . 'style.css' );
307 $content = ob_get_contents();
308 ob_end_clean();
309
310 $popover['style'] = str_replace('#messagebox', '#' . $popover_messagebox, $content);
311 $popover['style'] = str_replace('%styleurl%', trailingslashit($availablestylesurl[$popoverstyle]), $popover['style']);
312
313 }
314
315 }
316
317
318 // Add the cookie
319 if ( isset($_COOKIE['popover_view_'.COOKIEHASH]) ) {
320 $count = intval($_COOKIE['popover_view_'.COOKIEHASH]);
321 if(!is_numeric($count)) $count = 0;
322 $count++;
323 } else {
324 $count = 1;
325 }
326 if(!headers_sent()) setcookie('popover_view_'.COOKIEHASH, $count , time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
327
328
329 return $popover;
330 // Exit from the for - as we have sent a popover
331 break;
332 }
333 }
334
335 }
336
337 // There is no popover to show - so send back a no-popover message
338 return array( 'name' => 'nopopover' );
339
340
341 }
342
343 function sanitise_array($arrayin) {
344
345 foreach( (array) $arrayin as $key => $value) {
346 $arrayin[$key] = htmlentities(stripslashes($value) ,ENT_QUOTES, 'UTF-8');
347 }
348
349 return $arrayin;
350 }
351
352 function is_fromsearchengine( $ref = '') {
353
354 $SE = array('/search?', '.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.', '.bing.' );
355
356 foreach ($SE as $url) {
357 if (strpos( $ref, $url) !== false ) {
358 if($url == '.google.') {
359 if( $this->is_googlesearch( $ref) ) {
360 return true;
361 } else {
362 return false;
363 }
364 } else {
365 return true;
366 }
367 }
368 }
369 return false;
370 }
371
372 function is_googlesearch( $ref = '' ) {
373 $SE = array('.google.');
374
375 foreach ($SE as $url) {
376 if (strpos($ref,$url) !== false ) {
377 // We've found a google referrer - get the query strings and check its a web source
378 $qs = parse_url( $ref, PHP_URL_QUERY );
379 $qget = array();
380 foreach(explode('&', $qs) as $keyval) {
381 list( $key, $value ) = explode('=', $keyval);
382 $qget[ trim($key) ] = trim($value);
383 }
384 if(array_key_exists('source', $qget) && $qget['source'] == 'web') {
385 return true;
386 }
387 }
388 }
389 return false;
390 }
391
392 function is_ie()
393 {
394 if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
395 return true;
396 else
397 return false;
398 }
399
400 function is_loggedin() {
401 return is_user_logged_in();
402 }
403
404 function has_commented() {
405 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {
406 return true;
407 } else {
408 return false;
409 }
410 }
411
412 function referrer_matches($check, $referer = '') {
413
414 if(preg_match( '/' . $check . '/i', $referer )) {
415 return true;
416 } else {
417 return false;
418 }
419
420 }
421
422 function has_reached_limit($count = 3) {
423 if ( isset($_COOKIE['popover_view_'.COOKIEHASH]) && addslashes($_COOKIE['popover_view_'.COOKIEHASH]) >= $count ) {
424 return true;
425 } else {
426 return false;
427 }
428 }
429
430 function myURL() {
431
432 if ($_SERVER["HTTPS"] == "on") {
433 $url .= "https://";
434 } else {
435 $url = 'http://';
436 }
437
438 if ($_SERVER["SERVER_PORT"] != "80") {
439 $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
440 } else {
441 $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
442 }
443
444 return trailingslashit($url);
445 }
446
447 function onurl( $urllist = array(), $url = '' ) {
448
449 $urllist = array_map( 'trim', $urllist );
450
451 if(!empty($urllist)) {
452 foreach( $urllist as $ul ) {
453 if(preg_match( '#' . $ul . '#i', $url )) {
454 return true;
455 }
456 }
457 // if we are here then there hasn't been a match
458 return false;
459 } else {
460 return true;
461 }
462
463 }
464
465 function insertonduplicate($table, $data) {
466
467 global $wpdb;
468
469 $fields = array_keys($data);
470 $formatted_fields = array();
471 foreach ( $fields as $field ) {
472 $form = '%s';
473 $formatted_fields[] = $form;
474 }
475 $sql = "INSERT INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";
476 $sql .= " ON DUPLICATE KEY UPDATE ";
477
478 $dup = array();
479 foreach($fields as $field) {
480 $dup[] = "`" . $field . "` = VALUES(`" . $field . "`)";
481 }
482
483 $sql .= implode(',', $dup);
484
485 return $wpdb->query( $wpdb->prepare( $sql, $data) );
486 }
487
488 function clear_forever() {
489 if ( isset($_COOKIE['popover_never_view']) ) {
490 return true;
491 } else {
492 return false;
493 }
494 }
495
496 }
497
498 }
499 ?>