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

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