PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / libs / HTML / QuickForm2 / Element / InputFile.php
matomo / app / libs / HTML / QuickForm2 / Element Last commit date
Button.php 6 years ago Date.php 6 years ago Input.php 6 years ago InputButton.php 6 years ago InputCheckable.php 6 years ago InputCheckbox.php 6 years ago InputFile.php 6 years ago InputHidden.php 6 years ago InputImage.php 6 years ago InputPassword.php 6 years ago InputRadio.php 6 years ago InputReset.php 6 years ago InputSubmit.php 6 years ago InputText.php 6 years ago Select.php 6 years ago Static.php 6 years ago Textarea.php 6 years ago
InputFile.php
269 lines
1 <?php
2 /**
3 * Class for <input type="file" /> elements
4 *
5 * PHP version 5
6 *
7 * LICENSE:
8 *
9 * Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
10 * Bertrand Mansion <golgote@mamasam.com>
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * * The names of the authors may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
33 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * @category HTML
38 * @package HTML_QuickForm2
39 * @author Alexey Borzov <avb@php.net>
40 * @author Bertrand Mansion <golgote@mamasam.com>
41 * @license http://opensource.org/licenses/bsd-license.php New BSD License
42 * @version SVN: $Id: InputFile.php 300722 2010-06-24 10:15:52Z mansion $
43 * @link http://pear.php.net/package/HTML_QuickForm2
44 */
45
46 /**
47 * Base class for <input> elements
48 */
49 // require_once 'HTML/QuickForm2/Element/Input.php';
50
51 /**
52 * Class for <input type="file" /> elements
53 *
54 * @category HTML
55 * @package HTML_QuickForm2
56 * @author Alexey Borzov <avb@php.net>
57 * @author Bertrand Mansion <golgote@mamasam.com>
58 * @version Release: @package_version@
59 */
60 class HTML_QuickForm2_Element_InputFile extends HTML_QuickForm2_Element_Input
61 {
62 /**
63 * Default language for error messages
64 */
65 const DEFAULT_LANGUAGE = 'en';
66
67 /**
68 * Localized error messages for PHP's file upload errors
69 * @var array
70 */
71 protected $errorMessages = array(
72 'en' => array(
73 UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds size permitted by PHP configuration (%d bytes)',
74 UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive in HTML form (%d bytes)',
75 UPLOAD_ERR_PARTIAL => 'The file was only partially uploaded',
76 UPLOAD_ERR_NO_TMP_DIR => 'Server error: temporary directory is missing',
77 UPLOAD_ERR_CANT_WRITE => 'Server error: failed to write the file to disk',
78 UPLOAD_ERR_EXTENSION => 'File upload was stopped by extension'
79 ),
80 'fr' => array(
81 UPLOAD_ERR_INI_SIZE => 'Le fichier envoy&eacute; exc&egrave;de la taille autoris&eacute;e par la configuration de PHP (%d octets)',
82 UPLOAD_ERR_FORM_SIZE => 'Le fichier envoy&eacute; exc&egrave;de la taille de MAX_FILE_SIZE sp&eacute;cifi&eacute;e dans le formulaire HTML (%d octets)',
83 UPLOAD_ERR_PARTIAL => 'Le fichier n\'a &eacute;t&eacute; que partiellement t&eacute;l&eacute;charg&eacute;',
84 UPLOAD_ERR_NO_TMP_DIR => 'Erreur serveur: le r&eacute;pertoire temporaire est manquant',
85 UPLOAD_ERR_CANT_WRITE => 'Erreur serveur: &eacute;chec de l\'&eacute;criture du fichier sur le disque',
86 UPLOAD_ERR_EXTENSION => 'L\'envoi de fichier est arr&ecirc;t&eacute; par l\'extension'
87 ),
88 'ru' => array(
89 UPLOAD_ERR_INI_SIZE => '&#x420;&#x430;&#x437;&#x43c;&#x435;&#x440; &#x437;&#x430;&#x433;&#x440;&#x443;&#x436;&#x435;&#x43d;&#x43d;&#x43e;&#x433;&#x43e; &#x444;&#x430;&#x439;&#x43b;&#x430; &#x43f;&#x440;&#x435;&#x432;&#x43e;&#x441;&#x445;&#x43e;&#x434;&#x438;&#x442; &#x43c;&#x430;&#x43a;&#x441;&#x438;&#x43c;&#x430;&#x43b;&#x44c;&#x43d;&#x43e; &#x440;&#x430;&#x437;&#x440;&#x435;&#x448;&#x451;&#x43d;&#x43d;&#x44b;&#x439; &#x43d;&#x430;&#x441;&#x442;&#x440;&#x43e;&#x439;&#x43a;&#x430;&#x43c;&#x438; PHP (%d &#x431;&#x430;&#x439;&#x442;)',
90 UPLOAD_ERR_FORM_SIZE => '&#x420;&#x430;&#x437;&#x43c;&#x435;&#x440; &#x437;&#x430;&#x433;&#x440;&#x443;&#x436;&#x435;&#x43d;&#x43d;&#x43e;&#x433;&#x43e; &#x444;&#x430;&#x439;&#x43b;&#x430; &#x43f;&#x440;&#x435;&#x432;&#x43e;&#x441;&#x445;&#x43e;&#x434;&#x438;&#x442; &#x434;&#x438;&#x440;&#x435;&#x43a;&#x442;&#x438;&#x432;&#x443; MAX_FILE_SIZE, &#x443;&#x43a;&#x430;&#x437;&#x430;&#x43d;&#x43d;&#x443;&#x44e; &#x432; &#x444;&#x43e;&#x440;&#x43c;&#x435; (%d &#x431;&#x430;&#x439;&#x442;)',
91 UPLOAD_ERR_PARTIAL => '&#x424;&#x430;&#x439;&#x43b; &#x431;&#x44b;&#x43b; &#x437;&#x430;&#x433;&#x440;&#x443;&#x436;&#x435;&#x43d; &#x43d;&#x435; &#x43f;&#x43e;&#x43b;&#x43d;&#x43e;&#x441;&#x442;&#x44c;&#x44e;',
92 UPLOAD_ERR_NO_TMP_DIR => '&#x41e;&#x448;&#x438;&#x431;&#x43a;&#x430; &#x43d;&#x430; &#x441;&#x435;&#x440;&#x432;&#x435;&#x440;&#x435;: &#x43e;&#x442;&#x441;&#x443;&#x442;&#x441;&#x442;&#x432;&#x443;&#x435;&#x442; &#x43a;&#x430;&#x442;&#x430;&#x43b;&#x43e;&#x433; &#x434;&#x43b;&#x44f; &#x432;&#x440;&#x435;&#x43c;&#x435;&#x43d;&#x43d;&#x44b;&#x445; &#x444;&#x430;&#x439;&#x43b;&#x43e;&#x432;',
93 UPLOAD_ERR_CANT_WRITE => '&#x41e;&#x448;&#x438;&#x431;&#x43a;&#x430; &#x43d;&#x430; &#x441;&#x435;&#x440;&#x432;&#x435;&#x440;&#x435;: &#x43d;&#x435; &#x443;&#x434;&#x430;&#x43b;&#x43e;&#x441;&#x44c; &#x437;&#x430;&#x43f;&#x438;&#x441;&#x430;&#x442;&#x44c; &#x444;&#x430;&#x439;&#x43b; &#x43d;&#x430; &#x434;&#x438;&#x441;&#x43a;',
94 UPLOAD_ERR_EXTENSION => '&#x417;&#x430;&#x433;&#x440;&#x443;&#x437;&#x43a;&#x430; &#x444;&#x430;&#x439;&#x43b;&#x430; &#x431;&#x44b;&#x43b;&#x430; &#x43e;&#x441;&#x442;&#x430;&#x43d;&#x43e;&#x432;&#x43b;&#x435;&#x43d;&#x430; &#x440;&#x430;&#x441;&#x448;&#x438;&#x440;&#x435;&#x43d;&#x438;&#x435;&#x43c;'
95 )
96 );
97
98 /**
99 * Language to display error messages in
100 * @var string
101 */
102 protected $language;
103
104 /**
105 * Information on uploaded file, from submit data source
106 * @var array
107 */
108 protected $value = null;
109
110 protected $attributes = array('type' => 'file');
111
112
113 /**
114 * Class constructor
115 *
116 * Possible keys in $data array are:
117 * - 'language': language to display error messages in, it should either be
118 * already available in the class or provided in 'errorMessages'
119 * - 'errorMessages': an array of error messages with the following format
120 * <pre>
121 * 'language code 1' => array(
122 * UPLOAD_ERR_... => 'message',
123 * ...
124 * UPLOAD_ERR_... => 'message'
125 * ),
126 * ...
127 * 'language code N' => array(
128 * ...
129 * )
130 * </pre>
131 * Note that error messages for UPLOAD_ERR_INI_SIZE and UPLOAD_ERR_FORM_SIZE
132 * may contain '%d' placeholders that will be automatically replaced by the
133 * appropriate size limits. Note also that you don't need to provide messages
134 * for every possible error code in the arrays, you may e.g. override just
135 * one error message for a particular language.
136 *
137 * @param string Element name
138 * @param mixed Attributes (either a string or an array)
139 * @param array Data used to set up error messages for PHP's file
140 * upload errors.
141 */
142 public function __construct($name = null, $attributes = null, array $data = array())
143 {
144 if (isset($data['errorMessages'])) {
145 // neither array_merge() nor array_merge_recursive will do
146 foreach ($data['errorMessages'] as $lang => $ary) {
147 foreach ($ary as $code => $message) {
148 $this->errorMessages[$lang][$code] = $message;
149 }
150 }
151 unset($data['errorMessages']);
152 }
153 if (!isset($data['language'])) {
154 $this->language = self::DEFAULT_LANGUAGE;
155 } else {
156 $this->language = isset($this->errorMessages[$data['language']])?
157 $data['language']: self::DEFAULT_LANGUAGE;
158 unset($data['language']);
159 }
160 parent::__construct($name, $attributes, $data);
161 }
162
163
164 /**
165 * File upload elements cannot be frozen
166 *
167 * To properly "freeze" a file upload element one has to store the uploaded
168 * file somewhere and store the file info in session. This is way outside
169 * the scope of this class.
170 *
171 * @param bool Whether element should be frozen or editable. This
172 * parameter is ignored in case of file uploads
173 * @return bool Always returns false
174 */
175 public function toggleFrozen($freeze = null)
176 {
177 return false;
178 }
179
180 /**
181 * Returns the information on uploaded file
182 *
183 * @return array|null
184 */
185 public function getValue()
186 {
187 return $this->value;
188 }
189
190 /**
191 * File upload's value cannot be set here
192 *
193 * @param mixed Value for file element, this parameter is ignored
194 * @return HTML_QuickForm2_Element_InputFile
195 */
196 public function setValue($value)
197 {
198 return $this;
199 }
200
201 public function updateValue()
202 {
203 foreach ($this->getDataSources() as $ds) {
204 if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
205 $value = $ds->getUpload($this->getName());
206 if (null !== $value) {
207 $this->value = $value;
208 return;
209 }
210 }
211 }
212 $this->value = null;
213 }
214
215 /**
216 * Performs the server-side validation
217 *
218 * Before the Rules added to the element kick in, the element checks the
219 * error code added to the $_FILES array by PHP. If the code isn't
220 * UPLOAD_ERR_OK or UPLOAD_ERR_NO_FILE then a built-in error message will be
221 * displayed and no further validation will take place.
222 *
223 * @return boolean Whether the element is valid
224 */
225 protected function validate()
226 {
227 if (strlen($this->error)) {
228 return false;
229 }
230 if (isset($this->value['error']) &&
231 !in_array($this->value['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE)))
232 {
233 if (isset($this->errorMessages[$this->language][$this->value['error']])) {
234 $errorMessage = $this->errorMessages[$this->language][$this->value['error']];
235 } else {
236 $errorMessage = $this->errorMessages[self::DEFAULT_LANGUAGE][$this->value['error']];
237 }
238 if (UPLOAD_ERR_INI_SIZE == $this->value['error']) {
239 $iniSize = ini_get('upload_max_filesize');
240 $size = intval($iniSize);
241 switch (strtoupper(substr($iniSize, -1))) {
242 case 'G': $size *= 1024;
243 case 'M': $size *= 1024;
244 case 'K': $size *= 1024;
245 }
246
247 } elseif (UPLOAD_ERR_FORM_SIZE == $this->value['error']) {
248 foreach ($this->getDataSources() as $ds) {
249 if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
250 $size = intval($ds->getValue('MAX_FILE_SIZE'));
251 break;
252 }
253 }
254 }
255 $this->error = isset($size)? sprintf($errorMessage, $size): $errorMessage;
256 return false;
257 }
258 return parent::validate();
259 }
260
261 public function addFilter($callback, array $options = null, $recursive = true)
262 {
263 throw new HTML_QuickForm2_Exception(
264 'InputFile elements do not support filters'
265 );
266 }
267 }
268 ?>
269