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

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