PluginProbe
GetResponse Forms by Optin Cat / 2.0.2
GetResponse Forms by Optin Cat v2.0.2
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
← All changes | includes/eoi-shortcode.php +55 -322 1.5.42.0.2 View file →
@@ -25,141 +25,10 @@
25 25 add_action( 'media_buttons', array( $this, 'button' ), 1000 );
26 26 add_action( 'admin_footer', array( $this, 'button_footer' ) );
27 27 }
28 28
29 - if ( ! is_admin() ) {
30 - add_action( 'wp', array( $this, 'parse_shortcodes' ), 11 );
31 - }
32 29 }
33 30
34 - public function wp_head() {
35 - foreach ( $this->prerequisites as $form_id => $head ) {
36 - echo $head;
37 - $this->prerequisites[ $form_id ] = '';
38 - }
39 - }
40 -
41 - public function parse_shortcodes() {
42 - global $post;
43 -
44 - if ( empty( $post ) ) {
45 - return;
46 - }
47 -
48 - if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches )
49 - && array_key_exists( 2, $matches )
50 - && array_key_exists( 3, $matches )
51 - && in_array( $this->settings['shortcode'], $matches[2] )
52 - ) {
53 - foreach ( $matches[3] as $params ) {
54 - $params = shortcode_parse_atts( $params );
55 - if ( ! empty( $params['id'] ) ) {
56 - $this->add_prerequisites_for_form( (int) $params['id'] );
57 - }
58 - }
59 - }
60 -
61 - if ( ! empty( $this->prerequisites ) ) {
62 - $this->enqueue_assets();
63 - add_action( 'wp_head', array( $this, 'wp_head' ) );
64 - }
65 - }
66 -
67 - /**
68 - * @param int $form_id
69 - *
70 - * @return string
71 - */
72 - private function add_prerequisites_for_form( $form_id ) {
73 - $head = get_post_meta( $form_id, 'fca_eoi_head', true );
74 - if ( !empty ( $head ) ) {
75 - return $head;
76 - } else {
77 -
78 - if ( array_key_exists( $form_id, $this->prerequisites ) ) {
79 - return $this->prerequisites[ $form_id ];
80 - }
81 -
82 - $head = '';
83 -
84 - $fca_eoi_meta = get_post_meta( $form_id, 'fca_eoi', true );
85 - if ( ! $fca_eoi_meta ) {
86 - return $head;
87 - }
88 -
89 - $layout_id = $fca_eoi_meta['layout'];
90 - $layout = new EasyOptInsLayout( $layout_id );
91 - $scss_path = $layout->path_to_resource( 'layout', 'scss' );
92 -
93 - $scss = $layout->new_scss_compiler();
94 -
95 - if ( file_exists( $scss_path ) ) {
96 - $head .=
97 - '<style>' .
98 - '.fca_eoi_form p { width: auto; }' . $scss->compile(
99 - sprintf( '$ltr: %s;', is_rtl() ? 'false' : 'true' ) .
100 - '#fca_eoi_form_' . $form_id . '{' .
101 - 'input{ max-width: 9999px; }' .
102 - file_get_contents( $scss_path ) .
103 - '}'
104 - ) .
105 - '</style>';
106 - }
107 -
108 - // Add per form CSS
109 - $head .= '<style>.fca_eoi_form{ margin: auto; }</style>';
110 -
111 - $css_for_scss = '';
112 - if ( ! empty( $fca_eoi_meta[ $layout_id ] ) ) {
113 - $head .= '<style>';
114 - $css_for_scss .= "#fca_eoi_form_$form_id {";
115 - foreach ( $fca_eoi_meta[ $layout_id ] as $selector => $declarations ) {
116 - $css_for_scss .= "$selector{";
117 - foreach ( $declarations as $property => $value ) {
118 - if ( strlen( $value ) ) {
119 - $css_for_scss .= "$property:$value !important;";
120 - }
121 - }
122 - $css_for_scss .= '}';
123 - }
124 - $css_for_scss .= '}';
125 - $head .= $scss->compile( $css_for_scss ) . '</style>';
126 - }
127 -
128 - if ( $layout->layout_type != 'lightbox' ) {
129 - $head .= '<script>' . EasyOptInsActivity::get_instance()->get_tracking_code( $form_id ) . '</script>';
130 - }
131 -
132 - $this->prerequisites[ $form_id ] = $head;
133 -
134 - delete_post_meta( $form_id, 'fca_eoi_head' );
135 - add_post_meta( $form_id, 'fca_eoi_head', $head );
136 -
137 -
138 - return $head;
139 -
140 - }
141 -
142 - }
143 -
144 - /**
145 - * @param int $form_id
146 - *
147 - * @return string
148 - */
149 - private function get_prerequisites_for_form( $form_id ) {
150 - $prerequisites = $this->add_prerequisites_for_form( $form_id );
151 -
152 - $this->prerequisites[ $form_id ] = '';
153 -
154 - if ( ! empty( $prerequisites ) ) {
155 - $this->enqueue_assets();
156 - return $prerequisites;
157 - }
158 -
159 - return '';
160 - }
161 -
162 31 public function button_head() {
163 32 ?>
164 33
165 34 <style>
@@ -172,19 +41,20 @@
172 41 <?php
173 42 }
174 43
175 44 public function button() {
176 - if (current_user_can( 'delete_pages')){
45 + global $post;
46 + if (current_user_can( 'delete_pages' ) && $post->post_type != 'easy-opt-ins'){
177 47
178 - $button_title = __( 'Optin Cat' );
179 -
180 - if ( version_compare( $GLOBALS['wp_version'], '3.5', '<' ) ) {
181 - echo '<a href="#TB_inline?width=640&inlineId=fca-eoi-shortcode-thickbox" class="thickbox" title="' . $button_title . '">' . $button_title . '</a>';
182 - } else {
183 - $img = '<span class="wp-media-buttons-icon" id="fca-eoi-media-button"></span>';
184 - 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>';
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 + }
185 56 }
186 - }
187 57 }
188 58
189 59 public function button_footer() {
190 60 $options = array();
@@ -235,204 +105,67 @@
235 105 <?php
236 106 }
237 107
238 108 public function enqueue_assets() {
239 -
240 - if ( $this->assets_enqueued ) {
241 - return;
242 - }
243 -
244 - $this->assets_enqueued = true;
245 -
246 109 $protocol = is_ssl() ? 'https' : 'http';
247 -
248 - // Get lightboxes
249 - $lightboxes = get_posts( array(
250 - 'post_type' => 'easy-opt-ins',
251 - 'posts_per_page' => -1,
252 - 'orderby' => 'ID',
253 - 'meta_key' => 'fca_eoi_layout',
254 - 'meta_value' => 'lightbox_',
255 - 'meta_compare' => 'like',
256 - ) );
257 -
258 - // Get postboxes
259 - $postboxes = get_posts( array(
260 - 'post_type' => 'easy-opt-ins',
261 - 'posts_per_page' => -1,
262 - 'orderby' => 'ID',
263 - 'meta_key' => 'fca_eoi_layout',
264 - 'meta_value' => 'postbox_',
265 - 'meta_compare' => 'like',
266 - ) );
267 -
268 - // Get postboxes
269 - $widgets = get_posts( array(
270 - 'post_type' => 'easy-opt-ins',
271 - 'posts_per_page' => -1,
272 - 'orderby' => 'ID',
273 - 'meta_key' => 'fca_eoi_layout',
274 - 'meta_value' => 'layout_',
275 - 'meta_compare' => 'like',
276 - ) );
277 -
278 - // Exit function if not optin form exist
279 - if ( ! $lightboxes && ! $postboxes && ! $widgets ) {
280 - return;
281 - }
282 -
110 +
283 111 wp_enqueue_script( 'jquery' );
112 + wp_enqueue_style( 'fontawesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER );
284 113
285 - wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL . '/assets/style-new.css' );
286 - wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL . '/assets/script.js' );
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', 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.min.js', array( 'fca_eoi_jstz', 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js'), FCA_EOI_VER, true );
287 125
288 - wp_enqueue_style( 'fontawesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css' );
289 -
290 - wp_enqueue_script( 'tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/jquery.tooltipster.min.js' );
291 - wp_enqueue_style( 'tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.min.css' );
292 -
293 - wp_enqueue_script( 'featherlight', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.js' );
294 - wp_enqueue_style( 'featherlight', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.css' );
295 -
296 126 //PASS VARIABLES TO JAVASCRIPT
297 - wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
127 + $data = array (
128 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
129 + 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ),
130 + );
131 +
132 + wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data );
298 133 }
299 134
300 135 public function shortcode_content( $atts ) {
301 -
302 - $form_id = $atts['id'];
303 -
304 - /**
305 - * Check that we have a valid post ID
306 - */
307 - if( empty ( $form_id ) ) {
308 - return 'Missing form ID';
136 + if ( empty ( $atts['id'] ) ) {
137 + return 'Optin Cat: Invalid Form ID';
138 + } else {
139 + $form_id = $atts['id'];
140 + $post = get_post( $form_id );
309 141 }
310 - if( ! $post = get_post( $form_id ) ) {
311 - return 'Wrong form ID';
142 +
143 + if( !is_object( $post ) OR $post->post_status == 'trash' ) {
144 + return 'Optin Cat: Missing Form Data. Is it in the trash?';
312 145 }
313 -
314 - $fca_eoi_meta = get_post_meta( $form_id, 'fca_eoi', true );
315 - if( ! $fca_eoi_meta ) {
316 - return 'Form doesn\'t exist';
317 - }
318 -
319 - // Get template
320 - $layout_id = $fca_eoi_meta[ 'layout' ];
321 -
322 - $layout = new EasyOptInsLayout( $layout_id );
323 - $layout_type = $layout->layout_type;
324 - $html_path = $layout->path_to_resource( 'layout', 'html' );
325 - $html_wrap_path = $layout->path_to_html_wrapper();
326 146
327 - if ( ! file_exists( $html_path ) ) {
328 - return '';
147 + $animation = get_post_meta( $form_id, 'fca_eoi_animation', true);
148 + if (!empty( $animation ) ) {
149 + wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER );
329 150 }
330 -
331 -
332 - $template = str_replace(
333 - '{{{layout}}}',
334 - file_get_contents( $html_path ),
335 - file_get_contents( $html_wrap_path )
336 - );
337 -
338 -
339 - $form_wrapper = '';
340 - $form_wrapper_end = '';
341 -
342 - if ( $layout->layout_type != 'lightbox' ) {
343 - $form_wrapper =
344 - '<div class="' .
345 - 'fca_eoi_form_wrapper ' .
346 - $layout->layout_class . '_wrapper ' .
347 - 'fca_eoi_layout_' . $layout->layout_number . '_wrapper' .
348 - '">';
349 - $form_wrapper_end = '</div>';
350 - }
351 151
352 - $errorTexts = fca_eoi_get_error_texts($form_id);
152 + $this->enqueue_assets();
153 + $head = get_post_meta( $form_id, 'fca_eoi_head', true );
353 154
354 - //determine if ajax or thank you page redirect
355 - $thanks_mode = fca_eoi_get_thanks_mode($form_id);
356 - if ($thanks_mode == 'ajax') {
357 - $thanks_page = K::get_var( 'thankyou_ajax', $fca_eoi_meta, '' );
358 - } else {
359 - $thanks_page = get_permalink( K::get_var( 'thank_you_page', $fca_eoi_meta ) );
360 - }
155 + $layout_id = get_post_meta ( $form_id, 'fca_eoi_layout', true );
156 + $layout = new EasyOptInsLayout( $layout_id );
361 157
362 - if (empty ($thanks_page)) {
363 - $thanks_mode = 'redirect';
364 - $thanks_page = get_site_url();
365 - }
158 + if ( $layout->layout_type !== 'lightbox' && $layout->layout_type !== 'banner' && $layout->layout_type !== 'overlay' ) {
159 +
160 + require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/RobotDetector/RobotDetector.php';
161 + $robot_detector = new RobotDetector();
162 +
163 + if ( get_post( $form_id ) && !is_user_logged_in() && !$robot_detector->is_robot() ) {
164 + EasyOptInsActivity::get_instance()->add_impression( $form_id );
165 + }
166 +
167 + }
366 168
367 - // Fill template with our formatting stuff
368 - $template = str_replace(
369 - array(
370 - '<form>',
371 - '{{{description_copy}}}',
372 - '{{{headline_copy}}}',
373 - '{{{name_field}}}',
374 - '{{{email_field}}}',
375 - '{{{submit_button}}}',
376 - '{{{privacy_copy}}}',
377 - '{{{fatcatapps_link}}}',
378 - '</form>',
379 - ),
380 - array(
381 - sprintf(
382 - $form_wrapper .
383 - '<div id="fca_eoi_form_%s" class="fca_eoi_form_content">' .
384 - '<form method="post" action="#" class="fca_eoi_form %s %s" ' .
385 - 'data-fca_eoi_list_id="%s" data-fca_eoi_thank_you_page="%s" data-fca_eoi_thank_you_mode="%s" novalidate' .
386 - '>' .
387 - '<input type="hidden" id="fca_eoi_form_id" name="fca_eoi_form_id" value="%s" />',
388 - $form_id,
389 - 'fca_eoi_layout_' . $layout->layout_number,
390 - $layout->layout_class,
391 - K::get_var( 'list_id', $fca_eoi_meta ),
392 - $thanks_page,
393 - $thanks_mode,
394 - $post->ID
395 - ),
396 - '<div>{{{description_copy}}}</div>',
397 - '<div>{{{headline_copy}}}</div>',
398 - '<input class="fca_eoi_form_input_element" type="text" name="name" placeholder="{{{name_placeholder}}}">',
399 - '<input class="fca_eoi_form_input_element" type="email" name="email" placeholder="{{{email_placeholder}}}">',
400 - '<div class="fca_eoi_spiner_div"><span class="fca_eoi_loading_spinner"></span></div><input class="fca_eoi_form_button_element" type="submit" value="{{{button_copy}}}">',
401 - '<div>{{{privacy_copy}}}</div>',
402 - '{{#show_fatcatapps_link}}<div class="fca_eoi_layout_fatcatapps_link_wrapper fca_eoi_form_text_element"><a href="http://fatcatapps.com/eoi" target="_blank">Powered by Optin Cat</a></div>{{/show_fatcatapps_link}}',
403 - '<input type="hidden" name="id" value="' . $form_id . '"><input type="hidden" name="fca_eoi" value="1">
404 - <input type="hidden" name="fca_eoi_error_texts_email" class="fca_eoi_error_texts_email" value="' . htmlspecialchars ($errorTexts['invalid_email']) . '">
405 - <input type="hidden" name="fca_eoi_error_texts_required" class="fca_eoi_error_texts_required" value="' . htmlspecialchars ($errorTexts['field_required']) . '">' . wp_nonce_field( 'fca_eoi_submit_form', 'fca_eoi_nonce', TRUE, FALSE ) . '</form></div>' . $form_wrapper_end,
406 - ),
407 - $template
408 - );
409 -
410 - $mustache = new Mustache_Engine;
411 - $output = $mustache->render(
412 - $template,
413 - array(
414 - 'headline_copy' => $fca_eoi_meta[ 'headline_copy' ],
415 - 'description_copy' => $fca_eoi_meta[ 'description_copy' ],
416 - 'privacy_copy' => $fca_eoi_meta[ 'privacy_copy' ],
417 - 'name_placeholder' => $fca_eoi_meta[ 'name_placeholder' ],
418 - 'email_placeholder' => $fca_eoi_meta[ 'email_placeholder' ],
419 - 'button_copy' => $fca_eoi_meta[ 'button_copy' ],
420 - 'show_name_field' => K::get_var( 'show_name_field', $fca_eoi_meta ),
421 - 'show_fatcatapps_link' => K::get_var( 'show_fatcatapps_link', $fca_eoi_meta ),
422 - )
423 - );
424 -
425 - // add the fca_eoi_alter_form
426 - $output = apply_filters( 'fca_eoi_alter_form'
427 - , $output
428 - , $fca_eoi_meta
429 - );
430 -
431 -
432 - $prerequisites = $this->get_prerequisites_for_form( $form_id );
433 - $prerequisites = str_replace('<style', '<style scoped', $prerequisites);
434 -
435 - // Return form with debugging information if applicable
436 - return $prerequisites . $output . ( FCA_EOI_DEBUG ? @d( $fca_eoi_meta, $template ) : '' );
169 + return $head;
437 170 }
438 171 }