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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / includes / mail-tag.php
contact-form-7 / includes Last commit date
block-editor 1 year ago config-validator 11 months ago css 11 months ago js 1 year ago swv 10 months ago capabilities.php 7 years ago contact-form-functions.php 11 months ago contact-form-template.php 11 months ago contact-form.php 11 months ago controller.php 11 months ago file.php 10 months ago filesystem.php 11 months ago form-tag.php 11 months ago form-tags-manager.php 11 months ago formatting.php 11 months ago functions.php 10 months ago html-formatter.php 10 months ago integration.php 11 months ago l10n.php 11 months ago mail-tag.php 11 months ago mail.php 11 months ago pipe.php 11 months ago pocket-holder.php 3 years ago rest-api.php 11 months ago shortcodes.php 11 months ago special-mail-tags.php 10 months ago submission.php 10 months ago upgrade.php 11 months ago validation-functions.php 11 months ago validation.php 11 months ago
mail-tag.php
199 lines
1 <?php
2
3 /**
4 * Class that represents a mail-tag.
5 */
6 class WPCF7_MailTag {
7
8 private $tag;
9 private $tagname = '';
10 private $name = '';
11 private $options = array();
12 private $values = array();
13 private $form_tag = null;
14
15
16 /**
17 * The constructor method.
18 */
19 public function __construct( $tag, $tagname, $values ) {
20 $this->tag = $tag;
21 $this->name = $this->tagname = $tagname;
22
23 $this->options = array(
24 'do_not_heat' => false,
25 'format' => '',
26 );
27
28 if ( ! empty( $values ) ) {
29 preg_match_all( '/"[^"]*"|\'[^\']*\'/', $values, $matches );
30 $this->values = wpcf7_strip_quote_deep( $matches[0] );
31 }
32
33 if ( preg_match( '/^_raw_(.+)$/', $tagname, $matches ) ) {
34 $this->name = trim( $matches[1] );
35 $this->options['do_not_heat'] = true;
36 }
37
38 if ( preg_match( '/^_format_(.+)$/', $tagname, $matches ) ) {
39 $this->name = trim( $matches[1] );
40 $this->options['format'] = $this->values[0];
41 }
42 }
43
44
45 /**
46 * Returns the name part of this mail-tag.
47 */
48 public function tag_name() {
49 return $this->tagname;
50 }
51
52
53 /**
54 * Returns the form field name corresponding to this mail-tag.
55 */
56 public function field_name() {
57 return strtr( $this->name, '.', '_' );
58 }
59
60
61 /**
62 * Returns the value of the specified option.
63 */
64 public function get_option( $option ) {
65 return $this->options[$option];
66 }
67
68
69 /**
70 * Returns the values part of this mail-tag.
71 */
72 public function values() {
73 return $this->values;
74 }
75
76
77 /**
78 * Retrieves the WPCF7_FormTag object that corresponds to this mail-tag.
79 */
80 public function corresponding_form_tag() {
81 if ( $this->form_tag instanceof WPCF7_FormTag ) {
82 return $this->form_tag;
83 }
84
85 if ( $submission = WPCF7_Submission::get_instance() ) {
86 $contact_form = $submission->get_contact_form();
87
88 $tags = $contact_form->scan_form_tags( array(
89 'name' => $this->field_name(),
90 'feature' => '! zero-controls-container',
91 ) );
92
93 if ( $tags ) {
94 $this->form_tag = $tags[0];
95 }
96 }
97
98 return $this->form_tag;
99 }
100
101 }
102
103
104 use Contactable\SWV;
105
106 /**
107 * Mail-tag output calculator.
108 */
109 class WPCF7_MailTag_OutputCalculator {
110
111 const email = 0b100;
112 const text = 0b010;
113 const blank = 0b001;
114
115 private $contact_form;
116
117 public function __construct( WPCF7_ContactForm $contact_form ) {
118 $this->contact_form = $contact_form;
119 }
120
121 public function calc_output( WPCF7_MailTag $mail_tag ) {
122 return $this->calc_swv_result(
123 $mail_tag,
124 $this->contact_form->get_schema()
125 );
126 }
127
128 private function calc_swv_result( WPCF7_MailTag $mail_tag, SWV\Rule $rule ) {
129
130 if ( $rule instanceof SWV\AnyRule ) {
131 $result = 0b000;
132
133 foreach ( $rule->rules() as $child_rule ) {
134 $result |= $this->calc_swv_result( $mail_tag, $child_rule );
135 }
136
137 return $result;
138 }
139
140 if ( $rule instanceof SWV\CompositeRule ) {
141 $result = 0b111;
142
143 foreach ( $rule->rules() as $child_rule ) {
144 $result &= $this->calc_swv_result( $mail_tag, $child_rule );
145 }
146
147 return $result;
148 }
149
150 $field_prop = $rule->get_property( 'field' );
151
152 if ( empty( $field_prop ) or $field_prop !== $mail_tag->field_name() ) {
153 return self::email | self::text | self::blank;
154 }
155
156 if ( $rule instanceof SWV\RequiredRule ) {
157 return ~ self::blank;
158 }
159
160 if ( $rule instanceof SWV\EmailRule ) {
161 return self::email | self::blank;
162 }
163
164 if ( $rule instanceof SWV\EnumRule ) {
165 $acceptable_values = (array) $rule->get_property( 'accept' );
166 $acceptable_values = array_map( 'strval', $acceptable_values );
167 $acceptable_values = array_filter( $acceptable_values );
168 $acceptable_values = array_unique( $acceptable_values );
169
170 if ( ! $mail_tag->get_option( 'do_not_heat' ) ) {
171 $pipes = $this->contact_form->get_pipes(
172 $mail_tag->field_name()
173 );
174
175 $acceptable_values = array_map(
176 static function ( $val ) use ( $pipes ) {
177 return $pipes->do_pipe( $val );
178 },
179 $acceptable_values
180 );
181 }
182
183 $email_values = array_filter(
184 $acceptable_values,
185 'wpcf7_is_mailbox_list'
186 );
187
188 if ( count( $email_values ) === count( $acceptable_values ) ) {
189 return self::email | self::blank;
190 } else {
191 return self::email | self::text | self::blank;
192 }
193 }
194
195 return self::email | self::text | self::blank;
196 }
197
198 }
199