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

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