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

1,271 lines 58.8 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.5
7 * Author: Icegram
8 * Author URI: http://www.icegram.com/
9 *
10 * Copyright (c) 2014 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
32 public static $current_page_id;
33
34 function __construct() {
35
36 $this->version = "1.5";
37 $this->shortcode_instances = array();
38 $this->plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
39 $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
40 $this->include_classes();
41
42 if( is_admin() && current_user_can( 'manage_options' ) ) {
43 new Icegram_Campaign_Admin();
44 $ig_message_admin = Icegram_Message_Admin::getInstance();
45 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_admin_styles_and_scripts' ) );
46 add_action( 'admin_print_styles', array( &$this, 'remove_preview_button' ) );
47 add_filter( 'post_row_actions', array( &$this , 'remove_row_actions' ), 10, 2 );
48
49 add_action( 'admin_menu', array( &$this, 'admin_menus') );
50 add_action( 'admin_init', array( &$this, 'welcome' ) );
51
52 add_action( 'icegram_settings_after', array( &$this, 'klawoo_subscribe_form' ) );
53 add_action( 'icegram_about_changelog', array( &$this, 'klawoo_subscribe_form' ) );
54 add_action( 'icegram_settings_after', array( &$this, 'icegram_houskeeping' ) );
55 } else {
56 add_action( 'wp_footer', array( &$this, 'display_messages' ) );
57 //add_action( 'wp_head', array( &$this, 'nofollow_noindex' ) );
58 add_action( 'wp_print_scripts', array( &$this, 'identify_current_page' ) );
59 add_shortcode( 'icegram', array( &$this, 'execute_shortcode' ) );
60 add_filter( 'icegram_branding_data', array( &$this , 'branding_data_remove' ), 10 );
61 add_filter( 'icegram_get_valid_campaigns_sql', array( &$this , 'append_to_valid_campaigns_sql' ), 10, 2 );
62 // WPML compatibility
63 add_filter( 'icegram_identify_current_page', array( &$this, 'wpml_get_parent_id' ), 10 );
64 }
65
66 // common
67 add_action( 'init', array( &$this, 'register_campaign_post_type' ) );
68 add_action( 'init', array( &$this, 'register_message_post_type' ) );
69
70 if ( defined( 'DOING_AJAX' ) ) {
71 add_action( 'wp_ajax_icegram_event_track', array( &$this, 'icegram_event_track' ) );
72 add_action( 'wp_ajax_nopriv_icegram_event_track', array( &$this, 'icegram_event_track' ) );
73 add_action( 'wp_ajax_klawoo_subscribe', array( &$this, 'klawoo_subscribe' ) );
74 add_action( 'wp_ajax_icegram_run_housekeeping', array( &$this, 'run_housekeeping' ) );
75 }
76
77 }
78
79 public function klawoo_subscribe_form() {
80 ?>
81 <div class="wrap">
82 <?php
83 if ( stripos(get_current_screen()->base, 'settings') !== false ) {
84 echo "<h2>".__( 'Free Add-ons, Proven Marketing Tricks and Updates', 'icegram' )."</h2>";
85 }
86 ?>
87 <table class="form-table">
88 <tr>
89 <th scope="row"><?php _e( 'Get add-ons and tips...', 'icegram' ) ?></th>
90 <td>
91 <form name="klawoo_subscribe" action="#" method="POST" accept-charset="utf-8">
92 <input class="ltr" type="text" name="name" id="name" placeholder="Name"/>
93 <input class="regular-text ltr" type="text" name="email" id="email" placeholder="Email"/>
94 <input type="hidden" name="list" value="7I763v6Ldrs3YhJeee5EOgFA"/>
95 <input type="submit" name="submit" id="submit" class="button button-primary" value="Subscribe">
96 <br/>
97 <div id="klawoo_response"></div>
98 </form>
99 </td>
100 </tr>
101 </table>
102 </div>
103 <script type="text/javascript">
104 jQuery(function () {
105 jQuery("form[name=klawoo_subscribe]").submit(function (e) {
106 e.preventDefault();
107
108 jQuery('#klawoo_response').html('');
109 params = jQuery("form[name=klawoo_subscribe]").serializeArray();
110 params.push( {name: 'action', value: 'klawoo_subscribe' });
111
112 jQuery.ajax({
113 method: 'POST',
114 type: 'text',
115 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
116 data: params,
117 success: function(response) {
118 if (response != '') {
119 jQuery('#klawoo_response').html(response);
120 } else {
121 jQuery('#klawoo_response').html('error!');
122 }
123 }
124 });
125 });
126 });
127 </script>
128 <?php
129 }
130
131
132 public function klawoo_subscribe() {
133 $url = 'http://app.klawoo.com/subscribe';
134
135 if( !empty( $_POST ) ) {
136 $params = $_POST;
137 } else {
138 exit();
139 }
140 $method = 'POST';
141 $qs = http_build_query( $params );
142
143 $options = array(
144 'timeout' => 15,
145 'method' => $method
146 );
147
148 if ( $method == 'POST' ) {
149 $options['body'] = $qs;
150 } else {
151 if ( strpos( $url, '?' ) !== false ) {
152 $url .= '&'.$qs;
153 } else {
154 $url .= '?'.$qs;
155 }
156 }
157
158 $response = wp_remote_request( $url, $options );
159 if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
160 $data = $response['body'];
161 if ( $data != 'error' ) {
162
163 $message_start = substr( $data, strpos( $data,'<body>' ) + 6 );
164 $remove = substr( $message_start, strpos( $message_start,'</body>' ) );
165 $message = trim( str_replace( $remove, '', $message_start ) );
166 echo ( $message );
167 exit();
168 }
169 }
170 exit();
171 }
172
173 public function icegram_houskeeping(){
174 ?>
175 <div class="wrap">
176 <?php
177 if ( stripos(get_current_screen()->base, 'settings') !== false ) {
178 ?>
179 <form name="icegram_housekeeping" action="#" method="POST" accept-charset="utf-8">
180 <h2><?php _e( 'Housekeeping', 'icegram' ) ?></h2>
181 <p class="ig_housekeeping">
182 <label for="icegram_remove_shortcodes">
183 <input type="checkbox" name="icegram_remove_shortcodes" value="yes" />
184 <?php _e( 'Remove all Icegram shortcodes', 'icegram' ); ?>
185 </label>
186 <br/><br/>
187 <label for="icegram_remove_all_data">
188 <input type="checkbox" name="icegram_remove_all_data" value="yes" />
189 <?php _e( 'Remove all Icegram campaigns and messages', 'icegram' ); ?>
190 </label>
191 <br/><br/>
192 <img alt="" src="<?php echo admin_url( 'images/wpspin_light.gif' ) ?>" class="ig_loader" style="vertical-align:middle;display:none" />
193 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Clean Up', 'icegram' ); ?>">
194 <div id="icegram_housekeeping_response"></div>
195 </p>
196 </form>
197
198 </div>
199 <script type="text/javascript">
200 jQuery(function () {
201 jQuery("form[name=icegram_housekeeping]").submit(function (e) {
202 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){
203 e.preventDefault();
204 jQuery('.ig_loader').show();
205 jQuery('#icegram_housekeeping_response').text("");
206 params = jQuery("form[name=icegram_housekeeping]").serializeArray();
207 params.push( {name: 'action', value: 'icegram_run_housekeeping' });
208
209 jQuery.ajax({
210 method: 'POST',
211 type: 'text',
212 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
213 data: params,
214 success: function(response) {
215 jQuery('.ig_loader').hide();
216 jQuery('#icegram_housekeeping_response').text("<?php _e('Done!', 'icegram'); ?>");
217 }
218 });
219 }
220 });
221 });
222 </script>
223 <?php
224 }
225 }
226 public function run_housekeeping() {
227 global $wpdb;
228 $params = $_POST;
229 $_POST = array();
230
231 if(!empty($params['icegram_remove_shortcodes']) && $params['icegram_remove_shortcodes'] == 'yes') {
232 // first get all posts with [icegram] shortcode in them
233 $sql = "SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE '%[icegram %]%' and `post_type` != 'revision' ";
234 $posts = $wpdb->get_results($sql, OBJECT);
235 if ( !empty($posts) && is_array($posts) ) {
236 foreach ($posts as $post) {
237 $post_content = $post->post_content;
238 // remove shortcode with regexp now
239 $re = "/\\[icegram(.)*\\]/i";
240 $post_content = preg_replace($re, '', $post_content);
241 // save post content back
242 if ($post_content && $post_content != $post->post_content) {
243 wp_update_post( array ( 'ID' => $post->ID,
244 'post_content' => $post_content
245 ) );
246 }
247 }
248 }
249 }
250
251 if(!empty($params['icegram_remove_all_data']) && $params['icegram_remove_all_data'] == 'yes') {
252 $posts = get_posts( array( 'post_type' => array( 'ig_campaign', 'ig_message' ) ) );
253 if ( !empty($posts) && is_array($posts) ) {
254 foreach ($posts as $post) {
255 wp_delete_post( $post->ID, true);
256 }
257 }
258 do_action('icegram_remove_all_data');
259 }
260 $_POST = $params;
261 }
262
263 public function icegram_event_track() {
264 if( !empty( $_POST['event_data'] ) ) {
265
266 foreach ( $_POST['event_data'] as $event ) {
267 switch ($event['type']) {
268 case 'shown':
269 if (is_array($event['params']) && !empty($event['params']['message_id'])) {
270 $messages_shown[] = $event['params']['message_id'];
271 if(!empty($event['params']['expiry_time'])){
272 if($event['params']['expiry_time'] =='today'){
273 $event['params']['expiry_time'] = strtotime('+1 day', mktime(0, 0, 0));
274 }else if($event['params']['expiry_time'] == 'current_session'){
275 $event['params']['expiry_time'] = 0;
276 }else{
277 $event['params']['expiry_time'] = strtotime($event['params']['expiry_time']);
278 }
279 setcookie('icegram_messages_shown_'.$event['params']['message_id'],true , $event['params']['expiry_time'] , '/');
280 }
281 }
282 break;
283
284 default:
285 break;
286 }
287
288 // Emit event for other plugins to handle it
289 do_action('icegram_event_track', $event);
290 do_action('icegram_event_track_'.$event['type'], $event['params']);
291 }
292 }
293 exit();
294 }
295
296 static function install() {
297 // Redirect to welcome screen
298 delete_option( '_icegram_activation_redirect' );
299 add_option( '_icegram_activation_redirect', 'pending' );
300 }
301
302 public function welcome() {
303
304 $this->db_update();
305 // Bail if no activation redirect transient is set
306 if ( false === get_option( '_icegram_activation_redirect' ) )
307 return;
308
309 // Delete the redirect transient
310 delete_option( '_icegram_activation_redirect' );
311
312 wp_redirect( admin_url( 'edit.php?post_type=ig_campaign&page=icegram-support' ) );
313 exit;
314 }
315
316 function db_update() {
317 $current_db_version = get_option( 'icegram_db_version' );
318 if ( !$current_db_version || version_compare( $current_db_version, '1.2', '<' ) ) {
319 include( 'updates/icegram-update-1.2.php' );
320 }
321 }
322
323 public function admin_menus() {
324
325 $welcome_page_title = __( 'Welcome to Icegram', 'icegram' );
326 $settings_page_title = __( 'Settings', 'icegram' );
327 $addons_page_title = __( 'Add-ons', 'icegram' );
328
329 /*
330 if ( false === ( $ig_addons = get_transient( 'icegram_addons_data' ) ) ) {
331 $this->check_for_addons();
332 }
333 $addon_count = get_option( 'icegram_no_of_addons' );
334
335 if ($addon_count > 0) {
336 $addons_page_title .= " <span class='awaiting-mod update-plugins count-$addon_count'><span class='addon-count'>" . number_format_i18n( $addon_count ) . "</span></span>" ;
337 }
338 */
339
340 $menu_title = __( 'Docs & Support', 'icegram' );
341 $about = add_submenu_page( 'edit.php?post_type=ig_campaign', $welcome_page_title, $menu_title, 'manage_options', 'icegram-support', array( $this, 'about_screen' ) );
342 $settings = add_submenu_page( 'edit.php?post_type=ig_campaign', $settings_page_title, $settings_page_title, 'manage_options', 'icegram-settings', array( $this, 'settings_screen' ) );
343 $addons = add_submenu_page( 'edit.php?post_type=ig_campaign', $addons_page_title, $addons_page_title, 'manage_options', 'icegram-addons', array( $this, 'addons_screen' ) );
344
345 add_action( 'admin_print_styles-'. $about, array( $this, 'admin_css' ) );
346 add_action( 'admin_print_styles-'. $settings, array( $this, 'admin_css' ) );
347 add_action( 'admin_print_styles-'. $addons, array( $this, 'admin_css' ) );
348
349 }
350
351 public function admin_css() {
352 wp_enqueue_style( 'icegram-activation', $this->plugin_url . '/assets/css/admin.css' );
353 }
354
355 public function about_screen() {
356
357 // Import data if not done already
358 if( false === get_option( 'icegram_sample_data_imported' ) ) {
359 $this->import( $this->get_sample_data() );
360 }
361
362 include ( 'about-icegram.php' );
363 }
364
365 public function settings_screen() {
366 include ( 'settings.php' );
367 }
368
369 public function addons_screen() {
370 $ig_addons = $this->check_for_addons( true );
371 include ( 'addons.php' );
372 }
373
374 public function check_for_addons( $force_update = false ) {
375
376 if ( $force_update === true || false === ( $ig_addons = get_transient( 'icegram_addons_data' ) ) ) {
377 $ig_addons_json = wp_remote_get( 'http://icegram.com/addons.json', array( 'user-agent' => 'Icegram Addons' ) );
378
379 if ( ! is_wp_error( $ig_addons_json ) ) {
380 $ig_addons = json_decode( wp_remote_retrieve_body( $ig_addons_json ) );
381 $addon_count = get_option( 'icegram_no_of_addons', 0 );
382 if ( !empty($ig_addons) && is_array($ig_addons) ) {
383 set_transient( 'icegram_addons_data', $ig_addons, 24 * HOUR_IN_SECONDS ); // 1 day
384 update_option( 'icegram_no_of_addons', count( $ig_addons ) - $addon_count ); // display count of newly added addons
385 }
386 }
387 }
388 return $ig_addons;
389 }
390
391 public function branding_data_remove( $icegram_branding_data ) {
392 if( !empty( $icegram_branding_data ) && 'yes' != get_option('icegram_share_love', 'no') ) {
393 $icegram_branding_data['powered_by_logo'] = '';
394 $icegram_branding_data['powered_by_text'] = '';
395 }
396 return $icegram_branding_data;
397 }
398
399 function execute_shortcode( $atts = array() ) {
400 // When shortcode is called, it will only prepare an array with conditions
401 // And add a placeholder div
402 // Display will happen in footer via display_messages()
403 $i = count($this->shortcode_instances);
404 $this->shortcode_instances[ $i ] = shortcode_atts( array(
405 'campaigns' => '',
406 'messages' => '',
407 'skip_others' => 'no'
408 ), $atts );
409 $html[] = "<div class='ig_shortcode_container' id='icegram_shortcode_{$i}'";
410 foreach ($atts as $key => $value) {
411 $value = str_replace(",", " ", $value);
412 $html[] = " data-{$key}=\"".htmlentities($value)."\" ";
413 }
414 $html[] = " >"."</div>";
415 return implode(" ", $html);
416 }
417
418 // Do not index Icegram campaigns / messages...
419 // Not using currently - made custom post types non public...
420 function nofollow_noindex() {
421 $post = get_queried_object();
422 if ( (!empty($post) && !empty( $post->post_type ) && ( $post->post_type == 'ig_campaign' || $post->post_type == 'ig_message' ))
423 || is_post_type_archive( array('ig_message', 'ig_campaign') ) ) {
424 echo PHP_EOL . '<meta name="robots" content="NOINDEX,NOFOLLOW" />' . PHP_EOL;
425 }
426 }
427
428 function display_messages() {
429
430 $skip_others = $preview_mode = false;
431 $campaign_ids = $message_ids = array();
432
433 // Pull in message and campaign IDs from shortcodes - if set
434 if( !empty( $this->shortcode_instances ) ) {
435 foreach ($this->shortcode_instances as $i => $value) {
436 $cids = array_map( 'trim', (array) explode( ',', $value['campaigns'] ) );
437 $mids = array_map( 'trim', (array) explode( ',', $value['messages'] ) );
438 if ($value['skip_others'] == 'yes' && (!empty($cids) || !empty($mids))) {
439 $skip_others = true;
440 }
441 $campaign_ids = array_merge($campaign_ids, $cids);
442 $message_ids = array_merge($message_ids, $mids);
443 }
444 }
445
446 if( !empty( $_GET['campaign_preview_id'] ) && current_user_can( 'manage_options' ) ) {
447 $campaign_ids = array( $_GET['campaign_preview_id'] );
448 $preview_mode = true;
449 }
450
451 $messages = $this->get_valid_messages( $message_ids, $campaign_ids, $preview_mode, $skip_others );
452
453 if( empty( $messages ) ) {
454 return;
455 }
456
457 $types_shown = array(); $messages_to_show_ids = array();
458 foreach ( $messages as $key => $message_data ) {
459
460 if( !is_array( $message_data ) || empty( $message_data ) ) {
461 continue;
462 }
463 // Don't show a seen message again - if needed
464 if( !empty( $message_data['id'] ) &&
465 empty( $_GET['campaign_preview_id'] ) &&
466 !empty($_COOKIE['icegram_messages_shown_'.$message_data['id']])&&
467 !empty( $message_data['retargeting'] ) &&
468 $message_data['retargeting'] == 'yes'
469 ) {
470 unset( $messages[$key] );
471 continue;
472 }
473
474 // Avoid showing the same message twice
475 if (in_array($message_data['id'], $messages_to_show_ids)) {
476 unset ( $messages[$key] );
477 continue;
478 } else {
479 $messages_to_show_ids[] = $message_data['id'];
480 }
481
482
483 /*
484 // Our own implementation so WP does not mess with script, style and pre tags
485 add_filter('the_content', array( $this, 'before_wpautop' ) , 9);
486 add_filter('the_content', array( $this, 'after_wpautop' ) , 11);
487 $messages[$key]['message'] = apply_filters( 'the_content', $message_data['message'] );
488 remove_filter('the_content', array( $this, 'before_wpautop' ) , 9);
489 remove_filter('the_content', array( $this, 'after_wpautop' ) , 11);
490 */
491 // Redo the_content functionality to avoid other plugins adding extraneous code to messages
492 $content = $message_data['message'];
493 $content = convert_chars( convert_smilies( wptexturize( $content ) ) );
494 if(isset($GLOBALS['wp_embed'])) {
495 $content = $GLOBALS['wp_embed']->autoembed($content);
496 }
497 $content = $this->after_wpautop( wpautop( $this->before_wpautop( $content ) ) );
498 $content = do_shortcode( shortcode_unautop( $content ) );
499 $messages[$key]['message'] = $content;
500
501 }
502
503 if( empty( $messages ) )
504 return;
505
506 wp_register_script( 'icegram_js', $this->plugin_url . '/assets/js/icegram.js', array ( 'jquery' ), '', true);
507 wp_enqueue_style( 'icegram_css', $this->plugin_url . '/assets/css/frontend.css' );
508 wp_enqueue_style( 'dashicons' );
509
510 $icegram_default = apply_filters( 'icegram_branding_data',
511 array ( 'icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
512 'powered_by_logo' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
513 'powered_by_text' => __( 'Powered by Icegram', 'icegram' )
514 ) );
515 $messages = apply_filters( 'icegram_messages_to_show', $messages );
516 $icegram = apply_filters( 'icegram_data', array ( 'messages' => array_values( $messages ),
517 'ajax_url' => admin_url( 'admin-ajax.php' ),
518 'preview_id' => !empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '',
519 'defaults' => $icegram_default
520 ));
521 foreach ($icegram['messages'] as $key => $message_data) {
522 $types_shown[] = $message_data['type'];
523 }
524 if (empty($icegram['preview_id'])) {
525 unset($icegram['preview_id']);
526 }
527
528 if( !wp_script_is( 'icegram_js' ) ) {
529 wp_enqueue_script( 'icegram_js' );
530 wp_localize_script( 'icegram_js', 'icegram_data', $icegram );
531 }
532
533 // Load JS and default CSS
534 $types_shown = array_unique($types_shown);
535
536 if (in_array('popup', $types_shown)) {
537 wp_enqueue_script( 'thickbox' );
538 wp_enqueue_style( 'thickbox' );
539 }
540
541 foreach ($types_shown as $message_type) {
542 wp_register_script( 'icegram_message_type_'.$message_type, $this->message_types[$message_type]['baseurl'] . "main.js" , array ( 'icegram_js' ), '', true );
543 wp_enqueue_script( 'icegram_message_type_'.$message_type );
544 wp_enqueue_style( 'icegram_css_'.$message_type, $this->message_types[$message_type]['baseurl'] . 'default.css' );
545 }
546
547 // Load theme CSS
548 foreach ($messages as $message) {
549 if (!empty( $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ]) ) {
550 $theme = $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ];
551 wp_enqueue_style( 'icegram_css_'.$message['type'].'_'.$message['theme'], $theme['baseurl'] . $message['theme'].'.css' );
552 }
553 }
554
555 }
556
557 function enqueue_admin_styles_and_scripts() {
558
559 $screen = get_current_screen();
560 if ( !in_array( $screen->id, array( 'ig_campaign', 'ig_message' ), true ) ) return;
561
562 // Register scripts
563 wp_register_script( 'icegram_writepanel', $this->plugin_url . '/assets/js/admin.js' , array ( 'jquery', 'wp-color-picker' ) );
564 wp_register_script( 'icegram_chosen', $this->plugin_url . '/assets/js/chosen.jquery.min.js' , array ( 'jquery' ), '1.0' );
565 wp_register_script( 'icegram_ajax-chosen', $this->plugin_url . '/assets/js/ajax-chosen.jquery.min.js' , array ( 'icegram_chosen' ), '1.0' );
566 wp_register_script( 'icegram_tiptip', $this->plugin_url . '/assets/js/jquery.tipTip.min.js' , array ( 'jquery' ), get_bloginfo( 'version' ) );
567
568 wp_enqueue_script( 'icegram_writepanel' );
569 wp_enqueue_script( 'icegram_ajax-chosen' );
570 wp_enqueue_script( 'icegram_tiptip' );
571 wp_enqueue_script( 'thickbox' );
572
573 $icegram_writepanel_params = array ( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'search_message_nonce' => wp_create_nonce( "search-messages" ) );
574 $this->available_headlines = apply_filters( 'icegram_available_headlines', array() );
575 $icegram_writepanel_params = array_merge( $icegram_writepanel_params, array( 'available_headlines' => $this->available_headlines ) );
576
577 wp_localize_script( 'icegram_writepanel', 'icegram_writepanel_params', $icegram_writepanel_params );
578
579 wp_enqueue_style( 'thickbox' );
580 wp_enqueue_style( 'dashicons' );
581 wp_enqueue_style( 'wp-color-picker' );
582 wp_enqueue_style( 'icegram_admin_styles', $this->plugin_url . '/assets/css/admin.css' );
583 wp_enqueue_style( 'icegram_jquery-ui-style', $this->plugin_url . '/assets/css/jquery-ui.min.css' );
584 wp_enqueue_style( 'icegram_chosen_styles', $this->plugin_url . '/assets/css/chosen.min.css' );
585
586 if ( !wp_script_is( 'jquery-ui-datepicker' ) ) {
587 wp_enqueue_script( 'jquery-ui-datepicker' );
588 }
589
590 }
591
592 public static function get_platform() {
593 $platform = '';
594 $user_agent = trim(strtolower($_SERVER['HTTP_USER_AGENT']));
595 $pattern = '/(android\s\d|blackberry|ip(hone|ad|od)|iemobile|webos|palm|symbian|kindle|windows|win64|wow64|macintosh|intel\smac\sos\sx|ppx\smac\sos\sx|googlebot|googlebot-mobile)/';
596 if ( preg_match( $pattern, $user_agent, $matches ) ) {
597 $platform = $matches[0];
598 }
599
600 switch ( $platform ) {
601
602 /* phones / smartphones */
603 case 'android 1':
604 case 'android 2':
605 case 'blackberry':
606 case 'iphone':
607 case 'ipod':
608 case 'iemobile':
609 case 'webos':
610 case 'palm':
611 case 'symbian':
612 case 'googlebot-mobile':
613 $platform = 'mobile';
614 break;
615
616 /* tablets */
617 case 'android 3':
618 case 'android 4':
619 case 'ipad':
620 case 'kindle':
621 $platform = 'tablet';
622 break;
623
624 /* desktops / laptops */
625 case 'windows':
626 case 'win64':
627 case 'wow64':
628 case 'macintosh':
629 case 'ppx mac os x':
630 case 'intel mac os x':
631 case 'googlebot':
632 $platform = 'laptop';
633 break;
634
635 /* in case nothing else matches */
636 default:
637 $platform = 'laptop';
638 break;
639 }
640 return $platform;
641 }
642
643 function get_message_data( $message_ids = array(), $preview = false ) {
644 global $wpdb;
645
646 $message_data = array();
647 $original_message_id_map = array();
648 $meta_key = $preview ? 'icegram_message_preview_data' : 'icegram_message_data';
649 $message_data_query = "SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE '$meta_key'";
650 if ( !empty( $message_ids ) && is_array( $message_ids ) ) {
651 // For WPML compatibility
652 if ( function_exists('icl_object_id') ) {
653 $wpml_settings = get_option('icl_sitepress_settings');
654 $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;
655 foreach ($message_ids as $i=>$id ) {
656 $translated = icl_object_id( $id, 'ig_message', $original_if_missing );
657 $message_ids[ $i ] = $translated;
658 $original_message_id_map[ $translated ] = $id;
659 }
660 }
661 $message_ids = array_filter(array_unique($message_ids));
662 if ( !empty( $message_ids ) ) {
663 $message_data_query .= " AND post_id IN ( " . implode( ',', $message_ids ) . " )";
664 $message_data_results = $wpdb->get_results( $message_data_query, 'ARRAY_A' );
665 foreach ( $message_data_results as $message_data_result ) {
666 $message_data[$message_data_result['post_id']] = maybe_unserialize( $message_data_result['meta_value'] );
667 // For WPML compatibility
668 if (!empty( $original_message_id_map[ $message_data_result['post_id'] ])) {
669 $message_data[$message_data_result['post_id']]['original_message_id'] = $original_message_id_map[ $message_data_result['post_id'] ];
670 }
671 }
672 }
673 }
674 return $message_data;
675 }
676
677 function get_valid_messages( $message_ids = array(), $campaign_ids = array(), $preview_mode = false, $skip_others = false) {
678
679 $valid_messages = $valid_campaigns = $message_campaign_map = array();
680
681 $campaign_ids = array_filter(array_unique($campaign_ids));
682 $message_ids = array_filter(array_unique($message_ids));
683
684 if ( !empty( $campaign_ids ) ) {
685 $valid_campaigns = $this->get_valid_campaigns( $campaign_ids, true );
686 }
687 // When skip_others is true, we won't load campaigns / messages from db
688 if (!$skip_others && !$preview_mode) {
689 $campaigns = $this->get_valid_campaigns();
690 if (!empty($campaigns)) {
691 foreach ($campaigns as $id => $campaign) {
692 if (!array_key_exists($id, $valid_campaigns)) {
693 $valid_campaigns[ $id ] = $campaign;
694 }
695 }
696 }
697 }
698 // Create a map to look up campaign id for a given message
699 if( !empty( $valid_campaigns ) ) {
700 foreach ($valid_campaigns as $id => $campaign) {
701 if ($preview_mode) {
702 $campaign->messages = get_post_meta( $id, 'campaign_preview', true );
703 }
704
705 foreach( $campaign->messages as $msg) {
706 $message_ids[] = $msg['id'];
707 if (!array_key_exists( $msg['id'], $message_campaign_map)) {
708 $message_campaign_map[ $msg['id'] ] = $id;
709 }
710 }
711 }
712 }
713
714 // We don't display same message twice...
715 $message_ids = array_unique($message_ids);
716
717 if( empty( $message_ids ) ) {
718 return array();
719 }
720 $valid_messages = $this->get_message_data( $message_ids, $preview_mode );
721
722 foreach ($valid_messages as $id => $message_data) {
723 // Remove message if message type is uninstalled
724 $class_name = 'Icegram_Message_Type_' . str_replace(' ', '_', ucwords(str_replace('-', ' ', $message_data['type'])));
725 if( !class_exists( $class_name ) ) {
726 unset( $valid_messages[$id] );
727 continue;
728 }
729 $message_data['delay_time'] = 0;
730 $message_data['retargeting'] = '';
731 $message_data['campaign_id'] = ($preview_mode) ? $_GET['campaign_preview_id'] : '';
732
733 // Pull display time and retargeting rule from campaign if possible
734 $message_id = (!empty($message_data['original_message_id'])) ? $message_data['original_message_id'] : $id;
735 if (!empty($message_campaign_map[ $message_id ])) {
736 $message_data['campaign_id'] = $message_campaign_map[ $message_id ];
737 $campaign = $valid_campaigns[ $message_data['campaign_id'] ];
738 if (!empty($campaign) && $campaign instanceof Icegram_Campaign) {
739 $message_meta_from_campaign = $campaign->get_message_meta_by_id( $message_id );
740 if (!empty($message_meta_from_campaign['time'])) {
741 $message_data['delay_time'] = $message_meta_from_campaign['time'];
742 }
743 $rule_value = $campaign->get_rule_value('retargeting');
744 $message_data['retargeting'] = !empty( $rule_value['retargeting'] ) ? $rule_value['retargeting'] : '';
745 $message_data['expiry_time'] = !empty( $rule_value['retargeting'] ) ? $rule_value['expiry_time'] : '';
746 }
747 }
748 $valid_messages[$id] = $message_data;
749 }
750
751 $valid_messages = apply_filters( 'icegram_valid_messages', $valid_messages );
752 return $valid_messages;
753 }
754
755 function get_valid_campaigns( $campaign_ids = array(), $skip_page_check = false ) {
756 global $wpdb;
757
758 if ( empty( $campaign_ids ) ) {
759 $sql = "SELECT pm.post_id
760 FROM {$wpdb->prefix}posts AS p
761 LEFT JOIN {$wpdb->prefix}postmeta AS pm ON ( pm.post_id = p.ID )
762 WHERE p.post_status = 'publish' ";
763 // Filter handler within this file (and possibly others) will append to this SQL
764 // and provide arguments for wpdb->prepare if needed.
765 // First element in the array is SQL, remaining are values for placeholders in SQL
766 $sql_params = apply_filters( 'icegram_get_valid_campaigns_sql', array($sql), array() );
767 $campaign_ids = $wpdb->get_col( $wpdb->prepare( array_shift($sql_params), $sql_params ) );
768 }
769 $valid_campaigns = array();
770 foreach ( (array) $campaign_ids as $campaign_id ) {
771 $campaign = new Icegram_Campaign( $campaign_id );
772 if ( $campaign->is_valid( array('skip_page_check' => $skip_page_check) ) ) {
773 $valid_campaigns[$campaign_id] = $campaign;
774 } else {
775 // Campgain is invalid!
776 }
777 }
778 return $valid_campaigns;
779 }
780
781 function append_to_valid_campaigns_sql( $sql_params = array(), $options = array() ) {
782
783 // Page check conditions
784 $pid = Icegram::get_current_page_id();
785 $sql = " AND (
786 pm.meta_key = 'icegram_campaign_target_rules' AND (
787 ( pm.meta_value LIKE '%%%s%%' )
788 OR ( pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' )
789 ";
790 $sql_params[] = 's:8:"sitewide";s:3:"yes";';
791 $sql_params[] = 's:10:"other_page";s:3:"yes";';
792 $sql_params[] = 's:7:"page_id";a:';
793 $sql_params[] = serialize( (string) $pid );
794
795 if (is_home() || is_front_page()) {
796 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )
797 ";
798 $sql_params[] = 's:8:"homepage";s:3:"yes";';
799 }
800 $sql .=" ) )";
801 $sql_params[0] .= $sql;
802
803 //s:9:"logged_in";s:3:"all";
804
805 return $sql_params;
806 }
807
808 // Include all classes required for Icegram plugin
809 function include_classes() {
810
811 $classes = glob( $this->plugin_path . '/classes/*.php' );
812 foreach ( $classes as $file ) {
813 // Files with 'admin' in their name are included only for admin section
814 if ( is_file( $file ) && ( (strpos($file, '-admin') >= 0 && is_admin()) || (strpos($file, '-admin') === false) ) ) {
815 include_once $file;
816 }
817 }
818
819 // Load built in message types
820 $icegram_message_type_basedirs = glob( $this->plugin_path . '/message-types/*' );
821 // Allow other plugins to add new message types
822 $icegram_message_type_basedirs = apply_filters( 'icegram_message_type_basedirs', $icegram_message_type_basedirs );
823 // Set up different message type classes
824 foreach ( $icegram_message_type_basedirs as $dir ) {
825 $type = basename ( $dir );
826 $class_file = $dir . "/main.php";
827 if( is_file( $class_file ) ) {
828 include_once( $class_file );
829 }
830 $class_name = 'Icegram_Message_Type_' . str_replace(' ', '_', ucwords(str_replace('-', ' ', $type)));
831 if (class_exists($class_name)) {
832 $this->message_type_objs[ $type ] = new $class_name();
833 }
834 }
835 $this->message_types = apply_filters( 'icegram_message_types', array() );
836
837 }
838
839 // Register Campaign post type
840 function register_campaign_post_type() {
841 $labels = array(
842 'name' => __( 'Campaigns', 'icegram' ),
843 'singular_name' => __( 'Campaign', 'icegram' ),
844 'add_new' => __( 'Add New Campaign', 'icegram' ),
845 'add_new_item' => __( 'Add New Campaign', 'icegram' ),
846 'edit_item' => __( 'Edit Campaign', 'icegram' ),
847 'new_item' => __( 'New Campaign', 'icegram' ),
848 'all_items' => __( 'Campaigns', 'icegram' ),
849 'view_item' => __( 'View Campaign', 'icegram' ),
850 'search_items' => __( 'Search Campaigns', 'icegram' ),
851 'not_found' => __( 'No campaigns found', 'icegram' ),
852 'not_found_in_trash' => __( 'No campaigns found in Trash', 'icegram' ),
853 'parent_item_colon' => __( '', 'icegram' ),
854 'menu_name' => __( 'Icegram', 'icegram' )
855 );
856
857 $args = array(
858 'labels' => $labels,
859 'menu_icon' => 'dashicons-info',
860 'public' => false,
861 'publicly_queryable' => false,
862 'show_ui' => true,
863 'show_in_menu' => true,
864 'query_var' => true,
865 'rewrite' => array( 'slug' => 'ig_campaign' ),
866 'capability_type' => 'post',
867 'has_archive' => false,
868 'hierarchical' => false,
869 'menu_position' => null,
870 'supports' => array( 'title', 'editor' )
871 );
872
873 register_post_type( 'ig_campaign', $args );
874 }
875
876 // Register Message post type
877 function register_message_post_type() {
878 $labels = array(
879 'name' => __( 'Messages', 'icegram' ),
880 'singular_name' => __( 'Message', 'icegram' ),
881 'add_new' => __( 'Create New', 'icegram' ),
882 'add_new_item' => __( 'Create New Message', 'icegram' ),
883 'edit_item' => __( 'Edit Message', 'icegram' ),
884 'new_item' => __( 'New Message', 'icegram' ),
885 'all_items' => __( 'Messages', 'icegram' ),
886 'view_item' => __( 'View Message', 'icegram' ),
887 'search_items' => __( 'Search Messages', 'icegram' ),
888 'not_found' => __( 'No messages found', 'icegram' ),
889 'not_found_in_trash' => __( 'No messages found in Trash', 'icegram' ),
890 'parent_item_colon' => __( '', 'icegram' ),
891 'menu_name' => __( 'Messages', 'icegram' )
892 );
893
894 $args = array(
895 'labels' => $labels,
896 'public' => false,
897 'publicly_queryable' => false,
898 'show_ui' => true,
899 'show_in_menu' => 'edit.php?post_type=ig_campaign',
900 'query_var' => true,
901 'rewrite' => array( 'slug' => 'ig_message' ),
902 'capability_type' => 'post',
903 'has_archive' => false,
904 'hierarchical' => false,
905 'menu_position' => null,
906 'supports' => array( 'title' )
907 );
908
909 register_post_type( 'ig_message', $args );
910 }
911
912 function import( $data = array() ) {
913
914 if ( empty( $data['campaigns'] ) && empty( $data['messages'] ) ) return;
915
916 $default_theme = $default_type = '';
917 $first_message_type = current( $this->message_types );
918
919 if( is_array( $first_message_type ) ) {
920 $default_type = $first_message_type['type'];
921 if( !empty( $first_message_type['themes'] ) ) {
922 $default_theme = key( $first_message_type['themes'] );
923 }
924 }
925
926 $new_campaign_ids = array();
927 foreach ( (array) $data['campaigns'] as $campaign ) {
928
929 $args = array(
930 'post_content' => ( !empty( $campaign['post_content'] ) ) ? esc_attr( $campaign['post_content'] ) : '',
931 'post_name' => ( !empty( $campaign['post_title'] ) ) ? sanitize_title( $campaign['post_title'] ) : '',
932 'post_title' => ( !empty( $campaign['post_title'] ) ) ? $campaign['post_title'] : '',
933 'post_status' => ( !empty( $campaign['post_status'] ) ) ? $campaign['post_status'] : 'draft',
934 'post_type' => 'ig_campaign'
935 );
936
937 $new_campaign_id = wp_insert_post( $args );
938 $new_campaign_ids[] = $new_campaign_id;
939
940 if ( !empty( $campaign['target_rules'] ) ) {
941
942 $defaults = array (
943 'homepage' => 'yes',
944 'when' => 'always',
945 'from' => '',
946 'to' => '',
947 'mobile' => 'yes',
948 'tablet' => 'yes',
949 'laptop' => 'yes',
950 'logged_in' => 'all'
951 );
952
953 $target_rules = wp_parse_args( $campaign['target_rules'], $defaults );
954 update_post_meta( $new_campaign_id, 'icegram_campaign_target_rules', $target_rules );
955 }
956
957 if ( !empty( $campaign['messages'] ) ) {
958
959 $messages = array();
960
961 foreach ( $campaign['messages'] as $message ) {
962
963 if ( !is_array( $message ) ) continue;
964
965 $args = array(
966 'post_content' => ( !empty( $message['message'] ) ) ? esc_attr( $message['message'] ) : '',
967 'post_name' => ( !empty( $message['post_title'] ) ) ? sanitize_title( $message['post_title'] ) : '',
968 'post_title' => ( !empty( $message['post_title'] ) ) ? $message['post_title'] : '',
969 'post_status' => ( !empty( $message['post_status'] ) ) ? $message['post_status'] : 'publish',
970 'post_type' => 'ig_message'
971 );
972
973 $new_message_id = wp_insert_post( $args );
974 $new_message = array(
975 'id' => $new_message_id,
976 'time' => ( !empty( $message['time'] ) ) ? $message['time'] : 0
977 );
978 $messages[] = $new_message;
979
980 unset( $message['post_content'] );
981 unset( $message['time'] );
982
983 $message['id'] = $new_message_id;
984
985 $defaults = array (
986 'post_title' => '',
987 'type' => $default_type,
988 'theme' => $default_theme,
989 'animation' => '',
990 'headline' => '',
991 'label' => '',
992 'link' => '',
993 'icon' => '',
994 'message' => '',
995 'position' => '',
996 'text_color' => '#000000',
997 'bg_color' => '#ffffff',
998 'id' => ''
999 );
1000
1001 $icegram_message_data = wp_parse_args( $message, $defaults );
1002
1003 if ( !empty( $icegram_message_data ) ) {
1004 update_post_meta( $new_message_id, 'icegram_message_data', $icegram_message_data );
1005 update_post_meta( $new_message_id, 'icegram_message_preview_data', $icegram_message_data );
1006 }
1007 }
1008
1009 if ( !empty( $campaign['messages'] ) ) {
1010 update_post_meta( $new_campaign_id, 'messages', $messages );
1011 update_post_meta( $new_campaign_id, 'campaign_preview', $messages );
1012 }
1013
1014 }
1015 }
1016 if( !empty( $new_campaign_ids ) ) {
1017 update_option( 'icegram_sample_data_imported', $new_campaign_ids );
1018 }
1019
1020 }
1021
1022 function get_sample_data() {
1023
1024 return array(
1025 'campaigns' => array(
1026 array(
1027 'post_name' => '',
1028 'post_title' => 'My First Icegram Campaign',
1029 'target_rules' => array (
1030 'homepage' => 'yes',
1031 'when' => 'always',
1032 'from' => '',
1033 'to' => '',
1034 'mobile' => 'yes',
1035 'tablet' => 'yes',
1036 'laptop' => 'yes',
1037 'logged_in' => 'all'
1038 ),
1039 'messages' => array(
1040 array (
1041 'post_title' => 'Get 2x more Contacts with Your Website',
1042 'post_status' => 'publish',
1043 'time' => '0',
1044 'type' => 'action-bar',
1045 'theme' => 'hello',
1046 'headline' => 'Get 2x more Contacts with Your Website',
1047 'label' => 'Show Me How',
1048 'link' => '',
1049 'icon' => '',
1050 'message' => 'Instant Results Guaranteed',
1051 'position' => '01',
1052 'text_color' => '#000000',
1053 'bg_color' => '#eb593c'
1054 ),
1055 array (
1056 'post_title' => '20% Off Coupon',
1057 'post_status' => 'publish',
1058 'time' => '4',
1059 'type' => 'messenger',
1060 'theme' => 'social',
1061 'animation' => 'slide',
1062 'headline' => '20% Off - for you',
1063 'label' => '',
1064 'link' => '',
1065 'icon' => '',
1066 'message' => "Hey there! We are running a <strong>special 20% off this week</strong> for registered users - like you.
1067
1068 Use coupon <code>LOYALTY20</code> during checkout.",
1069 'position' => '22',
1070 'text_color' => '#000000',
1071 'bg_color' => '#ffffff'
1072 ),
1073 array (
1074 'post_title' => 'How this blog makes over $34,800 / month for FREE.',
1075 'post_status' => 'publish',
1076 'time' => '10',
1077 'type' => 'popup',
1078 'theme' => 'air-mail',
1079 'headline' => 'How this blog makes over $34,800 / month for FREE.',
1080 'label' => 'FREE INSTANT ACCESS',
1081 'link' => '',
1082 'icon' => '',
1083 '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.
1084
1085 <strong>Download my free kit to learn how I do this.</strong>
1086
1087 <ul>
1088 <li>How to choose blog topics that create long term value</li>
1089 <li>The type of blog post that will make your site go viral</li>
1090 <li>How to free yourself from the routine tasks</li>
1091 <li>Resources and tips to get started quickly</li>
1092 <li>Private members club to connect with fellow owners</li>
1093 </ul>",
1094 'text_color' => '#000000',
1095 'bg_color' => '#ffffff'
1096
1097 ),
1098 array (
1099 'post_title' => 'Exclusive Marketing Report',
1100 'post_status' => 'publish',
1101 'time' => '6',
1102 'type' => 'toast',
1103 'theme' => 'stand-out',
1104 'animation' => 'pop',
1105 'headline' => 'Exclusive Marketing Report',
1106 'label' => '',
1107 'link' => '',
1108 'icon' => '',
1109 'message' => 'FREE for every subscriber. Click here to download it.',
1110 'position' => '02',
1111 'text_color' => '#000000',
1112 'bg_color' => '#ffffff'
1113 )
1114
1115 )
1116 )
1117 )
1118 );
1119 }
1120
1121 function remove_preview_button() {
1122 global $post_type;
1123
1124 if( $post_type == 'ig_message' || $post_type == 'ig_campaign' ) {
1125
1126 ?>
1127 <style>
1128 #preview-action { display:none; }
1129 </style>
1130 <?php
1131
1132 }
1133
1134 }
1135
1136 function remove_row_actions( $actions, $post ) {
1137
1138 if ( empty( $post->post_type ) || ( $post->post_type != 'ig_campaign' && $post->post_type != 'ig_message' ) ) return $actions;
1139
1140 unset( $actions['inline hide-if-no-js'] );
1141 unset( $actions['view'] );
1142
1143 return $actions;
1144
1145 }
1146
1147 function identify_current_page() {
1148 global $post, $wpdb;
1149
1150 $obj = get_queried_object();
1151 $id = 0;
1152 if( !empty( $obj->has_archive ) ) {
1153 $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $obj->has_archive ) );
1154 } elseif( is_object( $post ) && isset( $post->ID ) ) {
1155 $id = $post->ID;
1156 }
1157 $id = apply_filters('icegram_identify_current_page', $id );
1158 self::$current_page_id = $id;
1159 }
1160
1161 static function get_current_page_id() {
1162 return self::$current_page_id;
1163 }
1164
1165 function wpml_get_parent_id( $id ) {
1166 global $post;
1167 if (function_exists('icl_object_id') && function_exists('icl_get_default_language') ) {
1168 $id = icl_object_id($id, $post->post_type, true, icl_get_default_language() );
1169 }
1170 return $id;
1171 }
1172
1173
1174 /**
1175 * Our implementation of wpautop to preserve script and style tags
1176 */
1177 function before_wpautop($pee) {
1178 if ( trim($pee) === '' ) {
1179 $this->_wpautop_tags = array();
1180 return '';
1181 }
1182
1183 $tags = array();
1184 // Pull out tags and add placeholders
1185 list( $pee, $tags['pre'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'pre' );
1186 list( $pee, $tags['script'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'script' );
1187 list( $pee, $tags['style'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'style' );
1188 $this->_wpautop_tags = $tags;
1189
1190 if( !empty( $pre_tags ) )
1191 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $pre_tags );
1192 if( !empty( $script_tags ) )
1193 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $script_tags );
1194 if( !empty( $style_tags ) )
1195 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $style_tags );
1196
1197 return $pee;
1198 }
1199
1200 function after_wpautop($pee) {
1201 if ( trim($pee) === '' || empty($this->_wpautop_tags) )
1202 return '';
1203
1204 // Replace placeholders with original content
1205 if (!empty($this->_wpautop_tags['pre'])) {
1206 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['pre'] );
1207 }
1208 if (!empty($this->_wpautop_tags['script'])) {
1209 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['script'] );
1210 }
1211 if (!empty($this->_wpautop_tags['style'])) {
1212 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['style'] );
1213 }
1214
1215 $this->_wpautop_tags = array();
1216
1217 return $pee;
1218 }
1219
1220 function _wpautop_add_tag_placeholders( $pee, $tag ) {
1221 $tags = array();
1222
1223 if ( false !== strpos( $pee, "<{$tag}" ) ) {
1224 $pee_parts = explode( "</{$tag}>", $pee );
1225 $last_pee = array_pop( $pee_parts );
1226 $pee = '';
1227 $i = 0;
1228
1229 foreach ( $pee_parts as $pee_part ) {
1230 $start = strpos( $pee_part, "<{$tag}" );
1231
1232 // Malformed html?
1233 if ( false === $start ) {
1234 $pee .= $pee_part;
1235 continue;
1236 }
1237
1238 $name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
1239 $tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
1240
1241 $pee .= substr( $pee_part, 0, $start ) . $name;
1242 $i++;
1243 }
1244
1245 $pee .= $last_pee;
1246 }
1247
1248 return array( $pee, $tags );
1249 }
1250
1251 function _wpautop_replace_tag_placeholders( $pee, $tags ) {
1252 if ( ! empty( $tags ) ) {
1253 $pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
1254 }
1255
1256 return $pee;
1257 }
1258
1259 }
1260
1261 function initialize_icegram() {
1262 global $icegram;
1263
1264 // i18n / l10n - load translations
1265 load_plugin_textdomain( 'icegram', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
1266
1267 $icegram = new Icegram();
1268 }
1269
1270 add_action( 'plugins_loaded', 'initialize_icegram' );
1271 register_activation_hook( __FILE__, array( 'Icegram', 'install' ) );