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

850 lines 39.1 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.1.1
7 * Author: Icegram
8 * Author URI: http://www.icegram.com/
9 * Copyright (c) 2014 Icegram All rights reserved.
10 *
11 * Text Domain: icegram
12 * Domain Path: /lang/
13 */
14
15 /**
16 * Main class Icegram
17 */
18 class Icegram {
19
20 var $plugin_url;
21 var $plugin_path;
22 var $_wpautop_tags;
23 public static $current_page_id;
24
25 function __construct() {
26
27 $this->include_classes();
28 $this->plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
29 $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
30
31 add_action( 'init', array( &$this, 'register_campaign_post_type' ) );
32 add_action( 'init', array( &$this, 'register_message_post_type' ) );
33
34 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_admin_styles_and_scripts' ) );
35 add_action( 'wp_footer', array( &$this, 'display_messages' ) );
36
37 add_action( 'admin_print_styles', array( &$this, 'remove_preview_button' ) ) ;
38 add_filter( 'post_row_actions', array( &$this , 'remove_row_actions' ), 10, 2 );
39 add_action( 'wp_print_scripts', array( &$this, 'identify_current_page' ) );
40
41 add_shortcode( 'icegram', array( &$this, 'display_messages' ) );
42 add_action( 'admin_menu', array( &$this, 'admin_menus') );
43 add_action( 'admin_init', array( &$this, 'welcome' ) );
44
45 add_action( 'wp_ajax_nopriv_icegram_event_track', array( &$this, 'icegram_event_track' ) );
46 add_action( 'wp_ajax_icegram_event_track', array( &$this, 'icegram_event_track' ) );
47
48 }
49
50 public function icegram_event_track() {
51
52 if( !empty( $_POST['event_data'] ) ) {
53
54 $messages_shown = (array) unserialize( (!empty($_COOKIE['icegram_messages_shown']) ? stripslashes( $_COOKIE['icegram_messages_shown'] ) : '') );
55
56 foreach ( $_POST['event_data'] as $event ) {
57 switch ($event['type']) {
58 case 'shown':
59 if (is_array($event['params']) && !empty($event['params']['message_id'])) {
60 $messages_shown[] = $event['params']['message_id'];
61 }
62 break;
63
64 default:
65 break;
66 }
67
68 // Emit event for other plugins to handle it
69 do_action('icegram_event_track', $event);
70 do_action('icegram_event_track_'.$event['type'], $event['params']);
71 }
72 }
73 $messages_shown = array_values ( array_filter ( array_unique($messages_shown) ) );
74 setcookie('icegram_messages_shown', serialize($messages_shown), 0, '/');
75 exit();
76
77 }
78
79 static function install() {
80 // Redirect to welcome screen
81 delete_option( '_icegram_activation_redirect' );
82 add_option( '_icegram_activation_redirect', 'pending' );
83 }
84
85 public function welcome() {
86 // Bail if no activation redirect transient is set
87 if ( false === get_option( '_icegram_activation_redirect' ) )
88 return;
89
90 // Delete the redirect transient
91 delete_option( '_icegram_activation_redirect' );
92
93 wp_redirect( admin_url( 'edit.php?post_type=campaign&page=icegram-support' ) );
94 exit;
95 }
96
97 public function admin_menus() {
98
99 $welcome_page_title = __( 'Welcome to Icegram', 'icegram' );
100 $menu_title = __( 'Docs & Support', 'icegram' );
101 $about = add_submenu_page( 'edit.php?post_type=campaign', $welcome_page_title, $menu_title, 'manage_options', 'icegram-support', array( $this, 'about_screen' ) );
102
103 add_action( 'admin_print_styles-'. $about, array( $this, 'admin_css' ) );
104
105 }
106
107 public function admin_css() {
108 wp_enqueue_style( 'icegram-activation', $this->plugin_url . '/assets/css/admin.css' );
109 }
110
111 public function about_screen() {
112 global $icegram, $icegram_upgrader;
113
114 // Import data if not done already
115 if( false === get_option( 'icegram_sample_data_imported' ) ) {
116 $icegram->import( $icegram->get_sample_data() );
117 }
118
119 include ( 'about-icegram.php' );
120 }
121
122 function display_messages( $atts = array() ) {
123
124 if( !empty( $atts ) ) {
125 extract( shortcode_atts( array(
126 'campaigns' => '',
127 'messages' => ''
128 ), $atts ) );
129
130 $campaign_ids = explode( ',', $campaigns );
131 $campaign_ids = array_map( 'trim', $campaign_ids );
132 $message_ids = explode( ',', $messages );
133 $message_ids = array_map( 'trim', $message_ids );
134 $messages = $this->get_valid_messages( $message_ids, $campaign_ids );
135
136 } elseif( !empty( $_GET['campaign_preview_id'] ) ) {
137
138 $message_ids = get_post_meta( $_GET['campaign_preview_id'], 'campaign_preview', true );
139 $messages = $this->get_valid_messages( $message_ids, array(), true );
140
141 } else {
142 $messages = $this->get_valid_messages();
143 }
144
145 if( empty( $messages ) )
146 return;
147
148 $messages_shown = (array) unserialize( (!empty($_COOKIE['icegram_messages_shown']) ? stripslashes( $_COOKIE['icegram_messages_shown'] ) : '') );
149
150 foreach ( $messages as $key => $message_data ) {
151
152 if( !empty( $message_data['id'] ) &&
153 empty( $_GET['campaign_preview_id'] ) &&
154 in_array( $message_data['id'], $messages_shown ) &&
155 !empty( $message_data['retargeting'] ) &&
156 $message_data['retargeting'] == 'yes'
157 ) {
158 unset( $messages[$key] );
159 continue;
160 }
161
162 // Our own implementation so WP does not mess with script, style and pre tags
163 add_filter('the_content', array( $this, 'before_wpautop' ) , 9);
164 add_filter('the_content', array( $this, 'after_wpautop' ) , 11);
165 $messages[$key]['message'] = apply_filters( 'the_content', $message_data['message'] );
166 remove_filter('the_content', array( $this, 'before_wpautop' ) , 9);
167 remove_filter('the_content', array( $this, 'after_wpautop' ) , 11);
168 $this->get_template( $message_data );
169 }
170
171 if( empty( $messages ) )
172 return;
173
174 wp_register_script( 'icegram_frontend_script', $this->plugin_url . '/assets/js/frontend.js', array ( 'jquery' ), '', true );
175 wp_enqueue_style( 'icegram_frontend_styles', $this->plugin_url . '/assets/css/frontend.css' );
176 wp_enqueue_style( 'dashicons' );
177 wp_enqueue_script( 'thickbox' );
178 wp_enqueue_style( 'thickbox' );
179
180 $icegram_default = apply_filters( 'icegram_branding_data',
181 array ( 'default_promo_image' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
182 'powered_by_logo' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
183 'powered_by_text' => __( 'Powered by Icegram', 'icegram' )
184 ) );
185 $icegram = array ( 'messages' => array_values( $messages ),
186 'ajax_url' => admin_url( 'admin-ajax.php' ),
187 'preview_id' => !empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '',
188 'icegram_default'=> $icegram_default
189 );
190
191 if( !wp_script_is( 'icegram_frontend_script' ) ) {
192 wp_enqueue_script( 'icegram_frontend_script' );
193 wp_localize_script( 'icegram_frontend_script', 'icegram_data', $icegram );
194 }
195
196 }
197
198 function get_template( $message_data = array() ) {
199
200 if( empty( $message_data ) )
201 return;
202
203 $theme = $message_data['theme'][$message_data['type']];
204
205 if( !wp_style_is( $message_data['type'] . "_" . $theme ) ) {
206 wp_enqueue_style( $message_data['type'] . "_" . $theme , $this->plugin_url . '/assets/css/' . str_replace( "_", "-", $message_data['type'] ) . '/' . $theme . '.css' );
207 }
208
209 $template_file = str_replace( "_", "-", $message_data['type'] ) . ".php";
210 include( $this->plugin_path . '/templates/' . $template_file );
211
212 }
213
214 function enqueue_admin_styles_and_scripts() {
215
216 $screen = get_current_screen();
217 if ( !in_array( $screen->id, array( 'campaign', 'message' ), true ) ) return;
218
219 // Register scripts
220 wp_register_script( 'icegram_writepanel', $this->plugin_url . '/assets/js/admin.js' , array ( 'jquery', 'wp-color-picker' ) );
221 wp_register_script( 'icegram_frontend_script', $this->plugin_url . '/assets/js/frontend.js', array ( 'jquery' ), '', true );
222 wp_register_script( 'icegram_chosen', $this->plugin_url . '/assets/js/chosen.jquery.js' , array ( 'jquery' ), '1.0' );
223 wp_register_script( 'icegram_ajax-chosen', $this->plugin_url . '/assets/js/ajax-chosen.jquery.min.js' , array ( 'icegram_chosen' ), '1.0' );
224 wp_register_script( 'icegram_tiptip', $this->plugin_url . '/assets/js/jquery.tipTip.min.js' , array ( 'jquery' ), get_bloginfo( 'version' ) );
225
226 wp_enqueue_script( 'icegram_writepanel' );
227 wp_enqueue_script( 'icegram_frontend_script' );
228 wp_enqueue_script( 'icegram_ajax-chosen' );
229 wp_enqueue_script( 'icegram_tiptip' );
230 wp_enqueue_script( 'thickbox' );
231
232 $icegram_witepanel_params = array ('ajax_url' => admin_url( 'admin-ajax.php' ), 'search_message_nonce' => wp_create_nonce( "search-messages" ) );
233 $icegram_available_headlines = apply_filters( 'icegram_available_headlines', array() );
234 $icegram_witepanel_params = array_merge( $icegram_witepanel_params, array( 'available_headlines' => $icegram_available_headlines ) );
235
236 wp_localize_script( 'icegram_writepanel', 'icegram_writepanel_params', $icegram_witepanel_params );
237
238 wp_enqueue_style( 'thickbox' );
239 wp_enqueue_style( 'wp-color-picker' );
240 wp_enqueue_style( 'icegram_admin_styles', $this->plugin_url . '/assets/css/admin.css' );
241 wp_enqueue_style( 'icegram_jquery-ui-style', $this->plugin_url . '/assets/css/jquery-ui.css' );
242 wp_enqueue_style( 'icegram_chosen_styles', $this->plugin_url . '/assets/css/chosen.css' );
243
244 if ( !wp_script_is( 'jquery-ui-datepicker' ) ) {
245 wp_enqueue_script( 'jquery-ui-datepicker' );
246 }
247
248 }
249
250 public static function get_platform() {
251 $platform = '';
252 $user_agent = trim(strtolower($_SERVER['HTTP_USER_AGENT']));
253 $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)/';
254 if ( preg_match( $pattern, $user_agent, $matches ) ) {
255 $platform = $matches[0];
256 }
257
258 switch ( $platform ) {
259
260 /* phones / smartphones */
261 case 'android 1':
262 case 'android 2':
263 case 'blackberry':
264 case 'iphone':
265 case 'ipod':
266 case 'iemobile':
267 case 'webos':
268 case 'palm':
269 case 'symbian':
270 case 'googlebot-mobile':
271 $platform = 'mobile';
272 break;
273
274 /* tablets */
275 case 'android 3':
276 case 'android 4':
277 case 'ipad':
278 case 'kindle':
279 $platform = 'tablet';
280 break;
281
282 /* desktops / laptops */
283 case 'windows':
284 case 'win64':
285 case 'wow64':
286 case 'macintosh':
287 case 'ppx mac os x':
288 case 'intel mac os x':
289 case 'googlebot':
290 $platform = 'laptop';
291 break;
292
293 /* in case nothing else matches */
294 default:
295 $platform = 'laptop';
296 break;
297 }
298 return $platform;
299 }
300
301 function get_message_data( $message_ids = array(), $preview = false ) {
302 global $wpdb;
303
304 $meta_key = $preview ? 'icegram_message_preview_data' : 'icegram_message_data';
305 $message_data_query = "SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE '$meta_key'";
306 if ( !empty( $message_ids ) && is_array( $message_ids ) ) {
307 $message_data_query .= " AND post_id IN ( " . implode( ',', $message_ids ) . " )";
308 }
309 $message_data_results = $wpdb->get_results( $message_data_query, 'ARRAY_A' );
310 $message_data = array();
311 foreach ( $message_data_results as $message_data_result ) {
312 $message_data[$message_data_result['post_id']] = maybe_unserialize( $message_data_result['meta_value'] );
313 }
314
315 return $message_data;
316 }
317
318 function get_valid_messages( $message_ids = array(), $campaign_ids = array(), $preview = false ) {
319
320 $valid_message_data = $this->get_message_data( array(), $preview );
321
322 $valid_messages = array();
323 $valid_campaigns = array();
324
325 if ( empty( $message_ids ) && empty( $campaign_ids ) ) {
326 $valid_campaigns = $this->get_valid_campaigns();
327 } else {
328 if ( !empty( $message_ids ) ) {
329
330 if( $preview ) {
331 foreach ( $message_ids as $message ) {
332 if ( empty( $valid_message_data[$message['id']] ) ) continue;
333 $message_data = $valid_message_data[$message['id']];
334 if ( !empty( $message_data ) ) {
335 $message_data['delay_time'] = $message['time'];
336 $message_data['campaign_id'] = !empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '';
337 $message_data['retargeting'] = '';
338 $valid_messages[] = $message_data;
339 }
340 }
341 } else {
342 foreach ( $message_ids as $message_id ) {
343 if ( empty( $valid_message_data[$message_id] ) ) continue;
344 $message_data = $valid_message_data[$message_id];
345 if ( !empty( $message_data ) ) {
346 $message_data['delay_time'] = 0;
347 $message_data['campaign_id'] = '';
348 $message_data['retargeting'] = '';
349 $valid_messages[] = $message_data;
350 }
351 }
352 }
353 }
354
355 if ( !empty( $campaign_ids ) ) {
356 foreach ( $campaign_ids as $campaign_id ) {
357 $valid_campaigns[$campaign_id] = new WP_Campaign( $campaign_id );
358 }
359 }
360
361 }
362
363 if ( !empty( $valid_campaigns ) ) {
364 foreach ( $valid_campaigns as $campaign_id => $campaign ) {
365 if ( !empty( $campaign->message_ids ) ) {
366 foreach ( $campaign->message_ids as $message ) {
367 $message_data = $valid_message_data[$message['id']];
368 if ( !empty( $message_data ) ) {
369 $campaign_rules = get_post_meta( $campaign_id, 'icegram_campaign_target_rules', true );
370 $message_data['delay_time'] = $message['time'];
371 $message_data['campaign_id'] = $campaign_id;
372 $message_data['retargeting'] = !empty( $campaign_rules['retargeting'] ) ? $campaign_rules['retargeting'] : '';
373 $valid_messages[] = $message_data;
374 }
375 }
376 }
377 }
378 }
379
380 return $valid_messages;
381
382 }
383
384 function get_valid_campaigns( $campaign_ids = array() ) {
385 global $wpdb;
386
387 if ( empty( $campaign_ids ) ) {
388 $search_text = serialize((string)self::$current_page_id);
389 $campaign_ids = $wpdb->get_col( "SELECT pm.post_id FROM {$wpdb->prefix}posts AS p LEFT JOIN {$wpdb->prefix}postmeta AS pm ON ( pm.post_id = p.ID ) WHERE pm.meta_key LIKE 'icegram_campaign_target_rules' AND pm.meta_value LIKE '%" . $search_text . "%' AND p.post_status LIKE 'publish'" );
390 }
391 $valid_campaigns = array();
392 foreach ( $campaign_ids as $campaign_id ) {
393 // if ( empty( $campaign_id['post_id'] ) ) continue;
394 $campaign = new WP_Campaign( $campaign_id );
395 if ( $campaign->is_valid() ) {
396 $valid_campaigns[$campaign_id] = $campaign;
397 }
398 }
399 return $valid_campaigns;
400 }
401
402 // Include all classes required for Icegram plugin
403 function include_classes() {
404
405 if ( ! class_exists( 'WP_Campaign' ) )
406 include_once( 'classes/class-wp-campaign.php' );
407
408 if ( ! class_exists( 'WP_Message' ) )
409 include_once( 'classes/class-wp-message.php' );
410
411 }
412
413 // Register Campaign post type
414 function register_campaign_post_type() {
415 $labels = array(
416 'name' => __( 'Campaigns', 'icegram' ),
417 'singular_name' => __( 'Campaign', 'icegram' ),
418 'add_new' => __( 'Add New Campaign', 'icegram' ),
419 'add_new_item' => __( 'Add New Campaign', 'icegram' ),
420 'edit_item' => __( 'Edit Campaign', 'icegram' ),
421 'new_item' => __( 'New Campaign', 'icegram' ),
422 'all_items' => __( 'Campaigns', 'icegram' ),
423 'view_item' => __( 'View Campaign', 'icegram' ),
424 'search_items' => __( 'Search Campaigns', 'icegram' ),
425 'not_found' => __( 'No campaigns found', 'icegram' ),
426 'not_found_in_trash' => __( 'No campaigns found in Trash', 'icegram' ),
427 'parent_item_colon' => __( '', 'icegram' ),
428 'menu_name' => __( 'Icegram', 'icegram' )
429 );
430
431 $args = array(
432 'labels' => $labels,
433 'menu_icon' => 'dashicons-info',
434 'public' => true,
435 'publicly_queryable' => true,
436 'show_ui' => true,
437 'show_in_menu' => true,
438 'query_var' => true,
439 'rewrite' => array( 'slug' => 'campaign' ),
440 'capability_type' => 'post',
441 'has_archive' => true,
442 'hierarchical' => false,
443 'menu_position' => null,
444 'supports' => array( 'title', 'editor' )
445 );
446
447 register_post_type( 'campaign', $args );
448 }
449
450 // Register Message promo type
451 function register_message_post_type() {
452 $labels = array(
453 'name' => __( 'Messages', 'icegram' ),
454 'singular_name' => __( 'Message', 'icegram' ),
455 'add_new' => __( 'Create New', 'icegram' ),
456 'add_new_item' => __( 'Create New Message', 'icegram' ),
457 'edit_item' => __( 'Edit Message', 'icegram' ),
458 'new_item' => __( 'New Message', 'icegram' ),
459 'all_items' => __( 'Messages', 'icegram' ),
460 'view_item' => __( 'View Message', 'icegram' ),
461 'search_items' => __( 'Search Messages', 'icegram' ),
462 'not_found' => __( 'No messages found', 'icegram' ),
463 'not_found_in_trash' => __( 'No messages found in Trash', 'icegram' ),
464 'parent_item_colon' => __( '', 'icegram' ),
465 'menu_name' => __( 'Messages', 'icegram' )
466 );
467
468 $args = array(
469 'labels' => $labels,
470 'public' => true,
471 'publicly_queryable' => true,
472 'show_ui' => true,
473 'show_in_menu' => 'edit.php?post_type=campaign',
474 'query_var' => true,
475 'rewrite' => array( 'slug' => 'message' ),
476 'capability_type' => 'post',
477 'has_archive' => true,
478 'hierarchical' => false,
479 'menu_position' => null,
480 'supports' => array( 'title' )
481 );
482
483 register_post_type( 'message', $args );
484 }
485
486 function import( $data = array() ) {
487
488 if ( empty( $data['campaigns'] ) && empty( $data['messages'] ) ) return;
489
490 $message_themes = apply_filters( 'icegram_all_message_theme', array() );
491
492 $default_themes = array();
493
494 foreach ( (array) $message_themes as $message_type => $available_themes ) {
495
496 reset( $available_themes );
497 $first_theme = key( $available_themes );
498 $default_themes[ $message_type ] = $first_theme;
499
500 }
501
502 $new_campaign_ids = array();
503
504 foreach ( (array) $data['campaigns'] as $campaign ) {
505
506 $args = array(
507 'post_content' => ( !empty( $campaign['post_content'] ) ) ? esc_attr( $campaign['post_content'] ) : '',
508 'post_name' => ( !empty( $campaign['post_title'] ) ) ? sanitize_title( $campaign['post_title'] ) : '',
509 'post_title' => ( !empty( $campaign['post_title'] ) ) ? $campaign['post_title'] : '',
510 'post_status' => ( !empty( $campaign['post_status'] ) ) ? $campaign['post_status'] : 'draft',
511 'post_type' => 'campaign'
512 );
513
514 $new_campaign_id = wp_insert_post( $args );
515 $new_campaign_ids[] = $new_campaign_id;
516
517 if ( !empty( $campaign['target_rules'] ) ) {
518
519 $defaults = array (
520 'homepage' => 'yes',
521 'when' => 'always',
522 'from' => '',
523 'to' => '',
524 'mobile' => 'yes',
525 'tablet' => 'yes',
526 'laptop' => 'yes',
527 'logged_in' => 'all'
528 );
529
530 $target_rules = wp_parse_args( $campaign['target_rules'], $defaults );
531 update_post_meta( $new_campaign_id, 'icegram_campaign_target_rules', $target_rules );
532 }
533
534 if ( !empty( $campaign['messages'] ) ) {
535
536 $messages = array();
537
538 foreach ( $campaign['messages'] as $message ) {
539
540 if ( !is_array( $message ) ) continue;
541
542 $args = array(
543 'post_content' => ( !empty( $message['message'] ) ) ? esc_attr( $message['message'] ) : '',
544 'post_name' => ( !empty( $message['post_title'] ) ) ? sanitize_title( $message['post_title'] ) : '',
545 'post_title' => ( !empty( $message['post_title'] ) ) ? $message['post_title'] : '',
546 'post_status' => ( !empty( $message['post_status'] ) ) ? $message['post_status'] : 'publish',
547 'post_type' => 'message'
548 );
549
550 $new_message_id = wp_insert_post( $args );
551 $new_message = array(
552 'id' => $new_message_id,
553 'time' => ( !empty( $message['time'] ) ) ? $message['time'] : 0
554 );
555 $messages[] = $new_message;
556
557 unset( $message['post_content'] );
558 unset( $message['time'] );
559
560 $message['id'] = $new_message_id;
561
562 $defaults = array (
563 'post_title' => '',
564 'type' => $first_theme,
565 'theme' => $default_themes,
566 'animation' => '',
567 'toast_animation' => '',
568 'title' => '',
569 'label' => '',
570 'link' => '',
571 'promo_image' => '',
572 'message' => '',
573 'position' => '',
574 'text_color' => '#000000',
575 'bg_color' => '#ffffff',
576 'id' => ''
577 );
578
579 $icegram_message_data = wp_parse_args( $message, $defaults );
580
581 if ( !empty( $icegram_message_data ) ) {
582 update_post_meta( $new_message_id, 'icegram_message_data', $icegram_message_data );
583 update_post_meta( $new_message_id, 'icegram_message_preview_data', $icegram_message_data );
584 }
585 }
586
587 if ( !empty( $campaign['messages'] ) ) {
588 update_post_meta( $new_campaign_id, 'messages', $messages );
589 update_post_meta( $new_campaign_id, 'campaign_preview', $messages );
590 }
591
592 }
593 }
594 if( !empty( $new_campaign_ids ) ) {
595 update_option( 'icegram_sample_data_imported', $new_campaign_ids );
596 }
597
598 }
599
600 function get_sample_data() {
601 global $icegram;
602 return array(
603 'campaigns' => array(
604 array(
605 'post_name' => '',
606 'post_title' => 'My First Icegram Campaign',
607 'target_rules' => array (
608 'homepage' => 'yes',
609 'when' => 'always',
610 'from' => '',
611 'to' => '',
612 'mobile' => 'yes',
613 'tablet' => 'yes',
614 'laptop' => 'yes',
615 'logged_in' => 'all'
616 ),
617 'messages' => array(
618 array (
619 'post_title' => 'Get 2x more Contacts with Your Website',
620 'post_status' => 'publish',
621 'time' => '0',
622 'type' => 'action-bar',
623 'theme' => array ( 'action-bar' => 'hello' ),
624 'animation' => 'slide',
625 'toast_animation' => 'effect1',
626 'title' => 'Get 2x more Contacts with Your Website',
627 'label' => 'Show Me How',
628 'link' => '',
629 'promo_image' => '',
630 'message' => 'Instant Results Guaranteed',
631 'position' => '01',
632 'text_color' => '#000000',
633 'bg_color' => '#eb593c'
634 ),
635 array (
636 'post_title' => '20% Off Coupon',
637 'post_status' => 'publish',
638 'time' => '4',
639 'type' => 'messenger',
640 'theme' => array ( 'messenger' => 'social' ),
641 'animation' => 'slide',
642 'toast_animation' => '',
643 'title' => '20% Off - for you',
644 'label' => '',
645 'link' => '',
646 'promo_image' => '',
647 'message' => "Hey there! We are running a <strong>special 20% off this week</strong> for registered users - like you.
648
649 Use coupon <code>LOYALTY20</code> during checkout.",
650 'position' => '22',
651 'text_color' => '#000000',
652 'bg_color' => '#ffffff'
653 ),
654 array (
655 'post_title' => 'How this blog makes over $34,800 / month for FREE.',
656 'post_status' => 'publish',
657 'time' => '10',
658 'type' => 'popup',
659 'theme' => array ( 'popup' => 'air-mail' ),
660 'animation' => '',
661 'toast_animation' => '',
662 'title' => 'How this blog makes over $34,800 / month for FREE.',
663 'label' => 'FREE INSTANT ACCESS',
664 'link' => '',
665 'promo_image' => '',
666 '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.
667
668 <strong>Download my free kit to learn how I do this.</strong>
669
670 <ul>
671 <li>How to choose blog topics that create long term value</li>
672 <li>The type of blog post that will make your site go viral</li>
673 <li>How to free yourself from the routine tasks</li>
674 <li>Resources and tips to get started quickly</li>
675 <li>Private members club to connect with fellow owners</li>
676 </ul>",
677 'text_color' => '#000000',
678 'bg_color' => '#ffffff'
679
680 ),
681 array (
682 'post_title' => 'Exclusive Marketing Report',
683 'post_status' => 'publish',
684 'time' => '6',
685 'type' => 'toast',
686 'theme' => array ( 'toast' => 'stand-out' ),
687 'animation' => '',
688 'toast_animation' => 'slide-down',
689 'title' => 'Exclusive Marketing Report',
690 'label' => '',
691 'link' => '',
692 'promo_image' => '',
693 'message' => 'FREE for every subscriber. Click here to download it.',
694 'position' => '02',
695 'text_color' => '#000000',
696 'bg_color' => '#ffffff'
697 )
698
699 )
700 )
701 )
702 );
703 }
704
705 function remove_preview_button() {
706 global $post_type;
707
708 if( $post_type == 'message' || $post_type == 'campaign' ) {
709
710 ?>
711 <style>
712 #preview-action { display:none; }
713 </style>
714 <?php
715
716 }
717
718 }
719
720 function remove_row_actions( $actions, $post ) {
721
722 if ( empty( $post->post_type ) || ( $post->post_type != 'campaign' && $post->post_type != 'message' ) ) return $actions;
723
724 unset( $actions['inline hide-if-no-js'] );
725 unset( $actions['view'] );
726
727 return $actions;
728
729 }
730
731 function identify_current_page() {
732 if ( is_page() ) {
733 global $post;
734 self::$current_page_id = $post->ID;
735 }
736 }
737
738 /**
739 * Our implementation of wpautop to preserve script and style tags
740 */
741 function before_wpautop($pee) {
742 if ( trim($pee) === '' ) {
743 $this->_wpautop_tags = array();
744 return '';
745 }
746
747 $tags = array();
748 // Pull out tags and add placeholders
749 list( $pee, $tags['pre'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'pre' );
750 list( $pee, $tags['script'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'script' );
751 list( $pee, $tags['style'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'style' );
752 $this->_wpautop_tags = $tags;
753
754 if( !empty( $pre_tags ) )
755 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $pre_tags );
756 if( !empty( $script_tags ) )
757 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $script_tags );
758 if( !empty( $style_tags ) )
759 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $style_tags );
760
761 return $pee;
762 }
763
764 function after_wpautop($pee) {
765 if ( trim($pee) === '' || empty($this->_wpautop_tags) )
766 return '';
767
768 // Replace placeholders with original content
769 if (!empty($this->_wpautop_tags['pre'])) {
770 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['pre'] );
771 }
772 if (!empty($this->_wpautop_tags['script'])) {
773 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['script'] );
774 }
775 if (!empty($this->_wpautop_tags['style'])) {
776 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['style'] );
777 }
778
779 $this->_wpautop_tags = array();
780
781 return $pee;
782 }
783
784
785 function _wpautop_add_tag_placeholders( $pee, $tag ) {
786 $tags = array();
787
788 if ( false !== strpos( $pee, "<{$tag}" ) ) {
789 $pee_parts = explode( "</{$tag}>", $pee );
790 $last_pee = array_pop( $pee_parts );
791 $pee = '';
792 $i = 0;
793
794 foreach ( $pee_parts as $pee_part ) {
795 $start = strpos( $pee_part, "<{$tag}" );
796
797 // Malformed html?
798 if ( false === $start ) {
799 $pee .= $pee_part;
800 continue;
801 }
802
803 $name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
804 $tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
805
806 $pee .= substr( $pee_part, 0, $start ) . $name;
807 $i++;
808 }
809
810 $pee .= $last_pee;
811 }
812
813 return array( $pee, $tags );
814 }
815
816
817 function _wpautop_replace_tag_placeholders( $pee, $tags ) {
818 if ( ! empty( $tags ) ) {
819 $pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
820 }
821
822 return $pee;
823 }
824
825
826 }
827
828 function initialize_icegram() {
829 global $icegram, $icegram_upgrader;
830
831 // i18n / l10n - load translations
832 load_plugin_textdomain( 'icegram', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
833
834 $icegram = new Icegram();
835
836 if ( ! class_exists( 'IceGram_Upgrade' ) ) {
837 require_once 'icegram-includes/class-icegram-upgrade.php';
838 }
839
840 $sku = 'icegram';
841 $prefix = 'icegram';
842 $plugin_name = 'Icegram ';
843 $text_domain = 'icegram';
844 $documentation_link = '';
845 $icegram_upgrader = new IceGram_Upgrade( __FILE__, $sku, $prefix, $plugin_name, $text_domain, $documentation_link );
846
847 }
848
849 add_action( 'plugins_loaded', 'initialize_icegram' );
850 register_activation_hook( __FILE__, array( 'Icegram', 'install' ) );