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

2,021 lines 74.9 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.38
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.0';
39 $ig_tracker = 'IG_Tracker_V_' . str_replace( '.', '_', $feedback_version );
40
41 $this->version = "1.10.38";
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 public function add_admin_notices() {
170
171 global $ig_feedback;
172
173 $screen = get_current_screen();
174 if ( ! in_array( $screen->id, array( 'ig_campaign', 'ig_message', 'edit-ig_message', 'edit-ig_campaign' ), true ) ) {
175 return;
176 }
177
178 //bfcm 2019 :start
179 $timezone_format = _x( 'Y-m-d', 'timezone date format' );
180 $ig_current_date = strtotime( date_i18n( $timezone_format ) );
181 $ig_offer_start = strtotime( "2019-11-22" );
182 $ig_offer_end = strtotime( "2019-12-03" );
183 if ( ( $ig_current_date >= $ig_offer_start ) && ( $ig_current_date <= $ig_offer_end ) ) {
184 include_once( 'ig-offer.php' );
185 }
186 //bfcm 2019 :end
187
188 }
189
190 public function dismiss_admin_notice() {
191 if ( isset( $_GET['ig_dismiss_admin_notice'] ) && $_GET['ig_dismiss_admin_notice'] == '1' && isset( $_GET['ig_option_name'] ) ) {
192 $option_name = sanitize_text_field( $_GET['ig_option_name'] );
193 update_option( $option_name . '_icegram', true );
194 if ( $option_name === 'ig_offer_bfcm_done_2019' || $option_name === 'ig_offer_last_day_bfcm_done_2019' ) {
195 header( "Location: https://www.icegram.com/?utm_source=in_app&utm_medium=ig_banner&utm_campaign=ig-bfcm-2019" );
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 wp_register_script( 'icegram_main_js', $this->plugin_url . '/assets/js/main.min.js', array( 'jquery' ), $this->version, true );
761 if ( ! wp_script_is( 'icegram_main_js' ) ) {
762 wp_enqueue_script( 'icegram_main_js' );
763 wp_localize_script( 'icegram_main_js', 'icegram_pre_data', $icegram_pre_data );
764 }
765 }
766
767 function display_messages() {
768
769 $skip_others = $preview_mode = false;
770 $campaign_ids = $message_ids = array();
771 $this->shortcode_instances = ( $this->cache_compatibility == 'yes' && ! empty( $_REQUEST['shortcodes'] ) ) ? $_REQUEST['shortcodes'] : $this->shortcode_instances;
772 // Pull in message and campaign IDs from shortcodes - if set
773 if ( ! empty( $this->shortcode_instances ) ) {
774 foreach ( $this->shortcode_instances as $i => $value ) {
775 $cids = array_map( 'trim', (array) explode( ',', intval( $value['campaigns'] ) ) );
776 $mids = array_map( 'trim', (array) explode( ',', intval( $value['messages'] ) ) );
777 if ( ! empty( $value['skip_others'] ) && $value['skip_others'] == 'yes' && ( ! empty( $cids ) || ! empty( $mids ) ) ) {
778 $skip_others = true;
779 }
780 $campaign_ids = array_merge( $campaign_ids, $cids );
781 $message_ids = array_merge( $message_ids, $mids );
782 }
783 }
784 if ( ! empty( $_REQUEST['campaign_preview_id'] ) && intval( $_REQUEST['campaign_preview_id'] ) && ( 'edit_posts' ) ) {
785 $campaign_ids = array( intval( $_REQUEST['campaign_preview_id'] ) );
786 $preview_mode = true;
787 }
788
789
790 $messages = $this->get_valid_messages( $message_ids, $campaign_ids, $preview_mode, $skip_others );
791
792 if ( empty( $messages ) ) {
793 //wp_die(0);
794 return;
795 }
796
797 $messages_to_show_ids = array();
798 foreach ( $messages as $key => $message_data ) {
799
800 if ( ! is_array( $message_data ) || empty( $message_data ) ) {
801 continue;
802 }
803
804 // Don't show a seen message again - if needed
805 // change to campaign targetting in v1.9.1
806 if ( ! empty( $message_data['id'] ) &&
807 empty( $_GET['campaign_preview_id'] ) &&
808 ! empty( $message_data['retargeting'] ) &&
809 $message_data['retargeting'] == 'yes'
810 ) {
811 if ( ! empty( $_COOKIE[ 'icegram_messages_shown_' . $message_data['id'] ] ) || ! empty( $_COOKIE[ 'icegram_campaign_shown_' . floor( $message_data['campaign_id'] ) ] ) ) {
812 unset( $messages[ $key ] );
813 continue;
814 }
815 }
816 if ( ! empty( $message_data['id'] ) &&
817 empty( $_GET['campaign_preview_id'] ) &&
818 ! empty( $message_data['retargeting_clicked'] ) &&
819 $message_data['retargeting_clicked'] == 'yes'
820 ) {
821 if ( ! empty( $_COOKIE[ 'icegram_messages_clicked_' . $message_data['id'] ] ) || ! empty( $_COOKIE[ 'icegram_campaign_clicked_' . floor( $message_data['campaign_id'] ) ] ) ) {
822 unset( $messages[ $key ] );
823 continue;
824 }
825 }
826
827 // Avoid showing the same message twice
828 if ( in_array( $message_data['id'], $messages_to_show_ids ) ) {
829 unset ( $messages[ $key ] );
830 continue;
831 } else {
832 $messages_to_show_ids[] = $message_data['id'];
833 }
834
835 $this->process_message_body( $messages[ $key ] );
836 }
837 if ( empty( $messages ) ) {
838 return;
839 }
840 $icegram_default = apply_filters( 'icegram_branding_data',
841 array(
842 'icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
843 'powered_by_logo' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
844 'powered_by_text' => __( 'Powered by Icegram', 'icegram' )
845 ) );
846 $messages = apply_filters( 'icegram_messages_to_show', $messages );
847 $icegram_data = apply_filters( 'icegram_data', array(
848 'messages' => array_values( $messages ),
849 'ajax_url' => admin_url( 'admin-ajax.php' ),
850 'preview_id' => ! empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '',
851 'defaults' => $icegram_default
852 ) );
853 if ( empty( $icegram_data['preview_id'] ) ) {
854 unset( $icegram_data['preview_id'] );
855 }
856
857 do_action( 'icegram_print_js_css_data', $icegram_data );
858
859 do_action( 'icegram_data_printed' );
860 }
861
862 function two_step_mobile_popup( $icegram_data ) {
863
864 $temp = array();
865 foreach ( $icegram_data['messages'] as $message_id => $message ) {
866
867 if ( ! empty( $message['ig_mobile_popup'] ) && $message['ig_mobile_popup'] == true ) {
868 $action_bar = $message;
869 $action_bar['type'] = 'action-bar';
870 $action_bar['theme'] = 'hello';
871 $action_bar['position'] = '21';
872 $action_bar['message'] = '';
873 $action_bar['label'] = __( 'Show More', 'icegram' );
874 $action_bar['id'] = $action_bar['id'] . '_00';
875 $action_bar['use_custom_code'] = 'yes';
876 $action_bar['form_html'] = '';
877 $action_bar['form_html_original'] = '';
878 $action_bar['rainmaker_form_code'] = '';
879 $action_bar['link'] = '';
880 $action_bar['redirect_to_link'] = '';
881 $action_bar['cta'] = '';
882 $action_bar['alt_cta'] = '';
883 $action_bar['add_alt_cta'] = '';
884 $action_bar['custom_css'] = '#ig_this_message .ig_close{display:none;}';
885 $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>";
886 unset( $action_bar['ig_mobile_popup'] );
887 $temp[] = $action_bar;
888 }
889 }
890 $icegram_data['messages'] = array_merge( $icegram_data['messages'], $temp );
891 unset( $temp );
892
893 return $icegram_data;
894 }
895
896
897 function print_js_css_data( $icegram_data ) {
898
899 $this->collect_js_and_css( $icegram_data );
900 if ( $this->cache_compatibility === 'yes' ) {
901 echo json_encode( $icegram_data );
902 wp_die();
903 } else {
904 wp_localize_script( 'icegram_main_js', 'icegram_data', $icegram_data );
905 }
906 }
907
908 function collect_js_and_css( &$icegram_data ) {
909
910 $types_shown = array();
911 $scripts = array();
912 $css = array();
913 foreach ( $icegram_data['messages'] as $key => $message_data ) {
914 $types_shown[] = $message_data['type'];
915 }
916
917 $types_shown = array_unique( $types_shown );
918 $ver_prefix = '?var=' . $this->version;
919
920 $scripts[] = $this->plugin_url . "/assets/js/icegram.min.js" . $ver_prefix;
921 $css[] = $this->plugin_url . "/assets/css/frontend.min.css" . $ver_prefix;
922 //minify and combine only for default msg type
923 $ig_core_message_types = array( 'popup', 'action-bar', 'toast', 'messenger' );
924 // Load JS and default CSS
925 foreach ( $types_shown as $message_type ) {
926 if ( ! in_array( $message_type, $ig_core_message_types ) ) {
927 $scripts[] = $this->message_types[ $message_type ]['baseurl'] . "main.js" . $ver_prefix;
928 $css[] = $this->message_types[ $message_type ]['baseurl'] . "default.css" . $ver_prefix;
929 } else {
930 $css[] = $this->message_types[ $message_type ]['baseurl'] . 'themes/' . $message_type . ".min.css" . $ver_prefix;
931 }
932 }
933
934 //TODO :: add theme pack theme css files too.
935 // Load theme CSS
936 foreach ( $icegram_data['messages'] as $key => $message ) {
937 if ( ! empty( $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ] ) ) {
938 $theme = $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ]['baseurl'] . $message['theme'] . '.css' . $ver_prefix;
939 } else {
940 $theme_default = $this->message_types[ $message['type'] ] ['settings']['theme']['default'];
941 $theme = $this->message_types[ $message['type'] ]['themes'][ $theme_default ]['baseurl'] . $theme_default . '.css' . $ver_prefix;
942 $icegram_data['messages'][ $key ]['theme'] = $theme_default;
943 }
944 if ( ! preg_match( '/icegram\/message-types/i', $theme ) ) {
945 $css [] = $theme;
946 }
947 }
948 $css = array_unique( $css );
949 $icegram_data['scripts'] = apply_filters( 'add_icegram_script', $scripts );
950 $icegram_data['css'] = apply_filters( 'add_icegram_css', $css );
951
952 return $icegram_data;
953 }
954
955 // Process
956 function process_message_body( &$message_data ) {
957 global $wp_scripts;
958 global $wp_styles;
959
960 if ( $this->cache_compatibility == 'yes' ) {
961 $q_script = ! empty( $wp_scripts->queue ) ? $wp_scripts->queue : array();
962 $q_style = ! empty( $wp_styles->queue ) ? $wp_styles->queue : array();
963 }
964 $content = $message_data['message'];
965 $content = convert_chars( convert_smilies( wptexturize( $content ) ) );
966 if ( isset( $GLOBALS['wp_embed'] ) ) {
967 $content = $GLOBALS['wp_embed']->autoembed( $content );
968 }
969 $content = $this->after_wpautop( wpautop( $this->before_wpautop( $content ) ) );
970 $content = do_shortcode( shortcode_unautop( $content ) );
971 $message_data['message'] = $content;
972
973 //do_shortcode in headline
974 $message_data['headline'] = do_shortcode( shortcode_unautop( $message_data['headline'] ) );
975 //shortcode support for Third party forms and Rainmaker
976 $form_html_original = ! empty( $message_data["rainmaker_form_code"] )
977 ? ( '[rainmaker_form id="' . $message_data["rainmaker_form_code"] . '"]' )
978 : ( ! empty( $message_data['form_html_original'] ) ? $message_data['form_html_original'] : '' );
979 $form_html_original = ! empty( $message_data["es_form_code"] )
980 ? ( '[email-subscribers-form id="' . $message_data["es_form_code"] . '"]' )
981 : $form_html_original;
982
983 if ( ! empty( $form_html_original ) ) {
984 $message_data['form_html'] = do_shortcode( shortcode_unautop( $form_html_original ) );
985 }
986 //TODO :: Handle case for inline style and script
987 if ( $this->cache_compatibility == 'yes' ) {
988 $handles = ! empty( $wp_scripts->queue ) ? array_diff( $wp_scripts->queue, $q_script ) : array();
989 unset( $q_script );
990 if ( ! empty( $handles ) ) {
991 if ( empty( $message_data['assets'] ) ) {
992 $message_data['assets'] = array();
993 }
994
995 ob_start();
996 $wp_scripts->do_items( $handles );
997 $message_data['assets']['scripts'] = array_filter( explode( '<script', ob_get_clean() ) );
998 }
999
1000 //TODO :: do_items if required
1001 $handles = ! empty( $wp_styles->queue ) ? array_diff( $wp_styles->queue, $q_style ) : array();
1002 unset( $q_style );
1003 if ( ! empty( $handles ) ) {
1004 if ( empty( $message_data['assets'] ) ) {
1005 $message_data['assets'] = array();
1006 }
1007
1008 foreach ( $handles as $handle ) {
1009 ob_start();
1010 $wp_styles->do_item( $handle );
1011 $message_data['assets']['styles'][ $handle ] = ob_get_clean();
1012 }
1013 }
1014 }
1015 }
1016
1017 function enqueue_admin_styles_and_scripts() {
1018
1019 $screen = get_current_screen();
1020 if ( ! in_array( $screen->id, array( 'ig_campaign', 'ig_message', 'edit-ig_campaign' ), true ) ) {
1021 return;
1022 }
1023
1024 // Register scripts
1025 wp_register_script( 'icegram_writepanel', $this->plugin_url . '/assets/js/admin.min.js', array( 'jquery', 'wp-color-picker' ), $this->version );
1026
1027 wp_enqueue_script( 'icegram_writepanel' );
1028
1029 $icegram_writepanel_params = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'search_message_nonce' => wp_create_nonce( "search-messages" ), 'home_url' => home_url( '/' ) );
1030 $this->available_headlines = apply_filters( 'icegram_available_headlines', array() );
1031 $icegram_writepanel_params = array_merge( $icegram_writepanel_params, array( 'available_headlines' => $this->available_headlines ) );
1032
1033 wp_localize_script( 'icegram_writepanel', 'icegram_writepanel_params', $icegram_writepanel_params );
1034
1035 wp_enqueue_style( 'dashicons' );
1036 wp_enqueue_style( 'wp-color-picker' );
1037 wp_enqueue_style( 'icegram_admin_styles', $this->plugin_url . '/assets/css/admin.min.css', array(), $this->version );
1038
1039 if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) {
1040 wp_enqueue_script( 'jquery-ui-datepicker' );
1041 }
1042
1043 }
1044
1045 //execute shortcode in text widget
1046 function ig_widget_text_filter( $content ) {
1047 if ( ! preg_match( '/\[[\r\n\t ]*icegram?[\r\n\t ].*?\]/', $content ) ) {
1048 return $content;
1049 }
1050
1051 $content = do_shortcode( $content );
1052
1053 return $content;
1054 }
1055
1056 public static function get_platform() {
1057 $mobile_detect = new Ig_Mobile_Detect();
1058 $mobile_detect->setUserAgent();
1059 if ( $mobile_detect->isMobile() ) {
1060 return ( $mobile_detect->isTablet() ) ? 'tablet' : 'mobile';
1061 } elseif ( $mobile_detect->isTablet() ) {
1062 return 'tablet';
1063 }
1064
1065 return 'laptop';
1066 }
1067
1068 function get_message_data( $message_ids = array(), $preview = false ) {
1069 global $wpdb;
1070 $message_data = array();
1071 $original_message_id_map = array();
1072 $meta_key = $preview ? 'icegram_message_preview_data' : 'icegram_message_data';
1073 $message_data_query = "SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE '$meta_key'";
1074 if ( ! empty( $message_ids ) && is_array( $message_ids ) ) {
1075 // For WPML compatibility
1076 if ( function_exists( 'icl_object_id' ) ) {
1077 $wpml_settings = get_option( 'icl_sitepress_settings' );
1078 $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;
1079
1080 foreach ( $message_ids as $i => $id ) {
1081 $translated = icl_object_id( $id, 'ig_message', $original_if_missing );
1082 $message_ids[ $i ] = $translated;
1083 $original_message_id_map[ $translated ] = $id;
1084 }
1085 }
1086 $message_ids = array_filter( array_unique( $message_ids ) );
1087 if ( ! empty( $message_ids ) ) {
1088 $message_data_query .= " AND post_id IN ( " . implode( ',', $message_ids ) . " )";
1089 $message_data_results = $wpdb->get_results( $message_data_query, 'ARRAY_A' );
1090 foreach ( $message_data_results as $message_data_result ) {
1091 $data = maybe_unserialize( $message_data_result['meta_value'] );
1092 if ( ! empty( $data ) ) {
1093 $message_data[ $message_data_result['post_id'] ] = $data;
1094 // For WPML compatibility
1095 if ( ! empty( $original_message_id_map[ $message_data_result['post_id'] ] ) ) {
1096 $message_data[ $message_data_result['post_id'] ]['original_message_id'] = $original_message_id_map[ $message_data_result['post_id'] ];
1097 }
1098 }
1099 }
1100 }
1101 }
1102
1103 return $message_data;
1104 }
1105
1106 function get_valid_messages( $message_ids = array(), $campaign_ids = array(), $preview_mode = false, $skip_others = false ) {
1107 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 ) );
1108
1109 $valid_messages = $valid_campaigns = $message_campaign_map = array();
1110
1111 $campaign_ids = array_filter( array_unique( (array) $campaign_ids ) );
1112 $message_ids = array_filter( array_unique( (array) $message_ids ) );
1113 if ( ! empty( $campaign_ids ) ) {
1114 $valid_campaigns = $this->get_valid_campaigns( $campaign_ids, true, $preview_mode );
1115 }
1116
1117 // When skip_others is true, we won't load campaigns / messages from db
1118 if ( ! $skip_others && ! $preview_mode ) {
1119 $campaigns = $this->get_valid_campaigns();
1120 if ( ! empty( $campaigns ) ) {
1121 foreach ( $campaigns as $id => $campaign ) {
1122 if ( ! array_key_exists( $id, $valid_campaigns ) ) {
1123 $valid_campaigns[ $id ] = $campaign;
1124 }
1125 }
1126 }
1127 }
1128
1129 // Create a map to look up campaign id for a given message
1130 if ( ! empty( $valid_campaigns ) ) {
1131 foreach ( $valid_campaigns as $id => $campaign ) {
1132 if ( $preview_mode ) {
1133 $campaign->messages = get_post_meta( $id, 'campaign_preview', true );
1134 }
1135 if ( ! empty( $campaign->messages ) ) {
1136 foreach ( $campaign->messages as $msg ) {
1137 $message_ids[] = $msg['id'];
1138 if ( ! array_key_exists( $msg['id'], $message_campaign_map ) ) {
1139 $message_campaign_map[ $msg['id'] ] = $id;
1140 }
1141 }
1142 }
1143 }
1144 }
1145
1146 // We don't display same message twice...
1147 $message_ids = array_unique( $message_ids );
1148
1149 if ( empty( $message_ids ) ) {
1150 return array();
1151 }
1152 $valid_messages = $this->get_message_data( $message_ids, $preview_mode );
1153
1154 foreach ( $valid_messages as $id => $message_data ) {
1155 // Remove message if required fields are missing
1156 if ( empty( $message_data ) || empty( $message_data['type'] ) ) {
1157 unset( $valid_messages[ $id ] );
1158 continue;
1159 }
1160 // Remove message if message type is uninstalled
1161 $class_name = 'Icegram_Message_Type_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $message_data['type'] ) ) );
1162 if ( ! class_exists( $class_name ) ) {
1163 unset( $valid_messages[ $id ] );
1164 continue;
1165 }
1166 $message_data['delay_time'] = 0;
1167 $message_data['retargeting'] = '';
1168 $message_data['campaign_id'] = ( $preview_mode ) ? $_REQUEST['campaign_preview_id'] : '';
1169
1170 // Pull display time and retargeting rule from campaign if possible
1171 $message_id = ( ! empty( $message_data['original_message_id'] ) ) ? $message_data['original_message_id'] : $id;
1172 if ( ! empty( $message_campaign_map[ $message_id ] ) ) {
1173 //modify campaign id
1174 $message_data['campaign_id'] = apply_filters( 'modify_campaing_id', $message_campaign_map[ $message_id ], $message_id );
1175 $campaign = $valid_campaigns[ floor( $message_data['campaign_id'] ) ];
1176 if ( ! empty( $campaign ) && $campaign instanceof Icegram_Campaign ) {
1177 $message_meta_from_campaign = $campaign->get_message_meta_by_id( $message_id );
1178 if ( ! empty( $message_meta_from_campaign['time'] ) ) {
1179 $message_data['delay_time'] = $message_meta_from_campaign['time'];
1180 }
1181
1182 //check if campaign is targeted to mobile at zero
1183 $device_rule = $campaign->get_rule_value( 'device' );
1184 if ( $this->get_platform() !== 'laptop' && ! empty( $device_rule['mobile'] ) && $device_rule['mobile'] == 'yes' && $message_data['delay_time'] == 0 && $message_data['type'] == 'popup' ) {
1185 $message_data['ig_mobile_popup'] = true;
1186 if ( ! empty( $message_data['triggers'] ) && ! empty( $message_data['triggers']['when_to_show'] ) ) {
1187 $message_data['ig_mobile_popup'] = ( $message_data['triggers']['when_to_show'] == 'duration_on_page' && $message_data['triggers']['duration_on_page'] == 0 ) ? true : false;
1188 }
1189 }
1190 //set delay time -1 if shortcode with content
1191 foreach ( $this->shortcode_instances as $i => $value ) {
1192 $campaign_ids = explode( ',', $value['campaigns'] );
1193 if ( ! empty( $value['with_content'] ) && in_array( $message_data['campaign_id'], $campaign_ids ) ) {
1194 $message_data['delay_time'] = - 1;
1195 }
1196 }
1197 $rule_value = $campaign->get_rule_value( 'retargeting' );
1198 $message_data['retargeting'] = ! empty( $rule_value['retargeting'] ) ? $rule_value['retargeting'] : '';
1199 $message_data['expiry_time'] = ! empty( $rule_value['retargeting'] ) ? $rule_value['expiry_time'] : '';
1200 $rule_value_retargeting_clicked = $campaign->get_rule_value( 'retargeting_clicked' );
1201 $message_data['retargeting_clicked'] = ! empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['retargeting_clicked'] : '';
1202 $message_data['expiry_time_clicked'] = ! empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['expiry_time_clicked'] : '';
1203
1204 }
1205 }
1206 $valid_messages[ $id ] = $message_data;
1207 }
1208 $valid_messages = apply_filters( 'icegram_valid_messages', $valid_messages );
1209
1210 return $valid_messages;
1211 }
1212
1213 function get_valid_campaigns( $campaign_ids = array(), $skip_page_check = false, $preview_mode = false ) {
1214 global $wpdb;
1215 if ( empty( $campaign_ids ) ) {
1216 $sql = "SELECT pm.post_id
1217 FROM {$wpdb->prefix}posts AS p
1218 LEFT JOIN {$wpdb->prefix}postmeta AS pm ON ( pm.post_id = p.ID )
1219 WHERE p.post_status = 'publish' ";
1220 // Filter handler within this file (and possibly others) will append to this SQL
1221 // and provide arguments for wpdb->prepare if needed.
1222 // First element in the array is SQL, remaining are values for placeholders in SQL
1223 $sql_params = apply_filters( 'icegram_get_valid_campaigns_sql', array( $sql ), array() );
1224 $campaign_ids = $wpdb->get_col( $wpdb->prepare( array_shift( $sql_params ), $sql_params ) );
1225 }
1226 $valid_campaigns = array();
1227 foreach ( (array) $campaign_ids as $campaign_id ) {
1228 $campaign = new Icegram_Campaign( $campaign_id );
1229 if ( $preview_mode || $campaign->is_valid( array( 'skip_page_check' => $skip_page_check ) ) ) {
1230 $valid_campaigns[ $campaign_id ] = $campaign;
1231 } else {
1232 // Campgain is invalid!
1233 }
1234
1235 }
1236 $valid_campaigns = apply_filters( 'icegram_valid_campaigns', $valid_campaigns );
1237
1238 return $valid_campaigns;
1239 }
1240
1241 function append_to_valid_campaigns_sql( $sql_params = array(), $options = array() ) {
1242 // Page check conditions
1243 //$pid = $_GET['page_id'];
1244 $pid = Icegram::get_current_page_id();
1245 $sql = " AND (
1246 pm.meta_key = 'icegram_campaign_target_rules' AND (
1247 ( pm.meta_value LIKE '%%%s%%' )
1248 OR ( pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' )
1249 ";
1250 $sql_params[] = 's:8:"sitewide";s:3:"yes";';
1251 $sql_params[] = 's:10:"other_page";s:3:"yes";';
1252 $sql_params[] = 's:7:"page_id";a:';
1253 $sql_params[] = serialize( (string) $pid );
1254 //local url
1255 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
1256 $sql_params[] = 's:9:"local_url";s:3:"yes";';
1257 if ( ! empty( $_REQUEST['cache_compatibility'] ) && $_REQUEST['cache_compatibility'] == 'yes' ) {
1258 $is_home = ( ! empty( $_REQUEST['is_home'] ) && $_REQUEST['is_home'] === 'true' ) ? true : false;
1259 } else {
1260 $is_home = ( is_home() || is_front_page() ) ? true : false;
1261 }
1262 if ( $is_home === true ) {
1263 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
1264 $sql_params[] = 's:8:"homepage";s:3:"yes";';
1265 }
1266 $sql .= " ) )";
1267
1268 $sql_params[0] .= $sql;
1269
1270 //s:9:"logged_in";s:3:"all";
1271
1272 return $sql_params;
1273 }
1274
1275 // Include all classes required for Icegram plugin
1276 function include_classes( $feedback_version ) {
1277 global $ig_tracker, $ig_feedback;
1278
1279 $feedback_version_for_file = str_replace( '.', '-', $feedback_version );
1280 $t = 'classes/feedback/class-ig-tracker.php';
1281 $f = 'classes/feedback/class-ig-feedback.php';
1282 require_once( $t );
1283 require_once( $f );
1284
1285 $ig_feedback_class = 'IG_Feedback_V_' . str_replace( '.', '_', $feedback_version );
1286 $ig_feedback = new $ig_feedback_class( 'Icegram', 'icegram', 'ig', 'igfree.', false );
1287
1288 require_once( 'classes/feedback.php' );
1289
1290 $classes = glob( $this->plugin_path . '/classes/*.php' );
1291 foreach ( $classes as $file ) {
1292 // Files with 'admin' in their name are included only for admin section
1293 if ( is_file( $file ) && ( ( strpos( $file, '-admin' ) >= 0 && is_admin() ) ) ) {
1294 $all_active_plugins = $ig_tracker::get_plugins();
1295 if ( ( strpos( $file, 'ig-upsale-admin.php' ) !== false ) && in_array( 'icegram-engage/icegram-engage.php', $all_active_plugins ) ) {
1296 continue;
1297 }
1298 include_once $file;
1299 } elseif ( ! is_admin() ) {
1300 include_once $file;
1301 }
1302 }
1303
1304 // Load built in message types
1305 $icegram_message_type_basedirs = glob( $this->plugin_path . '/message-types/*' );
1306 // Allow other plugins to add new message types
1307 $icegram_message_type_basedirs = apply_filters( 'icegram_message_type_basedirs', $icegram_message_type_basedirs );
1308 // Set up different message type classes
1309 foreach ( $icegram_message_type_basedirs as $dir ) {
1310 $type = basename( $dir );
1311 $class_file = $dir . "/main.php";
1312 if ( is_file( $class_file ) ) {
1313 include_once( $class_file );
1314 }
1315 $class_name = 'Icegram_Message_Type_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $type ) ) );
1316 if ( class_exists( $class_name ) ) {
1317 $this->message_type_objs[ $type ] = new $class_name();
1318 }
1319 }
1320 do_action( 'ig_file_include' );
1321 $this->message_types = apply_filters( 'icegram_message_types', array() );
1322
1323 }
1324
1325 // Register Campaign post type
1326 function register_campaign_post_type() {
1327 $labels = array(
1328 'name' => __( 'Campaigns', 'icegram' ),
1329 'singular_name' => __( 'Campaign', 'icegram' ),
1330 'add_new' => __( 'Add New Campaign', 'icegram' ),
1331 'add_new_item' => __( 'Add New Campaign', 'icegram' ),
1332 'edit_item' => __( 'Edit Campaign', 'icegram' ),
1333 'new_item' => __( 'New Campaign', 'icegram' ),
1334 'all_items' => __( 'Campaigns', 'icegram' ),
1335 'view_item' => __( 'View Campaign', 'icegram' ),
1336 'search_items' => __( 'Search Campaigns', 'icegram' ),
1337 'not_found' => __( 'No campaigns found', 'icegram' ),
1338 'not_found_in_trash' => __( 'No campaigns found in Trash', 'icegram' ),
1339 'parent_item_colon' => __( '', 'icegram' ),
1340 'menu_name' => __( 'Icegram', 'icegram' )
1341 );
1342
1343 $args = array(
1344 'labels' => $labels,
1345 // 'menu_icon' => 'dashicons-info',
1346 'public' => false,
1347 'publicly_queryable' => false,
1348 'show_ui' => true,
1349 'show_in_menu' => true,
1350 'query_var' => true,
1351 'rewrite' => array( 'slug' => 'ig_campaign' ),
1352 'capability_type' => 'post',
1353 'has_archive' => false,
1354 'hierarchical' => false,
1355 'menu_position' => null,
1356 'menu_icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-18-white.png',
1357 'supports' => array( 'title', 'editor' )
1358 );
1359
1360 register_post_type( 'ig_campaign', $args );
1361 }
1362
1363 // Register Message post type
1364 function register_message_post_type() {
1365 $labels = array(
1366 'name' => __( 'Messages', 'icegram' ),
1367 'singular_name' => __( 'Message', 'icegram' ),
1368 'add_new' => __( 'Create New', 'icegram' ),
1369 'add_new_item' => __( 'Create New Message', 'icegram' ),
1370 'edit_item' => __( 'Edit Message', 'icegram' ),
1371 'new_item' => __( 'New Message', 'icegram' ),
1372 'all_items' => __( 'Messages', 'icegram' ),
1373 'view_item' => __( 'View Message', 'icegram' ),
1374 'search_items' => __( 'Search Messages', 'icegram' ),
1375 'not_found' => __( 'No messages found', 'icegram' ),
1376 'not_found_in_trash' => __( 'No messages found in Trash', 'icegram' ),
1377 'parent_item_colon' => __( '', 'icegram' ),
1378 'menu_name' => __( 'Messages', 'icegram' )
1379 );
1380
1381 $args = array(
1382 'labels' => $labels,
1383 'public' => false,
1384 'publicly_queryable' => false,
1385 'show_ui' => true,
1386 'show_in_menu' => 'edit.php?post_type=ig_campaign',
1387 'query_var' => true,
1388 'rewrite' => array( 'slug' => 'ig_message' ),
1389 'capability_type' => 'post',
1390 'has_archive' => false,
1391 'hierarchical' => false,
1392 'menu_position' => null,
1393 'supports' => array( 'title' )
1394 );
1395
1396 register_post_type( 'ig_message', $args );
1397 }
1398
1399
1400 function import( $data = array() ) {
1401 if ( empty( $data['campaigns'] ) && empty( $data['messages'] ) ) {
1402 return;
1403 }
1404
1405 $default_theme = $default_type = '';
1406 $first_message_type = current( $this->message_types );
1407
1408 if ( is_array( $first_message_type ) ) {
1409 $default_type = $first_message_type['type'];
1410 if ( ! empty( $first_message_type['themes'] ) ) {
1411 $default_theme = key( $first_message_type['themes'] );
1412 }
1413 }
1414
1415 $new_campaign_ids = array();
1416 foreach ( (array) $data['campaigns'] as $campaign ) {
1417
1418 $args = array(
1419 'post_content' => ( ! empty( $campaign['post_content'] ) ) ? esc_attr( $campaign['post_content'] ) : '',
1420 'post_name' => ( ! empty( $campaign['post_title'] ) ) ? sanitize_title( $campaign['post_title'] ) : '',
1421 'post_title' => ( ! empty( $campaign['post_title'] ) ) ? $campaign['post_title'] : '',
1422 // 'post_status' => ( !empty( $campaign['post_status'] ) ) ? $campaign['post_status'] : 'draft',
1423 'post_status' => 'draft',
1424 'post_type' => 'ig_campaign'
1425 );
1426
1427 $new_campaign_id = wp_insert_post( $args );
1428 $new_campaign_ids[] = $new_campaign_id;
1429
1430 if ( ! empty( $campaign['target_rules'] ) ) {
1431
1432 $defaults = array(
1433 'homepage' => 'yes',
1434 'when' => 'always',
1435 'from' => '',
1436 'to' => '',
1437 'mobile' => 'yes',
1438 'tablet' => 'yes',
1439 'laptop' => 'yes',
1440 'logged_in' => 'all'
1441 );
1442
1443 $target_rules = wp_parse_args( $campaign['target_rules'], $defaults );
1444 update_post_meta( $new_campaign_id, 'icegram_campaign_target_rules', $target_rules );
1445 }
1446
1447 if ( ! empty( $campaign['messages'] ) ) {
1448
1449 $messages = array();
1450
1451 foreach ( $campaign['messages'] as $message ) {
1452
1453 if ( ! is_array( $message ) ) {
1454 continue;
1455 }
1456
1457 $args = array(
1458 'post_content' => ( ! empty( $message['message'] ) ) ? esc_attr( $message['message'] ) : '',
1459 'post_name' => ( ! empty( $message['post_title'] ) ) ? sanitize_title( $message['post_title'] ) : '',
1460 'post_title' => ( ! empty( $message['post_title'] ) ) ? $message['post_title'] : '',
1461 'post_status' => ( ! empty( $message['post_status'] ) ) ? $message['post_status'] : 'publish',
1462 'post_type' => 'ig_message'
1463 );
1464
1465 $new_message_id = wp_insert_post( $args );
1466 $new_message = array(
1467 'id' => $new_message_id,
1468 'time' => ( ! empty( $message['time'] ) ) ? $message['time'] : 0
1469 );
1470 //for gallery + CTA another message
1471 if ( ! empty( $message['cta'] ) && $message['cta'] == 'cta_another_message' && ! empty( $message['cta_linked_message_id'] ) && $message['cta_linked_message_id'] == 'auto' ) {
1472 $prev_message = end( $messages );
1473 $message['cta_linked_message_id'] = $prev_message['id'];
1474 array_pop( $messages );
1475 }
1476 $messages[] = $new_message;
1477
1478 unset( $message['post_content'] );
1479 unset( $message['time'] );
1480
1481 $message['id'] = $new_message_id;
1482
1483 $defaults = array(
1484 'post_title' => '',
1485 'type' => $default_type,
1486 'theme' => $default_theme,
1487 'animation' => '',
1488 'headline' => '',
1489 'label' => '',
1490 'link' => '',
1491 'icon' => '',
1492 'message' => '',
1493 'position' => '',
1494 'text_color' => '#000000',
1495 'bg_color' => '#ffffff',
1496 'custom_code' => '',
1497 'id' => ''
1498 );
1499 $icegram_message_data = wp_parse_args( $message, $defaults );
1500 if ( ! empty( $icegram_message_data ) ) {
1501 update_post_meta( $new_message_id, 'icegram_message_data', $icegram_message_data );
1502 update_post_meta( $new_message_id, 'icegram_message_preview_data', $icegram_message_data );
1503 }
1504 }//foreach
1505
1506 if ( ! empty( $campaign['messages'] ) ) {
1507 update_post_meta( $new_campaign_id, 'messages', $messages );
1508 update_post_meta( $new_campaign_id, 'campaign_preview', $messages );
1509 }
1510 }//if
1511 }
1512
1513 return $new_campaign_ids;
1514
1515 }
1516
1517 function import_gallery_item() {
1518 if ( ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'fetch_messages' && ! empty( $_REQUEST['campaign_id'] ) && ! empty( $_REQUEST['gallery_item'] ) ) {
1519 $url = 'https://www.icegram.com/gallery/wp-admin/admin-ajax.php?utm_source=ig_inapp&utm_campaign=ig_gallery&utm_medium=' . $_REQUEST['campaign_id'];
1520 $params = $_REQUEST;
1521 $imported_gallery_items = array();
1522 $options = array(
1523 'timeout' => 15,
1524 'method' => 'POST',
1525 'body' => http_build_query( $params )
1526 );
1527 $response = wp_remote_request( $url, $options );
1528 $response_code = wp_remote_retrieve_response_code( $response );
1529 if ( $response_code == 200 ) {
1530 $new_campaign_ids = $this->import( json_decode( $response['body'], true ) );
1531 if ( ! empty( $new_campaign_ids ) ) {
1532 $imported_gallery_items = get_option( 'ig_imported_gallery_items' );
1533 $imported_gallery_items[] = $_REQUEST['campaign_id'];
1534 update_option( 'ig_imported_gallery_items', $imported_gallery_items );
1535 $location = admin_url( 'post.php?post=' . $new_campaign_ids[0] . '&action=edit' );
1536 header( 'Location:' . $location );
1537 exit;
1538 } else {
1539 wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
1540 }
1541 }
1542 }
1543 }
1544
1545 function import_sample_data( $data = array() ) {
1546 $new_campaign_ids = $this->import( $data );
1547 if ( ! empty( $new_campaign_ids ) ) {
1548 update_option( 'icegram_sample_data_imported', $new_campaign_ids );
1549 }
1550 }
1551
1552
1553 function get_sample_data() {
1554
1555 return array(
1556 'campaigns' => array(
1557 array(
1558 'post_name' => '',
1559 'post_title' => 'My First Icegram Campaign',
1560 'target_rules' => array(
1561 'homepage' => 'yes',
1562 'when' => 'always',
1563 'from' => '',
1564 'to' => '',
1565 'mobile' => 'yes',
1566 'tablet' => 'yes',
1567 'laptop' => 'yes',
1568 'logged_in' => 'all'
1569 ),
1570 'messages' => array(
1571 array(
1572 'post_title' => 'Get 2x more Contacts with Your Website',
1573 'post_status' => 'publish',
1574 'time' => '0',
1575 'type' => 'action-bar',
1576 'theme' => 'hello',
1577 'headline' => 'Get 2x more Contacts with Your Website',
1578 'label' => 'Show Me How',
1579 'link' => '',
1580 'icon' => '',
1581 'message' => 'Instant Results Guaranteed',
1582 'position' => '01',
1583 'text_color' => '#000000',
1584 'bg_color' => '#eb593c'
1585 ),
1586 array(
1587 'post_title' => '20% Off Coupon',
1588 'post_status' => 'publish',
1589 'time' => '4',
1590 'type' => 'messenger',
1591 'theme' => 'social',
1592 'animation' => 'slide',
1593 'headline' => '20% Off - for you',
1594 'label' => '',
1595 'link' => '',
1596 'icon' => '',
1597 'message' => "Hey there! We are running a <strong>special 20% off this week</strong> for registered users - like you.
1598
1599 Use coupon <code>LOYALTY20</code> during checkout.",
1600 'position' => '22',
1601 'text_color' => '#000000',
1602 'bg_color' => '#ffffff'
1603 ),
1604 array(
1605 'post_title' => 'How this blog makes over $34,800 / month for FREE.',
1606 'post_status' => 'publish',
1607 'time' => '10',
1608 'type' => 'popup',
1609 'theme' => 'air-mail',
1610 'headline' => 'How this blog makes over $34,800 / month for FREE.',
1611 'label' => 'FREE INSTANT ACCESS',
1612 'link' => '',
1613 'icon' => '',
1614 '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.
1615
1616 <strong>Download my free kit to learn how I do this.</strong>
1617
1618 <ul>
1619 <li>How to choose blog topics that create long term value</li>
1620 <li>The type of blog post that will make your site go viral</li>
1621 <li>How to free yourself from the routine tasks</li>
1622 <li>Resources and tips to get started quickly</li>
1623 <li>Private members club to connect with fellow owners</li>
1624 </ul>",
1625 'text_color' => '#000000',
1626 'bg_color' => '#ffffff'
1627
1628 ),
1629 array(
1630 'post_title' => 'Exclusive Marketing Report',
1631 'post_status' => 'publish',
1632 'time' => '6',
1633 'type' => 'toast',
1634 'theme' => 'stand-out',
1635 'animation' => 'pop',
1636 'headline' => 'Exclusive Marketing Report',
1637 'label' => '',
1638 'link' => '',
1639 'icon' => '',
1640 'message' => 'FREE for every subscriber. Click here to download it.',
1641 'position' => '02',
1642 'text_color' => '#000000',
1643 'bg_color' => '#ffffff'
1644 )
1645
1646 )
1647 )
1648 )
1649 );
1650 }
1651
1652 function remove_preview_button() {
1653 global $post_type;
1654 if ( $post_type == 'ig_message' || $post_type == 'ig_campaign' ) {
1655 ?>
1656 <style type="text/css">
1657 #message.updated.below-h2 {
1658 display: none;
1659 }
1660
1661 #preview-action {
1662 display: none;
1663 }
1664
1665 /*Remove add new campaign and message*/
1666 .page-title-action {
1667 display: none;
1668 }
1669 </style>
1670 <?php
1671 }
1672 }
1673
1674
1675 function remove_row_actions( $actions, $post ) {
1676
1677 if ( empty( $post->post_type ) || ( $post->post_type != 'ig_campaign' && $post->post_type != 'ig_message' ) ) {
1678 return $actions;
1679 }
1680
1681 unset( $actions['inline hide-if-no-js'] );
1682 unset( $actions['view'] );
1683
1684 return $actions;
1685
1686 }
1687
1688 function identify_current_page() {
1689 global $post, $wpdb;
1690
1691 $obj = get_queried_object();
1692 $id = 0;
1693 if ( ! empty( $obj->has_archive ) ) {
1694 $sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s ", array( $obj->has_archive, 'page' ) );
1695 $id = $wpdb->get_var( $sql );
1696 } elseif ( is_object( $post ) && isset( $post->ID ) ) {
1697 $id = $post->ID;
1698 }
1699 $id = apply_filters( 'icegram_identify_current_page', $id );
1700 self::$current_page_id = $id;
1701 }
1702
1703 static function get_current_page_id() {
1704 global $post;
1705 if ( ! empty( $_REQUEST['page_id'] ) && is_numeric( $_REQUEST['page_id'] ) ) {
1706 $post = get_post( $_REQUEST['page_id'] );
1707 setup_postdata( $post );
1708 // WPML check
1709 $id = apply_filters( 'icegram_identify_current_page', $post->ID );
1710 self::$current_page_id = $id;
1711 }
1712
1713 return self::$current_page_id;
1714 }
1715
1716 static function get_current_page_url() {
1717 if ( ! empty( $_REQUEST['cache_compatibility'] ) && $_REQUEST['cache_compatibility'] == 'yes' ) {
1718 $pageURL = ( ! empty( $_REQUEST['referral_url'] ) ) ? $_REQUEST['referral_url'] : '';
1719 } else {
1720 $pageURL = 'http';
1721 if ( isset( $_SERVER["HTTPS"] ) ) {
1722 if ( $_SERVER["HTTPS"] == "on" ) {
1723 $pageURL .= "s";
1724 }
1725 }
1726 $pageURL .= "://";
1727 if ( $_SERVER["SERVER_PORT"] != "80" ) {
1728 $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
1729 } else {
1730 $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
1731 }
1732 }
1733
1734 return $pageURL;
1735 }
1736
1737 function wpml_get_parent_id( $id ) {
1738 global $post;
1739 if ( function_exists( 'icl_object_id' ) && function_exists( 'icl_get_default_language' ) ) {
1740 $id = icl_object_id( $id, $post->post_type, true, icl_get_default_language() );
1741 }
1742
1743 return $id;
1744 }
1745
1746
1747 /**
1748 * Our implementation of wpautop to preserve script and style tags
1749 */
1750 function before_wpautop( $pee ) {
1751 if ( trim( $pee ) === '' ) {
1752 $this->_wpautop_tags = array();
1753
1754 return '';
1755 }
1756
1757 $tags = array();
1758 // Pull out tags and add placeholders
1759 list( $pee, $tags['pre'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'pre' );
1760 list( $pee, $tags['script'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'script' );
1761 list( $pee, $tags['style'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'style' );
1762 $this->_wpautop_tags = $tags;
1763
1764 if ( ! empty( $pre_tags ) ) {
1765 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $pre_tags );
1766 }
1767 if ( ! empty( $script_tags ) ) {
1768 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $script_tags );
1769 }
1770 if ( ! empty( $style_tags ) ) {
1771 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $style_tags );
1772 }
1773
1774 return $pee;
1775 }
1776
1777 function after_wpautop( $pee ) {
1778 if ( trim( $pee ) === '' || empty( $this->_wpautop_tags ) ) {
1779 return '';
1780 }
1781
1782 // Replace placeholders with original content
1783 if ( ! empty( $this->_wpautop_tags['pre'] ) ) {
1784 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['pre'] );
1785 }
1786 if ( ! empty( $this->_wpautop_tags['script'] ) ) {
1787 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['script'] );
1788 }
1789 if ( ! empty( $this->_wpautop_tags['style'] ) ) {
1790 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['style'] );
1791 }
1792
1793 $this->_wpautop_tags = array();
1794
1795 return $pee;
1796 }
1797
1798 function _wpautop_add_tag_placeholders( $pee, $tag ) {
1799 $tags = array();
1800
1801 if ( false !== strpos( $pee, "<{$tag}" ) ) {
1802 $pee_parts = explode( "</{$tag}>", $pee );
1803 $last_pee = array_pop( $pee_parts );
1804 $pee = '';
1805 $i = 0;
1806
1807 foreach ( $pee_parts as $pee_part ) {
1808 $start = strpos( $pee_part, "<{$tag}" );
1809
1810 // Malformed html?
1811 if ( false === $start ) {
1812 $pee .= $pee_part;
1813 continue;
1814 }
1815
1816 $name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
1817 $tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
1818
1819 $pee .= substr( $pee_part, 0, $start ) . $name;
1820 $i ++;
1821 }
1822
1823 $pee .= $last_pee;
1824 }
1825
1826 return array( $pee, $tags );
1827 }
1828
1829 function _wpautop_replace_tag_placeholders( $pee, $tags ) {
1830 if ( ! empty( $tags ) ) {
1831 $pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
1832 }
1833
1834 return $pee;
1835 }
1836
1837 static function duplicate_in_db( $original_id ) {
1838 // Get access to the database
1839 global $wpdb;
1840 // Get the post as an array
1841 $duplicate = get_post( $original_id, 'ARRAY_A' );
1842 // Modify some of the elements
1843 $duplicate['post_title'] = $duplicate['post_title'] . ' ' . __( 'Copy', 'icegram' );
1844 $duplicate['post_status'] = 'draft';
1845 // Set the post date
1846 $timestamp = current_time( 'timestamp', 0 );
1847
1848 $duplicate['post_date'] = date( 'Y-m-d H:i:s', $timestamp );
1849
1850 // Remove some of the keys
1851 unset( $duplicate['ID'] );
1852 unset( $duplicate['guid'] );
1853 unset( $duplicate['comment_count'] );
1854
1855 // Insert the post into the database
1856 $duplicate_id = wp_insert_post( $duplicate );
1857
1858 // Duplicate all taxonomies/terms
1859 $taxonomies = get_object_taxonomies( $duplicate['post_type'] );
1860
1861 foreach ( $taxonomies as $taxonomy ) {
1862 $terms = wp_get_post_terms( $original_id, $taxonomy, array( 'fields' => 'names' ) );
1863 wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
1864 }
1865
1866 // Duplicate all custom fields
1867 $custom_fields = get_post_custom( $original_id );
1868 foreach ( $custom_fields as $key => $value ) {
1869 if ( $key === 'messages' ) {
1870 $messages = unserialize( $value[0] );
1871 foreach ( $messages as &$message ) {
1872 $clone_msg_id = Icegram::duplicate_in_db( $message['id'] );
1873 $message['id'] = $clone_msg_id;
1874 }
1875 $value[0] = serialize( $messages );
1876 }
1877 add_post_meta( $duplicate_id, $key, maybe_unserialize( $value[0] ) );
1878 }
1879
1880 return $duplicate_id;
1881 }
1882
1883 static function duplicate( $original_id ) {
1884 $duplicate_id = Icegram::duplicate_in_db( $original_id );
1885 $location = admin_url( 'post.php?post=' . $duplicate_id . '&action=edit' );
1886 header( 'Location:' . $location );
1887 exit;
1888 }
1889
1890 public static function form_submission_validate_request( $request_data ) {
1891 if ( ! empty( $request_data ) ) {
1892 // Check for Remote Rainmaker form submission request
1893 $request_data['ig_is_remote'] = false;
1894 $request_data['is_remote'] = false;
1895 if ( ! empty( $request_data['ig_mode'] ) && $request_data['ig_mode'] === 'remote' ) {
1896 $ig_remote_url = $request_data['ig_remote_url'];
1897 if ( ! empty( $request_data['ig_campaign_id'] ) ) {
1898 $rules = get_post_meta( $request_data['ig_campaign_id'], 'icegram_campaign_target_rules', true );
1899 if ( ! empty( $rules['remote_urls'] ) && is_array( $rules['remote_urls'] ) ) {
1900 foreach ( $rules['remote_urls'] as $remote_url_pattern ) {
1901 $valid = Icegram_Campaign::is_valid_url( $remote_url_pattern, $ig_remote_url );
1902 if ( $valid ) {
1903 $request_data['ig_is_remote'] = true;
1904 $request_data['is_remote'] = true;
1905 break;
1906 }
1907 }
1908 //TODO :: discard the the remote request and data
1909 // if($request_data['ig_is_remote'] == false){
1910 // return array();
1911 // }
1912 }
1913
1914 }
1915 }
1916 }
1917
1918 return $request_data;
1919 }
1920
1921 public static function get_ig_meta_info() {
1922 $total_campaigns = wp_count_posts( 'ig_campaign' );
1923 $total_campaigns_publish = $total_campaigns->publish;
1924 $total_campaigns_draft = $total_campaigns->draft;
1925
1926 $meta_info = array(
1927 'total_campaigns_publish' => $total_campaigns_publish,
1928 'total_campaigns_draft' => $total_campaigns_draft,
1929 );
1930
1931 return $meta_info;
1932 }
1933
1934 /**
1935 * Render Quick Feedback Widget
1936 *
1937 * @param $params
1938 *
1939 * @since 1.10.38
1940 */
1941 public function render_feedback_widget( $params ) {
1942 global $ig_feedback;
1943
1944 $feedback = $ig_feedback;
1945
1946 if ( ! $feedback->can_show_feedback_widget() ) {
1947 return;
1948 }
1949
1950 $default_params = array(
1951 'set_transient' => true,
1952 'force' => false,
1953 'show_once' => false
1954 );
1955
1956 $params = wp_parse_args( $params, $default_params );
1957
1958 if ( ! empty( $params['event'] ) ) {
1959
1960 $event = $feedback->event_prefix . $params['event'];
1961 $force = ! empty( $params['force'] ) ? $params['force'] : false;
1962
1963 $can_show = false;
1964
1965 if ( $force ) {
1966 $can_show = true;
1967 } else {
1968 if ( ! $feedback->is_event_transient_set( $event ) ) {
1969 $can_show = true;
1970
1971 $feedback_data = $feedback->get_event_feedback_data( $feedback->plugin_abbr, $event );
1972 if ( count( $feedback_data ) > 0 ) {
1973 $show_once = $params['show_once'];
1974 $feedback_data = array_reverse( $feedback_data );
1975 $last_feedback_given_on = $feedback_data[0]['created_on'];
1976
1977 // If event feedback given within 45 days or show event only once?
1978 // Don't show now
1979 if ( $show_once || ( strtotime( $last_feedback_given_on ) > strtotime( '-45 days' ) ) ) {
1980 $can_show = false;
1981 }
1982 }
1983 }
1984 }
1985
1986 if ( $can_show ) {
1987 if ( 'star' === $params['type'] ) {
1988 $feedback->render_stars( $params );
1989 } elseif ( 'emoji' === $params['type'] ) {
1990 $feedback->render_emoji( $params );
1991 } elseif ( 'feedback' === $params['type'] ) {
1992 $feedback->render_general_feedback( $params );
1993 } elseif ( 'fb' === $params['type'] ) {
1994 /**
1995 * We are not calling home for this event and we want to show
1996 * this Widget only once. So, we are storing feedback data now.
1997 */
1998 $feedback->set_feedback_data( 'ig', $event );
1999 $feedback->render_fb_widget( $params );
2000 } elseif ( 'poll' === $params['type'] ) {
2001 $feedback->set_feedback_data( 'ig', $event );
2002 $feedback->render_poll_widget( $params );
2003 }
2004 }
2005 }
2006 }
2007
2008 }
2009
2010 function initialize_icegram() {
2011 global $icegram;
2012 // i18n / l10n - load translations
2013 load_plugin_textdomain( 'icegram', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
2014
2015 $icegram = new Icegram();
2016
2017 do_action( 'icegram_loaded' );
2018 }
2019
2020 add_action( 'plugins_loaded', 'initialize_icegram' );
2021 register_activation_hook( __FILE__, array( 'Icegram', 'install' ) );