cf7-conditional-fields
Last commit date
js
5 years ago
jsdoc-out
5 years ago
Wpcf7cfMailParser.php
5 years ago
admin-style.css
6 years ago
admin-style.css.map
6 years ago
admin-style.scss
6 years ago
admin.php
5 years ago
cf7cf.php
5 years ago
contact-form-7-conditional-fields.php
5 years ago
init.php
5 years ago
readme.txt
5 years ago
style.css
6 years ago
tg_pane_group.php
5 years ago
wpcf7cf-options.php
5 years ago
Wpcf7cfMailParser.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | //require_once __DIR__.'/init.php'; |
| 4 | |
| 5 | class Wpcf7cfMailParser { |
| 6 | private $mail_body; |
| 7 | private $visible_groups; |
| 8 | private $hidden_groups; |
| 9 | private $repeaters; |
| 10 | private $posted_data; |
| 11 | |
| 12 | function __construct($mail_body, $visible_groups, $hidden_groups, $repeaters, $posted_data) { |
| 13 | $this->mail_body = $mail_body; |
| 14 | $this->visible_groups = $visible_groups; |
| 15 | $this->hidden_groups = $hidden_groups; |
| 16 | $this->repeaters = $repeaters; |
| 17 | $this->posted_data = $posted_data; |
| 18 | } |
| 19 | |
| 20 | public function getParsedMail() { |
| 21 | return preg_replace_callback(WPCF7CF_REGEX_MAIL_GROUP, array($this, 'hide_hidden_mail_fields_regex_callback'), $this->mail_body ); |
| 22 | } |
| 23 | |
| 24 | function hide_hidden_mail_fields_regex_callback ( $matches ) { |
| 25 | $name = $matches[1]; |
| 26 | |
| 27 | $name_parts = explode('__', $name); |
| 28 | |
| 29 | $name_root = array_shift($name_parts); |
| 30 | $name_suffix = implode('__',$name_parts); |
| 31 | |
| 32 | $content = $matches[2]; |
| 33 | if ( in_array( $name, $this->hidden_groups ) ) { |
| 34 | |
| 35 | // The tag name represents a hidden group, so replace everything from [tagname] to [/tagname] with nothing |
| 36 | return ''; |
| 37 | |
| 38 | } elseif ( in_array( $name, $this->visible_groups ) ) { |
| 39 | |
| 40 | // The tag name represents a visible group, so remove the tags themselves, but return everything else |
| 41 | // ( instead of just returning the $content, return the preg_replaced content ) |
| 42 | return preg_replace_callback(WPCF7CF_REGEX_MAIL_GROUP, array($this, 'hide_hidden_mail_fields_regex_callback'), $content ); |
| 43 | |
| 44 | } elseif ( $this->repeaters !== null && in_array( $name, $this->repeaters ) ) { |
| 45 | |
| 46 | $original_name = explode('__',$name)[0]; |
| 47 | |
| 48 | $inner_template = $content; |
| 49 | |
| 50 | ob_start(); |
| 51 | |
| 52 | $num_subs = $this->posted_data[$name.'_count']; |
| 53 | |
| 54 | for ($i=1; $i<=$num_subs; $i++) { |
| 55 | $str = preg_replace(["/\[{$original_name}\:index[^\]]*?\]/"],$i,$inner_template); |
| 56 | //echo str_replace(']','__'.$i.']',$str); |
| 57 | echo preg_replace("/\[([^\s^\]]*?)([\s\]]+)([^\]]*?)/", "[$1__{$i}$2",$str); |
| 58 | } |
| 59 | |
| 60 | $underscored_content = ob_get_clean(); |
| 61 | |
| 62 | return preg_replace_callback(WPCF7CF_REGEX_MAIL_GROUP, array($this, 'hide_hidden_mail_fields_regex_callback'), $underscored_content ); |
| 63 | |
| 64 | }else { |
| 65 | |
| 66 | // The tag name doesn't represent a group that was used in the form. Leave it alone (return the entire match). |
| 67 | return $matches[0]; |
| 68 | |
| 69 | } |
| 70 | } |
| 71 | } |