| 1 |
<?php |
| 2 |
|
| 3 |
class EasyOptInsPostTypes { |
| 4 |
|
| 5 |
public $settings; |
| 6 |
|
| 7 |
private $activity_day_interval = array( |
| 8 |
'form_list' => null, |
| 9 |
'dashboard_widget' => 30 |
| 10 |
); |
| 11 |
|
| 12 |
private $targeting_cat_path = 'assets/vendor/targeting-cat/TargetingCat-OptinCat-1.2.min.js'; |
| 13 |
|
| 14 |
private $two_step_ids_on_page = array(); |
| 15 |
|
| 16 |
public function __construct( $settings ) { |
| 17 |
|
| 18 |
$this->settings = $settings; |
| 19 |
|
| 20 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 21 |
|
| 22 |
// Register custom post type |
| 23 |
add_action( 'init', array( $this, 'register_custom_post_type' ) ); |
| 24 |
add_filter( 'manage_easy-opt-ins_posts_columns', array( $this, 'add_new_columns' ) ); |
| 25 |
add_action( 'manage_easy-opt-ins_posts_custom_column', array( $this, 'set_column_data' ), 10, 2 ); |
| 26 |
add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 ); |
| 27 |
|
| 28 |
// Reset action |
| 29 |
add_action( 'admin_post_fca_eoi_reset_stats', array( $this, 'reset_stats' ) ); |
| 30 |
|
| 31 |
// Dashboard widget |
| 32 |
add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); |
| 33 |
|
| 34 |
// Save |
| 35 |
add_action( 'save_post', array( $this, 'save_meta_box_content' ), 1, 2 ); |
| 36 |
|
| 37 |
// Live preview |
| 38 |
add_filter( 'the_content', array( $this, 'live_preview' ) ); |
| 39 |
|
| 40 |
// Scripts and styles |
| 41 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) ); |
| 42 |
|
| 43 |
add_action( 'admin_head', array( $this, 'hide_minor_publishing' ) ); |
| 44 |
|
| 45 |
add_action( 'admin_notices', array( $this, 'onboard_help' ), 1 ); |
| 46 |
|
| 47 |
if ( $this->settings['distribution'] === 'free' ) { |
| 48 |
add_action( 'admin_notices', array( $this, 'review_notice' ) ); |
| 49 |
} |
| 50 |
|
| 51 |
add_filter( 'admin_body_class', array( $this, 'add_body_class' ) ); |
| 52 |
|
| 53 |
add_filter( 'wp_insert_post_data', array( $this, 'force_published' ) ); |
| 54 |
|
| 55 |
add_action( 'wp_ajax_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) ); |
| 56 |
add_action( 'wp_ajax_nopriv_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) ); |
| 57 |
|
| 58 |
add_action( 'wp_ajax_fca_eoi_dismiss', array( $this, 'ajax_dismiss_notice' ) ); |
| 59 |
|
| 60 |
add_filter( 'get_user_option_screen_layout_easy-opt-ins', array( $this, 'force_one_column' ) ); |
| 61 |
|
| 62 |
add_filter( 'get_user_option_meta-box-order_easy-opt-ins', array( $this, 'order_columns' ) ); |
| 63 |
|
| 64 |
add_filter( 'post_updated_messages', array( $this, 'override_text' ) ); |
| 65 |
|
| 66 |
add_filter( 'bulk_actions-edit-easy-opt-ins', array( $this, 'disable_bulk_edit' ) ); |
| 67 |
|
| 68 |
add_filter( 'post_row_actions', array( $this, 'remove_quick_edit' ) ); |
| 69 |
|
| 70 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 71 |
|
| 72 |
add_filter( 'enter_title_here', array( $this, 'change_default_title' ) ); |
| 73 |
|
| 74 |
add_filter( 'init', array( $this, 'bind_content_filter' ), 10 ); |
| 75 |
|
| 76 |
add_filter( 'template_redirect', array( $this, 'parse_tc_condition_request' ), 1 ); |
| 77 |
|
| 78 |
add_filter( 'plugin_action_links_' . FCA_EOI_PLUGIN_BASENAME, array( $this, 'add_plugin_action_links' ) ); |
| 79 |
|
| 80 |
//ADD ACTIONS TO GET THE ENTIRE PAGE OUTPUT IN BUFFER |
| 81 |
|
| 82 |
if ( wp_get_theme() == 'Customizr' ) { |
| 83 |
add_filter( 'the_content', array( $this, 'scan_for_shortcodes' ) ); |
| 84 |
} else { |
| 85 |
add_action('wp_head', array( $this, 'fca_eoi_buffer_start' )); |
| 86 |
add_action('wp_footer', array( $this, 'fca_eoi_buffer_end' )); |
| 87 |
} |
| 88 |
|
| 89 |
add_filter( 'init', array( $this, 'request_prepare_lightbox' ) ); |
| 90 |
|
| 91 |
add_filter( 'wp_footer', array( $this, 'show_lightbox' ) ); |
| 92 |
|
| 93 |
foreach ( $providers_available as $provider ) { |
| 94 |
add_action( 'wp_ajax_fca_eoi_' . $provider . '_get_lists', $provider . '_ajax_get_lists' ); |
| 95 |
} |
| 96 |
|
| 97 |
// Hook provder callback functions |
| 98 |
foreach ( $providers_available as $provider ) { |
| 99 |
add_filter( 'fca_eoi_alter_admin_notices', $provider . '_admin_notices', 10, 1 ); |
| 100 |
} |
| 101 |
|
| 102 |
// Handle licensing |
| 103 |
if( count( $providers_available ) > 1 ) { |
| 104 |
require_once FCA_EOI_PLUGIN_DIR . 'includes/licensing.php'; |
| 105 |
new EasyOptInsLicense( $this->settings ); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
public function add_plugin_action_links( $links ) { |
| 110 |
$url = admin_url('post-new.php?post_type=easy-opt-ins'); |
| 111 |
|
| 112 |
$new_links = array( |
| 113 |
'addnew' => "<a href='$url' >" . __('Add New Optin Form', 'easy-opt-ins' ) . '</a>' |
| 114 |
); |
| 115 |
|
| 116 |
$links = array_merge( $new_links, $links ); |
| 117 |
|
| 118 |
return $links; |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
function fca_eoi_buffer_start() { ob_start(array( $this, 'scan_for_shortcodes' )); } |
| 123 |
function fca_eoi_buffer_end() { ob_end_flush(); } |
| 124 |
|
| 125 |
public function register_custom_post_type() { |
| 126 |
|
| 127 |
$labels = array( |
| 128 |
'name' => __('Optin Forms') , |
| 129 |
'singular_name' => __('Optin Form') , |
| 130 |
'add_new' => __('Add New') , |
| 131 |
'add_new_item' => __('Add New Optin Form') , |
| 132 |
'edit_item' => __('Edit Optin Form') , |
| 133 |
'new_item' => __('New Optin Form') , |
| 134 |
'all_items' => __('All Optin Forms') , |
| 135 |
'view_item' => __('View Optin Form') , |
| 136 |
'search_items' => __('Search Optin Form') , |
| 137 |
'not_found' => __('No Optin Form Found') , |
| 138 |
'not_found_in_trash' => __('No Optin Form Found in Trash') , |
| 139 |
'parent_item_colon' => '', |
| 140 |
'menu_name' => __('Optin Forms') |
| 141 |
); |
| 142 |
$args = array( |
| 143 |
'menu_icon' => FCA_EOI_PLUGIN_URL . '/icon.png', |
| 144 |
'labels' => $labels, |
| 145 |
'public' => false, |
| 146 |
'exclude_from_search' => true, |
| 147 |
'publicly_queryable' => false, |
| 148 |
'show_ui' => true, |
| 149 |
'show_in_menu' => true, |
| 150 |
'query_var' => true, |
| 151 |
'rewrite' => array( |
| 152 |
'slug' => 'easy-opt-ins', |
| 153 |
) , |
| 154 |
'capability_type' => 'page', |
| 155 |
'has_archive' => false, |
| 156 |
'hierarchical' => false, |
| 157 |
'menu_position' => 105, |
| 158 |
'supports' => array( |
| 159 |
'title', |
| 160 |
) , |
| 161 |
'register_meta_box_cb' => array( |
| 162 |
$this, |
| 163 |
'add_meta_boxes' |
| 164 |
) |
| 165 |
); |
| 166 |
register_post_type('easy-opt-ins', $args); |
| 167 |
} |
| 168 |
|
| 169 |
private function enqueue_activity_style() { |
| 170 |
wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.css', array(), FCA_EOI_VER ); |
| 171 |
} |
| 172 |
|
| 173 |
public function add_new_columns( $columns ) { |
| 174 |
$new_columns = array(); |
| 175 |
|
| 176 |
if ( ! empty( $columns['cb'] ) ) { |
| 177 |
$new_columns['cb'] = $columns['cb']; |
| 178 |
} |
| 179 |
|
| 180 |
if ( ! empty( $columns['title'] ) ) { |
| 181 |
$new_columns['title'] = $columns['title']; |
| 182 |
} |
| 183 |
|
| 184 |
$this->enqueue_activity_style(); |
| 185 |
$activity = EasyOptInsActivity::get_instance(); |
| 186 |
|
| 187 |
$period = |
| 188 |
'<span class="fca_eoi_activity_period">(' . |
| 189 |
$activity->get_text( 'period', null, array( $this->activity_day_interval['form_list'] ) ) . |
| 190 |
')</span>'; |
| 191 |
|
| 192 |
foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ) { |
| 193 |
$new_columns[ $activity_type ] = esc_html( $activity->get_text( $activity_type, 'form' ) ) . '<br>' . $period; |
| 194 |
} |
| 195 |
|
| 196 |
return $new_columns; |
| 197 |
} |
| 198 |
|
| 199 |
public function set_column_data( $column_name, $form_id ) { |
| 200 |
$activity = EasyOptInsActivity::get_instance(); |
| 201 |
|
| 202 |
$stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] ); |
| 203 |
$value = 0; |
| 204 |
|
| 205 |
if ( ! empty( $stats[ $column_name ][ $form_id ] ) ) { |
| 206 |
$value = $stats[ $column_name ][ $form_id ]; |
| 207 |
} |
| 208 |
|
| 209 |
echo $activity->format_column_text( $column_name, $value ); |
| 210 |
} |
| 211 |
|
| 212 |
public function post_row_actions( $actions, $post ) { |
| 213 |
if ( $post->post_type == 'easy-opt-ins' ) { |
| 214 |
$action = 'fca_eoi_reset_stats'; |
| 215 |
$title = __( 'Reset stats for this item' ); |
| 216 |
$label = __( 'Reset Stats' ); |
| 217 |
|
| 218 |
$url = add_query_arg( 'action', $action, admin_url( 'admin-post.php?post=' . $post->ID ) ); |
| 219 |
$url = wp_nonce_url( $url ); |
| 220 |
|
| 221 |
$actions[$action] = $this->confirm_tag( |
| 222 |
'<a href="' . $url . '" title="' . $title . '">' . $label . '</a>', |
| 223 |
__( 'Are you sure?' ), |
| 224 |
__( 'Do you really want to reset this Optin Form\'s stats? This action cannot be undone.' ) |
| 225 |
); |
| 226 |
} |
| 227 |
return $actions; |
| 228 |
} |
| 229 |
|
| 230 |
public function reset_stats() { |
| 231 |
if ( wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { |
| 232 |
EasyOptInsActivity::get_instance()->reset_stats( (int) $_REQUEST['post'] ); |
| 233 |
wp_redirect( wp_get_referer() ); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
private function confirm_tag( $tag, $title, $message ) { |
| 238 |
return preg_replace( |
| 239 |
'/>/', |
| 240 |
' onclick="return confirm(' . |
| 241 |
esc_html( '"' . $title . '\n\n' . $message . '"' ) . |
| 242 |
')">', |
| 243 |
$tag, 1 ); |
| 244 |
} |
| 245 |
|
| 246 |
public function dashboard_setup() { |
| 247 |
|
| 248 |
if ( defined ( 'FCA_EOI_DISABLE_STATS_TRACKING' )) { |
| 249 |
$title = 'Optin Cat Summary (TRACKING DISABLED)'; |
| 250 |
} else { |
| 251 |
$title = 'Optin Cat Summary'; |
| 252 |
} |
| 253 |
add_meta_box( |
| 254 |
'fca_eoi_dashboard_widget', |
| 255 |
$title, |
| 256 |
array( $this, 'add_dashboard_widget' ), |
| 257 |
'dashboard', |
| 258 |
'normal', |
| 259 |
'high' |
| 260 |
); |
| 261 |
} |
| 262 |
|
| 263 |
public function add_dashboard_widget() { |
| 264 |
wp_enqueue_script( 'd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/d3.min.js', array(), FCA_EOI_VER, true ); |
| 265 |
wp_enqueue_script( 'nvd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.js', array(), FCA_EOI_VER, true ); |
| 266 |
wp_enqueue_style( 'nvd3_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.css', array(), FCA_EOI_VER ); |
| 267 |
$this->enqueue_activity_style(); |
| 268 |
|
| 269 |
$day_interval = $this->activity_day_interval['dashboard_widget']; |
| 270 |
$activity = EasyOptInsActivity::get_instance(); |
| 271 |
$stats = $activity->get_daily_stats( $day_interval ); |
| 272 |
|
| 273 |
$date_labels = array(); |
| 274 |
foreach ( array_keys( $stats['impressions'] ) as $date ) { |
| 275 |
$date_labels[] = strftime( '%e %b', strtotime( $date ) ); |
| 276 |
} |
| 277 |
|
| 278 |
$colors = array( |
| 279 |
'impressions' => '#5b90bf', |
| 280 |
'conversions' => '#bf616a' |
| 281 |
); |
| 282 |
|
| 283 |
?> |
| 284 |
<div class="fca_eoi_activity_chart_title_container"> |
| 285 |
<div class="fca_eoi_activity_chart_legend"> |
| 286 |
<?php foreach ( array( 'impressions', 'conversions' ) as $activity_type ): ?> |
| 287 |
<div class="fca_eoi_activity_chart_legend_item"> |
| 288 |
<div class="fca_eoi_activity_chart_legend_sample" style="background-color: <?php echo $colors[ $activity_type ] ?>;"></div> |
| 289 |
<div class="fca_eoi_activity_chart_legend_text"> |
| 290 |
<?php echo esc_html( $activity->get_text( $activity_type, 'total' ) ) ?> |
| 291 |
</div> |
| 292 |
</div> |
| 293 |
<?php endforeach ?> |
| 294 |
</div> |
| 295 |
<div class="fca_eoi_activity_chart_period"> |
| 296 |
<?php echo esc_html( $activity->get_text( 'period', null, array( $day_interval ) ) ) ?> |
| 297 |
- |
| 298 |
<a href="<?php echo admin_url( 'edit.php?post_type=easy-opt-ins' ) ?>"><?php echo __( 'View All Data' ) ?></a> |
| 299 |
</div> |
| 300 |
</div> |
| 301 |
<div class="fca_eoi_activity_chart" id="fca_eoi_activity_chart"></div> |
| 302 |
<div class="fca_eoi_activity_chart_stat"> |
| 303 |
<?php foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ): ?> |
| 304 |
<div class="fca_eoi_activity_chart_stat_item"> |
| 305 |
<div class="fca_eoi_activity_chart_stat_value"> |
| 306 |
<?php echo $activity->format_column_text( $activity_type, $stats['totals'][ $activity_type ] ) ?> |
| 307 |
</div> |
| 308 |
<div class="fca_eoi_activity_chart_stat_title"> |
| 309 |
<?php echo esc_html( $activity->get_text( $activity_type, 'total' ) ) ?> |
| 310 |
</div> |
| 311 |
</div> |
| 312 |
<?php endforeach ?> |
| 313 |
</div> |
| 314 |
<script> |
| 315 |
jQuery( function() { |
| 316 |
var impressions = <?php echo json_encode( array_values( $stats['impressions'] ) ) ?>; |
| 317 |
var conversions = <?php echo json_encode( array_values( $stats['conversions'] ) ) ?>; |
| 318 |
var dates = <?php echo json_encode( $date_labels ) ?>; |
| 319 |
|
| 320 |
var chart = nv.models.lineChart().options({ |
| 321 |
duration: 0, |
| 322 |
transitionDuration: 0, |
| 323 |
useInteractiveGuideline: true, |
| 324 |
isArea: true, |
| 325 |
showLegend: false, |
| 326 |
margin: { top: 10, right: 20, bottom: 30, left: 40 } |
| 327 |
} ); |
| 328 |
|
| 329 |
chart.xAxis.tickFormat( function( index ) { return dates[ index ]; } ); |
| 330 |
chart.yAxis.tickFormat( d3.format( 'd' ) ); |
| 331 |
chart.forceY( [ 0, d3.max(impressions) || 1 ] ); |
| 332 |
|
| 333 |
var valuesToPoint = function( value, index ) { |
| 334 |
return { x: index, y: value }; |
| 335 |
}; |
| 336 |
|
| 337 |
d3.select( '#fca_eoi_activity_chart' ).append( 'svg' ).datum( [ |
| 338 |
{ color: '<?php echo $colors['impressions'] ?>', key: 'Impressions', values: impressions.map(valuesToPoint) }, |
| 339 |
{ color: '<?php echo $colors['conversions'] ?>', key: 'Conversions', values: conversions.map(valuesToPoint) } |
| 340 |
] ).call( chart ); |
| 341 |
|
| 342 |
nv.utils.windowResize( chart.update ); |
| 343 |
} ); |
| 344 |
</script> |
| 345 |
<?php |
| 346 |
} |
| 347 |
|
| 348 |
public function add_meta_boxes() { |
| 349 |
|
| 350 |
add_meta_box( |
| 351 |
'fca_eoi_meta_box_setup', |
| 352 |
__( 'Setup' ), |
| 353 |
array( &$this, 'meta_box_content_setup' ), |
| 354 |
'easy-opt-ins', |
| 355 |
'side', |
| 356 |
'high' |
| 357 |
); |
| 358 |
add_meta_box( |
| 359 |
'fca_eoi_meta_box_build', |
| 360 |
__( 'Form Builder' ), |
| 361 |
array( &$this, 'meta_box_content_build' ), |
| 362 |
'easy-opt-ins', |
| 363 |
'side', |
| 364 |
'high' |
| 365 |
); |
| 366 |
|
| 367 |
add_meta_box( |
| 368 |
'fca_eoi_meta_box_provider', |
| 369 |
__( 'Email Marketing Provider Integration' ), |
| 370 |
array( &$this, 'meta_box_content_provider' ), |
| 371 |
'easy-opt-ins', |
| 372 |
'side', |
| 373 |
'high' |
| 374 |
); |
| 375 |
add_meta_box( |
| 376 |
'fca_eoi_meta_box_publish', |
| 377 |
__( 'Publication' ), |
| 378 |
array( &$this, 'meta_box_content_publish' ), |
| 379 |
'easy-opt-ins', |
| 380 |
'side', |
| 381 |
'high' |
| 382 |
); |
| 383 |
add_meta_box( |
| 384 |
'fca_eoi_meta_box_thanks', |
| 385 |
__( 'Messages' ), |
| 386 |
array( &$this, 'meta_box_content_messages' ), |
| 387 |
'easy-opt-ins', |
| 388 |
'side', |
| 389 |
'high' |
| 390 |
); |
| 391 |
if ( has_action( 'fca_eoi_powerups' ) ) { |
| 392 |
add_meta_box( |
| 393 |
'fca_eoi_meta_box_powerups', |
| 394 |
__( 'Power Ups' ), |
| 395 |
array( &$this, 'meta_box_content_powerups' ), |
| 396 |
'easy-opt-ins', |
| 397 |
'side', |
| 398 |
'high' |
| 399 |
); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
public function meta_box_content_setup() { |
| 404 |
|
| 405 |
$layouts_types_labels = array( |
| 406 |
'lightbox' => 'Popups', |
| 407 |
'postbox' => 'Post Boxes', |
| 408 |
'widget' => 'Sidebar Widgets', |
| 409 |
); |
| 410 |
|
| 411 |
// Build the layouts array |
| 412 |
$layouts = $layouts_types = $layouts_types_found = array(); |
| 413 |
foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) as $v) { |
| 414 |
$layouts_types_found[] = basename( $v ); |
| 415 |
} |
| 416 |
|
| 417 |
$layouts_types_accepted = array_keys( $layouts_types_labels ); |
| 418 |
foreach ( $layouts_types_accepted as $layout_type ) { |
| 419 |
if ( in_array( $layout_type, $layouts_types_found ) ) { |
| 420 |
$layouts_types[] = $layout_type; |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
// Layouts types mini-tabs |
| 425 |
echo '<ul class="category-tabs" id="layouts_types_tabs">'; |
| 426 |
foreach ( $layouts_types as $layout_type ) { |
| 427 |
K::wrap( |
| 428 |
$layouts_types_labels[ $layout_type ] |
| 429 |
, array( |
| 430 |
'href' => '#'. 'layouts_type_' . $layout_type, |
| 431 |
) |
| 432 |
, array( |
| 433 |
'html_before' => '<li' . ( 'widget' === $layout_type ? ' class="tabs"' : '' ) . ' >', |
| 434 |
'html_after' => '</li> ', |
| 435 |
'in' => 'a', |
| 436 |
) |
| 437 |
); |
| 438 |
} |
| 439 |
echo '<button type="button" class="button button-primary" id="fca_eoi_layout_revert_button" style="display: none">' . __('Back', 'easy-opt-in') . '</button>'; |
| 440 |
|
| 441 |
echo '</ul>'; |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
//GENERATE SCREENSHOTS / OPTIN THEME PICKER |
| 446 |
//RN NOTE: COULD CACHE THIS (?) |
| 447 |
$output = ''; |
| 448 |
foreach ( $layouts_types as $layout_type ) { |
| 449 |
|
| 450 |
$output .= "<div class='fca_eoi_accordion_tab' id='layouts_type_$layout_type'>"; |
| 451 |
$layout_counter = 1; |
| 452 |
foreach ( glob( FCA_EOI_PLUGIN_DIR . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) { |
| 453 |
$layout_id = basename( $layout_path ); |
| 454 |
|
| 455 |
$layout_helper = new EasyOptInsLayout( $layout_id ); |
| 456 |
$layout_type = ucfirst ( $layout_helper->layout_type ); |
| 457 |
|
| 458 |
$screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' ); |
| 459 |
$screenshot_url = $layout_helper->url_to_resource( 'screenshot', 'png' ); |
| 460 |
$screenshot = file_exists( $screenshot_path ) ? $screenshot_url : FCA_EOI_PLUGIN_URL . '/layouts/no-image.jpg'; |
| 461 |
|
| 462 |
$layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) ); |
| 463 |
$layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name ); |
| 464 |
$output .= "<div class='fca_eoi_layout has-tip fca_eoi_layout_preview' data-layout-id='$layout_id' data-layout-type='$layout_type'>"; |
| 465 |
$output .= "<img src='$screenshot'>"; |
| 466 |
$output .= "<div class='fca_eoi_layout_info'>"; |
| 467 |
$output .= "<h3>$layout_name</h3>"; |
| 468 |
$output .= "</div>"; |
| 469 |
$output .= "</div>"; |
| 470 |
|
| 471 |
$layout_counter = $layout_counter + 1; |
| 472 |
} |
| 473 |
$output .= "</div>"; |
| 474 |
|
| 475 |
} |
| 476 |
$output .= '<br clear="all">'; |
| 477 |
echo $output; |
| 478 |
} |
| 479 |
|
| 480 |
public function meta_box_content_provider() { |
| 481 |
|
| 482 |
global $post; |
| 483 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 484 |
|
| 485 |
//DISABLE CUSTOM FORM |
| 486 |
$allow_customform = get_option ( 'fca_eoi_allow_customform', 'false' ); |
| 487 |
if ( $allow_customform == 'false' ) { |
| 488 |
$providers = $this->settings[ 'providers' ]; |
| 489 |
unset ( $providers['customform'] ); |
| 490 |
$providers_available = array_keys( $providers ); |
| 491 |
} else { |
| 492 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 493 |
} |
| 494 |
|
| 495 |
$providers_options = array(); |
| 496 |
|
| 497 |
// Prepare providers options |
| 498 |
foreach ( $this->settings[ 'providers' ] as $provider_id => $provider ) { |
| 499 |
$providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ]; |
| 500 |
} |
| 501 |
|
| 502 |
if ( $allow_customform == 'false') { |
| 503 |
unset ( $providers_options['customform'] ); |
| 504 |
} |
| 505 |
|
| 506 |
// Provider choice if there are many providers |
| 507 |
if ( 1 < count( $providers_available) ) { |
| 508 |
|
| 509 |
$provider = get_option( 'fca_eoi_last_provider', '' ); |
| 510 |
$provider = empty($provider) ? 'mailchimp' : $provider; // use mailchimp by default |
| 511 |
|
| 512 |
K::select( 'fca_eoi[provider]' |
| 513 |
, array( |
| 514 |
'class' => 'select2', |
| 515 |
'style' => 'width: 27em;', |
| 516 |
) |
| 517 |
, array( |
| 518 |
'format' => '<p><label>:select</label></p>', |
| 519 |
'options' => array( '' => 'Not set' ) + $providers_options, |
| 520 |
'selected' => K::get_var( 'provider', $fca_eoi, $provider ), |
| 521 |
) |
| 522 |
); |
| 523 |
} |
| 524 |
|
| 525 |
foreach ( $providers_available as $provider ) { |
| 526 |
call_user_func( $provider . '_integration', $this->settings ); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
//SEND JS TEMPLATE DATA FOR RULE CREATION |
| 531 |
public function prepare_publish_rules_html( $rules = array() ) { |
| 532 |
|
| 533 |
switch ( $this->settings['distribution'] ) { |
| 534 |
case 'free': |
| 535 |
$conditions_options = array( |
| 536 |
'' => __( 'Choose a rule...' ), |
| 537 |
'time_on_page' => __( 'Time on page' ), |
| 538 |
); |
| 539 |
break; |
| 540 |
case 'premium': |
| 541 |
$conditions_options = array( |
| 542 |
'' => __( 'Choose a rule...' ), |
| 543 |
'scrolled_percent' => __( 'Scrolled down' ), |
| 544 |
'pageviews' => __( 'Number of Pageviews' ), |
| 545 |
'time_on_page' => __( 'Time on page' ), |
| 546 |
'include' => __( 'Only display on these pages' ), |
| 547 |
'exclude' => __( 'Never display on these pages' ), |
| 548 |
'exit_intervention' => __( 'Exit Intervention' ), |
| 549 |
); |
| 550 |
break; |
| 551 |
} |
| 552 |
|
| 553 |
$ruleTableHtml = array ( |
| 554 |
'rowNew' => "<tr><th>" . |
| 555 |
K::select( |
| 556 |
'', |
| 557 |
array( |
| 558 |
'class' => 'fca_eoi_condition_select', |
| 559 |
), |
| 560 |
array( |
| 561 |
'options' => $conditions_options, |
| 562 |
'return' => true, |
| 563 |
) |
| 564 |
) . "<span class='fca_eoi_at_least' style='display:none' >at least</span></th><td></td><td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td></tr>", |
| 565 |
|
| 566 |
'dataScroll' => K::input( |
| 567 |
'fca_eoi[publish_lightbox][conditions][scrolled_percent]', |
| 568 |
array( |
| 569 |
'type' => 'number', |
| 570 |
'min' => '0', |
| 571 |
'value' => '30', |
| 572 |
'class' => '', |
| 573 |
), |
| 574 |
array( |
| 575 |
'return' => true, |
| 576 |
) |
| 577 |
) . ' %', |
| 578 |
|
| 579 |
'dataPageviews' => K::input( |
| 580 |
'fca_eoi[publish_lightbox][conditions][pageviews]', |
| 581 |
array( |
| 582 |
'type' => 'number', |
| 583 |
'min' => '0', |
| 584 |
'value' => '2', |
| 585 |
'class' => '', |
| 586 |
), |
| 587 |
array( |
| 588 |
'return' => true, |
| 589 |
) |
| 590 |
) . ' pageviews', |
| 591 |
|
| 592 |
'dataTime' => K::input( |
| 593 |
'fca_eoi[publish_lightbox][conditions][time_on_page]', |
| 594 |
array( |
| 595 |
'type' => 'number', |
| 596 |
'min' => '0', |
| 597 |
'value' => '30', |
| 598 |
'class' => '', |
| 599 |
), |
| 600 |
array( |
| 601 |
'return' => true, |
| 602 |
) |
| 603 |
) . ' seconds', |
| 604 |
|
| 605 |
'dataExit' => K::input( 'fca_eoi[publish_lightbox][conditions][exit_intervention]', |
| 606 |
array( |
| 607 |
'type' => 'checkbox', |
| 608 |
'class' => 'switch-input' |
| 609 |
), |
| 610 |
array( |
| 611 |
'format' => '<label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label>', |
| 612 |
'return' => true, |
| 613 |
) |
| 614 |
), |
| 615 |
|
| 616 |
'dataInclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][include]', array(), true ), |
| 617 |
'dataExclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][exclude]', array(), true ), |
| 618 |
); |
| 619 |
|
| 620 |
wp_localize_script( 'fca-eoi-rules', 'ruleTableHtml', $ruleTableHtml ); |
| 621 |
wp_localize_script( 'fca-eoi-rules', 'rules', $rules ); |
| 622 |
wp_localize_script( 'fca-eoi-rules', 'distro', $this->settings['distribution'] ); |
| 623 |
} |
| 624 |
|
| 625 |
public function meta_box_content_publish( $post ) { |
| 626 |
|
| 627 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 628 |
|
| 629 |
$conditions = empty( $fca_eoi['publish_lightbox']['conditions'] ) ? array() : $fca_eoi['publish_lightbox']['conditions']; |
| 630 |
$this->prepare_publish_rules_html( $conditions ); |
| 631 |
|
| 632 |
K::wrap( |
| 633 |
sprintf( |
| 634 |
__( 'You can publish this optin box by going to <a href="%s" target="_blank">Appearance › Widgets</a>'), |
| 635 |
admin_url( 'widgets.php') |
| 636 |
), |
| 637 |
array( 'id' => 'fca_eoi_publish_widget' ), |
| 638 |
array( 'in' => 'p' ) |
| 639 |
); |
| 640 |
|
| 641 |
// Post boxes |
| 642 |
echo '<div id ="fca_eoi_publish_postbox">'; |
| 643 |
K::wrap( __( 'Shortcode'), |
| 644 |
array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ), |
| 645 |
array( 'in' => 'h3' ) |
| 646 |
); |
| 647 |
K::wrap( __( "Copy and paste beneath shortcode anywhere on your site where you'd like this opt-in form to appear." ), |
| 648 |
null, |
| 649 |
array( 'in' => 'p' ) |
| 650 |
); |
| 651 |
K::input( '', |
| 652 |
array( |
| 653 |
'class' => 'regular-text autoselect', |
| 654 |
'readonly' => 'readonly', |
| 655 |
'value' => sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ), |
| 656 |
), |
| 657 |
array( 'format' => '<p>:input</p>', ) |
| 658 |
); |
| 659 |
K::wrap( __( 'Append to post or page'), |
| 660 |
array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ), |
| 661 |
array( 'in' => 'h3' ) |
| 662 |
); |
| 663 |
K::wrap( __( 'Automatically append this optin to the following posts, categories and/or pages.' ), |
| 664 |
null, |
| 665 |
array( 'in' => 'p' ) |
| 666 |
); |
| 667 |
k_selector( 'fca_eoi[publish_postbox]', K::get_var( 'publish_postbox', $fca_eoi, array() ) ); |
| 668 |
echo '</div>'; |
| 669 |
|
| 670 |
// Lightboxes |
| 671 |
|
| 672 |
|
| 673 |
$fca_eoi[ 'publish_lightbox' ] = K::get_var( 'publish_lightbox', $fca_eoi, array() ); |
| 674 |
|
| 675 |
|
| 676 |
echo "<div id='fca_eoi_publish_lightbox'>"; |
| 677 |
|
| 678 |
echo '<div id="publish_lightbox_mode_selector_div">'; |
| 679 |
if ( 'premium' === $this->settings[ 'distribution' ] ) { |
| 680 |
|
| 681 |
K::input( 'fca_eoi[publish_lightbox_mode]', |
| 682 |
array( |
| 683 |
'type' => 'radio', |
| 684 |
'value' => 'two_step_optin', |
| 685 |
'checked' => 'two_step_optin' === K::get_var( 'publish_lightbox_mode', $fca_eoi ), |
| 686 |
), |
| 687 |
array( |
| 688 |
'format' => '<p><label>:input Two-Step Optin (Trigger popup only when the visitor clicks on a call to action link)</label></p>', |
| 689 |
) |
| 690 |
); |
| 691 |
|
| 692 |
|
| 693 |
} |
| 694 |
|
| 695 |
K::input( 'fca_eoi[publish_lightbox_mode]', |
| 696 |
array( |
| 697 |
'type' => 'radio', |
| 698 |
'value' => 'traditional_popup', |
| 699 |
'checked' => 'traditional_popup' === K::get_var( 'publish_lightbox_mode', $fca_eoi ), |
| 700 |
), |
| 701 |
array( |
| 702 |
'format' => '<p><label>:input Traditional Popup (Trigger popup when the visitor is browsing your site)</label></p>', |
| 703 |
) |
| 704 |
); |
| 705 |
echo '</div>'; |
| 706 |
|
| 707 |
echo '<div id="fca_eoi_publish_lightbox_mode_traditional_popup">'; |
| 708 |
echo "<h3>Rules</h3>"; |
| 709 |
|
| 710 |
echo "<table class='fca_eoi_display_rules_table'>"; |
| 711 |
echo "<tr><th>Display Frequency</th><td>"; |
| 712 |
K::select( |
| 713 |
'fca_eoi[publish_lightbox][show_every]', |
| 714 |
array(), |
| 715 |
array( |
| 716 |
'options' => array( |
| 717 |
'never' => __( 'Never' ), |
| 718 |
'always' => __( 'On every pageview' ), |
| 719 |
'session' => __( 'Once per visit' ), |
| 720 |
'day' => __( 'Once per day' ), |
| 721 |
'month' => __( 'Once per month' ), |
| 722 |
'once' => __( 'Only once' ), |
| 723 |
), |
| 724 |
'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ], 'once' ), |
| 725 |
) |
| 726 |
); |
| 727 |
echo "</td></tr>"; |
| 728 |
|
| 729 |
echo "<tr><th>Devices to Display on</th><td>"; |
| 730 |
K::select( |
| 731 |
'fca_eoi[publish_lightbox][devices]', |
| 732 |
array(), |
| 733 |
array( |
| 734 |
'options' => array( |
| 735 |
'desktop' => __( 'Desktop Only' ), |
| 736 |
'mobile' => __( 'Mobile Only' ), |
| 737 |
'all' => __( 'Desktop & Mobile' ), |
| 738 |
), |
| 739 |
'selected' => K::get_var( 'devices', $fca_eoi[ 'publish_lightbox' ], 'desktop' ), |
| 740 |
) |
| 741 |
); |
| 742 |
echo "</td></tr>"; |
| 743 |
|
| 744 |
|
| 745 |
echo "</table>"; |
| 746 |
|
| 747 |
echo "<table class='fca_eoi_display_rules_table' id='fca_eoi_primary_rules_table' >"; |
| 748 |
//to be filled dynamically? |
| 749 |
echo "</table>"; |
| 750 |
|
| 751 |
echo "<a href='#' id='fca_eoi_add_rule'>+ Add a rule</a>"; |
| 752 |
|
| 753 |
echo "<h3>Go Live</h3>"; |
| 754 |
echo "<table class='fca_eoi_display_rules_table' >"; |
| 755 |
echo "<tr><th>Deployed (makes this popup go live)</th><td>"; |
| 756 |
K::input( 'fca_eoi[publish_lightbox][live]', |
| 757 |
array( |
| 758 |
'type' => 'checkbox', |
| 759 |
'checked' => K::get_var( 'live', $fca_eoi[ 'publish_lightbox' ], '' ), |
| 760 |
'class' => 'switch-input' |
| 761 |
), |
| 762 |
array( |
| 763 |
'format' => '<label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label>' |
| 764 |
) |
| 765 |
); |
| 766 |
echo "</td></tr>"; |
| 767 |
echo "</table>"; |
| 768 |
echo "</div>"; |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
if ( 'premium' === $this->settings[ 'distribution' ] ) { |
| 773 |
|
| 774 |
echo '<div id="fca_eoi_publish_lightbox_mode_two_step_optin">'; |
| 775 |
echo "<h3>Two-Step</h3>"; |
| 776 |
K::input( 'fca_eoi[lightbox_cta_text]', |
| 777 |
array( |
| 778 |
'value' => K::get_var( 'lightbox_cta_text', $fca_eoi ) ? K::get_var( 'lightbox_cta_text', $fca_eoi ) : __( 'Free Download' ), |
| 779 |
'class' => 'regular-text', |
| 780 |
), |
| 781 |
array( |
| 782 |
'format' => '<p><label>Call to action text :input</label></p>', |
| 783 |
) |
| 784 |
); |
| 785 |
K::input( 'fca_eoi[lightbox_cta_link]', |
| 786 |
array( |
| 787 |
'readonly' => 'readonly', |
| 788 |
'value' => htmlspecialchars( sprintf( '<button data-optin-cat="%d">%s</button>', |
| 789 |
$post->ID, |
| 790 |
__( 'Free Download' ) ) ), |
| 791 |
'class' => 'regular-text autoselect', |
| 792 |
), |
| 793 |
array( |
| 794 |
'format' => '<p><label>Call to action link :input</label></p>', |
| 795 |
) |
| 796 |
); |
| 797 |
|
| 798 |
K::wrap( __( 'Post above link into the text editor window of your post/page/widget.' ), |
| 799 |
array( 'class' => 'description' ), |
| 800 |
array( 'in' => 'p' ) |
| 801 |
); |
| 802 |
echo "</div>"; |
| 803 |
} |
| 804 |
echo "</div>"; |
| 805 |
} |
| 806 |
|
| 807 |
private function meta_box_field( $id, $title, $controls = array() ) { |
| 808 |
$content = ''; |
| 809 |
|
| 810 |
foreach ( $controls as $control ) { |
| 811 |
$control[2] = empty( $control[2] ) ? array() : $control[2]; |
| 812 |
$control[3] = empty( $control[3] ) ? array() : $control[3]; |
| 813 |
|
| 814 |
$control[3][ 'return' ] = true; |
| 815 |
|
| 816 |
$content .= call_user_func_array( 'K::' . $control[0], array_slice( $control, 1 ) ); |
| 817 |
} |
| 818 |
|
| 819 |
$content = trim( $content ); |
| 820 |
$class_name = 'accordion-section-primary-' . ( empty( $content ) ? 'empty' : 'full' ); |
| 821 |
$content = '<div class="' . $class_name . '">' . $content . '</div>'; |
| 822 |
|
| 823 |
$title_id = str_replace ( ' ', '_', $title ); |
| 824 |
$title_id = strtolower ( $title_id ); |
| 825 |
$title_id = preg_replace('/[^a-zA-Z0-9_.]/', '', $title_id); |
| 826 |
|
| 827 |
K::wrap( |
| 828 |
K::wrap( |
| 829 |
$title . "<span class='accordion-info' id='accordion-info-$title_id'></span>", |
| 830 |
array( 'class' => 'accordion-section-title' ), |
| 831 |
array( 'return' => true ) |
| 832 |
) . |
| 833 |
K::wrap( |
| 834 |
$content, |
| 835 |
array( 'class' => 'accordion-section-content' ), |
| 836 |
array( 'return' => true ) |
| 837 |
), |
| 838 |
array( |
| 839 |
'class' => 'accordion-section', |
| 840 |
'id' => $id |
| 841 |
) |
| 842 |
); |
| 843 |
} |
| 844 |
|
| 845 |
public function meta_box_content_build() { |
| 846 |
|
| 847 |
global $post; |
| 848 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 849 |
$layout = get_post_meta( $post->ID, 'fca_eoi_layout', true ); |
| 850 |
|
| 851 |
$selected_layout = empty( $layout ) ? 'lightbox_not_set' : $layout; |
| 852 |
$class = empty( $layout ) ? 'fca-new-layout' : ''; |
| 853 |
echo "<input id='fca_eoi_layout_select' name='fca_eoi[layout]' value='$selected_layout' hidden readonly class='$class'>"; |
| 854 |
|
| 855 |
//OUTPUT SELECTED OR DEFAULT TEMPLATE |
| 856 |
|
| 857 |
echo "<div id='fca_eoi_form_preview'>"; |
| 858 |
|
| 859 |
$output = '<div id="fca_eoi_preview">'; |
| 860 |
//JS WILL LOAD THE TEMPLATE |
| 861 |
//$output .= fca_eoi_get_layout_html( $selected_layout ); |
| 862 |
|
| 863 |
$output .= '</div>'; |
| 864 |
echo $output; |
| 865 |
/* END FORM HTML GENERATION */ |
| 866 |
|
| 867 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 868 |
$providers_options = array(); |
| 869 |
$screen = get_current_screen(); |
| 870 |
|
| 871 |
// Prepare providers options |
| 872 |
foreach ($this->settings[ 'providers' ] as $provider_id => $provider ) { |
| 873 |
$providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ]; |
| 874 |
} |
| 875 |
|
| 876 |
echo '<div id="fca_eoi_settings" class="accordion-container">'; |
| 877 |
|
| 878 |
echo '<div id="fca_eoi_fieldset_layout">'; |
| 879 |
echo '<span id="accordion-info-layout">Layout</span><button title="Change Layout" type="button" id="fca_eoi_layout_select_button" class="button button-secondary"><span style="margin-top: 3px; margin-right: 3px;" class="dashicons dashicons-admin-appearance"></span>Change Layout</button>'; |
| 880 |
echo '</div>'; |
| 881 |
|
| 882 |
$this->meta_box_field( 'fca_eoi_fieldset_form', 'Form', array( |
| 883 |
$this->generate_hidden_css_select_input('form_background_color_selector'), |
| 884 |
$this->generate_color_picker('form_background_color','Form Background Color'), |
| 885 |
$this->generate_hidden_css_select_input('form_border_color_selector'), |
| 886 |
$this->generate_color_picker('form_border_color','Border Color'), |
| 887 |
$this->generate_hidden_css_select_input('form_width_selector'), |
| 888 |
$this->generate_width_select_input('form_width','Width', 100), |
| 889 |
//$this->generate_hidden_css_select_input('form_alignment_selector'), |
| 890 |
//$this->generate_alignment_select_input('form_alignment','Alignment', 'center'), |
| 891 |
|
| 892 |
) ); |
| 893 |
|
| 894 |
$this->meta_box_field( 'fca_eoi_fieldset_headline', 'Headline', array( |
| 895 |
array( 'input', 'fca_eoi[show_headline_field]', |
| 896 |
array( |
| 897 |
'type' => 'checkbox', |
| 898 |
'checked' => K::get_var( 'show_headline_field', $post_meta, 'on' ) == 'off' ? '' : 'on', |
| 899 |
'class' => 'switch-input' |
| 900 |
), |
| 901 |
array( |
| 902 |
'format' => '<p><span class="control-title">Headline Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 903 |
), |
| 904 |
), |
| 905 |
array( 'input', 'fca_eoi[headline_copy]', |
| 906 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'headline_copy', $post_meta ) ), |
| 907 |
array( 'format' => '<p><label><span class="control-title">Headline Copy</span><br />:input</label></p>' ) |
| 908 |
), |
| 909 |
$this->generate_hidden_css_select_input('headline_font_size_selector'), |
| 910 |
$this->generate_font_size_picker ('headline_font_size', 'Font Size'), |
| 911 |
$this->generate_hidden_css_select_input('headline_font_color_selector'), |
| 912 |
$this->generate_color_picker('headline_font_color','Font Color'), |
| 913 |
$this->generate_hidden_css_select_input('headline_background_color_selector'), |
| 914 |
$this->generate_color_picker('headline_background_color','Background Color'), |
| 915 |
|
| 916 |
) ); |
| 917 |
|
| 918 |
$this->meta_box_field( 'fca_eoi_fieldset_description', 'Description', array( |
| 919 |
array( 'input', 'fca_eoi[show_description_field]', |
| 920 |
array( |
| 921 |
'type' => 'checkbox', |
| 922 |
'checked' => K::get_var( 'show_description_field', $post_meta, 'on' ) == 'off' ? '' : 'on', |
| 923 |
'class' => 'switch-input' |
| 924 |
), |
| 925 |
array( |
| 926 |
'format' => '<p><span class="control-title">Description Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 927 |
), |
| 928 |
), |
| 929 |
array( 'textarea', 'fca_eoi[description_copy]', array(), array( |
| 930 |
'format' => ':textarea', |
| 931 |
'editor' => true, |
| 932 |
'value' => K::get_var( 'description_copy', $post_meta ), |
| 933 |
) ), |
| 934 |
$this->generate_hidden_css_select_input('description_font_size_selector'), |
| 935 |
$this->generate_font_size_picker ('description_font_size', 'Font Size'), |
| 936 |
$this->generate_hidden_css_select_input('description_font_color_selector'), |
| 937 |
$this->generate_color_picker('description_font_color','Font Color'), |
| 938 |
) ); |
| 939 |
|
| 940 |
$this->meta_box_field( 'fca_eoi_fieldset_name_field', 'Name Field', array( |
| 941 |
array( 'input', 'fca_eoi[show_name_field]', |
| 942 |
array( |
| 943 |
'type' => 'checkbox', |
| 944 |
'checked' => K::get_var( 'show_name_field', $post_meta, 'off' ) == 'off' ? '' : 'on', |
| 945 |
'class' => 'switch-input' |
| 946 |
), |
| 947 |
array( |
| 948 |
'format' => '<p><span class="control-title">Name Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 949 |
), |
| 950 |
), |
| 951 |
array( 'input', 'fca_eoi[name_placeholder]', |
| 952 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'name_placeholder', $post_meta, 'First Name' ) ), |
| 953 |
array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' ) |
| 954 |
), |
| 955 |
$this->generate_hidden_css_select_input('name_font_size_selector'), |
| 956 |
$this->generate_font_size_picker ('name_font_size', 'Font Size'), |
| 957 |
$this->generate_hidden_css_select_input('name_font_color_selector'), |
| 958 |
$this->generate_color_picker('name_font_color','Font Color'), |
| 959 |
$this->generate_hidden_css_select_input('name_background_color_selector'), |
| 960 |
$this->generate_color_picker('name_background_color','Background Color'), |
| 961 |
$this->generate_hidden_css_select_input('name_border_color_selector'), |
| 962 |
$this->generate_color_picker('name_border_color','Border Color'), |
| 963 |
$this->generate_hidden_css_select_input('name_width_selector'), |
| 964 |
$this->generate_width_select_input('name_width','Width', 100), |
| 965 |
//$this->generate_hidden_css_select_input('name_alignment_selector'), |
| 966 |
//$this->generate_alignment_select_input('name_alignment','Alignment', 'left'), |
| 967 |
) ); |
| 968 |
|
| 969 |
$this->meta_box_field( 'fca_eoi_fieldset_email_field', 'Email Field', array( |
| 970 |
array( 'input', 'fca_eoi[email_placeholder]', |
| 971 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'email_placeholder', $post_meta, 'Your Email' ) ), |
| 972 |
array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' ) |
| 973 |
), |
| 974 |
$this->generate_hidden_css_select_input('email_font_size_selector'), |
| 975 |
$this->generate_font_size_picker ('email_font_size', 'Font Size'), |
| 976 |
$this->generate_hidden_css_select_input('email_font_color_selector'), |
| 977 |
$this->generate_color_picker('email_font_color','Font Color'), |
| 978 |
$this->generate_hidden_css_select_input('email_background_color_selector'), |
| 979 |
$this->generate_color_picker('email_background_color','Background Color'), |
| 980 |
$this->generate_hidden_css_select_input('email_border_color_selector'), |
| 981 |
$this->generate_color_picker('email_border_color','Border Color'), |
| 982 |
$this->generate_hidden_css_select_input('email_width_selector'), |
| 983 |
$this->generate_width_select_input('email_width','Width', 100), |
| 984 |
//$this->generate_hidden_css_select_input('email_alignment_selector'), |
| 985 |
//$this->generate_alignment_select_input('email_alignment','Alignment', 'left'), |
| 986 |
) ); |
| 987 |
|
| 988 |
$this->meta_box_field( 'fca_eoi_fieldset_button', 'Button', array( |
| 989 |
array( 'input', 'fca_eoi[button_copy]', |
| 990 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'button_copy', $post_meta, 'Subscribe Now' ) ), |
| 991 |
array( 'format' => '<p><label><span class="control-title">Button Copy</span><br />:input</label></p>' ) |
| 992 |
), |
| 993 |
$this->generate_hidden_css_select_input('button_font_size_selector'), |
| 994 |
$this->generate_font_size_picker ('button_font_size', 'Font Size'), |
| 995 |
$this->generate_hidden_css_select_input('button_font_color_selector'), |
| 996 |
$this->generate_color_picker('button_font_color','Font Color'), |
| 997 |
|
| 998 |
$this->generate_hidden_css_select_input('button_background_color_selector'), |
| 999 |
$this->generate_color_picker('button_background_color','Background Color'), |
| 1000 |
$this->generate_hidden_css_select_input('button_wrapper_background_color_selector'), |
| 1001 |
$this->generate_color_picker('button_wrapper_background_color','Bottom Border Color'), |
| 1002 |
$this->generate_hidden_css_select_input('button_border_color_selector'), |
| 1003 |
$this->generate_color_picker('button_border_color','Border Color'), |
| 1004 |
|
| 1005 |
$this->generate_hidden_css_select_input('button_hover_color_selector'), |
| 1006 |
$this->generate_color_picker('button_hover_color','Hover Color'), |
| 1007 |
|
| 1008 |
$this->generate_hidden_css_select_input('button_width_selector'), |
| 1009 |
$this->generate_width_select_input('button_width','Width', 100), |
| 1010 |
//$this->generate_hidden_css_select_input('button_alignment_selector'), |
| 1011 |
//$this->generate_alignment_select_input('button_alignment','Alignment', 'center'), |
| 1012 |
|
| 1013 |
) ); |
| 1014 |
|
| 1015 |
$this->meta_box_field( 'fca_eoi_fieldset_privacy', 'After Button Area', array( |
| 1016 |
array( 'input', 'fca_eoi[show_privacy_field]', |
| 1017 |
array( |
| 1018 |
'type' => 'checkbox', |
| 1019 |
'checked' => K::get_var( 'show_privacy_field', $post_meta, 'on' ) == 'off' ? '' : 'on', |
| 1020 |
'class' => 'switch-input' |
| 1021 |
), |
| 1022 |
array( |
| 1023 |
'format' => '<p><span class="control-title">After Button Area</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1024 |
), |
| 1025 |
), |
| 1026 |
array( 'textarea', 'fca_eoi[privacy_copy]', |
| 1027 |
array( |
| 1028 |
'class' => 'large-text fca_eoi_text_input', |
| 1029 |
), |
| 1030 |
array( |
| 1031 |
'format' => '<p><label><span class="control-title">After Button Area Copy</span><br />:textarea</label></p>', |
| 1032 |
'value' => K::get_var( 'privacy_copy', $post_meta ), |
| 1033 |
) |
| 1034 |
), |
| 1035 |
$this->generate_hidden_css_select_input('privacy_font_size_selector'), |
| 1036 |
$this->generate_font_size_picker ('privacy_font_size', 'Font Size'), |
| 1037 |
$this->generate_hidden_css_select_input('privacy_font_color_selector'), |
| 1038 |
$this->generate_color_picker('privacy_font_color','Font Color'), |
| 1039 |
) ); |
| 1040 |
if ( $this->settings['distribution'] === 'free' ) { |
| 1041 |
$this->meta_box_field( 'fca_eoi_fieldset_fatcatapps', 'Branding', array( |
| 1042 |
array( 'input', 'fca_eoi[show_fatcatapps_link]', |
| 1043 |
array( |
| 1044 |
'type' => 'checkbox', |
| 1045 |
'checked' => K::get_var( 'show_fatcatapps_link', $post_meta ), |
| 1046 |
'class' => 'switch-input' |
| 1047 |
), |
| 1048 |
array( |
| 1049 |
'format' => '<p><span class="control-title"><a href="http://fatcatapps.com/" target="_blank">Optin Cat</a> Branding</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1050 |
), |
| 1051 |
), |
| 1052 |
|
| 1053 |
$this->generate_hidden_css_select_input('branding_font_color_selector'), |
| 1054 |
$this->generate_color_picker ('branding_font_color', 'Font Color'), |
| 1055 |
) ); |
| 1056 |
} |
| 1057 |
|
| 1058 |
echo '</div>'; |
| 1059 |
echo '</div>'; |
| 1060 |
echo '<br clear="all"/>'; |
| 1061 |
|
| 1062 |
|
| 1063 |
} |
| 1064 |
public function generate_width_select_input( $id, $name, $default = 100 ) { |
| 1065 |
global $post; |
| 1066 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1067 |
$value = K::get_var( "$id", $post_meta, $default ); |
| 1068 |
$units = K::get_var( "$id" . "-units", $post_meta, '%' ); |
| 1069 |
|
| 1070 |
$px_selected = $units == 'px' ? 'selected' : ''; |
| 1071 |
$pct_selected = $units == '%' ? 'selected' : ''; |
| 1072 |
|
| 1073 |
return array( 'input', "fca_eoi[$id]", |
| 1074 |
array( |
| 1075 |
'type' => 'number', |
| 1076 |
'min' => '0', |
| 1077 |
'value' => $value, |
| 1078 |
'class' => 'fca_eoi_width_input', |
| 1079 |
), |
| 1080 |
array( |
| 1081 |
'format' => "<p><label><span class='control-title'>$name</span></label><br />:input <select class='fca_eoi_width_units_select' name='fca_eoi[$id-units]'><option value='%' $pct_selected>%</option><option value='px' $px_selected>px</option></select></p>", |
| 1082 |
|
| 1083 |
) |
| 1084 |
); |
| 1085 |
} |
| 1086 |
|
| 1087 |
public function generate_alignment_select_input( $id, $name, $default ) { |
| 1088 |
global $post; |
| 1089 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1090 |
$value = K::get_var( "$id", $post_meta, $default ); |
| 1091 |
|
| 1092 |
return array( 'input', "fca_eoi[$id]", |
| 1093 |
array( |
| 1094 |
'type' => 'hidden', |
| 1095 |
'value' => $value, |
| 1096 |
'class' => 'fca_eoi_alignment_input', |
| 1097 |
), |
| 1098 |
array( |
| 1099 |
'format' => "<p><label><span class='control-title'>$name</span></label><br><span data-value='left' class='dashicons dashicons-editor-alignleft fca-eoi-align-button fca-eoi-align-left-btn'></span><span data-value='center' class='dashicons dashicons-editor-aligncenter fca-eoi-align-button fca-eoi-align-center-btn'></span><span data-value='right' class='dashicons dashicons-editor-alignright fca-eoi-align-button fca-eoi-align-right-btn'></span>:input</p>", |
| 1100 |
), |
| 1101 |
); |
| 1102 |
} |
| 1103 |
|
| 1104 |
public function generate_hidden_css_select_input ($id) { |
| 1105 |
return array( 'input', "fca_eoi[$id]", |
| 1106 |
array ( 'class' => 'fca-hidden-input hidden', |
| 1107 |
'value' => '' |
| 1108 |
) |
| 1109 |
); |
| 1110 |
} |
| 1111 |
|
| 1112 |
public function generate_color_picker ($id, $name) { |
| 1113 |
global $post; |
| 1114 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1115 |
return array( 'input', "fca_eoi[$id]", |
| 1116 |
array ( 'class' => 'fca-color-picker', |
| 1117 |
'value' => K::get_var( "$id", $post_meta ) |
| 1118 |
), |
| 1119 |
array( |
| 1120 |
'format' => '<p><label><span class="control-title">'. $name . '</span><br />:input</label></p>', |
| 1121 |
), |
| 1122 |
); |
| 1123 |
} |
| 1124 |
|
| 1125 |
public function generate_font_size_picker ($id, $name) { |
| 1126 |
global $post; |
| 1127 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1128 |
return array( 'select', "fca_eoi[$id]", |
| 1129 |
|
| 1130 |
array ( |
| 1131 |
'data-selected' => K::get_var( "$id", $post_meta ), |
| 1132 |
'class' => 'fca-font-size-picker ', |
| 1133 |
), |
| 1134 |
array( |
| 1135 |
'format' => '<p class="clear"><label><span class="control-title">'. $name . '</span><br />:select</label></p>', |
| 1136 |
'options' => array( |
| 1137 |
'none' => '', |
| 1138 |
'7px' => '7px', |
| 1139 |
'8px' => '8px', |
| 1140 |
'9px' => '9px', |
| 1141 |
'10px' => '10px', |
| 1142 |
'11px' => '11px', |
| 1143 |
'12px' => '12px', |
| 1144 |
'13px' => '13px', |
| 1145 |
'14px' => '14px', |
| 1146 |
'15px' => '15px', |
| 1147 |
'16px' => '16px', |
| 1148 |
'17px' => '17px', |
| 1149 |
'18px' => '18px', |
| 1150 |
'19px' => '19px', |
| 1151 |
'20px' => '20px', |
| 1152 |
'21px' => '21px', |
| 1153 |
'22px' => '22px', |
| 1154 |
'23px' => '23px', |
| 1155 |
'24px' => '24px', |
| 1156 |
'25px' => '25px', |
| 1157 |
'26px' => '26px', |
| 1158 |
'27px' => '27px', |
| 1159 |
'28px' => '28px', |
| 1160 |
'29px' => '29px', |
| 1161 |
'30px' => '30px', |
| 1162 |
'31px' => '31px', |
| 1163 |
'32px' => '32px', |
| 1164 |
'33px' => '33px', |
| 1165 |
'34px' => '34px', |
| 1166 |
'35px' => '35px', |
| 1167 |
'36px' => '36px', |
| 1168 |
), |
| 1169 |
'selected' => K::get_var( "$id", $post_meta ), |
| 1170 |
'return' => true, |
| 1171 |
), |
| 1172 |
); |
| 1173 |
} |
| 1174 |
|
| 1175 |
public function meta_box_content_messages( $post ) { |
| 1176 |
|
| 1177 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1178 |
$screen = get_current_screen(); |
| 1179 |
|
| 1180 |
// Get the previous thank you page if this is a new post |
| 1181 |
$last_form_meta = get_option( 'fca_eoi_last_form_meta', '' ); |
| 1182 |
$thank_you_page_suggestion = empty ($last_form_meta['thank_you_page']) ? '~' : $last_form_meta['thank_you_page']; |
| 1183 |
$thank_you_mode_suggestion = empty ($last_form_meta['thankyou_page_mode']) ? 'ajax' : $last_form_meta['thankyou_page_mode']; |
| 1184 |
$thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? __('Thank you! Please check your inbox for your confirmation email.', 'easy-opt-ins') : $last_form_meta['thankyou_ajax']; |
| 1185 |
$subscribing_suggestion = empty ($last_form_meta['subscribing_message']) ? __('Subscribing...', 'easy-opt-ins') : $last_form_meta['subscribing_message']; |
| 1186 |
$text_error_suggestion = empty ($last_form_meta['error_text_field_required']) ? __('Please fill out this field to continue', 'easy-opt-ins') : $last_form_meta['error_text_field_required']; |
| 1187 |
$email_error_suggestion = empty ($last_form_meta['error_text_invalid_email']) ? __('Please enter a valid email address. For example "hi@fatcatapps.com".', 'easy-opt-ins') : $last_form_meta['error_text_invalid_email']; |
| 1188 |
|
| 1189 |
echo '<h3>' . __('Subscribing Message', 'easy-opt-ins') . fca_eoi_tooltip ( __('This message will be displayed after your visitors submit your form.', 'easy-opt-ins') ) . '</h3>'; |
| 1190 |
echo '<table class="fca_eoi_text_messages_table">'; |
| 1191 |
echo '<tr><th>Message</th><td>'; |
| 1192 |
K::input( 'fca_eoi[subscribing_message]', |
| 1193 |
array( |
| 1194 |
'class' => 'regular-text', |
| 1195 |
'value' => K::get_var( 'subscribing_message', $fca_eoi, $subscribing_suggestion ), |
| 1196 |
), |
| 1197 |
array() |
| 1198 |
); |
| 1199 |
|
| 1200 |
echo '</td></tr></table>'; |
| 1201 |
|
| 1202 |
echo '<h3>' . __('Thank You Message', 'easy-opt-ins') . fca_eoi_tooltip( __('This message will be displayed after someone has successfully subscribed.', 'easy-opt-ins') ) . '</h3>'; |
| 1203 |
echo '<table class="fca_eoi_text_messages_table">'; |
| 1204 |
echo '<tr><th>Behavior</th><td>'; |
| 1205 |
_e('Display immediately', 'easy-opt-ins'); |
| 1206 |
$checked = K::get_var( 'thankyou_page_mode', $fca_eoi, $thank_you_mode_suggestion ); |
| 1207 |
|
| 1208 |
K::input( 'fca_eoi[thankyou_page_mode]', |
| 1209 |
array( |
| 1210 |
'type' => 'checkbox', |
| 1211 |
'value' => 'redirect', |
| 1212 |
'checked' => 'redirect' === $checked, |
| 1213 |
'class' => 'switch-input fca-eoi-redirect-mode-toggle' |
| 1214 |
), |
| 1215 |
array( |
| 1216 |
'format' => '<label class="switch" id="fca-eoi-redirect-mode-toggle-label" >:input<span class="switch-label" data-on="" data-off=""></span><span class="switch-handle"></span></label>' |
| 1217 |
) |
| 1218 |
); |
| 1219 |
_e('Redirect', 'easy-opt-ins'); |
| 1220 |
|
| 1221 |
echo '</td></tr>'; |
| 1222 |
|
| 1223 |
echo '<tr id="fca_eoi_thankyou_ajax_msg"><th>Thank You Message</th><td>'; |
| 1224 |
|
| 1225 |
K::textarea( 'fca_eoi[thankyou_ajax]', array( |
| 1226 |
'class' => 'large-text fca_eoi_text_input', |
| 1227 |
), |
| 1228 |
array( |
| 1229 |
'value' => K::get_var( 'thankyou_ajax', $fca_eoi, $thank_you_text_suggestion ), |
| 1230 |
) |
| 1231 |
); |
| 1232 |
|
| 1233 |
echo '</td></tr>'; |
| 1234 |
|
| 1235 |
|
| 1236 |
echo '<tr id="fca_eoi_thankyou_redirect"><th>Redirect to'; |
| 1237 |
|
| 1238 |
K::select( |
| 1239 |
'fca_eoi[redirect_page_mode]', |
| 1240 |
array( |
| 1241 |
'class' => 'fca-eoi-redirect-page-toggle', |
| 1242 |
), |
| 1243 |
array( |
| 1244 |
'options' => array( |
| 1245 |
'page' => __( 'Page' ), |
| 1246 |
'url' => __( 'URL' ), |
| 1247 |
|
| 1248 |
), |
| 1249 |
'selected' => K::get_var( 'redirect_page_mode', $fca_eoi, 'page' ), |
| 1250 |
) |
| 1251 |
); |
| 1252 |
|
| 1253 |
|
| 1254 |
echo '</th><td>'; |
| 1255 |
|
| 1256 |
echo '<span id="fca_eoi_redirect_page_span">'; |
| 1257 |
$pages = array( '~' => __( 'Front page' ) ); |
| 1258 |
$pages_objects = get_pages(); |
| 1259 |
foreach ( $pages_objects as $page_obj ) { |
| 1260 |
$pages[ $page_obj->ID ] = $page_obj->post_title; |
| 1261 |
} |
| 1262 |
K::select( 'fca_eoi[thank_you_page]', |
| 1263 |
array( |
| 1264 |
'class' => 'select2', |
| 1265 |
'style' => 'width: 27em;', |
| 1266 |
), |
| 1267 |
array( |
| 1268 |
'format' => '<p><label>:select</label></p>', |
| 1269 |
'options' => $pages, |
| 1270 |
'selected' => 'add' === $screen->action |
| 1271 |
? $thank_you_page_suggestion |
| 1272 |
: K::get_var( 'thank_you_page', $fca_eoi, '~' ), |
| 1273 |
) |
| 1274 |
); |
| 1275 |
echo '</span>'; |
| 1276 |
echo '<span id="fca_eoi_redirect_url_span">'; |
| 1277 |
K::input( 'fca_eoi[thank_you_url]', |
| 1278 |
array( |
| 1279 |
'class' => 'regular-text', |
| 1280 |
'value' => K::get_var( 'thank_you_url', $fca_eoi ), |
| 1281 |
'placeholder' => 'enter URL here', |
| 1282 |
), |
| 1283 |
array() |
| 1284 |
); |
| 1285 |
echo '</span>'; |
| 1286 |
echo '</td></tr>'; |
| 1287 |
|
| 1288 |
|
| 1289 |
echo '</table>'; |
| 1290 |
|
| 1291 |
echo '<h3>' . __('Error Messages', 'easy-opt-ins') . fca_eoi_tooltip( __("These messages will be dispalyed if someone fills out the form incorrectly.", 'easy-opt-ins') ) . '</h3>'; |
| 1292 |
echo '<table class="fca_eoi_text_messages_table">'; |
| 1293 |
echo '<tr><th>Field Required</th><td>'; |
| 1294 |
|
| 1295 |
K::textarea( 'fca_eoi[error_text_field_required]', |
| 1296 |
array( |
| 1297 |
'class' => 'large-text fca_eoi_text_input', |
| 1298 |
), |
| 1299 |
array( |
| 1300 |
'value' => K::get_var( 'error_text_field_required', $fca_eoi, $text_error_suggestion ), |
| 1301 |
) |
| 1302 |
); |
| 1303 |
|
| 1304 |
echo '</td></tr>'; |
| 1305 |
|
| 1306 |
echo '<tr><th>Invalid Email</th><td>'; |
| 1307 |
|
| 1308 |
K::textarea( 'fca_eoi[error_text_invalid_email]', |
| 1309 |
array( |
| 1310 |
'class' => 'large-text fca_eoi_text_input', |
| 1311 |
), |
| 1312 |
array( |
| 1313 |
'value' => K::get_var( 'error_text_invalid_email', $fca_eoi, $email_error_suggestion ) |
| 1314 |
) |
| 1315 |
); |
| 1316 |
|
| 1317 |
echo '</td></tr>'; |
| 1318 |
|
| 1319 |
|
| 1320 |
echo '</table>'; |
| 1321 |
} |
| 1322 |
|
| 1323 |
public function meta_box_content_powerups() { |
| 1324 |
|
| 1325 |
global $post; |
| 1326 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1327 |
do_action('fca_eoi_powerups', $fca_eoi ); |
| 1328 |
} |
| 1329 |
|
| 1330 |
/** |
| 1331 |
* Save the Metabox Data |
| 1332 |
*/ |
| 1333 |
public function save_meta_box_content( $post_id, $post ) { |
| 1334 |
|
| 1335 |
if ( isset ($_POST['fca_eoi'])) { |
| 1336 |
$form_id = $post_id; |
| 1337 |
$meta = $_POST['fca_eoi']; |
| 1338 |
|
| 1339 |
//SET SHOW/HIDE SETTINGS |
| 1340 |
$toggles = array ( |
| 1341 |
'show_headline_field', |
| 1342 |
'show_description_field', |
| 1343 |
'show_name_field', |
| 1344 |
'show_privacy_field', |
| 1345 |
|
| 1346 |
); |
| 1347 |
|
| 1348 |
forEach ( $toggles as $field ) { |
| 1349 |
$meta[$field] = empty ( $meta[$field] ) ? 'off' : 'on'; |
| 1350 |
} |
| 1351 |
|
| 1352 |
$settings = array ( |
| 1353 |
'form_background_color_selector' => 'background-color', |
| 1354 |
'form_border_color_selector' => 'border-color', |
| 1355 |
'headline_font_size_selector' => 'font-size', |
| 1356 |
'headline_font_color_selector' => 'color', |
| 1357 |
'headline_background_color_selector' => 'background-color', |
| 1358 |
'description_font_size_selector' => 'font-size', |
| 1359 |
'description_font_color_selector' => 'color', |
| 1360 |
'name_font_size_selector' => 'font-size', |
| 1361 |
'name_font_color_selector' => 'color', |
| 1362 |
'name_background_color_selector' => 'background-color', |
| 1363 |
'name_border_color_selector' => 'border-color', |
| 1364 |
'email_font_size_selector' => 'font-size', |
| 1365 |
'email_font_color_selector' => 'color', |
| 1366 |
'email_background_color_selector' => 'background-color', |
| 1367 |
'email_border_color_selector' => 'border-color', |
| 1368 |
'button_font_size_selector' => 'font-size', |
| 1369 |
'button_font_color_selector' => 'color', |
| 1370 |
'button_background_color_selector' => 'background-color', |
| 1371 |
'button_border_color_selector' => 'border-color', |
| 1372 |
// 'button_hover_color_selector' => 'background-color', special case |
| 1373 |
'button_wrapper_background_color_selector' => 'background-color', |
| 1374 |
'privacy_font_size_selector' => 'font-size', |
| 1375 |
'privacy_font_color_selector' => 'color', |
| 1376 |
'branding_font_color_selector' => 'color', |
| 1377 |
); |
| 1378 |
|
| 1379 |
$animation = isset($_POST['fca_eoi_animations']) ? $_POST['fca_eoi_animations'] : ''; |
| 1380 |
$animationValue = isset($_POST['fca_eoi_show_animation_checkbox']) ? $_POST['fca_eoi_show_animation_checkbox'] : ''; |
| 1381 |
if ($animationValue != 'on') { |
| 1382 |
$animation = ''; |
| 1383 |
} |
| 1384 |
|
| 1385 |
// Add provider if missing (happens on free distros where there is only one provider) |
| 1386 |
if( ! K::get_var( 'provider', $meta ) ) { |
| 1387 |
$meta[ 'provider' ] = $this->settings[ 'provider' ]; |
| 1388 |
} |
| 1389 |
|
| 1390 |
// Keep only the current providers settings, Remove all [provider]_[setting] not belonging to the current provider |
| 1391 |
$provider = K::get_var( 'provider', $meta ); |
| 1392 |
if( $provider ) { |
| 1393 |
$providers = array_keys( $this->settings[ 'providers' ] ); |
| 1394 |
$other_providers = array_values( array_diff( $providers, array( $provider ) ) ); |
| 1395 |
foreach ( $meta as $k => $v ) { |
| 1396 |
$p = explode( '_', $k ); |
| 1397 |
$k_1 = array_shift( $p ); |
| 1398 |
if( in_array( $k_1, $other_providers ) ) { |
| 1399 |
unset( $meta[ $k ] ); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
|
| 1403 |
foreach ( $_POST as $k => $v ) { |
| 1404 |
if ( strpos( $k, 'fca_eoi_' . $provider . '_' ) === 0 ) { |
| 1405 |
delete_post_meta( $post->ID, $k ); |
| 1406 |
add_post_meta( $post->ID, $k, $v ); |
| 1407 |
$meta[ substr($k, 8) ] = $v; |
| 1408 |
} |
| 1409 |
} |
| 1410 |
} |
| 1411 |
|
| 1412 |
// Make sure empty value for publish_postbox or publish_lightbox are saved as array(-1) |
| 1413 |
if( ! K::get_var( 'publish_postbox' , $meta, array() ) ) { |
| 1414 |
$meta[ 'publish_postbox' ] = array(-1); |
| 1415 |
} |
| 1416 |
if( ! K::get_var( 'publish_lightbox' , $meta, array() ) ) { |
| 1417 |
$meta[ 'publish_lightbox' ] = array(-1); |
| 1418 |
} |
| 1419 |
|
| 1420 |
//sanitize thank you ajax message |
| 1421 |
if ( !empty ( $meta[ 'thankyou_ajax' ] ) ) { |
| 1422 |
$meta[ 'thankyou_ajax' ] = htmlentities($meta[ 'thankyou_ajax' ], ENT_QUOTES, "UTF-8"); |
| 1423 |
} |
| 1424 |
|
| 1425 |
//RN NOTE: THIS DO ANYTHING? -> ONLY FOR CUSTOM HTML FORMS SEEMS LIKE |
| 1426 |
$on_save_function = $provider . '_on_save'; |
| 1427 |
if ( function_exists( $on_save_function ) ) { |
| 1428 |
$meta = $on_save_function( $meta ); |
| 1429 |
} |
| 1430 |
|
| 1431 |
//COMPILE CSS AND SAVE INTO 'HEAD' META |
| 1432 |
$layout_id = $meta[ 'layout' ]; |
| 1433 |
|
| 1434 |
// General CSS for all forms |
| 1435 |
$css = "<style type='text/css' class='fca-eoi-style'>.fca_eoi_form{ margin: auto; } .fca_eoi_form p { width: auto; } #fca_eoi_form_$form_id input{ max-width: 9999px; }"; |
| 1436 |
|
| 1437 |
if ( !empty( $layout_id ) ) { |
| 1438 |
|
| 1439 |
// CACHE (ALMOST) ALL THE OUTPUT HERE |
| 1440 |
$layout = new EasyOptInsLayout( $layout_id ); |
| 1441 |
$scss_path = $layout->path_to_resource( 'layout', 'scss' ); |
| 1442 |
|
| 1443 |
if ( file_exists( $scss_path ) ) { |
| 1444 |
$css_path = str_replace ( '.scss' , '_min.css', $scss_path ); |
| 1445 |
$css_file = file_get_contents( $css_path ); |
| 1446 |
} |
| 1447 |
|
| 1448 |
$show_name = K::get_var( 'show_name_field', $meta, 'off' ); |
| 1449 |
if ( $show_name === 'off' ) { |
| 1450 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}"; |
| 1451 |
$selector = K::get_var( 'email_width_selector', $meta, '' ); |
| 1452 |
$css .= "#fca_eoi_form_$form_id $selector {float:none;margin-left:auto;margin-right:auto;}"; |
| 1453 |
|
| 1454 |
} |
| 1455 |
$show_headline_field = K::get_var( 'show_headline_field', $meta, 'on' ); |
| 1456 |
if ( $show_headline_field === 'off' ) { |
| 1457 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_headline_copy_wrapper {display: none !important;}"; |
| 1458 |
} |
| 1459 |
|
| 1460 |
$show_description_field = K::get_var( 'show_description_field', $meta, 'on' ); |
| 1461 |
if ( $show_description_field === 'off' ) { |
| 1462 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_description_copy_wrapper {display: none !important;}"; |
| 1463 |
} |
| 1464 |
|
| 1465 |
//VENDOR PREFIXED PLACEHOLDER COLORS |
| 1466 |
$placeholder_color = K::get_var( 'email_font_color', $meta, '#000000' ); |
| 1467 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-webkit-input-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1468 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-moz-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1469 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element:-ms-input-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1470 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element:-moz-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1471 |
|
| 1472 |
//HOVER |
| 1473 |
$hover_color = K::get_var( 'button_hover_color', $meta, 'initial' ); |
| 1474 |
$selector = K::get_var( 'button_hover_color_selector', $meta, '' ); |
| 1475 |
|
| 1476 |
$s1 = str_replace ( ' input', ':hover', $selector ); |
| 1477 |
$s2 = str_replace ( ' input', ' input:hover', $selector ); |
| 1478 |
|
| 1479 |
$css .= "#fca_eoi_form_$form_id $s1, #fca_eoi_form_$form_id $s2 {background-color:$hover_color !important;}"; |
| 1480 |
|
| 1481 |
//WIDTHS |
| 1482 |
$width_selects = array( |
| 1483 |
'form_width', |
| 1484 |
'name_width', |
| 1485 |
'email_width', |
| 1486 |
'button_width', |
| 1487 |
); |
| 1488 |
|
| 1489 |
forEach ( $width_selects as $w ) { |
| 1490 |
$width = K::get_var( $w, $meta, '100' ); |
| 1491 |
$units = K::get_var( "$w-units", $meta, '%' ); |
| 1492 |
$selector = K::get_var( $w . "_selector", $meta, '' ); |
| 1493 |
$css .= "#fca_eoi_form_$form_id $selector {width:$width$units;}"; |
| 1494 |
|
| 1495 |
} |
| 1496 |
|
| 1497 |
//ADD CSS FROM FILE |
| 1498 |
$css .= $css_file; |
| 1499 |
|
| 1500 |
//ADD CUSTOM CSS FROM SAVE |
| 1501 |
|
| 1502 |
$added_widget_3_css_rule = false; |
| 1503 |
|
| 1504 |
foreach ( $settings as $key => $property ) { |
| 1505 |
$selector = empty ( $meta[$key] ) ? '' : $meta[$key]; |
| 1506 |
$input = str_replace ( '_selector', '', $key); |
| 1507 |
|
| 1508 |
if ( !empty ( $selector ) ) { |
| 1509 |
//SPECIAL CASE FOR BUTTON BORDER |
| 1510 |
if ( $key === 'button_wrapper_background_color_selector' ) { |
| 1511 |
$selector = str_replace ( 'input', '', $selector ); |
| 1512 |
} |
| 1513 |
//SPECIAL CASE FOR WIDGET 3 |
| 1514 |
if ( $selector == '.fca_eoi_layout_3.fca_eoi_layout_widget div.fca_eoi_layout_headline_copy_wrapper div' && !$added_widget_3_css_rule && $input == 'headline_background_color' ) { |
| 1515 |
$css .= "#fca_eoi_form_$form_id form.fca_eoi_layout_3.fca_eoi_layout_widget svg.fca_eoi_layout_headline_copy_triangle { fill: $meta[$input] !important; }"; |
| 1516 |
$added_widget_3_css_rule = true; |
| 1517 |
} |
| 1518 |
|
| 1519 |
$css .= "#fca_eoi_form_$form_id $selector { $property: $meta[$input] !important; }"; |
| 1520 |
|
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
$head = $css . '</style>'; |
| 1525 |
|
| 1526 |
$html = fca_eoi_get_html ( $form_id, $meta ); |
| 1527 |
|
| 1528 |
$head = $head . $html; |
| 1529 |
$meta[ 'post_id' ] = $post_id; |
| 1530 |
|
| 1531 |
//format conditions |
| 1532 |
$new_conditions = array(); |
| 1533 |
$conditions = empty ( $meta['publish_lightbox']['conditions'] ) ? array() : $meta['publish_lightbox']['conditions']; |
| 1534 |
|
| 1535 |
forEach ( $conditions as $key => $value ) { |
| 1536 |
$new_conditions[] = array ( |
| 1537 |
'parameter' => $key, |
| 1538 |
'value' => $value, |
| 1539 |
|
| 1540 |
); |
| 1541 |
} |
| 1542 |
$meta['publish_lightbox']['conditions'] = $new_conditions; |
| 1543 |
|
| 1544 |
//SET THE LIVE TO 'FALSE' FOR BACKWARD COMPATIBILITY |
| 1545 |
$meta['publish_lightbox']['live'] = empty ( $meta['publish_lightbox']['live'] ) ? false : true; |
| 1546 |
|
| 1547 |
update_option( 'fca_eoi_last_provider', $meta[ 'provider' ] ); |
| 1548 |
update_option( 'fca_eoi_last_form_meta', $meta ); |
| 1549 |
update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' ); |
| 1550 |
update_post_meta( $post->ID, 'fca_eoi', $meta ); |
| 1551 |
update_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] ); |
| 1552 |
update_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] ); |
| 1553 |
update_post_meta( $post->ID, 'fca_eoi_animation', $animation ); |
| 1554 |
update_post_meta( $post->ID, 'fca_eoi_head', $head ); |
| 1555 |
|
| 1556 |
} |
| 1557 |
} |
| 1558 |
} |
| 1559 |
|
| 1560 |
public function live_preview( $content ) { |
| 1561 |
global $post; |
| 1562 |
if (get_post_type() == 'easy-opt-ins' && is_main_query()) { |
| 1563 |
$shortcode = sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ); |
| 1564 |
return do_shortcode($shortcode); |
| 1565 |
} else { |
| 1566 |
return $content; |
| 1567 |
} |
| 1568 |
} |
| 1569 |
|
| 1570 |
public function admin_enqueue() { |
| 1571 |
|
| 1572 |
$provider = $this->settings[ 'provider' ]; |
| 1573 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 1574 |
|
| 1575 |
/** |
| 1576 |
* Disable autosaving optin forms since it causes data loss |
| 1577 |
*/ |
| 1578 |
if ( 'easy-opt-ins' == get_post_type() ) { |
| 1579 |
wp_dequeue_script( 'autosave' ); |
| 1580 |
} |
| 1581 |
|
| 1582 |
$screen = get_current_screen(); |
| 1583 |
if( 'easy-opt-ins' === $screen->id ){ |
| 1584 |
global $post; |
| 1585 |
$meta = get_post_meta($post->ID, 'fca_eoi', true ); |
| 1586 |
$options = get_option( 'fca_eoi_settings' ); |
| 1587 |
//LOAD DEPENDENCIES |
| 1588 |
wp_enqueue_script( 'fca_eoi_tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); |
| 1589 |
wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); |
| 1590 |
wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); |
| 1591 |
|
| 1592 |
wp_enqueue_style( 'wp-color-picker' ); |
| 1593 |
wp_enqueue_script( 'wp-color-picker' ); |
| 1594 |
wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); |
| 1595 |
wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER ); |
| 1596 |
wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); |
| 1597 |
wp_enqueue_script( 'accordion' ); |
| 1598 |
|
| 1599 |
if ( !empty( $options['animation'] ) ) { |
| 1600 |
wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.css', array(), FCA_EOI_VER ); |
| 1601 |
} |
| 1602 |
|
| 1603 |
//LOAD CUSTOM AJAX SPINNER CODE/CSS |
| 1604 |
wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.js', array(), FCA_EOI_VER, true ); |
| 1605 |
wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.css', array(), FCA_EOI_VER ); |
| 1606 |
|
| 1607 |
//LOAD COMMON CSS |
| 1608 |
wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL .'/assets/style-new.css', array(), FCA_EOI_VER ); |
| 1609 |
|
| 1610 |
//LOAD EDITOR JS |
| 1611 |
wp_enqueue_script( 'fca-eoi-editor', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.js', array('jquery', 'fca_eoi_tooltipster', 'wp-color-picker', 'select2', 'accordion' ), FCA_EOI_VER, true ); |
| 1612 |
wp_enqueue_script( 'fca-eoi-rules', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-rules.js', array('jquery' ), FCA_EOI_VER, true ); |
| 1613 |
|
| 1614 |
//LOAD PROVIDER JS AND CSS |
| 1615 |
foreach ( $providers_available as $provider ) { |
| 1616 |
wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.js', array(), FCA_EOI_VER, true ); |
| 1617 |
|
| 1618 |
$css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.css'; |
| 1619 |
if ( is_readable( FCA_EOI_PLUGIN_DIR . $css_path ) ) { |
| 1620 |
wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path, array(), FCA_EOI_VER ); |
| 1621 |
} |
| 1622 |
} |
| 1623 |
//SEND VARIABLES TO JS |
| 1624 |
$useGroups = empty ( $options['mailchimp_groups'] ) ? array('off') : array('on') ; |
| 1625 |
wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'useGroups', $useGroups ); |
| 1626 |
|
| 1627 |
$tags = empty($meta['aweber_tags']) ? '' : $meta['aweber_tags']; |
| 1628 |
$aweberSettings = array( |
| 1629 |
'tags' => $tags, |
| 1630 |
); |
| 1631 |
wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'aweberSettings', $aweberSettings ); |
| 1632 |
|
| 1633 |
$file = plugin_dir_path( __FILE__ ) . "layout-cache"; |
| 1634 |
$layout_data = unserialize (file_get_contents($file)); |
| 1635 |
|
| 1636 |
wp_localize_script( 'fca-eoi-editor', 'layouts', $layout_data ); |
| 1637 |
|
| 1638 |
//EDITOR CSS |
| 1639 |
wp_enqueue_style( 'admin-cpt-easy-opt-ins', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins.css', array(), FCA_EOI_VER ); |
| 1640 |
|
| 1641 |
if ( has_action( 'fca_eoi_powerups' ) ) { |
| 1642 |
wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.js', array(), FCA_EOI_VER, true); |
| 1643 |
} |
| 1644 |
} |
| 1645 |
if( 'widgets' === $screen->id ){ |
| 1646 |
wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); |
| 1647 |
wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); |
| 1648 |
} |
| 1649 |
} |
| 1650 |
|
| 1651 |
/** |
| 1652 |
* Hides minor publising form items (status, visibility and publication date) |
| 1653 |
* |
| 1654 |
* This function shoud be used along with force_published to prevent |
| 1655 |
* saving posts as drafts |
| 1656 |
*/ |
| 1657 |
public function hide_minor_publishing() { |
| 1658 |
$screen = get_current_screen(); |
| 1659 |
if( in_array( $screen->id, array( 'easy-opt-ins' ) ) ) { |
| 1660 |
echo '<style>#minor-publishing { display: none; }</style>'; |
| 1661 |
} |
| 1662 |
} |
| 1663 |
|
| 1664 |
public function onboard_help() { |
| 1665 |
|
| 1666 |
$current_screen = get_current_screen(); |
| 1667 |
|
| 1668 |
// Exit function if we are not on the opt-in list |
| 1669 |
if ( $current_screen->id === 'edit-easy-opt-ins' ) { |
| 1670 |
$posts = get_posts( 'posts_per_page=-1&post_type=easy-opt-ins' ); |
| 1671 |
|
| 1672 |
if ( empty ( $posts ) ) { |
| 1673 |
|
| 1674 |
wp_enqueue_style( 'fca_eoi_onboard_stylesheet', FCA_EOI_PLUGIN_URL . '/assets/admin/onboard.css', array(), FCA_EOI_VER ); |
| 1675 |
|
| 1676 |
echo '<div class="error fca_eoi_onboard_div">'; |
| 1677 |
|
| 1678 |
echo '<img id="fca_eoi_onboard_text" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-text.png' . '">'; |
| 1679 |
echo '<img id="fca_eoi_onboard_arrow" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-arrow.png' . '">'; |
| 1680 |
echo '</div>'; |
| 1681 |
} |
| 1682 |
} |
| 1683 |
} |
| 1684 |
|
| 1685 |
public function review_notice() { |
| 1686 |
|
| 1687 |
$dismissed = get_option ( 'fca_eoi_dismiss_review' ); |
| 1688 |
|
| 1689 |
if ( $dismissed !== 'true' ) { |
| 1690 |
$activity = EasyOptInsActivity::get_instance(); |
| 1691 |
$stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] ); |
| 1692 |
$conversions = empty ( $stats['conversions'] ) ? array() : $stats['conversions']; |
| 1693 |
$conversions = array_sum ( $conversions ); |
| 1694 |
|
| 1695 |
if ( $conversions >= 25 ) { |
| 1696 |
$review_link = 'https://wordpress.org/support/plugin/' . FCA_EOI_PLUGIN_SLUG . '/reviews/?rate=5#new-post'; |
| 1697 |
|
| 1698 |
wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.js', array(), FCA_EOI_VER ); |
| 1699 |
wp_localize_script( 'fca_eoi_dismiss_review_js', 'fca_eoi', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) ); |
| 1700 |
|
| 1701 |
echo '<div class="notice notice-success fca_eoi_review_div">'; |
| 1702 |
echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">'; |
| 1703 |
echo '<p><strong>' . __( "Great work! You've gotten more than 25 email subscribers using Optin Cat.", 'easy-opt-ins' ) . '</strong></p>'; |
| 1704 |
|
| 1705 |
echo '<p>' . sprintf( __( "If you love Optin Cat, why not leave us a nice review on %sWordPress.org%s? Reviews keeps us motivated - we'd really appreciate it.", 'easy-opt-ins' ), "<a target='_blank' href='$review_link'>", '</a>') . '</p>'; |
| 1706 |
echo '<br>'; |
| 1707 |
|
| 1708 |
echo "<a target='_blank' href='$review_link' class='button button-primary'>" . __( 'Leave a Review', 'easy-opt-ins') . "</a> "; |
| 1709 |
echo "<button type='button' class='button button-secondary' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>"; |
| 1710 |
echo '<br style="clear:both">'; |
| 1711 |
echo '</div>'; |
| 1712 |
|
| 1713 |
} |
| 1714 |
} |
| 1715 |
} |
| 1716 |
|
| 1717 |
public function ajax_dismiss_notice() { |
| 1718 |
|
| 1719 |
$nonce = empty ( $_REQUEST['nonce'] ) ? '' : $_REQUEST['nonce']; |
| 1720 |
|
| 1721 |
if ( wp_verify_nonce ( $nonce, 'fca_eoi_dismiss') == 1 ) { |
| 1722 |
$result = update_option( 'fca_eoi_dismiss_review', 'true' ); |
| 1723 |
if ( $result ) { |
| 1724 |
echo 'success'; |
| 1725 |
} |
| 1726 |
|
| 1727 |
} |
| 1728 |
wp_die(); // this is required to terminate immediately and return a proper response |
| 1729 |
} |
| 1730 |
|
| 1731 |
/** |
| 1732 |
* Forces one column |
| 1733 |
*/ |
| 1734 |
public function force_one_column() { |
| 1735 |
|
| 1736 |
return 1; |
| 1737 |
} |
| 1738 |
|
| 1739 |
/** |
| 1740 |
* Sort metaboxes |
| 1741 |
*/ |
| 1742 |
public function order_columns( $order ) { |
| 1743 |
return array( |
| 1744 |
'normal' => join( ",", array( |
| 1745 |
'submitdiv', |
| 1746 |
'fca_eoi_meta_box_nav', |
| 1747 |
'fca_eoi_meta_box_setup', |
| 1748 |
'fca_eoi_meta_box_build', |
| 1749 |
'fca_eoi_meta_box_provider', |
| 1750 |
'fca_eoi_meta_box_thanks', |
| 1751 |
'fca_eoi_meta_box_publish', |
| 1752 |
'fca_eoi_meta_box_powerups', |
| 1753 |
'fca_eoi_meta_box_debug', |
| 1754 |
) ), |
| 1755 |
'side' => '', |
| 1756 |
'advanced' => '', |
| 1757 |
); |
| 1758 |
} |
| 1759 |
|
| 1760 |
/** |
| 1761 |
* replacing the default "Enter title here" placeholder text in the title input box to |
| 1762 |
* |
| 1763 |
*/ |
| 1764 |
public function change_default_title($title) { |
| 1765 |
|
| 1766 |
$screen = get_current_screen(); |
| 1767 |
|
| 1768 |
if ( 'easy-opt-ins' == $screen->post_type ) { |
| 1769 |
$title = 'Enter name here'; |
| 1770 |
} |
| 1771 |
|
| 1772 |
return $title; |
| 1773 |
} |
| 1774 |
|
| 1775 |
/** |
| 1776 |
* Override some strings to match our likings |
| 1777 |
*/ |
| 1778 |
public function override_text( $messages ) { |
| 1779 |
|
| 1780 |
global $post; |
| 1781 |
|
| 1782 |
$post_ID = $post->ID; |
| 1783 |
$post_type = get_post_type( $post_ID ); |
| 1784 |
|
| 1785 |
$obj = get_post_type_object( $post_type ); |
| 1786 |
$singular = $obj->labels->singular_name; |
| 1787 |
|
| 1788 |
if ( 'easy-opt-ins' === $post->post_type ) { |
| 1789 |
|
| 1790 |
$messages[$post_type] = array( |
| 1791 |
0 => '', // Unused. Messages start at index 1. |
| 1792 |
1 => __( 'Opt-In Form updated.' ), |
| 1793 |
2 => __( 'Opt-In Form updated.' ), |
| 1794 |
3 => __( 'Opt-In Form deleted.' ), |
| 1795 |
4 => __( 'Opt-In Form updated.' ), |
| 1796 |
5 => isset( $_GET['revision']) ? sprintf( __('%2$s restored to revision from %1$s' ), wp_post_revision_title( (int) $_GET['revision'], false ), esc_attr( $singular ) ) : false, |
| 1797 |
6 => __( 'Opt-In Form saved.' ), |
| 1798 |
7 => sprintf( __( '%s saved.' ), esc_attr( $singular ) ), |
| 1799 |
8 => sprintf( __( '%s submitted. <a href="%s" target="_blank">Preview %s</a>'), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), strtolower( $singular ) ), |
| 1800 |
9 => sprintf( __( '%s scheduled for: <strong>%s</strong>. <a href="%s" target="_blank">Preview %s</a>' ), $singular, date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), strtolower( $singular ) ), |
| 1801 |
10 => sprintf( __( '%s draft updated. <a href="%s" target="_blank">Preview %s</a>'), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), strtolower( $singular ) ) |
| 1802 |
); |
| 1803 |
|
| 1804 |
} |
| 1805 |
|
| 1806 |
return $messages; |
| 1807 |
|
| 1808 |
} |
| 1809 |
|
| 1810 |
public function force_published( $post ) { |
| 1811 |
|
| 1812 |
if( ! in_array( $post[ 'post_status' ], array( 'auto-draft', 'trash') ) ) { |
| 1813 |
if( in_array( $post[ 'post_type' ], array( 'easy-opt-ins' ) ) ) { |
| 1814 |
$post['post_status'] = 'publish'; |
| 1815 |
} |
| 1816 |
} |
| 1817 |
return $post; |
| 1818 |
} |
| 1819 |
|
| 1820 |
/** |
| 1821 |
* Disables bulk editing |
| 1822 |
*/ |
| 1823 |
public function disable_bulk_edit( $actions ){ |
| 1824 |
unset( $actions[ 'edit' ] ); |
| 1825 |
return $actions; |
| 1826 |
} |
| 1827 |
|
| 1828 |
/** |
| 1829 |
* Removes quick edit |
| 1830 |
*/ |
| 1831 |
public function remove_quick_edit( $actions ) { |
| 1832 |
global $post; |
| 1833 |
if( 'easy-opt-ins' === $post->post_type ) { |
| 1834 |
unset($actions['inline hide-if-no-js']); |
| 1835 |
} |
| 1836 |
return $actions; |
| 1837 |
} |
| 1838 |
|
| 1839 |
/** |
| 1840 |
* Add the desired body classes (backend) |
| 1841 |
*/ |
| 1842 |
public function add_body_class( $classes ) { |
| 1843 |
return "$classes fca_eoi"; |
| 1844 |
} |
| 1845 |
|
| 1846 |
|
| 1847 |
/** |
| 1848 |
* Handle Adding a subscriber with Ajax |
| 1849 |
*/ |
| 1850 |
public function ajax_subscribe() { |
| 1851 |
|
| 1852 |
$error = ''; |
| 1853 |
// Get meta |
| 1854 |
$id = $_REQUEST['form_id']; |
| 1855 |
|
| 1856 |
if (empty ($id)){ |
| 1857 |
$error .= "Couldn't find form ID"; |
| 1858 |
} |
| 1859 |
|
| 1860 |
$fca_eoi = get_post_meta( $id, 'fca_eoi', true ); |
| 1861 |
|
| 1862 |
if (empty ($fca_eoi)){ |
| 1863 |
$error .= "Couldn't find post meta"; |
| 1864 |
} |
| 1865 |
|
| 1866 |
$provider = K::get_var( 'provider' , $fca_eoi ); |
| 1867 |
|
| 1868 |
// Check a list_id is provided |
| 1869 |
$list_id = K::get_var( $provider . '_list_id' , $fca_eoi ); |
| 1870 |
if ( empty( $list_id ) ) { |
| 1871 |
$error .= "List not set"; |
| 1872 |
} |
| 1873 |
|
| 1874 |
$nonce = $_REQUEST['nonce']; |
| 1875 |
$nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' ); |
| 1876 |
if ($nonceVerified === FALSE) { |
| 1877 |
$error .= "Couldn't verify form submission"; |
| 1878 |
} |
| 1879 |
|
| 1880 |
// Subscribe user |
| 1881 |
$status = false; |
| 1882 |
|
| 1883 |
if( $list_id && $nonceVerified !== FALSE ) { |
| 1884 |
$str = $provider . '_add_user'; |
| 1885 |
|
| 1886 |
$status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id ); |
| 1887 |
|
| 1888 |
do_action('fca_eoi_after_submission', $fca_eoi, $_POST ); |
| 1889 |
|
| 1890 |
if ($status !== TRUE) { |
| 1891 |
$error .= " Can't add user"; |
| 1892 |
} |
| 1893 |
} |
| 1894 |
|
| 1895 |
if ( $status !== FALSE && $error === '' ) { |
| 1896 |
echo '✓'; |
| 1897 |
EasyOptInsActivity::get_instance()->add_conversion( $id ); |
| 1898 |
} else { |
| 1899 |
echo '✗' . " Error: " . $error; |
| 1900 |
} |
| 1901 |
|
| 1902 |
exit; |
| 1903 |
} |
| 1904 |
|
| 1905 |
public function admin_notices() { |
| 1906 |
|
| 1907 |
//RN NOTE: MAYBE REWRITE |
| 1908 |
$current_screen = get_current_screen(); |
| 1909 |
|
| 1910 |
// Exit function if we are not on the opt-in editing page |
| 1911 |
if ( ! ( |
| 1912 |
'easy-opt-ins' === $current_screen->id |
| 1913 |
&& 'post' === $current_screen->base |
| 1914 |
&& 'edit' === $current_screen->parent_base |
| 1915 |
&& '' === $current_screen->action |
| 1916 |
) ) { |
| 1917 |
return; |
| 1918 |
} |
| 1919 |
|
| 1920 |
global $post; |
| 1921 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1922 |
$provider = K::get_var( 'provider', $fca_eoi); |
| 1923 |
$errors = array(); |
| 1924 |
|
| 1925 |
// Add error for missing thank you page |
| 1926 |
$confirmation_page_set = ( bool ) K::get_var( 'thank_you_page', $fca_eoi); |
| 1927 |
if( ! $confirmation_page_set ) { |
| 1928 |
$errors[] = __( 'No "Thank you" page selected. You will not be able to use this form.' ); |
| 1929 |
} |
| 1930 |
|
| 1931 |
// Add error for missing list setting for the current provider |
| 1932 |
$list_set = ( bool ) K::get_var( $provider . '_list_id', $fca_eoi); |
| 1933 |
|
| 1934 |
// @todo: remove |
| 1935 |
// Hack for mailchimp upgrade |
| 1936 |
if( empty( $fca_eoi[ 'provider' ] ) ) { |
| 1937 |
$fca_eoi[ 'mailchimp_list_id' ] = K::get_var( |
| 1938 |
'mailchimp_list_id' |
| 1939 |
, $fca_eoi |
| 1940 |
, K::get_var( 'list_id' , $fca_eoi ) |
| 1941 |
); |
| 1942 |
$list_set = ( bool ) K::get_var( 'mailchimp_list_id', $fca_eoi); |
| 1943 |
} |
| 1944 |
// End of Hack |
| 1945 |
|
| 1946 |
|
| 1947 |
if( ! $list_set ) { |
| 1948 |
$errors[] = __( 'No List selected. You will not be able to use this form.' ); |
| 1949 |
} |
| 1950 |
|
| 1951 |
$errors = apply_filters( 'fca_eoi_alter_admin_notices', $errors ); |
| 1952 |
|
| 1953 |
foreach ( $errors as $error ) { |
| 1954 |
echo '<div class="error"><p>' . $error . '</p></div>'; |
| 1955 |
} |
| 1956 |
} |
| 1957 |
|
| 1958 |
public function bind_content_filter() { |
| 1959 |
|
| 1960 |
// Do nothing in backend |
| 1961 |
if ( is_admin() ) { |
| 1962 |
return; |
| 1963 |
} |
| 1964 |
|
| 1965 |
add_action( 'wp', array( $this, 'content' ), 10 ); |
| 1966 |
} |
| 1967 |
|
| 1968 |
public function content() { |
| 1969 |
//RN NOTE WAT |
| 1970 |
global $post; |
| 1971 |
|
| 1972 |
if ( empty( $post ) ) { |
| 1973 |
return; |
| 1974 |
} |
| 1975 |
|
| 1976 |
// Do nothing if viewing an opt-in |
| 1977 |
if ( 'easy-opt-ins' === $post->post_type ) { |
| 1978 |
return; |
| 1979 |
} |
| 1980 |
|
| 1981 |
// Work only when viewing a post of any type |
| 1982 |
if ( empty( $post ) ) { |
| 1983 |
return; |
| 1984 |
} |
| 1985 |
|
| 1986 |
$priorities = array(); |
| 1987 |
|
| 1988 |
// Post details |
| 1989 |
$post_ID = $post->ID; |
| 1990 |
$post_type = get_post_type( $post_ID ); |
| 1991 |
|
| 1992 |
// Build the array for testing |
| 1993 |
$post_cond = array( |
| 1994 |
'*', |
| 1995 |
$post_type, |
| 1996 |
'#' . $post_ID, |
| 1997 |
); |
| 1998 |
if ( is_front_page() ) { |
| 1999 |
$post_cond[] = '~'; |
| 2000 |
} |
| 2001 |
|
| 2002 |
$priorities[] = '#' . $post_ID; |
| 2003 |
|
| 2004 |
$taxonomies = get_taxonomies('','names'); |
| 2005 |
$post_taxonomies = wp_get_object_terms( $post->ID,$taxonomies); |
| 2006 |
foreach ( $post_taxonomies as $t ) { |
| 2007 |
$condition = $post_type . ':' . $t->term_id; |
| 2008 |
|
| 2009 |
$post_cond[] = $condition; |
| 2010 |
$priorities[] = $condition; |
| 2011 |
} |
| 2012 |
|
| 2013 |
$priorities[] = $post_type; |
| 2014 |
$priorities[] = '*'; |
| 2015 |
|
| 2016 |
$fca_eoi_last_99_forms = array(); |
| 2017 |
foreach (get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ) as $i => $f ) { |
| 2018 |
$fca_eoi_last_99_forms[ $i ][ 'post' ] = $f; |
| 2019 |
$fca_eoi_last_99_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true ); |
| 2020 |
} |
| 2021 |
// wp_reset_query(); |
| 2022 |
|
| 2023 |
$postboxes = array(); |
| 2024 |
|
| 2025 |
// Append postcode shortcode when the conditions match |
| 2026 |
foreach( $fca_eoi_last_99_forms as $f) { |
| 2027 |
|
| 2028 |
// Exclude other layout types |
| 2029 |
if ( empty ( $f[ 'fca_eoi' ][ 'layout' ] ) ) { |
| 2030 |
continue; |
| 2031 |
} |
| 2032 |
if ( strpos( $f[ 'fca_eoi' ][ 'layout' ], 'postbox_' ) !== 0 ) { |
| 2033 |
continue; |
| 2034 |
} |
| 2035 |
|
| 2036 |
// Get conditions |
| 2037 |
$eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() ); |
| 2038 |
|
| 2039 |
// Append |
| 2040 |
if ( array_intersect( $eoi_form_cond, $post_cond ) ) { |
| 2041 |
foreach ( $eoi_form_cond as $cond ) { |
| 2042 |
if ( empty( $postboxes[ $cond ] ) ) { |
| 2043 |
$postboxes[ $cond ] = sprintf( '[%s id=%d]', $this->settings['shortcode'], $f['post']->ID ); |
| 2044 |
} |
| 2045 |
} |
| 2046 |
} |
| 2047 |
} |
| 2048 |
|
| 2049 |
if ( ! empty( $postboxes ) ) { |
| 2050 |
foreach ( $priorities as $cond ) { |
| 2051 |
if ( ! empty( $postboxes[ $cond ] ) ) { |
| 2052 |
$post->post_content .= $postboxes[ $cond ]; |
| 2053 |
return; |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
$post->post_content .= reset( $postboxes ); |
| 2058 |
return; |
| 2059 |
} |
| 2060 |
} |
| 2061 |
|
| 2062 |
private function get_tc_token( $form_id ) { |
| 2063 |
return "$form_id"; |
| 2064 |
} |
| 2065 |
|
| 2066 |
private function to_call_tc_condition( $name, $arguments ) { |
| 2067 |
return array_merge( array( $name ), $arguments ); |
| 2068 |
} |
| 2069 |
|
| 2070 |
private function to_value_tc_condition( $form_id, $name, $eoi_condition ) { |
| 2071 |
$value = intval( $eoi_condition['value'] ); |
| 2072 |
$params = array( $value ); |
| 2073 |
|
| 2074 |
if ( $name === 'page_views' ) { |
| 2075 |
$params[] = $this->get_tc_token( $form_id ); |
| 2076 |
} else if ( $name === 'time_on_page' ) { |
| 2077 |
$params[0] *= 1000; |
| 2078 |
} |
| 2079 |
|
| 2080 |
return $this->to_call_tc_condition( $name, $params ); |
| 2081 |
} |
| 2082 |
|
| 2083 |
private function to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ) { |
| 2084 |
$url = add_query_arg( array( |
| 2085 |
'fca_eoi_tc_condition_pass' => urlencode( $parameter ), |
| 2086 |
'fca_eoi_tc_condition_value' => urlencode( implode( ',', $eoi_condition['value'] ) ), |
| 2087 |
'fca_eoi_tc_condition_post_id' => $post_id |
| 2088 |
) ); |
| 2089 |
|
| 2090 |
return $this->to_call_tc_condition( 'server_pass', array( $url, 'true' ) ); |
| 2091 |
} |
| 2092 |
|
| 2093 |
private function to_tc_condition( $form_id, $post_id, $eoi_condition ) { |
| 2094 |
$eoi_to_tc_value_map = array( |
| 2095 |
'pageviews' => 'page_views', |
| 2096 |
'scrolled_percent' => 'scroll_percent', |
| 2097 |
'time_on_page' => 'time_on_page' |
| 2098 |
); |
| 2099 |
|
| 2100 |
$eoi_server_pass_conditions = array( 'include', 'exclude' ); |
| 2101 |
|
| 2102 |
$parameter = $eoi_condition['parameter']; |
| 2103 |
if ( array_key_exists( $parameter, $eoi_to_tc_value_map ) ) { |
| 2104 |
return $this->to_value_tc_condition( $form_id, $eoi_to_tc_value_map[ $parameter ], $eoi_condition ); |
| 2105 |
} else if ( in_array( $parameter, $eoi_server_pass_conditions ) ) { |
| 2106 |
return $this->to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ); |
| 2107 |
} |
| 2108 |
|
| 2109 |
return null; |
| 2110 |
} |
| 2111 |
|
| 2112 |
private function to_show_every_tc_condition( $form_id, $condition ) { |
| 2113 |
if ( in_array( $condition, array( 'day', 'month', 'once', 'session' ) ) ) { |
| 2114 |
return array( $condition, $this->get_tc_token( $form_id ) ); |
| 2115 |
} elseif ( $condition === 'always' ) { |
| 2116 |
return 'true'; |
| 2117 |
} elseif ( $condition === 'never' ) { |
| 2118 |
return 'false'; |
| 2119 |
} |
| 2120 |
|
| 2121 |
return $condition; |
| 2122 |
} |
| 2123 |
|
| 2124 |
private function get_tc_conditions( $form_id, $post_id, $conditions ) { |
| 2125 |
$tc_conditions = array(); |
| 2126 |
$sequence_conditions = array(); |
| 2127 |
|
| 2128 |
if ( isSet( $conditions['live'] ) && $conditions['live'] === false ) { |
| 2129 |
return array( 'false' ); |
| 2130 |
} |
| 2131 |
if ( ! empty( $conditions['show_every'] ) ) { |
| 2132 |
$condition = $this->to_show_every_tc_condition( $form_id, $conditions['show_every'] ); |
| 2133 |
|
| 2134 |
if ( $condition === 'false' ) { |
| 2135 |
return array( 'false' ); |
| 2136 |
} else { |
| 2137 |
$sequence_conditions[] = $condition; |
| 2138 |
} |
| 2139 |
} |
| 2140 |
|
| 2141 |
if ( ! empty( $conditions['conditions'] ) ) { |
| 2142 |
foreach ( $conditions['conditions'] as $condition ) { |
| 2143 |
if ( $condition['parameter'] === 'exit_intervention' ) { |
| 2144 |
$sequence_conditions[] = 'exit'; |
| 2145 |
continue; |
| 2146 |
} |
| 2147 |
|
| 2148 |
$tc_condition = $this->to_tc_condition( $form_id, $post_id, $condition ); |
| 2149 |
if ( ! empty( $tc_condition ) ) { |
| 2150 |
$tc_conditions[] = $tc_condition; |
| 2151 |
} |
| 2152 |
} |
| 2153 |
} |
| 2154 |
|
| 2155 |
$has_conditions = ! empty ( $tc_conditions ); |
| 2156 |
if ( $has_conditions ) { |
| 2157 |
$tc_conditions = array( 'and' => $tc_conditions ); |
| 2158 |
} |
| 2159 |
|
| 2160 |
if ( $sequence_conditions ) { |
| 2161 |
if ( $has_conditions ) { |
| 2162 |
$tc_conditions = array( 'sequence' => array( $tc_conditions ) ); |
| 2163 |
} else { |
| 2164 |
$tc_conditions = array( 'sequence' => array() ); |
| 2165 |
} |
| 2166 |
foreach ( $sequence_conditions as $condition ) { |
| 2167 |
$tc_conditions['sequence'][] = $condition; |
| 2168 |
} |
| 2169 |
} |
| 2170 |
|
| 2171 |
return $tc_conditions; |
| 2172 |
} |
| 2173 |
|
| 2174 |
private function echo_tc_conditions_for_form( $form_id, $post_id ) { |
| 2175 |
$fca_eoi = get_post_meta( $form_id , 'fca_eoi', true ); |
| 2176 |
$publish_lightbox = K::get_var( 'publish_lightbox', $fca_eoi, array() ); |
| 2177 |
|
| 2178 |
header( 'Content-Type: application/json' ); |
| 2179 |
exit( json_encode( $this->get_tc_conditions( $form_id, $post_id, $publish_lightbox ) ) ); |
| 2180 |
} |
| 2181 |
|
| 2182 |
private function echo_tc_condition_pass( $post_id, $type, $values ) { |
| 2183 |
$post_cond = array( '*' ); |
| 2184 |
|
| 2185 |
if ( is_front_page() ) { |
| 2186 |
$post_cond[] = '~'; |
| 2187 |
} |
| 2188 |
|
| 2189 |
if ( $post_id ) { |
| 2190 |
$post_type = get_post_type( $post_id ); |
| 2191 |
|
| 2192 |
$post_cond[] = $post_type; |
| 2193 |
$post_cond[] = '#' . $post_id; |
| 2194 |
|
| 2195 |
$taxonomies = get_taxonomies( '', 'names' ); |
| 2196 |
$post_taxonomies = wp_get_object_terms( $post_id, $taxonomies ); |
| 2197 |
|
| 2198 |
foreach ( $post_taxonomies as $t ) { |
| 2199 |
$post_cond[] = $post_type . ':' . $t->term_id; |
| 2200 |
} |
| 2201 |
} else { |
| 2202 |
//FIX FOR NOT DISPLAYING ON BLOG PAGE |
| 2203 |
if ( is_home() ) { |
| 2204 |
$post_cond[] = '#' . get_option('page_for_posts'); |
| 2205 |
} |
| 2206 |
|
| 2207 |
} |
| 2208 |
|
| 2209 |
$intersect = array_intersect( $values, $post_cond ); |
| 2210 |
|
| 2211 |
if ( $type === 'include' ) { |
| 2212 |
echo $intersect ? 'true' : 'false'; |
| 2213 |
} else if ( $type === 'exclude' ) { |
| 2214 |
echo $intersect ? 'false' : 'true'; |
| 2215 |
} |
| 2216 |
|
| 2217 |
exit; |
| 2218 |
} |
| 2219 |
|
| 2220 |
public function parse_tc_condition_request() { |
| 2221 |
$post_id = empty( $_REQUEST['fca_eoi_tc_condition_post_id'] ) ? 0 : (int) $_REQUEST['fca_eoi_tc_condition_post_id']; |
| 2222 |
|
| 2223 |
if ( ! empty( $_REQUEST['fca_eoi_tc_conditions_for'] ) ) { |
| 2224 |
$form_id = (int) $_REQUEST['fca_eoi_tc_conditions_for']; |
| 2225 |
$this->echo_tc_conditions_for_form( $form_id, $post_id ); |
| 2226 |
} |
| 2227 |
|
| 2228 |
if ( ! empty( $_REQUEST['fca_eoi_tc_condition_pass'] ) ) { |
| 2229 |
$this->echo_tc_condition_pass( |
| 2230 |
$post_id, |
| 2231 |
$_REQUEST['fca_eoi_tc_condition_pass'], |
| 2232 |
explode( ',', $_REQUEST['fca_eoi_tc_condition_value'] ) |
| 2233 |
); |
| 2234 |
} |
| 2235 |
} |
| 2236 |
|
| 2237 |
private function get_cookie_configuration() { |
| 2238 |
$cookie_configuration = array(); |
| 2239 |
|
| 2240 |
if ( defined( 'COOKIEPATH' ) ) { |
| 2241 |
$path = COOKIEPATH; |
| 2242 |
if ( ! empty( $path ) ) { |
| 2243 |
$cookie_configuration['path'] = $path; |
| 2244 |
} |
| 2245 |
} |
| 2246 |
|
| 2247 |
if ( defined( 'COOKIE_DOMAIN' ) ) { |
| 2248 |
$domain = COOKIE_DOMAIN; |
| 2249 |
if ( ! empty( $domain ) ) { |
| 2250 |
$cookie_configuration['domain'] = $domain; |
| 2251 |
} |
| 2252 |
} |
| 2253 |
|
| 2254 |
return $cookie_configuration; |
| 2255 |
} |
| 2256 |
|
| 2257 |
public function scan_for_shortcodes( $content ) { |
| 2258 |
if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) { |
| 2259 |
$this->two_step_ids_on_page = array_map( 'intval', $matches[1] ); |
| 2260 |
} |
| 2261 |
|
| 2262 |
return $content; |
| 2263 |
} |
| 2264 |
|
| 2265 |
public function show_lightbox() { |
| 2266 |
|
| 2267 |
// Get lightboxes |
| 2268 |
$lightboxes = get_posts( array( |
| 2269 |
'post_type' => 'easy-opt-ins', |
| 2270 |
'posts_per_page' => -1, |
| 2271 |
'orderby' => 'ID', |
| 2272 |
'meta_key' => 'fca_eoi_layout', |
| 2273 |
'meta_value' => 'lightbox_', |
| 2274 |
'meta_compare' => 'like', |
| 2275 |
) ); |
| 2276 |
|
| 2277 |
// Exit function if no lightbox found |
| 2278 |
if( ! $lightboxes ) { |
| 2279 |
return; |
| 2280 |
} |
| 2281 |
|
| 2282 |
$two_step_ids = array(); |
| 2283 |
$traditional_ids = array(); |
| 2284 |
|
| 2285 |
$mobile_detect = new Mobile_Detect; |
| 2286 |
$is_mobile = $mobile_detect->isMobile(); |
| 2287 |
|
| 2288 |
foreach ( $lightboxes as $lightbox ) { |
| 2289 |
|
| 2290 |
// Get conditions |
| 2291 |
$lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true ); |
| 2292 |
$publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() ); |
| 2293 |
|
| 2294 |
$lightbox_conditions = K::get_var( 'publish_lightbox', $lightbox->fca_eoi, array() ); |
| 2295 |
|
| 2296 |
$mobile_mode = K::get_var( 'devices', $lightbox_conditions, 'all' ); |
| 2297 |
$fail_mobile = $mobile_mode === 'mobile' && !$is_mobile; |
| 2298 |
$fail_desktop = $mobile_mode === 'desktop' && $is_mobile; |
| 2299 |
|
| 2300 |
// If on a free distribution, force traditional popup mode |
| 2301 |
if ( $this->settings['distribution'] === 'free' ) { |
| 2302 |
$publish_lightbox_mode = 'traditional_popup'; |
| 2303 |
} |
| 2304 |
|
| 2305 |
if ( 'two_step_optin' === $publish_lightbox_mode ) { |
| 2306 |
$two_step_ids[] = $lightbox->ID; |
| 2307 |
} else if ( !$fail_mobile && !$fail_desktop ) { |
| 2308 |
$traditional_ids[] = $lightbox->ID; |
| 2309 |
} |
| 2310 |
|
| 2311 |
|
| 2312 |
} |
| 2313 |
|
| 2314 |
$this->display_traditional_popups($traditional_ids, $this->display_two_step_popups($two_step_ids)); |
| 2315 |
} |
| 2316 |
|
| 2317 |
private function display_two_step_popups($lightbox_ids) { |
| 2318 |
$lightbox_ids = array_intersect( $lightbox_ids, $this->two_step_ids_on_page ); |
| 2319 |
|
| 2320 |
if ( empty( $lightbox_ids ) ) { |
| 2321 |
return false; |
| 2322 |
} |
| 2323 |
do_action( 'fca_eoi_display_lightbox' ); |
| 2324 |
|
| 2325 |
foreach ( $lightbox_ids as $lightbox_id ) { |
| 2326 |
$this->prepare_lightbox( $lightbox_id ); |
| 2327 |
} |
| 2328 |
|
| 2329 |
?> |
| 2330 |
<script> |
| 2331 |
jQuery( function() { |
| 2332 |
jQuery( document ).on( 'click', '[data-optin-cat]', function( e ) { |
| 2333 |
var lightbox_id = jQuery( this ).data( 'optin-cat' ); |
| 2334 |
<?php echo EasyOptInsActivity::get_instance()->get_tracking_code( 'lightbox_id', false ) ?> |
| 2335 |
jQuery.featherlight( jQuery( '#fca_eoi_lightbox_' + lightbox_id ), <?php echo $this->get_featherlight_options() ?> ); |
| 2336 |
e.preventDefault(); |
| 2337 |
} ); |
| 2338 |
} ); |
| 2339 |
</script> |
| 2340 |
<?php |
| 2341 |
|
| 2342 |
return true; |
| 2343 |
} |
| 2344 |
|
| 2345 |
private function display_traditional_popups( $lightbox_ids, $prerequisites_loaded = false ) { |
| 2346 |
if ( empty( $lightbox_ids ) ) { |
| 2347 |
return false; |
| 2348 |
} |
| 2349 |
|
| 2350 |
wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.js', array(), FCA_EOI_VER, true ); |
| 2351 |
//PASS VARIABLES TO JAVASCRIPT |
| 2352 |
$data = array ( |
| 2353 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 2354 |
'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), |
| 2355 |
); |
| 2356 |
|
| 2357 |
wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', $data ); |
| 2358 |
wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); |
| 2359 |
wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); |
| 2360 |
|
| 2361 |
?> |
| 2362 |
<script type="text/javascript" src="<?php echo FCA_EOI_PLUGIN_URL . '/' . $this->targeting_cat_path ?>"></script> |
| 2363 |
<script> |
| 2364 |
(function() { |
| 2365 |
if ( typeof fca_eoi === "undefined" ) { |
| 2366 |
fca_eoi = {}; |
| 2367 |
} |
| 2368 |
|
| 2369 |
fca_eoi.ajax_url = <?php echo json_encode( admin_url( 'admin-ajax.php' ) ) ?>; |
| 2370 |
})(); |
| 2371 |
|
| 2372 |
<?php $v = array( |
| 2373 |
'prerequisites_loaded' => 'p', |
| 2374 |
'load_prerequisites' => 'l', |
| 2375 |
'head' => 'h', |
| 2376 |
'load_script' => 'c', |
| 2377 |
'load_style' => 'y', |
| 2378 |
'callback' => 'k', |
| 2379 |
'vendor_url' => 'v', |
| 2380 |
'done' => 'n', |
| 2381 |
'document' => 'd', |
| 2382 |
'window.location.href' => 'w', |
| 2383 |
'display_popup' => 's', |
| 2384 |
'false' => '!1', |
| 2385 |
'true' => '1', |
| 2386 |
'evaluable' => 'e', |
| 2387 |
'descriptors' => 'r', |
| 2388 |
'form_id' => 'm', |
| 2389 |
'TargetingCat_OptinCat' => 'g', |
| 2390 |
'url' => 'u' |
| 2391 |
); ?> |
| 2392 |
|
| 2393 |
<?php ob_start(); ?> |
| 2394 |
|
| 2395 |
jQuery( function( $ ) { |
| 2396 |
var |
| 2397 |
<?php echo $v['document'] ?> = document, |
| 2398 |
<?php echo $v['window.location.href'] ?> = window.location.href, |
| 2399 |
<?php echo $v['TargetingCat_OptinCat'] ?> = TargetingCat_OptinCat; |
| 2400 |
|
| 2401 |
<?php if ( ! $prerequisites_loaded ) { ?> |
| 2402 |
|
| 2403 |
var |
| 2404 |
<?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['false'] ?>, |
| 2405 |
<?php echo $v['head'] ?> = <?php echo $v['document'] ?>.head; |
| 2406 |
|
| 2407 |
function <?php echo $v['load_script'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) { |
| 2408 |
var e = <?php echo $v['document'] ?>.createElement( 'script' ); |
| 2409 |
|
| 2410 |
e.type = 'text/javascript'; |
| 2411 |
e.src = <?php echo $v['url'] ?>; |
| 2412 |
e.onload = <?php echo $v['callback'] ?>; |
| 2413 |
|
| 2414 |
<?php echo $v['head'] ?>.appendChild( e ); |
| 2415 |
} |
| 2416 |
|
| 2417 |
function <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) { |
| 2418 |
var e = <?php echo $v['document'] ?>.createElement( 'link' ); |
| 2419 |
|
| 2420 |
e.rel = 'stylesheet'; |
| 2421 |
e.type = 'text/css'; |
| 2422 |
e.href = <?php echo $v['url'] ?>; |
| 2423 |
e.onload = <?php echo $v['callback'] ?>; |
| 2424 |
|
| 2425 |
<?php echo $v['head'] ?>.appendChild( e ); |
| 2426 |
} |
| 2427 |
|
| 2428 |
function <?php echo $v['load_prerequisites'] ?>( <?php echo $v['callback'] ?> ) { |
| 2429 |
if ( <?php echo $v['prerequisites_loaded'] ?> ) { |
| 2430 |
<?php echo $v['callback'] ?>(); |
| 2431 |
return; |
| 2432 |
} |
| 2433 |
|
| 2434 |
var t = 4, |
| 2435 |
<?php echo $v['url'] ?> = <?php echo json_encode( FCA_EOI_PLUGIN_URL . '/assets/' ) ?>, |
| 2436 |
<?php echo $v['vendor_url'] ?> = <?php echo $v['url'] ?> + 'vendor/', |
| 2437 |
<?php echo $v['done'] ?> = function() { |
| 2438 |
if ( ! --t ) { |
| 2439 |
<?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['true'] ?>; |
| 2440 |
<?php echo $v['callback'] ?>(); |
| 2441 |
} |
| 2442 |
}; |
| 2443 |
|
| 2444 |
<?php echo $v['load_style'] ?>( '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', <?php echo $v['done'] ?> ); |
| 2445 |
|
| 2446 |
|
| 2447 |
<?php echo $v['load_style'] ?>( <?php echo $v['url'] ?> + 'style-new.css', <?php echo $v['done'] ?> ); |
| 2448 |
|
| 2449 |
<?php echo $v['load_script'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.js', <?php echo $v['done'] ?> ); |
| 2450 |
<?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.css', <?php echo $v['done'] ?> ); |
| 2451 |
<?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster-borderless.min.css', <?php echo $v['done'] ?> ); |
| 2452 |
|
| 2453 |
<?php |
| 2454 |
|
| 2455 |
$loadAnim = false; |
| 2456 |
forEach ($lightbox_ids as $id) { |
| 2457 |
$animation = get_post_meta( $id, 'fca_eoi_animation', true ); |
| 2458 |
if ($animation != '') { |
| 2459 |
$loadAnim = true; |
| 2460 |
break; |
| 2461 |
} |
| 2462 |
} |
| 2463 |
|
| 2464 |
if ( $loadAnim ) { |
| 2465 |
|
| 2466 |
echo $v['load_style'] . "(" . $v['vendor_url'] . "+ 'animate/animate.css'," . $v['done'] . ');'; } ?> |
| 2467 |
} |
| 2468 |
|
| 2469 |
<?php } ?> |
| 2470 |
|
| 2471 |
function <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ) { |
| 2472 |
var t = <?php echo $prerequisites_loaded ? 1 : 2 ?>, |
| 2473 |
<?php echo $v['done'] ?> = function() { |
| 2474 |
if ( ! --t ) { |
| 2475 |
$.featherlight( |
| 2476 |
$( '#fca_eoi_lightbox_' + <?php echo $v['form_id'] ?> ), |
| 2477 |
<?php echo $this->get_featherlight_options() ?> |
| 2478 |
); |
| 2479 |
|
| 2480 |
<?php echo EasyOptInsActivity::get_instance()->get_tracking_code( $v['form_id'], false ) ?> |
| 2481 |
} |
| 2482 |
}; |
| 2483 |
|
| 2484 |
$.post( <?php echo $v['window.location.href'] ?>, { |
| 2485 |
fca_eoi_prepare_lightbox: <?php echo $v['form_id'] ?> |
| 2486 |
}, function( html ) { |
| 2487 |
$( 'body' ).append( html ); |
| 2488 |
<?php echo $v['done'] ?>(); |
| 2489 |
} ); |
| 2490 |
|
| 2491 |
<?php if ( ! $prerequisites_loaded ) { ?> |
| 2492 |
<?php echo $v['load_prerequisites'] ?>( <?php echo $v['done'] ?> ); |
| 2493 |
<?php } ?> |
| 2494 |
} |
| 2495 |
|
| 2496 |
<?php echo $v['TargetingCat_OptinCat'] ?>.StorageManagerSessionPermanent.get_instance().default_configuration = <?php echo json_encode( $this->get_cookie_configuration() ) ?>; |
| 2497 |
|
| 2498 |
<?php echo json_encode( $lightbox_ids ) ?>.forEach( function( <?php echo $v['form_id'] ?> ) { |
| 2499 |
$.post( <?php echo $v['window.location.href'] ?>, { |
| 2500 |
<?php if ( is_single() || is_page() ) { ?> |
| 2501 |
'fca_eoi_tc_condition_post_id': <?php echo get_the_ID() ?>, |
| 2502 |
<?php } ?> |
| 2503 |
'fca_eoi_tc_conditions_for': <?php echo $v['form_id'] ?> |
| 2504 |
}, function( <?php echo $v['descriptors'] ?> ) { |
| 2505 |
var <?php echo $v['evaluable'] ?> = <?php echo $v['TargetingCat_OptinCat'] ?>.ConditionManager.get_instance().parse_descriptors( |
| 2506 |
typeof <?php echo $v['descriptors'] ?> === 'string' |
| 2507 |
? JSON.parse( <?php echo $v['descriptors'] ?> ) |
| 2508 |
: <?php echo $v['descriptors'] ?> |
| 2509 |
); |
| 2510 |
if ( <?php echo $v['evaluable'] ?> ) { |
| 2511 |
<?php echo $v['evaluable'] ?>.set_pass_callback( function() { |
| 2512 |
<?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ); |
| 2513 |
} ); |
| 2514 |
<?php echo $v['evaluable'] ?>.evaluate(); |
| 2515 |
} |
| 2516 |
} ); |
| 2517 |
} ); |
| 2518 |
|
| 2519 |
var lightbox_ids_Count = <?php echo count ($lightbox_ids) ?>; |
| 2520 |
var currentLightBoxCount = 0; |
| 2521 |
var totalAddedLightboxes = 0; |
| 2522 |
|
| 2523 |
function waitUntilPopupsAreMade() { |
| 2524 |
|
| 2525 |
if( totalAddedLightboxes < lightbox_ids_Count ) { |
| 2526 |
|
| 2527 |
if (document.getElementsByClassName("fca_eoi_featherlight").length > currentLightBoxCount) { |
| 2528 |
|
| 2529 |
totalAddedLightboxes++; |
| 2530 |
currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length; |
| 2531 |
attachDeleteButtons(); |
| 2532 |
window.setTimeout(waitUntilPopupsAreMade, 200); |
| 2533 |
}else { |
| 2534 |
|
| 2535 |
currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length; |
| 2536 |
window.setTimeout(waitUntilPopupsAreMade, 200); |
| 2537 |
} |
| 2538 |
|
| 2539 |
} else { |
| 2540 |
|
| 2541 |
attachDeleteButtons(); |
| 2542 |
} |
| 2543 |
} |
| 2544 |
if (lightbox_ids_Count > 1) { |
| 2545 |
waitUntilPopupsAreMade(); |
| 2546 |
} |
| 2547 |
|
| 2548 |
function attachDeleteButtons() { |
| 2549 |
myNodes = document.getElementsByClassName("fca_eoi_layout_popup_close"); |
| 2550 |
|
| 2551 |
for (var i=0; i<myNodes.length; i++) { |
| 2552 |
myNodes[i].onclick = function(e) { |
| 2553 |
$(this).parents(".fca_eoi_featherlight").hide(); |
| 2554 |
}; |
| 2555 |
|
| 2556 |
} |
| 2557 |
} |
| 2558 |
|
| 2559 |
|
| 2560 |
} ); |
| 2561 |
|
| 2562 |
<?php |
| 2563 |
|
| 2564 |
echo preg_replace( |
| 2565 |
array( '/\s+/', '/([-+|\(\){}&=;,:?])\s+/', '/\s+([-+|\(\){}&=?])/', '/;}/' ), |
| 2566 |
array( ' ', '$1', '$1', '}' ), |
| 2567 |
trim( ob_get_clean() ) |
| 2568 |
); |
| 2569 |
|
| 2570 |
?> |
| 2571 |
</script> |
| 2572 |
<?php |
| 2573 |
|
| 2574 |
return true; |
| 2575 |
} |
| 2576 |
|
| 2577 |
public function request_prepare_lightbox() { |
| 2578 |
if (array_key_exists('fca_eoi_prepare_lightbox', $_POST)) { |
| 2579 |
$lightbox_id = (int) $_POST['fca_eoi_prepare_lightbox']; |
| 2580 |
if ( $lightbox_id > 0 ) { |
| 2581 |
$this->prepare_lightbox( $lightbox_id ); |
| 2582 |
exit; |
| 2583 |
} |
| 2584 |
} |
| 2585 |
} |
| 2586 |
|
| 2587 |
public function prepare_lightbox( $id ) { |
| 2588 |
$id = (int) $id; |
| 2589 |
|
| 2590 |
global $post; |
| 2591 |
|
| 2592 |
$animation = get_post_meta( $id, 'fca_eoi_animation', true ); |
| 2593 |
$animation_html_class = "animated $animation"; |
| 2594 |
|
| 2595 |
if ( empty ( $animation ) || $animation == 'None' ) { |
| 2596 |
$animation_html_class = ''; |
| 2597 |
} |
| 2598 |
|
| 2599 |
|
| 2600 |
$featherlight_class = 'fca_eoi_featherlight'; |
| 2601 |
$content = do_shortcode( "[easy-opt-in id=$id]" ); |
| 2602 |
|
| 2603 |
?> |
| 2604 |
<div style="display:none"> |
| 2605 |
<style>.<?php echo $featherlight_class ?>-content { background: transparent !important; }</style> |
| 2606 |
<div class="<?php echo $animation_html_class ?>" id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div> |
| 2607 |
</div> |
| 2608 |
<?php |
| 2609 |
} |
| 2610 |
|
| 2611 |
private function get_featherlight_options() { |
| 2612 |
|
| 2613 |
$is_iphone = preg_match('/(?:iPhone|iPod);/i', $_SERVER['HTTP_USER_AGENT']); |
| 2614 |
$is_ios = preg_match( '/(?:iPhone|iPad|iPod).* OS ([\d])_.* Safari/', $_SERVER['HTTP_USER_AGENT'], $matches ); |
| 2615 |
|
| 2616 |
if ( $is_ios ) { |
| 2617 |
$ios_specific_options = ', |
| 2618 |
beforeOpen: function() { |
| 2619 |
var viewport = jQuery( "meta[name=viewport]" ); |
| 2620 |
if ( viewport.length == 0 ) { |
| 2621 |
viewport = jQuery( "<meta name=\"viewport\" content=\"\"/>" ); |
| 2622 |
jQuery( "head" ).append( viewport ); |
| 2623 |
} |
| 2624 |
|
| 2625 |
var viewport_content = viewport.attr( "content" ); |
| 2626 |
this.fca_eoi_viewport_content = viewport_content; |
| 2627 |
viewport.attr( "content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" ); |
| 2628 |
|
| 2629 |
this.fca_eoi_orientation_change_listener = function() { |
| 2630 |
window.scrollTo( 0, 0 ); |
| 2631 |
jQuery( ".fca_eoi_form input" ).each( function() { |
| 2632 |
this.blur(); |
| 2633 |
} ); |
| 2634 |
}; |
| 2635 |
window.addEventListener( "orientationchange", this.fca_eoi_orientation_change_listener, false ); |
| 2636 |
|
| 2637 |
this.fca_eoi_touch_move_listener = function( event ) { |
| 2638 |
event.preventDefault(); |
| 2639 |
}; |
| 2640 |
window.addEventListener( "touchmove", this.fca_eoi_touch_move_listener, false ); |
| 2641 |
}, |
| 2642 |
afterOpen: function() { |
| 2643 |
this.$instance.find(".fca_eoi_form_input_element").first().focus(); |
| 2644 |
jQuery( "body" ).append( "<div class=\"fca_eoi_featherlight_pad\" style=\"display: block; height: 1000px;\"/>" ); |
| 2645 |
}, |
| 2646 |
beforeClose: function() { |
| 2647 |
jQuery( ".fca_eoi_featherlight_pad" ).remove(); |
| 2648 |
}, |
| 2649 |
afterClose: function() { |
| 2650 |
if ( this.hasOwnProperty( "fca_eoi_viewport_content" ) ) { |
| 2651 |
jQuery( "meta[name=viewport]" ).attr( "content", this.fca_eoi_viewport_content ); |
| 2652 |
} |
| 2653 |
|
| 2654 |
if ( this.hasOwnProperty( "fca_eoi_orientation_change_listener" ) ) { |
| 2655 |
window.removeEventListener( "orientationchange", this.fca_eoi_orientation_change_listener ); |
| 2656 |
} |
| 2657 |
|
| 2658 |
if ( this.hasOwnProperty( "fca_eoi_touch_move_listener" ) ) { |
| 2659 |
window.removeEventListener( "touchmove", this.fca_eoi_touch_move_listener ); |
| 2660 |
} |
| 2661 |
}'; |
| 2662 |
} else { |
| 2663 |
$ios_specific_options = ', |
| 2664 |
afterOpen: function() { |
| 2665 |
this.$instance.find(".fca_eoi_form_input_element").first().focus(); |
| 2666 |
}'; |
| 2667 |
} |
| 2668 |
|
| 2669 |
return '{ |
| 2670 |
namespace: "fca_eoi_featherlight", |
| 2671 |
otherClose: ".fca_eoi_layout_popup_close"' . $ios_specific_options . ', |
| 2672 |
variant: ' . ( $is_iphone ? '"fca_eoi_device_iphone"' : 'null' ) . ' |
| 2673 |
}'; |
| 2674 |
} |
| 2675 |
} |
| 2676 |
|
| 2677 |
function k_selector( $name, $selected_options = array(), $return = false ) { |
| 2678 |
|
| 2679 |
global $post; |
| 2680 |
// Dirty fix to restore the global $post |
| 2681 |
$post_bak = $post; |
| 2682 |
|
| 2683 |
// Get all post types except media |
| 2684 |
$post_types = get_post_types( array( 'public' => true ) ); |
| 2685 |
unset( $post_types[ 'attachment' ] ); |
| 2686 |
|
| 2687 |
$ret = ob_start(); |
| 2688 |
|
| 2689 |
// Start ouput |
| 2690 |
echo '<select data-placeholder="' . __( 'Type to search for posts, categories or pages.' ) . '" name = "' . $name . '[]" class="select2" multiple="multiple" style="width: 100%;">'; |
| 2691 |
|
| 2692 |
// Front page |
| 2693 |
K::wrap( __( 'Front page' ) |
| 2694 |
, array( |
| 2695 |
'value' => '~', |
| 2696 |
'selected' => in_array( '~', $selected_options ), |
| 2697 |
) |
| 2698 |
, array( 'in' => 'option' ) |
| 2699 |
); |
| 2700 |
|
| 2701 |
foreach ($post_types as $post_type => $post_type_args ) { |
| 2702 |
|
| 2703 |
$post_type_obj = get_post_type_object( $post_type ); |
| 2704 |
$post_type_name = $post_type_obj->labels->singular_name; |
| 2705 |
|
| 2706 |
$options = array(); |
| 2707 |
|
| 2708 |
// Add taxonomy/terms options |
| 2709 |
$taxonomies = get_object_taxonomies( $post_type ); |
| 2710 |
foreach ( $taxonomies as $taxonomy ) { |
| 2711 |
$taxonomy_obj = get_taxonomy( $taxonomy ); |
| 2712 |
$taxonomy_name = $taxonomy_obj->labels->singular_name; |
| 2713 |
$terms = get_categories("taxonomy=$taxonomy&type=$post_type"); |
| 2714 |
foreach ($terms as $term) { |
| 2715 |
$options[ 'taxonomies' ][ "$post_type:$term->term_id" ] = |
| 2716 |
$post_type_name |
| 2717 |
. " › $taxonomy_name" |
| 2718 |
. " › $term->name" |
| 2719 |
; |
| 2720 |
} |
| 2721 |
} |
| 2722 |
|
| 2723 |
// Add posts options |
| 2724 |
$the_query = new WP_Query( "post_type=$post_type&posts_per_page=-1" ); |
| 2725 |
if ( $the_query->have_posts() ) { |
| 2726 |
|
| 2727 |
while ( $the_query->have_posts() ) { |
| 2728 |
$the_query->the_post(); |
| 2729 |
$options[ 'posts' ][ '#' . get_the_ID() ] = $post_type_name |
| 2730 |
. ' ' . __( '›' ) . ' ' |
| 2731 |
. '#' . get_the_ID() . ' – ' |
| 2732 |
. ( get_the_title() ? get_the_title() : __('[Untitled]') ) |
| 2733 |
; |
| 2734 |
} |
| 2735 |
} |
| 2736 |
|
| 2737 |
// Dirty fix to restore the global $post |
| 2738 |
$post = $post_bak; |
| 2739 |
|
| 2740 |
// Posts > All |
| 2741 |
echo '<optgroup label="' . $post_type_name . '">'; |
| 2742 |
printf( |
| 2743 |
'<option value="%s" %s >%s</option>' |
| 2744 |
, $post_type |
| 2745 |
, ( in_array( $post_type, $selected_options ) ? 'selected' : '' ) |
| 2746 |
, $post_type_name . ' ' . ( '›' ) . ' ' . __( 'All' ) |
| 2747 |
); |
| 2748 |
echo '</optgroup>'; |
| 2749 |
|
| 2750 |
// Posts > Taoxonomies |
| 2751 |
if ( ! empty( $options[ 'taxonomies' ] ) ) { |
| 2752 |
printf( |
| 2753 |
'<optgroup label="%s">' |
| 2754 |
, $post_type_name . ' ' . __( '›' ) . ' ' . __( 'Taxonomies' ) |
| 2755 |
); |
| 2756 |
foreach ( $options[ 'taxonomies' ] as $k => $v ) { |
| 2757 |
$selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : ''; |
| 2758 |
printf( '<option value="%s" %s >%s</option>', $k, $selected, $v ); |
| 2759 |
} |
| 2760 |
echo '</optgroup>'; |
| 2761 |
} |
| 2762 |
|
| 2763 |
// Posts > content |
| 2764 |
if ( ! empty( $options[ 'posts' ] ) ) { |
| 2765 |
printf( '<optgroup label="%s">' |
| 2766 |
, $post_type_name . ' ' . __( '›' ) . ' ' . __( 'Content' ) |
| 2767 |
); |
| 2768 |
foreach ( $options[ 'posts' ] as $k => $v ) { |
| 2769 |
$selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : ''; |
| 2770 |
printf( '<option value="%s" %s >%s</option>' |
| 2771 |
, $k |
| 2772 |
, $selected |
| 2773 |
, $v |
| 2774 |
); |
| 2775 |
} |
| 2776 |
echo '</optgroup>'; |
| 2777 |
} |
| 2778 |
} |
| 2779 |
echo '</select>'; |
| 2780 |
|
| 2781 |
$ret = ob_get_clean(); |
| 2782 |
|
| 2783 |
if ( $return ) { |
| 2784 |
return $ret; |
| 2785 |
} else { |
| 2786 |
echo $ret; |
| 2787 |
} |
| 2788 |
} |
| 2789 |
|
| 2790 |
function fca_eoi_comp( $a, $b, $op, $negate = false ) { |
| 2791 |
switch ( $op ) { |
| 2792 |
case 'eq': return $negate ? ( ! ( $a == $b ) ) : ( $a == $b ); |
| 2793 |
case 'gt': return $negate ? ( ! ( $a > $b ) ) : ( $a > $b ); |
| 2794 |
case 'gte': return $negate ? ( ! ( $a >= $b ) ) : ( $a >= $b ); |
| 2795 |
case 'lt': return $negate ? ( ! ( $a < $b ) ) : ( $a < $b ); |
| 2796 |
case 'lte': return $negate ? ( ! ( $a <= $b ) ) : ( $a <= $b ); |
| 2797 |
} |
| 2798 |
} |
| 2799 |
|