| 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 |
} |
| 23 |
|
| 24 |
public function enqueue_assets() { |
| 25 |
$protocol = is_ssl() ? 'https' : 'http'; |
| 26 |
|
| 27 |
wp_enqueue_script( 'jquery' ); |
| 28 |
wp_enqueue_style( 'fca-eoi-font-awesome', FCA_EOI_PLUGIN_URL . '/assets/vendor/font-awesome/font-awesome.min.css', array(), FCA_EOI_VER ); |
| 29 |
|
| 30 |
wp_enqueue_script( 'fca_eoi_tooltipster_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); |
| 31 |
wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); |
| 32 |
wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); |
| 33 |
|
| 34 |
wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); |
| 35 |
wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); |
| 36 |
|
| 37 |
wp_enqueue_script( 'fca_eoi_jstz', FCA_EOI_PLUGIN_URL . '/assets/vendor/jstz/jstz.min.js', array(), FCA_EOI_VER, true ); |
| 38 |
|
| 39 |
wp_enqueue_style( 'fca-eoi-common-css', FCA_EOI_PLUGIN_URL . '/assets/style-new.min.css', array(), FCA_EOI_VER ); |
| 40 |
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 ); |
| 41 |
|
| 42 |
//PASS VARIABLES TO JAVASCRIPT |
| 43 |
$options = get_option( 'fca_eoi_settings' ); |
| 44 |
$consent_msg = empty( $options['consent_msg'] ) ? '' : $options['consent_msg']; |
| 45 |
$consent_headline = empty( $options['consent_headline'] ) ? '' : $options['consent_headline']; |
| 46 |
$data = array ( |
| 47 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 48 |
'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), |
| 49 |
'gdpr_checkbox' => fca_eoi_show_gdpr_checkbox(), |
| 50 |
'consent_headline' => $consent_headline, |
| 51 |
'consent_msg' => $consent_msg |
| 52 |
); |
| 53 |
wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data ); |
| 54 |
} |
| 55 |
|
| 56 |
public function shortcode_content( $atts ) { |
| 57 |
if ( empty ( $atts['id'] ) ) { |
| 58 |
return "The selected Optin Cat form doesn't exist."; |
| 59 |
} else { |
| 60 |
$form_id = $atts['id']; |
| 61 |
$post = get_post( $form_id ); |
| 62 |
} |
| 63 |
|
| 64 |
if( !is_object( $post ) OR $post->post_status == 'trash' ) { |
| 65 |
return "The selected Optin Cat form doesn't exist."; |
| 66 |
} |
| 67 |
|
| 68 |
$animation = get_post_meta( $form_id, 'fca_eoi_animation', true); |
| 69 |
if ( !empty( $animation ) ) { |
| 70 |
wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER ); |
| 71 |
} |
| 72 |
|
| 73 |
$this->enqueue_assets(); |
| 74 |
$head = get_post_meta( $form_id, 'fca_eoi_head', true ); |
| 75 |
|
| 76 |
$layout_id = get_post_meta ( $form_id, 'fca_eoi_layout', true ); |
| 77 |
$layout = new EasyOptInsLayout( $layout_id ); |
| 78 |
|
| 79 |
if ( $layout->layout_type !== 'lightbox' && $layout->layout_type !== 'banner' && $layout->layout_type !== 'overlay' ) { |
| 80 |
|
| 81 |
require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/RobotDetector/RobotDetector.php'; |
| 82 |
$robot_detector = new RobotDetector(); |
| 83 |
|
| 84 |
if ( get_post( $form_id ) && !is_user_logged_in() && !$robot_detector->is_robot() ) { |
| 85 |
EasyOptInsActivity::get_instance()->add_impression( $form_id ); |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
return wp_kses( $head, K::allowed_html() ); |
| 91 |
} |
| 92 |
} |
| 93 |
|