PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.16.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.16.2
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Core/Util/FileHandler.php +24 -4 2.10.22.16.2 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace BitCode\BitForm\Core\Util;
4 4
5 5 use BitCode\BitForm\Core\Form\FormManager;
6 +use BitCode\BitForm\enshrined\svgSanitize\Sanitizer;
6 7
7 8 final class FileHandler
8 9 {
9 10 public function rmrf($dir)
@@ -14,15 +15,15 @@
14 15 if ('.' !== $object && '..' !== $object) {
15 16 if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . DIRECTORY_SEPARATOR . $object)) {
16 17 $this->rmrf($dir . DIRECTORY_SEPARATOR . $object);
17 18 } else {
18 - unlink($dir . DIRECTORY_SEPARATOR . $object);
19 + wp_delete_file($dir . DIRECTORY_SEPARATOR . $object);
19 20 }
20 21 }
21 22 }
22 23 rmdir($dir);
23 24 } else {
24 - unlink($dir);
25 + wp_delete_file($dir);
25 26 }
26 27 }
27 28
28 29 public function cpyr($source, $destination)
@@ -98,9 +99,9 @@
98 99 public function deleteFiles($form_id, $entry_id, $files)
99 100 {
100 101 $_upload_dir = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $form_id . DIRECTORY_SEPARATOR . $entry_id;
101 102 foreach ($files as $name) {
102 - unlink($_upload_dir . DIRECTORY_SEPARATOR . $name);
103 + wp_delete_file($_upload_dir . DIRECTORY_SEPARATOR . $name);
103 104 }
104 105 }
105 106
106 107 public static function getFileUploadError($code)
@@ -283,9 +284,9 @@
283 284
284 285 return $errorMessage;
285 286 }
286 287
287 - private function validateSingleFile($fieldType, $file, $allowTypes, $maxSize = null)
288 + private function validateSingleFile($fieldType, &$file, $allowTypes, $maxSize = null)
288 289 {
289 290 $fileName = sanitize_file_name($file['name']);
290 291 if (!empty($fileName)) {
291 292 $fileSize = $file['size'];
@@ -312,7 +313,26 @@
312 313 'message' => __(($fileExtension ? ".{$fileExtension}" : 'empty') . ' file extension is not allowed', 'bit-form'),
313 314 'error_type'=> 'file_type_error',
314 315 ];
315 316 }
317 + if ('svg' === $fileExtension) {
318 + $svg_sanitizer = new Sanitizer();
319 + $dirty_svg = file_get_contents($file['tmp_name']);
320 + $clean_svg = $svg_sanitizer->sanitize($dirty_svg);
321 + if (false === $clean_svg) {
322 + return [
323 + 'message' => __('SVG file is not valid', 'bit-form'),
324 + 'error_type'=> 'file_type_error',
325 + ];
326 + }
327 + file_put_contents($file['tmp_name'], $clean_svg);
328 + }
329 + }
330 + }
331 +
332 + public static function deleteIsFileExists($path)
333 + {
334 + if (file_exists($path)) {
335 + wp_delete_file($path);
316 336 }
317 337 }
318 338 }