PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.0
JetFormBuilder — Dynamic Blocks Form Builder v2.1.0
3.6.4 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 4 years ago file.php 4 years ago media-block-value.php 4 years ago sanitize-file-exception.php 4 years ago upload-dir.php 4 years ago upload-exception.php 4 years ago upload-permission-exception.php 4 years ago uploaded-collection.php 4 years ago uploaded-file-path.php 4 years ago uploaded-file.php 4 years ago
file.php
183 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Resources;
5
6 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
7
8 class File implements Arrayable, Media_Block_Value {
9
10 protected $error = 0;
11 protected $size = 0;
12 protected $name = '';
13 protected $tmp_name = '';
14 protected $type = '';
15
16 /**
17 * File constructor.
18 *
19 * @param array $file
20 *
21 * @throws Sanitize_File_Exception
22 */
23 public function __construct( array $file ) {
24 $this->set_error( $file['error'] );
25 $this->set_size( $file['size'] );
26 $this->set_name( $file['name'] );
27 $this->set_tmp_name( $file['tmp_name'] );
28 $this->set_type( $file['type'] );
29
30 $this->sanitize_filename();
31 }
32
33 /**
34 * @param mixed $error
35 *
36 * @return File
37 */
38 public function set_error( $error ): File {
39 $this->error = absint( $error );
40
41 return $this;
42 }
43
44 /**
45 * @param mixed $name
46 *
47 * @return File
48 */
49 public function set_name( $name ): File {
50 $this->name = sanitize_file_name( $name );
51
52 return $this;
53 }
54
55 /**
56 * @param mixed $size
57 *
58 * @return File
59 */
60 public function set_size( $size ): File {
61 $this->size = absint( $size );
62
63 return $this;
64 }
65
66 /**
67 * @param mixed $tmp_name
68 *
69 * @return File
70 */
71 public function set_tmp_name( $tmp_name ): File {
72 $this->tmp_name = $tmp_name;
73
74 return $this;
75 }
76
77 /**
78 * @param mixed $type
79 *
80 * @return File
81 */
82 public function set_type( $type ): File {
83 $this->type = sanitize_mime_type( $type );
84
85 return $this;
86 }
87
88 /**
89 * @return string
90 */
91 public function get_type(): string {
92 return $this->type;
93 }
94
95 /**
96 * @return int
97 */
98 public function get_error(): int {
99 return $this->error;
100 }
101
102 /**
103 * @return string
104 */
105 public function get_name(): string {
106 return $this->name;
107 }
108
109 /**
110 * @return int
111 */
112 public function get_size(): int {
113 return $this->size;
114 }
115
116 /**
117 * @return string
118 */
119 public function get_tmp_name(): string {
120 return $this->tmp_name;
121 }
122
123 /**
124 * @throws Sanitize_File_Exception
125 */
126 protected function sanitize_filename() {
127 require_once ABSPATH . 'wp-admin/includes/file.php';
128
129 $validate = wp_check_filetype_and_ext( $this->tmp_name, $this->name );
130
131 $ext = $validate['ext'] ?? false;
132 $type = $validate['type'] ?? false;
133 $proper_filename = $validate['proper_filename'] ?? false;
134
135 if ( $proper_filename ) {
136 $this->name = $proper_filename;
137 }
138
139 if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
140 throw new Sanitize_File_Exception( 'Incorrect extension or mime type' );
141 }
142 }
143
144 /**
145 * @return array
146 */
147 public function to_array(): array {
148 return array(
149 'name' => $this->get_name(),
150 'type' => $this->get_type(),
151 'size' => $this->get_size(),
152 'error' => $this->get_error(),
153 'tmp_name' => $this->get_tmp_name(),
154 );
155 }
156
157 /*
158 * Realisation of
159 * \Jet_Form_Builder\Classes\Resources\Media_Block_Value
160 */
161
162 /**
163 * @return string
164 */
165 public function get_attachment_id(): string {
166 return '';
167 }
168
169 /**
170 * @return string
171 */
172 public function get_attachment_url(): string {
173 return $this->get_tmp_name();
174 }
175
176 /**
177 * @return array
178 */
179 public function get_attachment_both(): array {
180 return array();
181 }
182 }
183