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

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