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

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