· 4 years ago · Feb 25, 2021, 03:14 PM
1<?php
2/*
3 Plugin Name: Ninja Popups
4 Plugin URI: http://codecanyon.net/item/ninja-popups-for-wordpress/3476479?ref=arscode
5 Description: Awesome Popups for Your WordPress!
6 Version: 4.6.4
7 Author: ArsCode
8 Author URI: http://www.arscode.pro/
9 */
10if (!defined('ABSPATH')) {
11 die('-1');
12}
13
14define('SNP_VERSION', '4.6.4');
15define('SNP_OPTIONS', 'snp');
16define('SNP_DB_VER', '1.3');
17define('SNP_LIBRARY_DIR', 'ninja-popups/');
18define('SNP_DEMO_LIBRARY_URL', 'http://demo.arscode.pro/ninja-popups/wp-content/uploads/sites/2/ninja-popups/');
19define('SNP_DEMO_LIBRARY_URL_2', '/ninja-popups/wp-content/uploads/sites/2/ninja-popups/');
20define('SNP_DEMO_LIBRARY_URL_3', '/wp-content/uploads/sites/2/ninja-popups/');
21define('SNP_URL', plugins_url('/', __FILE__));
22define('SNP_DIR_PATH', plugin_dir_path(__FILE__));
23define('SNP_PROMO_LINK', 'http://codecanyon.net/item/ninja-popups-for-wordpress/3476479?ref=');
24DEFINE('SNP_API_URL', 'http://updates.arscode.pro/');
25
26$snp_options = array();
27$snp_popups = array();
28
29if (is_admin()) {
30 require_once(plugin_dir_path(__FILE__) . '/admin/options.php');
31 require_once(plugin_dir_path(__FILE__) . '/admin/init.php');
32 require_once(plugin_dir_path(__FILE__) . '/admin/updates.php');
33 require_once(plugin_dir_path(__FILE__) . '/include/lists.inc.php');
34}
35
36require_once(plugin_dir_path(__FILE__) . '/include/Mobile_Detect.php');
37require_once(plugin_dir_path(__FILE__) . '/include/country.inc.php');
38require_once(plugin_dir_path(__FILE__) . '/include/fonts.inc.php');
39require_once(plugin_dir_path(__FILE__) . '/include/functions.inc.php');
40require_once(plugin_dir_path(__FILE__) . '/include/snp_links.inc.php');
41
42/**
43 * Autload our custom classes
44 */
45spl_autoload_register(function($className) {
46 $directories = [
47 plugin_dir_path(__FILE__) . '/src/'
48 ];
49
50 foreach ($directories as $directory) {
51 $fileName = $directory . str_replace('\\', '/', $className) . '.php';
52
53 if (file_exists($fileName)) {
54 require_once $fileName;
55 }
56 }
57});
58
59/**
60 * Detect Country, Zip Code and City Code for GeoIP pop-up's
61 */
62$countryCode = null;
63$zipCode = null;
64$cityCode = null;
65if ((int)snp_get_option('geoip_popup') === 1) {
66 $countryCode = getXwebCountryCode();
67 $zipCode = getZipCode();
68 $cityCode = getCityCode();
69}
70
71/**
72 * Load filters that are used to subscribe client to mailing list manager
73 */
74foreach(glob(plugin_dir_path(__FILE__) . '/filters/*.php') as $file) {
75 require_once $file;
76}
77
78$detect = new Snp_Mobile_Detect;
79
80/**
81 * Run common integration tasks
82 */
83$integration = new \Relio\Integration();
84$integration->run();
85
86/**
87 * Setup front controller
88 */
89
90
91/**
92 * @param $opt_name
93 * @param null $default
94 * @return |null
95 */
96function snp_get_option($opt_name, $default = null)
97{
98 global $snp_options;
99
100 if (!$snp_options) {
101 $snp_options = get_option(SNP_OPTIONS);
102 }
103
104 return (!empty($snp_options[$opt_name])) ? $snp_options[$opt_name] : $default;
105}
106
107global $snp_ignore_cookies;
108
109$SNP_THEMES = array();
110$SNP_THEMES_DIR_2 = apply_filters('snp_themes_dir_2', '');
111$SNP_THEMES_DIR = apply_filters('snp_themes_dir', array(plugin_dir_path(__FILE__) . '/themes/', $SNP_THEMES_DIR_2));
112
113function snp_popup_submit()
114{
115 global $wpdb;
116
117 $result = array();
118 $errors = array();
119
120 $post_id = intval($_POST['popup_ID']);
121 if ($post_id) {
122 $POPUP_META = get_post_meta($post_id);
123 echo '1';
124 echo $POPUP_META;
125 }
126
127 $cf_data = array();
128
129 $POPUP_META['snp_theme'] = unserialize($POPUP_META['snp_theme'][0]);
130 if (!isset($POPUP_META['snp_theme']['mode'])) {
131 $POPUP_META['snp_theme']['mode'] = 0;
132 }
133
134 if ($POPUP_META['snp_theme']['mode'] == 0) {
135 if (isset($_POST['email'])) {
136 $_POST['email'] = snp_trim($_POST['email']);
137 }
138
139 if (isset($_POST['name'])) {
140 $_POST['name'] = trim($_POST['name']);
141 }
142
143 if (!snp_is_valid_email($_POST['email'])) {
144 $errors['email'] = __('This is not valid e-mail address', 'nhp-opts');
145 }
146
147 if (isset($_POST['email']) && !$_POST['email']) {
148 $errors['email'] = __('This field is required', 'nhp-opts');
149 }
150 }
151
152 require_once(plugin_dir_path(__FILE__) . '/include/recaptcha/src/autoload.php');
153
154 if (snp_get_option('recaptcha_secret_key')) {
155 $recaptcha = new \ReCaptcha\ReCaptcha(snp_get_option('recaptcha_secret_key'));
156 }
157
158 if (
159 isset($POPUP_META['snp_bld_cf']) &&
160 $POPUP_META['snp_theme']['mode'] == 1 &&
161 $post_id
162 ) {
163
164 $POPUP_META['snp_bld_cf'] = unserialize($POPUP_META['snp_bld_cf'][0]);
165
166 foreach ((array) $POPUP_META['snp_bld_cf'] as $f) {
167 if ($f['type'] == 'captcha' && snp_get_option('recaptcha_secret_key')) {
168 $resp = $recaptcha->verify($_POST['ninja_popup_recaptcha_response'], $_SERVER['REMOTE_ADDR']);
169 if (!$resp->isSuccess()) {
170 if ($f['validation_message']) {
171 $errors['captcha'] = $f['validation_message'];
172 } else {
173 $errors['captcha'] = 1;
174 }
175 }
176 } else if ($f['type'] == 'file') {
177 if (!empty($_FILES)) {
178 if (
179 isset($_FILES[$f['name']]) &&
180 ($uploadResult = snp_upload_file($_FILES[$f['name']]))
181 ) {
182 $cf_data[$f['name']] = $uploadResult;
183 }
184 }
185
186 if (
187 isset($f['required']) &&
188 $f['required'] == 1 &&
189 !$cf_data[$f['name']]
190 ) {
191 if ($f['validation_message']) {
192 $errors[$f['name']] = $f['validation_message'];
193 } else {
194 $errors[$f['name']] = __('This field is required', 'nhp-opts');
195 }
196 }
197 } else {
198 if ($f['name-type'] != '') {
199 $f['name'] = $f['name-type'];
200 }
201
202 if (isset($f['mailchimp_group']) && !empty($f['mailchimp_group'])) {
203 if (!empty($_POST['mcgroups'][$f['name']])) {
204 $cf_data['mcgroups'][$f['name']] = $_POST['mcgroups'][$f['name']];
205 }
206
207 if (
208 isset($f['required']) &&
209 $f['required'] == 1 &&
210 (
211 !isset($cf_data['mcgroups'][$f['name']]) ||
212 !$cf_data['mcgroups'][$f['name']]
213 )
214 ) {
215 if ($f['validation_message']) {
216 $errors[$f['name']] = $f['validation_message'];
217 } else {
218 $errors[$f['name']] = __('This field is required', 'nhp-opts');
219 }
220 }
221 } else {
222 if (strpos($f['name'], '[')) {
223 $f['name'] = substr($f['name'], 0, strpos($f['name'], '['));
224 }
225
226 if (!empty($_POST[$f['name']])) {
227 $cf_data[$f['name']] = snp_trim($_POST[$f['name']]);
228 }
229
230 if (
231 isset($f['required']) &&
232 $f['required'] == 1 &&
233 !$cf_data[$f['name']]
234 ) {
235 if ($f['validation_message']) {
236 $errors[$f['name']] = $f['validation_message'];
237 } else {
238 $errors[$f['name']] = __('This field is required', 'nhp-opts');
239 }
240 }
241
242 if (
243 isset($f['required']) &&
244 $f['required'] == 1 &&
245 $f['name'] == 'email'
246 ) {
247 if (!snp_is_valid_email($_POST[$f['name']])) {
248 if ($f['validation_message']) {
249 $errors[$f['name']] = $f['validation_message'];
250 } else {
251 $errors[$f['name']] = __('This is not valid e-mail address', 'nhp-opts');
252 }
253 }
254 }
255 }
256
257 if (in_array($f['name'],array('email','name'))) {
258 unset($cf_data[$f['name']]);
259 }
260 }
261 }
262 }
263
264 if (
265 isset($POPUP_META['snp_cf']) &&
266 $POPUP_META['snp_theme']['mode'] == 0 &&
267 $post_id
268 ) {
269 $cf = unserialize($POPUP_META['snp_cf'][0]);
270
271 if (isset($cf) && is_array($cf)) {
272 foreach ($cf as $f) {
273 if (mb_strtolower($f['type']) == 'file') {
274 if (!empty($_FILES)) {
275 if (
276 isset($_FILES[$f['name']]) &&
277 ($uploadResult = snp_upload_file($_FILES[$f['name']]))
278 ) {
279 $cf_data[$f['name']] = $uploadResult;
280 }
281 }
282
283 if (
284 isset($f['required']) &&
285 $f['required'] == 1 &&
286 !$cf_data[$f['name']]
287 ) {
288 $errors[$f['name']] = __('This field is required', 'nhp-opts');
289 }
290 } else {
291 if (isset($f['name'])) {
292 if (strpos($f['name'], '[')) {
293 $f['name'] = substr($f['name'], 0, strpos($f['name'], '['));
294 }
295
296 if (!empty($_POST[$f['name']])) {
297 $cf_data[$f['name']] = snp_trim($_POST[$f['name']]);
298 }
299 }
300
301 if (isset($f['required']) && $f['required'] == 'Yes' && !$cf_data[$f['name']]) {
302 $errors[$f['name']] = __('This field is required', 'nhp-opts');
303 }
304 }
305 }
306 }
307 }
308
309 if (isset($_POST['full_phone'])) {
310 $cf_data['full_phone'] = $_POST['full_phone'];
311 }
312
313 if (isset($_POST['np_custom_name1']) && !empty($_POST['np_custom_name1'])) {
314 $errors['np_custom_name1'] = __('Spam detected!', 'nhp-opts');
315 }
316
317 if (isset($_POST['np_custom_name2']) && $_POST['np_custom_name2'] !== '1') {
318 $errors['np_custom_name2'] = __('Spam detected!', 'nhp-opts');
319 }
320
321 if (count($errors) > 0) {
322 $result['Errors'] = $errors;
323 $result['Ok'] = false;
324 } else {
325 $Done = 0;
326 if (!empty($_POST['name'])) {
327 $names = snp_detect_names($_POST['name']);
328 } else {
329 $names = array('first' => '', 'last' => '');
330 }
331
332 $api_error_msg = '';
333
334 $ml_manager = snp_get_option('ml_manager');
335 if(isset($POPUP_META['snp_ml_send_by_email'][0]) && $POPUP_META['snp_ml_send_by_email'][0] == 1) {
336 $ml_manager = "email";
337 }
338
339 $filterAndActionData = array(
340 'popup_meta' => $POPUP_META,
341 'data' => array(
342 'post' => $_POST,
343 'names' => $names,
344 'cf' => $cf_data,
345 )
346 );
347
348 do_action('ninja_popups_send_form', $filterAndActionData);
349
350 $log_list_id = '';
351 if ($ml_manager != 'email') {
352 if (has_filter('ninja_popups_subscribe_by_' . $ml_manager)) {
353 $response = apply_filters('ninja_popups_subscribe_by_' . $ml_manager, $filterAndActionData);
354
355 $log_list_id = $response['log']['listId'];
356 if ($response['status'] === true) {
357 $Done = 1;
358 if (isset($response['drip'])) {
359 $result['drip'] = $response['drip'];
360 }
361
362 //Integration with Metrilo
363 $useMetrilo = isset($filterAndActionData['popup_meta']['snp_ml_use_metrilo'][0]) ? $filterAndActionData['popup_meta']['snp_ml_use_metrilo'][0] : false;
364 if (!$useMetrilo) {
365 $useMetrilo = snp_get_option('use_metrilo');
366 }
367
368 if ($useMetrilo) {
369 $metriloTagsSettings = isset($filterAndActionData['popup_meta']['snp_ml_metrilo_tags']) ? unserialize($filterAndActionData['popup_meta']['snp_ml_metrilo_tags']) : null;
370 if (!$metriloTagsSettings) {
371 $metriloTagsSettings = snp_get_option('ml_metrilo_tags');
372 }
373
374 $metriloTags = [];
375 if ($metriloTagsSettings) {
376 foreach ($metriloTagsSettings as $t) {
377 $metriloTags[] = $t;
378 }
379 }
380
381 $result['metrilo'] = [
382 'email' => snp_trim($filterAndActionData['data']['post']['email']),
383 'subscribed' => true,
384 'tags' => $metriloTags
385 ];
386
387 if (!empty($filterAndActionData['data']['post']['name'])) {
388 $result['metrilo'] = array_merge($result['metrilo'], [
389 'first_name' => $filterAndActionData['data']['names']['first'],
390 'last_name' => $filterAndActionData['data']['names']['last']
391 ]);
392 }
393
394 if (count($filterAndActionData['data']['cf']) > 0) {
395 $result['metrilo'] = array_merge($result['metrilo'], (array) $filterAndActionData['data']['cf']);
396 }
397
398 $result['metrilo'] = json_encode($result['metrilo']);
399
400 }
401 ///Integration with Metrilo
402
403 do_action('ninja_popups_send_form_success', $filterAndActionData);
404 } else {
405 $api_error_msg = $response['log']['errorMessage'];
406
407 do_action('ninja_popups_send_form_error', $filterAndActionData);
408 }
409 } else {
410 $api_error_msg = 'Mailing List Manager with name ' . $ml_manager . ' is not defined';
411
412 do_action('ninja_popups_send_form_error', $filterAndActionData);
413 }
414 }
415
416 if ($ml_manager == 'email' || !$Done) {
417 $Email = snp_get_option('ml_email');
418
419 if (isset($POPUP_META['snp_ml_email']) && !empty($POPUP_META['snp_ml_email'])) {
420 $Email = $POPUP_META['snp_ml_email'];
421 }
422
423 if (!$Email) {
424 $Email = get_bloginfo('admin_email');
425 }
426
427 if (is_array($Email)) {
428 $recipients = $Email;
429 } else {
430 $recipients = explode(',', $Email);
431 }
432
433 if (!isset($_POST['name'])) {
434 $_POST['name'] = '--';
435 }
436
437 $error_mgs = '';
438 if ($api_error_msg != '') {
439 $error_mgs.="IMPORTANT! You have received this message because connection to your e-mail marketing software failed. Please check connection setting in the plugin configuration.\n";
440 $error_mgs.=$api_error_msg . "\n";
441 }
442
443 $cf_msg = '';
444 if (count($cf_data) > 0) {
445 foreach ($cf_data as $k => $v) {
446 $cf_msg .= $k . ": " . $v . "\r\n";
447 }
448 }
449
450 $msg = "New subscription on " . get_bloginfo() . "\r\n" .
451 $error_mgs .
452 "\r\n" .
453 "E-mail: " . snp_trim($_POST['email']) . "\r\n" .
454 "\r\n" .
455 "Name: " . $_POST['name'] . "\r\n" .
456 "\r\n" .
457 $cf_msg .
458 "\r\n" .
459 "Form: " . get_the_title($_POST['popup_ID']) . " (" . $_POST['popup_ID'] . ")\r\n" .
460 "\r\n" .
461 "\r\n" .
462 "Referer: " . $_SERVER['HTTP_REFERER'] . "\r\n" .
463 "\r\n" .
464 "Date: " . date('Y-m-d H:i') . "\r\n" .
465 "\r\n" .
466 "IP: " . $_SERVER['REMOTE_ADDR'] . "";
467
468 if (isset($_POST['name']) && isset($_POST['email'])) {
469 $headers[] = 'Reply-To: ' . $_POST['name'] . ' <'.$_POST['email'].'>';
470 }
471
472 $subject = "New subscription on " . get_bloginfo();
473 if (snp_get_option('email_notify_subject')) {
474 $subject = snp_get_option('email_notify_subject');
475 }
476
477 foreach ($recipients as $emailRecipient) {
478 wp_mail($emailRecipient, $subject, $msg, $headers);
479 }
480 }
481
482 if ((snp_get_option('enable_log_gathering') == 'yes') && (snp_get_option('enable_log_g_subscribe') == 'yes')) {
483 snp_update_log_subscription($cf_data, $log_list_id, $api_error_msg);
484 }
485
486 $result['api_error_msg'] = $api_error_msg;
487 $result['Ok'] = true;
488 }
489
490 echo json_encode($result);
491 die('');
492}
493
494function snp_popup_stats()
495{
496 global $wpdb;
497
498 $table_name = $wpdb->prefix . "snp_stats";
499 $ab_id = intval($_POST['ab_ID']);
500 $post_id = intval($_POST['popup_ID']);
501
502 if (current_user_can('manage_options')) {
503 // die('');
504 }
505
506 if ($post_id > 0) {
507 if ($_POST['type'] == 'view') {
508 $count = get_post_meta($post_id, 'snp_views');
509 if (!$count || !$count[0])
510 $count[0] = 0;
511 update_post_meta($post_id, 'snp_views', $count[0] + 1);
512 if ($ab_id)
513 {
514 $count = get_post_meta($ab_id, 'snp_views');
515 if (!$count || !$count[0])
516 $count[0] = 0;
517 update_post_meta($ab_id, 'snp_views', $count[0] + 1);
518 }
519 if((snp_get_option('enable_log_gathering') == 'yes') && (snp_get_option('enable_log_g_view') == 'yes'))
520 {
521 snp_update_log_popup($post_id);
522 }
523 $wpdb->query("insert into $table_name (`date`,`ID`,`AB_ID`,imps) values (CURDATE(),$post_id,$ab_id,1) on duplicate key update imps = imps + 1;");
524 echo 'ok: view';
525 } else {
526 $count = get_post_meta($post_id, 'snp_conversions');
527 if (!$count || !$count[0])
528 $count[0] = 0;
529 update_post_meta($post_id, 'snp_conversions', $count[0] + 1);
530 if ($ab_id)
531 {
532 $count = get_post_meta($ab_id, 'snp_conversions');
533 if (!$count || !$count[0])
534 $count[0] = 0;
535 update_post_meta($ab_id, 'snp_conversions', $count[0] + 1);
536 }
537 $wpdb->query("insert into $table_name (`date`,`ID`,`AB_ID`,convs) values (CURDATE(),$post_id,$ab_id,1) on duplicate key update convs = convs + 1;");
538 echo 'ok: conversion';
539 }
540 }
541
542 die('');
543}
544
545function snp_get_theme($theme)
546{
547 global $SNP_THEMES, $SNP_THEMES_DIR;
548
549 if (!$theme) {
550 return false;
551 }
552 $theme = basename($theme);
553 foreach ($SNP_THEMES_DIR as $DIR) {
554 if (is_dir($DIR . '/' . $theme . '') && is_file($DIR . '/' . $theme . '/theme.php')) {
555 require_once( $DIR . '/' . $theme . '/theme.php' );
556 $SNP_THEMES[$theme]['DIR'] = $DIR . '/' . $theme . '/';
557 return $SNP_THEMES[$theme];
558 }
559 }
560
561 return false;
562}
563
564function snp_get_themes_list()
565{
566 global $SNP_THEMES, $SNP_THEMES_DIR;
567
568 if (count($SNP_THEMES) == 0) {
569 $files = array();
570 foreach ($SNP_THEMES_DIR as $DIR) {
571 if (is_dir($DIR)) {
572 if ($dh = opendir($DIR)) {
573 while (($file = readdir($dh)) !== false) {
574 if (is_dir($DIR . '/' . $file) && $file != '.' && $file != '..') {
575 $files[] = $file;
576 }
577 }
578 closedir($dh);
579 }
580 }
581 }
582
583 sort($files);
584
585 foreach ($files as $file) {
586 snp_get_theme($file);
587 }
588 }
589
590 return $SNP_THEMES;
591}
592
593function snp_popup_fields_list($popup)
594{
595 global $SNP_THEMES;
596
597 $popup = trim($popup);
598
599 if (is_array($SNP_THEMES) && is_array($SNP_THEMES[$popup])) {
600 return $SNP_THEMES[$popup]['FIELDS'];
601 } else {
602 return array();
603 }
604}
605
606function snp_popup_fields()
607{
608 global $SNP_THEMES, $SNP_NHP_Options, $post;
609
610 if (!$post) {
611 $post = (object) array();
612 }
613
614 $post->ID = intval($_POST['snp_post_ID']);
615 snp_get_themes_list();
616
617 if ($SNP_THEMES[$_POST['popup']]) {
618 $SNP_NHP_Options->_custom_fields_html('snp_popup_fields', $_POST['popup']);
619 } else {
620 echo 'Error...';
621 }
622
623 die();
624}
625
626function snp_ml_list()
627{
628 require_once( plugin_dir_path(__FILE__) . '/include/lists.inc.php' );
629
630 if ($_POST['ml_manager'] == 'mailchimp') {
631 echo json_encode(snp_ml_get_mc_lists($_POST['ml_mc_apikey']));
632 } elseif ($_POST['ml_manager'] == 'sendgrid') {
633 echo json_encode(snp_ml_get_sendgrid_lists($_POST['ml_sendgrid_username'], $_POST['ml_sendgrid_password']));
634 } elseif ($_POST['ml_manager'] == 'sendinblue') {
635 echo json_encode(snp_ml_get_sendinblue_lists($_POST['ml_sendinblue_apikey']));
636 } elseif ($_POST['ml_manager'] == 'getresponse') {
637 echo json_encode(snp_ml_get_gr_lists($_POST['ml_gr_apikey']));
638 } elseif ($_POST['ml_manager'] == 'freshmail') {
639 echo json_encode(snp_ml_get_freshmail_lists($_POST['ml_freshmail_apikey'], $_POST['ml_freshmail_apisecret']));
640 } elseif ($_POST['ml_manager'] == 'sendlane') {
641 echo json_encode(snp_ml_get_sendlane_lists($_POST['ml_sendlane_apikey'], $_POST['ml_sendlane_hash'], $_POST['ml_sendlane_subdomain']));
642 } elseif ($_POST['ml_manager'] == 'mailrelay') {
643 echo json_encode(snp_ml_get_mailrelay_lists($_POST['ml_mailrelay_apikey'], $_POST['ml_mailrelay_address']));
644 } elseif ($_POST['ml_manager'] == 'mailup') {
645 echo json_encode(snp_ml_get_mailup_lists($_POST['ml_mailup_clientid'], $_POST['ml_mailup_clientsecret'], $_POST['ml_mailup_login'], $_POST['ml_mailup_password']));
646 } elseif ($_POST['ml_manager'] == 'ontraport') {
647 echo json_encode(snp_ml_get_ontraport_lists($_POST['ml_ontraport_apiid'], $_POST['ml_ontraport_apikey']));
648 } elseif ($_POST['ml_manager'] == 'sendreach') {
649 echo json_encode(snp_ml_get_sendreach_lists($_POST['ml_sendreach_pubkey'], $_POST['ml_sendreach_privkey']));
650 } elseif ($_POST['ml_manager'] == 'sendpulse') {
651 echo json_encode(snp_ml_get_sendpulse_lists($_POST['ml_sendpulse_id'], $_POST['ml_sendpulse_apisecret']));
652 } elseif ($_POST['ml_manager'] == 'mailjet') {
653 echo json_encode(snp_ml_get_mailjet_lists($_POST['ml_mailjet_apikey'], $_POST['ml_mailjet_apisecret']));
654 } elseif ($_POST['ml_manager'] == 'elasticemail') {
655 echo json_encode(snp_ml_get_elasticemail_lists($_POST['ml_elasticemail_apikey']));
656 } elseif ($_POST['ml_manager'] == 'benchmarkemail') {
657 echo json_encode(snp_ml_get_benchmarkemail_lists($_POST['ml_benchmarkemail_apikey']));
658 } elseif ($_POST['ml_manager'] == 'myemma') {
659 echo json_encode(snp_ml_get_myemma_lists($_POST['ml_myemma_account_id'], $_POST['ml_myemma_pubkey'], $_POST['ml_myemma_privkey']));
660 } elseif ($_POST['ml_manager'] == 'mailerlite') {
661 echo json_encode(snp_ml_get_mailerlite_lists($_POST['ml_mailerlite_apikey']));
662 } elseif ($_POST['ml_manager'] == 'rocketresponder') {
663 echo json_encode(snp_ml_get_rocketresponder_lists($_POST['ml_rocketresponder_apipublic'], $_POST['ml_rocketresponder_apiprivate']));
664 } elseif ($_POST['ml_manager'] == 'activecampaign') {
665 echo json_encode(snp_ml_get_activecampaign_lists($_POST['ml_activecampaign_apiurl'], $_POST['ml_activecampaign_apikey']));
666 } elseif ($_POST['ml_manager'] == 'campaignmonitor') {
667 echo json_encode(snp_ml_get_cm_lists($_POST['ml_cm_clientid'], $_POST['ml_cm_apikey']));
668 } elseif ($_POST['ml_manager'] == 'icontact') {
669 echo json_encode(snp_ml_get_ic_lists($_POST['ml_ic_username'], $_POST['ml_ic_addid'], $_POST['ml_ic_apppass']));
670 } elseif ($_POST['ml_manager'] == 'constantcontact') {
671 echo json_encode(snp_ml_get_cc_lists($_POST['ml_cc_username'], $_POST['ml_cc_pass']));
672 } elseif ($_POST['ml_manager'] == 'aweber_auth') {
673 echo json_encode(snp_ml_get_aw_auth($_POST['ml_aw_auth_code']));
674 } elseif ($_POST['ml_manager'] == 'aweber_remove_auth') {
675 echo json_encode(snp_ml_get_aw_remove_auth());
676 } elseif ($_POST['ml_manager'] == 'aweber') {
677 echo json_encode(snp_ml_get_aw_lists());
678 } elseif ($_POST['ml_manager'] == 'wysija') {
679 echo json_encode(snp_ml_get_wy_lists());
680 } elseif ($_POST['ml_manager'] == 'madmimi') {
681 echo json_encode(snp_ml_get_madm_lists($_POST['ml_madm_username'], $_POST['ml_madm_apikey']));
682 } elseif ($_POST['ml_manager'] == 'infusionsoft') {
683 echo json_encode(snp_ml_get_infusionsoft_lists($_POST['ml_inf_subdomain'], $_POST['ml_inf_apikey']));
684 } elseif ($_POST['ml_manager'] == 'mymail') {
685 echo json_encode(snp_ml_get_mm_lists());
686 } elseif ($_POST['ml_manager'] == 'mailster') {
687 echo json_encode(snp_ml_get_mailster_lists());
688 } elseif ($_POST['ml_manager'] == 'sendpress') {
689 echo json_encode(snp_ml_get_sp_lists());
690 } elseif ($_POST['ml_manager'] == 'egoi') {
691 echo json_encode(snp_ml_get_egoi_lists($_POST['ml_egoi_apikey']));
692 } elseif ($_POST['ml_manager'] == 'hubspot') {
693 echo json_encode(snp_ml_get_hubspot_lists($_POST['ml_hubspot_apikey']));
694 } elseif ($_POST['ml_manager'] == 'convertkit') {
695 echo json_encode(snp_ml_get_convertkit_lists($_POST['ml_convertkit_apikey']));
696 } elseif ($_POST['ml_manager'] == 'enewsletter') {
697 echo json_encode(snp_ml_get_enewsletter_lists());
698 } elseif ($_POST['ml_manager'] == 'campaigner') {
699 echo json_encode(snp_ml_get_campaigner_lists($_POST['ml_campaigner_username'], $_POST['ml_campaigner_password']));
700 } elseif ($_POST['ml_manager'] == 'sgautorepondeur') {
701 echo json_encode(snp_ml_get_sgautorepondeur_lists($_POST['ml_sgautorepondeur_id'], $_POST['ml_sgautorepondeur_code']));
702 } else if ($_POST['ml_manager'] == 'kirim') {
703 echo json_decode(snp_ml_get_kirim_lists($_POST['ml_kirim_username'], $_POST['ml_kirim_token']));
704 } else if ($_POST['ml_manager'] == 'mautic_auth') {
705 echo json_encode(snp_ml_get_mautic_auth($_POST['ml_mautic_url'], $_POST['ml_mautic_key'], $_POST['ml_mautic_secret']));
706 } else if ($_POST['ml_manager'] == 'mautic_remove_auth') {
707 echo json_encode(snp_ml_get_mautic_remove_auth());
708 } else if ($_POST['ml_manager'] == 'zoho_auth') {
709 echo json_encode(snp_ml_get_zoho_auth($_POST['ml_zoho_email'], $_POST['ml_zoho_password'], $_POST['ml_zoho_application']));
710 } else if ($_POST['ml_manager'] == 'zoho_remove_auth') {
711 echo json_encode(snp_ml_get_zoho_remove_auth());
712 } else if ($_POST['ml_manager'] == 'zoho_campaign') {
713 echo json_encode(snp_ml_get_zoho_campaigns());
714 } else if ($_POST['ml_manager'] == 'mailpoet') {
715 echo json_encode(snp_ml_get_mailpoet_lists());
716 } else if ($_POST['ml_manager'] == 'drip') {
717 echo json_encode(snp_ml_get_drip_campaigns($_POST['ml_drip_account'], $_POST['ml_drip_token']));
718 } else if ($_POST['ml_manager'] == 'apsis') {
719 echo json_encode(snp_ml_get_apsis_lists($_POST['ml_apsis_key']));
720 } else if ($_POST['ml_manager'] == 'klayvio') {
721 echo json_encode(snp_ml_get_klayvio_lists($_POST['ml_klayvio_api_key']));
722 } else if ($_POST['ml_manager'] == 'moosend') {
723 echo json_encode(snp_ml_get_moosend_lists($_POST['ml_moosend_api_key']));
724 } else if ($_POST['ml_manager'] == 'mailfit') {
725 echo json_encode(snp_ml_get_mailfit_lists($_POST['ml_mailfit_endpoint'], $_POST['ml_mailfit_apitoken']));
726 } else if ($_POST['ml_managger'] == 'ngpvan') {
727 echo json_encode(snp_ml_get_ngpvan_contacts($_POST['ml_ngpvan_username'], $_POST['ml_ngpvan_password']));
728 } else {
729 echo json_encode(array());
730 }
731
732 die();
733}
734
735function snp_popup_colors()
736{
737 global $SNP_THEMES, $SNP_NHP_Options, $post;
738
739 snp_get_themes_list();
740 echo json_encode($SNP_THEMES[$_POST['popup']]['COLORS']);
741 die();
742}
743
744function snp_popup_types()
745{
746 global $SNP_THEMES, $SNP_NHP_Options, $post;
747
748 snp_get_themes_list();
749 echo json_encode($SNP_THEMES[$_POST['popup']]['TYPES']);
750 die();
751}
752
753function snp_init()
754{
755 $wp_scripts = wp_scripts();
756
757 if (!snp_get_option('js_disable_jqueryuitheme')) {
758 wp_enqueue_style('plugin_name-admin-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $wp_scripts->registered['jquery-ui-core']->ver . '/themes/smoothness/jquery-ui.css',
759 false,
760 SNP_VERSION,
761 false);
762 }
763
764 if (!snp_get_option('js_disble_jquery_ui_calendar')) {
765 wp_enqueue_script('jquery-ui-datepicker');
766 }
767
768 wp_enqueue_script(
769 'js-cookie', plugins_url('/assets/js/cookie.js', __FILE__), array('jquery'), false, true
770 );
771
772 if (
773 !snp_get_option('js_disable_tooltipster') ||
774 is_admin()
775 ) {
776 wp_register_style('tooltipster-css', plugins_url('/tooltipster/tooltipster.bundle.min.css', __FILE__));
777 wp_enqueue_style('tooltipster-css');
778
779 wp_register_style('tooltipster-css-theme', plugins_url('/tooltipster/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-light.min.css', __FILE__));
780 wp_enqueue_style('tooltipster-css-theme');
781
782 wp_enqueue_script(
783 'jquery-np-tooltipster', plugins_url('/assets/js/tooltipster.bundle.min.js', __FILE__), array('jquery'), false, true
784 );
785 }
786
787 if (!snp_get_option('js_disable_material')) {
788 wp_register_style('material-design-css', plugins_url('/themes/jquery.material.form.css', __FILE__));
789 wp_enqueue_style('material-design-css');
790
791 wp_enqueue_script(
792 'material-design-js', plugins_url('/assets/js/jquery.material.form.min.js', __FILE__), array('jquery'), false, true
793 );
794 }
795
796 if (snp_get_option('enable_jquery_accordion')) {
797 wp_enqueue_script('jquery-ui-accordion');
798 }
799
800 if (!snp_get_option('js_disable_phone_input')) {
801 wp_register_style('jquery-intl-phone-input-css', plugins_url('/assets/vendor/intl-tel-input/css/intlTelInput.min.css', __FILE__));
802 wp_enqueue_style('jquery-intl-phone-input-css');
803
804 wp_enqueue_script(
805 'jquery-intl-phone-input-js', plugins_url('/assets/vendor/intl-tel-input/js/intlTelInput-jquery.min.js', __FILE__), array('jquery'), false, true
806 );
807 }
808
809 wp_enqueue_script(
810 'js-dialog_trigger', plugins_url('/assets/js/dialog_trigger.js', __FILE__), array('jquery'), false, true
811 );
812
813 if (snp_get_option('js_use_nonminify')) {
814 wp_enqueue_script(
815 'js-ninjapopups', plugins_url('/assets/js/ninjapopups.js', __FILE__), array('jquery'), false, true
816 );
817 } else {
818 wp_enqueue_script(
819 'js-ninjapopups', plugins_url('/assets/js/ninjapopups.min.js', __FILE__), array('jquery'), false, true
820 );
821 }
822
823 //Ninja Popup JavaScript triggers fired after ajax response is received
824 //Mostly used for tracking tools like drip, learnq, metrilo and others
825 if (snp_get_option('js_use_drip')) {
826 wp_enqueue_script(
827 'js-ninjapopups-drip', plugins_url('/assets/js/ninjapopups.drip.min.js', __FILE__), array('jquery'), false, true
828 );
829 }
830
831 if (snp_get_option('js_use_learnq')) {
832 wp_enqueue_script(
833 'js-ninjapopups-learnq', plugins_url('/assets/js/ninjapopups.learnq.min.js', __FILE__), array('jquery'), false, true
834 );
835 }
836
837 if (snp_get_option('js_use_metrilo')) {
838 wp_enqueue_script(
839 'js-ninjapopups-metrilo', plugins_url('/assets/js/ninjapopups.metrilo.min.js', __FILE__), array('jquery'), false, true
840 );
841 }
842}
843
844function snp_init_fancybox()
845{
846 if (
847 !snp_get_option('js_disable_fancybox') ||
848 is_admin()
849 ) {
850 // Fancybox 2
851 wp_register_style('fancybox2', plugins_url('/fancybox2/jquery.fancybox.min.css', __FILE__));
852 wp_enqueue_style('fancybox2');
853 wp_enqueue_script(
854 'fancybox2', plugins_url('/fancybox2/jquery.fancybox.min.js', __FILE__), array('jquery'), false, true
855 );
856 }
857}
858
859function snp_init_mbYTPlayer()
860{
861 if (
862 !snp_get_option('js_disable_mbYTPlayer') ||
863 is_admin()
864 ) {
865 wp_enqueue_script('mbYTPlayer', SNP_URL . 'assets/js/jquery.mb.YTPlayer.min.js', array('jquery'), false, true);
866 }
867}
868
869function snp_init_fontawesome()
870{
871 if (
872 !snp_get_option('js_disable_fontawesome') ||
873 is_admin()
874 ) {
875 wp_register_style('font-awesome', plugins_url('/assets/font-awesome/css/font-awesome.min.css', __FILE__));
876 wp_enqueue_style('font-awesome');
877 }
878}
879
880function snp_run_popup($ID, $type, $is_preview = false)
881{
882 global $snp_popups, $PREVIEW_POPUP_META, $detect, $countryCode, $cityCode, $zipCode;
883
884 if (!$ID && $ID != -1) {
885 return;
886 }
887
888 snp_init();
889
890 if ($ID == -1) {
891 $POPUP_META = $PREVIEW_POPUP_META;
892 foreach ($POPUP_META as $k => $v) {
893 if (is_array($v) || $k == 'theme') {
894 $v = serialize($v);
895 } else {
896 $v = stripslashes($v);
897 }
898
899 $POPUP_META[$k] = $v;
900 $PREVIEW_POPUP_META[$k] = $v;
901 }
902 } else {
903 if (strpos($ID, 'ab_') === 0) {
904 $AB_ID = str_replace('ab_', '', $ID);
905 $AB_META = get_post_meta($AB_ID);
906
907 if (!isset($AB_META['snp_forms'])) {
908 return;
909 }
910
911 $AB_META['snp_forms'] = array_keys(unserialize($AB_META['snp_forms'][0]));
912
913 if (!is_array($AB_META['snp_forms']) || count($AB_META['snp_forms']) == 0) {
914 return;
915 }
916
917 $ID = $AB_META['snp_forms'][array_rand($AB_META['snp_forms'])];
918 }
919
920 if (get_post_status($ID) != 'publish') {
921 return;
922 }
923
924 $POPUP_META = get_post_meta($ID);
925 foreach ((array) $POPUP_META as $k => $v) {
926 $POPUP_META[$k] = $v[0];
927 }
928 }
929
930 if ($is_preview==true) {
931 $PREVIEW_POPUP_META['is_preview'] = true;
932 }
933
934 if (!isset($POPUP_META['snp_theme'])) {
935 $POPUP_META['snp_theme'] = '';
936 }
937
938 if (isset($POPUP_META['snp_theme']) && !is_array($POPUP_META['snp_theme'])) {
939 $POPUP_META['snp_theme'] = unserialize($POPUP_META['snp_theme']);
940 }
941
942 $POPUP_START_DATE = strtotime(isset($POPUP_META['snp_start_date']) ? $POPUP_META['snp_start_date'] : '');
943 $POPUP_END_DATE = strtotime(isset($POPUP_META['snp_end_date']) ? $POPUP_META['snp_end_date'] : '');
944
945 if (isset($POPUP_META['snp_start_hour']) && $POPUP_META['snp_start_hour']) {
946 $POPUP_START_HOUR = $POPUP_META['snp_start_hour'];
947 } else {
948 $POPUP_START_HOUR = '';
949 }
950
951 if (isset($POPUP_META['snp_end_hour']) && $POPUP_META['snp_end_hour']) {
952 $POPUP_END_HOUR = $POPUP_META['snp_end_hour'];
953 } else {
954 $POPUP_END_HOUR = '';
955 }
956
957
958 if ($detect->isMobile() && !(snp_get_option('enable_mobile') == 'enabled' && !is_admin())) {
959 return;
960 }
961
962 if ($POPUP_START_HOUR) {
963 if ($POPUP_START_DATE) {
964 $POPUP_START_HOUR = $POPUP_START_DATE . ' ' . $POPUP_START_HOUR;
965 } else {
966 $POPUP_START_HOUR = date('Y-m-d') . ' ' . $POPUP_START_HOUR;
967 }
968
969 if (!(time() >= strtotime($POPUP_START_HOUR))) {
970 return;
971 }
972 }
973
974 if ($POPUP_END_HOUR) {
975 if ($POPUP_END_DATE) {
976 $POPUP_END_HOUR = $POPUP_END_DATE . ' ' . $POPUP_END_HOUR;
977 } else {
978 $POPUP_END_HOUR = date('Y-m-d') . ' ' . $POPUP_END_HOUR;
979 }
980
981 if (!(time() <= strtotime($POPUP_END_HOUR))) {
982 return;
983 }
984 }
985
986 if ($POPUP_START_DATE && empty($POPUP_START_HOUR)) {
987 if ($POPUP_START_DATE <= time()) {
988 } else {
989 return;
990 }
991 }
992
993 if ($POPUP_END_DATE && empty($POPUP_END_HOUR)) {
994 if ($POPUP_END_DATE >= time()) {
995 } else {
996 return;
997 }
998 }
999
1000 //Option to show pop-up based on referer
1001 if (isset($POPUP_META['snp_show_by_referer']) && $POPUP_META['snp_show_by_referer'] == 'yes') {
1002 $found = false;
1003 if (($refs = unserialize($POPUP_META['snp_show_by_referer_urls'])) && isset($_SERVER['HTTP_REFERER'])) {
1004 foreach ($refs as $it) {
1005 if (preg_match($it, $_SERVER['HTTP_REFERER'], $matches)) {
1006 $found = true;
1007 }
1008 }
1009 }
1010
1011 if (!$found) {
1012 return;
1013 }
1014 }
1015
1016 //Option to hide pop-up based on referer
1017 if (isset($POPUP_META['snp_hide_by_referer']) && $POPUP_META['snp_hide_by_referer'] == 'yes') {
1018 $found = false;
1019 if (($refs = unserialize($POPUP_META['snp_hide_by_referer_urls'])) && isset($_SERVER['HTTP_REFERER'])) {
1020 foreach ($refs as $it) {
1021 if (preg_match($it, $_SERVER['HTTP_REFERER'], $matches)) {
1022 $found = true;
1023 }
1024 }
1025 }
1026
1027 if ($found) {
1028 return;
1029 }
1030 }
1031
1032 if ($countryCode) {
1033 if (isset($POPUP_META['snp_show_by_country']) && $POPUP_META['snp_show_by_country'] == 'yes') {
1034 $found = false;
1035 if (($countries = unserialize($POPUP_META['snp_show_by_country_countries']))) {
1036 $countries = array_map('strtolower', $countries);
1037 if (in_array(strtolower($countryCode), $countries)) {
1038 $found = true;
1039 }
1040 }
1041
1042 if (!$found) {
1043 return;
1044 }
1045 }
1046
1047 if (isset($POPUP_META['snp_hide_by_country']) && $POPUP_META['snp_hide_by_country'] == 'yes') {
1048 $found = false;
1049 if (($countries = unserialize($POPUP_META['snp_hide_by_country_countries']))) {
1050 $countries = array_map('strtolower', $countries);
1051 if (in_array(strtolower($countryCode), $countries)) {
1052 $found = true;
1053 }
1054 }
1055
1056 if ($found) {
1057 return;
1058 }
1059 }
1060 }
1061
1062 if ($zipCode) {
1063 if (isset($POPUP_META['snp_show_by_zip']) && $POPUP_META['snp_show_by_zip'] == 'yes') {
1064 $found = false;
1065 if (($codes = unserialize($POPUP_META['snp_show_by_zip_codes']))) {
1066 foreach ($codes as $it) {
1067 if ($it === $zipCode) {
1068 $found = true;
1069 }
1070 }
1071 }
1072
1073 if ($found) {
1074 return;
1075 }
1076 }
1077
1078 if (isset($POPUP_META['snp_hide_by_zip']) && $POPUP_META['snp_hide_by_zip'] == 'yes') {
1079 $found = false;
1080 if (($codes = unserialize($POPUP_META['snp_hide_by_zip_codes']))) {
1081 foreach ($codes as $it) {
1082 if ($it === $zipCode) {
1083 $found = true;
1084 }
1085 }
1086 }
1087
1088 if ($found) {
1089 return;
1090 }
1091 }
1092 }
1093
1094 if ($cityCode) {
1095 if (isset($POPUP_META['snp_show_by_city']) && $POPUP_META['snp_show_by_city'] == 'yes') {
1096 $found = false;
1097 if (($codes = unserialize($POPUP_META['snp_show_by_city_codes']))) {
1098 foreach ($codes as $it) {
1099 if ($it === $cityCode) {
1100 $found = true;
1101 }
1102 }
1103 }
1104
1105 if ($found) {
1106 return;
1107 }
1108 }
1109
1110 if (isset($POPUP_META['snp_hide_by_city']) && $POPUP_META['snp_hide_by_city'] == 'yes') {
1111 $found = false;
1112 if (($codes = unserialize($POPUP_META['snp_hide_by_city_codes']))) {
1113 foreach ($codes as $it) {
1114 if ($it === $cityCode) {
1115 $found = true;
1116 }
1117 }
1118 }
1119
1120 if ($found) {
1121 return;
1122 }
1123 }
1124 }
1125
1126 if ($type == 'exit') {
1127 $use_in = snp_get_option('use_in');
1128 if (isset($use_in['the_content']) && $use_in['the_content'] == 1) {
1129 add_filter('the_content', array('snp_links', 'search'), 100);
1130 }
1131
1132 if (isset($use_in['the_excerpt']) && $use_in['the_excerpt'] == 1) {
1133 add_filter('the_excerpt', array('snp_links', 'search'), 100);
1134 }
1135
1136 if (isset($use_in['widget_text']) && $use_in['widget_text'] == 1) {
1137 add_filter('widget_text', array('snp_links', 'search'), 100);
1138 }
1139
1140 if (isset($use_in['comment_text']) && $use_in['comment_text'] == 1) {
1141 add_filter('comment_text', array('snp_links', 'search'), 100);
1142 }
1143 }
1144
1145 if (snp_get_option('run_hook_footer') == 'snp_run_footer') {
1146 add_action('snp_run_footer', 'snp_footer');
1147 } else {
1148 add_action('wp_footer', 'snp_footer');
1149 }
1150 wp_register_style('snp_styles_reset', plugins_url('/themes/reset.min.css', __FILE__));
1151 wp_enqueue_style('snp_styles_reset');
1152
1153 if (isset($POPUP_META['snp_theme']['mode']) && $POPUP_META['snp_theme']['mode'] == '1') {
1154 $POPUP_META['snp_theme']['theme'] = 'builder';
1155 }
1156
1157 if ($POPUP_META['snp_theme']['theme'] != 'builder') {
1158 snp_init_fancybox();
1159 }
1160
1161 if (isset($POPUP_META['snp_theme']['theme']) && $POPUP_META['snp_theme']['theme']) {
1162 $THEME_INFO = snp_get_theme($POPUP_META['snp_theme']['theme']);
1163 }
1164
1165 if (isset($THEME_INFO['STYLES']) && $THEME_INFO['STYLES']) {
1166 wp_register_style('snp_styles_' . $POPUP_META['snp_theme']['theme'], plugins_url($POPUP_META['snp_theme']['theme'] . '/' . $THEME_INFO['STYLES'], realpath($THEME_INFO['DIR'])));
1167 wp_enqueue_style('snp_styles_' . $POPUP_META['snp_theme']['theme']);
1168 }
1169
1170 if (isset($POPUP_META['snp_theme']['theme']) && function_exists('snp_enqueue_' . $POPUP_META['snp_theme']['theme'])) {
1171 call_user_func('snp_enqueue_' . $POPUP_META['snp_theme']['theme'], $POPUP_META);
1172 }
1173
1174 if ($type == 'inline') {
1175
1176 } elseif ($type == 'content') {
1177 $snp_popups[$type][] = array(
1178 'ID' => $ID,
1179 'AB_ID' => isset($AB_ID) ? $AB_ID : false
1180 );
1181 } else {
1182 $snp_popups[$type] = array(
1183 'ID' => $ID,
1184 'AB_ID' => isset($AB_ID) ? $AB_ID : false
1185 );
1186 }
1187}
1188
1189function snp_create_popup($ID, $AB_ID, $type, $args = array())
1190{
1191 global $PREVIEW_POPUP_META;
1192
1193 $return = '';
1194 if ($ID == -1) {
1195 $POPUP_META = $PREVIEW_POPUP_META;
1196 } else {
1197 $POPUP = get_post($ID);
1198 $POPUP_META = get_post_meta($ID);
1199 foreach ($POPUP_META as $k => $v) {
1200 $POPUP_META[$k] = $v[0];
1201 }
1202 }
1203
1204 if (isset($PREVIEW_POPUP_META['is_preview'])) {
1205 $POPUP_META['snp_open']='load';
1206 $POPUP_META['snp_open_after']='';
1207 }
1208
1209 if (!is_array($POPUP_META['snp_theme'])) {
1210 $POPUP_META['snp_theme'] = unserialize($POPUP_META['snp_theme']);
1211 }
1212
1213 if (!isset($POPUP_META['snp_theme']['mode']) || $POPUP_META['snp_theme']['mode'] == '0') {
1214 if (!$POPUP_META['snp_theme']['theme']) {
1215 return;
1216 }
1217
1218 if ($POPUP_META['snp_theme']['type'] == 'social' || $POPUP_META['snp_theme']['type'] == 'likebox') {
1219 snp_enqueue_social_script();
1220 }
1221 } else {
1222 $POPUP_META['snp_theme']['theme'] = 'builder';
1223 }
1224
1225 $dataJsonConfig = [];
1226
1227 $dataJsonConfig['popupType'] = $type;
1228 $dataJsonConfig['popupId'] = $ID;
1229 $dataJsonConfig['abId'] = false;
1230 if ($AB_ID != false) {
1231 $dataJsonConfig['abId'] = $AB_ID;
1232 }
1233 $dataJsonConfig['popupDivId'] = 'snppopup-' . $type . ($type == 'content' || $type == 'inline' || $type == 'widget' ? '-' . $ID : '');
1234
1235 $dataJsonConfig['lock_id'] = (isset($args['lock_id']) && $args['lock_id'] ? $args['lock_id'] : '');
1236 $dataJsonConfig['openMethod'] = (isset($POPUP_META['snp_open']) ? $POPUP_META['snp_open'] : 'load');
1237 $dataJsonConfig['closeMethod'] = (isset($POPUP_META['snp_close']) ? $POPUP_META['snp_close'] : 'close_manual');
1238 $dataJsonConfig['snp_optin_form_submit'] = 'single';
1239 $dataJsonConfig['showReadyThemeCloseButton'] = $POPUP_META['snp_show_cb_button'];
1240 $dataJsonConfig['popupTheme'] = $POPUP_META['snp_theme']['theme'];
1241 $dataJsonConfig['overlayType'] = $POPUP_META['snp_popup_overlay'];
1242 $dataJsonConfig['snp_cookie_conversion'] = (is_numeric($POPUP_META['snp_cookie_conversion']) ? $POPUP_META['snp_cookie_conversion'] : '30');
1243 $dataJsonConfig['snp_cookie_close'] = (is_numeric($POPUP_META['snp_cookie_close']) && $POPUP_META['snp_cookie_close'] ? $POPUP_META['snp_cookie_close'] : '-1');
1244 $dataJsonConfig['snp_autoclose'] = (isset($POPUP_META['snp_autoclose']) && $POPUP_META['snp_autoclose'] ? $POPUP_META['snp_autoclose'] : '');
1245 $dataJsonConfig['snp_show_on_exit'] = (isset($POPUP_META['snp_show_on_exit']) ? $POPUP_META['snp_show_on_exit'] : '1');
1246 $dataJsonConfig['snp_exit_js_alert_text'] = (isset($POPUP_META['snp_exit_js_alert_text'])?str_replace("\r\n", '\n', htmlspecialchars((string) $POPUP_META['snp_exit_js_alert_text'])):'');
1247 $dataJsonConfig['snp_exit_scroll_down'] = (isset($POPUP_META['snp_exit_scroll_down']) ? $POPUP_META['snp_exit_scroll_down'] : '');
1248 $dataJsonConfig['snp_exit_scroll_up'] = (isset($POPUP_META['snp_exit_scroll_up']) ? $POPUP_META['snp_exit_scroll_up'] : '');
1249 $dataJsonConfig['snp_open_after'] = (isset($POPUP_META['snp_open_after']) && $POPUP_META['snp_open_after'] ? $POPUP_META['snp_open_after'] : '');
1250 $dataJsonConfig['snp_open_inactivity'] = (isset($POPUP_META['snp_open_inactivity']) && $POPUP_META['snp_open_inactivity'] ? $POPUP_META['snp_open_inactivity'] : '');
1251 $dataJsonConfig['snp_open_scroll'] = (isset($POPUP_META['snp_open_scroll']) && $POPUP_META['snp_open_scroll'] ? $POPUP_META['snp_open_scroll'] : '');
1252 $dataJsonConfig['snp_open_spend_time'] = (isset($POPUP_META['snp_open_spend_time']) && $POPUP_META['snp_open_spend_time'] ? $POPUP_META['snp_open_spend_time'] : '');
1253 $dataJsonConfig['snp_close_scroll'] = (isset($POPUP_META['snp_close_scroll']) && $POPUP_META['snp_close_scroll'] ? $POPUP_META['snp_close_scroll'] : '');
1254 $dataJsonConfig['formDataCollectType'] = (isset($POPUP_META['snp_optin_form_submit']) && $POPUP_META['snp_optin_form_submit'] ? $POPUP_META['snp_optin_form_submit'] : '');
1255
1256 $dataJsonConfig['snp_optin_redirect_url'] = '';
1257 if (isset($POPUP_META['snp_optin_redirect']) && $POPUP_META['snp_optin_redirect'] == 'yes' && !empty($POPUP_META['snp_optin_redirect_url'])) {
1258 $dataJsonConfig['snp_optin_redirect_url'] = $POPUP_META['snp_optin_redirect_url'];
1259 }
1260
1261 $dataJsonConfig['afterOptinWebhookUrl'] = '';
1262 if (isset($POPUP_META['snp_ajax_before_optin']) && $POPUP_META['snp_ajax_before_optin']) {
1263 $dataJsonConfig['afterOptinWebhookUrl'] = $POPUP_META['snp_ajax_before_optin'];
1264 } else if (snp_get_option('ajax_before_optin')) {
1265 $dataJsonConfig['afterOptinWebhookUrl'] = snp_get_option('ajax_before_optin');
1266 }
1267
1268 $dataJsonConfig['beforeOptinWebhookUrl'] = '';
1269 if (isset($POPUP_META['snp_ajax_after_optin']) && $POPUP_META['snp_ajax_after_optin']) {
1270 $dataJsonConfig['beforeOptinWebhookUrl'] = $POPUP_META['snp_ajax_after_optin'];
1271 } else if (snp_get_option('ajax_after_optin')) {
1272 $dataJsonConfig['beforeOptinWebhookUrl'] = snp_get_option('ajax_after_optin');
1273 }
1274
1275 $dataJsonConfig['ajaxUrl'] = admin_url('admin-ajax.php');
1276 if (isset($POPUP_META['snp_ajax_request_handler']) && $POPUP_META['snp_ajax_request_handler']) {
1277 $dataJsonConfig['ajaxUrl'] = $POPUP_META['snp_ajax_request_handler'];
1278 } else if (snp_get_option('ajax_request_handler')) {
1279 $dataJsonConfig['ajaxUrl'] = snp_get_option('ajax_request_handler');
1280 }
1281
1282 $CURRENT_URL = snp_get_current_url();
1283 $return .=' <div id="' . $dataJsonConfig['popupDivId'] . '" class="snp-pop-' . $ID . ' snppopup' . ($type == 'inline' ? ' snp-pop-inline' : '') . ($type == 'widget' ? ' snp-pop-widget' : '') . '">';
1284
1285 if (isset($args['lock_id']) && $args['lock_id']) {
1286 $return .= '<input type="hidden" class="snp_lock_id" value="' . $args['lock_id'] . '" />';
1287 }
1288
1289 if (isset($POPUP_META['snp_cb_close_after']) && $POPUP_META['snp_cb_close_after']) {
1290 $return .= '<input type="hidden" class="snp_autoclose" value="' . $POPUP_META['snp_cb_close_after'] . '" />';
1291 }
1292
1293 if (isset($POPUP_META['snp_open']) && $POPUP_META['snp_open']) {
1294 $return .= '<input type="hidden" class="snp_open" value="' . $POPUP_META['snp_open'] . '" />';
1295 } else {
1296 $return .= '<input type="hidden" class="snp_open" value="load" />';
1297 }
1298
1299 if (isset($POPUP_META['snp_close']) && $POPUP_META['snp_close']) {
1300 $return .= '<input type="hidden" class="snp_close" value="' . $POPUP_META['snp_close'] . '" />';
1301 } else {
1302 $return .= '<input type="hidden" class="snp_close" value="close_manual" />';
1303 }
1304
1305 $return .= '<input type="hidden" class="snp_show_on_exit" value="' . (isset($POPUP_META['snp_show_on_exit']) ? $POPUP_META['snp_show_on_exit'] : '1') . '" />';
1306 $return .= '<input type="hidden" class="snp_exit_js_alert_text" value="' . (isset($POPUP_META['snp_exit_js_alert_text'])?str_replace("\r\n", '\n', htmlspecialchars((string) $POPUP_META['snp_exit_js_alert_text'])):'') . '" />';
1307 $return .= '<input type="hidden" class="snp_exit_scroll_down" value="' . (isset($POPUP_META['snp_exit_scroll_down']) ? $POPUP_META['snp_exit_scroll_down'] : '') . '" />';
1308 $return .= '<input type="hidden" class="snp_exit_scroll_up" value="' . (isset($POPUP_META['snp_exit_scroll_up']) ? $POPUP_META['snp_exit_scroll_up'] : '') . '" />';
1309
1310 if (isset($POPUP_META['snp_open_after']) && $POPUP_META['snp_open_after']) {
1311 $return .= '<input type="hidden" class="snp_open_after" value="' . $POPUP_META['snp_open_after'] . '" />';
1312 }
1313
1314 if (isset($POPUP_META['snp_open_inactivity']) && $POPUP_META['snp_open_inactivity']) {
1315 $return .= '<input type="hidden" class="snp_open_inactivity" value="' . $POPUP_META['snp_open_inactivity'] . '" />';
1316 }
1317
1318 if (isset($POPUP_META['snp_open_scroll']) && $POPUP_META['snp_open_scroll']) {
1319 $return .= '<input type="hidden" class="snp_open_scroll" value="' . $POPUP_META['snp_open_scroll'] . '" />';
1320 }
1321
1322 if (isset($POPUP_META['snp_open_spend_time']) && $POPUP_META['snp_open_spend_time']) {
1323 $return .= '<input type="hidden" class="snp_open_spend_time" value="' . $POPUP_META['snp_open_spend_time'] . '" />';
1324 }
1325
1326 if (isset($POPUP_META['snp_close_scroll']) && $POPUP_META['snp_close_scroll']) {
1327 $return .= '<input type="hidden" class="snp_close_scroll" value="' . $POPUP_META['snp_close_scroll'] . '" />';
1328 }
1329
1330 if (isset($POPUP_META['snp_optin_redirect']) && $POPUP_META['snp_optin_redirect'] == 'yes' && !empty($POPUP_META['snp_optin_redirect_url'])) {
1331 $return .= '<input type="hidden" class="snp_optin_redirect_url" value="' . $POPUP_META['snp_optin_redirect_url'] . '" />';
1332 } else {
1333 $return .= '<input type="hidden" class="snp_optin_redirect_url" value="" />';
1334 }
1335
1336 if (isset($POPUP_META['snp_optin_form_submit']) && !empty($POPUP_META['snp_optin_form_submit'])) {
1337 $return .= '<input type="hidden" class="snp_optin_form_submit" value="' . $POPUP_META['snp_optin_form_submit'] . '" />';
1338 } else {
1339 $return .= '<input type="hidden" class="snp_optin_form_submit" value="single" />';
1340 }
1341
1342 if (!isset($POPUP_META['snp_popup_overlay'])) {
1343 $POPUP_META['snp_popup_overlay'] = '';
1344 }
1345
1346 $return .= '<input type="hidden" class="snp_show_cb_button" value="' . $POPUP_META['snp_show_cb_button'] . '" />';
1347 $return .= '<input type="hidden" class="snp_popup_id" value="' . $ID . '" />';
1348 if ($AB_ID != false) {
1349 $return .= '<input type="hidden" class="snp_popup_ab_id" value="' . $AB_ID . '" />';
1350 }
1351 $return .= '<input type="hidden" class="snp_popup_theme" value="' . $POPUP_META['snp_theme']['theme'] . '" />';
1352 $return .= '<input type="hidden" class="snp_overlay" value="' . $POPUP_META['snp_popup_overlay'] . '" />';
1353 $return .= '<input type="hidden" class="snp_cookie_conversion" value="' . (is_numeric($POPUP_META['snp_cookie_conversion']) ? $POPUP_META['snp_cookie_conversion'] : '30') . '" />';
1354 $return .= '<input type="hidden" class="snp_cookie_close" value="' . (is_numeric($POPUP_META['snp_cookie_close']) && $POPUP_META['snp_cookie_close'] ? $POPUP_META['snp_cookie_close'] : '-1') . '" />';
1355
1356 if (isset($POPUP_META['snp_ajax_before_optin']) && $POPUP_META['snp_ajax_before_optin']) {
1357 $return .= '<input type="hidden" class="snp_ajax_before_optin" value="' . $POPUP_META['snp_ajax_before_optin'] . '" />';
1358 } else if (snp_get_option('ajax_before_optin')) {
1359 $return .= '<input type="hidden" class="snp_ajax_before_optin" value="' . snp_get_option('ajax_before_optin') . '" />';
1360 }
1361
1362 if (isset($POPUP_META['snp_ajax_after_optin']) && $POPUP_META['snp_ajax_after_optin']) {
1363 $return .= '<input type="hidden" class="snp_ajax_after_optin" value="' . $POPUP_META['snp_ajax_after_optin'] . '" />';
1364 } else if (snp_get_option('ajax_after_optin')) {
1365 $return .= '<input type="hidden" class="snp_ajax_after_optin" value="' . snp_get_option('ajax_after_optin') . '" />';
1366 }
1367
1368 if (isset($POPUP_META['snp_ajax_request_handler']) && $POPUP_META['snp_ajax_request_handler']) {
1369 $return .= '<input type="hidden" class="snp_ajax_url" value="' . $POPUP_META['snp_ajax_request_handler'] . '" />';
1370 } else if (snp_get_option('ajax_request_handler')) {
1371 $return .= '<input type="hidden" class="snp_ajax_url" value="' . snp_get_option('ajax_request_handler') . '" />';
1372 }
1373
1374 $THEME_INFO = snp_get_theme($POPUP_META['snp_theme']['theme']);
1375 ob_start();
1376 include($THEME_INFO['DIR'] . '/template.php');
1377 $return .= ob_get_clean();
1378 if (!isset($POPUP_META['snp_cb_img'])) {
1379 $POPUP_META['snp_cb_img'] = '';
1380 }
1381
1382 if (!isset($POPUP_META['snp_custom_css'])) {
1383 $POPUP_META['snp_custom_css'] = '';
1384 }
1385
1386 if (!isset($POPUP_META['snp_custom_js'])) {
1387 $POPUP_META['snp_custom_js'] = '';
1388 }
1389
1390 if (!isset($POPUP_META['snp_theme']['mode']) || $POPUP_META['snp_theme']['mode'] == '0') {
1391 if ($POPUP_META['snp_popup_overlay'] == 'image' && $POPUP_META['snp_overlay_image']) {
1392 $return .= '<style>.snp-pop-' . $ID . '-overlay { background: url(\'' . $POPUP_META['snp_overlay_image'] . '\');}</style>';
1393 }
1394
1395 if ($POPUP_META['snp_cb_img'] != 'close_default' && $POPUP_META['snp_cb_img'] != '') {
1396 $return .= '<style>';
1397 switch ($POPUP_META['snp_cb_img']) {
1398 case 'close_1':
1399 $return .= '.snp-pop-' . $ID . '-wrap .fancybox-close { width: 31px; height: 31px; top: -15px; right: -15px; background: url(\'' . SNP_URL . 'img/' . $POPUP_META['snp_cb_img'] . '.png\');}';
1400 break;
1401 case 'close_2':
1402 $return .= '.snp-pop-' . $ID . '-wrap .fancybox-close { width: 19px; height: 19px; top: -8px; right: -8px; background: url(\'' . SNP_URL . 'img/' . $POPUP_META['snp_cb_img'] . '.png\');}';
1403 break;
1404 case 'close_3':
1405 $return .= '.snp-pop-' . $ID . '-wrap .fancybox-close { width: 33px; height: 33px; top: -16px; right: -16px; background: url(\'' . SNP_URL . 'img/' . $POPUP_META['snp_cb_img'] . '.png\');}';
1406 break;
1407 case 'close_4':
1408 case 'close_5':
1409 $return .= '.snp-pop-' . $ID . '-wrap .fancybox-close { width: 20px; height: 20px; top: -10px; right: -10px; background: url(\'' . SNP_URL . 'img/' . $POPUP_META['snp_cb_img'] . '.png\');}';
1410 break;
1411 case 'close_6':
1412 $return .= '.snp-pop-' . $ID . '-wrap .fancybox-close { width: 24px; height: 24px; top: -12px; right: -12px; background: url(\'' . SNP_URL . 'img/' . $POPUP_META['snp_cb_img'] . '.png\');}';
1413 break;
1414 }
1415 $return .= '</style>';
1416 }
1417 }
1418
1419 if ($POPUP_META['snp_custom_css'] != '') {
1420 $return .= '<style>';
1421 $return .= $POPUP_META['snp_custom_css'];
1422 $return .= '</style>';
1423 }
1424
1425 if ($POPUP_META['snp_custom_js'] != '') {
1426 $return .= '<script>';
1427 $return .= $POPUP_META['snp_custom_js'];
1428 $return .= '</script>';
1429 }
1430
1431 //Hooks
1432 if (
1433 (isset($POPUP_META['snp_js_np_submit']) && !empty($POPUP_META['snp_js_np_submit'])) ||
1434 (isset($POPUP_META['snp_js_np_submit_success']) && !empty($POPUP_META['snp_js_np_submit_success'])) ||
1435 (isset($POPUP_META['snp_js_np_submit_error']) && !empty($POPUP_META['snp_js_np_submit_error'])) ||
1436 (isset($POPUP_META['snp_js_np_submit_after']) && !empty($POPUP_META['snp_js_np_submit_after'])) ||
1437 (isset($POPUP_META['snp_js_np_convert']) && !empty($POPUP_META['snp_js_np_convert'])) ||
1438 (isset($POPUP_META['snp_js_np_open']) && !empty($POPUP_META['snp_js_np_open'])) ||
1439 (isset($POPUP_META['snp_js_np_gotostep']) && !empty($POPUP_META['snp_js_np_gotostep'])) ||
1440 (isset($POPUP_META['snp_js_np_open_link']) && !empty($POPUP_META['snp_js_np_open_link'])) ||
1441 (isset($POPUP_META['snp_sound_on_open']) && !empty($POPUP_META['snp_sound_on_open']))
1442 ) {
1443 $return .= '<script>' . "\n";
1444 $return .= 'jQuery(document).ready(function() {' . "\n";
1445
1446 if (isset($POPUP_META['snp_js_np_submit']) && !empty($POPUP_META['snp_js_np_submit'])) {
1447 $return .= 'jQuery(document).on("ninja_popups_submit", function(event, data) {' . "\n";
1448 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1449 $return .= $POPUP_META['snp_js_np_submit'] . "\n";
1450 $return .= '}' . "\n";
1451 $return .= "});" . "\n";
1452 }
1453
1454 if (isset($POPUP_META['snp_js_np_submit_success']) && !empty($POPUP_META['snp_js_np_submit_success'])) {
1455 $return .= 'jQuery(document).on("ninja_popups_submit_success", function(event, data) {' . "\n";
1456 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1457 $return .= $POPUP_META['snp_js_np_submit_success'] . "\n";
1458 $return .= '}' . "\n";
1459 $return .= "});" . "\n";
1460 }
1461
1462
1463 if (isset($POPUP_META['snp_js_np_submit_error']) && !empty($POPUP_META['snp_js_np_submit_error'])) {
1464 $return .= 'jQuery(document).on("ninja_popups_submit_error", function(event, data) {' . "\n";
1465 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1466 $return .= $POPUP_META['snp_js_np_submit_error'] . "\n";
1467 $return .= '}' . "\n";
1468 $return .= "});" . "\n";
1469 }
1470
1471 if (isset($POPUP_META['snp_js_np_submit_after']) && !empty($POPUP_META['snp_js_np_submit_after'])) {
1472 $return .= 'jQuery(document).on("ninja_popups_submit_after", function(event, data) {' . "\n";
1473 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1474 $return .= $POPUP_META['snp_js_np_submit_after'] . "\n";
1475 $return .= '}' . "\n";
1476 $return .= "});" . "\n";
1477 }
1478
1479
1480 if (isset($POPUP_META['snp_js_np_convert']) && !empty($POPUP_META['snp_js_np_convert'])) {
1481 $return .= 'jQuery(document).on("ninja_popups_convert", function(event, data) {' . "\n";
1482 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1483 $return .= $POPUP_META['snp_js_np_convert'] . "\n";
1484 $return .= '}' . "\n";
1485 $return .= "});" . "\n";
1486 }
1487
1488 if (isset($POPUP_META['snp_js_np_open']) && !empty($POPUP_META['snp_js_np_open'])) {
1489 $return .= 'jQuery(document).on("ninja_popups_open", function(event, data) {' . "\n";
1490 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1491 $return .= $POPUP_META['snp_js_np_open'] . "\n";
1492 $return .= '}' . "\n";
1493 $return .= "});" . "\n";
1494 }
1495
1496 if (isset($POPUP_META['snp_js_np_gotostep']) && !empty($POPUP_META['snp_js_np_gotostep'])) {
1497 $return .= 'jQuery(document).on("ninja_popups_gotostep", function(event, data) {' . "\n";
1498 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1499 $return .= $POPUP_META['snp_js_np_gotostep'] . "\n";
1500 $return .= '}' . "\n";
1501 $return .= "});" . "\n";
1502 }
1503
1504 if (isset($POPUP_META['snp_js_np_open_link']) && !empty($POPUP_META['snp_js_np_open_link'])) {
1505 $return .= 'jQuery(document).on("ninja_popups_open_link", function(event, data) {' . "\n";
1506 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1507 $return .= $POPUP_META['snp_js_np_open_link'] . "\n";
1508 $return .= '}' . "\n";
1509 $return .= "});" . "\n";
1510 }
1511
1512 if (isset($POPUP_META['snp_sound_on_open']) && !empty($POPUP_META['snp_sound_on_open'])) {
1513 $return .= 'jQuery(document).on("ninja_popups_open", function(event, data) {' . "\n";
1514 $return .= 'if (event.popup_id == ' . $ID . ') {' . "\n";
1515 $return .= 'var audio = new Audio("' . $POPUP_META['snp_sound_on_open'] . '");' . "\n";
1516 $return .= 'audio.play();' . "\n";
1517 $return .= '}' . "\n";
1518 $return .= "});" . "\n";
1519 }
1520
1521 $return .= '});' . "\n";
1522 $return .= '</script>' . "\n";
1523 }
1524
1525 if ((isset($THEME_INFO['OPEN_FUNCTION']) || isset($THEME_INFO['CLOSE_FUNCION'])) && $type != 'inline') {
1526 $return .= '<script>'."\n";
1527 $return .= 'snp_f[\'snppopup-' . $type . ($type == 'content' || $type == 'inline' ? '-' . $ID : '') . '-open\']=' . $THEME_INFO['OPEN_FUNCTION'] . ($POPUP_META['snp_theme']['theme'] == 'builder' ? abs($ID) : '') . ';'."\n";
1528 $return .= 'snp_f[\'snppopup-' . $type . ($type == 'content' || $type == 'inline' ? '-' . $ID : '') . '-close\']=' . $THEME_INFO['CLOSE_FUNCION'] . ($POPUP_META['snp_theme']['theme'] == 'builder' ? abs($ID) : '') .';'."\n";
1529 $return .= '</script>'."\n";
1530 }
1531 $return .= '</div>';
1532
1533 //$return .= '<script>';
1534 //$return .= 'NinjaPopup.init("' . $ID . '", "' . $type . '", ' . json_encode($dataJsonConfig) . ');';
1535 //$return .= '</script>';
1536
1537 return $return;
1538}
1539
1540function snp_footer()
1541{
1542 global $snp_popups, $snp_ignore_cookies, $post, $detect;
1543 ?>
1544 <script>
1545 var snp_f = [];
1546 var snp_hostname = new RegExp(location.host);
1547 var snp_http = new RegExp("^(http|https)://", "i");
1548 var snp_cookie_prefix = '<?php echo (string)snp_get_option('cookie_prefix') ?>';
1549 var snp_separate_cookies = <?php echo (snp_get_option('separate_popup_cookies') == 'yes') ? 'true' : 'false' ?>;
1550 var snp_ajax_url = '<?php echo admin_url('admin-ajax.php') ?>';
1551 var snp_domain_url = '<?php echo site_url(); ?>';
1552 var snp_ajax_nonce = '<?php echo wp_create_nonce('snp_popup_submit'); ?>';
1553 var snp_ajax_ping_time = <?php echo (snp_get_option('wp_ajax_ping_time')) ? (snp_get_option('wp_ajax_ping_time')*1000) : 1000 ?>;
1554 var snp_ignore_cookies = <?php if (!$snp_ignore_cookies) echo 'false'; else echo 'true'; ?>;
1555 var snp_enable_analytics_events = <?php if (snp_get_option('enable_analytics_events') == 'yes' && !is_admin()) echo 'true'; else echo 'false'; ?>;
1556 var snp_is_mobile = <?php if ($detect->isMobile()) { echo 'true'; } else { echo 'false'; } ?>;
1557 var snp_enable_mobile = <?php if (snp_get_option('enable_mobile') == 'enabled' && !is_admin()) echo 'true'; else echo 'false'; ?>;
1558 var snp_use_in_all = <?php $use_in = snp_get_option('use_in'); if ($use_in['all'] == 1) echo 'true'; else echo 'false'; ?>;
1559 var snp_excluded_urls = [];
1560 <?php
1561 $exit_excluded_urls = snp_get_option('exit_excluded_urls');
1562 if (is_array($exit_excluded_urls)) {
1563 foreach ($exit_excluded_urls as $url) {
1564 echo "snp_excluded_urls.push('" . $url . "');";
1565 }
1566 }
1567 ?>
1568 </script>
1569 <div class="snp-root">
1570 <input type="hidden" id="snp_popup" value="" />
1571 <input type="hidden" id="snp_popup_id" value="" />
1572 <input type="hidden" id="snp_popup_theme" value="" />
1573 <input type="hidden" id="snp_exithref" value="" />
1574 <input type="hidden" id="snp_exittarget" value="" />
1575 <?php if (function_exists('is_woocommerce') && function_exists('WC')) { ?>
1576 <input type="hidden" id="snp_woocommerce_cart_contents" value="<?php echo WC()->cart->cart_contents_count; ?>" />
1577 <?php } ?>
1578 <?php
1579 $addedPopupContent = array();
1580
1581 // welcome popup
1582 if (!empty($snp_popups['welcome']['ID']) && intval($snp_popups['welcome']['ID'])) {
1583 if (!in_array($snp_popups['welcome']['ID'], $addedPopupContent)) {
1584 echo snp_create_popup($snp_popups['welcome']['ID'], $snp_popups['welcome']['AB_ID'], 'welcome');
1585
1586 $addedPopupContent[] = $snp_popups['welcome']['ID'];
1587 }
1588 }
1589
1590 // exit popup
1591 if (!empty($snp_popups['exit']['ID']) && intval($snp_popups['exit']['ID'])) {
1592 if (!in_array($snp_popups['exit']['ID'], $addedPopupContent)) {
1593 echo snp_create_popup($snp_popups['exit']['ID'], $snp_popups['exit']['AB_ID'], 'exit');
1594
1595 $addedPopupContent[] = $snp_popups['exit']['ID'];
1596 }
1597 }
1598
1599 // popups from content
1600 if (isset($snp_popups['content']) && is_array($snp_popups['content'])) {
1601 foreach ($snp_popups['content'] as $popup_id) {
1602 if (!in_array($popup_id['ID'], $addedPopupContent)) {
1603 echo snp_create_popup($popup_id['ID'], $popup_id['AB_ID'], 'content');
1604
1605 $addedPopupContent[] = $popup_id['ID'];
1606 }
1607 }
1608 }
1609 ?>
1610 <?php if (snp_get_option('recaptcha_api_key')) { ?>
1611 <script type="text/javascript">
1612 grecaptcha.ready(function () {
1613 grecaptcha.execute('<?php echo snp_get_option('recaptcha_api_key'); ?>', { action: 'NinjaPopUp' }).then(function (token) {
1614 jQuery('.ninja-popup-recaptcha3').val(token);
1615 });
1616 });
1617 </script>
1618 <?php } ?>
1619 </div>
1620 <?php
1621}
1622
1623function snp_enqueue_social_script()
1624{
1625 if (!snp_get_option('js_disable_fb') || is_admin()) {
1626 // Facebook
1627 wp_enqueue_script('fbsdk', 'https://connect.facebook.net/' . snp_get_option('fb_locale', 'en_GB') . '/all.js#xfbml=1', array());
1628 wp_localize_script('fbsdk', 'fbsdku', array(
1629 'xfbml' => 1,
1630 ));
1631 }
1632
1633 if (!snp_get_option('js_disable_gp') || is_admin()) {
1634 // Google Plus
1635 // Google Plus
1636 wp_enqueue_script('plusone', 'https://apis.google.com/js/plusone.js', array());
1637 }
1638
1639 if (!snp_get_option('js_disable_tw') || is_admin()) {
1640 // Twitter
1641 wp_enqueue_script('twitter', 'https://platform.twitter.com/widgets.js', array());
1642 }
1643
1644 if (!snp_get_option('js_disable_li') || is_admin()) {
1645 // Linkedin
1646 wp_enqueue_script('linkedin', 'https://platform.linkedin.com/in.js', array());
1647 }
1648}
1649
1650function snp_ninja_popup_shortcode($attr, $content = null)
1651{
1652 global $detect;
1653
1654 extract(shortcode_atts(array('id' => '', 'mobile_id' => '', 'autoopen' => false, 'enablemobile' => true), $attr));
1655
1656 if ($enablemobile == false && $detect->isMobile()) {
1657 return;
1658 }
1659
1660 if ($mobile_id && $detect->isMobile()) {
1661 snp_run_popup($mobile_id, 'content');
1662 } else {
1663 snp_run_popup($id, 'content');
1664 }
1665
1666 if (isset($autoopen) && $autoopen == true) {
1667 ?>
1668 <script type="text/javascript">
1669 jQuery(document).ready(function () {
1670 var snp_open_after = jQuery('#snppopup-content-<?php echo $id; ?> .snp_open_after').val();
1671 if (snp_open_after) {
1672 snp_timer_o = setTimeout("snp_open_popup('','','snppopup-content-<?php echo $id; ?>','content');", snp_open_after * 1000);
1673 } else {
1674 snp_open_popup('', '', 'snppopup-content-<?php echo $id; ?>', 'content');
1675 }
1676 });
1677 </script>
1678 <?php
1679 }
1680
1681 if ($content) {
1682 return '<a href="#ninja-popup-' . $id . '" class="snppopup-content" rel="' . $id . '">' . $content . ' </a>';
1683 }
1684
1685 return '';
1686}
1687add_shortcode('ninja-popup', 'snp_ninja_popup_shortcode');
1688
1689function snp_ninja_popup_external_link()
1690{
1691 return '<iframe src="" style="width: 100%; height: 100%;" class="ninja-popup-external-link-iframe"></iframe>';
1692}
1693add_shortcode('ninja-popup-external-link', 'snp_ninja_popup_external_link');
1694
1695function snp_run()
1696{
1697 global $post, $detect, $countryCode, $cityCode, $zipCode;
1698
1699 if (is_404()) {
1700 return;
1701 }
1702
1703 if (snp_get_option('enable') == 'disabled') {
1704 return;
1705 }
1706
1707 if ((isset($_REQUEST['nphide']) && $_REQUEST['nphide'] == 1) || isset($_COOKIE['nphide']) && $_COOKIE['nphide'] == 1) {
1708 setcookie('nphide', 1, 0, COOKIEPATH, COOKIE_DOMAIN, false);
1709 return;
1710 }
1711
1712 $welcome_phrase = 'welcome';
1713 $exit_phrase = 'exit';
1714
1715 if ($detect->isMobile()) {
1716 $welcome_phrase = 'mobile_welcome';
1717 $exit_phrase = 'mobile_exit';
1718 }
1719
1720 $WELCOME_ID = 'global';
1721 $EXIT_ID = 'global';
1722
1723 $postId = false;
1724 if (isset($post->ID)) {
1725 $postId = $post->ID;
1726 }
1727
1728 if (function_exists('is_woocommerce') && is_shop()) {
1729 $postId = get_option( 'woocommerce_shop_page_id' );
1730 }
1731
1732 if (function_exists('is_woocommerce') && is_cart()) {
1733 $postId = get_option( 'woocommerce_cart_page_id' );
1734 }
1735
1736 if (function_exists('is_woocommerce') && is_checkout()) {
1737 $postId = get_option( 'woocommerce_checkout_page_id' );
1738 }
1739
1740 if (function_exists('is_woocommerce') && is_account_page()) {
1741 $postId = get_option( 'woocommerce_myaccount_page_id' );
1742 }
1743
1744 if (
1745 $postId && (
1746 is_page() || is_single() || (
1747 function_exists('is_woocommerce') &&
1748 is_woocommerce()
1749 )
1750 )
1751 ) {
1752 $WELCOME_ID = get_post_meta($postId, 'snp_p_'.$welcome_phrase.'_popup', true);
1753 $WELCOME_ID = ($WELCOME_ID ? $WELCOME_ID : 'global');
1754
1755 $EXIT_ID = get_post_meta($postId, 'snp_p_'.$exit_phrase.'_popup', true);
1756 $EXIT_ID = ($EXIT_ID ? $EXIT_ID : 'global');
1757
1758 if ($WELCOME_ID == 'global' || $EXIT_ID == 'global') {
1759 if ($post->post_type == 'post') {
1760 $POST_CATS = wp_get_post_categories($post->ID);
1761 }
1762
1763 $enable_taxs = snp_get_option('enable_taxs');
1764 if (is_array($enable_taxs)) {
1765 foreach ((array) $enable_taxs as $k => $v) {
1766 $POST_CATS = array_merge((array) $POST_CATS, (array) wp_get_object_terms($post->ID, $k, array('fields' => 'ids')));
1767 }
1768 }
1769
1770 if (isset($POST_CATS) && is_array($POST_CATS)) {
1771 foreach ($POST_CATS as $term_id) {
1772 $term_meta = get_option("snp_taxonomy_" . $term_id);
1773 if (isset($term_meta[$welcome_phrase]) && $WELCOME_ID == 'global') {
1774 $WELCOME_ID = $term_meta[$welcome_phrase];
1775 }
1776
1777 if (isset($term_meta[$exit_phrase]) && $EXIT_ID == 'global') {
1778 $EXIT_ID = $term_meta[$exit_phrase];
1779 }
1780 }
1781 }
1782 }
1783 } elseif (is_category() || is_tax() || is_tag() || is_archive()) {
1784 $category = get_queried_object();
1785 if (isset($category->term_id)) {
1786 $term_meta = get_option("snp_taxonomy_" . $category->term_id);
1787 } else {
1788 $term_meta = [];
1789 }
1790 if (isset($term_meta[$welcome_phrase])) {
1791 $WELCOME_ID = $term_meta[$welcome_phrase];
1792 } else {
1793 $WELCOME_ID = 'global';
1794 }
1795
1796 if (isset($term_meta[$exit_phrase])) {
1797 $EXIT_ID = $term_meta[$exit_phrase];
1798 } else {
1799 $EXIT_ID = 'global';
1800 }
1801 }
1802
1803 if (defined('ICL_LANGUAGE_CODE')) {
1804 $snp_var_sufix = '_' . ICL_LANGUAGE_CODE;
1805 } else {
1806 $snp_var_sufix = '';
1807 }
1808
1809 // WELCOME
1810 if (snp_get_option('welcome_disable_for_logged') == 1 && is_user_logged_in()) {
1811 //Nothing to do here
1812 } else if (snp_get_option('welcome_enabled_for_logged') == 1 && !is_user_logged_in()) {
1813 //Nothing to do here
1814 } else {
1815 $WELCOME_ID = apply_filters('ninjapopups_welcome_id', $WELCOME_ID);
1816 if ($WELCOME_ID !== 'disabled' && $WELCOME_ID !== 'global') {
1817 snp_run_popup($WELCOME_ID, 'welcome');
1818 } elseif ($WELCOME_ID === 'global') {
1819
1820 $WELCOME_ID = snp_get_option($welcome_phrase.'_popup' . $snp_var_sufix);
1821 if ((int)snp_get_option('geoip_popup') === 1) {
1822 if (($welcomeGeoipPopups = snp_get_option($welcome_phrase.'_geoip_popup'))) {
1823 foreach ($welcomeGeoipPopups as $key => $value) {
1824 if (
1825 is_numeric($key) && (
1826 !empty($value['country']) ||
1827 !empty($value['city']) ||
1828 !empty($value['zip'])
1829 )
1830 ) {
1831 $countryPassed = false;
1832 if (empty($value['country'])) {
1833 $countryPassed = true;
1834 } else if (!empty($value['country']) && strtolower($countryCode) === strtolower($value['country'])) {
1835 $countryPassed = true;
1836 }
1837
1838 $cityPassed = false;
1839 if (empty($value['city'])) {
1840 $cityPassed = true;
1841 } else if (!empty($value['city']) && strtolower($cityCode) == strtolower($value['city'])) {
1842 $cityPassed = true;
1843 }
1844
1845 $zipPassed = false;
1846 if (empty($value['zip'])) {
1847 $zipPassed = true;
1848 } else if (!empty($value['zip']) && strtolower($zipCode) == strtolower($value['zip'])) {
1849 $zipPassed = true;
1850 }
1851
1852 if ($countryPassed && $cityPassed && $zipPassed) {
1853 $WELCOME_ID = $value['popup'];
1854 break;
1855 }
1856 }
1857 }
1858 }
1859 }
1860
1861 if ($WELCOME_ID === 'global' && defined('ICL_LANGUAGE_CODE')) {
1862 $WELCOME_ID = snp_get_option('welcome_popup');
1863 }
1864
1865 if ($WELCOME_ID !== 'disabled') {
1866 $welcome_display_in = snp_get_option('welcome_display_in');
1867 if (
1868 is_front_page() &&
1869 isset($welcome_display_in['home']) &&
1870 $welcome_display_in['home'] == 1
1871 ) {
1872 //home
1873 snp_run_popup($WELCOME_ID, 'welcome');
1874 }
1875 elseif (
1876 is_page() &&
1877 isset($welcome_display_in['pages']) &&
1878 $welcome_display_in['pages'] == 1
1879 ) {
1880 //page
1881 snp_run_popup($WELCOME_ID, 'welcome');
1882 } elseif (
1883 is_single() &&
1884 isset($welcome_display_in['posts']) &&
1885 $welcome_display_in['posts'] == 1
1886 ) {
1887 //post
1888 snp_run_popup($WELCOME_ID, 'welcome');
1889 } elseif (
1890 isset($welcome_display_in['others']) &&
1891 $welcome_display_in['others'] == 1 &&
1892 !is_front_page() &&
1893 !is_page() &&
1894 !is_single()
1895 ) {
1896 // other
1897 snp_run_popup($WELCOME_ID, 'welcome');
1898 } elseif (
1899 isset($welcome_display_in['others']) &&
1900 $welcome_display_in['others'] == 1 &&
1901 function_exists('is_woocommerce') &&
1902 is_woocommerce()
1903 ) {
1904 // woocomerce
1905 snp_run_popup($WELCOME_ID, 'welcome');
1906 }
1907 }
1908 }
1909 }
1910
1911 // EXIT
1912 if (snp_get_option('exit_disable_for_logged') == 1 && is_user_logged_in()) {
1913 //Nothing to do here
1914 } else if (snp_get_option('exit_enabled_for_logged') == 1 && !is_user_logged_in()) {
1915 //Nothing to do here
1916 } else {
1917 $EXIT_ID = apply_filters('ninjapopups_exit_id', $EXIT_ID);
1918 if ($EXIT_ID != 'disabled' && $EXIT_ID != 'global') {
1919 snp_run_popup($EXIT_ID, 'exit');
1920 } elseif ($EXIT_ID === 'global') {
1921 $EXIT_ID = snp_get_option($exit_phrase.'_popup' . $snp_var_sufix);
1922 if (snp_get_option('geoip_popup') === 1) {
1923 if (($exitGeoipPopups = snp_get_option($exit_phrase.'_geoip_popup'))) {
1924 foreach ($exitGeoipPopups as $key => $value) {
1925 if (
1926 is_numeric($key) && (
1927 !empty($value['country']) ||
1928 !empty($value['city']) ||
1929 !empty($value['zip'])
1930 )
1931 ) {
1932 $countryPassed = false;
1933 if (empty($value['country'])) {
1934 $countryPassed = true;
1935 } else if (!empty($value['country']) && strtolower($countryCode) === strtolower($value['country'])) {
1936 $countryPassed = true;
1937 }
1938
1939 $cityPassed = false;
1940 if (empty($value['city'])) {
1941 $cityPassed = true;
1942 } else if (!empty($value['city']) && strtolower($cityCode) == strtolower($value['city'])) {
1943 $cityPassed = true;
1944 }
1945
1946 $zipPassed = false;
1947 if (empty($value['zip'])) {
1948 $zipPassed = true;
1949 } else if (!empty($value['zip']) && strtolower($zipCode) == strtolower($value['zip'])) {
1950 $zipPassed = true;
1951 }
1952
1953 if ($countryPassed && $cityPassed && $zipPassed) {
1954 $EXIT_ID = $value['popup'];
1955 break;
1956 }
1957 }
1958 }
1959 }
1960 }
1961
1962 if ($EXIT_ID === 'global' && defined('ICL_LANGUAGE_CODE')) {
1963 $EXIT_ID = snp_get_option('exit_popup');
1964 }
1965
1966 if ($EXIT_ID != 'disabled') {
1967 $exit_display_in = snp_get_option('exit_display_in');
1968 if (
1969 is_front_page() &&
1970 isset($exit_display_in['home']) &&
1971 $exit_display_in['home'] == 1
1972 ) {
1973 //home
1974 snp_run_popup($EXIT_ID, 'exit');
1975 } elseif (
1976 is_page() &&
1977 isset($exit_display_in['pages']) &&
1978 $exit_display_in['pages'] == 1
1979 ) {
1980 //page
1981 snp_run_popup($EXIT_ID, 'exit');
1982 } elseif (
1983 is_single() &&
1984 isset($exit_display_in['posts']) &&
1985 $exit_display_in['posts'] == 1
1986 ) {
1987 //post
1988 snp_run_popup($EXIT_ID, 'exit');
1989 } elseif (
1990 isset($exit_display_in['others']) &&
1991 $exit_display_in['others'] == 1 &&
1992 !is_front_page() &&
1993 !is_page() &&
1994 !is_single()
1995 ) {
1996 // other
1997 snp_run_popup($EXIT_ID, 'exit');
1998 }
1999 }
2000 }
2001 }
2002
2003 add_filter('wp_nav_menu_objects', 'snp_wp_nav_menu_objects');
2004}
2005
2006function snp_wp_nav_menu_objects($items)
2007{
2008 $parents = array();
2009 foreach ($items as $item) {
2010 if (strpos($item->url, '#ninja-popup-') !== FALSE) {
2011 $ID = str_replace('#ninja-popup-', '', $item->url);
2012 if (intval($ID)) {
2013 snp_run_popup(intval($ID), 'content');
2014 }
2015 }
2016 }
2017
2018 return $items;
2019}
2020
2021function snp_setup()
2022{
2023
2024 register_post_type('snp_popups', array(
2025 'label' => 'Ninja Popups',
2026 'labels' => array(
2027 'name' => 'Ninja Popups',
2028 'menu_name' => 'Ninja Popups',
2029 'singular_name' => 'Popup',
2030 'add_new' => 'Add New Popup',
2031 'all_items' => 'Popups',
2032 'add_new_item' => 'Add New Popup',
2033 'edit_item' => 'Edit Popup',
2034 'new_item' => 'New Popup',
2035 'view_item' => 'View Popup',
2036 'search_items' => 'Search Popups',
2037 'not_found' => 'No popups found',
2038 'not_found_in_trash' => 'No popups found in Trash'
2039 ),
2040 'hierarchical' => false,
2041 'public' => true,
2042 'exclude_from_search' => true,
2043 'publicly_queryable' => false,
2044 'show_in_nav_menus' => false,
2045 'show_in_admin_bar' => false,
2046 'show_in_menu' => true,
2047 'capability_type' => 'page',
2048 'supports' => array('title', 'editor'),
2049 'menu_position' => 207,
2050 'menu_icon' => ''
2051 ));
2052
2053 register_post_type('snp_ab', array(
2054 'label' => 'A/B Testing',
2055 'labels' => array(
2056 'name' => 'A/B Testing',
2057 'menu_name' => 'A/B Testing',
2058 'singular_name' => 'A/B Testing',
2059 'add_new' => 'Add New',
2060 'all_items' => 'A/B Testing',
2061 'add_new_item' => 'Add New',
2062 'edit_item' => 'Edit',
2063 'new_item' => 'New',
2064 'view_item' => 'View',
2065 'search_items' => 'Search',
2066 'not_found' => 'Not found',
2067 'not_found_in_trash' => 'Not found in Trash'
2068 ),
2069 'hierarchical' => false,
2070 'public' => true,
2071 'exclude_from_search' => true,
2072 'publicly_queryable' => false,
2073 'show_in_nav_menus' => false,
2074 'show_in_admin_bar' => false,
2075 'show_in_menu' => 'edit.php?post_type=snp_popups',
2076 'capability_type' => 'page',
2077 'supports' => array('title')
2078 ));
2079
2080 register_post_type('snp_mail_log', array(
2081 'label' => 'WP-Mail Logs',
2082 'labels' => array(
2083 'name' => __('WP-Mail Records', 'nhp-opts'),
2084 'singular_name' => __('WP-Mail Record', 'nhp-opts'),
2085 'menu_name' => __('WP-Mail Log', 'nhp-opts'),
2086 ),
2087 'hierarchical' => false,
2088 'public' => true,
2089 'exclude_from_search' => true,
2090 'publicly_queryable' => false,
2091 'show_in_nav_menus' => false,
2092 'show_in_admin_bar' => false,
2093 'show_in_menu' => 'edit.php?post_type=snp_popups',
2094 'capability_type' => 'page',
2095 'supports' => array('title', 'editor'),
2096 'has_archive' => false,
2097 'query_var' => 'snp_mail_log',
2098 'capabilities' => array(
2099 'read_post' => 'manage_options',
2100 'delete_post' => 'do_not_allow',
2101 'edit_post' => 'manage_options',
2102 'edit_other_posts' => 'manage_options',
2103 'read_posts' => 'manage_options',
2104 'edit_posts' => 'manage_options',
2105 'delete_posts' => 'do_not_allow',
2106 'create_posts' => 'do_not_allow',
2107 ),
2108 ));
2109
2110 add_action('wp_ajax_nopriv_snp_popup_stats', 'snp_popup_stats');
2111 add_action('wp_ajax_snp_popup_stats', 'snp_popup_stats');
2112 add_action('wp_ajax_nopriv_snp_popup_submit', 'snp_popup_submit');
2113 add_action('wp_ajax_snp_popup_submit', 'snp_popup_submit');
2114 add_action('wp_ajax_nopriv_snp_popup_spend_time', 'snp_popup_spend_time');
2115 add_action('wp_ajax_snp_popup_spend_time', 'snp_popup_spend_time');
2116 //add_filter('wp_mail', 'snp_log_wp_mail');
2117 wp_enqueue_script('jquery');
2118}
2119
2120function snp_remove_meta_boxes()
2121{
2122 remove_meta_box('linktargetdiv', 'snp_mail_log', 'normal');
2123 remove_meta_box('linkxfndiv', 'snp_mail_log', 'normal');
2124 remove_meta_box('linkadvanceddiv', 'snp_mail_log', 'normal');
2125 remove_meta_box('postexcerpt', 'snp_mail_log', 'normal');
2126 remove_meta_box('trackbacksdiv', 'snp_mail_log', 'normal');
2127 remove_meta_box('postcustom', 'snp_mail_log', 'normal');
2128 remove_meta_box('commentstatusdiv', 'snp_mail_log', 'normal');
2129 remove_meta_box('commentsdiv', 'snp_mail_log', 'normal');
2130 remove_meta_box('revisionsdiv', 'snp_mail_log', 'normal');
2131 remove_meta_box('authordiv', 'snp_mail_log', 'normal');
2132 remove_meta_box('slugdiv', 'snp_mail_log', 'normal');
2133 remove_meta_box('sqpt-meta-tags', 'snp_mail_log', 'normal');
2134 remove_meta_box('submitdiv', 'snp_mail_log', 'side');
2135}
2136
2137function remove_bulk_actions($actions)
2138{
2139 unset( $actions['inline'] );
2140 return $actions;
2141}
2142
2143add_action( 'admin_menu', 'snp_remove_meta_boxes' );
2144
2145add_filter('bulk_actions-snp_mail_log', 'remove_bulk_actions');
2146
2147if (!is_admin() && !defined('DOING_CRON')) {
2148 add_action('init', 'snp_session_start', 1);
2149}
2150
2151add_action('init', 'snp_setup', 15);
2152
2153if (is_admin()) {
2154 add_action('init', 'snp_setup_admin', 15);
2155}
2156
2157if (!is_admin()) {
2158 if (snp_get_option('run_hook') == 'wp') {
2159 add_action('wp', 'snp_run');
2160 } else {
2161 add_action('get_header', 'snp_run');
2162 }
2163}
2164
2165function snp_session_start() {
2166 if (!session_id()) {
2167 session_start();
2168 }
2169}
2170
2171function snp_popup_spend_time()
2172{
2173 if (!session_id()) {
2174 session_start();
2175 }
2176
2177 $time = 1;
2178 if (!isset($_SESSION['snp_time_on_page_counter'])) {
2179 $_SESSION['snp_time_on_page_counter'] = $time;
2180 } else {
2181 $time = $_SESSION['snp_time_on_page_counter'];
2182
2183 $_SESSION['snp_time_on_page_counter'] = $time + 1;
2184 }
2185
2186 echo json_encode(array(
2187 'time' => $time
2188 ));
2189 exit;
2190}
2191
2192function snp_update_log_subscription($cf_data, $log_list_id, $errors = null)
2193{
2194 global $wpdb;
2195
2196 if (isset($_POST['name'])) {
2197 $cf_data['name'] = $_POST['name'];
2198 }
2199
2200 $data = array(
2201 'action' => 'subscribtion',
2202 'email' => snp_trim($_POST['email']),
2203 'ip' => $_SERVER['REMOTE_ADDR'],
2204 'browser' => $_SERVER['HTTP_USER_AGENT'],
2205 'list' => $log_list_id,
2206 'popup_id' => $_POST['popup_ID'],
2207 'custom_fields' => json_encode($cf_data),
2208 'referer' => $_SERVER['HTTP_REFERER'],
2209 'errors' => $errors,
2210 );
2211
2212 $result = $wpdb->insert($wpdb->prefix.'snp_log', $data);
2213}
2214
2215function snp_update_log_popup($popup_id, $errors = null)
2216{
2217 global $wpdb;
2218
2219 $data = array(
2220 'action' => 'popup_view',
2221 'ip' => $_SERVER['REMOTE_ADDR'],
2222 'browser' => $_SERVER['HTTP_USER_AGENT'],
2223 'popup_id' => $popup_id,
2224 'referer' => $_SERVER['HTTP_REFERER'],
2225 'errors' => $errors,
2226 );
2227
2228 $wpdb->insert($wpdb->prefix.'snp_log', $data, array('%s','%s','%s','%s','%s','%s'));
2229}
2230
2231function snp_get_mc_fields($apikey, $list_id)
2232{
2233 require_once SNP_DIR_PATH . '/include/mailchimp/MC_Lists.php';
2234
2235 $rest = new MC_Lists($apikey);
2236 $fields = json_decode($rest->mergeFields($list_id));
2237
2238 $result = array();
2239 foreach($fields->merge_fields as $v) {
2240 $result[$v->merge_id]['field'] = $v->tag;
2241 $result[$v->merge_id]['name'] = $v->name;
2242 $result[$v->merge_id]['required'] = $v->required;
2243 }
2244
2245 return json_encode($result, true);
2246}
2247
2248function snp_get_mc_groups($apikey, $list_id)
2249{
2250 require_once SNP_DIR_PATH . '/include/mailchimp/MC_Lists.php';
2251
2252 $rest = new MC_Lists($apikey);
2253 $groups = json_decode($rest->getGroups($list_id));
2254
2255 $result = array();
2256 foreach ($groups->categories as $v) {
2257 $result[$v->id]['field'] = $v->id;
2258 $result[$v->id]['name'] = $v->title;
2259 }
2260
2261 return json_encode($result, true);
2262}
2263
2264function snp_get_sharpspring_fields($account_id, $secret_key)
2265{
2266 if (!defined('SHARPSPRING_ACCOUNTID')) {
2267 define('SHARPSPRING_ACCOUNTID', snp_get_option('ml_sharpspring_account_id'));
2268 }
2269
2270 if (!defined('SHARPSPRING_SECRETKEY')) {
2271 define('SHARPSPRING_SECRETKEY', snp_get_option('ml_sharpspring_secret_key'));
2272 }
2273
2274 require_once SNP_DIR_PATH . '/include/sharpspring/sharpspring.php';
2275
2276 $api = new \CollingMedia\SharpSpring(SHARPSPRING_ACCOUNTID, SHARPSPRING_SECRETKEY);
2277
2278 $response = $api->call('getFields', array(
2279 'where' => ''
2280 ));
2281
2282 $result = array();
2283 if (isset($response['result']['field'])) {
2284 foreach ($response['result']['field'] as $field) {
2285 $result[$field['id']]['field'] = $field['systemName'];
2286 $result[$field['id']]['name'] = $field['label'];
2287 $result[$field['id']]['required'] = $field['isRequired'];
2288 }
2289 }
2290
2291 return json_encode($result, true);
2292}
2293
2294function snp_log_wp_mail($mail)
2295{
2296 $logger = new \Relio\Entity\MailLogger();
2297 $logger->log($mail['to'], $mail['subject'], $mail['message'], $mail['headers'], $mail['attachments']);
2298 $logger->save();
2299}
2300