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

1,690 lines 80.8 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 - Popups, Optins, CTAs & lot more...
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.10.2
7 * Author: icegram
8 * Author URI: http://www.icegram.com/
9 * Copyright (c) 2014-16 Icegram
10 * License: GPLv3
11 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
12 *
13 * Text Domain: icegram
14 * Domain Path: /lang/
15 */
16
17 /**
18 * Main class Icegram
19 */
20 class Icegram {
21
22 var $plugin_url;
23 var $plugin_path;
24 var $version;
25 var $_wpautop_tags;
26 var $message_types;
27 var $message_type_objs;
28 var $shortcode_instances;
29 var $available_headlines;
30 var $mode;
31 var $cache_compatibility;
32
33 public static $current_page_id;
34
35 function __construct() {
36
37 $this->version = "1.10.2";
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 $this->cache_compatibility = get_option('icegram_cache_compatibility', 'no');
44
45 if( is_admin() && current_user_can( 'edit_posts' ) ) {
46 $ig_campaign_admin = Icegram_Campaign_Admin::getInstance();
47 $ig_message_admin = Icegram_Message_Admin::getInstance();
48 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_admin_styles_and_scripts' ) );
49 add_action( 'admin_print_styles', array( &$this, 'remove_preview_button' ) );
50 add_filter( 'post_row_actions', array( &$this , 'remove_row_actions' ), 10, 2 );
51
52 add_action( 'admin_menu', array( &$this, 'admin_menus') );
53 add_action( 'admin_init', array( &$this, 'welcome' ) );
54 add_action( 'admin_init', array( &$this, 'dismiss_admin_notice' ) );
55
56 add_action( 'admin_init', array( &$this, 'import_gallery_item' ) );
57
58 add_action( 'icegram_settings_after', array( &$this, 'klawoo_subscribe_form' ) );
59 add_action( 'icegram_about_changelog', array( &$this, 'klawoo_subscribe_form' ) );
60 add_action( 'icegram_settings_after', array( &$this, 'icegram_houskeeping' ) );
61 add_action( 'admin_notices', array( &$this,'add_admin_notices'));
62 add_filter('plugin_action_links', array($this, 'ig_plugin_settings_link'), 10, 2);
63 } else {
64 add_action( 'wp_footer', array( &$this, 'icegram_load_data' ));
65 }
66 if($this->cache_compatibility === 'no'){
67 add_action( 'wp_footer', array( &$this, 'display_messages' ) );
68 }
69 add_shortcode( 'icegram', array( &$this, 'execute_shortcode' ) );
70 add_shortcode( 'ig_form', array( &$this, 'execute_form_shortcode' ) );
71 // WPML compatibility
72 add_filter( 'icegram_identify_current_page', array( &$this, 'wpml_get_parent_id' ), 10 );
73
74 add_filter( 'icegram_branding_data', array( &$this , 'branding_data_remove' ), 10 );
75 add_action( 'wp_enqueue_scripts', array( &$this, 'identify_current_page' ) );
76 add_filter( 'icegram_get_valid_campaigns_sql', array( &$this , 'append_to_valid_campaigns_sql' ), 10, 2 );
77 add_action( 'icegram_print_js_css_data', array( &$this, 'print_js_css_data' ), 10, 1);
78 // common
79 add_action( 'init', array( &$this, 'register_campaign_post_type' ) );
80 add_action( 'init', array( &$this, 'register_message_post_type' ) );
81
82 add_action( 'icegram_loaded', array( &$this, 'load_compat_classes') );
83
84 // execute shortcode in sidebar
85 add_filter( 'widget_text', array(&$this, 'ig_widget_text_filter') );
86
87 add_filter( 'rainmaker_validate_request', array(&$this,'form_submission_validate_request'), 10, 2);
88 add_filter( 'icegram_data', array( $this, 'two_step_mobile_popup' ), 100, 1);
89
90
91 if ( defined( 'DOING_AJAX' ) ) {
92 if($this->cache_compatibility === 'yes'){
93 add_action( 'wp_ajax_display_messages', array( &$this, 'display_messages' ) );
94 add_action( 'wp_ajax_nopriv_display_messages', array( &$this, 'display_messages' ) );
95 }
96 add_action( 'wp_ajax_icegram_event_track', array( &$this, 'icegram_event_track' ) );
97 add_action( 'wp_ajax_nopriv_icegram_event_track', array( &$this, 'icegram_event_track' ) );
98 add_action( 'wp_ajax_klawoo_subscribe', array( &$this, 'klawoo_subscribe' ) );
99 add_action( 'wp_ajax_icegram_run_housekeeping', array( &$this, 'run_housekeeping' ) );
100
101 }
102
103 }
104 function ig_plugin_settings_link($links, $file){
105 if ($file == plugin_basename(__FILE__)){
106 $settings_link = '<a href="edit.php?post_type=ig_campaign&page=icegram-settings">'.__('Settings', 'icegram').'</a>';
107 $support_link = '<a href="edit.php?post_type=ig_campaign&page=icegram-support">'.__('Support', 'icegram').'</a>';
108 array_unshift($links, $support_link);
109 array_unshift($links, $settings_link);
110 }
111 return $links;
112
113 }
114
115 public function load_compat_classes() {
116
117 $compat_classes = (array) glob( $this->plugin_path . '/classes/compat/class-icegram-compat-*.php' );
118 if (empty($compat_classes)) {
119 return;
120 }
121
122 $active_plugins = (array) get_option('active_plugins', array());
123 if (is_multisite()) {
124 $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
125 }
126 $active_plugins = array_unique( array_merge( array_values($active_plugins), array_keys($active_plugins)) );
127 $active_plugins_with_slugs = array();
128 foreach ($active_plugins as $key => $value) {
129 $slug = dirname( $value );
130 if ($slug == '.') {
131 unset($active_plugins[$key]);
132 } else {
133 $active_plugins[ $key ] = $slug;
134 }
135 }
136
137 foreach ($compat_classes as $file) {
138 if (is_file ( $file )) {
139 $slug = str_replace('class-icegram-compat-', '', str_replace(".php", "", basename( $file )) );
140 if ( in_array($slug, $active_plugins)) {
141 include_once( $file );
142 $class_name = 'Icegram_Compat_'. str_replace('-', '_', $slug);
143 if ( class_exists( $class_name ) ) {
144 new $class_name();
145 }
146 }
147 }
148 }
149 }
150 public function add_admin_notices(){
151 $screen = get_current_screen();
152 if ( !in_array( $screen->id, array( 'ig_campaign', 'ig_message','edit-ig_message','edit-ig_campaign' ), true ) ) return;
153 $active_plugins = get_option( 'active_plugins', array() );
154 ?>
155 <style type="text/css">
156 div.icegram_notice {
157 border-left: 4px solid #7bcf3a;
158 padding: 1px 12px;
159 background-color: #FFF;
160 -webkit-box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
161 box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
162 margin: 15px 20px 10px 6px;
163 }
164 a.ig-admin-btn{
165 margin-left: 10px;
166 padding: 4px 8px;
167 position: relative;
168 text-decoration: none;
169 border: none;
170 -webkit-border-radius: 2px;
171 border-radius: 2px;
172 background: #e0e0e0;
173 text-shadow: none;
174 font-weight: 600;
175 font-size: 13px;
176 }
177 a.ig-admin-btn-secondary{
178 background: #fafafa;
179 margin-left: 20px;
180 font-weight: 400;
181 }
182
183 a.ig-admin-btn:hover{
184 color: #FFF;
185 background-color: #363b3f;
186 }
187 </style>
188 <?php
189 //Admin notice for Rainmaker
190 $admin_notice_for_rm = '';
191 if(current_user_can('install_plugins') && !in_array('icegram-rainmaker/icegram-rainmaker.php', $active_plugins) && !get_option('ig_rm_notice_icegram')){
192 $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . 'icegram-rainmaker'), 'install-plugin_' . 'icegram-rainmaker');
193 $admin_notice_text_for_rm = "Icegram recommends <b>Rainmaker</b>";
194 echo '<div class="notice notice-warning"> <p> '.$admin_notice_text_for_rm.'<a style="display:inline-block" class="ig-admin-btn" href="'.$url.'">'.__('Begin installation','icegram').'</a><a style="display:inline-block" class="ig-admin-btn ig-admin-btn-secondary" href="?dismiss_admin_notice=1&option_name=ig_rm_notice">'.__('No, I don\'t need it', 'icegram').'</a></p></div>';
195 }
196
197
198 }
199 public function dismiss_admin_notice(){
200 if(isset($_GET['dismiss_admin_notice']) && $_GET['dismiss_admin_notice'] == '1' && isset($_GET['option_name'])){
201 $option_name = sanitize_text_field($_GET['option_name']);
202 update_option($option_name.'_icegram', true);
203 wp_safe_redirect($_SERVER['HTTP_REFERER']);
204 exit();
205 }
206 }
207 public function klawoo_subscribe_form() {
208 ?>
209 <div class="wrap">
210 <?php
211 if ( stripos(get_current_screen()->base, 'settings') !== false ) {
212 echo "<h2>".__( 'Free Add-ons, Proven Marketing Tricks and Updates', 'icegram' )."</h2>";
213 }
214 ?>
215 <table class="form-table">
216 <tr>
217 <th scope="row"><?php _e( 'Get add-ons and tips...', 'icegram' ) ?></th>
218 <td>
219 <form name="klawoo_subscribe" action="#" method="POST" accept-charset="utf-8">
220 <input class="ltr" type="text" name="name" id="name" placeholder="Name"/>
221 <input class="regular-text ltr" type="text" name="email" id="email" placeholder="Email"/>
222 <input type="hidden" name="list" value="7I763v6Ldrs3YhJeee5EOgFA"/>
223 <input type="submit" name="submit" id="submit" class="button button-primary" value="Subscribe">
224 <br/>
225 <div id="klawoo_response"></div>
226 </form>
227 </td>
228 </tr>
229 </table>
230 </div>
231 <script type="text/javascript">
232 jQuery(function () {
233 jQuery("form[name=klawoo_subscribe]").submit(function (e) {
234 e.preventDefault();
235
236 jQuery('#klawoo_response').html('');
237 params = jQuery("form[name=klawoo_subscribe]").serializeArray();
238 params.push( {name: 'action', value: 'klawoo_subscribe' });
239
240 jQuery.ajax({
241 method: 'POST',
242 type: 'text',
243 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
244 data: params,
245 success: function(response) {
246 if (response != '') {
247 jQuery('#klawoo_response').html(response);
248 } else {
249 jQuery('#klawoo_response').html('error!');
250 }
251 }
252 });
253 });
254 });
255 </script>
256 <?php
257 }
258
259
260 public function klawoo_subscribe() {
261 $url = 'http://app.klawoo.com/subscribe';
262
263 if( !empty( $_POST ) ) {
264 $params = $_POST;
265 } else {
266 exit();
267 }
268 $method = 'POST';
269 $qs = http_build_query( $params );
270
271 $options = array(
272 'timeout' => 15,
273 'method' => $method
274 );
275
276 if ( $method == 'POST' ) {
277 $options['body'] = $qs;
278 } else {
279 if ( strpos( $url, '?' ) !== false ) {
280 $url .= '&'.$qs;
281 } else {
282 $url .= '?'.$qs;
283 }
284 }
285
286 $response = wp_remote_request( $url, $options );
287 if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
288 $data = $response['body'];
289 if ( $data != 'error' ) {
290
291 $message_start = substr( $data, strpos( $data,'<body>' ) + 6 );
292 $remove = substr( $message_start, strpos( $message_start,'</body>' ) );
293 $message = trim( str_replace( $remove, '', $message_start ) );
294 echo ( $message );
295 exit();
296 }
297 }
298 exit();
299 }
300
301 public function icegram_houskeeping(){
302 ?>
303 <div class="wrap">
304 <?php
305 if ( stripos(get_current_screen()->base, 'settings') !== false ) {
306 ?>
307 <form name="icegram_housekeeping" action="#" method="POST" accept-charset="utf-8">
308 <h2><?php _e( 'Housekeeping', 'icegram' ) ?></h2>
309 <p class="ig_housekeeping">
310 <label for="icegram_remove_shortcodes">
311 <input type="checkbox" name="icegram_remove_shortcodes" value="yes" />
312 <?php _e( 'Remove all Icegram shortcodes', 'icegram' ); ?>
313 </label>
314 <br/><br/>
315 <label for="icegram_remove_all_data">
316 <input type="checkbox" name="icegram_remove_all_data" value="yes" />
317 <?php _e( 'Remove all Icegram campaigns and messages', 'icegram' ); ?>
318 </label>
319 <br/><br/>
320 <img alt="" src="<?php echo admin_url( 'images/wpspin_light.gif' ) ?>" class="ig_loader" style="vertical-align:middle;display:none" />
321 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Clean Up', 'icegram' ); ?>">
322 <div id="icegram_housekeeping_response"></div>
323 </p>
324 </form>
325
326 </div>
327 <script type="text/javascript">
328 jQuery(function () {
329 jQuery("form[name=icegram_housekeeping]").submit(function (e) {
330 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){
331 e.preventDefault();
332 jQuery('.ig_loader').show();
333 jQuery('#icegram_housekeeping_response').text("");
334 params = jQuery("form[name=icegram_housekeeping]").serializeArray();
335 params.push( {name: 'action', value: 'icegram_run_housekeeping' });
336 params.push( {name: 'security', value: '<?php echo wp_create_nonce('ig_run_housekeeping'); ?> '});
337
338 jQuery.ajax({
339 method: 'POST',
340 type: 'text',
341 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
342 data: params,
343 success: function(response) {
344 jQuery('.ig_loader').hide();
345 jQuery('#icegram_housekeeping_response').text("<?php _e('Done!', 'icegram'); ?>");
346 }
347 });
348 }
349 });
350 });
351 </script>
352 <?php
353 }
354 }
355 public function run_housekeeping() {
356 check_ajax_referer('ig_run_housekeeping', 'security');
357 global $wpdb, $current_user;
358 $params = $_POST;
359 $_POST = array();
360 if(current_user_can( 'manage_options' ) && !empty($params['icegram_remove_shortcodes']) && $params['icegram_remove_shortcodes'] == 'yes') {
361 // first get all posts with [icegram] shortcode in them
362 $sql = "SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE '%[icegram %]%' and `post_type` != 'revision' ";
363 $posts = $wpdb->get_results($sql, OBJECT);
364 if ( !empty($posts) && is_array($posts) ) {
365 foreach ($posts as $post) {
366 $post_content = $post->post_content;
367 // remove shortcode with regexp now
368 $re = "/\\[icegram(.)*\\]/i";
369 $post_content = preg_replace($re, '', $post_content);
370 // save post content back
371 if ($post_content && $post_content != $post->post_content) {
372 wp_update_post( array ( 'ID' => $post->ID,
373 'post_content' => $post_content
374 ) );
375 }
376 }
377 }
378 }
379
380 if(!empty($params['icegram_remove_all_data']) && $params['icegram_remove_all_data'] == 'yes') {
381 $posts = get_posts( array( 'post_type' => array( 'ig_campaign', 'ig_message' ) ) );
382 if ( !empty($posts) && is_array($posts) ) {
383 foreach ($posts as $post) {
384 wp_delete_post( $post->ID, true);
385 }
386 }
387 do_action('icegram_remove_all_data');
388 }
389 $_POST = $params;
390 }
391
392 public function icegram_event_track() {
393 if( !empty($_POST['ig_local_url_cs']) && isset($_SERVER['HTTP_ORIGIN']) ){
394 $parts = parse_url($_POST['ig_local_url_cs']);
395 $base_url = $parts["scheme"] . "://" . $parts["host"];
396 header('Access-Control-Allow-Origin: '.$base_url);
397 header('Access-Control-Allow-Credentials: true');
398 }
399
400 if( !empty( $_POST['event_data'] ) ) {
401 foreach ( $_POST['event_data'] as $event ) {
402 switch ($event['type']) {
403 case 'shown':
404 if (is_array($event['params']) && !empty($event['params']['message_id'])) {
405 $messages_shown[] = $event['params']['message_id'];
406 if(!empty($event['params']['expiry_time'])){
407 if($event['params']['expiry_time'] =='today'){
408 $event['params']['expiry_time'] = strtotime('+1 day', mktime(0, 0, 0));
409 }else if($event['params']['expiry_time'] == 'current_session'){
410 $event['params']['expiry_time'] = 0;
411 }else{
412 $event['params']['expiry_time'] = strtotime($event['params']['expiry_time']);
413 }
414
415 $event['default'] = true;
416 $event = apply_filters('icegram_check_event_track', $event);
417 if($event['default']){
418 setcookie('icegram_campaign_shown_'.floor($event['params']['campaign_id']),true , $event['params']['expiry_time'] , '/');
419 }
420 }
421 }
422 break;
423 case 'clicked':
424 if (is_array($event['params']) && !empty($event['params']['message_id'])) {
425 $messages_clicked[] = $event['params']['message_id'];
426 if(!empty($event['params']['expiry_time_clicked'])){
427 if($event['params']['expiry_time_clicked'] =='today'){
428 $event['params']['expiry_time_clicked'] = strtotime('+1 day', mktime(0, 0, 0));
429 }else if($event['params']['expiry_time_clicked'] == 'current_session'){
430 $event['params']['expiry_time_clicked'] = 0;
431 }else{
432 $event['params']['expiry_time_clicked'] = strtotime($event['params']['expiry_time_clicked']);
433 }
434 //setcookie('icegram_messages_clicked_'.$event['params']['message_id'],true , $event['params']['expiry_time_clicked'] , '/' );
435 setcookie('icegram_campaign_clicked_'.floor($event['params']['campaign_id']),true , $event['params']['expiry_time_clicked'] , '/' );
436 }
437 }
438 break;
439
440 default:
441 break;
442 }
443
444 // Emit event for other plugins to handle it
445 do_action('icegram_event_track', $event);
446 do_action('icegram_event_track_'.$event['type'], $event['params']);
447 }
448 }
449 exit();
450 }
451
452 static function install() {
453 // Redirect to welcome screen
454 delete_option( '_icegram_activation_redirect' );
455 add_option( '_icegram_activation_redirect', 'pending' );
456 }
457
458 public function welcome() {
459
460 $this->db_update();
461 // Bail if no activation redirect transient is set
462 if ( false === get_option( '_icegram_activation_redirect' ) )
463 return;
464
465 // Delete the redirect transient
466 delete_option( '_icegram_activation_redirect' );
467
468 wp_redirect( admin_url( 'edit.php?post_type=ig_campaign&page=icegram-support' ) );
469 exit;
470 }
471
472 function db_update() {
473 $current_db_version = get_option( 'icegram_db_version' );
474 if ( !$current_db_version || version_compare( $current_db_version, '1.2', '<' ) ) {
475 include( 'updates/icegram-update-1.2.php' );
476 }
477 }
478
479 public function admin_menus() {
480
481 $welcome_page_title = __( 'Welcome to Icegram', 'icegram' );
482 $settings_page_title = __( 'Settings', 'icegram' );
483 $upgrade_page_title = '<span style="color:#f18500;font-weight:bolder;">'.__( 'Upgrade', 'icegram' ) .'</span>';
484
485 $menu_title = __( 'Docs & Support', 'icegram' );
486 $about = add_submenu_page( 'edit.php?post_type=ig_campaign', $welcome_page_title, $menu_title, 'manage_options', 'icegram-support', array( $this, 'about_screen' ) );
487 $settings = add_submenu_page( 'edit.php?post_type=ig_campaign', $settings_page_title, $settings_page_title, 'manage_options', 'icegram-settings', array( $this, 'settings_screen' ) );
488 $upgrade = add_submenu_page( 'edit.php?post_type=ig_campaign', $upgrade_page_title, $upgrade_page_title, 'manage_options', 'icegram-upgrade', array( $this, 'upgrade_screen' ) );
489
490 add_action( 'admin_print_styles-'. $about, array( $this, 'admin_css' ) );
491 add_action( 'admin_print_styles-'. $settings, array( $this, 'admin_css' ) );
492 add_action( 'admin_print_styles-'. $upgrade, array( $this, 'admin_css' ) );
493
494 }
495
496 public function admin_css() {
497 wp_enqueue_style( 'icegram-activation', $this->plugin_url . '/assets/css/admin.min.css' );
498 }
499
500 public function about_screen() {
501
502 // Import data if not done already
503 if( false === get_option( 'icegram_sample_data_imported' ) ) {
504 $this->import_sample_data( $this->get_sample_data() );
505 }
506
507 include ( 'about-icegram.php' );
508 }
509
510 public function settings_screen() {
511 include ( 'settings.php' );
512 }
513
514 public function upgrade_screen() {
515 // $ig_addons = $this->check_for_addons( true );
516 include ( 'addons.php' );
517 }
518
519 public function check_for_addons( $force_update = false ) {
520
521 if ( $force_update === true || false === ( $ig_addons = get_transient( 'icegram_addons_data' ) ) ) {
522 $ig_addons_json = wp_remote_get( 'http://icegram.com/addons.json', array( 'user-agent' => 'Icegram Addons' ) );
523
524 if ( ! is_wp_error( $ig_addons_json ) ) {
525 $ig_addons = json_decode( wp_remote_retrieve_body( $ig_addons_json ));
526 $addon_count = get_option( 'icegram_no_of_addons', 0 );
527 if ( !empty($ig_addons) && is_array($ig_addons) ) {
528 set_transient( 'icegram_addons_data', $ig_addons, 24 * HOUR_IN_SECONDS ); // 1 day
529 update_option( 'icegram_no_of_addons', count( $ig_addons ) - $addon_count ); // display count of newly added addons
530 }
531 }
532 }
533 return $ig_addons;
534 }
535
536 public function branding_data_remove( $icegram_branding_data ) {
537 if( !empty( $icegram_branding_data ) && 'yes' != get_option('icegram_share_love', 'no') ) {
538 $icegram_branding_data['powered_by_logo'] = '';
539 $icegram_branding_data['powered_by_text'] = '';
540 }
541 return $icegram_branding_data;
542 }
543
544 //Execute Form shortcode
545 function execute_form_shortcode( $atts = array() ) {
546 return '<div class="ig_form_container layout_inline"></div>';
547 }
548
549 function execute_shortcode( $atts = array() , $content = null ) {
550 // When shortcode is called, it will only prepare an array with conditions
551 // And add a placeholder div
552 // Display will happen in footer via display_messages()
553 $i = count($this->shortcode_instances);
554 $this->shortcode_instances[ $i ] = shortcode_atts( array(
555 'campaigns' => '',
556 'messages' => '',
557 'skip_others' => 'no'
558 ), $atts );
559
560 $class[] = "ig_shortcode_container";
561 $html[] = "<div id='icegram_shortcode_{$i}'";
562 if(!empty($atts['campaigns']) && !empty($content)){
563 $this->shortcode_instances[ $i ]['with_content'] = true;
564 $class[] = "trigger_onclick";
565 }
566 foreach ($atts as $key => $value) {
567 $value = str_replace(",", " ", $value);
568 $html[] = " data-{$key}=\"".htmlentities($value)."\" ";
569 }
570 $class = implode(" ", $class);
571 $html[] = "class='".$class."' >".$content."</div>";
572 return implode(" ", $html);
573 }
574
575 // Do not index Icegram campaigns / messages...
576 // Not using currently - made custom post types non public...
577 function icegram_load_data() {
578 global $post;
579 $icegram_pre_data['ajax_url'] = admin_url( 'admin-ajax.php' );
580 $icegram_pre_data['post_obj'] = $_GET;
581 $icegram_pre_data['post_obj']['is_home'] = (is_home() || is_front_page()) ? true : false;
582 $icegram_pre_data['post_obj']['page_id'] = is_object($post) && isset($post->ID) ? $post->ID : 0;
583 $icegram_pre_data['post_obj']['action'] = 'display_messages';
584 $icegram_pre_data['post_obj']['shortcodes'] = $this->shortcode_instances;
585 $icegram_pre_data['post_obj']['cache_compatibility'] = $this->cache_compatibility;
586 $icegram_pre_data['post_obj']['device'] = $this->get_platform();
587 wp_register_script('icegram_main_js', $this->plugin_url . '/assets/js/main.min.js', array ( 'jquery' ), $this->version, true);
588 if( !wp_script_is( 'icegram_main_js' ) ) {
589 wp_enqueue_script( 'icegram_main_js' );
590 wp_localize_script( 'icegram_main_js', 'icegram_pre_data', $icegram_pre_data);
591 }
592 }
593
594 function display_messages() {
595
596 $skip_others = $preview_mode = false;
597 $campaign_ids = $message_ids = array();
598 $this->shortcode_instances = ($this->cache_compatibility == 'yes' && !empty($_REQUEST['shortcodes'])) ? $_REQUEST['shortcodes'] : $this->shortcode_instances;
599 // Pull in message and campaign IDs from shortcodes - if set
600 if( !empty( $this->shortcode_instances ) ) {
601 foreach ($this->shortcode_instances as $i => $value) {
602 $cids = array_map( 'trim', (array) explode( ',', $value['campaigns'] ) );
603 $mids = array_map( 'trim', (array) explode( ',', $value['messages'] ) );
604 if (!empty($value['skip_others']) && $value['skip_others'] == 'yes' && (!empty($cids) || !empty($mids))) {
605 $skip_others = true;
606 }
607 $campaign_ids = array_merge($campaign_ids, $cids);
608 $message_ids = array_merge($message_ids, $mids);
609 }
610 }
611 if( !empty( $_REQUEST['campaign_preview_id'] ) && ( 'edit_posts' ) ) {
612 $campaign_ids = array( $_REQUEST['campaign_preview_id'] );
613 $preview_mode = true;
614 }
615
616
617 $messages = $this->get_valid_messages( $message_ids, $campaign_ids, $preview_mode, $skip_others );
618
619 if( empty( $messages ) ) {
620 //wp_die(0);
621 return;
622 }
623
624 $messages_to_show_ids = array();
625 foreach ( $messages as $key => $message_data ) {
626
627 if( !is_array( $message_data ) || empty( $message_data ) ) {
628 continue;
629 }
630
631 // Don't show a seen message again - if needed
632 // change to campaign targetting in v1.9.1
633 if( !empty( $message_data['id'] ) &&
634 empty( $_GET['campaign_preview_id'] ) &&
635 !empty( $message_data['retargeting'] ) &&
636 $message_data['retargeting'] == 'yes'
637 ) {
638 if(!empty($_COOKIE['icegram_messages_shown_'.$message_data['id']]) || !empty($_COOKIE['icegram_campaign_shown_'.floor($message_data['campaign_id'])])){
639 unset( $messages[$key] );
640 continue;
641 }
642 }
643 if( !empty( $message_data['id'] ) &&
644 empty( $_GET['campaign_preview_id'] ) &&
645 !empty( $message_data['retargeting_clicked'] ) &&
646 $message_data['retargeting_clicked'] == 'yes'
647 ) {
648 if(!empty($_COOKIE['icegram_messages_clicked_'.$message_data['id']]) || !empty($_COOKIE['icegram_campaign_clicked_'.floor($message_data['campaign_id'])])){
649 unset( $messages[$key] );
650 continue;
651 }
652 }
653
654 // Avoid showing the same message twice
655 if (in_array($message_data['id'], $messages_to_show_ids)) {
656 unset ( $messages[$key] );
657 continue;
658 } else {
659 $messages_to_show_ids[] = $message_data['id'];
660 }
661
662 $this->process_message_body($messages[$key]);
663 }
664 if( empty( $messages ) )
665 return;
666 $icegram_default = apply_filters( 'icegram_branding_data',
667 array ( 'icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
668 'powered_by_logo' => $this->plugin_url . '/assets/images/icegram-logo-branding-64-grey.png',
669 'powered_by_text' => __( 'Powered by Icegram', 'icegram' )
670 ) );
671 $messages = apply_filters( 'icegram_messages_to_show', $messages );
672 $icegram_data = apply_filters( 'icegram_data', array ( 'messages' => array_values( $messages ),
673 'ajax_url' => admin_url( 'admin-ajax.php' ),
674 'preview_id' => !empty( $_GET['campaign_preview_id'] ) ? $_GET['campaign_preview_id'] : '',
675 'defaults' => $icegram_default
676 ));
677 if (empty($icegram_data['preview_id'])) {
678 unset($icegram_data['preview_id']);
679 }
680
681 do_action('icegram_print_js_css_data', $icegram_data);
682
683 do_action('icegram_data_printed');
684 }
685
686 function two_step_mobile_popup( $icegram_data ) {
687
688 $temp = array();
689 foreach ($icegram_data['messages'] as $message_id => $message) {
690
691 if(!empty($message['ig_mobile_popup']) && $message['ig_mobile_popup'] == true){
692 $action_bar = $message;
693 $action_bar['type'] = 'action-bar';
694 $action_bar['theme'] = 'hello';
695 $action_bar['position'] = '21';
696 $action_bar['message'] = '';
697 $action_bar['label'] = __('Show More', 'icegram');
698 $action_bar['id'] = $action_bar['id'].'_00';
699 $action_bar['use_custom_code'] = 'yes';
700 $action_bar['form_html'] = '';
701 $action_bar['form_html_original'] = '';
702 $action_bar['rainmaker_form_code'] = '';
703 $action_bar['link'] = '';
704 $action_bar['redirect_to_link'] = '';
705 $action_bar['cta'] = '';
706 $action_bar['custom_css'] = '#ig_this_message .ig_close{display:none;}';
707 $action_bar['custom_js'] = "<script type='text/javascript'>jQuery('#icegram_message_".$action_bar['id']."').on('click', '.ig_button', function(){icegram.get_message_by_id('".$action_bar['id']."').hide(); icegram.get_message_by_id('".$message['id']."').show(); });</script>";
708 unset($action_bar['ig_mobile_popup']);
709 $temp[] = $action_bar;
710 }
711 }
712 $icegram_data['messages'] = array_merge($icegram_data['messages'], $temp);
713 unset($temp);
714
715 return $icegram_data;
716 }
717
718
719 function print_js_css_data( $icegram_data ) {
720
721 $this->collect_js_and_css($icegram_data);
722 if($this->cache_compatibility === 'yes'){
723 echo json_encode($icegram_data);
724 wp_die();
725 }else{
726 wp_localize_script('icegram_main_js', 'icegram_data', $icegram_data);
727 }
728 }
729
730 function collect_js_and_css(&$icegram_data){
731
732 $types_shown = array();
733 $scripts = array();
734 $css = array();
735 foreach ($icegram_data['messages'] as $key => $message_data) {
736 $types_shown[] = $message_data['type'];
737 }
738
739 $types_shown = array_unique($types_shown);
740 $ver_psfix = '?var=' .$this->version;
741
742 $scripts[] = $this->plugin_url ."/assets/js/icegram.min.js". $ver_psfix;
743 $css[] = $this->plugin_url ."/assets/css/frontend.min.css". $ver_psfix;
744 //minify and combine only for default msg type
745 $ig_core_message_types = array('popup', 'action-bar', 'toast', 'messenger');
746 // Load JS and default CSS
747 foreach ($types_shown as $message_type) {
748 if(!in_array($message_type, $ig_core_message_types)){
749 $scripts[] = $this->message_types[$message_type]['baseurl'] ."main.js". $ver_psfix;
750 $css[] = $this->message_types[$message_type]['baseurl'] . "default.css". $ver_psfix;
751 }else{
752 $css[] = $this->message_types[$message_type]['baseurl'].'themes/'. $message_type. ".min.css". $ver_psfix;
753 }
754 }
755
756 //TODO :: add theme pack theme css files too.
757 // Load theme CSS
758 foreach ($icegram_data['messages'] as $key => $message) {
759 if ( !empty( $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ]) ) {
760 $theme = $this->message_types[ $message['type'] ]['themes'][ $message['theme'] ]['baseurl'] . $message['theme'].'.css'. $ver_psfix;
761 }else{
762 $theme_default = $this->message_types[ $message['type']] ['settings']['theme']['default'];
763 $theme = $this->message_types[ $message['type'] ]['themes'][ $theme_default]['baseurl'] . $theme_default.'.css'. $ver_psfix;
764 $icegram_data['messages'][$key]['theme'] = $theme_default;
765 }
766 if(!preg_match('/icegram\/message-types/i', $theme)){
767 $css [] = $theme;
768 }
769 }
770 $css = array_unique($css);
771 $icegram_data['scripts'] = apply_filters('add_icegram_script' , $scripts);
772 $icegram_data['css'] = apply_filters('add_icegram_css' , $css);
773 return $icegram_data;
774 }
775
776 // Process
777 function process_message_body(&$message_data){
778 global $wp_scripts;
779 global $wp_styles;
780
781 if($this->cache_compatibility == 'yes'){
782 $q_script = !empty($wp_scripts->queue) ? $wp_scripts->queue : array();
783 $q_style = !empty($wp_styles->queue) ? $wp_styles->queue : array();
784 }
785 $content = $message_data['message'];
786 $content = convert_chars(convert_smilies( wptexturize( $content )));
787 if(isset($GLOBALS['wp_embed'])) {
788 $content = $GLOBALS['wp_embed']->autoembed($content);
789 }
790 $content = $this->after_wpautop( wpautop( $this->before_wpautop( $content ) ) );
791 $content = do_shortcode( shortcode_unautop( $content ) );
792 $message_data['message'] = $content;
793
794 //do_shortcode in headline
795 $message_data['headline'] = do_shortcode( shortcode_unautop( $message_data['headline'] ) );
796 //shortcode support for Third party forms and Rainmaker
797 $form_html_original = !empty($message_data["rainmaker_form_code"])
798 ? ('[rainmaker_form id="'. $message_data["rainmaker_form_code"] .'"]')
799 :(!empty($message_data['form_html_original']) ? $message_data['form_html_original'] : '');
800 if(!empty($form_html_original)){
801 $message_data['form_html'] = do_shortcode( shortcode_unautop( $form_html_original) );
802 }
803 //TODO :: Handle case for inline style and script
804 if($this->cache_compatibility == 'yes'){
805 $handles = !empty($wp_scripts->queue) ? array_diff($wp_scripts->queue, $q_script) : array();
806 unset($q_script);
807 if(!empty($handles)){
808 if(empty($message_data['assets']))
809 $message_data['assets'] = array();
810
811 ob_start();
812 $wp_scripts->do_items($handles);
813 $message_data['assets']['scripts'] = array_filter(explode('<script', ob_get_clean()));
814 }
815
816 //TODO :: do_items if required
817 $handles = !empty($wp_styles->queue) ? array_diff($wp_styles->queue, $q_style) : array();
818 unset($q_style);
819 if(!empty($handles)){
820 if(empty($message_data['assets']))
821 $message_data['assets'] = array();
822
823 foreach ($handles as $handle) {
824 ob_start();
825 $wp_styles->do_item($handle);
826 $message_data['assets']['styles'][$handle] = ob_get_clean();
827 }
828 }
829 }
830 }
831
832 function enqueue_admin_styles_and_scripts() {
833
834 $screen = get_current_screen();
835 if ( !in_array( $screen->id, array( 'ig_campaign', 'ig_message', 'edit-ig_campaign' ), true ) ) return;
836
837 // Register scripts
838 wp_register_script( 'icegram_writepanel', $this->plugin_url . '/assets/js/admin.min.js', array ( 'jquery', 'wp-color-picker' ), $this->version );
839
840 wp_enqueue_script( 'icegram_writepanel' );
841
842 $icegram_writepanel_params = array ( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'search_message_nonce' => wp_create_nonce( "search-messages" ), 'home_url' => home_url( '/' ) );
843 $this->available_headlines = apply_filters( 'icegram_available_headlines', array() );
844 $icegram_writepanel_params = array_merge( $icegram_writepanel_params, array( 'available_headlines' => $this->available_headlines ) );
845
846 wp_localize_script( 'icegram_writepanel', 'icegram_writepanel_params', $icegram_writepanel_params );
847
848 wp_enqueue_style( 'dashicons' );
849 wp_enqueue_style( 'wp-color-picker' );
850 wp_enqueue_style( 'icegram_admin_styles', $this->plugin_url . '/assets/css/admin.min.css', array(), $this->version );
851
852 if ( !wp_script_is( 'jquery-ui-datepicker' ) ) {
853 wp_enqueue_script( 'jquery-ui-datepicker' );
854 }
855
856 }
857
858 //execute shortcode in text widget
859 function ig_widget_text_filter($content){
860 if ( ! preg_match( '/\[[\r\n\t ]*icegram?[\r\n\t ].*?\]/', $content ) )
861 return $content;
862
863 $content = do_shortcode( $content );
864
865 return $content;
866 }
867
868 public static function get_platform() {
869 $mobile_detect = new Ig_Mobile_Detect();
870 $mobile_detect->setUserAgent();
871 if($mobile_detect->isMobile()){
872 return ($mobile_detect->isTablet()) ? 'tablet' : 'mobile';
873 }else if($mobile_detect->isTablet()){
874 return 'tablet';
875 }
876 return 'laptop';
877 }
878
879 function get_message_data( $message_ids = array(), $preview = false ) {
880 global $wpdb;
881 $message_data = array();
882 $original_message_id_map = array();
883 $meta_key = $preview ? 'icegram_message_preview_data' : 'icegram_message_data';
884 $message_data_query = "SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE '$meta_key'";
885 if ( !empty( $message_ids ) && is_array( $message_ids ) ) {
886 // For WPML compatibility
887 if ( function_exists('icl_object_id') ) {
888 $wpml_settings = get_option('icl_sitepress_settings');
889 $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;
890
891 foreach ($message_ids as $i=>$id ) {
892 $translated = icl_object_id( $id, 'ig_message', $original_if_missing );
893 $message_ids[ $i ] = $translated;
894 $original_message_id_map[ $translated ] = $id;
895 }
896 }
897 $message_ids = array_filter(array_unique($message_ids));
898 if ( !empty( $message_ids ) ) {
899 $message_data_query .= " AND post_id IN ( " . implode( ',', $message_ids ) . " )";
900 $message_data_results = $wpdb->get_results( $message_data_query, 'ARRAY_A' );
901 foreach ( $message_data_results as $message_data_result ) {
902 $data = maybe_unserialize( $message_data_result['meta_value'] );
903 if (!empty($data)) {
904 $message_data[$message_data_result['post_id']] = $data;
905 // For WPML compatibility
906 if (!empty( $original_message_id_map[ $message_data_result['post_id'] ])) {
907 $message_data[$message_data_result['post_id']]['original_message_id'] = $original_message_id_map[ $message_data_result['post_id'] ];
908 }
909 }
910 }
911 }
912 }
913
914 return $message_data;
915 }
916
917 function get_valid_messages( $message_ids = array(), $campaign_ids = array(), $preview_mode = false, $skip_others = false) {
918 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));
919
920 $valid_messages = $valid_campaigns = $message_campaign_map = array();
921
922 $campaign_ids = array_filter(array_unique( (array) $campaign_ids));
923 $message_ids = array_filter(array_unique( (array) $message_ids));
924 if ( !empty( $campaign_ids ) ) {
925 $valid_campaigns = $this->get_valid_campaigns( $campaign_ids, true ,$preview_mode);
926 }
927
928 // When skip_others is true, we won't load campaigns / messages from db
929 if (!$skip_others && !$preview_mode) {
930 $campaigns = $this->get_valid_campaigns();
931 if (!empty($campaigns)) {
932 foreach ($campaigns as $id => $campaign) {
933 if (!array_key_exists($id, $valid_campaigns)) {
934 $valid_campaigns[ $id ] = $campaign;
935 }
936 }
937 }
938 }
939
940 // Create a map to look up campaign id for a given message
941 if( !empty( $valid_campaigns ) ) {
942 foreach ($valid_campaigns as $id => $campaign) {
943 if ($preview_mode) {
944 $campaign->messages = get_post_meta( $id, 'campaign_preview', true );
945 }
946 if( !empty( $campaign->messages ) ) {
947 foreach( $campaign->messages as $msg) {
948 $message_ids[] = $msg['id'];
949 if (!array_key_exists( $msg['id'], $message_campaign_map)) {
950 $message_campaign_map[ $msg['id'] ] = $id;
951 }
952 }
953 }
954 }
955 }
956
957 // We don't display same message twice...
958 $message_ids = array_unique($message_ids);
959
960 if( empty( $message_ids ) ) {
961 return array();
962 }
963 $valid_messages = $this->get_message_data( $message_ids, $preview_mode );
964
965 foreach ($valid_messages as $id => $message_data) {
966 // Remove message if required fields are missing
967 if (empty($message_data) || empty($message_data['type'])) {
968 unset( $valid_messages[$id] );
969 continue;
970 }
971 // Remove message if message type is uninstalled
972 $class_name = 'Icegram_Message_Type_' . str_replace(' ', '_', ucwords(str_replace('-', ' ', $message_data['type'])));
973 if( !class_exists( $class_name ) ) {
974 unset( $valid_messages[$id] );
975 continue;
976 }
977 $message_data['delay_time'] = 0;
978 $message_data['retargeting'] = '';
979 $message_data['campaign_id'] = ($preview_mode) ? $_REQUEST['campaign_preview_id'] : '';
980
981 // Pull display time and retargeting rule from campaign if possible
982 $message_id = (!empty($message_data['original_message_id'])) ? $message_data['original_message_id'] : $id;
983 if (!empty($message_campaign_map[ $message_id ])) {
984 //modify campaign id
985 $message_data['campaign_id'] = apply_filters('modify_campaing_id' , $message_campaign_map[ $message_id ] , $message_id) ;
986 $campaign = $valid_campaigns[ floor($message_data['campaign_id']) ];
987 if (!empty($campaign) && $campaign instanceof Icegram_Campaign) {
988 $message_meta_from_campaign = $campaign->get_message_meta_by_id( $message_id );
989 if (!empty($message_meta_from_campaign['time'])) {
990 $message_data['delay_time'] = $message_meta_from_campaign['time'];
991 }
992
993 //check if campaign is targeted to mobile at zero
994 $device_rule = $campaign->get_rule_value('device');
995 if($this->get_platform() !== 'laptop' && !empty($device_rule['mobile']) && $device_rule['mobile'] == 'yes'&& $message_data['delay_time'] == 0 && $message_data['type'] == 'popup'){
996 $message_data['ig_mobile_popup'] = true;
997 if(!empty($message_data['triggers']) && !empty($message_data['triggers']['when_to_show'])){
998 $message_data['ig_mobile_popup'] = ($message_data['triggers']['when_to_show'] == 'duration_on_page' && $message_data['triggers']['duration_on_page'] == 0 ) ? true : false;
999 }
1000 }
1001 //set delay time -1 if shortcode with content
1002 foreach ($this->shortcode_instances as $i => $value) {
1003 $campaign_ids = explode( ',', $value['campaigns']);
1004 if(!empty($value['with_content']) && in_array($message_data['campaign_id'], $campaign_ids)){
1005 $message_data['delay_time'] = -1;
1006 }
1007 }
1008 $rule_value = $campaign->get_rule_value('retargeting');
1009 $message_data['retargeting'] = !empty( $rule_value['retargeting'] ) ? $rule_value['retargeting'] : '';
1010 $message_data['expiry_time'] = !empty( $rule_value['retargeting'] ) ? $rule_value['expiry_time'] : '';
1011 $rule_value_retargeting_clicked = $campaign->get_rule_value('retargeting_clicked');
1012 $message_data['retargeting_clicked'] = !empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['retargeting_clicked'] : '';
1013 $message_data['expiry_time_clicked'] = !empty( $rule_value_retargeting_clicked['retargeting_clicked'] ) ? $rule_value_retargeting_clicked['expiry_time_clicked'] : '';
1014
1015 }
1016 }
1017 $valid_messages[$id] = $message_data;
1018 }
1019 $valid_messages = apply_filters( 'icegram_valid_messages', $valid_messages );
1020
1021 return $valid_messages;
1022 }
1023
1024 function get_valid_campaigns( $campaign_ids = array(), $skip_page_check = false ,$preview_mode = false) {
1025 global $wpdb;
1026 if ( empty( $campaign_ids ) ) {
1027 $sql = "SELECT pm.post_id
1028 FROM {$wpdb->prefix}posts AS p
1029 LEFT JOIN {$wpdb->prefix}postmeta AS pm ON ( pm.post_id = p.ID )
1030 WHERE p.post_status = 'publish' ";
1031 // Filter handler within this file (and possibly others) will append to this SQL
1032 // and provide arguments for wpdb->prepare if needed.
1033 // First element in the array is SQL, remaining are values for placeholders in SQL
1034 $sql_params = apply_filters( 'icegram_get_valid_campaigns_sql', array($sql), array() );
1035 $campaign_ids = $wpdb->get_col( $wpdb->prepare( array_shift($sql_params), $sql_params ) );
1036 }
1037 $valid_campaigns = array();
1038 foreach ( (array) $campaign_ids as $campaign_id ) {
1039 $campaign = new Icegram_Campaign( $campaign_id );
1040 if ( $preview_mode || $campaign->is_valid( array('skip_page_check' => $skip_page_check) ) ) {
1041 $valid_campaigns[$campaign_id] = $campaign;
1042 } else {
1043 // Campgain is invalid!
1044 }
1045
1046 }
1047 $valid_campaigns = apply_filters('icegram_valid_campaigns', $valid_campaigns);
1048 return $valid_campaigns;
1049 }
1050
1051 function append_to_valid_campaigns_sql( $sql_params = array(), $options = array() ) {
1052 // Page check conditions
1053 //$pid = $_GET['page_id'];
1054 $pid = Icegram::get_current_page_id();
1055 $sql = " AND (
1056 pm.meta_key = 'icegram_campaign_target_rules' AND (
1057 ( pm.meta_value LIKE '%%%s%%' )
1058 OR ( pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' AND pm.meta_value LIKE '%%%s%%' )
1059 ";
1060 $sql_params[] = 's:8:"sitewide";s:3:"yes";';
1061 $sql_params[] = 's:10:"other_page";s:3:"yes";';
1062 $sql_params[] = 's:7:"page_id";a:';
1063 $sql_params[] = serialize( (string) $pid );
1064 //local url
1065 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
1066 $sql_params[] = 's:9:"local_url";s:3:"yes";';
1067 if(!empty($_REQUEST['cache_compatibility']) && $_REQUEST['cache_compatibility'] == 'yes'){
1068 $is_home = (!empty($_REQUEST['is_home']) && $_REQUEST['is_home'] === 'true') ? true : false ;
1069 }else{
1070 $is_home = (is_home() || is_front_page()) ? true : false;
1071 }
1072 if ($is_home === true ) {
1073 $sql .= " OR ( pm.meta_value LIKE '%%%s%%' )";
1074 $sql_params[] = 's:8:"homepage";s:3:"yes";';
1075 }
1076 $sql .=" ) )";
1077
1078 $sql_params[0] .= $sql;
1079 //s:9:"logged_in";s:3:"all";
1080
1081 return $sql_params;
1082 }
1083
1084 // Include all classes required for Icegram plugin
1085 function include_classes() {
1086
1087 $classes = glob( $this->plugin_path . '/classes/*.php' );
1088 foreach ( $classes as $file ) {
1089 // Files with 'admin' in their name are included only for admin section
1090 if ( is_file( $file ) && ( (strpos($file, '-admin') >= 0 && is_admin()) || (strpos($file, '-admin') === false) ) ) {
1091 include_once $file;
1092 }
1093 }
1094
1095 // Load built in message types
1096 $icegram_message_type_basedirs = glob( $this->plugin_path . '/message-types/*' );
1097 // Allow other plugins to add new message types
1098 $icegram_message_type_basedirs = apply_filters( 'icegram_message_type_basedirs', $icegram_message_type_basedirs );
1099 // Set up different message type classes
1100 foreach ( $icegram_message_type_basedirs as $dir ) {
1101 $type = basename ( $dir );
1102 $class_file = $dir . "/main.php";
1103 if( is_file( $class_file ) ) {
1104 include_once( $class_file );
1105 }
1106 $class_name = 'Icegram_Message_Type_' . str_replace(' ', '_', ucwords(str_replace('-', ' ', $type)));
1107 if (class_exists($class_name)) {
1108 $this->message_type_objs[ $type ] = new $class_name();
1109 }
1110 }
1111 do_action('ig_file_include');
1112 $this->message_types = apply_filters( 'icegram_message_types', array() );
1113 }
1114
1115 // Register Campaign post type
1116 function register_campaign_post_type() {
1117 $labels = array(
1118 'name' => __( 'Campaigns', 'icegram' ),
1119 'singular_name' => __( 'Campaign', 'icegram' ),
1120 'add_new' => __( 'Add New Campaign', 'icegram' ),
1121 'add_new_item' => __( 'Add New Campaign', 'icegram' ),
1122 'edit_item' => __( 'Edit Campaign', 'icegram' ),
1123 'new_item' => __( 'New Campaign', 'icegram' ),
1124 'all_items' => __( 'Campaigns', 'icegram' ),
1125 'view_item' => __( 'View Campaign', 'icegram' ),
1126 'search_items' => __( 'Search Campaigns', 'icegram' ),
1127 'not_found' => __( 'No campaigns found', 'icegram' ),
1128 'not_found_in_trash' => __( 'No campaigns found in Trash', 'icegram' ),
1129 'parent_item_colon' => __( '', 'icegram' ),
1130 'menu_name' => __( 'Icegram', 'icegram' )
1131 );
1132
1133 $args = array(
1134 'labels' => $labels,
1135 'menu_icon' => 'dashicons-info',
1136 'public' => false,
1137 'publicly_queryable' => false,
1138 'show_ui' => true,
1139 'show_in_menu' => true,
1140 'query_var' => true,
1141 'rewrite' => array( 'slug' => 'ig_campaign' ),
1142 'capability_type' => 'post',
1143 'has_archive' => false,
1144 'hierarchical' => false,
1145 'menu_position' => null,
1146 'menu_icon' => $this->plugin_url . '/assets/images/icegram-logo-branding-18-white.png' ,
1147 'supports' => array( 'title', 'editor' )
1148 );
1149
1150 register_post_type( 'ig_campaign', $args );
1151 }
1152
1153 // Register Message post type
1154 function register_message_post_type() {
1155 $labels = array(
1156 'name' => __( 'Messages', 'icegram' ),
1157 'singular_name' => __( 'Message', 'icegram' ),
1158 'add_new' => __( 'Create New', 'icegram' ),
1159 'add_new_item' => __( 'Create New Message', 'icegram' ),
1160 'edit_item' => __( 'Edit Message', 'icegram' ),
1161 'new_item' => __( 'New Message', 'icegram' ),
1162 'all_items' => __( 'Messages', 'icegram' ),
1163 'view_item' => __( 'View Message', 'icegram' ),
1164 'search_items' => __( 'Search Messages', 'icegram' ),
1165 'not_found' => __( 'No messages found', 'icegram' ),
1166 'not_found_in_trash' => __( 'No messages found in Trash', 'icegram' ),
1167 'parent_item_colon' => __( '', 'icegram' ),
1168 'menu_name' => __( 'Messages', 'icegram' )
1169 );
1170
1171 $args = array(
1172 'labels' => $labels,
1173 'public' => false,
1174 'publicly_queryable' => false,
1175 'show_ui' => true,
1176 'show_in_menu' => 'edit.php?post_type=ig_campaign',
1177 'query_var' => true,
1178 'rewrite' => array( 'slug' => 'ig_message' ),
1179 'capability_type' => 'post',
1180 'has_archive' => false,
1181 'hierarchical' => false,
1182 'menu_position' => null,
1183 'supports' => array( 'title' )
1184 );
1185
1186 register_post_type( 'ig_message', $args );
1187 }
1188
1189
1190 function import( $data = array() ) {
1191 if ( empty( $data['campaigns'] ) && empty( $data['messages'] ) ) return;
1192
1193 $default_theme = $default_type = '';
1194 $first_message_type = current( $this->message_types );
1195
1196 if( is_array( $first_message_type ) ) {
1197 $default_type = $first_message_type['type'];
1198 if( !empty( $first_message_type['themes'] ) ) {
1199 $default_theme = key( $first_message_type['themes'] );
1200 }
1201 }
1202
1203 $new_campaign_ids = array();
1204 foreach ( (array) $data['campaigns'] as $campaign ) {
1205
1206 $args = array(
1207 'post_content' => ( !empty( $campaign['post_content'] ) ) ? esc_attr( $campaign['post_content'] ) : '',
1208 'post_name' => ( !empty( $campaign['post_title'] ) ) ? sanitize_title( $campaign['post_title'] ) : '',
1209 'post_title' => ( !empty( $campaign['post_title'] ) ) ? $campaign['post_title'] : '',
1210 'post_status' => ( !empty( $campaign['post_status'] ) ) ? $campaign['post_status'] : 'draft',
1211 'post_type' => 'ig_campaign'
1212 );
1213
1214 $new_campaign_id = wp_insert_post( $args );
1215 $new_campaign_ids[] = $new_campaign_id;
1216
1217 if ( !empty( $campaign['target_rules'] ) ) {
1218
1219 $defaults = array (
1220 'homepage' => 'yes',
1221 'when' => 'always',
1222 'from' => '',
1223 'to' => '',
1224 'mobile' => 'yes',
1225 'tablet' => 'yes',
1226 'laptop' => 'yes',
1227 'logged_in' => 'all'
1228 );
1229
1230 $target_rules = wp_parse_args( $campaign['target_rules'], $defaults );
1231 update_post_meta( $new_campaign_id, 'icegram_campaign_target_rules', $target_rules );
1232 }
1233
1234 if ( !empty( $campaign['messages'] ) ) {
1235
1236 $messages = array();
1237
1238 foreach ( $campaign['messages'] as $message ) {
1239
1240 if ( !is_array( $message ) ) continue;
1241
1242 $args = array(
1243 'post_content' => ( !empty( $message['message'] ) ) ? esc_attr( $message['message'] ) : '',
1244 'post_name' => ( !empty( $message['post_title'] ) ) ? sanitize_title( $message['post_title'] ) : '',
1245 'post_title' => ( !empty( $message['post_title'] ) ) ? $message['post_title'] : '',
1246 'post_status' => ( !empty( $message['post_status'] ) ) ? $message['post_status'] : 'publish',
1247 'post_type' => 'ig_message'
1248 );
1249
1250 $new_message_id = wp_insert_post( $args );
1251 $new_message = array(
1252 'id' => $new_message_id,
1253 'time' => ( !empty( $message['time'] ) ) ? $message['time'] : 0
1254 );
1255 //for gallery + CTA another message
1256 if(!empty($message['cta']) && $message['cta'] == 'cta_another_message' && !empty($message['cta_linked_message_id']) && $message['cta_linked_message_id'] == 'auto'){
1257 $prev_message = end($messages);
1258 $message['cta_linked_message_id'] = $prev_message['id'];
1259 array_pop($messages);
1260 }
1261 $messages[] = $new_message;
1262
1263 unset( $message['post_content'] );
1264 unset( $message['time'] );
1265
1266 $message['id'] = $new_message_id;
1267
1268 $defaults = array (
1269 'post_title' => '',
1270 'type' => $default_type,
1271 'theme' => $default_theme,
1272 'animation' => '',
1273 'headline' => '',
1274 'label' => '',
1275 'link' => '',
1276 'icon' => '',
1277 'message' => '',
1278 'position' => '',
1279 'text_color' => '#000000',
1280 'bg_color' => '#ffffff',
1281 'custom_code' => '',
1282 'id' => ''
1283 );
1284 $icegram_message_data = wp_parse_args( $message, $defaults );
1285 if ( !empty( $icegram_message_data ) ) {
1286 update_post_meta( $new_message_id, 'icegram_message_data', $icegram_message_data );
1287 update_post_meta( $new_message_id, 'icegram_message_preview_data', $icegram_message_data );
1288 }
1289 }//foreach
1290
1291 if ( !empty( $campaign['messages'] ) ) {
1292 update_post_meta( $new_campaign_id, 'messages', $messages );
1293 update_post_meta( $new_campaign_id, 'campaign_preview', $messages );
1294 }
1295 }//if
1296 }
1297 return $new_campaign_ids;
1298
1299 }
1300
1301 function import_sample_data ($data = array() ){
1302 $new_campaign_ids = $this->import($data);
1303 if( !empty( $new_campaign_ids ) ) {
1304 update_option( 'icegram_sample_data_imported', $new_campaign_ids );
1305 }
1306 }
1307
1308 function import_gallery_item(){
1309 if(!empty($_REQUEST['action']) && $_REQUEST['action'] == 'fetch_messages' && !empty($_REQUEST['campaign_id']) && !empty($_REQUEST['gallery_item'])){
1310 $params = $_REQUEST;
1311 $imported_gallery_items = array();
1312 $url = 'http://www.icegram.com/gallery/wp-admin/admin-ajax.php';
1313 $options = array(
1314 'timeout' => 15,
1315 'method' => 'POST',
1316 'body' => http_build_query( $params )
1317 );
1318 $response = wp_remote_request( $url, $options );
1319 $response_code = wp_remote_retrieve_response_code( $response );
1320 if ( $response_code == 200 ) {
1321 $new_campaign_ids = $this->import(json_decode($response['body'] ,true));
1322 if(!empty($new_campaign_ids)){
1323 $imported_gallery_items = get_option('ig_imported_gallery_items');
1324 $imported_gallery_items[] = $_REQUEST['gallery_item'];
1325 update_option( 'ig_imported_gallery_items', $imported_gallery_items );
1326 $location = admin_url( 'post.php?post='.$new_campaign_ids[0].'&action=edit');
1327 header('Location:'.$location);
1328 exit;
1329 }else{
1330 wp_safe_redirect($_SERVER['HTTP_REFERER']);
1331 }
1332 }
1333 }
1334 }
1335 function get_sample_data() {
1336
1337 return array(
1338 'campaigns' => array(
1339 array(
1340 'post_name' => '',
1341 'post_title' => 'My First Icegram Campaign',
1342 'target_rules' => array (
1343 'homepage' => 'yes',
1344 'when' => 'always',
1345 'from' => '',
1346 'to' => '',
1347 'mobile' => 'yes',
1348 'tablet' => 'yes',
1349 'laptop' => 'yes',
1350 'logged_in' => 'all'
1351 ),
1352 'messages' => array(
1353 array (
1354 'post_title' => 'Get 2x more Contacts with Your Website',
1355 'post_status' => 'publish',
1356 'time' => '0',
1357 'type' => 'action-bar',
1358 'theme' => 'hello',
1359 'headline' => 'Get 2x more Contacts with Your Website',
1360 'label' => 'Show Me How',
1361 'link' => '',
1362 'icon' => '',
1363 'message' => 'Instant Results Guaranteed',
1364 'position' => '01',
1365 'text_color' => '#000000',
1366 'bg_color' => '#eb593c'
1367 ),
1368 array (
1369 'post_title' => '20% Off Coupon',
1370 'post_status' => 'publish',
1371 'time' => '4',
1372 'type' => 'messenger',
1373 'theme' => 'social',
1374 'animation' => 'slide',
1375 'headline' => '20% Off - for you',
1376 'label' => '',
1377 'link' => '',
1378 'icon' => '',
1379 'message' => "Hey there! We are running a <strong>special 20% off this week</strong> for registered users - like you.
1380
1381 Use coupon <code>LOYALTY20</code> during checkout.",
1382 'position' => '22',
1383 'text_color' => '#000000',
1384 'bg_color' => '#ffffff'
1385 ),
1386 array (
1387 'post_title' => 'How this blog makes over $34,800 / month for FREE.',
1388 'post_status' => 'publish',
1389 'time' => '10',
1390 'type' => 'popup',
1391 'theme' => 'air-mail',
1392 'headline' => 'How this blog makes over $34,800 / month for FREE.',
1393 'label' => 'FREE INSTANT ACCESS',
1394 'link' => '',
1395 'icon' => '',
1396 '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.
1397
1398 <strong>Download my free kit to learn how I do this.</strong>
1399
1400 <ul>
1401 <li>How to choose blog topics that create long term value</li>
1402 <li>The type of blog post that will make your site go viral</li>
1403 <li>How to free yourself from the routine tasks</li>
1404 <li>Resources and tips to get started quickly</li>
1405 <li>Private members club to connect with fellow owners</li>
1406 </ul>",
1407 'text_color' => '#000000',
1408 'bg_color' => '#ffffff'
1409
1410 ),
1411 array (
1412 'post_title' => 'Exclusive Marketing Report',
1413 'post_status' => 'publish',
1414 'time' => '6',
1415 'type' => 'toast',
1416 'theme' => 'stand-out',
1417 'animation' => 'pop',
1418 'headline' => 'Exclusive Marketing Report',
1419 'label' => '',
1420 'link' => '',
1421 'icon' => '',
1422 'message' => 'FREE for every subscriber. Click here to download it.',
1423 'position' => '02',
1424 'text_color' => '#000000',
1425 'bg_color' => '#ffffff'
1426 )
1427
1428 )
1429 )
1430 )
1431 );
1432 }
1433
1434 function remove_preview_button() {
1435 global $post_type;
1436 if( $post_type == 'ig_message' || $post_type == 'ig_campaign' ) {
1437 ?>
1438 <style type="text/css">
1439 #message.updated.below-h2{ display: none; }
1440 #preview-action { display:none; }
1441 </style>
1442 <?php
1443 }
1444 }
1445
1446
1447 function remove_row_actions( $actions, $post ) {
1448
1449 if ( empty( $post->post_type ) || ( $post->post_type != 'ig_campaign' && $post->post_type != 'ig_message' ) ) return $actions;
1450
1451 unset( $actions['inline hide-if-no-js'] );
1452 unset( $actions['view'] );
1453
1454 return $actions;
1455
1456 }
1457
1458 function identify_current_page() {
1459 global $post, $wpdb;
1460
1461 $obj = get_queried_object();
1462 $id = 0;
1463 if( !empty( $obj->has_archive ) ) {
1464 $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $obj->has_archive ) );
1465 } elseif( is_object( $post ) && isset( $post->ID ) ) {
1466 $id = $post->ID;
1467 }
1468 $id = apply_filters('icegram_identify_current_page', $id );
1469 self::$current_page_id = $id;
1470 }
1471
1472 static function get_current_page_id() {
1473 global $post;
1474 if (!empty($_REQUEST['page_id']) && is_numeric($_REQUEST['page_id'])) {
1475 $post = get_post($_REQUEST['page_id']);
1476 setup_postdata( $post );
1477 // WPML check
1478 $id = apply_filters('icegram_identify_current_page', $post->ID );
1479 self::$current_page_id = $id;
1480 }
1481 return self::$current_page_id;
1482 }
1483 static function get_current_page_url() {
1484 if(!empty($_REQUEST['cache_compatibility']) && $_REQUEST['cache_compatibility'] == 'yes'){
1485 $pageURL = (!empty($_REQUEST['referral_url'])) ? $_REQUEST['referral_url'] : '';
1486 }else{
1487 $pageURL = 'http';
1488 if( isset($_SERVER["HTTPS"]) ) {
1489 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
1490 }
1491 $pageURL .= "://";
1492 if ($_SERVER["SERVER_PORT"] != "80") {
1493 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
1494 } else {
1495 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
1496 }
1497 }
1498 return $pageURL;
1499 }
1500
1501 function wpml_get_parent_id( $id ) {
1502 global $post;
1503 if (function_exists('icl_object_id') && function_exists('icl_get_default_language') ) {
1504 $id = icl_object_id($id, $post->post_type, true, icl_get_default_language() );
1505 }
1506 return $id;
1507 }
1508
1509
1510 /**
1511 * Our implementation of wpautop to preserve script and style tags
1512 */
1513 function before_wpautop($pee) {
1514 if ( trim($pee) === '' ) {
1515 $this->_wpautop_tags = array();
1516 return '';
1517 }
1518
1519 $tags = array();
1520 // Pull out tags and add placeholders
1521 list( $pee, $tags['pre'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'pre' );
1522 list( $pee, $tags['script'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'script' );
1523 list( $pee, $tags['style'] ) = $this->_wpautop_add_tag_placeholders( $pee, 'style' );
1524 $this->_wpautop_tags = $tags;
1525
1526 if( !empty( $pre_tags ) )
1527 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $pre_tags );
1528 if( !empty( $script_tags ) )
1529 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $script_tags );
1530 if( !empty( $style_tags ) )
1531 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $style_tags );
1532
1533 return $pee;
1534 }
1535
1536 function after_wpautop($pee) {
1537 if ( trim($pee) === '' || empty($this->_wpautop_tags) )
1538 return '';
1539
1540 // Replace placeholders with original content
1541 if (!empty($this->_wpautop_tags['pre'])) {
1542 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['pre'] );
1543 }
1544 if (!empty($this->_wpautop_tags['script'])) {
1545 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['script'] );
1546 }
1547 if (!empty($this->_wpautop_tags['style'])) {
1548 $pee = $this->_wpautop_replace_tag_placeholders( $pee, $this->_wpautop_tags['style'] );
1549 }
1550
1551 $this->_wpautop_tags = array();
1552
1553 return $pee;
1554 }
1555
1556 function _wpautop_add_tag_placeholders( $pee, $tag ) {
1557 $tags = array();
1558
1559 if ( false !== strpos( $pee, "<{$tag}" ) ) {
1560 $pee_parts = explode( "</{$tag}>", $pee );
1561 $last_pee = array_pop( $pee_parts );
1562 $pee = '';
1563 $i = 0;
1564
1565 foreach ( $pee_parts as $pee_part ) {
1566 $start = strpos( $pee_part, "<{$tag}" );
1567
1568 // Malformed html?
1569 if ( false === $start ) {
1570 $pee .= $pee_part;
1571 continue;
1572 }
1573
1574 $name = "<{$tag} wp-{$tag}-tag-$i></{$tag}>";
1575 $tags[ $name ] = substr( $pee_part, $start ) . "</{$tag}>";
1576
1577 $pee .= substr( $pee_part, 0, $start ) . $name;
1578 $i++;
1579 }
1580
1581 $pee .= $last_pee;
1582 }
1583
1584 return array( $pee, $tags );
1585 }
1586
1587 function _wpautop_replace_tag_placeholders( $pee, $tags ) {
1588 if ( ! empty( $tags ) ) {
1589 $pee = str_replace( array_keys( $tags ), array_values( $tags ), $pee );
1590 }
1591
1592 return $pee;
1593 }
1594
1595 static function duplicate_in_db( $original_id){
1596 // Get access to the database
1597 global $wpdb;
1598 // Get the post as an array
1599 $duplicate = get_post( $original_id, 'ARRAY_A' );
1600 // Modify some of the elements
1601 $duplicate['post_title'] = $duplicate['post_title'].' '.__('Copy', 'icegram');
1602 $duplicate['post_status'] = 'draft';
1603 // Set the post date
1604 $timestamp = current_time('timestamp', 0);
1605
1606 $duplicate['post_date'] = date('Y-m-d H:i:s', $timestamp);
1607
1608 // Remove some of the keys
1609 unset( $duplicate['ID'] );
1610 unset( $duplicate['guid'] );
1611 unset( $duplicate['comment_count'] );
1612
1613 // Insert the post into the database
1614 $duplicate_id = wp_insert_post( $duplicate );
1615
1616 // Duplicate all taxonomies/terms
1617 $taxonomies = get_object_taxonomies( $duplicate['post_type'] );
1618
1619 foreach( $taxonomies as $taxonomy ) {
1620 $terms = wp_get_post_terms( $original_id, $taxonomy, array('fields' => 'names') );
1621 wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
1622 }
1623
1624 // Duplicate all custom fields
1625 $custom_fields = get_post_custom( $original_id );
1626 foreach ( $custom_fields as $key => $value ) {
1627 if($key === 'messages'){
1628 $messages = unserialize($value[0]);
1629 foreach ($messages as &$message) {
1630 $clone_msg_id = Icegram::duplicate_in_db($message['id']);
1631 $message['id'] = $clone_msg_id;
1632 }
1633 $value[0] = serialize($messages);
1634 }
1635 add_post_meta( $duplicate_id, $key, maybe_unserialize($value[0]) );
1636 }
1637 return $duplicate_id;
1638 }
1639
1640 static function duplicate( $original_id){
1641 $duplicate_id = Icegram::duplicate_in_db($original_id);
1642 $location = admin_url( 'post.php?post='.$duplicate_id.'&action=edit');
1643 header('Location:'.$location);
1644 exit;
1645 }
1646
1647 public static function form_submission_validate_request($request_data){
1648 if(!empty($request_data)){
1649 // Check for Remote Rainmaker form submission request
1650 $request_data['ig_is_remote'] = false;
1651 $request_data['is_remote'] = false;
1652 if(!empty($request_data['ig_mode']) && $request_data['ig_mode'] === 'remote'){
1653 $ig_remote_url = $request_data['ig_remote_url'];
1654 if(!empty($request_data['ig_campaign_id'])){
1655 $rules = get_post_meta( $request_data['ig_campaign_id'], 'icegram_campaign_target_rules', true );
1656 if( !empty($rules['remote_urls']) && is_array($rules['remote_urls']) ){
1657 foreach ($rules['remote_urls'] as $remote_url_pattern) {
1658 $valid = Icegram_Campaign::is_valid_url($remote_url_pattern , $ig_remote_url);
1659 if( $valid ){
1660 $request_data['ig_is_remote'] = true;
1661 $request_data['is_remote'] = true;
1662 break;
1663 }
1664 }
1665 //TODO :: discard the the remote request and data
1666 // if($request_data['ig_is_remote'] == false){
1667 // return array();
1668 // }
1669 }
1670
1671 }
1672 }
1673 }
1674 return $request_data;
1675 }
1676 }
1677
1678
1679 function initialize_icegram() {
1680 global $icegram;
1681
1682 // i18n / l10n - load translations
1683 load_plugin_textdomain( 'icegram', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
1684
1685 $icegram = new Icegram();
1686 do_action('icegram_loaded');
1687 }
1688
1689 add_action( 'plugins_loaded', 'initialize_icegram' );
1690 register_activation_hook( __FILE__, array( 'Icegram', 'install' ) );