| 1 |
<?php |
| 2 |
|
| 3 |
class EasyOptInsShortcodes { |
| 4 |
|
| 5 |
var $settings; |
| 6 |
var $prerequisites = array(); |
| 7 |
var $assets_enqueued = false; |
| 8 |
|
| 9 |
public function __construct( $settings = array() ) { |
| 10 |
global $pagenow, $typenow; |
| 11 |
|
| 12 |
$this->settings = $settings; |
| 13 |
|
| 14 |
// Add shortcode |
| 15 |
add_shortcode( $this->settings[ 'shortcode' ], array( $this, 'shortcode_content' ) ); |
| 16 |
|
| 17 |
// Add shortcode aliases |
| 18 |
foreach ( $settings[ 'shortcode_aliases' ] as $shortcode) { |
| 19 |
add_shortcode( $shortcode, array( $this, 'shortcode_content' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
// Add shortcode generator button |
| 23 |
if ( FCA_EOI_EDITION != 'email_popup' && in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) { |
| 24 |
add_action( 'admin_head', array( $this, 'button_head' ) ); |
| 25 |
add_action( 'media_buttons', array( $this, 'button' ), 1000 ); |
| 26 |
add_action( 'admin_footer', array( $this, 'button_footer' ) ); |
| 27 |
} |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
public function button_head() { |
| 32 |
?> |
| 33 |
|
| 34 |
<style> |
| 35 |
#fca-eoi-media-button { |
| 36 |
background: url(<?php echo FCA_EOI_PLUGIN_URL . '/icon.png' ?>) 0 -1px no-repeat; |
| 37 |
background-size: 16px 16px; |
| 38 |
} |
| 39 |
</style> |
| 40 |
|
| 41 |
<?php |
| 42 |
} |
| 43 |
|
| 44 |
public function button() { |
| 45 |
global $post; |
| 46 |
if (current_user_can( 'delete_pages' ) && $post->post_type != 'easy-opt-ins'){ |
| 47 |
|
| 48 |
$button_title = __( 'Add Optin Form' ); |
| 49 |
|
| 50 |
if ( version_compare( $GLOBALS['wp_version'], '3.5', '<' ) ) { |
| 51 |
echo '<a href="#TB_inline?width=640&inlineId=fca-eoi-shortcode-thickbox" class="thickbox" title="' . $button_title . '">' . $button_title . '</a>'; |
| 52 |
} else { |
| 53 |
$img = '<span class="wp-media-buttons-icon" id="fca-eoi-media-button"></span>'; |
| 54 |
echo '<a href="#TB_inline?width=640&inlineId=fca-eoi-shortcode-thickbox" class="thickbox button" title="' . $button_title . '" style="padding-left: .4em;">' . $img . $button_title . '</a>'; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public function button_footer() { |
| 60 |
$options = array(); |
| 61 |
|
| 62 |
foreach ( get_posts( array( 'post_type' => 'easy-opt-ins', 'post_status' => 'publish', 'posts_per_page' => -1 ) ) as $post ) { |
| 63 |
$form_id = $post->ID; |
| 64 |
$layout = get_post_meta( $form_id, 'fca_eoi_layout', true ); |
| 65 |
|
| 66 |
if ( ! empty( $layout ) && strpos( $layout, 'postbox_' ) === 0 ) { |
| 67 |
$options[ $form_id ] = empty( $post->post_title ) ? '(no title)' : $post->post_title; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
?> |
| 72 |
|
| 73 |
<script type="text/javascript"> |
| 74 |
jQuery( function( $ ) { |
| 75 |
$( '#fca-eoi-shortcode-insert' ).on( 'click', function() { |
| 76 |
var id = $( '#fca-eoi-shortcode' ).val(); |
| 77 |
|
| 78 |
if ( '' === id ) { |
| 79 |
alert( <?php echo json_encode( __( 'You must choose a form' ) ) ?> ); |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
window.send_to_editor( '[<?php echo $this->settings[ 'shortcode' ] ?> id="' + id + '"]' ); |
| 84 |
} ); |
| 85 |
} ); |
| 86 |
</script> |
| 87 |
<div id="fca-eoi-shortcode-thickbox" style="display: none;"> |
| 88 |
<div class="wrap" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"> |
| 89 |
<p><?php _e('Use the form below to insert an Optin Cat shortcode .' ) ?></p> |
| 90 |
<div> |
| 91 |
<select id="fca-eoi-shortcode"> |
| 92 |
<option value=""><?php _e( 'Please select...' ) ?></option> |
| 93 |
<?php foreach ( $options as $form_id => $title ) { ?> |
| 94 |
<option value="<?php echo (int) $form_id ?>"><?php echo esc_html( $title ) ?></option> |
| 95 |
<?php } ?> |
| 96 |
</select> |
| 97 |
</div> |
| 98 |
<p class="submit"> |
| 99 |
<input type="button" id="fca-eoi-shortcode-insert" class="button-primary" value="<?php _e( 'Insert' ) ?>"> |
| 100 |
<a id="fca-eoi-shortcode-cancel" class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel' ) ?>"><?php _e( 'Cancel' ) ?></a> |
| 101 |
</p> |
| 102 |
</div> |
| 103 |
</div> |
| 104 |
|
| 105 |
<?php |
| 106 |
} |
| 107 |
|
| 108 |
public function enqueue_assets() { |
| 109 |
$protocol = is_ssl() ? 'https' : 'http'; |
| 110 |
|
| 111 |
wp_enqueue_script( 'jquery' ); |
| 112 |
wp_enqueue_style( 'fca-eoi-font-awesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER ); |
| 113 |
|
| 114 |
wp_enqueue_script( 'fca_eoi_tooltipster_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); |
| 115 |
wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); |
| 116 |
wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); |
| 117 |
|
| 118 |
wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); |
| 119 |
wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); |
| 120 |
|
| 121 |
wp_enqueue_script( 'fca_eoi_jstz', FCA_EOI_PLUGIN_URL . '/assets/vendor/jstz/jstz.min.js', array(), FCA_EOI_VER, true ); |
| 122 |
|
| 123 |
wp_enqueue_style( 'fca-eoi-common-css', FCA_EOI_PLUGIN_URL . '/assets/style-new.min.css', array(), FCA_EOI_VER ); |
| 124 |
wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL . '/assets/script.js', array( 'fca_eoi_jstz', 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js'), FCA_EOI_VER, true ); |
| 125 |
|
| 126 |
//PASS VARIABLES TO JAVASCRIPT |
| 127 |
$options = get_option( 'fca_eoi_settings' ); |
| 128 |
$consent_msg = empty( $options['consent_msg'] ) ? '' : $options['consent_msg']; |
| 129 |
$consent_headline = empty( $options['consent_headline'] ) ? '' : $options['consent_headline']; |
| 130 |
$data = array ( |
| 131 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 132 |
'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), |
| 133 |
'gdpr_checkbox' => fca_eoi_show_gdpr_checkbox(), |
| 134 |
'consent_headline' => $consent_headline, |
| 135 |
'consent_msg' => $consent_msg |
| 136 |
); |
| 137 |
wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data ); |
| 138 |
} |
| 139 |
|
| 140 |
public function shortcode_content( $atts ) { |
| 141 |
if ( empty ( $atts['id'] ) ) { |
| 142 |
return "The selected Optin Cat form doesn't exist."; |
| 143 |
} else { |
| 144 |
$form_id = $atts['id']; |
| 145 |
$post = get_post( $form_id ); |
| 146 |
} |
| 147 |
|
| 148 |
if( !is_object( $post ) OR $post->post_status == 'trash' ) { |
| 149 |
return "The selected Optin Cat form doesn't exist."; |
| 150 |
} |
| 151 |
|
| 152 |
$animation = get_post_meta( $form_id, 'fca_eoi_animation', true); |
| 153 |
if ( !empty( $animation ) ) { |
| 154 |
wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER ); |
| 155 |
} |
| 156 |
|
| 157 |
$this->enqueue_assets(); |
| 158 |
$head = get_post_meta( $form_id, 'fca_eoi_head', true ); |
| 159 |
|
| 160 |
$layout_id = get_post_meta ( $form_id, 'fca_eoi_layout', true ); |
| 161 |
$layout = new EasyOptInsLayout( $layout_id ); |
| 162 |
|
| 163 |
if ( $layout->layout_type !== 'lightbox' && $layout->layout_type !== 'banner' && $layout->layout_type !== 'overlay' ) { |
| 164 |
|
| 165 |
require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/RobotDetector/RobotDetector.php'; |
| 166 |
$robot_detector = new RobotDetector(); |
| 167 |
|
| 168 |
if ( get_post( $form_id ) && !is_user_logged_in() && !$robot_detector->is_robot() ) { |
| 169 |
EasyOptInsActivity::get_instance()->add_impression( $form_id ); |
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
return $head; |
| 175 |
} |
| 176 |
} |
| 177 |
|