@@ -15,36 +15,36 @@ |
||
15 | 15 | interface FileSubmissionInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function getName(); |
|
22 | - |
|
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getType(); |
|
27 | - |
|
28 | - /** |
|
29 | - * @return int |
|
30 | - */ |
|
31 | - public function getSize(); |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function getTmpFile(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @since $VID:$ |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function __toString(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getErrorCode(); |
|
18 | + /** |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function getName(); |
|
22 | + |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getType(); |
|
27 | + |
|
28 | + /** |
|
29 | + * @return int |
|
30 | + */ |
|
31 | + public function getSize(); |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function getTmpFile(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @since $VID:$ |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function __toString(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getErrorCode(); |
|
48 | 48 | } |
49 | 49 | // End of file FileSubmissionInterface.php |
50 | 50 | // Location: EventEspresso\core\services\request\files/FileSubmissionInterface.php |
@@ -38,260 +38,260 @@ |
||
38 | 38 | */ |
39 | 39 | class FilesDataHandler |
40 | 40 | { |
41 | - /** |
|
42 | - * @var Request |
|
43 | - */ |
|
44 | - protected $request; |
|
41 | + /** |
|
42 | + * @var Request |
|
43 | + */ |
|
44 | + protected $request; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var CollectionInterface | FileSubmissionInterface[] |
|
48 | - */ |
|
49 | - protected $file_objects; |
|
46 | + /** |
|
47 | + * @var CollectionInterface | FileSubmissionInterface[] |
|
48 | + */ |
|
49 | + protected $file_objects; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - protected $initialized = false; |
|
51 | + /** |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $initialized = false; |
|
55 | 55 | |
56 | - /** |
|
57 | - * FilesDataHandler constructor. |
|
58 | - * @param Request $request |
|
59 | - */ |
|
60 | - public function __construct(Request $request) |
|
61 | - { |
|
62 | - $this->request = $request; |
|
63 | - } |
|
56 | + /** |
|
57 | + * FilesDataHandler constructor. |
|
58 | + * @param Request $request |
|
59 | + */ |
|
60 | + public function __construct(Request $request) |
|
61 | + { |
|
62 | + $this->request = $request; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @since $VID:$ |
|
67 | - * @return CollectionInterface | FileSubmissionInterface[] |
|
68 | - * @throws UnexpectedValueException |
|
69 | - * @throws InvalidArgumentException |
|
70 | - */ |
|
71 | - protected function getFileObjects() |
|
72 | - { |
|
73 | - $this->initialize(); |
|
74 | - return $this->file_objects; |
|
75 | - } |
|
65 | + /** |
|
66 | + * @since $VID:$ |
|
67 | + * @return CollectionInterface | FileSubmissionInterface[] |
|
68 | + * @throws UnexpectedValueException |
|
69 | + * @throws InvalidArgumentException |
|
70 | + */ |
|
71 | + protected function getFileObjects() |
|
72 | + { |
|
73 | + $this->initialize(); |
|
74 | + return $this->file_objects; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Sets up the file objects from the request's $_FILES data. |
|
79 | - * @since $VID:$ |
|
80 | - * @throws UnexpectedValueException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
83 | - */ |
|
84 | - protected function initialize() |
|
85 | - { |
|
86 | - if ($this->initialized) { |
|
87 | - return; |
|
88 | - } |
|
89 | - $this->file_objects = new Collection( |
|
90 | - // collection interface |
|
91 | - 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
92 | - // collection name |
|
93 | - 'submitted_files' |
|
94 | - ); |
|
95 | - $files_raw_data = $this->request->filesParams(); |
|
96 | - if (empty($files_raw_data)) { |
|
97 | - return; |
|
98 | - } |
|
99 | - if ($this->isStrangeFilesArray($files_raw_data)) { |
|
100 | - $data = $this->fixFilesDataArray($files_raw_data); |
|
101 | - } else { |
|
102 | - $data = $files_raw_data; |
|
103 | - } |
|
104 | - $this->createFileObjects($data); |
|
105 | - $this->initialized = true; |
|
106 | - } |
|
77 | + /** |
|
78 | + * Sets up the file objects from the request's $_FILES data. |
|
79 | + * @since $VID:$ |
|
80 | + * @throws UnexpectedValueException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
83 | + */ |
|
84 | + protected function initialize() |
|
85 | + { |
|
86 | + if ($this->initialized) { |
|
87 | + return; |
|
88 | + } |
|
89 | + $this->file_objects = new Collection( |
|
90 | + // collection interface |
|
91 | + 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
92 | + // collection name |
|
93 | + 'submitted_files' |
|
94 | + ); |
|
95 | + $files_raw_data = $this->request->filesParams(); |
|
96 | + if (empty($files_raw_data)) { |
|
97 | + return; |
|
98 | + } |
|
99 | + if ($this->isStrangeFilesArray($files_raw_data)) { |
|
100 | + $data = $this->fixFilesDataArray($files_raw_data); |
|
101 | + } else { |
|
102 | + $data = $files_raw_data; |
|
103 | + } |
|
104 | + $this->createFileObjects($data); |
|
105 | + $this->initialized = true; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
110 | - * @since $VID:$ |
|
111 | - * @param $files_data |
|
112 | - * @return bool |
|
113 | - * @throws UnexpectedValueException |
|
114 | - */ |
|
115 | - protected function isStrangeFilesArray($files_data) |
|
116 | - { |
|
117 | - if (!is_array($files_data)) { |
|
118 | - throw new UnexpectedValueException( |
|
119 | - sprintf( |
|
120 | - esc_html__( |
|
121 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
122 | - 'event_espresso' |
|
123 | - ), |
|
124 | - (string) $files_data |
|
125 | - ) |
|
126 | - ); |
|
127 | - } |
|
128 | - $first_value = reset($files_data); |
|
129 | - if (!is_array($first_value)) { |
|
130 | - throw new UnexpectedValueException( |
|
131 | - sprintf( |
|
132 | - esc_html__( |
|
133 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - (string) $first_value |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
140 | - $first_sub_array_item = reset($first_value); |
|
141 | - if (is_array($first_sub_array_item)) { |
|
142 | - // not just a 2d array |
|
143 | - return true; |
|
144 | - } |
|
145 | - // yep, just 2d array |
|
146 | - return false; |
|
147 | - } |
|
108 | + /** |
|
109 | + * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
110 | + * @since $VID:$ |
|
111 | + * @param $files_data |
|
112 | + * @return bool |
|
113 | + * @throws UnexpectedValueException |
|
114 | + */ |
|
115 | + protected function isStrangeFilesArray($files_data) |
|
116 | + { |
|
117 | + if (!is_array($files_data)) { |
|
118 | + throw new UnexpectedValueException( |
|
119 | + sprintf( |
|
120 | + esc_html__( |
|
121 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
122 | + 'event_espresso' |
|
123 | + ), |
|
124 | + (string) $files_data |
|
125 | + ) |
|
126 | + ); |
|
127 | + } |
|
128 | + $first_value = reset($files_data); |
|
129 | + if (!is_array($first_value)) { |
|
130 | + throw new UnexpectedValueException( |
|
131 | + sprintf( |
|
132 | + esc_html__( |
|
133 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + (string) $first_value |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | + $first_sub_array_item = reset($first_value); |
|
141 | + if (is_array($first_sub_array_item)) { |
|
142 | + // not just a 2d array |
|
143 | + return true; |
|
144 | + } |
|
145 | + // yep, just 2d array |
|
146 | + return false; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
151 | - * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
152 | - * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
153 | - * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
154 | - * @since $VID:$ |
|
155 | - * @param $files_data |
|
156 | - * @return array |
|
157 | - */ |
|
158 | - protected function fixFilesDataArray($files_data) |
|
159 | - { |
|
160 | - $sane_files_array = []; |
|
161 | - foreach ($files_data as $top_key => $top_key_value) { |
|
162 | - foreach ($top_key_value as $lower_key => $lower_key_value) { |
|
163 | - foreach ($lower_key_value as $lowest_key => $lowest_key_value) { |
|
164 | - $next_data = [ |
|
165 | - $top_key => [ |
|
166 | - $lowest_key => $this->organizeFilesData($lowest_key_value, $lower_key, $lowest_key) |
|
167 | - ] |
|
168 | - ]; |
|
169 | - $sane_files_array = array_merge_recursive( |
|
170 | - $sane_files_array, |
|
171 | - $next_data |
|
172 | - ); |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $sane_files_array; |
|
177 | - } |
|
149 | + /** |
|
150 | + * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
151 | + * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
152 | + * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
153 | + * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
154 | + * @since $VID:$ |
|
155 | + * @param $files_data |
|
156 | + * @return array |
|
157 | + */ |
|
158 | + protected function fixFilesDataArray($files_data) |
|
159 | + { |
|
160 | + $sane_files_array = []; |
|
161 | + foreach ($files_data as $top_key => $top_key_value) { |
|
162 | + foreach ($top_key_value as $lower_key => $lower_key_value) { |
|
163 | + foreach ($lower_key_value as $lowest_key => $lowest_key_value) { |
|
164 | + $next_data = [ |
|
165 | + $top_key => [ |
|
166 | + $lowest_key => $this->organizeFilesData($lowest_key_value, $lower_key, $lowest_key) |
|
167 | + ] |
|
168 | + ]; |
|
169 | + $sane_files_array = array_merge_recursive( |
|
170 | + $sane_files_array, |
|
171 | + $next_data |
|
172 | + ); |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $sane_files_array; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
181 | - * @since $VID:$ |
|
182 | - * @param $data either 'name', 'tmp_name', 'size', or 'error' |
|
183 | - * @param $type |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - protected function organizeFilesData($data, $type) |
|
187 | - { |
|
188 | - $organized_data = []; |
|
189 | - foreach ($data as $key => $val) { |
|
190 | - if (is_array($val)) { |
|
191 | - $organized_data[ $key ] = $this->organizeFilesData($val, $type); |
|
192 | - } else { |
|
193 | - $organized_data[ $key ][ $type ] = $val; |
|
194 | - } |
|
195 | - } |
|
196 | - return $organized_data; |
|
197 | - } |
|
179 | + /** |
|
180 | + * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
181 | + * @since $VID:$ |
|
182 | + * @param $data either 'name', 'tmp_name', 'size', or 'error' |
|
183 | + * @param $type |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + protected function organizeFilesData($data, $type) |
|
187 | + { |
|
188 | + $organized_data = []; |
|
189 | + foreach ($data as $key => $val) { |
|
190 | + if (is_array($val)) { |
|
191 | + $organized_data[ $key ] = $this->organizeFilesData($val, $type); |
|
192 | + } else { |
|
193 | + $organized_data[ $key ][ $type ] = $val; |
|
194 | + } |
|
195 | + } |
|
196 | + return $organized_data; |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
201 | - * to be in $_GET or $_POST, with all the file's data located side-by-side in an array) and creates a |
|
202 | - * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
203 | - * @since $VID:$ |
|
204 | - * @param array $organized_files $_FILES but organized like $_POST |
|
205 | - * @param array $name_parts_so_far for multidimensional HTML form names, |
|
206 | - * @throws UnexpectedValueException |
|
207 | - * @throws InvalidArgumentException |
|
208 | - */ |
|
209 | - protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
210 | - { |
|
211 | - if (!is_array($organized_files)) { |
|
212 | - throw new UnexpectedValueException( |
|
213 | - sprintf( |
|
214 | - esc_html__( |
|
215 | - 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - (string) $organized_files |
|
219 | - ) |
|
220 | - ); |
|
221 | - } |
|
222 | - foreach ($organized_files as $key => $value) { |
|
223 | - array_push( |
|
224 | - $name_parts_so_far, |
|
225 | - $key |
|
226 | - ); |
|
227 | - if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
228 | - $html_name = $this->inputNameFromParts($name_parts_so_far); |
|
229 | - $this->file_objects->add( |
|
230 | - new FileSubmission( |
|
231 | - $html_name, |
|
232 | - $value['name'], |
|
233 | - $value['tmp_name'], |
|
234 | - $value['size'], |
|
235 | - $value['error'] |
|
236 | - ), |
|
237 | - $html_name |
|
238 | - ); |
|
239 | - } else { |
|
240 | - $this->createFileObjects($value, $name_parts_so_far); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
199 | + /** |
|
200 | + * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
201 | + * to be in $_GET or $_POST, with all the file's data located side-by-side in an array) and creates a |
|
202 | + * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
203 | + * @since $VID:$ |
|
204 | + * @param array $organized_files $_FILES but organized like $_POST |
|
205 | + * @param array $name_parts_so_far for multidimensional HTML form names, |
|
206 | + * @throws UnexpectedValueException |
|
207 | + * @throws InvalidArgumentException |
|
208 | + */ |
|
209 | + protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
210 | + { |
|
211 | + if (!is_array($organized_files)) { |
|
212 | + throw new UnexpectedValueException( |
|
213 | + sprintf( |
|
214 | + esc_html__( |
|
215 | + 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + (string) $organized_files |
|
219 | + ) |
|
220 | + ); |
|
221 | + } |
|
222 | + foreach ($organized_files as $key => $value) { |
|
223 | + array_push( |
|
224 | + $name_parts_so_far, |
|
225 | + $key |
|
226 | + ); |
|
227 | + if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
228 | + $html_name = $this->inputNameFromParts($name_parts_so_far); |
|
229 | + $this->file_objects->add( |
|
230 | + new FileSubmission( |
|
231 | + $html_name, |
|
232 | + $value['name'], |
|
233 | + $value['tmp_name'], |
|
234 | + $value['size'], |
|
235 | + $value['error'] |
|
236 | + ), |
|
237 | + $html_name |
|
238 | + ); |
|
239 | + } else { |
|
240 | + $this->createFileObjects($value, $name_parts_so_far); |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
247 | - * and returns the HTML name for it, "my[great][file][input1]" |
|
248 | - * @since $VID:$ |
|
249 | - * @param $parts |
|
250 | - * @throws UnexpectedValueException |
|
251 | - */ |
|
252 | - protected function inputNameFromParts($parts) |
|
253 | - { |
|
254 | - if (!is_array($parts)) { |
|
255 | - throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
256 | - } |
|
257 | - $generated_string = ''; |
|
258 | - foreach ($parts as $part) { |
|
259 | - if ($generated_string === '') { |
|
260 | - $generated_string = (string) $part; |
|
261 | - } else { |
|
262 | - $generated_string .= '[' . (string) $part . ']'; |
|
263 | - } |
|
264 | - } |
|
265 | - return $generated_string; |
|
266 | - } |
|
245 | + /** |
|
246 | + * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
247 | + * and returns the HTML name for it, "my[great][file][input1]" |
|
248 | + * @since $VID:$ |
|
249 | + * @param $parts |
|
250 | + * @throws UnexpectedValueException |
|
251 | + */ |
|
252 | + protected function inputNameFromParts($parts) |
|
253 | + { |
|
254 | + if (!is_array($parts)) { |
|
255 | + throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
256 | + } |
|
257 | + $generated_string = ''; |
|
258 | + foreach ($parts as $part) { |
|
259 | + if ($generated_string === '') { |
|
260 | + $generated_string = (string) $part; |
|
261 | + } else { |
|
262 | + $generated_string .= '[' . (string) $part . ']'; |
|
263 | + } |
|
264 | + } |
|
265 | + return $generated_string; |
|
266 | + } |
|
267 | 267 | |
268 | - /** |
|
269 | - * Gets the input by the indicated $name_parts. |
|
270 | - * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
271 | - * should be `['my', 'great', 'file', 'input1']`. |
|
272 | - * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
273 | - * @since $VID:$ |
|
274 | - * @param $name_parts |
|
275 | - * @throws UnexpectedValueException |
|
276 | - * @return FileSubmissionInterface |
|
277 | - */ |
|
278 | - public function getFileObjectFromNameParts($name_parts) |
|
279 | - { |
|
280 | - return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
281 | - } |
|
268 | + /** |
|
269 | + * Gets the input by the indicated $name_parts. |
|
270 | + * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
271 | + * should be `['my', 'great', 'file', 'input1']`. |
|
272 | + * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
273 | + * @since $VID:$ |
|
274 | + * @param $name_parts |
|
275 | + * @throws UnexpectedValueException |
|
276 | + * @return FileSubmissionInterface |
|
277 | + */ |
|
278 | + public function getFileObjectFromNameParts($name_parts) |
|
279 | + { |
|
280 | + return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
285 | - * @since $VID:$ |
|
286 | - * @param $html_name |
|
287 | - * @return mixed |
|
288 | - * @throws InvalidArgumentException |
|
289 | - * @throws UnexpectedValueException |
|
290 | - */ |
|
291 | - public function getFileObject($html_name) |
|
292 | - { |
|
293 | - return $this->getFileObjects()->get($html_name); |
|
294 | - } |
|
283 | + /** |
|
284 | + * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
285 | + * @since $VID:$ |
|
286 | + * @param $html_name |
|
287 | + * @return mixed |
|
288 | + * @throws InvalidArgumentException |
|
289 | + * @throws UnexpectedValueException |
|
290 | + */ |
|
291 | + public function getFileObject($html_name) |
|
292 | + { |
|
293 | + return $this->getFileObjects()->get($html_name); |
|
294 | + } |
|
295 | 295 | } |
296 | 296 | // End of file FilesDataHandler.php |
297 | 297 | // Location: EventEspresso\core\services\request\files/FilesDataHandler.php |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function isStrangeFilesArray($files_data) |
116 | 116 | { |
117 | - if (!is_array($files_data)) { |
|
117 | + if ( ! is_array($files_data)) { |
|
118 | 118 | throw new UnexpectedValueException( |
119 | 119 | sprintf( |
120 | 120 | esc_html__( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ); |
127 | 127 | } |
128 | 128 | $first_value = reset($files_data); |
129 | - if (!is_array($first_value)) { |
|
129 | + if ( ! is_array($first_value)) { |
|
130 | 130 | throw new UnexpectedValueException( |
131 | 131 | sprintf( |
132 | 132 | esc_html__( |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | $organized_data = []; |
189 | 189 | foreach ($data as $key => $val) { |
190 | 190 | if (is_array($val)) { |
191 | - $organized_data[ $key ] = $this->organizeFilesData($val, $type); |
|
191 | + $organized_data[$key] = $this->organizeFilesData($val, $type); |
|
192 | 192 | } else { |
193 | - $organized_data[ $key ][ $type ] = $val; |
|
193 | + $organized_data[$key][$type] = $val; |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | return $organized_data; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | protected function createFileObjects($organized_files, $name_parts_so_far = []) |
210 | 210 | { |
211 | - if (!is_array($organized_files)) { |
|
211 | + if ( ! is_array($organized_files)) { |
|
212 | 212 | throw new UnexpectedValueException( |
213 | 213 | sprintf( |
214 | 214 | esc_html__( |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | protected function inputNameFromParts($parts) |
253 | 253 | { |
254 | - if (!is_array($parts)) { |
|
254 | + if ( ! is_array($parts)) { |
|
255 | 255 | throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
256 | 256 | } |
257 | 257 | $generated_string = ''; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | if ($generated_string === '') { |
260 | 260 | $generated_string = (string) $part; |
261 | 261 | } else { |
262 | - $generated_string .= '[' . (string) $part . ']'; |
|
262 | + $generated_string .= '['.(string) $part.']'; |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | return $generated_string; |
@@ -59,7 +59,7 @@ |
||
59 | 59 | * Makes sure the input has the desired key and casts it as the appropriate type. |
60 | 60 | * @since $VID:$ |
61 | 61 | * @param $php_file_info_array |
62 | - * @param $desired_key |
|
62 | + * @param string $desired_key |
|
63 | 63 | * @param string $cast_as "string" or "int" |
64 | 64 | * @return int|string |
65 | 65 | * @throws InvalidArgumentException |
@@ -17,121 +17,121 @@ |
||
17 | 17 | */ |
18 | 18 | class UploadedFile |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string original name on the client machine |
|
22 | - */ |
|
23 | - protected $name; |
|
20 | + /** |
|
21 | + * @var string original name on the client machine |
|
22 | + */ |
|
23 | + protected $name; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string mime type |
|
27 | - */ |
|
28 | - protected $type; |
|
25 | + /** |
|
26 | + * @var string mime type |
|
27 | + */ |
|
28 | + protected $type; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var int in bytes |
|
32 | - */ |
|
33 | - protected $size; |
|
30 | + /** |
|
31 | + * @var int in bytes |
|
32 | + */ |
|
33 | + protected $size; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var string local filepath to the temporary file |
|
37 | - */ |
|
38 | - protected $tmp_name; |
|
35 | + /** |
|
36 | + * @var string local filepath to the temporary file |
|
37 | + */ |
|
38 | + protected $tmp_name; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var string one of https://secure.php.net/manual/en/features.file-upload.errors.php |
|
42 | - */ |
|
43 | - protected $error; |
|
40 | + /** |
|
41 | + * @var string one of https://secure.php.net/manual/en/features.file-upload.errors.php |
|
42 | + */ |
|
43 | + protected $error; |
|
44 | 44 | |
45 | - public function __construct($php_file_info) |
|
46 | - { |
|
47 | - $this->name = $this->extractFromArrayOrThrowException($php_file_info, 'name'); |
|
48 | - try { |
|
49 | - $this->type = $this->extractFromArrayOrThrowException($php_file_info, 'type'); |
|
50 | - } catch (InvalidArgumentException $e) { |
|
51 | - // The browser must have not provided the mimetype, oh well. |
|
52 | - $this->type = 'text/html'; |
|
53 | - } |
|
54 | - $this->size = $this->extractFromArrayOrThrowException($php_file_info, 'size', 'int'); |
|
55 | - $this->tmp_name = $this->extractFromArrayOrThrowException($php_file_info, 'tmp_name'); |
|
56 | - } |
|
45 | + public function __construct($php_file_info) |
|
46 | + { |
|
47 | + $this->name = $this->extractFromArrayOrThrowException($php_file_info, 'name'); |
|
48 | + try { |
|
49 | + $this->type = $this->extractFromArrayOrThrowException($php_file_info, 'type'); |
|
50 | + } catch (InvalidArgumentException $e) { |
|
51 | + // The browser must have not provided the mimetype, oh well. |
|
52 | + $this->type = 'text/html'; |
|
53 | + } |
|
54 | + $this->size = $this->extractFromArrayOrThrowException($php_file_info, 'size', 'int'); |
|
55 | + $this->tmp_name = $this->extractFromArrayOrThrowException($php_file_info, 'tmp_name'); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Makes sure the input has the desired key and casts it as the appropriate type. |
|
60 | - * @since $VID:$ |
|
61 | - * @param $php_file_info_array |
|
62 | - * @param $desired_key |
|
63 | - * @param string $cast_as "string" or "int" |
|
64 | - * @return int|string |
|
65 | - * @throws InvalidArgumentException |
|
66 | - */ |
|
67 | - protected function extractFromArrayOrThrowException($php_file_info_array, $desired_key, $cast_as = 'string') |
|
68 | - { |
|
69 | - if (!isset($php_file_info_array[$desired_key])) { |
|
70 | - throw new InvalidArgumentException( |
|
71 | - sprintf( |
|
72 | - esc_html__('PHP Upload data for a file was missing the key %1$s', 'event_espresso'), |
|
73 | - $desired_key |
|
74 | - ) |
|
75 | - ); |
|
76 | - } |
|
77 | - $raw_value = $php_file_info_array[$desired_key]; |
|
78 | - switch ($cast_as) { |
|
79 | - case 'int': |
|
80 | - return (int)$raw_value; |
|
81 | - case 'string': |
|
82 | - default: |
|
83 | - return (string)$raw_value; |
|
84 | - } |
|
85 | - } |
|
58 | + /** |
|
59 | + * Makes sure the input has the desired key and casts it as the appropriate type. |
|
60 | + * @since $VID:$ |
|
61 | + * @param $php_file_info_array |
|
62 | + * @param $desired_key |
|
63 | + * @param string $cast_as "string" or "int" |
|
64 | + * @return int|string |
|
65 | + * @throws InvalidArgumentException |
|
66 | + */ |
|
67 | + protected function extractFromArrayOrThrowException($php_file_info_array, $desired_key, $cast_as = 'string') |
|
68 | + { |
|
69 | + if (!isset($php_file_info_array[$desired_key])) { |
|
70 | + throw new InvalidArgumentException( |
|
71 | + sprintf( |
|
72 | + esc_html__('PHP Upload data for a file was missing the key %1$s', 'event_espresso'), |
|
73 | + $desired_key |
|
74 | + ) |
|
75 | + ); |
|
76 | + } |
|
77 | + $raw_value = $php_file_info_array[$desired_key]; |
|
78 | + switch ($cast_as) { |
|
79 | + case 'int': |
|
80 | + return (int)$raw_value; |
|
81 | + case 'string': |
|
82 | + default: |
|
83 | + return (string)$raw_value; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getName() |
|
91 | - { |
|
92 | - return $this->name; |
|
93 | - } |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getName() |
|
91 | + { |
|
92 | + return $this->name; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getType() |
|
99 | - { |
|
100 | - return $this->type; |
|
101 | - } |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getType() |
|
99 | + { |
|
100 | + return $this->type; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function getSize() |
|
107 | - { |
|
108 | - return $this->size; |
|
109 | - } |
|
103 | + /** |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function getSize() |
|
107 | + { |
|
108 | + return $this->size; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function getTmpName() |
|
115 | - { |
|
116 | - return $this->tmp_name; |
|
117 | - } |
|
111 | + /** |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function getTmpName() |
|
115 | + { |
|
116 | + return $this->tmp_name; |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function getError() |
|
123 | - { |
|
124 | - return $this->error; |
|
125 | - } |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function getError() |
|
123 | + { |
|
124 | + return $this->error; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @since $VID:$ |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function __toString() |
|
132 | - { |
|
133 | - return $this->getTmpName(); |
|
134 | - } |
|
127 | + /** |
|
128 | + * @since $VID:$ |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function __toString() |
|
132 | + { |
|
133 | + return $this->getTmpName(); |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | // End of file UploadedFile.php |
137 | 137 | // Location: EventEspresso\core\entities\forms/UploadedFile.php |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected function extractFromArrayOrThrowException($php_file_info_array, $desired_key, $cast_as = 'string') |
68 | 68 | { |
69 | - if (!isset($php_file_info_array[$desired_key])) { |
|
69 | + if ( ! isset($php_file_info_array[$desired_key])) { |
|
70 | 70 | throw new InvalidArgumentException( |
71 | 71 | sprintf( |
72 | 72 | esc_html__('PHP Upload data for a file was missing the key %1$s', 'event_espresso'), |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | $raw_value = $php_file_info_array[$desired_key]; |
78 | 78 | switch ($cast_as) { |
79 | 79 | case 'int': |
80 | - return (int)$raw_value; |
|
80 | + return (int) $raw_value; |
|
81 | 81 | case 'string': |
82 | 82 | default: |
83 | - return (string)$raw_value; |
|
83 | + return (string) $raw_value; |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 |
@@ -15,59 +15,59 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class EE_File_Input extends EE_Form_Input_Base |
17 | 17 | { |
18 | - /** |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $allowed_file_extensions; |
|
18 | + /** |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $allowed_file_extensions; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var |
|
25 | - */ |
|
26 | - protected $allowed_mime_types; |
|
23 | + /** |
|
24 | + * @var |
|
25 | + */ |
|
26 | + protected $allowed_mime_types; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param array $options |
|
30 | - * @throws InvalidArgumentException |
|
31 | - */ |
|
32 | - public function __construct($options = array()) |
|
33 | - { |
|
34 | - if (isset($options['allowed_file_extensions'])) { |
|
35 | - if (!is_array($options['allowed_file_extensions'])) { |
|
36 | - throw new InvalidArgumentException(esc_html__('A valid allowed_file_extensions array was not provided to EE_File_Input', 'event_espresso')); |
|
37 | - } |
|
38 | - $this->allowed_file_extensions = $options['allowed_file_extensions']; |
|
39 | - } else { |
|
40 | - $this->allowed_file_extensions = ['csv']; |
|
41 | - } |
|
42 | - if (isset($options['allowed_mime_types'])) { |
|
43 | - if (!is_array($options['allowed_mime_types'])) { |
|
44 | - throw new InvalidArgumentException(esc_html__('A valid allowed_mime_types array was not provided to EE_File_Input', 'event_espresso')); |
|
45 | - } |
|
46 | - $this->allowed_mime_types = $options['allowed_file_extensions']; |
|
47 | - } else { |
|
48 | - $this->allowed_mime_types = ['text/csv']; |
|
49 | - } |
|
28 | + /** |
|
29 | + * @param array $options |
|
30 | + * @throws InvalidArgumentException |
|
31 | + */ |
|
32 | + public function __construct($options = array()) |
|
33 | + { |
|
34 | + if (isset($options['allowed_file_extensions'])) { |
|
35 | + if (!is_array($options['allowed_file_extensions'])) { |
|
36 | + throw new InvalidArgumentException(esc_html__('A valid allowed_file_extensions array was not provided to EE_File_Input', 'event_espresso')); |
|
37 | + } |
|
38 | + $this->allowed_file_extensions = $options['allowed_file_extensions']; |
|
39 | + } else { |
|
40 | + $this->allowed_file_extensions = ['csv']; |
|
41 | + } |
|
42 | + if (isset($options['allowed_mime_types'])) { |
|
43 | + if (!is_array($options['allowed_mime_types'])) { |
|
44 | + throw new InvalidArgumentException(esc_html__('A valid allowed_mime_types array was not provided to EE_File_Input', 'event_espresso')); |
|
45 | + } |
|
46 | + $this->allowed_mime_types = $options['allowed_file_extensions']; |
|
47 | + } else { |
|
48 | + $this->allowed_mime_types = ['text/csv']; |
|
49 | + } |
|
50 | 50 | |
51 | - $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
|
52 | - $this->_set_normalization_strategy(new EE_File_Normalization()); |
|
53 | - $this->add_validation_strategy( |
|
54 | - new EE_Text_Validation_Strategy( |
|
55 | - sprintf( |
|
56 | - // translators: %1$s is a list of allowed file extensions. |
|
57 | - esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
|
58 | - implode(', ', $this->allowed_file_extensions) |
|
59 | - ), |
|
60 | - '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
61 | - ) |
|
62 | - ); |
|
63 | - parent::__construct($options); |
|
51 | + $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
|
52 | + $this->_set_normalization_strategy(new EE_File_Normalization()); |
|
53 | + $this->add_validation_strategy( |
|
54 | + new EE_Text_Validation_Strategy( |
|
55 | + sprintf( |
|
56 | + // translators: %1$s is a list of allowed file extensions. |
|
57 | + esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
|
58 | + implode(', ', $this->allowed_file_extensions) |
|
59 | + ), |
|
60 | + '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
61 | + ) |
|
62 | + ); |
|
63 | + parent::__construct($options); |
|
64 | 64 | |
65 | 65 | // It would be great to add this HTML attribute, but jQuery validate chokes on it. |
66 | - $this->set_other_html_attributes( |
|
67 | - $this->other_html_attributes() |
|
68 | - . ' extension="' |
|
69 | - . implode( |
|
70 | - ',', |
|
66 | + $this->set_other_html_attributes( |
|
67 | + $this->other_html_attributes() |
|
68 | + . ' extension="' |
|
69 | + . implode( |
|
70 | + ',', |
|
71 | 71 | // array_merge( |
72 | 72 | // array_map( |
73 | 73 | // function ($mime_type) { |
@@ -80,86 +80,86 @@ discard block |
||
80 | 80 | // }, |
81 | 81 | // $this->allowed_mime_types |
82 | 82 | // ) |
83 | - array_map( |
|
84 | - function ($file_extension) { |
|
85 | - return $file_extension; |
|
86 | - }, |
|
87 | - $this->allowed_file_extensions |
|
88 | - ) |
|
83 | + array_map( |
|
84 | + function ($file_extension) { |
|
85 | + return $file_extension; |
|
86 | + }, |
|
87 | + $this->allowed_file_extensions |
|
88 | + ) |
|
89 | 89 | // ) |
90 | - ) |
|
91 | - . '"' |
|
92 | - ); |
|
93 | - } |
|
90 | + ) |
|
91 | + . '"' |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
97 | - * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
98 | - * "name", "size", "temp_file", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
99 | - * "my[size][hierarchical][form]", "my[temp_name][hierarchical][form]", etc. It's really weird. |
|
100 | - * @since $VID:$ |
|
101 | - * @param array $req_data |
|
102 | - * @return array|mixed|NULL |
|
103 | - * @throws EE_Error |
|
104 | - */ |
|
105 | - public function find_form_data_for_this_section($req_data) |
|
106 | - { |
|
107 | - $name_parts = $this->getInputNameParts(); |
|
108 | - // now get the value for the input |
|
109 | - $value = $this->findFileData($name_parts, $req_data); |
|
95 | + /** |
|
96 | + * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
97 | + * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
98 | + * "name", "size", "temp_file", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
99 | + * "my[size][hierarchical][form]", "my[temp_name][hierarchical][form]", etc. It's really weird. |
|
100 | + * @since $VID:$ |
|
101 | + * @param array $req_data |
|
102 | + * @return array|mixed|NULL |
|
103 | + * @throws EE_Error |
|
104 | + */ |
|
105 | + public function find_form_data_for_this_section($req_data) |
|
106 | + { |
|
107 | + $name_parts = $this->getInputNameParts(); |
|
108 | + // now get the value for the input |
|
109 | + $value = $this->findFileData($name_parts, $req_data); |
|
110 | 110 | |
111 | - if (empty($value)) { |
|
112 | - $value = $this->findFileData($name_parts, $_FILES); |
|
113 | - } |
|
114 | - if (empty($value)) { |
|
115 | - array_shift($name_parts); |
|
116 | - // check if this thing's name is at the TOP level of the request data |
|
117 | - $value = $this->findFileData($name_parts, $req_data); |
|
118 | - } |
|
119 | - return $value; |
|
120 | - } |
|
111 | + if (empty($value)) { |
|
112 | + $value = $this->findFileData($name_parts, $_FILES); |
|
113 | + } |
|
114 | + if (empty($value)) { |
|
115 | + array_shift($name_parts); |
|
116 | + // check if this thing's name is at the TOP level of the request data |
|
117 | + $value = $this->findFileData($name_parts, $req_data); |
|
118 | + } |
|
119 | + return $value; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Look for the file's data in this request data. |
|
124 | - * @since $VID:$ |
|
125 | - * @param $name_parts |
|
126 | - * @param $req_data |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - protected function findFileData($name_parts, $req_data) |
|
130 | - { |
|
131 | - $file_parts = [ |
|
132 | - 'name', |
|
133 | - 'error', |
|
134 | - 'size', |
|
135 | - 'tmp_name', |
|
136 | - 'type' |
|
137 | - ]; |
|
138 | - $file_data = []; |
|
139 | - foreach($file_parts as $file_part){ |
|
140 | - $datum = $this->findRequestForSectionUsingNameParts($this->getFileDataNameParts($name_parts, $file_part),$req_data); |
|
141 | - if(!empty($datum)) { |
|
142 | - $file_data[$file_part] = $datum; |
|
143 | - } |
|
144 | - } |
|
145 | - return $file_data; |
|
146 | - } |
|
122 | + /** |
|
123 | + * Look for the file's data in this request data. |
|
124 | + * @since $VID:$ |
|
125 | + * @param $name_parts |
|
126 | + * @param $req_data |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + protected function findFileData($name_parts, $req_data) |
|
130 | + { |
|
131 | + $file_parts = [ |
|
132 | + 'name', |
|
133 | + 'error', |
|
134 | + 'size', |
|
135 | + 'tmp_name', |
|
136 | + 'type' |
|
137 | + ]; |
|
138 | + $file_data = []; |
|
139 | + foreach($file_parts as $file_part){ |
|
140 | + $datum = $this->findRequestForSectionUsingNameParts($this->getFileDataNameParts($name_parts, $file_part),$req_data); |
|
141 | + if(!empty($datum)) { |
|
142 | + $file_data[$file_part] = $datum; |
|
143 | + } |
|
144 | + } |
|
145 | + return $file_data; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Finds the file name parts for the desired file data. |
|
150 | - * @since $VID:$ |
|
151 | - * @param $original_name_parts |
|
152 | - * @param $file_data_sought |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function getFileDataNameParts($original_name_parts, $file_data_sought){ |
|
156 | - return |
|
157 | - array_merge( |
|
158 | - [ |
|
159 | - $original_name_parts[0], |
|
160 | - $file_data_sought |
|
161 | - ], |
|
162 | - array_slice($original_name_parts, 1) |
|
163 | - ); |
|
164 | - } |
|
148 | + /** |
|
149 | + * Finds the file name parts for the desired file data. |
|
150 | + * @since $VID:$ |
|
151 | + * @param $original_name_parts |
|
152 | + * @param $file_data_sought |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function getFileDataNameParts($original_name_parts, $file_data_sought){ |
|
156 | + return |
|
157 | + array_merge( |
|
158 | + [ |
|
159 | + $original_name_parts[0], |
|
160 | + $file_data_sought |
|
161 | + ], |
|
162 | + array_slice($original_name_parts, 1) |
|
163 | + ); |
|
164 | + } |
|
165 | 165 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function __construct($options = array()) |
33 | 33 | { |
34 | 34 | if (isset($options['allowed_file_extensions'])) { |
35 | - if (!is_array($options['allowed_file_extensions'])) { |
|
35 | + if ( ! is_array($options['allowed_file_extensions'])) { |
|
36 | 36 | throw new InvalidArgumentException(esc_html__('A valid allowed_file_extensions array was not provided to EE_File_Input', 'event_espresso')); |
37 | 37 | } |
38 | 38 | $this->allowed_file_extensions = $options['allowed_file_extensions']; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $this->allowed_file_extensions = ['csv']; |
41 | 41 | } |
42 | 42 | if (isset($options['allowed_mime_types'])) { |
43 | - if (!is_array($options['allowed_mime_types'])) { |
|
43 | + if ( ! is_array($options['allowed_mime_types'])) { |
|
44 | 44 | throw new InvalidArgumentException(esc_html__('A valid allowed_mime_types array was not provided to EE_File_Input', 'event_espresso')); |
45 | 45 | } |
46 | 46 | $this->allowed_mime_types = $options['allowed_file_extensions']; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
58 | 58 | implode(', ', $this->allowed_file_extensions) |
59 | 59 | ), |
60 | - '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
60 | + '~.*\.('.implode('|', $this->allowed_file_extensions).')$~' |
|
61 | 61 | ) |
62 | 62 | ); |
63 | 63 | parent::__construct($options); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | // $this->allowed_mime_types |
82 | 82 | // ) |
83 | 83 | array_map( |
84 | - function ($file_extension) { |
|
84 | + function($file_extension) { |
|
85 | 85 | return $file_extension; |
86 | 86 | }, |
87 | 87 | $this->allowed_file_extensions |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | 'type' |
137 | 137 | ]; |
138 | 138 | $file_data = []; |
139 | - foreach($file_parts as $file_part){ |
|
140 | - $datum = $this->findRequestForSectionUsingNameParts($this->getFileDataNameParts($name_parts, $file_part),$req_data); |
|
141 | - if(!empty($datum)) { |
|
139 | + foreach ($file_parts as $file_part) { |
|
140 | + $datum = $this->findRequestForSectionUsingNameParts($this->getFileDataNameParts($name_parts, $file_part), $req_data); |
|
141 | + if ( ! empty($datum)) { |
|
142 | 142 | $file_data[$file_part] = $datum; |
143 | 143 | } |
144 | 144 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param $file_data_sought |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - protected function getFileDataNameParts($original_name_parts, $file_data_sought){ |
|
155 | + protected function getFileDataNameParts($original_name_parts, $file_data_sought) { |
|
156 | 156 | return |
157 | 157 | array_merge( |
158 | 158 | [ |
@@ -29,641 +29,641 @@ |
||
29 | 29 | abstract class FormHandler implements FormHandlerInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * will add opening and closing HTML form tags as well as a submit button |
|
34 | - */ |
|
35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | - |
|
37 | - /** |
|
38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
39 | - */ |
|
40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | - |
|
42 | - /** |
|
43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | - */ |
|
45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | - |
|
47 | - /** |
|
48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | - */ |
|
50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | - |
|
52 | - /** |
|
53 | - * if set to false, then this form has no displayable content, |
|
54 | - * and will only be used for processing data sent passed via GET or POST |
|
55 | - * defaults to true ( ie: form has displayable content ) |
|
56 | - * |
|
57 | - * @var boolean $displayable |
|
58 | - */ |
|
59 | - private $displayable = true; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $form_name |
|
63 | - */ |
|
64 | - private $form_name; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $admin_name |
|
68 | - */ |
|
69 | - private $admin_name; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string $slug |
|
73 | - */ |
|
74 | - private $slug; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var string $submit_btn_text |
|
78 | - */ |
|
79 | - private $submit_btn_text; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var string $form_action |
|
83 | - */ |
|
84 | - private $form_action; |
|
85 | - |
|
86 | - /** |
|
87 | - * form params in key value pairs |
|
88 | - * can be added to form action URL or as hidden inputs |
|
89 | - * |
|
90 | - * @var array $form_args |
|
91 | - */ |
|
92 | - private $form_args = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * value of one of the string constant above |
|
96 | - * |
|
97 | - * @var string $form_config |
|
98 | - */ |
|
99 | - private $form_config; |
|
100 | - |
|
101 | - /** |
|
102 | - * whether or not the form was determined to be invalid |
|
103 | - * |
|
104 | - * @var boolean $form_has_errors |
|
105 | - */ |
|
106 | - private $form_has_errors; |
|
107 | - |
|
108 | - /** |
|
109 | - * the absolute top level form section being used on the page |
|
110 | - * |
|
111 | - * @var EE_Form_Section_Proper $form |
|
112 | - */ |
|
113 | - private $form; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var EE_Registry $registry |
|
117 | - */ |
|
118 | - protected $registry; |
|
119 | - |
|
120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | - /** |
|
122 | - * Form constructor. |
|
123 | - * |
|
124 | - * @param string $form_name |
|
125 | - * @param string $admin_name |
|
126 | - * @param string $slug |
|
127 | - * @param string $form_action |
|
128 | - * @param string $form_config |
|
129 | - * @param EE_Registry $registry |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws DomainException |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $form_name, |
|
136 | - $admin_name, |
|
137 | - $slug, |
|
138 | - $form_action = '', |
|
139 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
140 | - EE_Registry $registry |
|
141 | - ) { |
|
142 | - $this->setFormName($form_name); |
|
143 | - $this->setAdminName($admin_name); |
|
144 | - $this->setSlug($slug); |
|
145 | - $this->setFormAction($form_action); |
|
146 | - $this->setFormConfig($form_config); |
|
147 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
148 | - $this->registry = $registry; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public static function getFormConfigConstants() |
|
156 | - { |
|
157 | - return array( |
|
158 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
159 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
160 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
161 | - FormHandler::DO_NOT_SETUP_FORM, |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param bool $for_display |
|
168 | - * @return EE_Form_Section_Proper |
|
169 | - * @throws EE_Error |
|
170 | - * @throws LogicException |
|
171 | - */ |
|
172 | - public function form($for_display = false) |
|
173 | - { |
|
174 | - if (! $this->formIsValid()) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - if ($for_display) { |
|
178 | - $form_config = $this->formConfig(); |
|
179 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
180 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
181 | - ) { |
|
182 | - $this->appendSubmitButton(); |
|
183 | - $this->clearFormButtonFloats(); |
|
184 | - } |
|
185 | - } |
|
186 | - return $this->form; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @return boolean |
|
192 | - * @throws LogicException |
|
193 | - */ |
|
194 | - public function formIsValid() |
|
195 | - { |
|
196 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
197 | - return true; |
|
198 | - } |
|
199 | - $form = apply_filters( |
|
200 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
201 | - $this->generate(), |
|
202 | - $this |
|
203 | - ); |
|
204 | - if ($this->verifyForm($form)) { |
|
205 | - $this->setForm($form); |
|
206 | - } |
|
207 | - return true; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param EE_Form_Section_Proper|null $form |
|
213 | - * @return bool |
|
214 | - * @throws LogicException |
|
215 | - */ |
|
216 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
217 | - { |
|
218 | - $form = $form !== null ? $form : $this->form; |
|
219 | - if ($form instanceof EE_Form_Section_Proper) { |
|
220 | - return true; |
|
221 | - } |
|
222 | - throw new LogicException( |
|
223 | - sprintf( |
|
224 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
225 | - $this->form_name, |
|
226 | - var_export($form, true) |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param EE_Form_Section_Proper $form |
|
234 | - */ |
|
235 | - public function setForm(EE_Form_Section_Proper $form) |
|
236 | - { |
|
237 | - $this->form = $form; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return boolean |
|
243 | - */ |
|
244 | - public function displayable() |
|
245 | - { |
|
246 | - return $this->displayable; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param boolean $displayable |
|
252 | - */ |
|
253 | - public function setDisplayable($displayable = false) |
|
254 | - { |
|
255 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * a public name for the form that can be displayed on the frontend of a site |
|
261 | - * |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public function formName() |
|
265 | - { |
|
266 | - return $this->form_name; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @param string $form_name |
|
272 | - * @throws InvalidDataTypeException |
|
273 | - */ |
|
274 | - public function setFormName($form_name) |
|
275 | - { |
|
276 | - if (! is_string($form_name)) { |
|
277 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
278 | - } |
|
279 | - $this->form_name = $form_name; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * a public name for the form that can be displayed, but only in the admin |
|
285 | - * |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function adminName() |
|
289 | - { |
|
290 | - return $this->admin_name; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $admin_name |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - */ |
|
298 | - public function setAdminName($admin_name) |
|
299 | - { |
|
300 | - if (! is_string($admin_name)) { |
|
301 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
302 | - } |
|
303 | - $this->admin_name = $admin_name; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * a URL friendly string that can be used for identifying the form |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function slug() |
|
313 | - { |
|
314 | - return $this->slug; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @param string $slug |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - */ |
|
322 | - public function setSlug($slug) |
|
323 | - { |
|
324 | - if (! is_string($slug)) { |
|
325 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
326 | - } |
|
327 | - $this->slug = $slug; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function submitBtnText() |
|
335 | - { |
|
336 | - return $this->submit_btn_text; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * @param string $submit_btn_text |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidArgumentException |
|
344 | - */ |
|
345 | - public function setSubmitBtnText($submit_btn_text) |
|
346 | - { |
|
347 | - if (! is_string($submit_btn_text)) { |
|
348 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
349 | - } |
|
350 | - if (empty($submit_btn_text)) { |
|
351 | - throw new InvalidArgumentException( |
|
352 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
353 | - ); |
|
354 | - } |
|
355 | - $this->submit_btn_text = $submit_btn_text; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - public function formAction() |
|
363 | - { |
|
364 | - return ! empty($this->form_args) |
|
365 | - ? add_query_arg($this->form_args, $this->form_action) |
|
366 | - : $this->form_action; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param string $form_action |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - */ |
|
374 | - public function setFormAction($form_action) |
|
375 | - { |
|
376 | - if (! is_string($form_action)) { |
|
377 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
378 | - } |
|
379 | - $this->form_action = $form_action; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @param array $form_args |
|
385 | - * @throws InvalidDataTypeException |
|
386 | - * @throws InvalidArgumentException |
|
387 | - */ |
|
388 | - public function addFormActionArgs($form_args = array()) |
|
389 | - { |
|
390 | - if (is_object($form_args)) { |
|
391 | - throw new InvalidDataTypeException( |
|
392 | - '$form_args', |
|
393 | - $form_args, |
|
394 | - 'anything other than an object was expected.' |
|
395 | - ); |
|
396 | - } |
|
397 | - if (empty($form_args)) { |
|
398 | - throw new InvalidArgumentException( |
|
399 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
400 | - ); |
|
401 | - } |
|
402 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public function formConfig() |
|
410 | - { |
|
411 | - return $this->form_config; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $form_config |
|
417 | - * @throws DomainException |
|
418 | - */ |
|
419 | - public function setFormConfig($form_config) |
|
420 | - { |
|
421 | - if (! in_array( |
|
422 | - $form_config, |
|
423 | - array( |
|
424 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
425 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
426 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
427 | - FormHandler::DO_NOT_SETUP_FORM, |
|
428 | - ), |
|
429 | - true |
|
430 | - ) |
|
431 | - ) { |
|
432 | - throw new DomainException( |
|
433 | - sprintf( |
|
434 | - esc_html__( |
|
435 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - $form_config |
|
439 | - ) |
|
440 | - ); |
|
441 | - } |
|
442 | - $this->form_config = $form_config; |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * called after the form is instantiated |
|
448 | - * and used for performing any logic that needs to occur early |
|
449 | - * before any of the other methods are called. |
|
450 | - * returns true if everything is ok to proceed, |
|
451 | - * and false if no further form logic should be implemented |
|
452 | - * |
|
453 | - * @return boolean |
|
454 | - */ |
|
455 | - public function initialize() |
|
456 | - { |
|
457 | - $this->form_has_errors = EE_Error::has_error(true); |
|
458 | - return true; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * used for setting up css and js |
|
464 | - * |
|
465 | - * @return void |
|
466 | - * @throws LogicException |
|
467 | - * @throws EE_Error |
|
468 | - */ |
|
469 | - public function enqueueStylesAndScripts() |
|
470 | - { |
|
471 | - $this->form()->enqueue_js(); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * creates and returns the actual form |
|
477 | - * |
|
478 | - * @return EE_Form_Section_Proper |
|
479 | - */ |
|
480 | - abstract public function generate(); |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
485 | - * |
|
486 | - * @param string $text |
|
487 | - * @return EE_Submit_Input |
|
488 | - */ |
|
489 | - public function generateSubmitButton($text = '') |
|
490 | - { |
|
491 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
492 | - return new EE_Submit_Input( |
|
493 | - array( |
|
494 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | - 'html_class' => 'ee-form-submit', |
|
497 | - 'html_label' => ' ', |
|
498 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
499 | - 'default' => $text, |
|
500 | - ) |
|
501 | - ); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
507 | - * |
|
508 | - * @param string $text |
|
509 | - * @return void |
|
510 | - * @throws EE_Error |
|
511 | - */ |
|
512 | - public function appendSubmitButton($text = '') |
|
513 | - { |
|
514 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
515 | - return; |
|
516 | - } |
|
517 | - $this->form->add_subsections( |
|
518 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | - null, |
|
520 | - false |
|
521 | - ); |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
527 | - * |
|
528 | - * @param string $text |
|
529 | - * @return EE_Submit_Input |
|
530 | - */ |
|
531 | - public function generateCancelButton($text = '') |
|
532 | - { |
|
533 | - $cancel_button = new EE_Submit_Input( |
|
534 | - array( |
|
535 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | - 'html_class' => 'ee-cancel-form', |
|
538 | - 'html_label' => ' ', |
|
539 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
540 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
541 | - ) |
|
542 | - ); |
|
543 | - $cancel_button->set_button_css_attributes(false); |
|
544 | - return $cancel_button; |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * appends a float clearing div onto end of form |
|
550 | - * |
|
551 | - * @return void |
|
552 | - * @throws EE_Error |
|
553 | - */ |
|
554 | - public function clearFormButtonFloats() |
|
555 | - { |
|
556 | - $this->form->add_subsections( |
|
557 | - array( |
|
558 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
559 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
560 | - ), |
|
561 | - ), |
|
562 | - null, |
|
563 | - false |
|
564 | - ); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
570 | - * returns a string of HTML that can be directly echoed in a template |
|
571 | - * |
|
572 | - * @return string |
|
573 | - * @throws \InvalidArgumentException |
|
574 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
575 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
576 | - * @throws LogicException |
|
577 | - * @throws EE_Error |
|
578 | - */ |
|
579 | - public function display() |
|
580 | - { |
|
581 | - $form_html = apply_filters( |
|
582 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
583 | - '' |
|
584 | - ); |
|
585 | - $form_config = $this->formConfig(); |
|
586 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
587 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
588 | - ) { |
|
589 | - if($this->requiresMultipartEnctype()){ |
|
590 | - $additional_props = 'enctype="multipart/form-data"'; |
|
591 | - } else { |
|
592 | - $additional_props = ''; |
|
593 | - } |
|
594 | - $form_html .= $this->form()->form_open( |
|
595 | - $this->formAction(), |
|
596 | - 'POST', |
|
597 | - $additional_props |
|
598 | - ); |
|
599 | - } |
|
600 | - $form_html .= $this->form(true)->get_html(); |
|
601 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
602 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
603 | - ) { |
|
604 | - $form_html .= $this->form()->form_close(); |
|
605 | - } |
|
606 | - $form_html .= apply_filters( |
|
607 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
608 | - '' |
|
609 | - ); |
|
610 | - return $form_html; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Determines if this form needs " |
|
615 | - * @since $VID:$ |
|
616 | - * @return bool |
|
617 | - * @throws EE_Error |
|
618 | - */ |
|
619 | - public function requiresMultipartEnctype() |
|
620 | - { |
|
621 | - foreach($this->form()->inputs_in_subsections() as $input){ |
|
622 | - if($input instanceof EE_File_Input){ |
|
623 | - return true; |
|
624 | - } |
|
625 | - } |
|
626 | - return false; |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * handles processing the form submission |
|
632 | - * returns true or false depending on whether the form was processed successfully or not |
|
633 | - * |
|
634 | - * @param array $submitted_form_data |
|
635 | - * @return array |
|
636 | - * @throws \InvalidArgumentException |
|
637 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
638 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
639 | - * @throws EE_Error |
|
640 | - * @throws LogicException |
|
641 | - * @throws InvalidFormSubmissionException |
|
642 | - */ |
|
643 | - public function process($submitted_form_data = array()) |
|
644 | - { |
|
645 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
646 | - throw new InvalidFormSubmissionException($this->form_name); |
|
647 | - } |
|
648 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
649 | - if (! $this->form()->is_valid()) { |
|
650 | - throw new InvalidFormSubmissionException( |
|
651 | - $this->form_name, |
|
652 | - sprintf( |
|
653 | - esc_html__( |
|
654 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
655 | - 'event_espresso' |
|
656 | - ), |
|
657 | - $this->form_name, |
|
658 | - '<br />', |
|
659 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
660 | - ) |
|
661 | - ); |
|
662 | - } |
|
663 | - return apply_filters( |
|
664 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
665 | - $this->form()->valid_data(), |
|
666 | - $this |
|
667 | - ); |
|
668 | - } |
|
32 | + /** |
|
33 | + * will add opening and closing HTML form tags as well as a submit button |
|
34 | + */ |
|
35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
36 | + |
|
37 | + /** |
|
38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
39 | + */ |
|
40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
41 | + |
|
42 | + /** |
|
43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
44 | + */ |
|
45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
46 | + |
|
47 | + /** |
|
48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
49 | + */ |
|
50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
51 | + |
|
52 | + /** |
|
53 | + * if set to false, then this form has no displayable content, |
|
54 | + * and will only be used for processing data sent passed via GET or POST |
|
55 | + * defaults to true ( ie: form has displayable content ) |
|
56 | + * |
|
57 | + * @var boolean $displayable |
|
58 | + */ |
|
59 | + private $displayable = true; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $form_name |
|
63 | + */ |
|
64 | + private $form_name; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $admin_name |
|
68 | + */ |
|
69 | + private $admin_name; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string $slug |
|
73 | + */ |
|
74 | + private $slug; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var string $submit_btn_text |
|
78 | + */ |
|
79 | + private $submit_btn_text; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var string $form_action |
|
83 | + */ |
|
84 | + private $form_action; |
|
85 | + |
|
86 | + /** |
|
87 | + * form params in key value pairs |
|
88 | + * can be added to form action URL or as hidden inputs |
|
89 | + * |
|
90 | + * @var array $form_args |
|
91 | + */ |
|
92 | + private $form_args = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * value of one of the string constant above |
|
96 | + * |
|
97 | + * @var string $form_config |
|
98 | + */ |
|
99 | + private $form_config; |
|
100 | + |
|
101 | + /** |
|
102 | + * whether or not the form was determined to be invalid |
|
103 | + * |
|
104 | + * @var boolean $form_has_errors |
|
105 | + */ |
|
106 | + private $form_has_errors; |
|
107 | + |
|
108 | + /** |
|
109 | + * the absolute top level form section being used on the page |
|
110 | + * |
|
111 | + * @var EE_Form_Section_Proper $form |
|
112 | + */ |
|
113 | + private $form; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var EE_Registry $registry |
|
117 | + */ |
|
118 | + protected $registry; |
|
119 | + |
|
120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
121 | + /** |
|
122 | + * Form constructor. |
|
123 | + * |
|
124 | + * @param string $form_name |
|
125 | + * @param string $admin_name |
|
126 | + * @param string $slug |
|
127 | + * @param string $form_action |
|
128 | + * @param string $form_config |
|
129 | + * @param EE_Registry $registry |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws DomainException |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $form_name, |
|
136 | + $admin_name, |
|
137 | + $slug, |
|
138 | + $form_action = '', |
|
139 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
140 | + EE_Registry $registry |
|
141 | + ) { |
|
142 | + $this->setFormName($form_name); |
|
143 | + $this->setAdminName($admin_name); |
|
144 | + $this->setSlug($slug); |
|
145 | + $this->setFormAction($form_action); |
|
146 | + $this->setFormConfig($form_config); |
|
147 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
148 | + $this->registry = $registry; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public static function getFormConfigConstants() |
|
156 | + { |
|
157 | + return array( |
|
158 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
159 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
160 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
161 | + FormHandler::DO_NOT_SETUP_FORM, |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param bool $for_display |
|
168 | + * @return EE_Form_Section_Proper |
|
169 | + * @throws EE_Error |
|
170 | + * @throws LogicException |
|
171 | + */ |
|
172 | + public function form($for_display = false) |
|
173 | + { |
|
174 | + if (! $this->formIsValid()) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + if ($for_display) { |
|
178 | + $form_config = $this->formConfig(); |
|
179 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
180 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
181 | + ) { |
|
182 | + $this->appendSubmitButton(); |
|
183 | + $this->clearFormButtonFloats(); |
|
184 | + } |
|
185 | + } |
|
186 | + return $this->form; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @return boolean |
|
192 | + * @throws LogicException |
|
193 | + */ |
|
194 | + public function formIsValid() |
|
195 | + { |
|
196 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
197 | + return true; |
|
198 | + } |
|
199 | + $form = apply_filters( |
|
200 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
201 | + $this->generate(), |
|
202 | + $this |
|
203 | + ); |
|
204 | + if ($this->verifyForm($form)) { |
|
205 | + $this->setForm($form); |
|
206 | + } |
|
207 | + return true; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param EE_Form_Section_Proper|null $form |
|
213 | + * @return bool |
|
214 | + * @throws LogicException |
|
215 | + */ |
|
216 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
217 | + { |
|
218 | + $form = $form !== null ? $form : $this->form; |
|
219 | + if ($form instanceof EE_Form_Section_Proper) { |
|
220 | + return true; |
|
221 | + } |
|
222 | + throw new LogicException( |
|
223 | + sprintf( |
|
224 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
225 | + $this->form_name, |
|
226 | + var_export($form, true) |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param EE_Form_Section_Proper $form |
|
234 | + */ |
|
235 | + public function setForm(EE_Form_Section_Proper $form) |
|
236 | + { |
|
237 | + $this->form = $form; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return boolean |
|
243 | + */ |
|
244 | + public function displayable() |
|
245 | + { |
|
246 | + return $this->displayable; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param boolean $displayable |
|
252 | + */ |
|
253 | + public function setDisplayable($displayable = false) |
|
254 | + { |
|
255 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * a public name for the form that can be displayed on the frontend of a site |
|
261 | + * |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public function formName() |
|
265 | + { |
|
266 | + return $this->form_name; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @param string $form_name |
|
272 | + * @throws InvalidDataTypeException |
|
273 | + */ |
|
274 | + public function setFormName($form_name) |
|
275 | + { |
|
276 | + if (! is_string($form_name)) { |
|
277 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
278 | + } |
|
279 | + $this->form_name = $form_name; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * a public name for the form that can be displayed, but only in the admin |
|
285 | + * |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function adminName() |
|
289 | + { |
|
290 | + return $this->admin_name; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $admin_name |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + */ |
|
298 | + public function setAdminName($admin_name) |
|
299 | + { |
|
300 | + if (! is_string($admin_name)) { |
|
301 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
302 | + } |
|
303 | + $this->admin_name = $admin_name; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * a URL friendly string that can be used for identifying the form |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function slug() |
|
313 | + { |
|
314 | + return $this->slug; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @param string $slug |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + */ |
|
322 | + public function setSlug($slug) |
|
323 | + { |
|
324 | + if (! is_string($slug)) { |
|
325 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
326 | + } |
|
327 | + $this->slug = $slug; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function submitBtnText() |
|
335 | + { |
|
336 | + return $this->submit_btn_text; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * @param string $submit_btn_text |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidArgumentException |
|
344 | + */ |
|
345 | + public function setSubmitBtnText($submit_btn_text) |
|
346 | + { |
|
347 | + if (! is_string($submit_btn_text)) { |
|
348 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
349 | + } |
|
350 | + if (empty($submit_btn_text)) { |
|
351 | + throw new InvalidArgumentException( |
|
352 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
353 | + ); |
|
354 | + } |
|
355 | + $this->submit_btn_text = $submit_btn_text; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + public function formAction() |
|
363 | + { |
|
364 | + return ! empty($this->form_args) |
|
365 | + ? add_query_arg($this->form_args, $this->form_action) |
|
366 | + : $this->form_action; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param string $form_action |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + */ |
|
374 | + public function setFormAction($form_action) |
|
375 | + { |
|
376 | + if (! is_string($form_action)) { |
|
377 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
378 | + } |
|
379 | + $this->form_action = $form_action; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @param array $form_args |
|
385 | + * @throws InvalidDataTypeException |
|
386 | + * @throws InvalidArgumentException |
|
387 | + */ |
|
388 | + public function addFormActionArgs($form_args = array()) |
|
389 | + { |
|
390 | + if (is_object($form_args)) { |
|
391 | + throw new InvalidDataTypeException( |
|
392 | + '$form_args', |
|
393 | + $form_args, |
|
394 | + 'anything other than an object was expected.' |
|
395 | + ); |
|
396 | + } |
|
397 | + if (empty($form_args)) { |
|
398 | + throw new InvalidArgumentException( |
|
399 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
400 | + ); |
|
401 | + } |
|
402 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public function formConfig() |
|
410 | + { |
|
411 | + return $this->form_config; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $form_config |
|
417 | + * @throws DomainException |
|
418 | + */ |
|
419 | + public function setFormConfig($form_config) |
|
420 | + { |
|
421 | + if (! in_array( |
|
422 | + $form_config, |
|
423 | + array( |
|
424 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
425 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
426 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
427 | + FormHandler::DO_NOT_SETUP_FORM, |
|
428 | + ), |
|
429 | + true |
|
430 | + ) |
|
431 | + ) { |
|
432 | + throw new DomainException( |
|
433 | + sprintf( |
|
434 | + esc_html__( |
|
435 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + $form_config |
|
439 | + ) |
|
440 | + ); |
|
441 | + } |
|
442 | + $this->form_config = $form_config; |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * called after the form is instantiated |
|
448 | + * and used for performing any logic that needs to occur early |
|
449 | + * before any of the other methods are called. |
|
450 | + * returns true if everything is ok to proceed, |
|
451 | + * and false if no further form logic should be implemented |
|
452 | + * |
|
453 | + * @return boolean |
|
454 | + */ |
|
455 | + public function initialize() |
|
456 | + { |
|
457 | + $this->form_has_errors = EE_Error::has_error(true); |
|
458 | + return true; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * used for setting up css and js |
|
464 | + * |
|
465 | + * @return void |
|
466 | + * @throws LogicException |
|
467 | + * @throws EE_Error |
|
468 | + */ |
|
469 | + public function enqueueStylesAndScripts() |
|
470 | + { |
|
471 | + $this->form()->enqueue_js(); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * creates and returns the actual form |
|
477 | + * |
|
478 | + * @return EE_Form_Section_Proper |
|
479 | + */ |
|
480 | + abstract public function generate(); |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
485 | + * |
|
486 | + * @param string $text |
|
487 | + * @return EE_Submit_Input |
|
488 | + */ |
|
489 | + public function generateSubmitButton($text = '') |
|
490 | + { |
|
491 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
492 | + return new EE_Submit_Input( |
|
493 | + array( |
|
494 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
496 | + 'html_class' => 'ee-form-submit', |
|
497 | + 'html_label' => ' ', |
|
498 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
499 | + 'default' => $text, |
|
500 | + ) |
|
501 | + ); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
507 | + * |
|
508 | + * @param string $text |
|
509 | + * @return void |
|
510 | + * @throws EE_Error |
|
511 | + */ |
|
512 | + public function appendSubmitButton($text = '') |
|
513 | + { |
|
514 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
515 | + return; |
|
516 | + } |
|
517 | + $this->form->add_subsections( |
|
518 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | + null, |
|
520 | + false |
|
521 | + ); |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
527 | + * |
|
528 | + * @param string $text |
|
529 | + * @return EE_Submit_Input |
|
530 | + */ |
|
531 | + public function generateCancelButton($text = '') |
|
532 | + { |
|
533 | + $cancel_button = new EE_Submit_Input( |
|
534 | + array( |
|
535 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
537 | + 'html_class' => 'ee-cancel-form', |
|
538 | + 'html_label' => ' ', |
|
539 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
540 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
541 | + ) |
|
542 | + ); |
|
543 | + $cancel_button->set_button_css_attributes(false); |
|
544 | + return $cancel_button; |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * appends a float clearing div onto end of form |
|
550 | + * |
|
551 | + * @return void |
|
552 | + * @throws EE_Error |
|
553 | + */ |
|
554 | + public function clearFormButtonFloats() |
|
555 | + { |
|
556 | + $this->form->add_subsections( |
|
557 | + array( |
|
558 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
559 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
560 | + ), |
|
561 | + ), |
|
562 | + null, |
|
563 | + false |
|
564 | + ); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
570 | + * returns a string of HTML that can be directly echoed in a template |
|
571 | + * |
|
572 | + * @return string |
|
573 | + * @throws \InvalidArgumentException |
|
574 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
575 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
576 | + * @throws LogicException |
|
577 | + * @throws EE_Error |
|
578 | + */ |
|
579 | + public function display() |
|
580 | + { |
|
581 | + $form_html = apply_filters( |
|
582 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
583 | + '' |
|
584 | + ); |
|
585 | + $form_config = $this->formConfig(); |
|
586 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
587 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
588 | + ) { |
|
589 | + if($this->requiresMultipartEnctype()){ |
|
590 | + $additional_props = 'enctype="multipart/form-data"'; |
|
591 | + } else { |
|
592 | + $additional_props = ''; |
|
593 | + } |
|
594 | + $form_html .= $this->form()->form_open( |
|
595 | + $this->formAction(), |
|
596 | + 'POST', |
|
597 | + $additional_props |
|
598 | + ); |
|
599 | + } |
|
600 | + $form_html .= $this->form(true)->get_html(); |
|
601 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
602 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
603 | + ) { |
|
604 | + $form_html .= $this->form()->form_close(); |
|
605 | + } |
|
606 | + $form_html .= apply_filters( |
|
607 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
608 | + '' |
|
609 | + ); |
|
610 | + return $form_html; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Determines if this form needs " |
|
615 | + * @since $VID:$ |
|
616 | + * @return bool |
|
617 | + * @throws EE_Error |
|
618 | + */ |
|
619 | + public function requiresMultipartEnctype() |
|
620 | + { |
|
621 | + foreach($this->form()->inputs_in_subsections() as $input){ |
|
622 | + if($input instanceof EE_File_Input){ |
|
623 | + return true; |
|
624 | + } |
|
625 | + } |
|
626 | + return false; |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * handles processing the form submission |
|
632 | + * returns true or false depending on whether the form was processed successfully or not |
|
633 | + * |
|
634 | + * @param array $submitted_form_data |
|
635 | + * @return array |
|
636 | + * @throws \InvalidArgumentException |
|
637 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
638 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
639 | + * @throws EE_Error |
|
640 | + * @throws LogicException |
|
641 | + * @throws InvalidFormSubmissionException |
|
642 | + */ |
|
643 | + public function process($submitted_form_data = array()) |
|
644 | + { |
|
645 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
646 | + throw new InvalidFormSubmissionException($this->form_name); |
|
647 | + } |
|
648 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
649 | + if (! $this->form()->is_valid()) { |
|
650 | + throw new InvalidFormSubmissionException( |
|
651 | + $this->form_name, |
|
652 | + sprintf( |
|
653 | + esc_html__( |
|
654 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
655 | + 'event_espresso' |
|
656 | + ), |
|
657 | + $this->form_name, |
|
658 | + '<br />', |
|
659 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
660 | + ) |
|
661 | + ); |
|
662 | + } |
|
663 | + return apply_filters( |
|
664 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
665 | + $this->form()->valid_data(), |
|
666 | + $this |
|
667 | + ); |
|
668 | + } |
|
669 | 669 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function form($for_display = false) |
173 | 173 | { |
174 | - if (! $this->formIsValid()) { |
|
174 | + if ( ! $this->formIsValid()) { |
|
175 | 175 | return null; |
176 | 176 | } |
177 | 177 | if ($for_display) { |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | public function setFormName($form_name) |
275 | 275 | { |
276 | - if (! is_string($form_name)) { |
|
276 | + if ( ! is_string($form_name)) { |
|
277 | 277 | throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
278 | 278 | } |
279 | 279 | $this->form_name = $form_name; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | public function setAdminName($admin_name) |
299 | 299 | { |
300 | - if (! is_string($admin_name)) { |
|
300 | + if ( ! is_string($admin_name)) { |
|
301 | 301 | throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
302 | 302 | } |
303 | 303 | $this->admin_name = $admin_name; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function setSlug($slug) |
323 | 323 | { |
324 | - if (! is_string($slug)) { |
|
324 | + if ( ! is_string($slug)) { |
|
325 | 325 | throw new InvalidDataTypeException('$slug', $slug, 'string'); |
326 | 326 | } |
327 | 327 | $this->slug = $slug; |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function setSubmitBtnText($submit_btn_text) |
346 | 346 | { |
347 | - if (! is_string($submit_btn_text)) { |
|
347 | + if ( ! is_string($submit_btn_text)) { |
|
348 | 348 | throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
349 | 349 | } |
350 | 350 | if (empty($submit_btn_text)) { |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function setFormAction($form_action) |
375 | 375 | { |
376 | - if (! is_string($form_action)) { |
|
376 | + if ( ! is_string($form_action)) { |
|
377 | 377 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
378 | 378 | } |
379 | 379 | $this->form_action = $form_action; |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function setFormConfig($form_config) |
420 | 420 | { |
421 | - if (! in_array( |
|
421 | + if ( ! in_array( |
|
422 | 422 | $form_config, |
423 | 423 | array( |
424 | 424 | FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | $text = ! empty($text) ? $text : $this->submitBtnText(); |
492 | 492 | return new EE_Submit_Input( |
493 | 493 | array( |
494 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
495 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
494 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
495 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
496 | 496 | 'html_class' => 'ee-form-submit', |
497 | 497 | 'html_label' => ' ', |
498 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
498 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
499 | 499 | 'default' => $text, |
500 | 500 | ) |
501 | 501 | ); |
@@ -511,11 +511,11 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public function appendSubmitButton($text = '') |
513 | 513 | { |
514 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
514 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
515 | 515 | return; |
516 | 516 | } |
517 | 517 | $this->form->add_subsections( |
518 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
518 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
519 | 519 | null, |
520 | 520 | false |
521 | 521 | ); |
@@ -532,11 +532,11 @@ discard block |
||
532 | 532 | { |
533 | 533 | $cancel_button = new EE_Submit_Input( |
534 | 534 | array( |
535 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
536 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
535 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
536 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
537 | 537 | 'html_class' => 'ee-cancel-form', |
538 | 538 | 'html_label' => ' ', |
539 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
539 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
540 | 540 | 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
541 | 541 | ) |
542 | 542 | ); |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | $this->form->add_subsections( |
557 | 557 | array( |
558 | 558 | 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
559 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
559 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
560 | 560 | ), |
561 | 561 | ), |
562 | 562 | null, |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
587 | 587 | || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
588 | 588 | ) { |
589 | - if($this->requiresMultipartEnctype()){ |
|
589 | + if ($this->requiresMultipartEnctype()) { |
|
590 | 590 | $additional_props = 'enctype="multipart/form-data"'; |
591 | 591 | } else { |
592 | 592 | $additional_props = ''; |
@@ -618,8 +618,8 @@ discard block |
||
618 | 618 | */ |
619 | 619 | public function requiresMultipartEnctype() |
620 | 620 | { |
621 | - foreach($this->form()->inputs_in_subsections() as $input){ |
|
622 | - if($input instanceof EE_File_Input){ |
|
621 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
622 | + if ($input instanceof EE_File_Input) { |
|
623 | 623 | return true; |
624 | 624 | } |
625 | 625 | } |
@@ -642,11 +642,11 @@ discard block |
||
642 | 642 | */ |
643 | 643 | public function process($submitted_form_data = array()) |
644 | 644 | { |
645 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
645 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
646 | 646 | throw new InvalidFormSubmissionException($this->form_name); |
647 | 647 | } |
648 | 648 | $this->form(true)->receive_form_submission($submitted_form_data); |
649 | - if (! $this->form()->is_valid()) { |
|
649 | + if ( ! $this->form()->is_valid()) { |
|
650 | 650 | throw new InvalidFormSubmissionException( |
651 | 651 | $this->form_name, |
652 | 652 | sprintf( |
@@ -13,41 +13,41 @@ |
||
13 | 13 | class EE_File_Normalization extends EE_Normalization_Strategy_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Convert the $_FILES inputted data into a well-defined object. |
|
18 | - * @param string $value_to_normalize |
|
19 | - * @return UploadedFile |
|
20 | - */ |
|
21 | - public function normalize($value_to_normalize) |
|
22 | - { |
|
23 | - if (is_array($value_to_normalize)) { |
|
24 | - return new UploadedFile($value_to_normalize); |
|
25 | - } elseif( $value_to_normalize instanceof UploadedFile){ |
|
26 | - return $value_to_normalize; |
|
27 | - } else { |
|
28 | - throw new EE_Validation_Error( |
|
29 | - esc_html__('The file input has an inavlid format.', 'event_espresso') |
|
30 | - ); |
|
31 | - } |
|
32 | - } |
|
16 | + /** |
|
17 | + * Convert the $_FILES inputted data into a well-defined object. |
|
18 | + * @param string $value_to_normalize |
|
19 | + * @return UploadedFile |
|
20 | + */ |
|
21 | + public function normalize($value_to_normalize) |
|
22 | + { |
|
23 | + if (is_array($value_to_normalize)) { |
|
24 | + return new UploadedFile($value_to_normalize); |
|
25 | + } elseif( $value_to_normalize instanceof UploadedFile){ |
|
26 | + return $value_to_normalize; |
|
27 | + } else { |
|
28 | + throw new EE_Validation_Error( |
|
29 | + esc_html__('The file input has an inavlid format.', 'event_espresso') |
|
30 | + ); |
|
31 | + } |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Convert the object back into a string of the filename. |
|
37 | - * |
|
38 | - * @param string $normalized_value |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function unnormalize($normalized_value) |
|
42 | - { |
|
43 | - if ($normalized_value instanceof UploadedFile) { |
|
44 | - // Leave it as the object, it can be treated like a string because it |
|
45 | - // overrides __toString() |
|
46 | - return $normalized_value; |
|
47 | - } elseif (is_array($normalized_value)) { |
|
48 | - return new UploadedFile($normalized_value); |
|
49 | - } else { |
|
50 | - return (string) $normalized_value; |
|
51 | - } |
|
52 | - } |
|
35 | + /** |
|
36 | + * Convert the object back into a string of the filename. |
|
37 | + * |
|
38 | + * @param string $normalized_value |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function unnormalize($normalized_value) |
|
42 | + { |
|
43 | + if ($normalized_value instanceof UploadedFile) { |
|
44 | + // Leave it as the object, it can be treated like a string because it |
|
45 | + // overrides __toString() |
|
46 | + return $normalized_value; |
|
47 | + } elseif (is_array($normalized_value)) { |
|
48 | + return new UploadedFile($normalized_value); |
|
49 | + } else { |
|
50 | + return (string) $normalized_value; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
22 | 22 | { |
23 | 23 | if (is_array($value_to_normalize)) { |
24 | 24 | return new UploadedFile($value_to_normalize); |
25 | - } elseif( $value_to_normalize instanceof UploadedFile){ |
|
25 | + } elseif ($value_to_normalize instanceof UploadedFile) { |
|
26 | 26 | return $value_to_normalize; |
27 | 27 | } else { |
28 | 28 | throw new EE_Validation_Error( |
@@ -10,20 +10,20 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_File_Input_Display_Strategy extends EE_Text_Input_Display_Strategy |
12 | 12 | { |
13 | - /** |
|
14 | - * The html "type" attribute value. default is "text" |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $allowed_extensions; |
|
13 | + /** |
|
14 | + * The html "type" attribute value. default is "text" |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $allowed_extensions; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @param string $allowed_extensions |
|
23 | - */ |
|
24 | - public function __construct($type = 'file', $allowed_extensions = []) |
|
25 | - { |
|
26 | - $this->allowed_extensions = $allowed_extensions; |
|
27 | - parent::__construct($type); |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param string $allowed_extensions |
|
23 | + */ |
|
24 | + public function __construct($type = 'file', $allowed_extensions = []) |
|
25 | + { |
|
26 | + $this->allowed_extensions = $allowed_extensions; |
|
27 | + parent::__construct($type); |
|
28 | + } |
|
29 | 29 | } |
@@ -13,58 +13,58 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * The html "type" attribute value. default is "text" |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $_type; |
|
16 | + /** |
|
17 | + * The html "type" attribute value. default is "text" |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $_type; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param string $allowed_extensions |
|
26 | - */ |
|
27 | - public function __construct($allowed_extensions = 'text') |
|
28 | - { |
|
29 | - $this->_type = $allowed_extensions; |
|
30 | - parent::__construct(); |
|
31 | - } |
|
24 | + /** |
|
25 | + * @param string $allowed_extensions |
|
26 | + */ |
|
27 | + public function __construct($allowed_extensions = 'text') |
|
28 | + { |
|
29 | + $this->_type = $allowed_extensions; |
|
30 | + parent::__construct(); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Gets the html "type" attribute's value |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function get_type() |
|
40 | - { |
|
41 | - if ($this->_type === 'email' |
|
42 | - && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false) |
|
43 | - ) { |
|
44 | - return 'text'; |
|
45 | - } |
|
46 | - return $this->_type; |
|
47 | - } |
|
35 | + /** |
|
36 | + * Gets the html "type" attribute's value |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function get_type() |
|
40 | + { |
|
41 | + if ($this->_type === 'email' |
|
42 | + && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false) |
|
43 | + ) { |
|
44 | + return 'text'; |
|
45 | + } |
|
46 | + return $this->_type; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * |
|
53 | - * @return string of html to display the field |
|
54 | - */ |
|
55 | - public function display() |
|
56 | - { |
|
57 | - $input = '<input type="'. $this->get_type() .'"'; |
|
58 | - $input .= ' name="' . $this->_input->html_name() . '"'; |
|
59 | - $input .= ' id="' . $this->_input->html_id() . '"'; |
|
60 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
61 | - $input .= ' class="' . $class . '"'; |
|
62 | - // add html5 required |
|
63 | - $input .= $this->_input->required() ? ' required' : ''; |
|
64 | - $input .= ' value="' . $this->_input->raw_value_in_form() . '"'; |
|
65 | - $input .= ' style="' . $this->_input->html_style() . '"'; |
|
66 | - $input .= $this->_input->other_html_attributes(); |
|
67 | - $input .= '/>'; |
|
68 | - return $input; |
|
69 | - } |
|
51 | + /** |
|
52 | + * |
|
53 | + * @return string of html to display the field |
|
54 | + */ |
|
55 | + public function display() |
|
56 | + { |
|
57 | + $input = '<input type="'. $this->get_type() .'"'; |
|
58 | + $input .= ' name="' . $this->_input->html_name() . '"'; |
|
59 | + $input .= ' id="' . $this->_input->html_id() . '"'; |
|
60 | + $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
61 | + $input .= ' class="' . $class . '"'; |
|
62 | + // add html5 required |
|
63 | + $input .= $this->_input->required() ? ' required' : ''; |
|
64 | + $input .= ' value="' . $this->_input->raw_value_in_form() . '"'; |
|
65 | + $input .= ' style="' . $this->_input->html_style() . '"'; |
|
66 | + $input .= $this->_input->other_html_attributes(); |
|
67 | + $input .= '/>'; |
|
68 | + return $input; |
|
69 | + } |
|
70 | 70 | } |