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

1,382 lines 65.2 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.8
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.8";
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 case 'clicked':
348 if (is_array($event['params']) && !empty($event['params']['message_id'])) {
349 $messages_clicked[] = $event['params']['message_id'];
350 if(!empty($event['params']['expiry_time_clicked'])){
351 if($event['params']['expiry_time_clicked'] =='today'){
352 $event['params']['expiry_time_clicked'] = strtotime('+1 day', mktime(0, 0, 0));
353 }else if($event['params']['expiry_time_clicked'] == 'current_session'){
354 $event['params']['expiry_time_clicked'] = 0;
355 }else{
356 $event['params']['expiry_time_clicked'] = strtotime($event['params']['expiry_time_clicked']);
357 }
358 setcookie('icegram_messages_clicked_'.$event['params']['message_id'],true , $event['params']['expiry_time_clicked'] , '/' );
359 }
360 }
361 break;
362
363 default:
364 break;
365 }
366
367 // Emit event for other plugins to handle it
368 do_action('icegram_event_track', $event);
369 do_action('icegram_event_track_'.$event['type'], $event['params']);
370 }
371 }
372 exit();
373 }
374
375 static function install() {
376 // Redirect to welcome screen
377 delete_option( '_icegram_activation_redirect' );
378 add_option( '_icegram_activation_redirect', 'pending' );
379 }
380
381 public function welcome() {
382
383 $this->db_update();
384 // Bail if no activation redirect transient is set
385 if ( false === get_option( '_icegram_activation_redirect' ) )
386 return;
387
388 // Delete the redirect transient
389 delete_option( '_icegram_activation_redirect' );
390
391 wp_redirect( admin_url( 'edit.php?post_type=ig_campaign&page=icegram-support' ) );
392 exit;
393 }
394
395 function db_update() {
396 $current_db_version = get_option( 'icegram_db_version' );
397 if ( !$current_db_version || version_compare( $current_db_version, '1.2', '<' ) ) {
398 include( 'updates/icegram-update-1.2.php' );
399 }
400 }
401
402 public function admin_menus() {
403
404 $welcome_page_title = __( 'Welcome to Icegram', 'icegram' );
405 $settings_page_title = __( 'Settings', 'icegram' );
406 $addons_page_title = __( 'Add-ons', 'icegram' );
407
408 /*
409 if ( false === ( $ig_addons = get_transient( 'icegram_addons_data' ) ) ) {
410 $this->check_for_addons();
411 }
412 $addon_count = get_option( 'icegram_no_of_addons' );
413
414 if ($addon_count > 0) {
415 $addons_page_title .= " <span class='awaiting-mod update-plugins count-$addon_count'><span class='addon-count'>" . number_format_i18n( $addon_count ) . "</span></span>" ;
416 }
417 */
418
419 $menu_title = __( 'Docs & Support', 'icegram' );
420 $about = add_submenu_page( 'edit.php?post_type=ig_campaign', $welcome_page_title, $menu_title, 'manage_options', 'icegram-support', array( $this, 'about_screen' ) );
421 $settings = add_submenu_page( 'edit.php?post_type=ig_campaign', $settings_page_title, $settings_page_title, 'manage_options', 'icegram-settings', array( $this, 'settings_screen' ) );
422 $addons = add_submenu_page( 'edit.php?post_type=ig_campaign', $addons_page_title, $addons_page_title, 'manage_options', 'icegram-addons', array( $this, 'addons_screen' ) );
423
424 add_action( 'admin_print_styles-'. $about, array( $this, 'admin_css' ) );
425 add_action( 'admin_print_styles-'. $settings, array( $this, 'admin_css' ) );
426 add_action( 'admin_print_styles-'. $addons, array( $this, 'admin_css' ) );
427
428 }
429
430 public function admin_css() {
431 wp_enqueue_style( 'icegram-activation', $this->plugin_url . '/assets/css/admin.css' );
432 }
433
434 public function about_screen() {
435
436 // Import data if not done already
437 if( false === get_option( 'icegram_sample_data_imported' ) ) {
438 $this->import( $this->get_sample_data() );
439 }
440
441 include ( 'about-icegram.php' );
442 }
443
444 public function settings_screen() {
445 include ( 'settings.php' );
446 }
447
448 public function addons_screen() {
449 $ig_addons = $this->check_for_addons( true );
450 include ( 'addons.php' );
451 }
452
453 public function check_for_addons( $force_update = false ) {
454
455 if ( $force_update === true || false === ( $ig_addons = get_transient( 'icegram_addons_data' ) ) ) {
456 $ig_addons_json = wp_remote_get( 'http://icegram.com/addons.json', array( 'user-agent' => 'Icegram Addons' ) );
457
458 if ( ! is_wp_error( $ig_addons_json ) ) {
459 $ig_addons = json_decode( wp_remote_retrieve_body( $ig_addons_json ) );
460 $addon_count = get_option( 'icegram_no_of_addons', 0 );
461 if ( !empty($ig_addons) && is_array($ig_addons) ) {
462 set_transient( 'icegram_addons_data', $ig_addons, 24 * HOUR_IN_SECONDS ); // 1 day
463 update_option( 'icegram_no_of_addons', count( $ig_addons ) - $addon_count ); // display count of newly added addons
464 }
465 }
466 }
467 return $ig_addons;
468 }
469
470 public function branding_data_remove( $icegram_branding_data ) {
471 if( !empty( $icegram_branding_data ) && 'yes' != get_option('icegram_share_love', 'no') ) {
472 $icegram_branding_data['powered_by_logo'] = '';
473 $icegram_branding_data['powered_by_text'] = '';
474 }
475 return $icegram_branding_data;
476 }
477
478 function execute_shortcode( $atts = array() ) {
479 // When shortcode is called, it will only prepare an array with conditions
480 // And add a placeholder div
481 // Display will happen in footer via display_messages()
482 $i = count($this->shortcode_instances);
483 $this->shortcode_instances[ $i ] = shortcode_atts( array(
484 'campaigns' => '',
485 'messages' => '',
486 'skip_others' => 'no'
487 ), $atts );
488 $html[] = "<div class='ig_shortcode_container' id='icegram_shortcode_{$i}'";
489 foreach ($atts as $key => $value) {
490 $value = str_replace(",", " ", $value);
491 $html[] = " data-{$key}=\"".htmlentities($value)."\" ";
492 }
493 $html[] = " >"."</div>";
494 return implode(" ", $html);
495 }
496
497 // Do not index Icegram campaigns / messages...
498 // Not using currently - made custom post types non public...
499 function nofollow_noindex() {
500 $post = get_queried_object();
501 if ( (!empty($post) && !empty( $post->post_type ) && ( $post->post_type == 'ig_campaign' || $post->post_type == 'ig_message' ))
502 || is_post_type_archive( array('ig_message', 'ig_campaign') ) ) {
503 echo PHP_EOL . '<meta name="robots" content="NOINDEX,NOFOLLOW" />' . PHP_EOL;
504 }
505 }
506
507 function display_messages() {
508
509 $skip_others = $preview_mode = false;
510 $campaign_ids = $message_ids = array();
511
512 // Pull in message and campaign IDs from shortcodes - if set
513 if( !empty( $this->shortcode_instances ) ) {
514 foreach ($this->shortcode_instances as $i => $value) {
515 $cids = array_map( 'trim', (array) explode( ',', $value['campaigns'] ) );
516 $mids = array_map( 'trim', (array) explode( ',', $value['messages'] ) );
517 if ($value['skip_others'] == 'yes' && (!empty($cids) || !empty($mids))) {
518 $skip_others = true;
519 }
520 $campaign_ids = array_merge($campaign_ids, $cids);
521 $message_ids = array_merge($message_ids, $mids);
522 }
523 }
524
525 if( !empty( $_GET['campaign_preview_id'] ) && current_user_can( 'manage_options' ) ) {
526 $campaign_ids = array( $_GET['campaign_preview_id'] );
527 $preview_mode = true;
528 }
529
530 $messages = $this->get_valid_messages( $message_ids, $campaign_ids, $preview_mode, $skip_others );
531
532 if( empty( $messages ) ) {
533 return;
534 }
535
536 $types_shown = array(); $messages_to_show_ids = array();
537 foreach ( $messages as $key => $message_data ) {
538
539 if( !is_array( $message_data ) || empty( $message_data ) ) {
540 continue;
541 }
542
543
544 // Don't show a seen message again - if needed
545 if( !empty( $message_data['id'] ) &&
546 empty( $_GET['campaign_preview_id'] ) &&
547 !empty($_COOKIE['icegram_messages_shown_'.$message_data['id']])&&
548 !empty( $message_data['retargeting'] ) &&
549 $message_data['retargeting'] == 'yes'
550 ) {
551 unset( $messages[$key] );
552 continue;
553 }
554 if( !empty( $message_data['id'] ) &&
555 empty( $_GET['campaign_preview_id'] ) &&
556 !empty($_COOKIE['icegram_messages_clicked_'.$message_data['id']]) &&
557 !empty( $message_data['retargeting_clicked'] ) &&
558 $message_data['retargeting_clicked'] == 'yes'
559 ) {
560 unset( $messages[$key] );
561 continue;
562 }
563
564 // Avoid showing the same message twice
565 if (in_array($message_data['id'], $messages_to_show_ids)) {
566 unset ( $messages[$key] );
567 continue;
568 } else {
569 $messages_to_show_ids[] = $message_data['id'];
570 }
571
572
573 /*
574 // Our own implementation so WP does not mess with script, style and pre tags
575 add_filter('the_content', array( $this, 'before_wpautop' ) , 9);
576 add_filter('the_content', array( $this, 'after_wpautop' ) , 11);
577 $messages[$key]['message'] = apply_filters( 'the_content', $message_data['message'] );
578 remove_filter('the_content', array( $this, 'before_wpautop' ) , 9);
579 remove_filter('the_content', array( $this, 'after_wpautop' ) , 11);
580 */
581 // Redo the_content functionality to avoid other plugins adding extraneous code to messages
582 $content = $message_data['message'];
583 $content = convert_chars( convert_smilies( wptexturize( $content ) ) );
584 if(isset($GLOBALS['wp_embed'])) {
585 $content = $GLOBALS['wp_embed']->autoembed($content);
586 }
587 $content = $this->after_wpautop( wpautop( $this->before_wpautop( $content ) ) );
588 $content = do_shortcode( shortcode_unautop( $content ) );
589 $messages[$key]['message'] = $content;
590
591 }
592
593 if( empty( $messages ) )
594 return;
595
596 wp_register_script( 'icegram_js', $this->plugin_url . '/assets/js/icegram.js', array ( 'jquery' ), $this->version, true);
597 wp_enqueue_style( 'icegram_css', $this->plugin_url . '/assets/css/frontend.css', array(), $this->version );
598 wp_enqueue_style( 'dashicons' );
599
600 $icegram_default = apply_filters( 'icegram_branding_data',
601 array ( 'icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
602 'powered_by_logo' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
603 'powered_by_text' => __( 'Powered by Icegram', 'icegram' )
604 ) );
605 $messages = apply_filters( 'icegram_messages_to_show', $messages );
606 $icegram = apply_filters( 'icegram_data', array ( 'messages' => array_values( $messages ),
607 'ajax_url' => admin_url( 'admin-ajax.php' ),
608 'preview_id' => !empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '',
609 'defaults' => $icegram_default
610 ));
611 foreach ($icegram['messages'] as $key => $message_data) {
612 $types_shown[] = $message_data['type'];
613 }
614 if (empty($icegram['preview_id'])) {
615 unset($icegram['preview_id']);
616 }
617
618 if( !wp_script_is( 'icegram_js' ) ) {
619 wp_enqueue_script( 'icegram_js' );
620 wp_localize_script( 'icegram_js', 'icegram_data', $icegram );
621 }
622
623 // Load JS and default CSS
624 $types_shown = array_unique($types_shown);
625
626 if (in_array('popup', $types_shown)) {
627 wp_enqueue_script( 'thickbox' );
628 wp_enqueue_style( 'thickbox' );
629 }
630
631 foreach ($types_shown as $message_type) {
632 $ver = ( !empty($this->message_types[$message_type]['version'])) ? $this->message_types[$message_type]['version'] : $this->version;
633 wp_register_script( 'icegram_message_type_'.$message_type, $this->message_types[$message_type]['baseurl'] . "main.js" , array ( 'icegram_js' ), $ver, true );
634 wp_enqueue_script( 'icegram_message_type_'.$message_type );
635 wp_enqueue_style( 'icegram_css_'.$message_type, $this->message_types[$message_type]['baseurl'] . 'default.css', array(), $ver );
636 }
637
638 // Load theme CSS
639 foreach ($messages as $message) {
640 if (!empty( $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ]) ) {
641 $theme = $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ];
642 wp_enqueue_style( 'icegram_css_'.$message['type'].'_'.$message['theme'], $theme['baseurl'] . $message['theme'].'.css' );
643 }
644 }
645
646 }
647
648 function enqueue_admin_styles_and_scripts() {
649
650 $screen = get_current_screen();
651 if ( !in_array( $screen->id, array( 'ig_campaign', 'ig_message' ), true ) ) return;
652
653 // Register scripts
654 wp_register_script( 'icegram_writepanel', $this->plugin_url . '/assets/js/admin.js' , array ( 'jquery', 'wp-color-picker' ), $this->version );
655 wp_register_script( 'icegram_chosen', $this->plugin_url . '/assets/js/chosen.jquery.min.js' , array ( 'jquery' ), $this->version );
656 wp_register_script( 'icegram_ajax-chosen', $this->plugin_url . '/assets/js/ajax-chosen.jquery.min.js' , array ( 'icegram_chosen' ), $this->version );
657 wp_register_script( 'icegram_tiptip', $this->plugin_url . '/assets/js/jquery.tipTip.min.js' , array ( 'jquery' ), $this->version );
658
659 wp_enqueue_script( 'icegram_writepanel' );
660 wp_enqueue_script( 'icegram_ajax-chosen' );
661 wp_enqueue_script( 'icegram_tiptip' );
662 wp_enqueue_script( 'thickbox' );
663
664 $icegram_writepanel_params = array ( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'search_message_nonce' => wp_create_nonce( "search-messages" ) );
665 $this->available_headlines = apply_filters( 'icegram_available_headlines', array() );
666 $icegram_writepanel_params = array_merge( $icegram_writepanel_params, array( 'available_headlines' => $this->available_headlines ) );
667
668 wp_localize_script( 'icegram_writepanel', 'icegram_writepanel_params', $icegram_writepanel_params );
669
670 wp_enqueue_style( 'thickbox' );
671 wp_enqueue_style( 'dashicons' );
672 wp_enqueue_style( 'wp-color-picker' );
673 wp_enqueue_style( 'icegram_admin_styles', $this->plugin_url . '/assets/css/admin.css', array(), $this->version );
674 wp_enqueue_style( 'icegram_jquery-ui-style', $this->plugin_url . '/assets/css/jquery-ui.min.css', array(), $this->version );
675 wp_enqueue_style( 'icegram_chosen_styles', $this->plugin_url . '/assets/css/chosen.min.css', array(), $this->version );
676
677 if ( !wp_script_is( 'jquery-ui-datepicker' ) ) {
678 wp_enqueue_script( 'jquery-ui-datepicker' );
679 }
680
681 }
682
683 public static function get_platform() {
684 $platform = '';
685 $user_agent = trim(strtolower($_SERVER['HTTP_USER_AGENT']));
686 $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)/';
687 if ( preg_match( $pattern, $user_agent, $matches ) ) {
688 $platform = $matches[0];
689 }
690
691 switch ( $platform ) {
692
693 /* phones / smartphones */
694 case 'android 1':
695 case 'android 2':
696 case 'blackberry':
697 case 'iphone':
698 case 'ipod':
699 case 'iemobile':
700 case 'webos':
701 case 'palm':
702 case 'symbian':
703 case 'googlebot-mobile':
704 $platform = 'mobile';
705 break;
706
707 /* tablets */
708 case 'android 3':
709 case 'android 4':
710 case 'ipad':
711 case 'kindle':
712 $platform = 'tablet';
713 break;
714
715 /* desktops / laptops */
716 case 'windows':
717 case 'win64':
718 case 'wow64':
719 case 'macintosh':
720 case 'ppx mac os x':
721 case 'intel mac os x':
722 case 'googlebot':
723 $platform = 'laptop';
724 break;
725
726 /* in case nothing else matches */
727 default:
728 $platform = 'laptop';
729 break;
730 }
731 return $platform;
732 }
733
734 function get_message_data( $message_ids = array(), $preview = false ) {
735 global $wpdb;
736
737 $message_data = array();
738 $original_message_id_map = array();
739 $meta_key = $preview ? 'icegram_message_preview_data' : 'icegram_message_data';
740 $message_data_query = "SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE '$meta_key'";
741 if ( !empty( $message_ids ) && is_array( $message_ids ) ) {
742 // For WPML compatibility
743 if ( function_exists('icl_object_id') ) {
744 $wpml_settings = get_option('icl_sitepress_settings');
745 $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;
746 foreach ($message_ids as $i=>$id ) {
747 $translated = icl_object_id( $id, 'ig_message', $original_if_missing );
748 $message_ids[ $i ] = $translated;
749 $original_message_id_map[ $translated ] = $id;
750 }
751 }
752 $message_ids = array_filter(array_unique($message_ids));
753 if ( !empty( $message_ids ) ) {
754 $message_data_query .= " AND post_id IN ( " . implode( ',', $message_ids ) . " )";
755 $message_data_results = $wpdb->get_results( $message_data_query, 'ARRAY_A' );
756 foreach ( $message_data_results as $message_data_result ) {
757 $message_data[$message_data_result['post_id']] = maybe_unserialize( $message_data_result['meta_value'] );
758 // For WPML compatibility
759 if (!empty( $original_message_id_map[ $message_data_result['post_id'] ])) {
760 $message_data[$message_data_result['post_id']]['original_message_id'] = $original_message_id_map[ $message_data_result['post_id'] ];
761 }
762 }
763 }
764 }
765 return $message_data;
766 }
767
768 function get_valid_messages( $message_ids = array(), $campaign_ids = array(), $preview_mode = false, $skip_others = false) {
769
770 $valid_messages = $valid_campaigns = $message_campaign_map = array();
771
772 $campaign_ids = array_filter(array_unique($campaign_ids));
773 $message_ids = array_filter(array_unique($message_ids));
774
775 if ( !empty( $campaign_ids ) ) {
776 $valid_campaigns = $this->get_valid_campaigns( $campaign_ids, true );
777 }
778 // When skip_others is true, we won't load campaigns / messages from db
779 if (!$skip_others && !$preview_mode) {
780 $campaigns = $this->get_valid_campaigns();
781 if (!empty($campaigns)) {
782 foreach ($campaigns as $id => $campaign) {
783 if (!array_key_exists($id, $valid_campaigns)) {
784 $valid_campaigns[ $id ] = $campaign;
785 }
786 }
787 }
788 }
789 // Create a map to look up campaign id for a given message
790 if( !empty( $valid_campaigns ) ) {
791 foreach ($valid_campaigns as $id => $campaign) {
792 if ($preview_mode) {
793 $campaign->messages = get_post_meta( $id, 'campaign_preview', true );
794 }
795
796 foreach( $campaign->messages as $msg) {
797 $message_ids[] = $msg['id'];
798 if (!array_key_exists( $msg['id'], $message_campaign_map)) {
799 $message_campaign_map[ $msg['id'] ] = $id;
800 }
801 }
802 }
803 }
804
805 // We don't display same message twice...
806 $message_ids = array_unique($message_ids);
807
808 if( empty( $message_ids ) ) {
809 return array();
810 }
811 $valid_messages = $this->get_message_data( $message_ids, $preview_mode );
812
813 foreach ($valid_messages as $id => $message_data) {
814 // Remove message if message type is uninstalled
815 $class_name = 'Icegram_Message_Type_' . str_replace(' ', '_', ucwords(str_replace('-', ' ', $message_data['type'])));
816 if( !class_exists( $class_name ) ) {
817 unset( $valid_messages[$id] );
818 continue;
819 }
820 $message_data['delay_time'] = 0;
821 $message_data['retargeting'] = '';
822 $message_data['campaign_id'] = ($preview_mode) ? $_GET['campaign_preview_id'] : '';
823
824 // Pull display time and retargeting rule from campaign if possible
825 $message_id = (!empty($message_data['original_message_id'])) ? $message_data['original_message_id'] : $id;
826 if (!empty($message_campaign_map[ $message_id ])) {
827 $message_data['campaign_id'] = $message_campaign_map[ $message_id ];
828 $campaign = $valid_campaigns[ $message_data['campaign_id'] ];
829 if (!empty($campaign) && $campaign instanceof Icegram_Campaign) {
830 $message_meta_from_campaign = $campaign->get_message_meta_by_id( $message_id );
831 if (!empty($message_meta_from_campaign['time'])) {
832 $message_data['delay_time'] = $message_meta_from_campaign['time'];
833 }
834 $rule_value = $campaign->get_rule_value('retargeting');
835 $message_data['retargeting'] = !empty( $rule_value['retargeting'] ) ? $rule_value['retargeting'] : '';
836 $message_data['expiry_time'] = !empty( $rule_value['retargeting'] ) ? $rule_value['expiry_time'] : '';
837 $rule_value_retargeting_clicked = $campaign->get_rule_value('retargeting_clicked');
838 $message_data['retargeting_clicked'] = !empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['retargeting_clicked'] : '';
839 $message_data['expiry_time_clicked'] = !empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['expiry_time_clicked'] : '';
840
841 }
842 }
843 $valid_messages[$id] = $message_data;
844 }
845
846 $valid_messages = apply_filters( 'icegram_valid_messages', $valid_messages );
847 return $valid_messages;
848 }
849
850 function get_valid_campaigns( $campaign_ids = array(), $skip_page_check = false ) {
851 global $wpdb;
852
853 if ( empty( $campaign_ids ) ) {
854 $sql = "SELECT pm.post_id
855 FROM {$wpdb->prefix}posts AS p
856 LEFT JOIN {$wpdb->prefix}postmeta AS pm ON ( pm.post_id = p.ID )
857 WHERE p.post_status = 'publish' ";
858 // Filter handler within this file (and possibly others) will append to this SQL
859 // and provide arguments for wpdb->prepare if needed.
860 // First element in the array is SQL, remaining are values for placeholders in SQL
861 $sql_params = apply_filters( 'icegram_get_valid_campaigns_sql', array($sql), array() );
862 $campaign_ids = $wpdb->get_col( $wpdb->prepare( array_shift($sql_params), $sql_params ) );
863 }
864 $valid_campaigns = array();
865 foreach ( (array) $campaign_ids as $campaign_id ) {
866 $campaign = new Icegram_Campaign( $campaign_id );
867
868 if ( $campaign->is_valid( array('skip_page_check' => $skip_page_check) ) ) {
869 $valid_campaigns[$campaign_id] = $campaign;
870 } else {
871 // Campgain is invalid!
872 }
873 }
874 return $valid_campaigns;
875 }
876
877 function append_to_valid_campaigns_sql( $sql_params = array(), $options = array() ) {
878 // Page check conditions
879 $pid = Icegram::get_current_page_id();
880
881 $sql = " AND (
882 pm.meta_key = 'icegram_campaign_target_rules' AND (
883 ( pm.meta_value LIKE '%%%s%%' )
884 OR ( pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' )
885 ";
886 $sql_params[] = 's:8:"sitewide";s:3:"yes";';
887 $sql_params[] = 's:10:"other_page";s:3:"yes";';
888 $sql_params[] = 's:7:"page_id";a:';
889 $sql_params[] = serialize( (string) $pid );
890 //local url
891 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
892 $sql_params[] = 's:9:"local_url";s:3:"yes";';
893
894 if (is_home() || is_front_page()) {
895 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
896 $sql_params[] = 's:8:"homepage";s:3:"yes";';
897 }
898 $sql .=" ) )";
899
900 $sql_params[0] .= $sql;
901
902 //s:9:"logged_in";s:3:"all";
903 return $sql_params;
904 }
905
906 // Include all classes required for Icegram plugin
907 function include_classes() {
908
909 $classes = glob( $this->plugin_path . '/classes/*.php' );
910 foreach ( $classes as $file ) {
911 // Files with 'admin' in their name are included only for admin section
912 if ( is_file( $file ) && ( (strpos($file, '-admin') >= 0 && is_admin()) || (strpos($file, '-admin') === false) ) ) {
913 include_once $file;
914 }
915 }
916
917 // Load built in message types
918 $icegram_message_type_basedirs = glob( $this->plugin_path . '/message-types/*' );
919 // Allow other plugins to add new message types
920 $icegram_message_type_basedirs = apply_filters( 'icegram_message_type_basedirs', $icegram_message_type_basedirs );
921 // Set up different message type classes
922 foreach ( $icegram_message_type_basedirs as $dir ) {
923 $type = basename ( $dir );
924 $class_file = $dir . "/main.php";
925 if( is_file( $class_file ) ) {
926 include_once( $class_file );
927 }
928 $class_name = 'Icegram_Message_Type_' . str_replace(' ', '_', ucwords(str_replace('-', ' ', $type)));
929 if (class_exists($class_name)) {
930 $this->message_type_objs[ $type ] = new $class_name();
931 }
932 }
933 $this->message_types = apply_filters( 'icegram_message_types', array() );
934
935 }
936
937 // Register Campaign post type
938 function register_campaign_post_type() {
939 $labels = array(
940 'name' => __( 'Campaigns', 'icegram' ),
941 'singular_name' => __( 'Campaign', 'icegram' ),
942 'add_new' => __( 'Add New Campaign', 'icegram' ),
943 'add_new_item' => __( 'Add New Campaign', 'icegram' ),
944 'edit_item' => __( 'Edit Campaign', 'icegram' ),
945 'new_item' => __( 'New Campaign', 'icegram' ),
946 'all_items' => __( 'Campaigns', 'icegram' ),
947 'view_item' => __( 'View Campaign', 'icegram' ),
948 'search_items' => __( 'Search Campaigns', 'icegram' ),
949 'not_found' => __( 'No campaigns found', 'icegram' ),
950 'not_found_in_trash' => __( 'No campaigns found in Trash', 'icegram' ),
951 'parent_item_colon' => __( '', 'icegram' ),
952 'menu_name' => __( 'Icegram', 'icegram' )
953 );
954
955 $args = array(
956 'labels' => $labels,
957 'menu_icon' => 'dashicons-info',
958 'public' => false,
959 'publicly_queryable' => false,
960 'show_ui' => true,
961 'show_in_menu' => true,
962 'query_var' => true,
963 'rewrite' => array( 'slug' => 'ig_campaign' ),
964 'capability_type' => 'post',
965 'has_archive' => false,
966 'hierarchical' => false,
967 'menu_position' => null,
968 'supports' => array( 'title', 'editor' )
969 );
970
971 register_post_type( 'ig_campaign', $args );
972 }
973
974 // Register Message post type
975 function register_message_post_type() {
976 $labels = array(
977 'name' => __( 'Messages', 'icegram' ),
978 'singular_name' => __( 'Message', 'icegram' ),
979 'add_new' => __( 'Create New', 'icegram' ),
980 'add_new_item' => __( 'Create New Message', 'icegram' ),
981 'edit_item' => __( 'Edit Message', 'icegram' ),
982 'new_item' => __( 'New Message', 'icegram' ),
983 'all_items' => __( 'Messages', 'icegram' ),
984 'view_item' => __( 'View Message', 'icegram' ),
985 'search_items' => __( 'Search Messages', 'icegram' ),
986 'not_found' => __( 'No messages found', 'icegram' ),
987 'not_found_in_trash' => __( 'No messages found in Trash', 'icegram' ),
988 'parent_item_colon' => __( '', 'icegram' ),
989 'menu_name' => __( 'Messages', 'icegram' )
990 );
991
992 $args = array(
993 'labels' => $labels,
994 'public' => false,
995 'publicly_queryable' => false,
996 'show_ui' => true,
997 'show_in_menu' => 'edit.php?post_type=ig_campaign',
998 'query_var' => true,
999 'rewrite' => array( 'slug' => 'ig_message' ),
1000 'capability_type' => 'post',
1001 'has_archive' => false,
1002 'hierarchical' => false,
1003 'menu_position' => null,
1004 'supports' => array( 'title' )
1005 );
1006
1007 register_post_type( 'ig_message', $args );
1008 }
1009
1010 function import( $data = array() ) {
1011
1012 if ( empty( $data['campaigns'] ) && empty( $data['messages'] ) ) return;
1013
1014 $default_theme = $default_type = '';
1015 $first_message_type = current( $this->message_types );
1016
1017 if( is_array( $first_message_type ) ) {
1018 $default_type = $first_message_type['type'];
1019 if( !empty( $first_message_type['themes'] ) ) {
1020 $default_theme = key( $first_message_type['themes'] );
1021 }
1022 }
1023
1024 $new_campaign_ids = array();
1025 foreach ( (array) $data['campaigns'] as $campaign ) {
1026
1027 $args = array(
1028 'post_content' => ( !empty( $campaign['post_content'] ) ) ? esc_attr( $campaign['post_content'] ) : '',
1029 'post_name' => ( !empty( $campaign['post_title'] ) ) ? sanitize_title( $campaign['post_title'] ) : '',
1030 'post_title' => ( !empty( $campaign['post_title'] ) ) ? $campaign['post_title'] : '',
1031 'post_status' => ( !empty( $campaign['post_status'] ) ) ? $campaign['post_status'] : 'draft',
1032 'post_type' => 'ig_campaign'
1033 );
1034
1035 $new_campaign_id = wp_insert_post( $args );
1036 $new_campaign_ids[] = $new_campaign_id;
1037
1038 if ( !empty( $campaign['target_rules'] ) ) {
1039
1040 $defaults = array (
1041 'homepage' => 'yes',
1042 'when' => 'always',
1043 'from' => '',
1044 'to' => '',
1045 'mobile' => 'yes',
1046 'tablet' => 'yes',
1047 'laptop' => 'yes',
1048 'logged_in' => 'all'
1049 );
1050
1051 $target_rules = wp_parse_args( $campaign['target_rules'], $defaults );
1052 update_post_meta( $new_campaign_id, 'icegram_campaign_target_rules', $target_rules );
1053 }
1054
1055 if ( !empty( $campaign['messages'] ) ) {
1056
1057 $messages = array();
1058
1059 foreach ( $campaign['messages'] as $message ) {
1060
1061 if ( !is_array( $message ) ) continue;
1062
1063 $args = array(
1064 'post_content' => ( !empty( $message['message'] ) ) ? esc_attr( $message['message'] ) : '',
1065 'post_name' => ( !empty( $message['post_title'] ) ) ? sanitize_title( $message['post_title'] ) : '',
1066 'post_title' => ( !empty( $message['post_title'] ) ) ? $message['post_title'] : '',
1067 'post_status' => ( !empty( $message['post_status'] ) ) ? $message['post_status'] : 'publish',
1068 'post_type' => 'ig_message'
1069 );
1070
1071 $new_message_id = wp_insert_post( $args );
1072 $new_message = array(
1073 'id' => $new_message_id,
1074 'time' => ( !empty( $message['time'] ) ) ? $message['time'] : 0
1075 );
1076 $messages[] = $new_message;
1077
1078 unset( $message['post_content'] );
1079 unset( $message['time'] );
1080
1081 $message['id'] = $new_message_id;
1082
1083 $defaults = array (
1084 'post_title' => '',
1085 'type' => $default_type,
1086 'theme' => $default_theme,
1087 'animation' => '',
1088 'headline' => '',
1089 'label' => '',
1090 'link' => '',
1091 'icon' => '',
1092 'message' => '',
1093 'position' => '',
1094 'text_color' => '#000000',
1095 'bg_color' => '#ffffff',
1096 'id' => ''
1097 );
1098
1099 $icegram_message_data = wp_parse_args( $message, $defaults );
1100
1101 if ( !empty( $icegram_message_data ) ) {
1102 update_post_meta( $new_message_id, 'icegram_message_data', $icegram_message_data );
1103 update_post_meta( $new_message_id, 'icegram_message_preview_data', $icegram_message_data );
1104 }
1105 }
1106
1107 if ( !empty( $campaign['messages'] ) ) {
1108 update_post_meta( $new_campaign_id, 'messages', $messages );
1109 update_post_meta( $new_campaign_id, 'campaign_preview', $messages );
1110 }
1111
1112 }
1113 }
1114 if( !empty( $new_campaign_ids ) ) {
1115 update_option( 'icegram_sample_data_imported', $new_campaign_ids );
1116 }
1117
1118 }
1119
1120 function get_sample_data() {
1121
1122 return array(
1123 'campaigns' => array(
1124 array(
1125 'post_name' => '',
1126 'post_title' => 'My First Icegram Campaign',
1127 'target_rules' => array (
1128 'homepage' => 'yes',
1129 'when' => 'always',
1130 'from' => '',
1131 'to' => '',
1132 'mobile' => 'yes',
1133 'tablet' => 'yes',
1134 'laptop' => 'yes',
1135 'logged_in' => 'all'
1136 ),
1137 'messages' => array(
1138 array (
1139 'post_title' => 'Get 2x more Contacts with Your Website',
1140 'post_status' => 'publish',
1141 'time' => '0',
1142 'type' => 'action-bar',
1143 'theme' => 'hello',
1144 'headline' => 'Get 2x more Contacts with Your Website',
1145 'label' => 'Show Me How',
1146 'link' => '',
1147 'icon' => '',
1148 'message' => 'Instant Results Guaranteed',
1149 'position' => '01',
1150 'text_color' => '#000000',
1151 'bg_color' => '#eb593c'
1152 ),
1153 array (
1154 'post_title' => '20% Off Coupon',
1155 'post_status' => 'publish',
1156 'time' => '4',
1157 'type' => 'messenger',
1158 'theme' => 'social',
1159 'animation' => 'slide',
1160 'headline' => '20% Off - for you',
1161 'label' => '',
1162 'link' => '',
1163 'icon' => '',
1164 'message' => "Hey there! We are running a <strong>special 20% off this week</strong> for registered users - like you.
1165
1166 Use coupon <code>LOYALTY20</code> during checkout.",
1167 'position' => '22',
1168 'text_color' => '#000000',
1169 'bg_color' => '#ffffff'
1170 ),
1171 array (
1172 'post_title' => 'How this blog makes over $34,800 / month for FREE.',
1173 'post_status' => 'publish',
1174 'time' => '10',
1175 'type' => 'popup',
1176 'theme' => 'air-mail',
1177 'headline' => 'How this blog makes over $34,800 / month for FREE.',
1178 'label' => 'FREE INSTANT ACCESS',
1179 'link' => '',
1180 'icon' => '',
1181 '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.
1182
1183 <strong>Download my free kit to learn how I do this.</strong>
1184
1185 <ul>
1186 <li>How to choose blog topics that create long term value</li>
1187 <li>The type of blog post that will make your site go viral</li>
1188 <li>How to free yourself from the routine tasks</li>
1189 <li>Resources and tips to get started quickly</li>
1190 <li>Private members club to connect with fellow owners</li>
1191 </ul>",
1192 'text_color' => '#000000',
1193 'bg_color' => '#ffffff'
1194
1195 ),
1196 array (
1197 'post_title' => 'Exclusive Marketing Report',
1198 'post_status' => 'publish',
1199 'time' => '6',
1200 'type' => 'toast',
1201 'theme' => 'stand-out',
1202 'animation' => 'pop',
1203 'headline' => 'Exclusive Marketing Report',
1204 'label' => '',
1205 'link' => '',
1206 'icon' => '',
1207 'message' => 'FREE for every subscriber. Click here to download it.',
1208 'position' => '02',
1209 'text_color' => '#000000',
1210 'bg_color' => '#ffffff'
1211 )
1212
1213 )
1214 )
1215 )
1216 );
1217 }
1218
1219 function remove_preview_button() {
1220 global $post_type;
1221
1222 if( $post_type == 'ig_message' || $post_type == 'ig_campaign' ) {
1223
1224 ?>
1225 <style>
1226 #preview-action { display:none; }
1227 </style>
1228 <?php
1229
1230 }
1231
1232 }
1233
1234 function remove_row_actions( $actions, $post ) {
1235
1236 if ( empty( $post->post_type ) || ( $post->post_type != 'ig_campaign' && $post->post_type != 'ig_message' ) ) return $actions;
1237
1238 unset( $actions['inline hide-if-no-js'] );
1239 unset( $actions['view'] );
1240
1241 return $actions;
1242
1243 }
1244
1245 function identify_current_page() {
1246 global $post, $wpdb;
1247
1248 $obj = get_queried_object();
1249 $id = 0;
1250 if( !empty( $obj->has_archive ) ) {
1251 $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $obj->has_archive ) );
1252 } elseif( is_object( $post ) && isset( $post->ID ) ) {
1253 $id = $post->ID;
1254 }
1255 $id = apply_filters('icegram_identify_current_page', $id );
1256 self::$current_page_id = $id;
1257 }
1258
1259 static function get_current_page_id() {
1260 return self::$current_page_id;
1261 }
1262 static function get_current_page_url() {
1263 $pageURL = 'http';
1264 if( isset($_SERVER["HTTPS"]) ) {
1265 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
1266 }
1267 $pageURL .= "://";
1268 if ($_SERVER["SERVER_PORT"] != "80") {
1269 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
1270 } else {
1271 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
1272 }
1273 return $pageURL;
1274 }
1275
1276 function wpml_get_parent_id( $id ) {
1277 global $post;
1278 if (function_exists('icl_object_id') && function_exists('icl_get_default_language') ) {
1279 $id = icl_object_id($id, $post->post_type, true, icl_get_default_language() );
1280 }
1281 return $id;
1282 }
1283
1284
1285 /**
1286 * Our implementation of wpautop to preserve script and style tags
1287 */
1288 function before_wpautop($pee) {
1289 if ( trim($pee) === '' ) {
1290 $this->_wpautop_tags = array();
1291 return '';
1292 }
1293
1294 $tags = array();
1295 // Pull out tags and add placeholders
1296 list( $pee, $tags['pre'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'pre' );
1297 list( $pee, $tags['script'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'script' );
1298 list( $pee, $tags['style'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'style' );
1299 $this->_wpautop_tags = $tags;
1300
1301 if( !empty( $pre_tags ) )
1302 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $pre_tags );
1303 if( !empty( $script_tags ) )
1304 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $script_tags );
1305 if( !empty( $style_tags ) )
1306 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $style_tags );
1307
1308 return $pee;
1309 }
1310
1311 function after_wpautop($pee) {
1312 if ( trim($pee) === '' || empty($this->_wpautop_tags) )
1313 return '';
1314
1315 // Replace placeholders with original content
1316 if (!empty($this->_wpautop_tags['pre'])) {
1317 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['pre'] );
1318 }
1319 if (!empty($this->_wpautop_tags['script'])) {
1320 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['script'] );
1321 }
1322 if (!empty($this->_wpautop_tags['style'])) {
1323 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['style'] );
1324 }
1325
1326 $this->_wpautop_tags = array();
1327
1328 return $pee;
1329 }
1330
1331 function _wpautop_add_tag_placeholders( $pee, $tag ) {
1332 $tags = array();
1333
1334 if ( false !== strpos( $pee, "<{$tag}" ) ) {
1335 $pee_parts = explode( "</{$tag}>", $pee );
1336 $last_pee = array_pop( $pee_parts );
1337 $pee = '';
1338 $i = 0;
1339
1340 foreach ( $pee_parts as $pee_part ) {
1341 $start = strpos( $pee_part, "<{$tag}" );
1342
1343 // Malformed html?
1344 if ( false === $start ) {
1345 $pee .= $pee_part;
1346 continue;
1347 }
1348
1349 $name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
1350 $tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
1351
1352 $pee .= substr( $pee_part, 0, $start ) . $name;
1353 $i++;
1354 }
1355
1356 $pee .= $last_pee;
1357 }
1358
1359 return array( $pee, $tags );
1360 }
1361
1362 function _wpautop_replace_tag_placeholders( $pee, $tags ) {
1363 if ( ! empty( $tags ) ) {
1364 $pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
1365 }
1366
1367 return $pee;
1368 }
1369
1370 }
1371
1372 function initialize_icegram() {
1373 global $icegram;
1374
1375 // i18n / l10n - load translations
1376 load_plugin_textdomain( 'icegram', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
1377
1378 $icegram = new Icegram();
1379 }
1380
1381 add_action( 'plugins_loaded', 'initialize_icegram' );
1382 register_activation_hook( __FILE__, array( 'Icegram', 'install' ) );