PluginProbe
Icegram Engage – Popups, Optins, CTAs & Lead Generation / 1.10.42
Icegram Engage – Popups, Optins, CTAs & Lead Generation v1.10.42
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.42, at icegram.php

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