PluginProbe
Icegram Engage – Popups, Optins, CTAs & Lead Generation / 1.10.46
Icegram Engage – Popups, Optins, CTAs & Lead Generation v1.10.46
3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 trunk 1.1 1.1.1 1.1.2 1.10 1.10.1 1.10.10 1.10.11 1.10.12 All 180 releases
icegram / icegram.php

icegram.php in Icegram Engage – Popups, Optins, CTAs & Lead Generation 1.10.46, at icegram.php

2,073 lines 75.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Icegram - Popups, Optins, CTAs & lot more...
4 * Plugin URI: https://www.icegram.com/
5 * Description: All in one solution to inspire, convert and engage your audiences. Action bars, Popup windows, Messengers, Toast notifications and more. Awesome themes and powerful rules.
6 * Version: 1.10.46
7 * Tested up to: 5.6
8 * Author: icegram
9 * Author URI: https://www.icegram.com/
10 * Copyright (c) 2014-19 Icegram
11 * License: GPLv3
12 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
13 *
14 * Text Domain: icegram
15 * Domain Path: /lang/
16 */
17
18 /**
19 * Main class Icegram
20 */
21 class Icegram {
22
23 var $plugin_url;
24 var $plugin_path;
25 var $version;
26 var $_wpautop_tags;
27 var $message_types;
28 var $message_type_objs;
29 var $shortcode_instances;
30 var $available_headlines;
31 var $mode;
32 var $cache_compatibility;
33
34 public static $current_page_id;
35
36 function __construct() {
37 global $ig_feedback, $ig_tracker;
38
39 $feedback_version = '1.2.2';
40 $ig_tracker = 'IG_Tracker_V_' . str_replace( '.', '_', $feedback_version );
41
42 $this->version = "1.10.46";
43 $this->shortcode_instances = array();
44 $this->mode = 'local';
45 $this->plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
46 $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
47 $this->define_constants();
48 $this->include_classes( $feedback_version );
49 $this->cache_compatibility = get_option( 'icegram_cache_compatibility', 'no' );
50
51 if ( is_admin() ) {
52 $ig_feedback->render_deactivate_feedback();
53 }
54
55 if ( is_admin() && current_user_can( 'edit_posts' ) ) {
56 $ig_campaign_admin = Icegram_Campaign_Admin::getInstance();
57 $ig_message_admin = Icegram_Message_Admin::getInstance();
58 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_admin_styles_and_scripts' ) );
59 add_action( 'admin_print_styles', array( &$this, 'remove_preview_button' ) );
60 add_filter( 'post_row_actions', array( &$this, 'remove_row_actions' ), 10, 2 );
61
62 add_action( 'admin_menu', array( &$this, 'admin_menus' ) );
63 add_action( 'admin_init', array( &$this, 'welcome' ) );
64 add_action( 'admin_init', array( &$this, 'dismiss_admin_notice' ) );
65
66 add_action( 'admin_init', array( &$this, 'import_gallery_item' ) );
67
68 add_action( 'icegram_settings_after', array( &$this, 'klawoo_subscribe_form' ) );
69 add_action( 'icegram_about_changelog', array( &$this, 'klawoo_subscribe_form' ) );
70 add_action( 'icegram_settings_after', array( &$this, 'icegram_houskeeping' ) );
71 add_action( 'admin_notices', array( &$this, 'add_admin_notices' ) );
72 add_filter( 'plugin_action_links', array( $this, 'ig_plugin_settings_link' ), 10, 2 );
73 } else {
74 add_action( 'wp_footer', array( &$this, 'icegram_load_data' ) );
75 }
76 if ( $this->cache_compatibility === 'no' ) {
77 add_action( 'wp_footer', array( &$this, 'display_messages' ) );
78 }
79 add_shortcode( 'icegram', array( &$this, 'execute_shortcode' ) );
80 add_shortcode( 'ig_form', array( &$this, 'execute_form_shortcode' ) );
81 // WPML compatibility
82 add_filter( 'icegram_identify_current_page', array( &$this, 'wpml_get_parent_id' ), 10 );
83
84 add_filter( 'icegram_branding_data', array( &$this, 'branding_data_remove' ), 10 );
85 add_action( 'wp_enqueue_scripts', array( &$this, 'identify_current_page' ) );
86 add_filter( 'icegram_get_valid_campaigns_sql', array( &$this, 'append_to_valid_campaigns_sql' ), 10, 2 );
87 add_action( 'icegram_print_js_css_data', array( &$this, 'print_js_css_data' ), 10, 1 );
88 // common
89 add_action( 'init', array( &$this, 'register_campaign_post_type' ) );
90 add_action( 'init', array( &$this, 'register_message_post_type' ) );
91
92 add_action( 'icegram_loaded', array( &$this, 'load_compat_classes' ) );
93
94 // execute shortcode in sidebar
95 add_filter( 'widget_text', array( &$this, 'ig_widget_text_filter' ) );
96
97 add_filter( 'rainmaker_validate_request', array( &$this, 'form_submission_validate_request' ), 10, 2 );
98 add_filter( 'icegram_data', array( $this, 'two_step_mobile_popup' ), 100, 1 );
99
100
101 if ( defined( 'DOING_AJAX' ) ) {
102 if ( $this->cache_compatibility === 'yes' ) {
103 add_action( 'wp_ajax_display_messages', array( &$this, 'display_messages' ) );
104 add_action( 'wp_ajax_nopriv_display_messages', array( &$this, 'display_messages' ) );
105 }
106 add_action( 'wp_ajax_icegram_event_track', array( &$this, 'icegram_event_track' ) );
107 add_action( 'wp_ajax_nopriv_icegram_event_track', array( &$this, 'icegram_event_track' ) );
108 add_action( 'wp_ajax_klawoo_subscribe', array( &$this, 'klawoo_subscribe' ) );
109 add_action( 'wp_ajax_icegram_run_housekeeping', array( &$this, 'run_housekeeping' ) );
110 add_action( 'wp_ajax_save_gallery_data', array( &$this, 'save_gallery_data' ) );
111
112 }
113
114 }
115
116 function ig_plugin_settings_link( $links, $file ) {
117 if ( $file == plugin_basename( __FILE__ ) ) {
118 $settings_link = '<a href="edit.php?post_type=ig_campaign&page=icegram-settings">' . __( 'Settings', 'icegram' ) . '</a>';
119 $support_link = '<a href="edit.php?post_type=ig_campaign&page=icegram-support">' . __( 'Support', 'icegram' ) . '</a>';
120 array_unshift( $links, $support_link );
121 array_unshift( $links, $settings_link );
122 }
123
124 return $links;
125
126 }
127
128 public function define_constants() {
129 if ( ! defined( 'IG_PLUGIN_URL' ) ) {
130 define( 'IG_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
131 }
132 }
133
134 public function load_compat_classes() {
135
136 $compat_classes = (array) glob( $this->plugin_path . '/classes/compat/class-icegram-compat-*.php' );
137 if ( empty( $compat_classes ) ) {
138 return;
139 }
140
141 $active_plugins = (array) get_option( 'active_plugins', array() );
142 if ( is_multisite() ) {
143 $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
144 }
145 $active_plugins = array_unique( array_merge( array_values( $active_plugins ), array_keys( $active_plugins ) ) );
146 $active_plugins_with_slugs = array();
147 foreach ( $active_plugins as $key => $value ) {
148 $slug = dirname( $value );
149 if ( $slug == '.' ) {
150 unset( $active_plugins[ $key ] );
151 } else {
152 $active_plugins[ $key ] = $slug;
153 }
154 }
155
156 foreach ( $compat_classes as $file ) {
157 if ( is_file( $file ) ) {
158 $slug = str_replace( 'class-icegram-compat-', '', str_replace( ".php", "", basename( $file ) ) );
159 if ( in_array( $slug, $active_plugins ) ) {
160 include_once( $file );
161 $class_name = 'Icegram_Compat_' . str_replace( '-', '_', $slug );
162 if ( class_exists( $class_name ) ) {
163 new $class_name();
164 }
165 }
166 }
167 }
168 }
169
170 /**
171 * Show promotion
172 */
173 public function add_admin_notices() {
174 global $icegram;
175
176 $screen = get_current_screen();
177 if ( ! in_array( $screen->id, array( 'ig_campaign', 'ig_message', 'edit-ig_message', 'edit-ig_campaign' ), true ) ) {
178 return;
179 }
180
181 if ( ! $icegram->is_premium_installed() ) {
182 include_once( 'ig-offer.php' );
183 }
184
185 }
186
187 public function dismiss_admin_notice() {
188 if ( isset( $_GET['ig_dismiss_admin_notice'] ) && $_GET['ig_dismiss_admin_notice'] == '1' && isset( $_GET['ig_option_name'] ) ) {
189 $option_name = sanitize_text_field( $_GET['ig_option_name'] );
190 update_option( $option_name . '_icegram', 'yes', false );
191
192 //BFCM 2020 offer
193 if ( 'ig_offer_bfcm_2020' === $option_name ) {
194 $url = "https://www.icegram.com/pricing/?utm_source=in_app&utm_medium=ig_banner&utm_campaign=offer_bfcm_2020";
195 header( "Location: {$url}" );
196 exit();
197 } else {
198 $referer = wp_get_referer();
199 wp_safe_redirect( $referer );
200 exit();
201 }
202 }
203 }
204
205 public function klawoo_subscribe_form() {
206 ?>
207 <div class="wrap">
208 <?php
209 if ( stripos( get_current_screen()->base, 'settings' ) !== false ) {
210 echo "<h2>" . __( 'Free Add-ons, Proven Marketing Tricks and Updates', 'icegram' ) . "</h2>";
211 }
212 $current_user = wp_get_current_user();
213 $customer_email = $current_user->user_email;
214 ?>
215 <table class="form-table">
216 <tr>
217 <th scope="row"><?php _e( 'Get add-ons and tips...', 'icegram' ) ?></th>
218 <td>
219 <form name="klawoo_subscribe" action="#" method="POST" accept-charset="utf-8">
220 <input class="ltr" type="text" name="name" id="name" placeholder="Name"/>
221 <input class="regular-text ltr" type="text" name="email" id="email" placeholder="Email" value="<?php echo $customer_email ?>"/>
222 <input type="hidden" name="list" value="7I763v6Ldrs3YhJeee5EOgFA"/>
223 <input type="submit" name="submit" id="submit" class="button button-primary" value="Subscribe">
224 <br><br>
225 <input type="checkbox" name="es-gdpr-agree" id="es-gdpr-agree" value="1" required="required">
226 <label for="es-gdpr-agree"><?php echo sprintf( __( 'I have read and agreed to our %s.', 'icegram' ), '<a href="https://www.icegram.com/privacy-policy/" target="_blank">' . __( 'Privacy Policy', 'icegram' ) . '</a>' ); ?></label>
227 <br>
228 </form>
229 <div id="klawoo_response"></div>
230 </td>
231 </tr>
232 </table>
233 </div>
234 <script type="text/javascript">
235 jQuery(function () {
236 jQuery("form[name=klawoo_subscribe]").submit(function (e) {
237 e.preventDefault();
238
239 jQuery('#klawoo_response').html('');
240 params = jQuery("form[name=klawoo_subscribe]").serializeArray();
241 params.push({name: 'action', value: 'klawoo_subscribe'});
242
243 jQuery.ajax({
244 method: 'POST',
245 type: 'text',
246 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
247 data: params,
248 success: function (response) {
249 if (response != '') {
250 jQuery('#klawoo_response').html(response);
251 } else {
252 jQuery('#klawoo_response').html('error!');
253 }
254 }
255 });
256 });
257 });
258 </script>
259 <?php
260 }
261
262
263 public function klawoo_subscribe() {
264 $url = 'http://app.klawoo.com/subscribe';
265
266 if ( ! empty( $_POST ) ) {
267 $params = $_POST;
268 } else {
269 exit();
270 }
271 $method = 'POST';
272 $qs = http_build_query( $params );
273
274 $options = array(
275 'timeout' => 15,
276 'method' => $method
277 );
278
279 if ( $method == 'POST' ) {
280 $options['body'] = $qs;
281 } else {
282 if ( strpos( $url, '?' ) !== false ) {
283 $url .= '&' . $qs;
284 } else {
285 $url .= '?' . $qs;
286 }
287 }
288
289 $response = wp_remote_request( $url, $options );
290 if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
291 $data = $response['body'];
292 if ( $data != 'error' ) {
293
294 $message_start = substr( $data, strpos( $data, '<body>' ) + 6 );
295 $remove = substr( $message_start, strpos( $message_start, '</body>' ) );
296 $message = trim( str_replace( $remove, '', $message_start ) );
297 echo( $message );
298 exit();
299 }
300 }
301 exit();
302 }
303
304 public function icegram_houskeeping() {
305 ?>
306 <div class="wrap">
307 <?php
308 if ( stripos( get_current_screen()->base, 'settings' ) !== false ) {
309 ?>
310 <form name="icegram_housekeeping" action="#" method="POST" accept-charset="utf-8">
311 <h2><?php _e( 'Housekeeping', 'icegram' ) ?></h2>
312 <p class="ig_housekeeping">
313 <label for="icegram_remove_shortcodes">
314 <input type="checkbox" name="icegram_remove_shortcodes" value="yes"/>
315 <?php _e( 'Remove all Icegram shortcodes', 'icegram' ); ?>
316 </label>
317 <br/><br/>
318 <label for="icegram_remove_all_data">
319 <input type="checkbox" name="icegram_remove_all_data" value="yes"/>
320 <?php _e( 'Remove all Icegram campaigns and messages', 'icegram' ); ?>
321 </label>
322 <br/><br/>
323 <img alt="" src="<?php echo admin_url( 'images/wpspin_light.gif' ) ?>" class="ig_loader" style="vertical-align:middle;display:none"/>
324 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Clean Up', 'icegram' ); ?>">
325 <div id="icegram_housekeeping_response"></div>
326 </p>
327 </form>
328
329 </div>
330 <script type="text/javascript">
331 jQuery(function () {
332 jQuery("form[name=icegram_housekeeping]").submit(function (e) {
333 if (confirm("<?php _e( 'You won\'t be able to recover this data once you proceed. Do you really want to perform this action?', 'icegram' ); ?>") == true) {
334 e.preventDefault();
335 jQuery('.ig_loader').show();
336 jQuery('#icegram_housekeeping_response').text("");
337 params = jQuery("form[name=icegram_housekeeping]").serializeArray();
338 params.push({name: 'action', value: 'icegram_run_housekeeping'});
339 params.push({name: 'security', value: '<?php echo wp_create_nonce( 'ig_run_housekeeping' ); ?> '});
340
341 jQuery.ajax({
342 method: 'POST',
343 type: 'text',
344 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
345 data: params,
346 success: function (response) {
347 jQuery('.ig_loader').hide();
348 jQuery('#icegram_housekeeping_response').text("<?php _e( 'Done!', 'icegram' ); ?>");
349 }
350 });
351 }
352 });
353 });
354 </script>
355 <?php
356 }
357 }
358
359 public function run_housekeeping() {
360 check_ajax_referer( 'ig_run_housekeeping', 'security' );
361 global $wpdb, $current_user;
362 $params = $_POST;
363 $_POST = array();
364 if ( current_user_can( 'manage_options' ) && ! empty( $params['icegram_remove_shortcodes'] ) && $params['icegram_remove_shortcodes'] == 'yes' ) {
365 // first get all posts with [icegram] shortcode in them
366 $sql = "SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE '%[icegram %]%' and `post_type` != 'revision' ";
367 $posts = $wpdb->get_results( $sql, OBJECT );
368 if ( ! empty( $posts ) && is_array( $posts ) ) {
369 foreach ( $posts as $post ) {
370 $post_content = $post->post_content;
371 // remove shortcode with regexp now
372 $re = "/\\[icegram(.)*\\]/i";
373 $post_content = preg_replace( $re, '', $post_content );
374 // save post content back
375 if ( $post_content && $post_content != $post->post_content ) {
376 wp_update_post( array(
377 'ID' => $post->ID,
378 'post_content' => $post_content
379 ) );
380 }
381 }
382 }
383 }
384
385 if ( ! empty( $params['icegram_remove_all_data'] ) && $params['icegram_remove_all_data'] == 'yes' ) {
386 $posts = get_posts( array( 'post_type' => array( 'ig_campaign', 'ig_message' ) ) );
387 if ( ! empty( $posts ) && is_array( $posts ) ) {
388 foreach ( $posts as $post ) {
389 wp_delete_post( $post->ID, true );
390 }
391 }
392 do_action( 'icegram_remove_all_data' );
393 }
394 $_POST = $params;
395 }
396
397 public function icegram_event_track() {
398 if ( ! empty( $_POST['ig_local_url_cs'] ) && isset( $_SERVER['HTTP_ORIGIN'] ) ) {
399 $parts = parse_url( $_POST['ig_local_url_cs'] );
400 $base_url = $parts["scheme"] . "://" . $parts["host"];
401 header( 'Access-Control-Allow-Origin: ' . $base_url );
402 header( 'Access-Control-Allow-Credentials: true' );
403 }
404
405 if ( ! empty( $_POST['event_data'] ) ) {
406 foreach ( $_POST['event_data'] as $event ) {
407 switch ( $event['type'] ) {
408 case 'shown':
409 if ( is_array( $event['params'] ) && ! empty( $event['params']['message_id'] ) ) {
410 $messages_shown[] = $event['params']['message_id'];
411 if ( ! empty( $event['params']['expiry_time'] ) ) {
412 if ( $event['params']['expiry_time'] == 'today' ) {
413 $event['params']['expiry_time'] = strtotime( '+1 day', mktime( 0, 0, 0 ) );
414 } elseif ( $event['params']['expiry_time'] == 'current_session' ) {
415 $event['params']['expiry_time'] = 0;
416 } else {
417 $event['params']['expiry_time'] = strtotime( $event['params']['expiry_time'] );
418 }
419
420 $event['default'] = true;
421 $event = apply_filters( 'icegram_check_event_track', $event );
422 if ( $event['default'] ) {
423 setcookie( 'icegram_campaign_shown_' . floor( $event['params']['campaign_id'] ), true, $event['params']['expiry_time'], '/' );
424 }
425 }
426 }
427 break;
428 case 'clicked':
429 if ( is_array( $event['params'] ) && ! empty( $event['params']['message_id'] ) ) {
430 $messages_clicked[] = $event['params']['message_id'];
431 if ( ! empty( $event['params']['expiry_time_clicked'] ) ) {
432 if ( $event['params']['expiry_time_clicked'] == 'today' ) {
433 $event['params']['expiry_time_clicked'] = strtotime( '+1 day', mktime( 0, 0, 0 ) );
434 } elseif ( $event['params']['expiry_time_clicked'] == 'current_session' ) {
435 $event['params']['expiry_time_clicked'] = 0;
436 } else {
437 $event['params']['expiry_time_clicked'] = strtotime( $event['params']['expiry_time_clicked'] );
438 }
439 //setcookie('icegram_messages_clicked_'.$event['params']['message_id'],true , $event['params']['expiry_time_clicked'] , '/' );
440 setcookie( 'icegram_campaign_clicked_' . floor( $event['params']['campaign_id'] ), true, $event['params']['expiry_time_clicked'], '/' );
441 }
442 }
443 break;
444
445 default:
446 break;
447 }
448
449 // Emit event for other plugins to handle it
450 do_action( 'icegram_event_track', $event );
451 do_action( 'icegram_event_track_' . $event['type'], $event['params'] );
452 }
453 }
454 exit();
455 }
456
457 static function install() {
458 // Redirect to welcome screen
459 delete_option( '_icegram_activation_redirect' );
460 add_option( '_icegram_activation_redirect', 'pending' );
461 }
462
463 public function welcome() {
464
465 $this->db_update();
466 // Bail if no activation redirect transient is set
467 if ( false === get_option( '_icegram_activation_redirect' ) ) {
468 return;
469 }
470
471 // Delete the redirect transient
472 delete_option( '_icegram_activation_redirect' );
473
474 wp_redirect( admin_url( 'edit.php?post_type=ig_campaign&page=icegram-support' ) );
475 exit;
476 }
477
478 function db_update() {
479 $current_db_version = get_option( 'icegram_db_version' );
480 if ( ! $current_db_version || version_compare( $current_db_version, '1.2', '<' ) ) {
481 include( 'updates/icegram-update-1.2.php' );
482 }
483 }
484
485 public function admin_menus() {
486
487 $welcome_page_title = __( 'Welcome to Icegram', 'icegram' );
488 $gallery_page_title = '<span style="color:#f18500;font-weight:bolder;">' . __( 'Gallery', 'icegram' ) . '<span>';
489 $gallery = add_submenu_page( 'edit.php?post_type=ig_campaign', $gallery_page_title, $gallery_page_title, 'manage_options', 'icegram-gallery', array( $this, 'gallery_screen' ) );
490 $settings_page_title = __( 'Settings', 'icegram' );
491 $upgrade_page_title = '<span style="color:#f18500;font-weight:bolder;">' . __( 'Upgrade', 'icegram' ) . '</span>';
492
493 $menu_title = __( 'Docs & Support', 'icegram' );
494 $about = add_submenu_page( 'edit.php?post_type=ig_campaign', $welcome_page_title, $menu_title, 'manage_options', 'icegram-support', array( $this, 'about_screen' ) );
495 $settings = add_submenu_page( 'edit.php?post_type=ig_campaign', $settings_page_title, $settings_page_title, 'manage_options', 'icegram-settings', array( $this, 'settings_screen' ) );
496 $upgrade = add_submenu_page( 'edit.php?post_type=ig_campaign', $upgrade_page_title, $upgrade_page_title, 'manage_options', 'icegram-upgrade', array( $this, 'upgrade_screen' ) );
497
498
499 add_action( 'admin_print_styles-' . $about, array( $this, 'admin_css' ) );
500 add_action( 'admin_print_styles-' . $settings, array( $this, 'admin_css' ) );
501 add_action( 'admin_print_styles-' . $upgrade, array( $this, 'admin_css' ) );
502
503 }
504
505 public function admin_css() {
506 wp_enqueue_style( 'icegram-activation', $this->plugin_url . '/assets/css/admin.min.css' );
507 }
508
509 public function about_screen() {
510
511 // Import data if not done already
512 if ( false === get_option( 'icegram_sample_data_imported' ) ) {
513 $this->import_sample_data( $this->get_sample_data() );
514 }
515
516 include( 'about-icegram.php' );
517 }
518
519 public function settings_screen() {
520 include( 'settings.php' );
521 }
522
523 public function upgrade_screen() {
524 // include ( 'addons.php' );
525 }
526
527 public function check_for_gallery_items( $force_update = false ) {
528 global $icegram;
529 if ( $force_update === true || false === ( $ig_last_gallery_item_update = get_transient( 'ig_last_gallery_item_update' ) ) ) {
530 // $url_for_gallery_item = 'https://www.icegram.com/gallery/wp-json/wp/v2/galleryitem?per_page=200&page=1';
531 $url_for_gallery_item = 'https://www.icegram.com/gallery/wp-json/wp/v2/galleryitem?filter[posts_per_page]=200';
532 $ig_gallery_json = wp_remote_get( $url_for_gallery_item );
533 if ( ! is_wp_error( $ig_gallery_json ) ) {
534 $ig_gallery_json = ( wp_remote_retrieve_body( $ig_gallery_json ) );
535 if ( ! empty( $ig_gallery_json ) ) {
536 update_option( 'ig_last_gallery_items', $ig_gallery_json );
537 }
538 } else {
539 update_option( 'requested_gallery_item_with_ajax', 'yes' );
540 ?>
541 <script type="text/javascript">
542 jQuery(document).ready(function () {
543 jQuery.ajax({
544 url: '<?php echo esc_url( $url_for_gallery_item ); ?>',
545 method: 'GET',
546 dataType: 'json',
547 success: function (response) {
548 if (response != undefined && response != '') {
549 //ajax to save data
550 jQuery.ajax({
551 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
552 method: 'POST',
553 dataType: 'json',
554 data: {
555 action: 'save_gallery_data',
556 galleryitems: JSON.stringify(response),
557 security: '<?php echo wp_create_nonce( 'gallery-save-data' ); // WPCS: XSS ok. ?>'
558 },
559 success: function (res) {
560 if (res != undefined && res != '' && res.success != undefined && res.success == 'yes') {
561 // All done.
562 }
563 }
564 });
565 }
566 },
567 error: function (response) {
568 console.log(response, 'res');
569
570 }
571 });
572 });
573 </script>
574 <?php }
575 $url_for_categories = 'https://www.icegram.com/gallery/wp-json/wp/v2/custom_cat?filter[orderby]=parent&order=desc';
576 $options = array(
577 'timeout' => 15,
578 'method' => 'GET',
579 'body' => ''
580 );
581 $response = wp_remote_request( $url_for_categories, $options );
582 $response_code = wp_remote_retrieve_response_code( $response );
583 // $body = json_decode($response['body'] ,true);
584 if ( $response_code == 200 ) {
585 $categories = json_decode( $response['body'], true );
586 $cat_list = array();
587 foreach ( $categories as $category ) {
588 if ( $category['parent'] == 0 ) {
589 $cat_list[ $category['term_id'] ]['name'] = $category['name'];
590 $cat_list[ $category['term_id'] ]['slug'] = $category['slug'];
591 $cat_list[ $category['term_id'] ]['term_id'] = $category['term_id'];
592 } else {
593 $cat_list[ $category['parent'] ]['list'][] = $category;
594 }
595 }
596 $featured_cat = $cat_list[53];
597 unset( $cat_list[53] );
598 array_unshift( $cat_list, $featured_cat );
599 update_option( 'ig_cat_list', $cat_list );
600 } else {
601 ?>
602 <script type="text/javascript">
603 jQuery(document).ready(function () {
604 jQuery.ajax({
605 url: '<?php echo esc_url( $url_for_categories ); ?>',
606 method: 'GET',
607 dataType: 'json',
608 success: function (response) {
609
610 if (response != undefined && response != '') {
611 //ajax to save data
612 jQuery.ajax({
613 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
614 method: 'POST',
615 dataType: 'json',
616 data: {
617 action: 'save_gallery_data',
618 categories: response,
619 security: '<?php echo wp_create_nonce( 'gallery-save-data' ); // WPCS: XSS ok. ?>'
620 },
621 success: function (res) {
622 if (res != undefined && res != '' && res.success != undefined && res.success == 'yes') {
623 // All done.
624 }
625 }
626 });
627 }
628 },
629 error: function (response) {
630 console.log(response, 'res');
631
632 }
633 });
634 });
635 </script>
636 <?php
637 }
638 set_transient( 'ig_last_gallery_item_update', current_time( 'timestamp' ), 24 * HOUR_IN_SECONDS ); // 1 day
639 }
640 }
641
642 public function save_gallery_data() {
643 check_ajax_referer( 'gallery-save-data', 'security' );
644 if ( current_user_can( 'manage_options' ) ) {
645 if ( ! empty( $_REQUEST ) && ! empty( $_REQUEST['galleryitems'] ) ) {
646 $ig_gallery_json = stripslashes( $_REQUEST['galleryitems'] );
647 update_option( 'ig_last_gallery_items', $ig_gallery_json );
648 }
649 if ( ! empty( $_REQUEST ) && ! empty( $_REQUEST['categories'] ) ) {
650 $categories = $_REQUEST['categories'];
651 $cat_list = array();
652 foreach ( $categories as $category ) {
653 if ( $category['parent'] == 0 ) {
654 $cat_list[ $category['term_id'] ]['name'] = $category['name'];
655 $cat_list[ $category['term_id'] ]['slug'] = $category['slug'];
656 } else {
657 $cat_list[ $category['parent'] ]['list'][] = $category;
658 }
659 }
660 update_option( 'ig_cat_list', $cat_list );
661 }
662 }
663
664 }
665
666 public static function gallery_screen() {
667 global $icegram;
668 //check for new gallery item
669 $ig_last_gallery_item_update = get_transient( 'ig_last_gallery_item_update' );
670
671 if ( empty( $ig_last_gallery_item_update ) ) {
672 $icegram->check_for_gallery_items( true );
673 }
674 $ig_gallery_items = get_option( 'ig_last_gallery_items', true );
675 $cat_list = get_option( 'ig_cat_list', true );
676 include( 'gallery.php' );
677 wp_register_script( 'ig_gallery_js', $icegram->plugin_url . '/assets/js/gallery.min.js', array( 'jquery', 'backbone', 'wp-backbone', 'wp-a11y', 'wp-util' ), $icegram->version, true );
678 if ( ! wp_script_is( 'ig_gallery_js' ) ) {
679 wp_enqueue_script( 'ig_gallery_js' );
680 $imported_gallery_items = get_option( 'ig_imported_gallery_items', true );
681 $ig_plan = get_option( 'ig_engage_plan' );
682 $ig_plan = ( ! empty( $ig_plan ) ) ? ( ( $ig_plan == 'plus' ) ? 1 : ( ( $ig_plan == 'pro' ) ? 2 : ( ( $ig_plan == 'max' ) ? 3 : 0 ) ) ) : 0;
683 $ig_gallery_json =
684 wp_localize_script( 'ig_gallery_js', '_wpThemeSettings', array(
685 'themes' => json_decode( $ig_gallery_items, true ),
686 'settings' => array(
687 'canInstall' => ( ! is_multisite() && ( 'install_themes' ) ),
688 'isInstall' => true,
689 'installURI' => ( ! is_multisite() && ( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
690 'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete.", 'icegram' ),
691 'adminUrl' => parse_url( admin_url(), PHP_URL_PATH ),
692 'ig_plan' => $ig_plan,
693 'cat_list' => $cat_list
694 ),
695 'l10n' => array(
696 'addNew' => __( 'Add New Gallery Templates', 'icegram' ),
697 'search' => __( 'Search Gallery Templates', 'icegram' ),
698 'searchPlaceholder' => __( 'Search Design Templates', 'icegram' ), // placeholder (no ellipsis)
699 'themesFound' => __( 'Number of Gallery Templates found: %d', 'icegram' ),
700 'noThemesFound' => __( 'No Gallery Templates found. Try a different search.', 'icegram' ),
701 ),
702 'installedThemes' => $imported_gallery_items
703 ) );
704 }
705 }
706
707 public function branding_data_remove( $icegram_branding_data ) {
708 if ( ! empty( $icegram_branding_data ) && 'yes' != get_option( 'icegram_share_love', 'no' ) ) {
709 $icegram_branding_data['powered_by_logo'] = '';
710 $icegram_branding_data['powered_by_text'] = '';
711 }
712
713 return $icegram_branding_data;
714 }
715
716 //Execute Form shortcode
717 function execute_form_shortcode( $atts = array() ) {
718 return '<div class="ig_form_container layout_inline"></div>';
719 }
720
721 function execute_shortcode( $atts = array(), $content = null ) {
722 // When shortcode is called, it will only prepare an array with conditions
723 // And add a placeholder div
724 // Display will happen in footer via display_messages()
725 $i = count( $this->shortcode_instances );
726 $this->shortcode_instances[ $i ] = shortcode_atts( array(
727 'campaigns' => '',
728 'messages' => '',
729 'skip_others' => 'no'
730 ), $atts );
731
732 $class[] = "ig_shortcode_container";
733 $html[] = "<div id='icegram_shortcode_{$i}'";
734 if ( ! empty( $atts['campaigns'] ) && ! empty( $content ) ) {
735 $this->shortcode_instances[ $i ]['with_content'] = true;
736 $class[] = "trigger_onclick";
737 }
738 foreach ( $atts as $key => $value ) {
739 $value = str_replace( ",", " ", $value );
740 $html[] = " data-{$key}=\"" . htmlentities( $value ) . "\" ";
741 }
742 $class = implode( " ", $class );
743 $html[] = "class='" . $class . "' >" . $content . "</div>";
744
745 return implode( " ", $html );
746 }
747
748 // Do not index Icegram campaigns / messages...
749 // Not using currently - made custom post types non public...
750 function icegram_load_data() {
751 global $post;
752 $icegram_pre_data['ajax_url'] = admin_url( 'admin-ajax.php' );
753 $icegram_pre_data['post_obj'] = $_GET;
754 $icegram_pre_data['post_obj']['is_home'] = ( is_home() || is_front_page() ) ? true : false;
755 $icegram_pre_data['post_obj']['page_id'] = is_object( $post ) && isset( $post->ID ) ? $post->ID : 0;
756 $icegram_pre_data['post_obj']['action'] = 'display_messages';
757 $icegram_pre_data['post_obj']['shortcodes'] = $this->shortcode_instances;
758 $icegram_pre_data['post_obj']['cache_compatibility'] = $this->cache_compatibility;
759 $icegram_pre_data['post_obj']['device'] = $this->get_platform();
760
761 wp_register_script( 'icegram_main_js', $this->plugin_url . '/assets/js/main.min.js', array( 'jquery' ), $this->version, true );
762 if ( 'yes' === $this->cache_compatibility ) {
763 if ( ! wp_script_is( 'icegram_main_js' ) ) {
764 wp_enqueue_script( 'icegram_main_js' );
765 }
766 }
767 wp_localize_script( 'icegram_main_js', 'icegram_pre_data', $icegram_pre_data );
768 }
769
770 function display_messages() {
771
772 $skip_others = $preview_mode = false;
773 $campaign_ids = $message_ids = array();
774 $this->shortcode_instances = ( $this->cache_compatibility == 'yes' && ! empty( $_REQUEST['shortcodes'] ) ) ? $_REQUEST['shortcodes'] : $this->shortcode_instances;
775 // Pull in message and campaign IDs from shortcodes - if set
776 if ( ! empty( $this->shortcode_instances ) ) {
777 foreach ( $this->shortcode_instances as $i => $value ) {
778 $cids = array_map( 'trim', (array) explode( ',', intval( $value['campaigns'] ) ) );
779 $mids = array_map( 'trim', (array) explode( ',', intval( $value['messages'] ) ) );
780 if ( ! empty( $value['skip_others'] ) && $value['skip_others'] == 'yes' && ( ! empty( $cids ) || ! empty( $mids ) ) ) {
781 $skip_others = true;
782 }
783 $campaign_ids = array_merge( $campaign_ids, $cids );
784 $message_ids = array_merge( $message_ids, $mids );
785 }
786 }
787 if ( ! empty( $_REQUEST['campaign_preview_id'] ) && intval( $_REQUEST['campaign_preview_id'] ) && ( 'edit_posts' ) ) {
788 $campaign_ids = array( intval( $_REQUEST['campaign_preview_id'] ) );
789 $preview_mode = true;
790 }
791
792 $messages = $this->get_valid_messages( $message_ids, $campaign_ids, $preview_mode, $skip_others );
793
794 if ( empty( $messages ) ) {
795 //wp_die(0);
796 return;
797 }
798
799 $messages_to_show_ids = array();
800 foreach ( $messages as $key => $message_data ) {
801
802 if ( ! is_array( $message_data ) || empty( $message_data ) ) {
803 continue;
804 }
805
806 // Don't show a seen message again - if needed
807 // change to campaign targetting in v1.9.1
808 if ( ! empty( $message_data['id'] ) &&
809 empty( $_GET['campaign_preview_id'] ) &&
810 ! empty( $message_data['retargeting'] ) &&
811 $message_data['retargeting'] == 'yes'
812 ) {
813 if ( ! empty( $_COOKIE[ 'icegram_messages_shown_' . $message_data['id'] ] ) || ! empty( $_COOKIE[ 'icegram_campaign_shown_' . floor( $message_data['campaign_id'] ) ] ) ) {
814 unset( $messages[ $key ] );
815 continue;
816 }
817 }
818 if ( ! empty( $message_data['id'] ) &&
819 empty( $_GET['campaign_preview_id'] ) &&
820 ! empty( $message_data['retargeting_clicked'] ) &&
821 $message_data['retargeting_clicked'] == 'yes'
822 ) {
823 if ( ! empty( $_COOKIE[ 'icegram_messages_clicked_' . $message_data['id'] ] ) || ! empty( $_COOKIE[ 'icegram_campaign_clicked_' . floor( $message_data['campaign_id'] ) ] ) ) {
824 unset( $messages[ $key ] );
825 continue;
826 }
827 }
828
829 // Avoid showing the same message twice
830 if ( in_array( $message_data['id'], $messages_to_show_ids ) ) {
831 unset ( $messages[ $key ] );
832 continue;
833 } else {
834 $messages_to_show_ids[] = $message_data['id'];
835 }
836
837 $this->process_message_body( $messages[ $key ] );
838 }
839 if ( empty( $messages ) ) {
840 return;
841 }
842
843 // Load icegram_main_js only when the $messages are still
844 // not empty at this stage.
845 if ( ! wp_script_is( 'icegram_main_js' ) ) {
846 wp_enqueue_script( 'icegram_main_js' );
847 }
848
849 $icegram_default = apply_filters( 'icegram_branding_data',
850 array(
851 'icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
852 'powered_by_logo' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
853 'powered_by_text' => __( 'Powered by Icegram', 'icegram' )
854 ) );
855 $messages = apply_filters( 'icegram_messages_to_show', $messages );
856 $icegram_data = apply_filters( 'icegram_data', array(
857 'messages' => array_values( $messages ),
858 'ajax_url' => admin_url( 'admin-ajax.php' ),
859 'preview_id' => ! empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '',
860 'defaults' => $icegram_default
861 ) );
862 if ( empty( $icegram_data['preview_id'] ) ) {
863 unset( $icegram_data['preview_id'] );
864 }
865
866 do_action( 'icegram_print_js_css_data', $icegram_data );
867
868
869 // Load CF7 & Garvity Forms CSS & JS only if form loaded
870 $compat_form_types = array( 'contact-form-7', 'gravityform' );
871
872 foreach ( $icegram_data['messages'] as $message_id ) {
873 foreach ( $compat_form_types as $type ) {
874 if ( strpos( $message_id['form_html_original'], $type ) ) {
875 do_action( 'icegram_data_printed', $type );
876 }
877 }
878 }
879 }
880
881 function two_step_mobile_popup( $icegram_data ) {
882
883 $temp = array();
884 foreach ( $icegram_data['messages'] as $message_id => $message ) {
885
886 if ( ! empty( $message['ig_mobile_popup'] ) && $message['ig_mobile_popup'] == true ) {
887 $action_bar = $message;
888 $action_bar['type'] = 'action-bar';
889 $action_bar['theme'] = 'hello';
890 $action_bar['position'] = '21';
891 $action_bar['message'] = '';
892 $action_bar['label'] = __( 'Show More', 'icegram' );
893 $action_bar['id'] = $action_bar['id'] . '_00';
894 $action_bar['use_custom_code'] = 'yes';
895 $action_bar['form_html'] = '';
896 $action_bar['form_html_original'] = '';
897 $action_bar['rainmaker_form_code'] = '';
898 $action_bar['link'] = '';
899 $action_bar['redirect_to_link'] = '';
900 $action_bar['cta'] = '';
901 $action_bar['alt_cta'] = '';
902 $action_bar['add_alt_cta'] = '';
903 $action_bar['custom_css'] = '#ig_this_message .ig_close{display:none;}';
904 $action_bar['custom_js'] = "<script type='text/javascript'>jQuery('#icegram_message_" . $action_bar['id'] . "').on('click', '.ig_button', function(){icegram.get_message_by_id('" . $action_bar['id'] . "').hide(); icegram.get_message_by_id('" . $message['id'] . "').show(); });</script>";
905 unset( $action_bar['ig_mobile_popup'] );
906 $temp[] = $action_bar;
907 }
908 }
909 $icegram_data['messages'] = array_merge( $icegram_data['messages'], $temp );
910 unset( $temp );
911
912 return $icegram_data;
913 }
914
915
916 function print_js_css_data( $icegram_data ) {
917
918 $this->collect_js_and_css( $icegram_data );
919 if ( $this->cache_compatibility === 'yes' ) {
920 echo json_encode( $icegram_data );
921 wp_die();
922 } else {
923 wp_localize_script( 'icegram_main_js', 'icegram_data', $icegram_data );
924 }
925 }
926
927 function collect_js_and_css( &$icegram_data ) {
928
929 $types_shown = array();
930 $scripts = array();
931 $css = array();
932 foreach ( $icegram_data['messages'] as $key => $message_data ) {
933 $types_shown[] = $message_data['type'];
934 }
935
936 $types_shown = array_unique( $types_shown );
937 $ver_prefix = '?var=' . $this->version;
938
939 $scripts[] = $this->plugin_url . "/assets/js/icegram.min.js" . $ver_prefix;
940 $css[] = $this->plugin_url . "/assets/css/frontend.min.css" . $ver_prefix;
941 //minify and combine only for default msg type
942 $ig_core_message_types = array( 'popup', 'action-bar', 'toast', 'messenger' );
943 // Load JS and default CSS
944 foreach ( $types_shown as $message_type ) {
945 if ( ! in_array( $message_type, $ig_core_message_types ) ) {
946 $scripts[] = $this->message_types[ $message_type ]['baseurl'] . "main.js" . $ver_prefix;
947 $css[] = $this->message_types[ $message_type ]['baseurl'] . "default.css" . $ver_prefix;
948 } else {
949 $css[] = $this->message_types[ $message_type ]['baseurl'] . 'themes/' . $message_type . ".min.css" . $ver_prefix;
950 }
951 }
952
953 //TODO :: add theme pack theme css files too.
954 // Load theme CSS
955 foreach ( $icegram_data['messages'] as $key => $message ) {
956 if ( ! empty( $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ] ) ) {
957 $theme = $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ]['baseurl'] . $message['theme'] . '.css' . $ver_prefix;
958 } else {
959 $theme_default = $this->message_types[ $message['type'] ] ['settings']['theme']['default'];
960 $theme = $this->message_types[ $message['type'] ]['themes'][ $theme_default ]['baseurl'] . $theme_default . '.css' . $ver_prefix;
961 $icegram_data['messages'][ $key ]['theme'] = $theme_default;
962 }
963 if ( ! preg_match( '/icegram\/message-types/i', $theme ) ) {
964 $css [] = $theme;
965 }
966 }
967 $css = array_unique( $css );
968 $icegram_data['scripts'] = apply_filters( 'add_icegram_script', $scripts );
969 $icegram_data['css'] = apply_filters( 'add_icegram_css', $css );
970
971 return $icegram_data;
972 }
973
974 // Process
975 function process_message_body( &$message_data ) {
976 global $wp_scripts;
977 global $wp_styles;
978
979 if ( $this->cache_compatibility == 'yes' ) {
980 $q_script = ! empty( $wp_scripts->queue ) ? $wp_scripts->queue : array();
981 $q_style = ! empty( $wp_styles->queue ) ? $wp_styles->queue : array();
982 }
983 $content = $message_data['message'];
984 $content = convert_chars( convert_smilies( wptexturize( $content ) ) );
985 if ( isset( $GLOBALS['wp_embed'] ) ) {
986 $content = $GLOBALS['wp_embed']->autoembed( $content );
987 }
988 $content = $this->after_wpautop( wpautop( $this->before_wpautop( $content ) ) );
989 $content = do_shortcode( shortcode_unautop( $content ) );
990 $message_data['message'] = $content;
991
992 //do_shortcode in headline
993 $message_data['headline'] = do_shortcode( shortcode_unautop( $message_data['headline'] ) );
994 //shortcode support for Third party forms and Rainmaker
995 $form_html_original = ! empty( $message_data["rainmaker_form_code"] )
996 ? ( '[rainmaker_form id="' . $message_data["rainmaker_form_code"] . '"]' )
997 : ( ! empty( $message_data['form_html_original'] ) ? $message_data['form_html_original'] : '' );
998 $form_html_original = ! empty( $message_data["es_form_code"] )
999 ? ( '[email-subscribers-form id="' . $message_data["es_form_code"] . '"]' )
1000 : $form_html_original;
1001
1002 if ( ! empty( $form_html_original ) ) {
1003 $message_data['form_html'] = do_shortcode( shortcode_unautop( $form_html_original ) );
1004 }
1005 //TODO :: Handle case for inline style and script
1006 if ( $this->cache_compatibility == 'yes' ) {
1007 $handles = ! empty( $wp_scripts->queue ) ? array_diff( $wp_scripts->queue, $q_script ) : array();
1008 unset( $q_script );
1009 if ( ! empty( $handles ) ) {
1010 if ( empty( $message_data['assets'] ) ) {
1011 $message_data['assets'] = array();
1012 }
1013
1014 ob_start();
1015 $wp_scripts->do_items( $handles );
1016 $message_data['assets']['scripts'] = array_filter( explode( '<script', ob_get_clean() ) );
1017 }
1018
1019 //TODO :: do_items if required
1020 $handles = ! empty( $wp_styles->queue ) ? array_diff( $wp_styles->queue, $q_style ) : array();
1021 unset( $q_style );
1022 if ( ! empty( $handles ) ) {
1023 if ( empty( $message_data['assets'] ) ) {
1024 $message_data['assets'] = array();
1025 }
1026
1027 foreach ( $handles as $handle ) {
1028 ob_start();
1029 $wp_styles->do_item( $handle );
1030 $message_data['assets']['styles'][ $handle ] = ob_get_clean();
1031 }
1032 }
1033 }
1034 }
1035
1036 function enqueue_admin_styles_and_scripts() {
1037
1038 $screen = get_current_screen();
1039 if ( ! in_array( $screen->id, array( 'ig_campaign', 'ig_message', 'edit-ig_campaign' ), true ) ) {
1040 return;
1041 }
1042
1043 // Register scripts
1044 wp_register_script( 'icegram_writepanel', $this->plugin_url . '/assets/js/admin.min.js', array( 'jquery', 'wp-color-picker' ), $this->version );
1045
1046 wp_enqueue_script( 'icegram_writepanel' );
1047
1048 $icegram_writepanel_params = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'search_message_nonce' => wp_create_nonce( "search-messages" ), 'home_url' => home_url( '/' ) );
1049 $this->available_headlines = apply_filters( 'icegram_available_headlines', array() );
1050 $icegram_writepanel_params = array_merge( $icegram_writepanel_params, array( 'available_headlines' => $this->available_headlines ) );
1051
1052 wp_localize_script( 'icegram_writepanel', 'icegram_writepanel_params', $icegram_writepanel_params );
1053
1054 wp_enqueue_style( 'dashicons' );
1055 wp_enqueue_style( 'wp-color-picker' );
1056 wp_enqueue_style( 'icegram_admin_styles', $this->plugin_url . '/assets/css/admin.min.css', array(), $this->version );
1057
1058 if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) {
1059 wp_enqueue_script( 'jquery-ui-datepicker' );
1060 }
1061
1062 }
1063
1064 //execute shortcode in text widget
1065 function ig_widget_text_filter( $content ) {
1066 if ( ! preg_match( '/\[[\r\n\t ]*icegram?[\r\n\t ].*?\]/', $content ) ) {
1067 return $content;
1068 }
1069
1070 $content = do_shortcode( $content );
1071
1072 return $content;
1073 }
1074
1075 public static function get_platform() {
1076 $mobile_detect = new Ig_Mobile_Detect();
1077 $mobile_detect->setUserAgent();
1078 if ( $mobile_detect->isMobile() ) {
1079 return ( $mobile_detect->isTablet() ) ? 'tablet' : 'mobile';
1080 } elseif ( $mobile_detect->isTablet() ) {
1081 return 'tablet';
1082 }
1083
1084 return 'laptop';
1085 }
1086
1087 function get_message_data( $message_ids = array(), $preview = false ) {
1088 global $wpdb;
1089 $message_data = array();
1090 $original_message_id_map = array();
1091 $meta_key = $preview ? 'icegram_message_preview_data' : 'icegram_message_data';
1092 $message_data_query = "SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE '$meta_key'";
1093 if ( ! empty( $message_ids ) && is_array( $message_ids ) ) {
1094 // For WPML compatibility
1095 if ( function_exists( 'icl_object_id' ) ) {
1096 $wpml_settings = get_option( 'icl_sitepress_settings' );
1097 $original_if_missing = ( is_array( $wpml_settings ) && array_key_exists( 'show_untranslated_blog_posts', $wpml_settings ) && ! empty( $wpml_settings['show_untranslated_blog_posts'] ) ) ? true : false;
1098
1099 foreach ( $message_ids as $i => $id ) {
1100 $translated = icl_object_id( $id, 'ig_message', $original_if_missing );
1101 $message_ids[ $i ] = $translated;
1102 $original_message_id_map[ $translated ] = $id;
1103 }
1104 }
1105 $message_ids = array_filter( array_unique( $message_ids ) );
1106 if ( ! empty( $message_ids ) ) {
1107 $message_data_query .= " AND post_id IN ( " . implode( ',', $message_ids ) . " )";
1108 $message_data_results = $wpdb->get_results( $message_data_query, 'ARRAY_A' );
1109 foreach ( $message_data_results as $message_data_result ) {
1110 $data = maybe_unserialize( $message_data_result['meta_value'] );
1111 if ( ! empty( $data ) ) {
1112 $message_data[ $message_data_result['post_id'] ] = $data;
1113 // For WPML compatibility
1114 if ( ! empty( $original_message_id_map[ $message_data_result['post_id'] ] ) ) {
1115 $message_data[ $message_data_result['post_id'] ]['original_message_id'] = $original_message_id_map[ $message_data_result['post_id'] ];
1116 }
1117 }
1118 }
1119 }
1120 }
1121
1122 return $message_data;
1123 }
1124
1125 function get_valid_messages( $message_ids = array(), $campaign_ids = array(), $preview_mode = false, $skip_others = false ) {
1126 list( $message_ids, $campaign_ids, $preview_mode, $skip_others ) = apply_filters( 'icegram_get_valid_messages_params', array( $message_ids, $campaign_ids, $preview_mode, $skip_others ) );
1127
1128 $valid_messages = $valid_campaigns = $message_campaign_map = array();
1129
1130 $campaign_ids = array_filter( array_unique( (array) $campaign_ids ) );
1131 $message_ids = array_filter( array_unique( (array) $message_ids ) );
1132 if ( ! empty( $campaign_ids ) ) {
1133 $valid_campaigns = $this->get_valid_campaigns( $campaign_ids, true, $preview_mode );
1134 }
1135
1136 // When skip_others is true, we won't load campaigns / messages from db
1137 if ( ! $skip_others && ! $preview_mode ) {
1138 $campaigns = $this->get_valid_campaigns();
1139 if ( ! empty( $campaigns ) ) {
1140 foreach ( $campaigns as $id => $campaign ) {
1141 if ( ! array_key_exists( $id, $valid_campaigns ) ) {
1142 $valid_campaigns[ $id ] = $campaign;
1143 }
1144 }
1145 }
1146 }
1147
1148 // Create a map to look up campaign id for a given message
1149 if ( ! empty( $valid_campaigns ) ) {
1150 foreach ( $valid_campaigns as $id => $campaign ) {
1151 if ( $preview_mode ) {
1152 $campaign->messages = get_post_meta( $id, 'campaign_preview', true );
1153 }
1154 if ( ! empty( $campaign->messages ) ) {
1155 foreach ( $campaign->messages as $msg ) {
1156 $message_ids[] = $msg['id'];
1157 if ( ! array_key_exists( $msg['id'], $message_campaign_map ) ) {
1158 $message_campaign_map[ $msg['id'] ] = $id;
1159 }
1160 }
1161 }
1162 }
1163 }
1164
1165 // We don't display same message twice...
1166 $message_ids = array_unique( $message_ids );
1167
1168 if ( empty( $message_ids ) ) {
1169 return array();
1170 }
1171 $valid_messages = $this->get_message_data( $message_ids, $preview_mode );
1172
1173 foreach ( $valid_messages as $id => $message_data ) {
1174 // Remove message if required fields are missing
1175 if ( empty( $message_data ) || empty( $message_data['type'] ) ) {
1176 unset( $valid_messages[ $id ] );
1177 continue;
1178 }
1179 // Remove message if message type is uninstalled
1180 $class_name = 'Icegram_Message_Type_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $message_data['type'] ) ) );
1181 if ( ! class_exists( $class_name ) ) {
1182 unset( $valid_messages[ $id ] );
1183 continue;
1184 }
1185 $message_data['delay_time'] = 0;
1186 $message_data['retargeting'] = '';
1187 $message_data['campaign_id'] = ( $preview_mode ) ? $_REQUEST['campaign_preview_id'] : '';
1188
1189 // Pull display time and retargeting rule from campaign if possible
1190 $message_id = ( ! empty( $message_data['original_message_id'] ) ) ? $message_data['original_message_id'] : $id;
1191 if ( ! empty( $message_campaign_map[ $message_id ] ) ) {
1192 //modify campaign id
1193 $message_data['campaign_id'] = apply_filters( 'modify_campaing_id', $message_campaign_map[ $message_id ], $message_id );
1194 $campaign = $valid_campaigns[ floor( $message_data['campaign_id'] ) ];
1195 if ( ! empty( $campaign ) && $campaign instanceof Icegram_Campaign ) {
1196 $message_meta_from_campaign = $campaign->get_message_meta_by_id( $message_id );
1197 if ( ! empty( $message_meta_from_campaign['time'] ) ) {
1198 $message_data['delay_time'] = $message_meta_from_campaign['time'];
1199 }
1200
1201 //check if campaign is targeted to mobile at zero
1202 $device_rule = $campaign->get_rule_value( 'device' );
1203 if ( $this->get_platform() !== 'laptop' && ! empty( $device_rule['mobile'] ) && $device_rule['mobile'] == 'yes' && $message_data['delay_time'] == 0 && $message_data['type'] == 'popup' ) {
1204 $message_data['ig_mobile_popup'] = true;
1205 if ( ! empty( $message_data['triggers'] ) && ! empty( $message_data['triggers']['when_to_show'] ) ) {
1206 $message_data['ig_mobile_popup'] = ( $message_data['triggers']['when_to_show'] == 'duration_on_page' && $message_data['triggers']['duration_on_page'] == 0 ) ? true : false;
1207 }
1208 }
1209 //set delay time -1 if shortcode with content
1210 foreach ( $this->shortcode_instances as $i => $value ) {
1211 $campaign_ids = explode( ',', $value['campaigns'] );
1212 if ( ! empty( $value['with_content'] ) && in_array( $message_data['campaign_id'], $campaign_ids ) ) {
1213 $message_data['delay_time'] = - 1;
1214 }
1215 }
1216 $rule_value = $campaign->get_rule_value( 'retargeting' );
1217 $message_data['retargeting'] = ! empty( $rule_value['retargeting'] ) ? $rule_value['retargeting'] : '';
1218 $message_data['expiry_time'] = ! empty( $rule_value['retargeting'] ) ? $rule_value['expiry_time'] : '';
1219 $rule_value_retargeting_clicked = $campaign->get_rule_value( 'retargeting_clicked' );
1220 $message_data['retargeting_clicked'] = ! empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['retargeting_clicked'] : '';
1221 $message_data['expiry_time_clicked'] = ! empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['expiry_time_clicked'] : '';
1222
1223 }
1224 }
1225 $valid_messages[ $id ] = $message_data;
1226 }
1227 $valid_messages = apply_filters( 'icegram_valid_messages', $valid_messages );
1228
1229 return $valid_messages;
1230 }
1231
1232 function get_valid_campaigns( $campaign_ids = array(), $skip_page_check = false, $preview_mode = false ) {
1233 global $wpdb;
1234 if ( empty( $campaign_ids ) ) {
1235 $sql = "SELECT pm.post_id
1236 FROM {$wpdb->prefix}posts AS p
1237 LEFT JOIN {$wpdb->prefix}postmeta AS pm ON ( pm.post_id = p.ID )
1238 WHERE p.post_status = 'publish' ";
1239 // Filter handler within this file (and possibly others) will append to this SQL
1240 // and provide arguments for wpdb->prepare if needed.
1241 // First element in the array is SQL, remaining are values for placeholders in SQL
1242 $sql_params = apply_filters( 'icegram_get_valid_campaigns_sql', array( $sql ), array() );
1243
1244 $campaign_ids = $wpdb->get_col( $wpdb->prepare( array_shift( $sql_params ), $sql_params ) );
1245 }
1246 $valid_campaigns = array();
1247 foreach ( (array) $campaign_ids as $campaign_id ) {
1248 $campaign = new Icegram_Campaign( $campaign_id );
1249 if ( $preview_mode || $campaign->is_valid( array( 'skip_page_check' => $skip_page_check ) ) ) {
1250 $valid_campaigns[ $campaign_id ] = $campaign;
1251 } else {
1252 // Campgain is invalid!
1253 }
1254
1255 }
1256
1257 $valid_campaigns = apply_filters( 'icegram_valid_campaigns', $valid_campaigns );
1258
1259 return $valid_campaigns;
1260 }
1261
1262 function append_to_valid_campaigns_sql( $sql_params = array(), $options = array() ) {
1263 // Page check conditions
1264 //$pid = $_GET['page_id'];
1265 $pid = Icegram::get_current_page_id();
1266 $sql = " AND (
1267 pm.meta_key = 'icegram_campaign_target_rules' AND (
1268 ( pm.meta_value LIKE '%%%s%%' )
1269 OR ( pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' )
1270 ";
1271 $sql_params[] = 's:8:"sitewide";s:3:"yes";';
1272 $sql_params[] = 's:10:"other_page";s:3:"yes";';
1273 $sql_params[] = 's:7:"page_id";a:';
1274 $sql_params[] = serialize( (string) $pid );
1275 //local url
1276 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
1277 $sql_params[] = 's:9:"local_url";s:3:"yes";';
1278 if ( ! empty( $_REQUEST['cache_compatibility'] ) && $_REQUEST['cache_compatibility'] == 'yes' ) {
1279 $is_home = ( ! empty( $_REQUEST['is_home'] ) && $_REQUEST['is_home'] === 'true' ) ? true : false;
1280 } else {
1281 $is_home = ( is_home() || is_front_page() ) ? true : false;
1282 }
1283 if ( $is_home === true ) {
1284 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
1285 $sql_params[] = 's:8:"homepage";s:3:"yes";';
1286 }
1287 $sql .= " ) )";
1288
1289 $sql_params[0] .= $sql;
1290
1291 //s:9:"logged_in";s:3:"all";
1292
1293 return $sql_params;
1294 }
1295
1296 // Include all classes required for Icegram plugin
1297 function include_classes( $feedback_version ) {
1298 global $ig_tracker, $ig_feedback;
1299
1300 $feedback_version_for_file = str_replace( '.', '-', $feedback_version );
1301 $t = 'classes/feedback/class-ig-tracker.php';
1302 $f = 'classes/feedback/class-ig-feedback.php';
1303 require_once( $t );
1304 require_once( $f );
1305
1306 $ig_feedback_class = 'IG_Feedback_V_' . str_replace( '.', '_', $feedback_version );
1307 $ig_feedback = new $ig_feedback_class( 'Icegram', 'icegram', 'ig', 'igfree.', false );
1308
1309 require_once( 'classes/feedback.php' );
1310
1311 $classes = glob( $this->plugin_path . '/classes/*.php' );
1312 foreach ( $classes as $file ) {
1313 // Files with 'admin' in their name are included only for admin section
1314 if ( is_file( $file ) && ( ( strpos( $file, '-admin' ) >= 0 && is_admin() ) ) ) {
1315 $all_active_plugins = $ig_tracker::get_plugins();
1316 if ( ( strpos( $file, 'ig-upsale-admin.php' ) !== false ) && in_array( 'icegram-engage/icegram-engage.php', $all_active_plugins ) ) {
1317 continue;
1318 }
1319 include_once $file;
1320 } elseif ( ! is_admin() ) {
1321 include_once $file;
1322 }
1323 }
1324
1325 // Load built in message types
1326 $icegram_message_type_basedirs = glob( $this->plugin_path . '/message-types/*' );
1327 // Allow other plugins to add new message types
1328 $icegram_message_type_basedirs = apply_filters( 'icegram_message_type_basedirs', $icegram_message_type_basedirs );
1329 // Set up different message type classes
1330 foreach ( $icegram_message_type_basedirs as $dir ) {
1331 $type = basename( $dir );
1332 $class_file = $dir . "/main.php";
1333 if ( is_file( $class_file ) ) {
1334 include_once( $class_file );
1335 }
1336 $class_name = 'Icegram_Message_Type_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $type ) ) );
1337 if ( class_exists( $class_name ) ) {
1338 $this->message_type_objs[ $type ] = new $class_name();
1339 }
1340 }
1341 do_action( 'ig_file_include' );
1342 $this->message_types = apply_filters( 'icegram_message_types', array() );
1343
1344 }
1345
1346 // Register Campaign post type
1347 function register_campaign_post_type() {
1348 $labels = array(
1349 'name' => __( 'Campaigns', 'icegram' ),
1350 'singular_name' => __( 'Campaign', 'icegram' ),
1351 'add_new' => __( 'Add New Campaign', 'icegram' ),
1352 'add_new_item' => __( 'Add New Campaign', 'icegram' ),
1353 'edit_item' => __( 'Edit Campaign', 'icegram' ),
1354 'new_item' => __( 'New Campaign', 'icegram' ),
1355 'all_items' => __( 'Campaigns', 'icegram' ),
1356 'view_item' => __( 'View Campaign', 'icegram' ),
1357 'search_items' => __( 'Search Campaigns', 'icegram' ),
1358 'not_found' => __( 'No campaigns found', 'icegram' ),
1359 'not_found_in_trash' => __( 'No campaigns found in Trash', 'icegram' ),
1360 'parent_item_colon' => __( '', 'icegram' ),
1361 'menu_name' => __( 'Icegram', 'icegram' )
1362 );
1363
1364 $args = array(
1365 'labels' => $labels,
1366 // 'menu_icon' => 'dashicons-info',
1367 'public' => false,
1368 'publicly_queryable' => false,
1369 'show_ui' => true,
1370 'show_in_menu' => true,
1371 'query_var' => true,
1372 'rewrite' => array( 'slug' => 'ig_campaign' ),
1373 'capability_type' => 'post',
1374 'has_archive' => false,
1375 'hierarchical' => false,
1376 'menu_position' => null,
1377 'menu_icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-18-white.png',
1378 'supports' => array( 'title', 'editor' )
1379 );
1380
1381 register_post_type( 'ig_campaign', $args );
1382 }
1383
1384 // Register Message post type
1385 function register_message_post_type() {
1386 $labels = array(
1387 'name' => __( 'Messages', 'icegram' ),
1388 'singular_name' => __( 'Message', 'icegram' ),
1389 'add_new' => __( 'Create New', 'icegram' ),
1390 'add_new_item' => __( 'Create New Message', 'icegram' ),
1391 'edit_item' => __( 'Edit Message', 'icegram' ),
1392 'new_item' => __( 'New Message', 'icegram' ),
1393 'all_items' => __( 'Messages', 'icegram' ),
1394 'view_item' => __( 'View Message', 'icegram' ),
1395 'search_items' => __( 'Search Messages', 'icegram' ),
1396 'not_found' => __( 'No messages found', 'icegram' ),
1397 'not_found_in_trash' => __( 'No messages found in Trash', 'icegram' ),
1398 'parent_item_colon' => __( '', 'icegram' ),
1399 'menu_name' => __( 'Messages', 'icegram' )
1400 );
1401
1402 $args = array(
1403 'labels' => $labels,
1404 'public' => false,
1405 'publicly_queryable' => false,
1406 'show_ui' => true,
1407 'show_in_menu' => 'edit.php?post_type=ig_campaign',
1408 'query_var' => true,
1409 'rewrite' => array( 'slug' => 'ig_message' ),
1410 'capability_type' => 'post',
1411 'has_archive' => false,
1412 'hierarchical' => false,
1413 'menu_position' => null,
1414 'supports' => array( 'title' )
1415 );
1416
1417 register_post_type( 'ig_message', $args );
1418 }
1419
1420
1421 function import( $data = array() ) {
1422 if ( empty( $data['campaigns'] ) && empty( $data['messages'] ) ) {
1423 return;
1424 }
1425
1426 $default_theme = $default_type = '';
1427 $first_message_type = current( $this->message_types );
1428
1429 if ( is_array( $first_message_type ) ) {
1430 $default_type = $first_message_type['type'];
1431 if ( ! empty( $first_message_type['themes'] ) ) {
1432 $default_theme = key( $first_message_type['themes'] );
1433 }
1434 }
1435
1436 $new_campaign_ids = array();
1437 foreach ( (array) $data['campaigns'] as $campaign ) {
1438
1439 $args = array(
1440 'post_content' => ( ! empty( $campaign['post_content'] ) ) ? esc_attr( $campaign['post_content'] ) : '',
1441 'post_name' => ( ! empty( $campaign['post_title'] ) ) ? sanitize_title( $campaign['post_title'] ) : '',
1442 'post_title' => ( ! empty( $campaign['post_title'] ) ) ? $campaign['post_title'] : '',
1443 // 'post_status' => ( !empty( $campaign['post_status'] ) ) ? $campaign['post_status'] : 'draft',
1444 'post_status' => 'draft',
1445 'post_type' => 'ig_campaign'
1446 );
1447
1448 $new_campaign_id = wp_insert_post( $args );
1449 $new_campaign_ids[] = $new_campaign_id;
1450
1451 if ( ! empty( $campaign['target_rules'] ) ) {
1452
1453 $defaults = array(
1454 'homepage' => 'yes',
1455 'when' => 'always',
1456 'from' => '',
1457 'to' => '',
1458 'mobile' => 'yes',
1459 'tablet' => 'yes',
1460 'laptop' => 'yes',
1461 'logged_in' => 'all'
1462 );
1463
1464 $target_rules = wp_parse_args( $campaign['target_rules'], $defaults );
1465 update_post_meta( $new_campaign_id, 'icegram_campaign_target_rules', $target_rules );
1466 }
1467
1468 if ( ! empty( $campaign['messages'] ) ) {
1469
1470 $messages = array();
1471
1472 foreach ( $campaign['messages'] as $message ) {
1473
1474 if ( ! is_array( $message ) ) {
1475 continue;
1476 }
1477
1478 $args = array(
1479 'post_content' => ( ! empty( $message['message'] ) ) ? esc_attr( $message['message'] ) : '',
1480 'post_name' => ( ! empty( $message['post_title'] ) ) ? sanitize_title( $message['post_title'] ) : '',
1481 'post_title' => ( ! empty( $message['post_title'] ) ) ? $message['post_title'] : '',
1482 'post_status' => ( ! empty( $message['post_status'] ) ) ? $message['post_status'] : 'publish',
1483 'post_type' => 'ig_message'
1484 );
1485
1486 $new_message_id = wp_insert_post( $args );
1487 $new_message = array(
1488 'id' => $new_message_id,
1489 'time' => ( ! empty( $message['time'] ) ) ? $message['time'] : 0
1490 );
1491 //for gallery + CTA another message
1492 if ( ! empty( $message['cta'] ) && $message['cta'] == 'cta_another_message' && ! empty( $message['cta_linked_message_id'] ) && $message['cta_linked_message_id'] == 'auto' ) {
1493 $prev_message = end( $messages );
1494 $message['cta_linked_message_id'] = $prev_message['id'];
1495 array_pop( $messages );
1496 }
1497 $messages[] = $new_message;
1498
1499 unset( $message['post_content'] );
1500 unset( $message['time'] );
1501
1502 $message['id'] = $new_message_id;
1503
1504 $defaults = array(
1505 'post_title' => '',
1506 'type' => $default_type,
1507 'theme' => $default_theme,
1508 'animation' => '',
1509 'headline' => '',
1510 'label' => '',
1511 'link' => '',
1512 'icon' => '',
1513 'message' => '',
1514 'position' => '',
1515 'text_color' => '#000000',
1516 'bg_color' => '#ffffff',
1517 'custom_code' => '',
1518 'id' => ''
1519 );
1520 $icegram_message_data = wp_parse_args( $message, $defaults );
1521 if ( ! empty( $icegram_message_data ) ) {
1522 update_post_meta( $new_message_id, 'icegram_message_data', $icegram_message_data );
1523 update_post_meta( $new_message_id, 'icegram_message_preview_data', $icegram_message_data );
1524 }
1525 }//foreach
1526
1527 if ( ! empty( $campaign['messages'] ) ) {
1528 update_post_meta( $new_campaign_id, 'messages', $messages );
1529 update_post_meta( $new_campaign_id, 'campaign_preview', $messages );
1530 }
1531 }//if
1532 }
1533
1534 return $new_campaign_ids;
1535
1536 }
1537
1538 function import_gallery_item() {
1539 if ( ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'fetch_messages' && ! empty( $_REQUEST['campaign_id'] ) && ! empty( $_REQUEST['gallery_item'] ) ) {
1540 $url = 'https://www.icegram.com/gallery/wp-admin/admin-ajax.php?utm_source=ig_inapp&utm_campaign=ig_gallery&utm_medium=' . $_REQUEST['campaign_id'];
1541 $params = $_REQUEST;
1542 $imported_gallery_items = array();
1543 $options = array(
1544 'timeout' => 15,
1545 'method' => 'POST',
1546 'body' => http_build_query( $params )
1547 );
1548 $response = wp_remote_request( $url, $options );
1549 $response_code = wp_remote_retrieve_response_code( $response );
1550 if ( $response_code == 200 ) {
1551 $new_campaign_ids = $this->import( json_decode( $response['body'], true ) );
1552 if ( ! empty( $new_campaign_ids ) ) {
1553 $imported_gallery_items = get_option( 'ig_imported_gallery_items' );
1554 $imported_gallery_items[] = $_REQUEST['campaign_id'];
1555 update_option( 'ig_imported_gallery_items', $imported_gallery_items );
1556 $location = admin_url( 'post.php?post=' . $new_campaign_ids[0] . '&action=edit' );
1557 header( 'Location:' . $location );
1558 exit;
1559 } else {
1560 wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
1561 }
1562 }
1563 }
1564 }
1565
1566 function import_sample_data( $data = array() ) {
1567 $new_campaign_ids = $this->import( $data );
1568 if ( ! empty( $new_campaign_ids ) ) {
1569 update_option( 'icegram_sample_data_imported', $new_campaign_ids );
1570 }
1571 }
1572
1573
1574 function get_sample_data() {
1575
1576 return array(
1577 'campaigns' => array(
1578 array(
1579 'post_name' => '',
1580 'post_title' => 'My First Icegram Campaign',
1581 'target_rules' => array(
1582 'homepage' => 'yes',
1583 'when' => 'always',
1584 'from' => '',
1585 'to' => '',
1586 'mobile' => 'yes',
1587 'tablet' => 'yes',
1588 'laptop' => 'yes',
1589 'logged_in' => 'all'
1590 ),
1591 'messages' => array(
1592 array(
1593 'post_title' => 'Get 2x more Contacts with Your Website',
1594 'post_status' => 'publish',
1595 'time' => '0',
1596 'type' => 'action-bar',
1597 'theme' => 'hello',
1598 'headline' => 'Get 2x more Contacts with Your Website',
1599 'label' => 'Show Me How',
1600 'link' => '',
1601 'icon' => '',
1602 'message' => 'Instant Results Guaranteed',
1603 'position' => '01',
1604 'text_color' => '#000000',
1605 'bg_color' => '#eb593c'
1606 ),
1607 array(
1608 'post_title' => '20% Off Coupon',
1609 'post_status' => 'publish',
1610 'time' => '4',
1611 'type' => 'messenger',
1612 'theme' => 'social',
1613 'animation' => 'slide',
1614 'headline' => '20% Off - for you',
1615 'label' => '',
1616 'link' => '',
1617 'icon' => '',
1618 'message' => "Hey there! We are running a <strong>special 20% off this week</strong> for registered users - like you.
1619
1620 Use coupon <code>LOYALTY20</code> during checkout.",
1621 'position' => '22',
1622 'text_color' => '#000000',
1623 'bg_color' => '#ffffff'
1624 ),
1625 array(
1626 'post_title' => 'How this blog makes over $34,800 / month for FREE.',
1627 'post_status' => 'publish',
1628 'time' => '10',
1629 'type' => 'popup',
1630 'theme' => 'air-mail',
1631 'headline' => 'How this blog makes over $34,800 / month for FREE.',
1632 'label' => 'FREE INSTANT ACCESS',
1633 'link' => '',
1634 'icon' => '',
1635 'message' => "This website earns over $30,000 every month, every single month, almost on autopilot. I have 4 other sites with similar results. All I do is publish new regular content every week.
1636
1637 <strong>Download my free kit to learn how I do this.</strong>
1638
1639 <ul>
1640 <li>How to choose blog topics that create long term value</li>
1641 <li>The type of blog post that will make your site go viral</li>
1642 <li>How to free yourself from the routine tasks</li>
1643 <li>Resources and tips to get started quickly</li>
1644 <li>Private members club to connect with fellow owners</li>
1645 </ul>",
1646 'text_color' => '#000000',
1647 'bg_color' => '#ffffff'
1648
1649 ),
1650 array(
1651 'post_title' => 'Exclusive Marketing Report',
1652 'post_status' => 'publish',
1653 'time' => '6',
1654 'type' => 'toast',
1655 'theme' => 'stand-out',
1656 'animation' => 'pop',
1657 'headline' => 'Exclusive Marketing Report',
1658 'label' => '',
1659 'link' => '',
1660 'icon' => '',
1661 'message' => 'FREE for every subscriber. Click here to download it.',
1662 'position' => '02',
1663 'text_color' => '#000000',
1664 'bg_color' => '#ffffff'
1665 )
1666
1667 )
1668 )
1669 )
1670 );
1671 }
1672
1673 function remove_preview_button() {
1674 global $post_type;
1675 if ( $post_type == 'ig_message' || $post_type == 'ig_campaign' ) {
1676 ?>
1677 <style type="text/css">
1678 #message.updated.below-h2 {
1679 display: none;
1680 }
1681
1682 #preview-action {
1683 display: none;
1684 }
1685
1686 /*Remove add new campaign and message*/
1687 .page-title-action {
1688 display: none;
1689 }
1690 </style>
1691 <?php
1692 }
1693 }
1694
1695
1696 function remove_row_actions( $actions, $post ) {
1697
1698 if ( empty( $post->post_type ) || ( $post->post_type != 'ig_campaign' && $post->post_type != 'ig_message' ) ) {
1699 return $actions;
1700 }
1701
1702 unset( $actions['inline hide-if-no-js'] );
1703 unset( $actions['view'] );
1704
1705 return $actions;
1706
1707 }
1708
1709 function identify_current_page() {
1710 global $post, $wpdb;
1711
1712 $obj = get_queried_object();
1713 $id = 0;
1714 if ( ! empty( $obj->has_archive ) ) {
1715 $sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s ", array( $obj->has_archive, 'page' ) );
1716 $id = $wpdb->get_var( $sql );
1717 } elseif ( is_object( $post ) && isset( $post->ID ) ) {
1718 $id = $post->ID;
1719 }
1720 $id = apply_filters( 'icegram_identify_current_page', $id );
1721 self::$current_page_id = $id;
1722 }
1723
1724 static function get_current_page_id() {
1725 global $post;
1726 if ( ! empty( $_REQUEST['page_id'] ) && is_numeric( $_REQUEST['page_id'] ) ) {
1727 $post = get_post( $_REQUEST['page_id'] );
1728 setup_postdata( $post );
1729 // WPML check
1730 $id = apply_filters( 'icegram_identify_current_page', $post->ID );
1731 self::$current_page_id = $id;
1732 }
1733
1734 return self::$current_page_id;
1735 }
1736
1737 static function get_current_page_url() {
1738 if ( ! empty( $_REQUEST['cache_compatibility'] ) && $_REQUEST['cache_compatibility'] == 'yes' ) {
1739 $pageURL = ( ! empty( $_REQUEST['referral_url'] ) ) ? $_REQUEST['referral_url'] : '';
1740 } else {
1741 $pageURL = 'http';
1742 if ( isset( $_SERVER["HTTPS"] ) ) {
1743 if ( $_SERVER["HTTPS"] == "on" ) {
1744 $pageURL .= "s";
1745 }
1746 }
1747 $pageURL .= "://";
1748 if ( $_SERVER["SERVER_PORT"] != "80" ) {
1749 $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
1750 } else {
1751 $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
1752 }
1753 }
1754
1755 return $pageURL;
1756 }
1757
1758 function wpml_get_parent_id( $id ) {
1759 global $post;
1760 if ( function_exists( 'icl_object_id' ) && function_exists( 'icl_get_default_language' ) ) {
1761 $id = icl_object_id( $id, $post->post_type, true, icl_get_default_language() );
1762 }
1763
1764 return $id;
1765 }
1766
1767
1768 /**
1769 * Our implementation of wpautop to preserve script and style tags
1770 */
1771 function before_wpautop( $pee ) {
1772 if ( trim( $pee ) === '' ) {
1773 $this->_wpautop_tags = array();
1774
1775 return '';
1776 }
1777
1778 $tags = array();
1779 // Pull out tags and add placeholders
1780 list( $pee, $tags['pre'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'pre' );
1781 list( $pee, $tags['script'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'script' );
1782 list( $pee, $tags['style'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'style' );
1783 $this->_wpautop_tags = $tags;
1784
1785 if ( ! empty( $pre_tags ) ) {
1786 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $pre_tags );
1787 }
1788 if ( ! empty( $script_tags ) ) {
1789 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $script_tags );
1790 }
1791 if ( ! empty( $style_tags ) ) {
1792 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $style_tags );
1793 }
1794
1795 return $pee;
1796 }
1797
1798 function after_wpautop( $pee ) {
1799 if ( trim( $pee ) === '' || empty( $this->_wpautop_tags ) ) {
1800 return '';
1801 }
1802
1803 // Replace placeholders with original content
1804 if ( ! empty( $this->_wpautop_tags['pre'] ) ) {
1805 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['pre'] );
1806 }
1807 if ( ! empty( $this->_wpautop_tags['script'] ) ) {
1808 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['script'] );
1809 }
1810 if ( ! empty( $this->_wpautop_tags['style'] ) ) {
1811 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['style'] );
1812 }
1813
1814 $this->_wpautop_tags = array();
1815
1816 return $pee;
1817 }
1818
1819 function _wpautop_add_tag_placeholders( $pee, $tag ) {
1820 $tags = array();
1821
1822 if ( false !== strpos( $pee, "<{$tag}" ) ) {
1823 $pee_parts = explode( "</{$tag}>", $pee );
1824 $last_pee = array_pop( $pee_parts );
1825 $pee = '';
1826 $i = 0;
1827
1828 foreach ( $pee_parts as $pee_part ) {
1829 $start = strpos( $pee_part, "<{$tag}" );
1830
1831 // Malformed html?
1832 if ( false === $start ) {
1833 $pee .= $pee_part;
1834 continue;
1835 }
1836
1837 $name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
1838 $tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
1839
1840 $pee .= substr( $pee_part, 0, $start ) . $name;
1841 $i ++;
1842 }
1843
1844 $pee .= $last_pee;
1845 }
1846
1847 return array( $pee, $tags );
1848 }
1849
1850 function _wpautop_replace_tag_placeholders( $pee, $tags ) {
1851 if ( ! empty( $tags ) ) {
1852 $pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
1853 }
1854
1855 return $pee;
1856 }
1857
1858 static function duplicate_in_db( $original_id ) {
1859 // Get access to the database
1860 global $wpdb;
1861 // Get the post as an array
1862 $duplicate = get_post( $original_id, 'ARRAY_A' );
1863 // Modify some of the elements
1864 $duplicate['post_title'] = $duplicate['post_title'] . ' ' . __( 'Copy', 'icegram' );
1865 $duplicate['post_status'] = 'draft';
1866 // Set the post date
1867 $timestamp = current_time( 'timestamp', 0 );
1868
1869 $duplicate['post_date'] = date( 'Y-m-d H:i:s', $timestamp );
1870
1871 // Remove some of the keys
1872 unset( $duplicate['ID'] );
1873 unset( $duplicate['guid'] );
1874 unset( $duplicate['comment_count'] );
1875
1876 // Insert the post into the database
1877 $duplicate_id = wp_insert_post( $duplicate );
1878
1879 // Duplicate all taxonomies/terms
1880 $taxonomies = get_object_taxonomies( $duplicate['post_type'] );
1881
1882 foreach ( $taxonomies as $taxonomy ) {
1883 $terms = wp_get_post_terms( $original_id, $taxonomy, array( 'fields' => 'names' ) );
1884 wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
1885 }
1886
1887 // Duplicate all custom fields
1888 $custom_fields = get_post_custom( $original_id );
1889 foreach ( $custom_fields as $key => $value ) {
1890 if ( $key === 'messages' ) {
1891 $messages = unserialize( $value[0] );
1892 foreach ( $messages as &$message ) {
1893 $clone_msg_id = Icegram::duplicate_in_db( $message['id'] );
1894 $message['id'] = $clone_msg_id;
1895 }
1896 $value[0] = serialize( $messages );
1897 }
1898 add_post_meta( $duplicate_id, $key, maybe_unserialize( $value[0] ) );
1899 }
1900
1901 return $duplicate_id;
1902 }
1903
1904 static function duplicate( $original_id ) {
1905 $duplicate_id = Icegram::duplicate_in_db( $original_id );
1906 $location = admin_url( 'post.php?post=' . $duplicate_id . '&action=edit' );
1907 header( 'Location:' . $location );
1908 exit;
1909 }
1910
1911 public static function form_submission_validate_request( $request_data ) {
1912 if ( ! empty( $request_data ) ) {
1913 // Check for Remote Rainmaker form submission request
1914 $request_data['ig_is_remote'] = false;
1915 $request_data['is_remote'] = false;
1916 if ( ! empty( $request_data['ig_mode'] ) && $request_data['ig_mode'] === 'remote' ) {
1917 $ig_remote_url = $request_data['ig_remote_url'];
1918 if ( ! empty( $request_data['ig_campaign_id'] ) ) {
1919 $rules = get_post_meta( $request_data['ig_campaign_id'], 'icegram_campaign_target_rules', true );
1920 if ( ! empty( $rules['remote_urls'] ) && is_array( $rules['remote_urls'] ) ) {
1921 foreach ( $rules['remote_urls'] as $remote_url_pattern ) {
1922 $valid = Icegram_Campaign::is_valid_url( $remote_url_pattern, $ig_remote_url );
1923 if ( $valid ) {
1924 $request_data['ig_is_remote'] = true;
1925 $request_data['is_remote'] = true;
1926 break;
1927 }
1928 }
1929 //TODO :: discard the the remote request and data
1930 // if($request_data['ig_is_remote'] == false){
1931 // return array();
1932 // }
1933 }
1934
1935 }
1936 }
1937 }
1938
1939 return $request_data;
1940 }
1941
1942 public static function get_ig_meta_info() {
1943 $total_campaigns = wp_count_posts( 'ig_campaign' );
1944 $total_campaigns_publish = $total_campaigns->publish;
1945 $total_campaigns_draft = $total_campaigns->draft;
1946
1947 $meta_info = array(
1948 'total_campaigns_publish' => $total_campaigns_publish,
1949 'total_campaigns_draft' => $total_campaigns_draft,
1950 );
1951
1952 return $meta_info;
1953 }
1954
1955 /**
1956 * Render Quick Feedback Widget
1957 *
1958 * @param $params
1959 *
1960 * @since 1.10.38
1961 */
1962 public function render_feedback_widget( $params ) {
1963 global $ig_feedback;
1964
1965 $feedback = $ig_feedback;
1966
1967 if ( ! $feedback->can_show_feedback_widget() ) {
1968 return;
1969 }
1970
1971 $default_params = array(
1972 'set_transient' => true,
1973 'force' => false,
1974 'show_once' => false
1975 );
1976
1977 $params = wp_parse_args( $params, $default_params );
1978
1979 if ( ! empty( $params['event'] ) ) {
1980
1981 $event = $feedback->event_prefix . $params['event'];
1982 $force = ! empty( $params['force'] ) ? $params['force'] : false;
1983
1984 $can_show = false;
1985
1986 if ( $force ) {
1987 $can_show = true;
1988 } else {
1989 if ( ! $feedback->is_event_transient_set( $event ) ) {
1990 $can_show = true;
1991
1992 $feedback_data = $feedback->get_event_feedback_data( $feedback->plugin_abbr, $event );
1993 if ( count( $feedback_data ) > 0 ) {
1994 $show_once = $params['show_once'];
1995 $feedback_data = array_reverse( $feedback_data );
1996 $last_feedback_given_on = $feedback_data[0]['created_on'];
1997
1998 // If event feedback given within 45 days or show event only once?
1999 // Don't show now
2000 if ( $show_once || ( strtotime( $last_feedback_given_on ) > strtotime( '-45 days' ) ) ) {
2001 $can_show = false;
2002 }
2003 }
2004 }
2005 }
2006
2007 if ( $can_show ) {
2008 if ( 'star' === $params['type'] ) {
2009 $feedback->render_stars( $params );
2010 } elseif ( 'emoji' === $params['type'] ) {
2011 $feedback->render_emoji( $params );
2012 } elseif ( 'feedback' === $params['type'] ) {
2013 $feedback->render_general_feedback( $params );
2014 } elseif ( 'fb' === $params['type'] ) {
2015 /**
2016 * We are not calling home for this event and we want to show
2017 * this Widget only once. So, we are storing feedback data now.
2018 */
2019 $feedback->set_feedback_data( 'ig', $event );
2020 $feedback->render_fb_widget( $params );
2021 } elseif ( 'poll' === $params['type'] ) {
2022 $feedback->set_feedback_data( 'ig', $event );
2023 $feedback->render_poll_widget( $params );
2024 }
2025 }
2026 }
2027 }
2028
2029 /**
2030 * Check if premium plugin installed
2031 *
2032 * @return boolean
2033 *
2034 * @since 1.10.39
2035 */
2036 public function is_premium_installed() {
2037 global $ig_tracker;
2038
2039 $icegram_premium = 'icegram-engage/icegram-engage.php';
2040
2041 return $ig_tracker::is_plugin_installed( $icegram_premium );
2042 }
2043
2044 /**
2045 * Check if premium plugin active
2046 *
2047 * @return boolean
2048 *
2049 * @since 1.10.39
2050 */
2051 public function is_premium_activated() {
2052 global $ig_tracker;
2053
2054 $icegram_premium = 'icegram-engage/icegram-engage.php';
2055
2056 return $ig_tracker::is_plugin_activated( $icegram_premium );
2057 }
2058
2059 }
2060
2061 function initialize_icegram() {
2062 /* @var Icegram Object */
2063 global $icegram;
2064 // i18n / l10n - load translations
2065 load_plugin_textdomain( 'icegram', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
2066
2067 $icegram = new Icegram();
2068
2069 do_action( 'icegram_loaded' );
2070 }
2071
2072 add_action( 'plugins_loaded', 'initialize_icegram' );
2073 register_activation_hook( __FILE__, array( 'Icegram', 'install' ) );