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

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