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 -318 1.5.52.0.2 View file →
@@ -25,137 +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 -
91 - $layout = new EasyOptInsLayout( $layout_id );
92 - $scss_path = $layout->path_to_resource( 'layout', 'scss' );
93 -
94 - if ( file_exists( $scss_path ) ) {
95 - $css_path = str_replace ( '.scss' , '_min.css', $scss_path );
96 - $css = file_get_contents( $css_path );
97 - $head .= '<style>' .
98 - '.fca_eoi_form p { width: auto; }' .
99 - '#fca_eoi_form_' . $form_id . ' input{ max-width: 9999px; }' . $css . '}' .
100 - '</style>';
101 - }
102 -
103 -
104 - // Add per form CSS
105 - $head .= '<style>.fca_eoi_form{ margin: auto; }</style>';
106 -
107 - $css = '';
108 - if ( ! empty( $fca_eoi_meta[ $layout_id ] ) ) {
109 - $head .= "<style name='fca_eoi_form_style_$form_id'>";
110 -
111 - foreach ( $fca_eoi_meta[ $layout_id ] as $selector => $declarations ) {
112 - $css .= "#fca_eoi_form_$form_id $selector{";
113 - foreach ( $declarations as $property => $value ) {
114 - if ( strlen( $value ) ) {
115 - $css .= "$property:$value !important;";
116 - }
117 - }
118 - $css .= '}';
119 - }
120 -
121 - $head .= $css . '</style>';
122 - }
123 -
124 - if ( $layout->layout_type != 'lightbox' ) {
125 - $head .= '<script>' . EasyOptInsActivity::get_instance()->get_tracking_code( $form_id ) . '</script>';
126 - }
127 -
128 - $this->prerequisites[ $form_id ] = $head;
129 -
130 - delete_post_meta( $form_id, 'fca_eoi_head' );
131 - add_post_meta( $form_id, 'fca_eoi_head', $head );
132 -
133 -
134 - return $head;
135 -
136 - }
137 -
138 - }
139 -
140 - /**
141 - * @param int $form_id
142 - *
143 - * @return string
144 - */
145 - private function get_prerequisites_for_form( $form_id ) {
146 - $prerequisites = $this->add_prerequisites_for_form( $form_id );
147 -
148 - $this->prerequisites[ $form_id ] = '';
149 -
150 - if ( ! empty( $prerequisites ) ) {
151 - $this->enqueue_assets();
152 - return $prerequisites;
153 - }
154 -
155 - return '';
156 - }
157 -
158 31 public function button_head() {
159 32 ?>
160 33
161 34 <style>
@@ -168,19 +41,20 @@
168 41 <?php
169 42 }
170 43
171 44 public function button() {
172 - if (current_user_can( 'delete_pages')){
45 + global $post;
46 + if (current_user_can( 'delete_pages' ) && $post->post_type != 'easy-opt-ins'){
173 47
174 - $button_title = __( 'Optin Cat' );
175 -
176 - if ( version_compare( $GLOBALS['wp_version'], '3.5', '<' ) ) {
177 - echo '<a href="#TB_inline?width=640&inlineId=fca-eoi-shortcode-thickbox" class="thickbox" title="' . $button_title . '">' . $button_title . '</a>';
178 - } else {
179 - $img = '<span class="wp-media-buttons-icon" id="fca-eoi-media-button"></span>';
180 - 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 + }
181 56 }
182 - }
183 57 }
184 58
185 59 public function button_footer() {
186 60 $options = array();
@@ -231,204 +105,67 @@
231 105 <?php
232 106 }
233 107
234 108 public function enqueue_assets() {
235 -
236 - if ( $this->assets_enqueued ) {
237 - return;
238 - }
239 -
240 - $this->assets_enqueued = true;
241 -
242 109 $protocol = is_ssl() ? 'https' : 'http';
243 -
244 - // Get lightboxes
245 - $lightboxes = get_posts( array(
246 - 'post_type' => 'easy-opt-ins',
247 - 'posts_per_page' => -1,
248 - 'orderby' => 'ID',
249 - 'meta_key' => 'fca_eoi_layout',
250 - 'meta_value' => 'lightbox_',
251 - 'meta_compare' => 'like',
252 - ) );
253 -
254 - // Get postboxes
255 - $postboxes = get_posts( array(
256 - 'post_type' => 'easy-opt-ins',
257 - 'posts_per_page' => -1,
258 - 'orderby' => 'ID',
259 - 'meta_key' => 'fca_eoi_layout',
260 - 'meta_value' => 'postbox_',
261 - 'meta_compare' => 'like',
262 - ) );
263 -
264 - // Get postboxes
265 - $widgets = get_posts( array(
266 - 'post_type' => 'easy-opt-ins',
267 - 'posts_per_page' => -1,
268 - 'orderby' => 'ID',
269 - 'meta_key' => 'fca_eoi_layout',
270 - 'meta_value' => 'layout_',
271 - 'meta_compare' => 'like',
272 - ) );
273 -
274 - // Exit function if not optin form exist
275 - if ( ! $lightboxes && ! $postboxes && ! $widgets ) {
276 - return;
277 - }
278 -
110 +
279 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 );
280 113
281 - wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL . '/assets/style-new.css' );
282 - 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 );
283 125
284 - wp_enqueue_style( 'fontawesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css' );
285 -
286 - wp_enqueue_script( 'tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/jquery.tooltipster.min.js' );
287 - wp_enqueue_style( 'tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.min.css' );
288 -
289 - wp_enqueue_script( 'featherlight', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.js' );
290 - wp_enqueue_style( 'featherlight', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.css' );
291 -
292 126 //PASS VARIABLES TO JAVASCRIPT
293 - 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 );
294 133 }
295 134
296 135 public function shortcode_content( $atts ) {
297 -
298 - $form_id = $atts['id'];
299 -
300 - /**
301 - * Check that we have a valid post ID
302 - */
303 - if( empty ( $form_id ) ) {
304 - 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 );
305 141 }
306 - if( ! $post = get_post( $form_id ) ) {
307 - 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?';
308 145 }
309 -
310 - $fca_eoi_meta = get_post_meta( $form_id, 'fca_eoi', true );
311 - if( ! $fca_eoi_meta ) {
312 - return 'Form doesn\'t exist';
313 - }
314 -
315 - // Get template
316 - $layout_id = $fca_eoi_meta[ 'layout' ];
317 -
318 - $layout = new EasyOptInsLayout( $layout_id );
319 - $layout_type = $layout->layout_type;
320 - $html_path = $layout->path_to_resource( 'layout', 'html' );
321 - $html_wrap_path = $layout->path_to_html_wrapper();
322 146
323 - if ( ! file_exists( $html_path ) ) {
324 - 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 );
325 150 }
326 -
327 -
328 - $template = str_replace(
329 - '{{{layout}}}',
330 - file_get_contents( $html_path ),
331 - file_get_contents( $html_wrap_path )
332 - );
333 -
334 -
335 - $form_wrapper = '';
336 - $form_wrapper_end = '';
337 -
338 - if ( $layout->layout_type != 'lightbox' ) {
339 - $form_wrapper =
340 - '<div class="' .
341 - 'fca_eoi_form_wrapper ' .
342 - $layout->layout_class . '_wrapper ' .
343 - 'fca_eoi_layout_' . $layout->layout_number . '_wrapper' .
344 - '">';
345 - $form_wrapper_end = '</div>';
346 - }
347 151
348 - $errorTexts = fca_eoi_get_error_texts($form_id);
152 + $this->enqueue_assets();
153 + $head = get_post_meta( $form_id, 'fca_eoi_head', true );
349 154
350 - //determine if ajax or thank you page redirect
351 - $thanks_mode = fca_eoi_get_thanks_mode($form_id);
352 - if ($thanks_mode == 'ajax') {
353 - $thanks_page = K::get_var( 'thankyou_ajax', $fca_eoi_meta, '' );
354 - } else {
355 - $thanks_page = get_permalink( K::get_var( 'thank_you_page', $fca_eoi_meta ) );
356 - }
155 + $layout_id = get_post_meta ( $form_id, 'fca_eoi_layout', true );
156 + $layout = new EasyOptInsLayout( $layout_id );
357 157
358 - if (empty ($thanks_page)) {
359 - $thanks_mode = 'redirect';
360 - $thanks_page = get_site_url();
361 - }
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 + }
362 168
363 - // Fill template with our formatting stuff
364 - $template = str_replace(
365 - array(
366 - '<form>',
367 - '{{{description_copy}}}',
368 - '{{{headline_copy}}}',
369 - '{{{name_field}}}',
370 - '{{{email_field}}}',
371 - '{{{submit_button}}}',
372 - '{{{privacy_copy}}}',
373 - '{{{fatcatapps_link}}}',
374 - '</form>',
375 - ),
376 - array(
377 - sprintf(
378 - $form_wrapper .
379 - '<div id="fca_eoi_form_%s" class="fca_eoi_form_content">' .
380 - '<form method="post" action="#" class="fca_eoi_form %s %s" ' .
381 - 'data-fca_eoi_list_id="%s" data-fca_eoi_thank_you_page="%s" data-fca_eoi_thank_you_mode="%s" novalidate' .
382 - '>' .
383 - '<input type="hidden" id="fca_eoi_form_id" name="fca_eoi_form_id" value="%s" />',
384 - $form_id,
385 - 'fca_eoi_layout_' . $layout->layout_number,
386 - $layout->layout_class,
387 - K::get_var( 'list_id', $fca_eoi_meta ),
388 - $thanks_page,
389 - $thanks_mode,
390 - $post->ID
391 - ),
392 - '<div>{{{description_copy}}}</div>',
393 - '<div>{{{headline_copy}}}</div>',
394 - '<input class="fca_eoi_form_input_element" type="text" name="name" placeholder="{{{name_placeholder}}}">',
395 - '<input class="fca_eoi_form_input_element" type="email" name="email" placeholder="{{{email_placeholder}}}">',
396 - '<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}}}">',
397 - '<div>{{{privacy_copy}}}</div>',
398 - '{{#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}}',
399 - '<input type="hidden" name="id" value="' . $form_id . '"><input type="hidden" name="fca_eoi" value="1">
400 - <input type="hidden" name="fca_eoi_error_texts_email" class="fca_eoi_error_texts_email" value="' . htmlspecialchars ($errorTexts['invalid_email']) . '">
401 - <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,
402 - ),
403 - $template
404 - );
405 -
406 - $mustache = new Mustache_Engine;
407 - $output = $mustache->render(
408 - $template,
409 - array(
410 - 'headline_copy' => $fca_eoi_meta[ 'headline_copy' ],
411 - 'description_copy' => $fca_eoi_meta[ 'description_copy' ],
412 - 'privacy_copy' => $fca_eoi_meta[ 'privacy_copy' ],
413 - 'name_placeholder' => $fca_eoi_meta[ 'name_placeholder' ],
414 - 'email_placeholder' => $fca_eoi_meta[ 'email_placeholder' ],
415 - 'button_copy' => $fca_eoi_meta[ 'button_copy' ],
416 - 'show_name_field' => K::get_var( 'show_name_field', $fca_eoi_meta ),
417 - 'show_fatcatapps_link' => K::get_var( 'show_fatcatapps_link', $fca_eoi_meta ),
418 - )
419 - );
420 -
421 - // add the fca_eoi_alter_form
422 - $output = apply_filters( 'fca_eoi_alter_form'
423 - , $output
424 - , $fca_eoi_meta
425 - );
426 -
427 -
428 - $prerequisites = $this->get_prerequisites_for_form( $form_id );
429 - $prerequisites = str_replace('<style', '<style scoped', $prerequisites);
430 -
431 - // Return form with debugging information if applicable
432 - return $prerequisites . $output . ( FCA_EOI_DEBUG ? @d( $fca_eoi_meta, $template ) : '' );
169 + return $head;
433 170 }
434 171 }