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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 / modules / file.php
contact-form-7 / modules Last commit date
akismet 11 months ago constant-contact 9 months ago recaptcha 9 months ago sendinblue 9 months ago stripe 9 months ago turnstile 9 months ago acceptance.php 11 months ago checkbox.php 9 months ago count.php 1 year ago date.php 9 months ago disallowed-list.php 9 months ago doi-helper.php 4 years ago file.php 11 months ago flamingo.php 9 months ago hidden.php 7 years ago listo.php 2 years ago number.php 9 months ago quiz.php 11 months ago really-simple-captcha.php 9 months ago reflection.php 3 years ago response.php 6 years ago select.php 9 months ago submit.php 11 months ago text.php 9 months ago textarea.php 11 months ago
file.php
288 lines
1 <?php
2 /**
3 ** A base module for [file] and [file*]
4 **/
5
6 /* form_tag handler */
7
8 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_file', 10, 0 );
9
10 function wpcf7_add_form_tag_file() {
11 wpcf7_add_form_tag( array( 'file', 'file*' ),
12 'wpcf7_file_form_tag_handler',
13 array(
14 'name-attr' => true,
15 'file-uploading' => true,
16 )
17 );
18 }
19
20 function wpcf7_file_form_tag_handler( $tag ) {
21 if ( empty( $tag->name ) ) {
22 return '';
23 }
24
25 $validation_error = wpcf7_get_validation_error( $tag->name );
26
27 $class = wpcf7_form_controls_class( $tag->type );
28
29 if ( $validation_error ) {
30 $class .= ' wpcf7-not-valid';
31 }
32
33 $atts = array();
34
35 $atts['size'] = $tag->get_size_option( '40' );
36 $atts['class'] = $tag->get_class_option( $class );
37 $atts['id'] = $tag->get_id_option();
38 $atts['capture'] = $tag->get_option( 'capture', '(user|environment)', true );
39 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
40
41 $atts['accept'] = wpcf7_acceptable_filetypes(
42 $tag->get_option( 'filetypes' ), 'attr'
43 );
44
45 if ( $tag->is_required() ) {
46 $atts['aria-required'] = 'true';
47 }
48
49 if ( $validation_error ) {
50 $atts['aria-invalid'] = 'true';
51 $atts['aria-describedby'] = wpcf7_get_validation_error_reference(
52 $tag->name
53 );
54 } else {
55 $atts['aria-invalid'] = 'false';
56 }
57
58 $atts['type'] = 'file';
59 $atts['name'] = $tag->name;
60
61 $html = sprintf(
62 '<span class="wpcf7-form-control-wrap" data-name="%1$s"><input %2$s />%3$s</span>',
63 esc_attr( $tag->name ),
64 wpcf7_format_atts( $atts ),
65 $validation_error
66 );
67
68 return $html;
69 }
70
71
72 add_action(
73 'wpcf7_swv_create_schema',
74 'wpcf7_swv_add_file_rules',
75 10, 2
76 );
77
78 function wpcf7_swv_add_file_rules( $schema, $contact_form ) {
79 $tags = $contact_form->scan_form_tags( array(
80 'basetype' => array( 'file' ),
81 ) );
82
83 foreach ( $tags as $tag ) {
84 if ( $tag->is_required() ) {
85 $schema->add_rule(
86 wpcf7_swv_create_rule( 'requiredfile', array(
87 'field' => $tag->name,
88 'error' => wpcf7_get_message( 'invalid_required' ),
89 ) )
90 );
91 }
92
93 $schema->add_rule(
94 wpcf7_swv_create_rule( 'file', array(
95 'field' => $tag->name,
96 'accept' => explode( ',', wpcf7_acceptable_filetypes(
97 $tag->get_option( 'filetypes' ), 'attr'
98 ) ),
99 'error' => wpcf7_get_message( 'upload_file_type_invalid' ),
100 ) )
101 );
102
103 $schema->add_rule(
104 wpcf7_swv_create_rule( 'maxfilesize', array(
105 'field' => $tag->name,
106 'threshold' => $tag->get_limit_option(),
107 'error' => wpcf7_get_message( 'upload_file_too_large' ),
108 ) )
109 );
110 }
111 }
112
113
114 add_filter( 'wpcf7_mail_tag_replaced_file', 'wpcf7_file_mail_tag', 10, 4 );
115 add_filter( 'wpcf7_mail_tag_replaced_file*', 'wpcf7_file_mail_tag', 10, 4 );
116
117 function wpcf7_file_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
118 $submission = WPCF7_Submission::get_instance();
119 $uploaded_files = $submission->uploaded_files();
120 $name = $mail_tag->field_name();
121
122 if ( ! empty( $uploaded_files[$name] ) ) {
123 $paths = (array) $uploaded_files[$name];
124 $paths = array_map( 'wp_basename', $paths );
125
126 $replaced = wpcf7_flat_join( $paths, array(
127 'separator' => wp_get_list_item_separator(),
128 ) );
129 }
130
131 return $replaced;
132 }
133
134
135 /* Tag generator */
136
137 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_file', 50, 0 );
138
139 function wpcf7_add_tag_generator_file() {
140 $tag_generator = WPCF7_TagGenerator::get_instance();
141
142 $tag_generator->add( 'file', __( 'file', 'contact-form-7' ),
143 'wpcf7_tag_generator_file',
144 array( 'version' => '2' )
145 );
146 }
147
148 function wpcf7_tag_generator_file( $contact_form, $options ) {
149 $field_types = array(
150 'file' => array(
151 'display_name' => __( 'File uploading field', 'contact-form-7' ),
152 'heading' => __( 'File uploading field form-tag generator', 'contact-form-7' ),
153 'description' => __( 'Generates a form-tag for a <a href="https://contactform7.com/file-uploading-and-attachment/">file uploading field</a>.', 'contact-form-7' ),
154 ),
155 );
156
157 $tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
158
159 $formatter = new WPCF7_HTMLFormatter();
160
161 $formatter->append_start_tag( 'header', array(
162 'class' => 'description-box',
163 ) );
164
165 $formatter->append_start_tag( 'h3' );
166
167 $formatter->append_preformatted(
168 esc_html( $field_types['file']['heading'] )
169 );
170
171 $formatter->end_tag( 'h3' );
172
173 $formatter->append_start_tag( 'p' );
174
175 $formatter->append_preformatted(
176 wp_kses_data( $field_types['file']['description'] )
177 );
178
179 $formatter->end_tag( 'header' );
180
181 $formatter->append_start_tag( 'div', array(
182 'class' => 'control-box',
183 ) );
184
185 $formatter->call_user_func( static function () use ( $tgg, $field_types ) {
186 $tgg->print( 'field_type', array(
187 'with_required' => true,
188 'select_options' => array(
189 'file' => $field_types['file']['display_name'],
190 ),
191 ) );
192
193 $tgg->print( 'field_name' );
194
195 $tgg->print( 'class_attr' );
196 } );
197
198 $formatter->append_start_tag( 'fieldset' );
199
200 $formatter->append_start_tag( 'legend', array(
201 'id' => $tgg->ref( 'filetypes-option-legend' ),
202 ) );
203
204 $formatter->append_preformatted(
205 esc_html( __( 'Acceptable file types', 'contact-form-7' ) )
206 );
207
208 $formatter->end_tag( 'legend' );
209
210 $formatter->append_start_tag( 'label' );
211
212 $formatter->append_start_tag( 'span', array(
213 'id' => $tgg->ref( 'filetypes-option-description' ),
214 ) );
215
216 $formatter->append_preformatted(
217 esc_html( __( 'Pipe-separated file types list. You can use file extensions and MIME types.', 'contact-form-7' ) )
218 );
219
220 $formatter->end_tag( 'span' );
221
222 $formatter->append_start_tag( 'br' );
223
224 $formatter->append_start_tag( 'input', array(
225 'type' => 'text',
226 'pattern' => '[0-9a-z*\/\|]*',
227 'value' => 'audio/*|video/*|image/*',
228 'aria-labelledby' => $tgg->ref( 'filetypes-option-legend' ),
229 'aria-describedby' => $tgg->ref( 'filetypes-option-description' ),
230 'data-tag-part' => 'option',
231 'data-tag-option' => 'filetypes:',
232 ) );
233
234 $formatter->end_tag( 'fieldset' );
235
236 $formatter->append_start_tag( 'fieldset' );
237
238 $formatter->append_start_tag( 'legend', array(
239 'id' => $tgg->ref( 'limit-option-legend' ),
240 ) );
241
242 $formatter->append_preformatted(
243 esc_html( __( 'File size limit', 'contact-form-7' ) )
244 );
245
246 $formatter->end_tag( 'legend' );
247
248 $formatter->append_start_tag( 'label' );
249
250 $formatter->append_start_tag( 'span', array(
251 'id' => $tgg->ref( 'limit-option-description' ),
252 ) );
253
254 $formatter->append_preformatted(
255 esc_html( __( 'In bytes. You can use kb and mb suffixes.', 'contact-form-7' ) )
256 );
257
258 $formatter->end_tag( 'span' );
259
260 $formatter->append_start_tag( 'br' );
261
262 $formatter->append_start_tag( 'input', array(
263 'type' => 'text',
264 'pattern' => '[1-9][0-9]*([kKmM]?[bB])?',
265 'value' => '1mb',
266 'aria-labelledby' => $tgg->ref( 'limit-option-legend' ),
267 'aria-describedby' => $tgg->ref( 'limit-option-description' ),
268 'data-tag-part' => 'option',
269 'data-tag-option' => 'limit:',
270 ) );
271
272 $formatter->end_tag( 'fieldset' );
273
274 $formatter->end_tag( 'div' );
275
276 $formatter->append_start_tag( 'footer', array(
277 'class' => 'insert-box',
278 ) );
279
280 $formatter->call_user_func( static function () use ( $tgg, $field_types ) {
281 $tgg->print( 'insert_box_content' );
282
283 $tgg->print( 'mail_tag_tip' );
284 } );
285
286 $formatter->print();
287 }
288