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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 2 years ago constant-contact 2 years ago recaptcha 2 years ago sendinblue 2 years ago stripe 2 years ago acceptance.php 3 years ago checkbox.php 3 years ago count.php 3 years ago date.php 3 years ago disallowed-list.php 4 years ago doi-helper.php 4 years ago file.php 3 years ago flamingo.php 3 years ago hidden.php 7 years ago listo.php 3 years ago number.php 3 years ago quiz.php 4 years ago really-simple-captcha.php 3 years ago reflection.php 3 years ago response.php 6 years ago select.php 3 years ago submit.php 4 years ago text.php 3 years ago textarea.php 3 years ago
file.php
213 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 $tag_generator->add( 'file', __( 'file', 'contact-form-7' ),
142 'wpcf7_tag_generator_file' );
143 }
144
145 function wpcf7_tag_generator_file( $contact_form, $args = '' ) {
146 $args = wp_parse_args( $args, array() );
147 $type = 'file';
148
149 $description = __( "Generate a form-tag for a file uploading field. For more details, see %s.", 'contact-form-7' );
150
151 $desc_link = wpcf7_link( __( 'https://contactform7.com/file-uploading-and-attachment/', 'contact-form-7' ), __( 'File uploading and attachment', 'contact-form-7' ) );
152
153 ?>
154 <div class="control-box">
155 <fieldset>
156 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
157
158 <table class="form-table">
159 <tbody>
160 <tr>
161 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
162 <td>
163 <fieldset>
164 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
165 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
166 </fieldset>
167 </td>
168 </tr>
169
170 <tr>
171 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
172 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
173 </tr>
174
175 <tr>
176 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-limit' ); ?>"><?php echo esc_html( __( "File size limit (bytes)", 'contact-form-7' ) ); ?></label></th>
177 <td><input type="text" name="limit" class="filesize oneline option" id="<?php echo esc_attr( $args['content'] . '-limit' ); ?>" /></td>
178 </tr>
179
180 <tr>
181 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>"><?php echo esc_html( __( 'Acceptable file types', 'contact-form-7' ) ); ?></label></th>
182 <td><input type="text" name="filetypes" class="filetype oneline option" id="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>" /></td>
183 </tr>
184
185 <tr>
186 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
187 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
188 </tr>
189
190 <tr>
191 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
192 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
193 </tr>
194
195 </tbody>
196 </table>
197 </fieldset>
198 </div>
199
200 <div class="insert-box">
201 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
202
203 <div class="submitbox">
204 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
205 </div>
206
207 <br class="clear" />
208
209 <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To attach the file uploaded through this field to mail, you need to insert the corresponding mail-tag (%s) into the File Attachments field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
210 </div>
211 <?php
212 }
213