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

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