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

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