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