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

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