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

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