PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.9
JetFormBuilder — Dynamic Blocks Form Builder v3.1.9
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / classes / resources / file.php
jetformbuilder / includes / classes / resources Last commit date
file-collection.php 2 years ago file-tools.php 2 years ago file.php 2 years ago has-error-file.php 2 years ago media-block-value.php 2 years ago sanitize-file-exception.php 2 years ago upload-dir.php 2 years ago upload-exception.php 2 years ago upload-permission-exception.php 2 years ago uploaded-collection.php 2 years ago uploaded-file-path.php 2 years ago uploaded-file.php 2 years ago
file.php
194 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Resources;
5
6 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 class File implements Arrayable, Media_Block_Value, Has_Error_File {
14
15 protected $error = 0;
16 protected $size = 0;
17 protected $name = '';
18 protected $tmp_name = '';
19 protected $type = '';
20
21 /**
22 * File constructor.
23 *
24 * @param array $file
25 *
26 * @throws Sanitize_File_Exception
27 */
28 public function __construct( array $file ) {
29 $this->set_error( $file['error'] );
30 $this->set_size( $file['size'] );
31 $this->set_name( $file['name'] );
32 $this->set_tmp_name( $file['tmp_name'] );
33 $this->set_type( $file['type'] );
34
35 $this->sanitize_filename();
36 }
37
38 /**
39 * @param mixed $error
40 *
41 * @return File
42 */
43 public function set_error( $error ): File {
44 $this->error = absint( $error );
45
46 return $this;
47 }
48
49 /**
50 * @param mixed $name
51 *
52 * @return File
53 */
54 public function set_name( $name ): File {
55 $this->name = sanitize_file_name( $name );
56
57 return $this;
58 }
59
60 /**
61 * @param mixed $size
62 *
63 * @return File
64 */
65 public function set_size( $size ): File {
66 $this->size = absint( $size );
67
68 return $this;
69 }
70
71 /**
72 * @param mixed $tmp_name
73 *
74 * @return File
75 */
76 public function set_tmp_name( $tmp_name ): File {
77 $this->tmp_name = $tmp_name;
78
79 return $this;
80 }
81
82 /**
83 * @param mixed $type
84 *
85 * @return File
86 */
87 public function set_type( $type ): File {
88 $this->type = sanitize_mime_type( $type );
89
90 return $this;
91 }
92
93 /**
94 * @return string
95 */
96 public function get_type(): string {
97 return $this->type;
98 }
99
100 /**
101 * @return int
102 */
103 public function get_error(): int {
104 return $this->error;
105 }
106
107 /**
108 * @return string
109 */
110 public function get_name(): string {
111 return $this->name;
112 }
113
114 /**
115 * @return int
116 */
117 public function get_size(): int {
118 return $this->size;
119 }
120
121 /**
122 * @return string
123 */
124 public function get_tmp_name(): string {
125 return $this->tmp_name;
126 }
127
128 /**
129 * @throws Sanitize_File_Exception
130 */
131 protected function sanitize_filename() {
132 require_once ABSPATH . 'wp-admin/includes/file.php';
133
134 $validate = wp_check_filetype_and_ext( $this->tmp_name, $this->name );
135
136 $ext = $validate['ext'] ?? false;
137 $type = $validate['type'] ?? false;
138 $proper_filename = $validate['proper_filename'] ?? false;
139
140 if ( $proper_filename ) {
141 $this->name = $proper_filename;
142 }
143
144 if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
145 throw new Sanitize_File_Exception( 'Incorrect extension or mime type' );
146 }
147
148 $this->type = $type;
149 }
150
151 /**
152 * @return array
153 */
154 public function to_array(): array {
155 return array(
156 'name' => $this->get_name(),
157 'type' => $this->get_type(),
158 'size' => $this->get_size(),
159 'error' => $this->get_error(),
160 'tmp_name' => $this->get_tmp_name(),
161 );
162 }
163
164 /*
165 * Realisation of
166 * \Jet_Form_Builder\Classes\Resources\Media_Block_Value
167 */
168
169 /**
170 * @return string
171 */
172 public function get_attachment_id(): string {
173 return '';
174 }
175
176 /**
177 * @return string
178 */
179 public function get_attachment_url(): string {
180 return $this->get_tmp_name();
181 }
182
183 /**
184 * @return array
185 */
186 public function get_attachment_both(): array {
187 return array();
188 }
189
190 public function has_error(): bool {
191 return 0 < $this->get_error();
192 }
193 }
194