PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.5
Smart Grid-Layout Design for Contact Form 7 v4.5
4.18.0 4.17.0 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 4.0.0 4.0.1 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10 4.11 4.12 4.13 4.14 All 119 releases
← All changes | public/class-cf7-grid-layout-public.php +504 -644 4.134.5 View file →
@@ -92,16 +92,9 @@
92 92 * @access private
93 93 * @var Array $localised_data Localised data parameters.
94 94 */
95 95 private $localised_data = array();
96 - /**
97 - * The wp_errors returned by the CF7 v5.4 wpcf7_unship_uploaded_file() function.
98 - *
99 - * @since 4.10.1
100 - * @access private
101 - * @var Array $file_wp_errors track file errors.
102 - */
103 - private $file_wp_errors = array();
96 +
104 97 /**
105 98 * Initialize the class and set its properties.
106 99 *
107 100 * @since 1.0.0
@@ -108,8 +101,9 @@
108 101 * @param string $plugin_name The name of the plugin.
109 102 * @param string $version The version of this plugin.
110 103 */
111 104 public function __construct( $plugin_name, $version ) {
105 +
112 106 $this->plugin_name = $plugin_name;
113 107 $this->version = $version;
114 108 }
115 109 /**
@@ -171,34 +165,9 @@
171 165 * Register the stylesheets for the public-facing side of the site.
172 166 *
173 167 * @since 1.0.0
174 168 */
175 - public function register_styles_and_scripts() {
176 - global $wp_scripts, $post;
177 - $cf7id = $cf7key = '';
178 - if ( is_a( $post, 'WP_Post' ) ) { //&& has_shortcode( , 'cf7form')
179 - preg_match_all( '/' . get_shortcode_regex() . '/', $post->post_content, $matches, PREG_SET_ORDER );
180 - foreach($matches as $sc){
181 - switch($sc[2]){
182 - case 'contact-form-7':
183 - $attrs = shortcode_parse_atts($sc[3]);
184 - if(is_array($attrs) && isset($attrs['id'])) $cf7id = $attrs['id'];
185 - break;
186 - case 'cf7form':
187 - $attrs = shortcode_parse_atts($sc[3]);
188 - if(is_array($attrs) && isset($attrs['cf7key'])){
189 - $cf7key = $attrs['cf7key'];
190 - $cf7id = get_cf7form_id($cf7key);
191 - }
192 - }
193 - }
194 - }
195 - $resources = array();
196 - if(!empty($cf7id)){
197 - $resources = get_post_meta($cf7id, '_cf7sg_script_classes', true);
198 - if(empty($resources)) $resources = array();
199 - }
200 -
169 + public function register_styles() {
201 170 $airplane=false;
202 171 if( class_exists( 'Airplane_Mode_Core' ) && Airplane_Mode_Core::getInstance()->enabled()){
203 172 $airplane=true;
204 173 }
@@ -205,17 +174,18 @@
205 174 $plugin_dir = plugin_dir_url( __DIR__ );
206 175 //default style for cf7 grid forms (row buttons and tables mainly).
207 176 //others
208 177 // get registered script object for jquery-ui
209 - $ui_ver = '1.12.1';
210 - if(!empty($wp_scripts)) $ui_ver = $wp_scripts->query('jquery-ui-core')->ver;
178 + global $wp_scripts;
179 + $ui = $wp_scripts->query('jquery-ui-core');
180 +
211 181 // tell WordPress to load the Smoothness theme from Google CDN
212 182 if( !$airplane ){
213 183 $protocol = is_ssl() ? 'https' : 'http';
214 - $url_path = "$protocol://ajax.googleapis.com/ajax/libs/jqueryui/{$ui_ver}/";
215 - wp_register_style('cf7-jquery-ui', $url_path . 'themes/smoothness/jquery-ui.min.css', array(), $ui_ver , 'all');
216 - wp_register_style( 'cf7-jquery-ui-theme', $url_path . 'jquery-ui.theme.min.css', array(), $ui_ver, 'all');
217 - wp_register_style( 'cf7-jquery-ui-structure', $url_path . 'jquery-ui.structure.min.css', array(), $ui_ver, 'all');
184 + $url_path = "$protocol://cdnjs.cloudflare.com/ajax/libs/jqueryui/{$ui->ver}/";
185 + wp_register_style('cf7-jquery-ui', $url_path . 'themes/smoothness/jquery-ui.min.css', array(), $ui->ver , 'all');
186 + wp_register_style( 'cf7-jquery-ui-theme', $url_path . 'jquery-ui.theme.min.css', array(), $ui->ver, 'all');
187 + wp_register_style( 'cf7-jquery-ui-structure', $url_path . 'jquery-ui.structure.min.css', array(), $ui->ver, 'all');
218 188 }
219 189
220 190
221 191 /** @since 3.1,0 improve live loading of resources */
@@ -220,80 +190,61 @@
220 190
221 191 /** @since 3.1,0 improve live loading of resources */
222 192 $ff = '';
223 193 $pf='';
224 - if((!defined('WP_DEBUG') || !WP_DEBUG) && !isset($_GET['cf7sgdbg'])){
194 + if(!defined('WP_DEBUG') || !WP_DEBUG){
225 195 $ff = '.min';
226 196 $pf = '/min';
227 197 }
228 198 wp_register_style( 'cf7-benchmark-css', $plugin_dir . "public/css{$pf}/cf7-benchmark.css", array(), $this->version, 'all' );
229 -
199 + wp_register_style( $this->plugin_name, $plugin_dir . "public/css{$pf}/cf7-grid-layout-public.css", array(), $this->version, 'all' );
230 200 wp_register_style( 'smart-grid', $plugin_dir . "assets/css.gs/smart-grid{$ff}.css", array(), $this->version, 'all' );
201 + wp_register_style('jquery-nice-select-css', $plugin_dir . "assets/jquery-nice-select/css/nice-select{$ff}.css", array(), $this->version, 'all' );
231 202 wp_register_style('jquery-toggles-css', $plugin_dir . "assets/jquery-toggles/css/toggles{$ff}.css", array(), $this->version, 'all' );
232 203 wp_register_style('jquery-toggles-light-css', $plugin_dir . "assets/jquery-toggles/css/themes/toggles-light{$ff}.css", array('jquery-toggles-css'), $this->version, 'all' );
233 -
204 + /** @since 3.2.1 use cloudflare for live sites */
205 + if( $airplane || (defined('WP_DEBUG') && WP_DEBUG) ){
206 + wp_register_style('select2-style', $plugin_dir . 'assets/select2/css/select2.min.css', array(), '4.0.13', 'all' );
207 + }else{
208 + wp_register_style('select2-style', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css', array(), '4.0.13','all');
209 + }
234 210 /** @since 4.2.0 enable Gliderliders for slider sections */
235 - $min = '';
236 - if(!defined('WP_GURUS_DEBUG') || !WP_GURUS_DEBUG) $min = '.min';
237 - wp_register_style('glider-style', $plugin_dir . "assets/glider-js/glider{$min}.css", array(), '1.7.4','all');
211 + wp_register_style('glider-style', $plugin_dir . 'assets/glider-js/glider.min.css', array(), '1.7.4','all');
238 212
239 - $dep = array();
240 - foreach($resources as $class){
241 - switch($class){
242 - case 'has-hybriddd':
243 - $dep[] ='hybriddd-style';
244 - break;
245 - case 'has-select2':
246 - $dep[] ='select2-style';
247 - break;
248 - case 'has-nice-select':
249 - $dep[] ='jquery-nice-select-css';
250 - break;
251 - case 'has-slider':
252 - $dep[] ='glider-style';
253 - break;
254 - case 'has-toggles':
255 - $dep[] = 'jquery-toggles-light-css';
256 - $dep[] = 'cf7-jquery-ui';
257 - $dep[] = 'cf7-jquery-ui-theme';
258 - $dep[] = 'cf7-jquery-ui-structure';
259 - break;
260 - case 'has-date':
261 - $dep[] = 'cf7-jquery-ui';
262 - case 'has-tabs':
263 - $dep[] = 'cf7-jquery-ui';
264 - $dep[] = 'cf7-jquery-ui-theme';
265 - $dep[] = 'cf7-jquery-ui-structure';
266 - break;
267 - case 'has-accodrion':
268 - $dep[] = 'cf7-jquery-ui';
269 - $dep[] = 'cf7-jquery-ui-theme';
270 - $dep[] = 'cf7-jquery-ui-structure';
271 - break;
213 + //allow custom script registration
214 + do_action('smart_grid_register_styles');
215 + }
272 216
273 - }
217 + /**
218 + * Register the JavaScript for the public-facing side of the site.
219 + *
220 + * @since 1.0.0
221 + */
222 + public function register_scripts() {
223 + $airplane=false;
224 + if( class_exists( 'Airplane_Mode_Core' ) && Airplane_Mode_Core::getInstance()->enabled()){
225 + $airplane=true;
274 226 }
275 - wp_register_style( $this->plugin_name, $plugin_dir . "public/css{$pf}/cf7-grid-layout-public.css", $dep, $this->version, 'all' );
276 -
277 - do_action('smart_grid_register_styles',$airplane, $min, $resources, $cf7key, $cf7id);
278 -
279 - //script registration
280 - //load custom css/js script from theme css folder.
281 - // $themepath = get_stylesheet_directory();
282 - // $themeuri = get_stylesheet_directory_uri();
283 - $dep = array( 'jquery','contact-form-7' );
284 -
285 - // if( !empty($cf7key) && file_exists($themepath.'/js/'.$cf7key.'.js') ){
286 - // $dep[] = $cf7key.'-js';
287 - // wp_register_script( $cf7key.'-js' , $themeuri.'/js/'.$cf7key.'.js', array('jquery', $this->plugin_name), null, true);
288 - // }
289 - wp_register_script( $this->plugin_name, $plugin_dir . "public/js{$pf}/cf7-grid-layout-public.js", $dep, $this->version, true );
227 + /** @since 3.1,0 improve live loading of resources */
228 + $pf='';
229 + if(!defined('WP_DEBUG') || !WP_DEBUG){
230 + $pf = '/min';
231 + }
232 + $plugin_dir = plugin_dir_url( __DIR__ );
233 + wp_register_script( $this->plugin_name, $plugin_dir . "public/js{$pf}/cf7-grid-layout-public.js", array( 'jquery','contact-form-7' ), $this->version, true );
234 + /** @since 3.2.1 use cloudflare for live sites */
235 + if( $airplane || (defined('WP_DEBUG') && WP_DEBUG) ){
236 + wp_register_script('jquery-select2', $plugin_dir . 'assets/select2/js/select2.min.js', array( 'jquery' ), '4.0.13', true );
237 + }else{
238 + wp_register_script('jquery-select2', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js', array( 'jquery' ), '4.0.13', true );
239 + }
240 + wp_register_script('jquery-nice-select', $plugin_dir . 'assets/jquery-nice-select/js/jquery.nice-select.min.js', array( 'jquery' ), $this->version, true );
290 241 wp_register_script('jquery-toggles', $plugin_dir . 'assets/jquery-toggles/toggles.min.js', array( 'jquery' ), $this->version, true );
291 242 wp_register_script('js-cf7sg-benchmarking', $plugin_dir . "public/js{$pf}/cf7-benchmark.js", array( 'jquery' ), $this->version, true );
292 -
293 - wp_register_script('glider-js', $plugin_dir . "assets/glider-js/glider{$min}.js", null, '1.7.4',true);
243 + /** @since 4.2.0 enable Glider sliders for slider sections */
244 + wp_register_script('glider-js', $plugin_dir . 'assets/glider-js/glider.js', null, '1.7.4',true);
294 245 //allow custom script registration
295 - do_action('smart_grid_register_scripts', $airplane, $min, $resources, $cf7key, $cf7id);
246 + do_action('smart_grid_register_scripts');
296 247 }
297 248 /**
298 249 * Dequeue script 'contact-form-7'
299 250 * hooked on 'wp_print_scripts', this canbe re-enqeued on specific cf7 shortcode calls
@@ -354,17 +305,8 @@
354 305 }
355 306 //wp_enqueue_script('contact-form-7'); //default cf7 plugin script.
356 307 wp_enqueue_script('contact-form-7'); //default cf7 plugin script.
357 308 $cf7_id = $attr['id'];
358 - //validate version number.
359 - /**
360 - * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
361 - */
362 - $is_form = get_post_meta($cf7_id, '_cf7sg_managed_form', true);
363 - $form_version = get_post_meta($cf7_id, '_cf7sg_version', true);
364 - if($is_form and (empty($form_version) or version_compare($form_version, CF7SG_VERSION_FORM_UPDATE, '<')) ){
365 - return '<p><em>'.__('Form is deprecated, please contact the webmaster to <a href="https://wordpress.org/support/topic/upgrade-your-form-message-instead-of-form-being-displayed/">upgrade</a> this form.', 'cf7-grid-layout').'</em></p>';
366 - }
367 309 //get the key
368 310 $cf7post = get_post($cf7_id);
369 311 if(empty($cf7post) || WPCF7_ContactForm::post_type != $cf7post->post_type){ //not a form.
370 312 return $output;
@@ -375,9 +317,8 @@
375 317 $class = get_post_meta($cf7_id, '_cf7sg_script_classes', true);
376 318 if(empty($class)){
377 319 $class = array();
378 320 }
379 - // debug_msg($class, "$cf7_id form classes ");
380 321 //check classes required for sub-forms.
381 322 $sub_forms = array();
382 323 $use_grid_js = false;
383 324 $sub_form_keys = get_post_meta($cf7_id, '_cf7sg_sub_forms', true);
@@ -413,8 +354,12 @@
413 354 wp_enqueue_script('jquery-ui-datepicker');
414 355 wp_enqueue_style('cf7-jquery-ui');
415 356 $use_grid_js=true;
416 357 }
358 + /**
359 + * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
360 + */
361 + $is_form = get_post_meta($cf7_id, '_cf7sg_managed_form', true);
417 362
418 363 $use_grid_js = ($use_grid_js or $is_form);
419 364
420 365 //cf7 plugin styles.
@@ -425,43 +370,25 @@
425 370 $messages = array();
426 371 if( !empty($form) ) $messages = $form->prop('messages');
427 372 else debug_msg("CF7SG FROM ERROR: unable to retrieve cf7 form $cf7_id");
428 373 //setup classes and id for wrapper.
429 - $css_id ='';
430 - apply_filters_deprecated('cf7_smart_grid_form_id', array($css_id, $attr), '4.6.0','', __('this filter is no longer available', 'cf7-grid-layout'));
431 - $css_id = $this->form_css_id($cf7_key);
432 - /** @since 4.6.0 allow redirect on submit */
433 - $redirect = get_post_meta($cf7_id, '_cf7sg_page_redirect',true);
434 - if(!empty($redirect)){
435 - $cache = get_post_meta($cf7_id, '_cf7sg_cache_redirect_data',true);
436 - if(!empty($cache)){
437 - $cache = wp_create_nonce($css_id);
438 - }
439 - $redirect = get_permalink($redirect).( empty($cache) ? '':"?cf7sg=$cache");
440 - }else $redirect='';
374 + $css_id = apply_filters('cf7_smart_grid_form_id', 'cf7sg-form-'.$cf7_key, $attr);
375 +
441 376 /** @since 4.4.0 enable prefilling of form fields*/
442 377 $prefill = apply_filters('cf7sg_prefill_form_fields', array(), $cf7_key);
443 - if( !empty($redirect) or !empty($prefill) ) $use_grid_js = true;
378 + if( !empty($prefill) and is_array($prefill) ) $use_grid_js = true;
444 379 if($use_grid_js){
445 - $this->localise_script( array(
380 + $this->localised_data = array(
446 381 'url' => admin_url( 'admin-ajax.php' ),
382 + 'submit_disabled'=> isset($messages['submit_disabled']) ? $messages['submit_disabled']: __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
383 + 'max_table_rows' => isset($messages['max_table_rows']) ? $messages['max_table_rows']: __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
384 + 'table_labels' => apply_filters('cf7sg_remove_table_row_labels',true,$cf7_key),
447 385 'debug'=>( defined('WP_DEBUG') && WP_DEBUG ),
448 - $css_id => array(
449 - 'prefill'=>$prefill,
450 - 'submit_disabled'=> isset($messages['submit_disabled']) ? $messages['submit_disabled']: __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
451 - 'max_table_rows' => isset($messages['max_table_rows']) ? $messages['max_table_rows']: __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
452 - 'table_labels' => apply_filters('cf7sg_remove_table_row_labels',true,$cf7_key),
453 - 'redirect'=>$redirect,
454 - 'slider_auto_scroll' => apply_filters('cf7sg_slider_auto_scroll', true, $cf7_key)
455 - )
456 - ));
386 + $css_id => $prefill,
387 + );
457 388 //cf7sg script & style.
458 389 wp_enqueue_script($this->plugin_name);
459 - //wp_add_inline_script( $this->plugin_name, 'cf7sg', json_encode($this->localise_script()), 'before' );
460 - $localise = json_encode($this->localise_script());
461 - add_action('wp_footer', function() use ($localise){
462 - printf('<script type="text/javascript">var cf7sg = %s</script>', $localise);
463 - });
390 + wp_localize_script( $this->plugin_name, 'cf7sg', $this->localise_script() );
464 391 }
465 392 //load custom css/js script from theme css folder.
466 393 $themepath = get_stylesheet_directory();
467 394 $themeuri = get_stylesheet_directory_uri();
@@ -470,17 +397,18 @@
470 397 if($is_form) $dep =array($this->plugin_name);
471 398 wp_enqueue_style( $cf7_key.'-css' , $themeuri.'/css/'.$cf7_key.'.css', $dep, null, 'all');
472 399 }
473 400 if( file_exists($themepath.'/js/'.$cf7_key.'.js') ){
474 - wp_enqueue_script( $cf7_key.'-js', $themeuri.'/js/'.$cf7_key.'.js', array('jquery', $this->plugin_name), null, true);
475 - do_action_deprecated('smart_grid_register_custom_script', array($cf7_key), '4.6.0', 'cf7sg_enqueue_custom_script-$form_key', __('deprecated action hook','cf7-grid-layout'));
476 - do_action("cf7sg_enqueue_custom_script-{$cf7_key}",$cf7_key.'-js');
401 + $dep = array();
402 + if($use_grid_js) $dep =array($this->plugin_name);
403 + wp_enqueue_script( $cf7_key.'-js' , $themeuri.'/js/'.$cf7_key.'.js', $dep , null, true);
404 + do_action('smart_grid_register_custom_script', $cf7_key);
477 405 }
478 406
479 407 if(empty($is_form) or !$is_form){
480 - do_action('smart_grid_enqueue_scripts', $cf7_key, $attr, $class);
408 + do_action('smart_grid_enqueue_scripts', $cf7_key, $attr);
481 409 $classes = implode(' ', $class) .' key_'.$cf7_key;
482 - $output = '<div class="cf7sg-container cf7sg-not-grid"><div id="' . $css_id . '" class="'.($use_grid_js?'cf7-smart-grid ':''). $classes . '">' . $output . '</div></div>';
410 + $output = '<div class="cf7sg-container cf7sg-not-grid"><div id="' . $css_id . '" class="cf7-smart-grid ' . $classes . '">' . $output . '</div></div>';
483 411 return $output;
484 412 }
485 413 //grid styling.
486 414 wp_enqueue_style($this->plugin_name);
@@ -545,9 +473,9 @@
545 473 wp_enqueue_style('jquery-toggles-light-css');
546 474 }
547 475 //$cf7_key = get_post_meta($cf7_id, '_smart_grid_cf7_form_key', true);
548 476 //allow custom script print
549 - do_action('smart_grid_enqueue_scripts', $cf7_key, $attr, $class);
477 + do_action('smart_grid_enqueue_scripts', $cf7_key, $attr);
550 478
551 479 $classes = implode(' ', $class) .' key_'.$cf7_key;
552 480 $output = '<div class="cf7sg-container"><div id="' . $css_id . '" class="cf7-smart-grid ' . $classes . '">' . $output . '</div></div>';
553 481 return $output;
@@ -552,20 +480,10 @@
552 480 $output = '<div class="cf7sg-container"><div id="' . $css_id . '" class="cf7-smart-grid ' . $classes . '">' . $output . '</div></div>';
553 481 return $output;
554 482 }
555 483 /**
484 + * Function hooked on 'cf7_2_post_form_values' to load toggle status for saed submissions
556 485 *
557 - *
558 - *@since 4.6.0
559 - *@param string $param text_description
560 - *@return string text_description
561 - */
562 - public function form_css_id($cf7_key){
563 - return 'cf7sg-form-'.$cf7_key;
564 - }
565 - /**
566 - * Function hooked on 'cf7_2_post_form_values' to load toggle status for saved submissions
567 - *
568 486 *@since 1.1.0
569 487 *@param string $post_id saved submission post ID
570 488 */
571 489 public function load_saved_toggled_status($field_values){
@@ -573,13 +491,12 @@
573 491 return $field_values;
574 492 }
575 493 $post_id = $field_values['map_post_id'];
576 494 $toggles = get_post_meta($post_id, 'cf7sg_toggles_status', true);
495 + //debug_msg($toggles, $post_id.' status ');
577 496 if(!empty($toggles)){
578 - $cf7post = get_post($post_id);
579 - $cf7_key = $cf7post->post_name;
580 497 wp_enqueue_script($this->plugin_name);
581 - wp_localize_script( $this->plugin_name, 'cf7sg', $this->localise_script( array('toggles_status' => $toggles)), $this->form_css_id($cf7_key));
498 + wp_localize_script( $this->plugin_name, 'cf7sg', $this->localise_script( array('toggles_status' => $toggles)) );
582 499 }
583 500 return $field_values;
584 501 }
585 502 /**
@@ -588,14 +505,10 @@
588 505 *@since 2.6.0
589 506 *@param array $params additional parameter to send.
590 507 *@return array data array to localise
591 508 */
592 - private function localise_script($params=array(), $css_id=null){
593 - if( empty($css_id) ) $this->localised_data += $params;
594 - else{
595 - if( !isset($this->localised_data[$css_id]) ) $this->localised_data[$css_id] = array();
596 - $this->localised_data[$css_id] += $params;
597 - }
509 + private function localise_script($params=array()){
510 + $this->localised_data += $params;
598 511 return $this->localised_data;
599 512 }
600 513 /**
601 514 * Update sub-forms in cf7 forms
@@ -653,19 +566,20 @@
653 566 * @since 2.0.0
654 567 */
655 568 public function register_cf7_shortcode() {
656 569 if( function_exists('wpcf7_add_form_tag') ) {
570 + //dynamic select
571 + wpcf7_add_form_tag(
572 + array( 'dynamic_select', 'dynamic_select*' ),
573 + array($this,'cf7_taxonomy_shortcode'),
574 + true //has name
575 + );
657 576 //benchmark
658 577 wpcf7_add_form_tag(
659 578 array( 'benchmark', 'benchmark*' ),
660 579 array($this,'cf7_benchmark_shortcode'),
661 580 true //has name
662 - );
663 - /** @since 4.10.0 abstract out dynamic lists */
664 - do_action('cf7sg_register_dynamic_lists');
665 - $lists = cf7sg_get_dynamic_lists();
666 - // debug_msg($lists, 'dynamic lists ');
667 - foreach($lists as $l) $l->register_cf7_shortcode();
581 + );
668 582 }
669 583 }
670 584 /**
671 585 * Register a [benchmark] shortcode with CF7.
@@ -683,12 +597,63 @@
683 597 ob_start();
684 598 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
685 599 $html = ob_get_contents ();
686 600 ob_end_clean();
601 + $this->update_form_classes('has-benchmark');
687 602 return $html;
688 603 }
604 + /**
605 + * Register a [dynamic_display] shortcode with CF7.
606 + * called by funciton above
607 + * This function registers a callback function to expand the shortcode for the googleMap form fields.
608 + * @since 1.0.0
609 + * @param strng $tag the tag name designated in the tag help screen
610 + * @return string a set of html fields to capture the googleMap information
611 + */
689 612
613 + public function cf7_taxonomy_shortcode($tag){
614 + $tag = new WPCF7_FormTag( $tag );
615 + $source = self::get_dynamic_drodown_attributes($tag);
616 + ob_start();
617 + include( plugin_dir_path( __FILE__ ) . '/partials/cf7-taxonomy-tag-display.php');
618 + $html = ob_get_contents ();
619 + ob_end_clean();
620 + return $html;
621 + }
690 622 /**
623 + *
624 + *
625 + * @since 1.0.0
626 + * @param mixed $class array of classes or string to set class for form and dependency loading .
627 + * @param Object $cf7_form cf7 post id against which set the c$lass .
628 + **/
629 + public function update_form_classes($class, $cf7_id=null){
630 + if(empty($cf7_id)){
631 + //get latest form
632 + if(function_exists('wpcf7_get_current_contact_form')){
633 + $cf7_form = wpcf7_get_current_contact_form();
634 + if(!empty($cf7_form)) $cf7_id = $cf7_form->id();
635 + }
636 + }
637 + if(empty($cf7_id)){
638 + debug_msg('Unable to get Contact Form 7 ID to set class: '.$class);
639 + return;
640 + }
641 + $classes = get_post_meta($cf7_id, '_cf7sg_classes', true);
642 + if(empty($classes)){
643 + $classes = array();
644 + }
645 + if(is_array($class)){
646 + foreach($class as $class_name){
647 + $classes[$class_name] = true;
648 + }
649 + }else{
650 + $classes[$class] = true;
651 + }
652 + update_post_meta($cf7_id, '_cf7sg_classes', $classes);
653 + return;
654 + }
655 + /**
691 656 * Function to save ajax submitted grid fields, grid fields are any input/select fields used in the table/tabs constructs
692 657 * hooked on wp_ajax_nopriv_save_grid_fields and wp_ajax_save_grid_fields. The ajax is only fired in case a sub-form has been updated.
693 658 * @since 1.0.0
694 659 **/
@@ -736,9 +701,8 @@
736 701 * @param Array $data unvalidated submitted data.
737 702 * @return Array filtered submitted data.
738 703 **/
739 704 public function setup_grid_values($data){
740 - // debug_msg($data, 'CF7 processed data ');
741 705 $cf7form = WPCF7_ContactForm::get_current();
742 706 // debug_msg($_POST);
743 707 if(empty($cf7form) ){
744 708 if(isset($_POST['_wpcf7']) ){
@@ -752,10 +716,10 @@
752 716 }
753 717 $cf7_id = $cf7form->id();
754 718 $this->form_id = $cf7_id;
755 719 //debug_msg($grid_fields, 'grid fields...');
756 -
757 - foreach($cf7form->scan_form_tags() as $tag){
720 + $tags = $cf7form->scan_form_tags();
721 + foreach($tags as $tag){
758 722 if(empty($tag->name)) continue;
759 723 $field_name = $tag['name'];
760 724 $field_type = self::field_type($field_name, $cf7_id);
761 725 switch($field_type){
@@ -763,39 +727,37 @@
763 727 case 'table':
764 728 case 'both':
765 729 // the $data array is passed by reference and will be consolidated.
766 730 /** @since 2.5.0 */
767 - $this->consolidate_grid_submissions($tag, $field_type, $data);
731 + if( isset($_POST['_cf7sg_version']) && version_compare($_POST['_cf7sg_version'],'2.5.0','>=') ){
732 + $this->consolidate_grid_submissions_v2($tag, $field_type, $data);
733 + }else{
734 + $this->consolidate_grid_submissions($field_name, $field_type, $data);
735 + }
768 736 break;
769 737 default:
770 738 $toggle = $this->get_toggle($field_name);
771 - /** @since 4.8.1 preserve cf7 data schema for some plugins */
772 - if( apply_filters('cf7sg_preserve_cf7_data_schema', false) ){
773 - if(!empty($toggle) && !$this->is_submitted($toggle)) $data[$field_name] = null;
774 - }else{
775 - if(!empty($toggle)){
776 - $data[$field_name] = $this->is_submitted($toggle) ? $this->get_field_value($field_name,$field_type, $tag) : null;
777 - }else $data[$field_name] = $this->get_field_value($field_name, $tag['basetype'], $tag);
778 - }
739 + if(!empty($toggle)){
740 + $data[$field_name] = $this->is_submitted($toggle) ? $this->get_field_value($field_name,$field_type, $tag) : null;
741 + }else $data[$field_name]= $this->get_field_value($field_name, $tag['basetype'], $tag);
742 +
779 743 break;
780 744 }
781 745 }
782 - // debug_msg($data, 'data consolidated');
783 746 //add toggled sections as submitted values.
784 747 $groups = get_post_meta($this->form_id, '_cf7sg_grid_grouped_toggles', true);
785 - if(!empty($groups)){
786 - foreach($groups as $group=>$grp_toggles){
787 - foreach($grp_toggles as $toggle){
788 - if( isset(self::$array_toggled_panels[$this->form_id][$toggle]) ){
789 - self::$array_toggled_panels[$this->form_id][$group]=self::$array_toggled_panels[$this->form_id][$toggle];
790 - break;
791 - }
748 +
749 + foreach($groups as $group=>$grp_toggles){
750 + foreach($grp_toggles as $toggle){
751 + if( isset(self::$array_toggled_panels[$this->form_id][$toggle]) ){
752 + self::$array_toggled_panels[$this->form_id][$group]=self::$array_toggled_panels[$this->form_id][$toggle];
753 + break;
792 754 }
793 755 }
794 - $data += self::$array_toggled_panels[$this->form_id];
795 756 }
757 + $data += self::$array_toggled_panels[$this->form_id];
796 758 // debug_msg($data, 'consolidated + submitted: ');
797 - // debug_msg($_POST);
759 + // $this->submitted_data[$this->form_id] = $data;
798 760 return $data;
799 761 }
800 762 /**
801 763 * new function to consolidate submitted data for improved handling of optional toggled fields as well as special fields such as files and checkboxes in tabbed sectoins.
@@ -805,13 +767,13 @@
805 767 *@param array $type field type, should be 'tab'/'table'/'both'.
806 768 *@param array $data cf7 form submissed data passed by reference as consolidated grid values will be removed and the original field value replaced with an array.
807 769 *@return array a filtered array of $index_suffix=>$value pairs for tabs or rows fields, The index suffix is '.row-<index>' for tables and '.tab-<index>' for tabs. This method returns a 2 dimensional array for fields which are both within rowns and tabs. The 2 dimensional array will list [<tab_suffix>][<row_suffix>]=>$value. The original field name that was submitted can be reconstructed as $field_name.$index_suffix. The first field will have an empty string as its $index_suffix.
808 770 */
809 - private function consolidate_grid_submissions($field_tag, $type, &$data){
771 + private function consolidate_grid_submissions_v2($field_tag, $type, &$data){
810 772 //get_post_meta($post_id, '_cf7sg_has_tables', true);
811 773 if(isset($_POST['_wpcf7']) ) $cf7_id = $_POST['_wpcf7'];
812 774 else{
813 - debug_msg("CF7SG ERROR: fn consolidate_grid_submissions() is unable to load submitted form");
775 + debug_msg("CF7SG ERROR: fn consolidate_grid_submissions_v2() is unable to load submitted form");
814 776 }
815 777 $is_used = false;
816 778 $field_name = $field_tag['name'];
817 779 $field_type = $field_tag['basetype'];
@@ -855,9 +817,14 @@
855 817 $table_origin = $origins[0];
856 818 $tab_origin = $origins[1];
857 819 $max_tabs = isset($_POST[$tab_origin])?$_POST[$tab_origin]:0;
858 820 $values[''] = array(); //init multi-dimensional array
859 -
821 + // not required since it is set in the for loop below.
822 + // if(!empty($toggle) && !$this->is_submitted($toggle)){ //check if submitted, tab<-toggle<-table.
823 + // $values[''][''] = null;
824 + // }else{
825 + // $values[''][''] = $this->get_field_value($field_name,$field_type,$field_tag);
826 + // }
860 827 for($idx=0;$idx<$max_tabs;$idx++){ //tables in other tabs.
861 828 $max_fields = 0;
862 829 if(0==$idx && isset($_POST[$table_origin])){
863 830 $max_fields = $_POST[$table_origin];
@@ -887,8 +854,10 @@
887 854 if ($a === $b) return 0;
888 855 return ($a > $b)? 1:-1;
889 856 }); //this will remove all the surplus fields
890 857 if( $is_used ) $data[$field_name] = $values;
858 + else
859 + return;
891 860 }
892 861 /**
893 862 * Extract either a file name or a field value
894 863 *
@@ -897,50 +866,23 @@
897 866 *@return string text_description
898 867 */
899 868 private function get_field_value($field_name, $field_type, $field_tag){
900 869 $value = '';
901 - if('file' == $field_type) { /** @since 4.9.0 handle files in posted data due to CF7 5.4 changes */
902 - if(empty($_FILES[$field_name])) return;
903 - $file = $_FILES[$field_name];
904 -
905 - $args = array(
906 - 'tag' => $field_tag,
907 - 'name' => $field_name,
908 - 'required' => $field_tag->is_required(),
909 - 'filetypes' => $field_tag->get_option( 'filetypes' ),
910 - 'limit' => $field_tag->get_limit_option(),
911 - );
912 - $value = wpcf7_unship_uploaded_file( $file, $args );
913 - if(is_wp_error($value)) {
914 - $this->file_wp_errors[$field_name]=$value;
915 - $value='';
916 - }
870 + if('file' == $field_type) {
871 + $value = isset($_FILES[$field_name]) ? $_FILES[$field_name]['name']:'';
917 872 }else{
918 873 $pipes = $field_tag->pipes;
874 + $value = isset($_POST[$field_name]) ? $_POST[$field_name]:'';
919 875
920 - $value = $posted = isset($_POST[$field_name]) ? $_POST[$field_name]:'';
921 -
922 - if(function_exists('wpcf7_form_tag_supports') and wpcf7_form_tag_supports( $field_type, 'selectable-values' )){
923 - $value = (array) $value;
924 - }
925 -
926 876 if ( WPCF7_USE_PIPE and $pipes instanceof WPCF7_Pipes and ! $pipes->zero() and !in_array( $field_type, array('map','dynamic_select')) ){
927 - if(is_array($posted)){
928 - $value = array();
929 - foreach($posted as $v){
930 - $value[] = $pipes->do_pipe($v);
877 + if(is_array($value)){
878 + $piped = array();
879 + foreach($value as $v){
880 + $piped[] = $pipes->do_pipe($v);
931 881 }
932 - }else $value = $pipes->do_pipe($posted);
882 + $value = $piped;
883 + }else $value = $pipes->do_pipe($value);
933 884 }
934 -
935 - if ( $field_tag->has_option( 'free_text' ) and isset( $_POST[$field_name . '_free_text'] ) ){
936 - if(is_array($value)){
937 - $v = array_pop($value).' '.sanitize_text_field($_POST[$field_name . '_free_text']);
938 - $value[] = $v;
939 - }else{
940 - $value = $value.' '.sanitize_text_field($_POST[$field_name . '_free_text']);
941 - }
942 - }
943 885 }
944 886 return $value;
945 887 }
946 888 /**
@@ -988,37 +930,178 @@
988 930 }
989 931 }
990 932 self::$array_grid_fields[$form_id]=$grid_fields;
991 933 //load panel fields.
992 - self::$array_toggled_panels[$form_id]=array();
993 - $toggled_panels = array();
994 - if(isset($_POST['_cf7sg_toggles'])){
995 - $toggled_panels = json_decode( stripslashes($_POST['_cf7sg_toggles']));
996 - if(!empty($toggled_panels)) $toggled_panels = get_object_vars($toggled_panels);
997 - else $toggled_panels = array();
998 - }
999 - self::$array_toggled_panels[$form_id]=$toggled_panels;
934 + if( isset($_POST['_cf7sg_version']) && version_compare($_POST['_cf7sg_version'],'2.5.0','>=') ){
935 + self::$array_toggled_panels[$form_id]=array();
936 + $toggled_panels = array();
937 + if(isset($_POST['_cf7sg_toggles'])){
938 + $toggled_panels = json_decode( stripslashes($_POST['_cf7sg_toggles']));
939 + if(!empty($toggled_panels)) $toggled_panels = get_object_vars($toggled_panels);
940 + else $toggled_panels = array();
941 + }
942 + self::$array_toggled_panels[$form_id]=$toggled_panels;
1000 943
1001 - $fields = get_post_meta($form_id, '_cf7sg_grid_toggled_names', true);
1002 - self::$array_toggle_fields[$form_id]=array();
1003 - if(!empty($fields)){
1004 - foreach($fields as $panel=>$pfields){
1005 - foreach($pfields as $field){
1006 - if( isset(self::$array_toggle_fields[$form_id][$field]) ){
1007 - self::$array_toggle_fields[$form_id][$field][] = $panel;
1008 - }else{
1009 - self::$array_toggle_fields[$form_id][$field]= array($panel);
944 + $fields = get_post_meta($form_id, '_cf7sg_grid_toggled_names', true);
945 + self::$array_toggle_fields[$form_id]=array();
946 + if(!empty($fields)){
947 + foreach($fields as $panel=>$pfields){
948 + foreach($pfields as $field){
949 + if( isset(self::$array_toggle_fields[$form_id][$field]) ){
950 + self::$array_toggle_fields[$form_id][$field][] = $panel;
951 + }else{
952 + self::$array_toggle_fields[$form_id][$field]= array($panel);
953 + }
1010 954 }
1011 955 }
1012 956 }
957 + if(version_compare($_POST['_cf7sg_version'],'4.0.0','>=')){ //track tabbed toggles.
958 + $tabtgls = get_post_meta($form_id, '_cf7sg_grid_tabbed_toggles', true);
959 + if(!empty($tabtgls)) $tabtgls = array_fill_keys($tabtgls,true);
960 + else $tabtgls = array();
961 + self::$array_tabbed_toggles[$form_id]=$tabtgls;
962 + }
1013 963 }
1014 - $tabtgls = get_post_meta($form_id, '_cf7sg_grid_tabbed_toggles', true);
1015 - if(!empty($tabtgls)) $tabtgls = array_fill_keys($tabtgls,true);
1016 - else $tabtgls = array();
1017 - self::$array_tabbed_toggles[$form_id]=$tabtgls;
1018 964 return $grid_fields;
1019 965 }
966 + /**
967 + * Consolidates submitted data from table and tab fields into arrays.
968 + *
969 + *@since 1.0.0
970 + *@param string $field_name a cf7 form field name which is part of tabs or table grid section.
971 + *@param array $type field type, should be 'tab'/'table'/'both'.
972 + *@param array $data cf7 form submissed data passed by reference as consolidated grid values will be removed and the original field value replaced with an array.
973 + *@return array a filtered array of $index_suffix=>$value pairs for tabs or rows fields, The index suffix is '.row-<index>' for tables and '.tab-<index>' for tabs. This method returns a 2 dimensional array for fields which are both within rowns and tabs. The 2 dimensional array will list [<tab_suffix>][<row_suffix>]=>$value. The original field name that was submitted can be reconstructed as $field_name.$index_suffix. The first field will have an empty string as its $index_suffix.
974 + */
975 + private function consolidate_grid_submissions($field_name, $type, &$data){
976 + $cf7_key = '';
977 + if(isset($_POST['_wpcf7_key'])) $cf7_key = $_POST['_wpcf7_key'];
978 + $cf7_id = 0;
979 + if(isset($_POST['_wpcf7'])) $cf7_id = $_POST['_wpcf7'];
1020 980
981 + $values = array();
982 + $regex = '';
983 + $submitted_fields=array();
984 + $max_fields =0;
985 + $purge_fields=array();
986 + switch($type){
987 + case 'table':
988 + $index_suffix = '_row-';
989 + $regex = '/^'.preg_quote($field_name).'_row-[0-9]+$/';
990 + $values['']=$data[$field_name];
991 + //extract all relevant fields
992 + $submitted_fields = preg_grep($regex, array_keys($data));
993 + $max_fields = sizeof($submitted_fields);
994 + break;
995 + case 'tab':
996 + $index_suffix = '_tab-';
997 + $regex = '/^'.preg_quote($field_name).'_tab-[0-9]+$/';
998 + $values['']=$data[$field_name];
999 + //extract all relevant fields
1000 + $submitted_fields = preg_grep($regex, array_keys($data));
1001 + foreach($submitted_fields as $field){
1002 + $idx = 1.0 * str_replace($field_name.'_tab-', '', $field);
1003 + if($max_fields < $idx) $max_fields = $idx;
1004 + }
1005 + break;
1006 + case 'both':
1007 + $regex = '/^'.preg_quote($field_name);
1008 + $values[''] = array(); //init multi-dimensional array
1009 + if(isset($data[$field_name])){
1010 + $values[''][''] = $data[$field_name];
1011 + }else{
1012 + $values[''][''] = null;
1013 + }
1014 + //extract all relevant fields
1015 + $submitted_fields = preg_grep($regex.'_tab-[0-9]+_row-[0-9]+$/', array_keys($data));
1016 + //we also need the rows with tab index=0
1017 + $submitted_fields += preg_grep($regex.'_row-[0-9]+$/', array_keys($data));
1018 + //.. and tabs with row index=0
1019 + $submitted_fields += preg_grep($regex.'_tab-[0-9]+$/', array_keys($data));
1020 + //if('other-rm-qty'==$field_name){
1021 + // debug_msg($submitted_fields, 'Found fields '.$field_name);
1022 + //}
1023 + $max_fields = sizeof($submitted_fields);
1024 + break;
1025 + }
1026 +
1027 + $row_idx=1; //[0][0] already set above is this is tab table field
1028 + $tab_idx=0;
1029 + $error_loop=false;
1030 + $loop_counter_limit = apply_filters('cf7sg_set_max_tabs_limit', 10, $cf7_key, $cf7_id);
1031 + for($idx=1; ($idx <= $max_fields && !$error_loop); $idx++){
1032 + switch($type){
1033 + case 'table':
1034 + case 'tab':
1035 + if(!isset($data[$field_name.$index_suffix.$idx])){
1036 + /**
1037 + *assuming this field was not submitted as it was disabled, hence set to null.
1038 + * @since 1.0.0
1039 + */
1040 + $values[$index_suffix.$idx] = null;
1041 + }else{
1042 + $values[$index_suffix.$idx] = $data[$field_name.$index_suffix.$idx];
1043 + $purge_fields[$field_name.$index_suffix.$idx] = true;
1044 + }
1045 + break;
1046 + case 'both':
1047 + //first attempt to look for the frist tab rows
1048 + $row_suffix = ($row_idx>0)?'_row-'.$row_idx:'';
1049 + $tab_suffix = ($tab_idx>0)?'_tab-'.$tab_idx:'';
1050 + //if('other-rm-qty'==$field_name){
1051 + // debug_msg($idx.'Looking for: '.$field_name.$tab_suffix.$row_suffix);
1052 + //}
1053 + if(isset($data[$field_name.$tab_suffix.$row_suffix])){
1054 + $values[$tab_suffix][$row_suffix] = $data[$field_name.$tab_suffix.$row_suffix];
1055 + $purge_fields[$field_name.$tab_suffix.$row_suffix] = true;
1056 + //next loop, look for the next row within the same tab,
1057 + $row_idx +=1;
1058 + }else{
1059 +
1060 + $loop_counter=$tab_idx;
1061 + $loop = true;
1062 + do{//move to next tab, and reset the row counter
1063 + // debug_msg('loop:'.$loop_counter.', max: '.$loop_counter_limit);
1064 + $loop_counter +=1;
1065 + if($loop_counter > $loop_counter_limit) $error_loop=true;
1066 + $tab_idx +=1;
1067 + $row_idx = 0;
1068 + $row_suffix = '';
1069 + $tab_suffix = '_tab-'.$tab_idx;
1070 + //init new tab row values array
1071 + $values[$tab_suffix] = array();
1072 + //keep looking for next tab if we don't find a value;
1073 + /**
1074 + *if the frist row is not submitted then this may be in a toggled section which has been disabled.
1075 + * but we still need to keep looking for values in other tabs.
1076 + *@since 1.1.0
1077 + */
1078 + $values[$tab_suffix][$row_suffix] = null;
1079 + $loop = !isset($data[$field_name.$tab_suffix.$row_suffix]) && !$error_loop;
1080 + }while($loop);
1081 + if(!$error_loop) {
1082 + $values[$tab_suffix][$row_suffix] = $data[$field_name.$tab_suffix.$row_suffix];
1083 + $purge_fields[$field_name.$tab_suffix.$row_suffix] = true;
1084 + $row_idx +=1; //next loop, keep searching in thsi tab.
1085 + }else{
1086 + debug_msg($submitted_fields, 'CF7SG ERROR: Reached max tabs search loop for table field '.$field_name.' (cannot find any new rows above tab '.$tab_idx.' therefor abandoning search for remaining '.(sizeof($submitted_fields)-$idx).' regex match in preg_grep result array listed below)');
1087 + //for loop will end here
1088 + }
1089 + }
1090 + break;
1091 + }//end switch.
1092 + }//end for loop preg_grep array.
1093 + if(!$error_loop){
1094 + //debug_msg($purge_fields, 'purging ');
1095 + //debug_msg($data);
1096 + $data = array_udiff_uassoc($data, $purge_fields, function($a, $b){return 0;}, function($a, $b){
1097 + if ($a === $b) return 0;
1098 + return ($a > $b)? 1:-1;
1099 + }); //this will remove all the surplus fields
1100 + $data[$field_name] = $values;
1101 + }
1102 + return $values;
1103 + }
1021 1104 /**
1022 1105 * Validates required benchmark and dynamic_select tags
1023 1106 *
1024 1107 * @since 1.0.0
@@ -1049,9 +1132,9 @@
1049 1132 * @param WPCF7_Validation $result validation object
1050 1133 * @param Array $tags an array of cf7 tag used in this form
1051 1134 * @return WPCF7_Validation validation result
1052 1135 **/
1053 - public function filter_wpcf7_validate($result){
1136 + public function filter_wpcf7_validate($result, $tags){
1054 1137 /** @since 3.3.3 fix for captch field validation*/
1055 1138 $invalids = $result->get_invalid_fields();
1056 1139 /**
1057 1140 *@since 1.1.0
@@ -1060,27 +1143,14 @@
1060 1143 * Disabled fields are not submitted but CF7 forces their values to empty and therefore flags requried fields as invalid at submission even if they are disabled.
1061 1144 * this bug was reported in the cf7 support forum:
1062 1145 * https://wordpress.org/support/topic/bug-javascript-disabled-fields-flagged-as-invalid/
1063 1146 **/
1147 + $result = new WPCF7_Validation();
1064 1148
1065 1149 //rebuild the default validation result.
1066 - $cf7form = $submitted = null;
1067 - if(method_exists('WPCF7_ContactForm','get_current')){ /** @since 4.12.8 */
1068 - $cf7form = WPCF7_ContactForm::get_current();
1069 - }else debug_msg('WPCF7_ContactForm::get_current() method no longer available');
1070 - if(empty($cf7form)) return $result;
1071 - //check if we have a submission
1072 - if(method_exists('WPCF7_Submission','get_instance')){
1073 - $submitted = WPCF7_Submission::get_instance();
1074 - }else debug_msg('WPCF7_Submission::get_instance() method no longer available');
1075 - if(empty($submitted)) return $result;
1076 - //check if we have a validation object constructor.
1077 - if(class_exists('WPCF7_Validation')){
1078 - $result = new WPCF7_Validation();
1079 - }else{
1080 - debug_msg('new WPCF7_Validation() constructor no longer available');
1081 - return $result;
1082 - }
1150 + $cf7form = WPCF7_ContactForm::get_current();
1151 + $tags = $cf7form->scan_form_tags();
1152 + $submitted = WPCF7_Submission::get_instance();
1083 1153 $data = $submitted->get_posted_data();
1084 1154 $tag_types = array(); //store all form tags, including cloned tags for array fields.
1085 1155
1086 1156 /** @since 3.1.3 allow validation of unvalidated data in custom validation filter */
@@ -1094,11 +1164,47 @@
1094 1164 $toggle_status = '';
1095 1165 if(isset($_POST['_cf7sg_toggles'])){
1096 1166 $toggle_status = json_decode( stripslashes($_POST['_cf7sg_toggles']));
1097 1167 }
1098 -
1099 - foreach ( $cf7form->scan_form_tags() as $tag ) {
1168 + /** @since 2.5.0 new data consolidation enables simpler validation */
1169 + $deprecated = true; //check if the form being submitted was created with an older version of the plugin.
1170 + if( isset($_POST['_cf7sg_version']) && version_compare($_POST['_cf7sg_version'],'2.5.0','>=') ){
1171 + $deprecated = false;
1172 + }
1173 + foreach ( $tags as $tag ) {
1100 1174 //debug_msg($data);
1175 + if($deprecated){
1176 + /**
1177 + * @since 2.1.5 fix validation of non-toggled checkox/radio. Toggled fields are now tracked in the tag itself as a class.
1178 + */
1179 + if(!isset($_POST[$tag['name']])){
1180 + $isRequired = false;
1181 + switch($tag['type']){
1182 + case 'checkbox*':
1183 + case 'radio':
1184 + case 'file*': /** @since 2.3.1 fix as file field has no values in $_POST.*/
1185 + $isRequired = true;
1186 + $tag_options = $tag->options;
1187 + if(empty($tag_options)) break; //break from switch, not toggled, we need to validate.
1188 + $toggle='';
1189 + foreach($tag_options as $option){
1190 + $match = array();
1191 + preg_match('/class:cf7sg-toggle-(.[^\s]+)/i',$option, $match);
1192 + if(!empty($match)){
1193 + $toggle=$match[1];
1194 + break; //break fromeach loop.
1195 + }
1196 + }
1197 + if(empty($toggle)) break; //break from switch, not toggled, we need to validate.
1198 + //check if the toggle is open. only open toggles are registered.
1199 + if(!empty($toggle_status) && property_exists($toggle_status, $toggle)) break; //break from switch, is toggled and in use, we need to validate.
1200 + //if we reached here, then the checkbox/radio is toggled and not in use, so do not validate.
1201 + $isRequired = false;
1202 + break;
1203 + }
1204 + if(!$isRequired) continue;//not submitted==disabled, or not used.
1205 + }
1206 + }
1101 1207 /**
1102 1208 *@since 1.9.0 fix issue with Conditional Field plugin.
1103 1209 */
1104 1210 //validation for non-deprecated plugins (v2.5.0+).
@@ -1124,48 +1230,56 @@
1124 1230 $validated[$tag['name']][$idx] = array();
1125 1231 $submission[$tag['name']][$idx] = array();
1126 1232 $rdx = 0;
1127 1233 foreach($value as $row=>$row_value){
1128 - if(!isset($row_value)) continue;
1234 + if($deprecated && !isset($_POST[$tag['name'].$index.$row])) continue;
1235 + elseif(!isset($row_value)) continue;
1129 1236 $sg_field_tag = clone $tag;
1130 1237 $sg_field_tag['name'] = $tag['name'].$index.$row;
1131 - if($tag['basetype'] === 'file' ){
1132 - $result = apply_filters("wpcf7_validate_{$sg_field_tag->type}", $result, $sg_field_tag,
1133 - array(
1134 - 'uploaded_files' => isset($this->file_wp_errors[$sg_field_tag['name']]) ? $this->file_wp_errors[$sg_field_tag['name']]: $row_value,
1135 - )
1136 - );
1137 - }else{
1138 - $result = apply_filters("wpcf7_validate_{$tag['type']}", $result, $sg_field_tag);
1139 - }
1238 + $result = apply_filters("wpcf7_validate_{$tag['type']}", $result, $sg_field_tag);
1140 1239 /** @since 3.1.3 */
1141 1240 $validation[$tag['name']][$idx][$rdx] = $this->strip_cf7_validation($result, $sg_field_tag->name);
1142 1241 $validated[$tag['name']][$idx][$rdx] = $sg_field_tag;
1143 - $submission[$tag['name']][$idx][$rdx] = $row_value;
1242 + $submission[$tag['name']][$idx][$rdx] = $this->get_submitted_data($tag['name'], $type, $row_value);
1144 1243 $rdx++;
1145 1244 }
1146 1245 }else{
1147 - if(!isset($value)) continue;
1246 + if($deprecated && !isset($_POST[$tag['name'].$index])) continue;
1247 + elseif(!isset($value)) continue;
1148 1248 $sg_field_tag = clone $tag;
1149 1249 $sg_field_tag['name'] = $tag['name'].$index;
1150 - if($tag['basetype'] === 'file' ){
1151 - $result = apply_filters("wpcf7_validate_{$sg_field_tag->type}", $result, $sg_field_tag,
1152 - array(
1153 - 'uploaded_files' => isset($this->file_wp_errors[$sg_field_tag['name']]) ? $this->file_wp_errors[$sg_field_tag['name']]: $value,
1154 - )
1155 - );
1156 - }else{
1157 - $result= apply_filters("wpcf7_validate_{$tag['type']}", $result, $sg_field_tag);
1158 - }
1250 + $result= apply_filters("wpcf7_validate_{$tag['type']}", $result, $sg_field_tag);
1159 1251 /** @since 3.1.3 */
1160 1252 $validation[$tag['name']][$idx] = $this->strip_cf7_validation($result, $sg_field_tag->name);
1161 1253 $validated[$tag['name']][$idx] = $sg_field_tag;
1162 - $submission[$tag['name']][$idx] = $value;
1254 + $submission[$tag['name']][$idx] = $this->get_submitted_data($tag['name'], $type, $value);
1163 1255 }
1164 1256 $idx++;
1165 1257 }
1166 1258 // debug_msg($values, 'values '.$tag['name'].'....');
1167 1259 // debug_msg($result, 'validation '.$tag['name'].'....');
1260 + if($deprecated){ //if deprecated no need to bother with validation/validated arrays.
1261 + /** @since 2.3.1 fix the files tag validation for files in tabs/tables*/
1262 + switch($type){
1263 + case 'file':
1264 + case 'file*':
1265 + // Search for $_FILES where name match a tabbed file field
1266 + $regex = '/^'.preg_quote($tag['name']);
1267 + $submitted_fields = preg_grep($regex.'$/', array_keys($_FILES));
1268 + //extract all relevant fields
1269 + $submitted_fields += preg_grep($regex.'_tab-[0-9]+_row-[0-9]+$/', array_keys($_FILES));
1270 + //we also need the rows with tab index=0
1271 + $row_fields = preg_grep($regex.'_row-[0-9]+$/', array_keys($_FILES));
1272 + //.. and tabs with row index=0
1273 + $submitted_fields += preg_grep($regex.'_tab-[0-9]+$/', array_keys($_FILES));
1274 + foreach($submitted_fields as $index => $field){
1275 + // For each tabbed file, call the filter validate to add uploaded_files
1276 + $sg_field_tag = clone $tag;
1277 + $sg_field_tag['name'] = $field;
1278 + $result = apply_filters("wpcf7_validate_{$sg_field_tag['type']}", $result, $sg_field_tag);
1279 + }
1280 + }
1281 + }
1168 1282 break;
1169 1283 default:
1170 1284 switch($type) {
1171 1285 case 'captchar': //cannot be called twice, hence see if already invalidated.
@@ -1176,21 +1290,14 @@
1176 1290 $validated[$tag['name']] = $tag;
1177 1291 }
1178 1292 break;
1179 1293 default:
1180 - if($tag['basetype'] === 'file' ){
1181 - $result = apply_filters("wpcf7_validate_{$tag->type}", $result, $tag,
1182 - array(
1183 - 'uploaded_files' => isset($this->file_wp_errors[$tag['name']]) ? $this->file_wp_errors[$tag['name']]: $data[$tag['name']],
1184 - )
1185 - );
1186 - }else{
1187 - $result= apply_filters( "wpcf7_validate_{$type}", $result, $tag );
1188 - }
1294 + //if(!isset($data[$tag['name']])) continue 2; /*likely toggled and unused*/
1295 + $result= apply_filters( "wpcf7_validate_{$type}", $result, $tag );
1189 1296 /** @since 3.1.3 */
1190 1297 $validation[$tag['name']] = $this->strip_cf7_validation($result, $tag['name']);
1191 1298 $validated[$tag['name']] = $tag;
1192 - $submission[$tag['name']] = $data[$tag['name']];
1299 + $submission[$tag['name']] = $this->get_submitted_data($tag['name'], $type, $data[$tag['name']]);
1193 1300 break;
1194 1301 }
1195 1302 break;
1196 1303 }
@@ -1198,9 +1305,9 @@
1198 1305 $form_key = '';
1199 1306 if(isset($_POST['_wpcf7_key'])){
1200 1307 $form_key = $_POST['_wpcf7_key'];
1201 1308 }
1202 - // debug_msg($data, 'data ');
1309 +
1203 1310 //allow for more complex validation.
1204 1311 if(has_filter('cf7sg_validate_submission')){
1205 1312 /**
1206 1313 * filter to validate the entire submission and check interdependency of fields
@@ -1250,21 +1357,10 @@
1250 1357 }
1251 1358 }
1252 1359 }
1253 1360 }
1254 - if($result->is_valid()){
1255 - /**
1256 - * Once data is valid fire action to expose final submitted data.
1257 - * @since 4.9.0
1258 - * @param Array $submission submitted data, $field_name => $value pairs ($value can be an array especially for fields in tables and tabs) null values are fields which have not been disabled and not submitted such as those in toggled sections.
1259 - * @param String $form_key unique form key to identify current form.
1260 - * @param int $form_id cf7 form post ID.
1261 - */
1262 - do_action('cf7sg_valid_form_submission',$submission, $form_key, $_POST['_wpcf7']);
1263 - }
1264 1361 return $result;
1265 1362 }
1266 -
1267 1363 /**
1268 1364 * Function to strip the submitted data for a given field.
1269 1365 * Handles base type files whose data is stored in the $_FILES global array.
1270 1366 *@since 3.1.3
@@ -1329,10 +1425,10 @@
1329 1425 * @since 1.0.0
1330 1426 * @param string $key form unique key.
1331 1427 * @param Array $submitted_data array of field-name=>value pairs submitted in form
1332 1428 **/
1333 - public function save_select2_custom_options($post_id, $cf7_key, $post_fields, $post_meta_fields, $submitted_data){
1334 - $form_id = get_cf7form_id($cf7_key);
1429 + public function save_select2_custom_options($post_id, $key, $post_fields, $post_meta_fields, $submitted_data){
1430 + $form_id = get_cf7form_id($key);
1335 1431 $tagged_fields = get_post_meta($form_id, '_cf7sg_select2_tagged_fields', true);
1336 1432 if(empty($tagged_fields)){
1337 1433 return;
1338 1434 }
@@ -1356,19 +1452,17 @@
1356 1452 * @param string $term the new term submitted by the user.
1357 1453 * @param string $field_name the name of the form field.
1358 1454 * @param string $taxonomy the taxonomy to which this is added.
1359 1455 * @param array $submitted_data array of other submitted $field=>$value pairs.
1360 - * @param string $cf7_key the form unique key.
1456 + * @param string $key the form unique key.
1361 1457 * @return string the new term name to insert.
1362 1458 * @since 2.0.0
1363 1459 */
1364 - $term = apply_filters('cf7sg_dynamic_dropdown_new_term', $term, $field_name, $taxonomy, $submitted_data, $cf7_key);
1365 - if(!empty($term)){
1366 - $new_term = wp_insert_term($term, $taxonomy);
1367 - if(!is_wp_error($new_term)){
1368 - $new_term = get_term($new_term['term_id'], $taxonomy);
1369 - $value[$idx] = $new_term->slug;
1370 - }
1460 + $term = apply_filters('cf7sg_dynamic_dropdown_new_term', $term, $field_name, $taxonomy, $submitted_data, $key);
1461 + $new_term = wp_insert_term($term, $taxonomy);
1462 + if(!is_wp_error($new_term)){
1463 + $new_term = get_term($new_term['term_id'], $taxonomy);
1464 + $value[$idx] = $new_term->slug;
1371 1465 }
1372 1466 }
1373 1467 $idx++;
1374 1468 }
@@ -1392,15 +1486,9 @@
1392 1486 );
1393 1487 }
1394 1488 $args['tax_query'] = $tax;
1395 1489 }
1396 - apply_filters_deprecated('cf7sg_dynamic_dropdown_post_query',
1397 - array(
1398 - $args,
1399 - $tag->name,
1400 - $cf7_key
1401 - ), '4.11.0', 'cf7sg_dynamic_list_post_query' );
1402 - $args = apply_filters('cf7sg_dynamic_list_post_query', $args, $tag->name, $cf7_key);
1490 + $args = apply_filters('cf7sg_dynamic_dropdown_post_query', $args, $tag->name, $key);
1403 1491 $posts = get_posts($args);
1404 1492 $options = array();
1405 1493 if(!empty($posts)){
1406 1494 foreach($posts as $post){
@@ -1423,11 +1511,11 @@
1423 1511 * @param string $title new value being submitted for a new post title.
1424 1512 * @param string $post_type the post type from which this dropdown was built
1425 1513 * @param array $args an array of additional parameters that was set in the tag, for example the taxonomy and terms from which to filter the posts for the dynamic list.
1426 1514 * @param array $submitted_data array of other submitted $field=>$value pairs.
1427 - * @param string $cf7_key the form unique key.
1515 + * @param string $key the form unique key.
1428 1516 */
1429 - $value[$idx] = apply_filters('cf7sg_dynamic_dropdown_new_post', $post_name, $field_name, $title, $post_type, $args, $submitted_data, $cf7_key);
1517 + $value[$idx] = apply_filters('cf7sg_dynamic_dropdown_new_post', $post_name, $field_name, $title, $post_type, $args, $submitted_data, $key);
1430 1518 }
1431 1519 $idx++;
1432 1520 }
1433 1521 break;
@@ -1439,11 +1527,11 @@
1439 1527 * Return updated values if any are custom values so that saved/draft submissions will reflect the correct value saved in the DB,
1440 1528 * @param array $values an array submitted values (several values can be submitted in the case of a tabbed/table input field).
1441 1529 * @param string $field_name the name of the form field.
1442 1530 * @param array $submitted_data array of other submitted $field=>$value pairs.
1443 - * @param string $cf7_key the form unique key.
1531 + * @param string $key the form unique key.
1444 1532 */
1445 - $value = apply_filters('cf7sg_dynamic_dropdown_filter_select2_submission', $values, $field_name, $submitted_data, $cf7_key);
1533 + $value = apply_filters('cf7sg_dynamic_dropdown_filter_select2_submission', $values, $field_name, $submitted_data, $key);
1446 1534 break;
1447 1535 }
1448 1536 //Save the modified value, find which post field the field is mapped to
1449 1537 if(!$is_array){
@@ -1472,9 +1560,48 @@
1472 1560 update_post_meta($post_id, $post_meta_fields[$field_name], $value);
1473 1561 }
1474 1562 }
1475 1563 }
1476 -
1564 + /**
1565 + * Function to retrieve dynamic-dropdown attributes
1566 + *
1567 + * @since 1.0.0
1568 + * @param WPCF7_FormTag $tag cf7 tag object of basetype dynamic_select.
1569 + * @return array an array of attributes with 'source'=>[post|taxonomy|filter], .
1570 + **/
1571 + static public function get_dynamic_drodown_attributes($tag){
1572 + if(is_array($tag) && isset($tag['basetype']) && 'dynamic_select' === $tag['basetype']){
1573 + $tag = new WPCF7_FormTag($tag);
1574 + }
1575 + if( !($tag instanceof WPCF7_FormTag) || 'dynamic_select' !== $tag['basetype']){
1576 + return false;
1577 + }
1578 + $source = array();
1579 + foreach($tag->values as $values){
1580 + if(0 === strpos($values, 'slug:') ){
1581 + $source['source'] = "taxonomy";
1582 + $source['taxonomy'] = str_replace('slug:', '', $values);
1583 + }
1584 + if(0 === strpos($values, 'source:post')){
1585 + $source['source'] = "post";
1586 + $source['post'] = str_replace('source:post:', '', $values);
1587 + }
1588 + if(0 === strpos($values, 'taxonomy:')){
1589 + if(empty($source['taxonomy'])){
1590 + $source['taxonomy'] = array();
1591 + }
1592 + $values = str_replace('taxonomy:', '', $values);
1593 + $exp = explode(":", $values);
1594 + if(!empty($exp) && is_array($exp)){
1595 + $source['taxonomy'][$exp[1]] = $exp[0];
1596 + }
1597 + }
1598 + if(0 === strpos($values, 'source:filter')){
1599 + $source['source'] = "filter";
1600 + }
1601 + }
1602 + return $source;
1603 + }
1477 1604 /**
1478 1605 * Function to temporarily fix the conditional fields plugin issue.
1479 1606 * this is is called by the vlidation function 'filter_wpcf7_validate' above.
1480 1607 *@since 2.1
@@ -1511,14 +1638,8 @@
1511 1638 *@return string replacement string.
1512 1639 */
1513 1640 public function filter_table_tab_mail_tag($replaced, $submitted, $html=false, $mail_tag=null ){
1514 1641 $cf7form = WPCF7_ContactForm::get_current();
1515 - if(empty($cf7form)){
1516 - debug_msg(mail_tag, 'SMART GRID (ERR): unable to retrieve current form while filtering mail tag: ');
1517 - return $replaced; //no form object.
1518 - }
1519 - if(empty($mail_tag) || !is_a($mail_tag,'WPCF7_MailTag')) return $replaced;
1520 -
1521 1642 $cf7form_key = get_cf7form_key($cf7form->id());
1522 1643 $submitted_cf7 = WPCF7_Submission::get_instance();
1523 1644 $submitted_data = array();
1524 1645 if(!empty($submitted_cf7)) $submitted_data = $submitted_cf7->get_posted_data();
@@ -1532,8 +1653,10 @@
1532 1653 $replaced ="";
1533 1654 break;
1534 1655 }
1535 1656
1657 + if(empty($mail_tag)) return $replaced;
1658 +
1536 1659 $field_type = self::field_type($mail_tag->field_name(), $cf7form->id());
1537 1660 $label = '';
1538 1661 $build = false;
1539 1662
@@ -1540,10 +1663,9 @@
1540 1663 switch($field_type){
1541 1664 case 'tab':
1542 1665 case 'table':
1543 1666 if($html){
1544 - $filtered = apply_filters_deprecated('cf7sg_mailtag_grid_fields', array('', $mail_tag->field_name(), $submitted, $cf7form_key, false), '4.6.2','cf7sg_mailtag_{$field_name}', __('this filter is no longer available', 'cf7-grid-layout'));
1545 - $filtered = apply_filters('cf7sg_mailtag_'.$mail_tag->field_name(), $filtered, $submitted_data, $cf7form_key);
1667 + $filtered = apply_filters('cf7sg_mailtag_grid_fields', '', $mail_tag->field_name(), $submitted, $cf7form_key, false);
1546 1668 if(!empty($filtered)){
1547 1669 $replaced = $filtered;
1548 1670 break;
1549 1671 }
@@ -1560,10 +1682,9 @@
1560 1682 }
1561 1683 break;
1562 1684 case 'both':
1563 1685 if($html){
1564 - $filtered = apply_filters_deprecated('cf7sg_mailtag_grid_fields', array('', $mail_tag->field_name(), $submitted, $cf7form_key, false), '4.6.2','cf7sg_mailtag_{$field_name}', __('this filter is no longer available', 'cf7-grid-layout'));
1565 - $filtered = apply_filters('cf7sg_mailtag_'.$mail_tag->field_name(), $filtered, $submitted_data, $cf7form_key);
1686 + $filtered = apply_filters('cf7sg_mailtag_grid_fields', '', $mail_tag->field_name(), $submitted, $cf7form_key, true);
1566 1687 if(!empty($filtered)){
1567 1688 $replaced = $filtered;
1568 1689 break;
1569 1690 }
@@ -1629,22 +1750,19 @@
1629 1750 * @param WPCF7_Mail $cf7mail cf7 mail object
1630 1751 * @return Array an array of mail parts
1631 1752 */
1632 1753 public function wpcf7_mail_components($components, $cf7form, $cf7mail) {
1754 + //$tags = $cf7form->scan_form_tags();
1633 1755 $submission = WPCF7_Submission::get_instance();
1634 - /** @since 4.9 file validation changes in CF7 v5.4 */
1635 - // $uploaded_files = $submission->uploaded_files(); //get file path from data subission itself.
1636 - //get the tags that are file uploads.
1637 - $tags = $cf7form->scan_form_tags(array(
1638 - 'feature' => 'file-uploading',
1639 - ) );
1756 + $uploaded_files = $submission->uploaded_files();
1757 + $cf7_mail = WPCF7_Mail::get_current();
1640 1758 /** @since 2.5.6 fix issue with non-attached files */
1641 - $template = $cf7mail->get( 'attachments' );
1759 + $template = $cf7_mail->get( 'attachments' );
1642 1760 $row = $tab = null;
1761 + $idx = 0;
1643 1762 /** @since 2.8.1 fix for send pdf */
1644 1763 $attachments = $components['attachments'];
1645 - foreach ( $tags as $tag ) {
1646 - $name = $tag['name'];
1764 + foreach ( (array) $uploaded_files as $name => $path ) {
1647 1765 if ( false === strpos( $template, "[${name}]" ) ) continue; //not attached.
1648 1766 $field_type = self::field_type($name, $cf7form->id());
1649 1767 $data = $submission->get_posted_data($name);
1650 1768 switch($field_type){
@@ -1649,51 +1767,46 @@
1649 1767 $data = $submission->get_posted_data($name);
1650 1768 switch($field_type){
1651 1769 case 'tab':
1652 1770 case 'table':
1653 - foreach($data as $field_idx=>$file_path){
1654 - if(empty($file_path)) continue 1;
1655 - foreach($file_path as $path){
1656 - $row = ('table'==$field_type)? str_replace('_row-', '', $field_idx):null;
1657 - $row = (isset($row) && empty($row))? 1:1+(int)$row;
1658 - $tab = ('tab'==$field_type)? str_replace('_tab-', '', $field_idx):null;
1659 - $tab = (isset($tab) && empty($tab))? 1:1+(int)$tab;
1660 - // $file = $uploaded_files[$name.$field_idx];
1661 -
1662 - if(!in_array($path,$attachments)) $attachments[] = $path;
1663 - $file_name = explode('/',$path);
1664 - $file_name = $file_name[count($file_name)-1];
1665 - $components['body'].= apply_filters('cf7sg_annotate_mail_attach_grid_files','', $name, $file_name, $tab, $row, $_POST['_wpcf7_key']);
1666 - }
1771 + foreach($data as $field_idx=>$file_name){
1772 + if(empty($file_name)) continue;
1773 + $idx++;
1774 + $row = ('table'==$field_type)? str_replace('_row-', '', $field_idx):null;
1775 + $row = (isset($row) && empty($row))? 1:1+(int)$row;
1776 + $tab = ('tab'==$field_type)? str_replace('_tab-', '', $field_idx):null;
1777 + $tab = (isset($tab) && empty($tab))? 1:1+(int)$tab;
1778 + $file = $uploaded_files[$name.$field_idx];
1779 + if(!in_array($attachments,$file)) $attachments[] = $file;
1780 + $file = explode('/',$file);
1781 + $filename = $file[count($file)-1];
1782 + $components['body'].= apply_filters('cf7sg_annotate_mail_attach_grid_files', '', $name, $row, $tab, $idx,$filename, $_POST['_wpcf7_key']);
1667 1783 }
1668 1784 break;
1669 1785 case 'both':
1670 1786 $row = $tab = 1;
1671 1787 foreach($data as $field_tab=>$tab_files){
1672 - if(empty($tab_files)) continue 1;
1673 1788 $tab = str_replace('_tab-', '', $field_tab);
1674 1789 $tab = empty($tab)?1:1+(int) $tab;
1675 - foreach($tab_files as $field_row=>$file_path){
1676 - if(empty($file_path)) continue;
1677 - foreach($file_path as $path){
1678 - $row = str_replace('_row-', '', $field_row);
1679 - // $file = $uploaded_files[$name.$field_tab.$field_row];
1680 - if(!in_array($path,$attachments)) $attachments[] = $path;
1681 - $file_name = explode('/',$path);
1682 - $file_name = $file_name[count($file_name)-1];
1683 - $components['body'].= apply_filters('cf7sg_annotate_mail_attach_grid_files','', $name, $file_name, $tab, $row, $_POST['_wpcf7_key']);
1684 - }
1790 + foreach($tab_files as $field_row=>$file_name){
1791 + if(empty($file_name)) continue;
1792 + $idx++;
1793 + $row = str_replace('_row-', '', $field_row);
1794 + $file = $uploaded_files[$name.$field_tab.$field_row];
1795 + if(!in_array($attachments,$file)) $attachments[] = $file;
1796 + $file = explode('/',$file);
1797 + $filename = $file[count($file)-1];
1798 + $components['body'].= apply_filters('cf7sg_annotate_mail_attach_grid_files','', $name, $row, $tab, $idx,$filename, $_POST['_wpcf7_key']);
1685 1799 }
1686 1800 }
1687 1801 break;
1688 1802 default: //singular fields.
1689 - if(empty($data)) continue 2;
1690 - foreach($data as $path){
1691 - if(!in_array($path, $attachments)) $attachments[] = $path;
1692 - $file_name = explode('/',$path);
1693 - $file_name = $file_name[count($file_name)-1];
1694 - $components['body'].= apply_filters('cf7sg_annotate_mail_attach_grid_files','', $name, $file_name, null, null, $_POST['_wpcf7_key']);
1695 - }
1803 + if(empty($path)) continue 2;
1804 + $idx++;
1805 + if(!in_array($path, $attachments)) $attachments[] = $path;
1806 + $path = explode('/',$path);
1807 + $filename = $path[count($path)-1];
1808 + $components['body'].= apply_filters('cf7sg_annotate_mail_attach_grid_files','', $name, null, null, $idx,$filename, $_POST['_wpcf7_key']);
1696 1809 break;
1697 1810 }
1698 1811 }
1699 1812 $components['attachments'] = $attachments;
@@ -1698,36 +1811,17 @@
1698 1811 }
1699 1812 $components['attachments'] = $attachments;
1700 1813 return $components;
1701 1814 }
1702 -
1703 1815 /**
1704 1816 * Track form field value submissions for preview forms.
1705 1817 * Hooked to action 'wpcf7_before_send_mail'
1706 1818 *@since 4.4.0
1707 - *@param WPCF7_Contact_Form $form cf7 form object.
1819 + *@param string $param text_description
1820 + *@return string text_description
1708 1821 */
1709 - public function on_submit_success($form){
1822 + public function prefill_preview_forms($form){
1710 1823 if(empty($form)) return;
1711 - /** @since 4.6.0 check if the form is being redirected and data cached */
1712 - $redirect = get_post_meta($form->id(), '_cf7sg_page_redirect',true);
1713 - if(!empty($redirect)){
1714 - $cache = get_post_meta($form->id(), '_cf7sg_cache_redirect_data',true);
1715 - if(is_array($cache)){
1716 - $submission = WPCF7_Submission::get_instance();
1717 - $data = array();
1718 - if(!empty($submission)){
1719 - $data['fields'] = $submission->get_posted_data();
1720 - $files = $submission->uploaded_files();
1721 - if(!empty($files)) $data['files'] = $files;
1722 - }
1723 - $data = apply_filters('cf7sg_form_redirect_cached_data',$data, $_POST['_wpcf7_key'], $form->id());
1724 - $transient = '_cf7sg_'.wp_create_nonce( $this->form_css_id($_POST['_wpcf7_key']) );
1725 - set_transient( $transient, $data, $cache[0]*$cache[1]);
1726 - // debug_msg($data, "setting transient $transient, expiring in ".$cache[0]*$cache[1]);
1727 - }
1728 - }
1729 - //for preview forms...
1730 1824 if( !isset($_POST['_cf7sg_preview']) ) return;
1731 1825 $prefill = array();
1732 1826 foreach( $form->scan_form_tags() as $tag){
1733 1827 if( isset($_POST[$tag->name]) and !empty($_POST[$tag->name]) ){
@@ -1735,242 +1829,8 @@
1735 1829 }
1736 1830 $prefill['_cf7sg_toggles'] = self::$array_toggled_panels[$form->id()];
1737 1831 }
1738 1832
1739 - if(!empty($prefill)) setcookie('_cf7sg_'. sanitize_text_field( $_POST['_wpcf7_key'] ), json_encode($prefill),0,'/');
1833 + if(!empty($prefill)) setcookie('_cf7sg_'.$_POST['_wpcf7_key'], json_encode($prefill),0,'/');
1740 1834 }
1741 - /**
1742 - * Register a [dynamic_display] shortcode with CF7.
1743 - * hooked on 'cf7sg_dynamic_select_html_field'
1744 - * This function registers a callback function to expand the shortcode for the googleMap form fields.
1745 - * @since 4.11.0
1746 - * @param Array $attrs array of attribute key=>value pairs to be included in the html element tag.
1747 - * @param Array $options array of value=>label pairs of options.
1748 - * @param Array $other_attrs array of other attributes selected in tag field as $attr=>true.
1749 - * @return String an html string representing the input field to a=be added to the field wrapper and into the form.
1750 - */
1751 - public function build_dynamic_select_field( $html, $attrs, $options, $other_attrs, $selected){
1752 - $attributes ='';
1753 - foreach($attrs as $key=>$value){
1754 - if('name'==$key && isset($other_attrs['multiple'])){
1755 - $value.='[]';
1756 - $attributes .= ' multiple';
1757 - }
1758 - $attributes .= ' '.$key.'="'.$value.'"';
1759 - }
1760 - $html = '<select value="'.$selected.'"'.$attributes.'>'.PHP_EOL;
1761 - if(is_array($options)){
1762 - foreach($options as $value=>$details){
1763 - $attributes ='';
1764 - foreach($details[1] as $name=>$attval){
1765 - $attributes .= ' '.$this->format_attribute($name,$attval);
1766 - }
1767 - if($value==$selected) $attributes .=' selected="selected"';
1768 - $html .= '<option value="'.$value.'"'.$attributes.'>'.$details[0].'</option>'.PHP_EOL;
1769 - }
1770 - }else $html .= $options; //pre 4.10.0 backward compatibility.
1771 - $html .='</select>'.PHP_EOL;
1772 - return $html;
1773 - }
1774 - /**
1775 - * Register a [dynamic_display] shortcode with CF7.
1776 - * hooked on 'cf7sg_dynamic_checkbox_html_field'
1777 - * This function registers a callback function to expand the shortcode for the googleMap form fields.
1778 - * @since 4.11.0
1779 - * @param Array $attrs array of attribute key=>value pairs to be included in the html element tag.
1780 - * @param Array $options array of value=>label pairs of options.
1781 - * @param Array $other_attrs array of other attributes selected in tag field as $attr=>true.
1782 - * @return String an html string representing the input field to a=be added to the field wrapper and into the form.
1783 - */
1784 - public function build_dynamic_checkbox_field( $html, $attrs, $options, $other_attrs, $selected){
1785 1835
1786 - if( !isset($attrs['class']) ) $attrs['class'] = '';
1787 - $classes = explode(' ',$attrs['class']);
1788 -
1789 - $type = 'radio';
1790 - $name_attr='';
1791 - $isImageGrid = isset($other_attrs['imagegrid']);
1792 - if(isset($other_attrs['nolimit'])) $attrs['data-limit-selection']="-1";
1793 - $attributes = '';
1794 - $hybrid_data = array();
1795 - switch(true){
1796 - case array_search('cf7sg-hybriddd',$classes)!==false:
1797 - break;
1798 - case array_search('cf7sg-imagehdd',$classes)!==false:
1799 - $attrs['data-checkboxes']='false';
1800 - $attrs['data-dropdown']='landscape';
1801 - break;
1802 - case array_search('cf7sg-treeview',$classes)!==false:
1803 - $attrs['class'] .=' cf7sg-hybriddd';
1804 - $attrs['data-tree-view']='true';
1805 - break;
1806 - case array_search('cf7sg-imagegrid',$classes)!==false:
1807 - $attrs['class'] .=' cf7sg-imagehdd';
1808 - $attrs['data-dropdown']='none';
1809 - break;
1810 - }
1811 - $default = apply_filters('cf7sg_hybrid_dynamic_checkbox_default_value','',$attrs['name']);
1812 - if(!empty($default)) $hybrid_data['']=$default;
1813 - if(!empty($attrs['name'])) $attributes .= ' data-field-name="'.$attrs['name'].'"';
1814 - if( isset($attrs['name'])){
1815 - $name_attr = 'name="'.$attrs['name'];
1816 - if(in_array('checkbox',$classes)){
1817 - $name_attr.='[]';
1818 - $type = 'checkbox';
1819 - }
1820 - $name_attr.='"';
1821 - }
1822 - $hasId = false;
1823 - foreach($attrs as $key=>$value){
1824 - if('name'==$key) continue;
1825 - if('id'==$key) $hasId = true;
1826 - if( 'data-maxcheck'==$key ) $key = 'data-limit-selection';
1827 - $attributes .= ' '.$key.'="'.$value.'"';
1828 - }
1829 - if(!$hasId) $attributes = 'id="dl-'.$attrs['name'].'" '.$attributes;
1830 -
1831 - $html = '<span '.$attributes.'>'.PHP_EOL;
1832 - $html .= '<script type="application/json">'.PHP_EOL;
1833 - $html .= json_encode($this->build_hybrid_list($options)).PHP_EOL;
1834 - $html .= '</script>'.PHP_EOL;
1835 - $html .='</span>'.PHP_EOL;
1836 - return $html;
1837 - }
1838 -
1839 - /**
1840 - * Build recursively nested list.
1841 - *
1842 - * @since 4.11.0
1843 - * @param Array $options array of value=>label pairs of options.
1844 - * @return String an html string representing the input field to a=be added to the field wrapper and into the form.
1845 - */
1846 - protected function build_hybrid_list($options){
1847 - $hybrid_data = array();
1848 -
1849 - foreach($options as $value=>$details){
1850 - $attributes = array($details[0]); //option label
1851 - // if($value==$selected) $attributes .=' checked="true"';
1852 - foreach($details[1] as $name=>$aval){
1853 - $attributes[] = $this->format_attribute($name,$aval);
1854 - }
1855 - $children = array();
1856 - if(isset($details[2])) $children = $this->build_hybrid_list($details[2]);
1857 - $hybrid_data[$value] = array('label'=>$attributes) + $children;
1858 - }
1859 - return $hybrid_data;
1860 - }
1861 - /**
1862 - * format html attribute as $name="$value".
1863 - * @since 4.11.0
1864 - * @param String $name
1865 - * @param Mixed $value either a string or an array.
1866 - * @return String
1867 - */
1868 - protected function format_attribute($name, $value){
1869 - if(is_array($value)){
1870 - $separator = ' ';
1871 - if('style' === $name ) $separator = ';';
1872 - $value = implode( $separator, $value);
1873 - }
1874 - return $name.'="'.$value.'"';
1875 - }
1876 - /**
1877 - * register scripts for dynamic select
1878 - * hooked on 'smart_grid_register_styles'
1879 - * @since 4.11.0
1880 - * @param Boolean $airplane if airplane mode is on, do not load remote scripts/styles.
1881 - * @param String $min set to '.min' by default, empty if in WP_DEBUG mode.
1882 - */
1883 - public function register_dynamic_list_styles($airplane, $min){
1884 - $ff = '';
1885 - if(!defined('WP_DEBUG') || !WP_DEBUG){
1886 - $ff = '.min';
1887 - }
1888 - $plugin_dir = plugin_dir_url( __DIR__ );
1889 - wp_register_style('jquery-nice-select-css', "{$plugin_dir}assets/jquery-nice-select/css/nice-select{$ff}.css", array(), '1.1.0', 'all' );
1890 - /** @since 3.2.1 use cloudflare for live sites */
1891 - if( $airplane || (defined('WP_DEBUG') && WP_DEBUG || apply_filters('cf7sg_use_local_select2', false) ) ){
1892 - wp_register_style('select2-style', "{$plugin_dir}assets/select2/css/select2.min.css", array(), '4.0.13', 'all' );
1893 - }else{
1894 - wp_register_style('select2-style', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css', array(), '4.0.13','all');
1895 - }
1896 - //hybrid style for the dynamic checkbox.
1897 - wp_register_style('hybriddd-style', $plugin_dir . "assets/hybrid-html-dropdown/hybrid-dropdown{$min}.css", array(), $this->version,'all');
1898 - }
1899 - /**
1900 - * register scripts for dynamic select
1901 - * hooked on 'smart_grid_register_scripts'
1902 - * @since 4.11.0
1903 - * @param Boolean $airplane if airplane mode is on, do not load remote scripts/styles.
1904 - * @param String $min set to '.min' by default, empty if in WP_DEBUG mode.
1905 - */
1906 - public function register_dynamic_list_scripts($airplane, $min){
1907 - /** @since 3.2.1 use cloudflare for live sites */
1908 - $plugin_dir = plugin_dir_url( __DIR__ );
1909 - if( $airplane || (defined('WP_DEBUG') && WP_DEBUG) || apply_filters('cf7sg_use_local_select2', false) ){
1910 - wp_register_script('jquery-select2', "{$plugin_dir}assets/select2/js/select2.min.js", array( 'jquery' ), '4.0.13', true );
1911 - }else{
1912 - wp_register_script('jquery-select2', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js', array( 'jquery' ), '4.0.13', true );
1913 - }
1914 - wp_register_script('jquery-nice-select', "{$plugin_dir}assets/jquery-nice-select/js/jquery.nice-select.min.js", array( 'jquery' ), '1.1.0', true );
1915 - wp_register_script('hybriddd-js', $plugin_dir . "assets/hybrid-html-dropdown/hybrid-dropdown{$min}.js", null, $this->version, true);
1916 -
1917 -
1918 - //listen for script enqueue action.
1919 - add_action('smart_grid_enqueue_scripts', function($cf7_key, $atts, $classes){
1920 - //check for classes set in get_form_classes() method in CF7SG_Dynamic_list class.
1921 - if(in_array('has-select2', $classes)){
1922 - wp_enqueue_style('select2-style');
1923 - wp_enqueue_script('jquery-select2');
1924 - }
1925 - if(in_array('has-nice-select', $classes)){
1926 - wp_enqueue_style('jquery-nice-select-css');
1927 - wp_enqueue_script('jquery-nice-select');
1928 - }
1929 - if( in_array('has-hybriddd', $classes) ){
1930 - wp_enqueue_style('hybriddd-style');
1931 - wp_enqueue_script('hybriddd-js');
1932 - }
1933 - },10,3);
1934 - }
1935 - /**
1936 - * Enable HTML messages in cf7 submission messages.
1937 - * Hooked on 'wpcf7_mail_sent' action fired after the submission response has been set.
1938 - *@since 4.11.0
1939 - *@param WPCF7_ContactForm $form cfy form
1940 - */
1941 - public function change_submission_msg($form){
1942 - if(has_filter('cf7sg_submission_success_message') || has_filter('cf7sg_redirect_on_success')){
1943 - if(is_a($form, 'WPCF7_ContactForm')){
1944 - $submitted = WPCF7_Submission::get_instance();
1945 - $data = $submitted->get_posted_data();
1946 - $cf7key = get_cf7form_key( $form->id() );
1947 - $message = apply_filters('cf7sg_submission_success_message', $form->message( 'mail_sent_ok' ), $data, $cf7key);
1948 - $url = apply_filters('cf7sg_redirect_on_success', '', $data, $cf7key);
1949 - if(wp_http_validate_url($url)) $message = 'cf7sg->redirect:' . $url;
1950 - $submitted->set_response( $message );
1951 - }
1952 - }
1953 - }
1954 -}
1955 -
1956 -if(!function_exists('cf7sg_extract_submitted_files')){
1957 - /**
1958 - * Extract submitted files. Used by other plugins to extract files.
1959 - *
1960 - *@since 4.9.0
1961 - *@param Array $files array of files.
1962 - *@return Array $file_name=>$file_path.
1963 - */
1964 - function cf7sg_extract_submitted_files(Array $files){
1965 - $results=array();
1966 - foreach($files as $file){
1967 - if(is_array($file)) $results = array_merge($results, cf7sg_extract_submitted_files($file));
1968 - else{
1969 - $filename = explode('/',$file);
1970 - $filename = $filename[count($filename)-1];
1971 - $results[$filename] = $file;
1972 - }
1973 - }
1974 - return $results;
1975 - }
1976 1836 }