Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fileinput.php
1<?php
2
3namespace Bitrix\Main\UI;
7
8Loc::loadMessages(__FILE__);
9
11{
12 public const UPLOAD_IMAGES = 'I';
13 public const UPLOAD_EXTENTION_LIST = 'F';
14 public const UPLOAD_ANY_FILES = 'A';
15
16 protected $elementSetts = array(
17 "name" => "FILE[n#IND#]",
18 "description" => true,
19 "delete" => true,
20 "edit" => true,
21 "thumbSize" => 640
22 );
23 protected $uploadSetts = array(
24 "upload" => false,
25 "uploadType" => "path",
26 "medialib" => false,
27 "fileDialog" => false,
28 "cloud" => false,
29 "maxCount" => 0,
30 "maxSize" => 0
31 );
32 protected $id = "bx_iblockfileprop";
33 protected $files = array();
34 protected static $instance = null;
35 protected $templates = array();
36
37 public static $templatePatterns = array(
38 'description' => <<<HTML
39 <input type="text" id="#id#Description" name="#description_name#" value="#description#" class="adm-fileinput-item-description" />
40HTML
41 ,
42 'regularInput' => '<input class="bx-bxu-fileinput-value" type="hidden" id="#id#Value" name="#input_name#" value="#input_value#" />',
43 'arrayInput' => <<<HTML
44 <input type="hidden" id="#id#Value" name="#input_name#[tmp_name]" value="#input_value#" />
45 <input type="hidden" name="#input_name#[type]" value="#type#" />
46 <input type="hidden" name="#input_name#[name]" value="#name#" />
47 <input type="hidden" name="#input_name#[size]" value="#size#" />
48 <input type="hidden" name="#input_name#[error]" value="0" />
49HTML
50 ,
51 'new' => <<<HTML
52 <div class="adm-fileinput-item">
53 <div class="adm-fileinput-item-preview">
54 <span class="adm-fileinput-item-loading">
55 <span class="container-loading-title">#MESS_LOADING#</span>
56 <span class="container-loading-bg"><span class="container-loading-bg-progress" style="width: 5%;" id="#id#Progress"></span></span>
57 </span>
58 <div class="adm-fileinput-item-preview-icon">
59 <div class="bx-file-icon-container-medium icon-#ext#">
60 <div class="bx-file-icon-cover">
61 <div class="bx-file-icon-corner">
62 <div class="bx-file-icon-corner-fix"></div>
63 </div>
64 <div class="bx-file-icon-images"></div>
65 </div>
66 <div class="bx-file-icon-label"></div>
67 </div>
68 <span class="container-doc-title" id="#id#Name">#name#</span>
69 </div>
70 <div class="adm-fileinput-item-preview-img">#preview#</div>
71 <input class="bx-bxu-fileinput-value" type="hidden" id="#id#Value" name="#input_name#" value="#input_value#" />
72 </div>
73 #description#
74 <div class="adm-fileinput-item-panel">
75 <span class="adm-fileinput-item-panel-btn adm-btn-setting" id="#id#Edit">&nbsp;</span>
76 <span class="adm-fileinput-item-panel-btn adm-btn-del" id="#id#Del">&nbsp;</span>
77 </div>
78 <div id="#id#Properties" class="adm-fileinput-item-properties">#properties#</div>
79 </div>
80HTML
81 ,
82 'unsaved' => <<<HTML
83<div class="adm-fileinput-item-wrapper" id="#id#Block">
84 <div class="adm-fileinput-item">
85 <div class="adm-fileinput-item-preview">
86 <span class="adm-fileinput-item-loading">
87 <span class="container-loading-title">#MESS_LOADING#</span>
88 <span class="container-loading-bg"><span class="container-loading-bg-progress" style="width: 60%;" id="#id#Progress"></span></span>
89 </span>
90 <div class="adm-fileinput-item-preview-icon">
91 <div class="bx-file-icon-container-medium icon-#ext#">
92 <div class="bx-file-icon-cover">
93 <div class="bx-file-icon-corner">
94 <div class="bx-file-icon-corner-fix"></div>
95 </div>
96 <div class="bx-file-icon-images"></div>
97 </div>
98 <div class="bx-file-icon-label"></div>
99 </div>
100 <span class="container-doc-title" id="#id#Name">#name#</span>
101 </div>
102 <div class="adm-fileinput-item-preview-img" id="#id#Canvas"></div>
103 #input#
104 </div>
105 #description#
106 <div class="adm-fileinput-item-panel">
107 <span class="adm-fileinput-item-panel-btn adm-btn-setting" id="#id#Edit">&nbsp;</span>
108 <span class="adm-fileinput-item-panel-btn adm-btn-del" id="#id#Del">&nbsp;</span>
109 </div>
110 <div id="#id#Properties" class="adm-fileinput-item-properties">#properties#</div>
111 </div>
112</div>
113HTML
114 ,
121 'uploaded' => <<<HTML
122<div class="adm-fileinput-item-wrapper" id="#id#Block">
123 <div class="adm-fileinput-item adm-fileinput-item-saved">
124 <div class="adm-fileinput-item-preview">
125 <span class="adm-fileinput-item-loading">
126 <span class="container-loading-title">#MESS_LOADING#</span>
127 <span class="container-loading-bg"><span class="container-loading-bg-progress" style="width: 60%;"></span></span>
128 </span>
129 <div class="adm-fileinput-item-preview-icon">
130 <div class="bx-file-icon-container-medium icon-#ext#">
131 <div class="bx-file-icon-cover">
132 <div class="bx-file-icon-corner">
133 <div class="bx-file-icon-corner-fix"></div>
134 </div>
135 <div class="bx-file-icon-images"></div>
136 </div>
137 <div class="bx-file-icon-label"></div>
138 </div>
139 <span class="container-doc-title" id="#id#Name">#name#</span>
140 </div>
141 <div class="adm-fileinput-item-preview-img" id="#id#Canvas"></div>
142 <input style="display: none;" type="hidden" id="#id#Value" readonly="readonly" name="#input_name#" value="#input_value#" />
143 </div>
144 #description#
145 <div class="adm-fileinput-item-panel">
146 <span class="adm-fileinput-item-panel-btn adm-btn-setting" id="#id#Edit">&nbsp;</span>
147 <span class="adm-fileinput-item-panel-btn adm-btn-del" id="#id#Del">&nbsp;</span>
148 </div>
149 <div id="#id#Properties" class="adm-fileinput-item-properties">#properties#</div>
150 </div>
151</div>
152HTML
153 ,
154 'unexisted' => <<<HTML
155<div class="adm-fileinput-item-wrapper" id="#id#Block">
156 <div class="adm-fileinput-item adm-fileinput-item-saved">
157 <div class="adm-fileinput-item-preview">
158 <span class="adm-fileinput-item-loading">
159 <span class="container-loading-title">#MESS_LOADING#</span>
160 <span class="container-loading-bg"><span class="container-loading-bg-progress" style="width: 60%;"></span></span>
161 </span>
162 <div class="adm-fileinput-item-preview-icon">
163 <div class="bx-file-icon-container-medium icon-#ext#">
164 <div class="bx-file-icon-cover">
165 <div class="bx-file-icon-corner">
166 <div class="bx-file-icon-corner-fix"></div>
167 </div>
168 <div class="bx-file-icon-images"></div>
169 </div>
170 <div class="bx-file-icon-label"></div>
171 </div>
172 <span class="container-doc-title" id="#id#Name">#name#</span>
173 </div>
174 <div class="adm-fileinput-item-preview-img" id="#id#Canvas"></div>
175 <input style="display: none;" data-fileinput="Y" type="file" id="#id#Value" readonly="readonly" name="#input_name#" value="" />
176 </div>
177 #description#
178 <div class="adm-fileinput-item-panel">
179 <span class="adm-fileinput-item-panel-btn adm-btn-del" id="#id#Del">&nbsp;</span>
180 </div>
181 <div id="#id#Properties" class="adm-fileinput-item-properties">#properties#</div>
182 </div>
183</div>
184HTML
185);
189 public function __construct($params = array())
190 {
191 global $USER;
192 $inputs = array_merge($this->elementSetts, $params);
193 $this->elementSetts = array(
194 "name" => $inputs["name"],
195 "description" => !empty($inputs["description"]),
196 "delete" => $inputs['delete'] !== false,
197 "edit" => $inputs['edit'] !== false,
198 "thumbSize" => 640,
199 //"properties" => (is_array($inputs) ? $inputs : array()) //TODO It is needed to deal with additional properties
200 );
201 if (isset($params['id']))
202 $this->elementSetts['id'] = $params['id'];
203 $replace = array(
204 "/\\#MESS_LOADING\\#/" => Loc::getMessage("BXU_LoadingProcess"),
205 "/\\#description\\#/" => ($this->elementSetts["edit"] == true && $this->elementSetts["description"] == true ? self::$templatePatterns["description"] : ""),
206 "/\\#properties\\#/" => "",
207 "/[\n\t]+/" => ""
208 );
209 $this->templates["uploaded"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["uploaded"]);
210 $this->templates["unexisted"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["unexisted"]);
211 $this->templates["new"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["new"]);
212 $this->templates["unsaved"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["unsaved"]);
213 $replace = array(
214 "#input_name#" => $inputs["name"],
215 "#input_value#" => "",
216 "#description_name#" => self::getInputName($inputs["name"], "_descr")
217 );
218 $this->templates["new"] = str_replace(array_keys($replace), array_values($replace), $this->templates["new"]);
219
220 $this->templates["unsavedArray"] = str_replace("#input#", self::$templatePatterns["arrayInput"], $this->templates["unsaved"]);
221 $this->templates["unsaved"] = str_replace("#input#", self::$templatePatterns["regularInput"], $this->templates["unsaved"]);
222
223 $inputs = array_merge($this->uploadSetts, $params);
224
225 $this->uploadSetts = array(
226 "upload" => '',
227 "uploadType" => "path",
228 "medialib" =>
229 isset($inputs['medialib'])
230 && $inputs['medialib'] === true
231 && \COption::GetOptionString('fileman', "use_medialib", "Y") != "N"
232 ,
233 "fileDialog" =>
234 (isset($inputs['file_dialog']) && $inputs['file_dialog'] === true)
235 || (isset($inputs['fileDialog']) && $inputs['fileDialog'] === true)
236 ,
237 "cloud" =>
238 isset($inputs['cloud'])
239 && $inputs['cloud'] === true
240 && $USER->CanDoOperation("clouds_browse")
241 && \CModule::IncludeModule("clouds")
242 && \CCloudStorage::HasActiveBuckets()
243 ,
244 "maxCount" => isset($params["maxCount"]) && $params["maxCount"] > 0 ? $params["maxCount"] : 0,
245 "maxSize" => isset($params["maxSize"]) && $params["maxSize"] > 0 ? $params["maxSize"] : 0,
246 "allowUpload" => $params["allowUpload"] ?? self::UPLOAD_ANY_FILES,
247 "allowUploadExt" => trim($params["allowUploadExt"] ?? ''),
248 "allowSort" => isset($params["allowSort"]) && $params["allowSort"] === "N" ? "N" : "Y",
249 );
250 if (!in_array(
251 $this->uploadSetts["allowUpload"],
252 [
253 self::UPLOAD_ANY_FILES,
254 self::UPLOAD_IMAGES,
255 self::UPLOAD_EXTENTION_LIST,
256 ]
257 ))
258 {
259 $this->uploadSetts["allowUpload"] = self::UPLOAD_ANY_FILES;
260 }
261 if ($this->uploadSetts["medialib"] === true)
262 $this->uploadSetts["medialib"] = (\Bitrix\Main\Loader::includeModule("fileman") && \CMedialib::CanDoOperation('medialib_view_collection', 0));
263 if($this->uploadSetts["fileDialog"] === true && !$USER->CanDoOperation('fileman_view_file_structure'))
264 $this->uploadSetts["fileDialog"] = false;
265
266 if (empty($this->uploadSetts["allowUploadExt"]) && $this->uploadSetts["allowUpload"] === self::UPLOAD_EXTENTION_LIST)
267 $this->uploadSetts["allowUpload"] = self::UPLOAD_ANY_FILES;
268 if (isset($this->elementSetts["id"]))
269 $this->id = 'bx_file_'.mb_strtolower(preg_replace("/[^a-z0-9]/i", "_", $this->elementSetts["id"]));
270 else
271 $this->id = 'bx_file_'.mb_strtolower(preg_replace("/[^a-z0-9]/i", "_", $this->elementSetts["name"]));
272
273 if ($inputs['upload'] === true)
274 {
275 $this->uploadSetts['upload'] = FileInputReceiver::sign(array(
276 "id" => ($inputs['uploadType'] === "hash" ? "hash" : "path"),
277 "allowUpload" => $this->uploadSetts["allowUpload"],
278 "allowUploadExt" => $this->uploadSetts["allowUploadExt"]
279 ));
280 $this->uploadSetts['uploadType'] = (in_array($inputs["uploadType"], array(/*"file",*/ "hash", "path")) ? $inputs["uploadType"] : "path");
281 }
282 self::$instance = $this;
283 }
284
290 public static function createInstance($params = array(), $hashIsID = true)
291 {
292 $c = __CLASS__;
293 return new $c($params, $hashIsID);
294 }
295
300 public function show($values = array(), $getDataFromRequest = false)
301 {
302 \CJSCore::Init(array('fileinput'));
303
304 $files = '';
305 if (!is_array($values) || array_key_exists("tmp_name", $values))
306 {
307 $values = array($this->elementSetts["name"] => $values);
308 }
309 $maxIndex = 0;
310 $pattMaxIndex = mb_strpos($this->elementSetts["name"], "#IND#") > 0 ? str_replace("#IND#", "(\\d+)", preg_quote($this->elementSetts["name"])) : null;
311 foreach($values as $inputName => $fileId)
312 {
313 if ($pattMaxIndex && preg_match("/".$pattMaxIndex."/", $inputName, $matches))
314 {
315 $maxIndex = max($maxIndex, intval($matches[1]));
316 }
317 if ($res = $this->getFile($fileId, $inputName, $getDataFromRequest))
318 {
319 $t = (isset($res["fileId"]) && $res["fileId"] > 0 ? $this->templates["uploaded"] : (is_array($fileId) ? $this->templates["unsavedArray"] : $this->templates["unsaved"]));
320 if (!is_array($res))
321 {
322 $res = $this->formFile($fileId, $inputName);
323 $t = $this->templates["unexisted"];
324 }
325 $patt = array();
326 foreach ($res as $pat => $rep)
327 {
328 $patt["#".$pat."#"] = htmlspecialcharsbx($rep);
329 }
330 if (array_key_exists("#description#", $patt) && strpos($patt["#description#"], "&amp;quot;") !== false)
331 {
332 $patt["#description#"] = str_replace("&amp;quot;", "&quot;", $patt["#description#"]);
333 }
334 $files .= str_ireplace(array_keys($patt), array_values($patt), $t);
335 $this->files[] = $res;
336 }
337 }
338
339 $canDelete = true ? '' : 'adm-fileinput-non-delete'; // In case we can not delete files
340 $canEdit = ($this->elementSetts["edit"] ? '' : 'adm-fileinput-non-edit');
341
342 $settings = \CUserOptions::GetOption('main', 'fileinput');
343 $settings = (is_array($settings) ? $settings : array(
344 "frameFiles" => "N",
345 "pinDescription" => "N",
346 "mode" => "mode-pict",
347 "presets" => array(
348 array("width" => 200, "height" => 200, "title" => "200x200")
349 ),
350 "presetActive" => 0
351 ));
352
353 if ($this->uploadSetts["maxCount"] == 1)
354 {
355 if ($this->uploadSetts["allowUpload"] === self::UPLOAD_IMAGES)
356 $hintMessage = Loc::getMessage("BXU_DNDMessage01");
357 else if ($this->uploadSetts["allowUpload"] === self::UPLOAD_EXTENTION_LIST)
358 $hintMessage = Loc::getMessage("BXU_DNDMessage02", array("#ext#" => htmlspecialcharsbx($this->uploadSetts["allowUploadExt"])));
359 else
360 $hintMessage = Loc::getMessage("BXU_DNDMessage03");
361
362 if ($this->uploadSetts["maxSize"] > 0)
363 $hintMessage .= Loc::getMessage("BXU_DNDMessage04", array("#size#" => \CFile::FormatSize($this->uploadSetts["maxSize"])));
364 }
365 else
366 {
367 $maxCount = ($this->uploadSetts["maxCount"] > 0 ? GetMessage("BXU_DNDMessage5", array("#maxCount#" => htmlspecialcharsbx($this->uploadSetts["maxCount"]))) : "");
368 if ($this->uploadSetts["allowUpload"] === self::UPLOAD_IMAGES)
369 $hintMessage = Loc::getMessage("BXU_DNDMessage1", array("#maxCount#" => $maxCount));
370 else if ($this->uploadSetts["allowUpload"] == self::UPLOAD_EXTENTION_LIST)
371 $hintMessage = Loc::getMessage("BXU_DNDMessage2", array("#ext#" => htmlspecialcharsbx($this->uploadSetts["allowUploadExt"]), "#maxCount#" => $maxCount));
372 else
373 $hintMessage = Loc::getMessage("BXU_DNDMessage3", array("#maxCount#" => $maxCount));
374 if ($this->uploadSetts["maxSize"] > 0)
375 $hintMessage .= Loc::getMessage("BXU_DNDMessage4", array("#size#" => \CFile::FormatSize($this->uploadSetts["maxSize"])));
376 }
377
378 $this->getExtDialogs();
379
380 $uploadSetts = $this->uploadSetts + $settings;
381 if (array_key_exists("presets", $settings))
382 {
383 $uploadSetts["presets"] = $settings["presets"];
384 $uploadSetts["presetActive"] = $settings["presetActive"];
385 }
386 $uploadSetts["maxIndex"] = $maxIndex;
387 $template = \CUtil::JSEscape($this->templates["new"]);
388 $classSingle = (array_key_exists("maxCount", $uploadSetts) && intval($uploadSetts["maxCount"]) == 1 ? "adm-fileinput-wrapper-single" : "");
389 $uploadSetts = \CUtil::PhpToJSObject($uploadSetts);
390 $elementSetts = \CUtil::PhpToJSObject($this->elementSetts);
391 $values = \CUtil::PhpToJSObject($this->files);
392 $mes = array(
393 "preview" => GetMessage("BXU_Preview"),
394 "nonPreview" => GetMessage("BXU_NonPreview")
395 );
396
397 $settings["modePin"] = (isset($settings["pinDescription"]) && $settings["pinDescription"] == "Y" && $this->elementSetts["description"] ? "mode-with-description" : "");
398 $t = <<<HTML
399<div class="adm-fileinput-wrapper {$classSingle}">
400<div class="adm-fileinput-btn-panel">
401 <span class="adm-btn add-file-popup-btn" id="{$this->id}_add"></span>
402 <div class="adm-fileinput-mode {$settings["mode"]}" id="{$this->id}_mode">
403 <a href="#" class="mode-pict" id="{$this->id}ThumbModePreview" title="{$mes["preview"]}"></a>
404 <a href="#" class="mode-file" id="{$this->id}ThumbModeNonPreview" title="{$mes["nonPreview"]}"></a>
405 </div>
406</div>
407<div id="{$this->id}_block" class="adm-fileinput-area {$canDelete} {$canEdit} {$settings['mode']} {$settings["modePin"]}">
408 <div class="adm-fileinput-area-container" id="{$this->id}_container">{$files}</div>
409 <span class="adm-fileinput-drag-area-hint" id="{$this->id}Notice">{$hintMessage}</span>
410<script>
411(function(BX)
412{
413 if (BX)
414 {
415 BX.ready(BX.defer(function(){
416 new BX.UI.FileInput('{$this->id}', {$uploadSetts}, {$elementSetts}, {$values}, '{$template}');
417 }));
418 }
419})(window["BX"] || top["BX"]);
420</script>
421</div>
422</div>
423HTML;
424 return $t;
425 }
426 private function getExtDialogs()
427 {
428 if ($this->uploadSetts["medialib"] && Loader::includeModule("fileman"))
429 {
430 $this->uploadSetts["medialib"] = array(
431 "click" => "OpenMedialibDialog".$this->id,
432 "handler" => "SetValueFromMedialib".$this->id
433 );
434 \CMedialib::ShowDialogScript(array(
435 "event" => $this->uploadSetts["medialib"]["click"],
436 "arResultDest" => array(
437 "FUNCTION_NAME" => $this->uploadSetts["medialib"]["handler"]
438 )
439 ));
440 }
441 if ($this->uploadSetts["fileDialog"])
442 {
443 $this->uploadSetts["fileDialog"] = array(
444 "click" => "OpenFileDialog".$this->id,
445 "handler" => "SetValueFromFileDialog".$this->id
446 );
447 \CAdminFileDialog::ShowScript
448 (
449 Array(
450 "event" => $this->uploadSetts["fileDialog"]["click"],
451 "arResultDest" => array("FUNCTION_NAME" => $this->uploadSetts["fileDialog"]["handler"]),
452 "arPath" => array("SITE" => SITE_ID, "PATH" =>"/upload"),
453 "select" => 'F',// F - file only, D - folder only
454 "operation" => 'O',
455 "showUploadTab" => true,
456 "allowAllFiles" => true,
457 "SaveConfig" => true,
458 )
459 );
460 }
461 }
462 private function formFile($fileId = "", $inputName = "file")
463 {
464 $result = array(
465 'id' => $fileId,
466 'name' => 'Unknown',
467 'description_name' => self::getInputName($inputName, "_descr"),
468 'description' => '',
469 'size' => 0,
470 'type' => 'unknown',
471 'input_name' => $inputName,
472 'input_value' => $fileId,
473 'entity' => "file",
474 'ext' => ''
475 );
476 if (!empty($this->elementSetts["properties"]))
477 {
478 foreach ($this->elementSetts["properties"] as $key)
479 {
480 $result[$key."_name"] = self::getInputName($inputName, "_".$key);
481 $result[$key] = "";
482 }
483 }
484 return $result;
485 }
486 private function getFile($fileId = "", $inputName = "file", $getDataFromRequest = false)
487 {
488 $result = null;
489 $properties = array();
490 if (is_array($fileId) && array_key_exists("ID", $fileId))
491 {
492 $properties = $fileId;
493 unset($properties["ID"]);
494 $fileId = $fileId["ID"];
495 }
496
497 if ($fileId > 0 && ($ar = \CFile::GetFileArray($fileId)) && is_array($ar))
498 {
499 $name = ($ar['ORIGINAL_NAME'] <> ''?$ar['ORIGINAL_NAME']:$ar['FILE_NAME']);
500 $result = array(
501 'fileId' => $fileId,
502 'id' => $this->id.'_'.$fileId,
503 'name' => $name,
504 'description_name' => self::getInputName($inputName, "_descr"),
505 'description' => str_replace('"', "&quot;", $ar['DESCRIPTION']),
506 'size' => $ar['FILE_SIZE'],
507 'type' => $ar['CONTENT_TYPE'],
508 'input_name' => $inputName,
509 'input_value' => $fileId,
510 'entity' => (($ar["WIDTH"] > 0 && $ar["HEIGHT"] > 0) ? "image" : "file"),
511 'ext' => GetFileExtension($name),
512 'real_url' => $ar['SRC']
513 );
514 if ($result['entity'] == "image")
515 {
516 $result['tmp_url'] = FileInputUnclouder::getSrc($ar);
517 $result['preview_url'] = FileInputUnclouder::getSrcWithResize($ar, array('width' => 200, 'height' => 200));
518 $result['width'] = $ar["WIDTH"];
519 $result['height'] = $ar["HEIGHT"];
520 }
521 }
522 else
523 {
524 $file = null;
525 if (is_array($fileId) && array_key_exists("tmp_name", $fileId))
526 $file = array(
527 "tmp_name" => $fileId["tmp_name"],
528 "type" => (array_key_exists("type", $fileId) ? $fileId["type"] : null),
529 "name" => (array_key_exists("name", $fileId) ? $fileId["name"] : null),
530 "description" => (array_key_exists("description", $fileId) ? $fileId["description"] : null)
531 );
532 else if (is_string($fileId))
533 $file = array(
534 "tmp_name" => $fileId,
535 "type" => null,
536 "name" => null,
537 "description" => null
538 );
539 if (is_array($file) && ($paths = Uploader::getPaths($file["tmp_name"])) &&
540 ($flTmp = \CBXVirtualIo::GetInstance()->GetFile($paths["tmp_name"])) && $flTmp->IsExists())
541 {
542 $name = is_string($file["name"]) && $file["name"] <> '' ? $file["name"] : $flTmp->getName();
543 $result = array(
544 'id' => md5($file["tmp_name"]),
545 'name' => $name,
546 'description_name' => self::getInputName($inputName, "_descr"),
547 'description' => is_string($file["description"]) && $file["description"] <> '' ? $file["description"] : "",
548 'size' => $flTmp->GetFileSize(),
549 'type' => is_string($file["type"]) && $file["type"] <> '' ? $file["type"] : $flTmp->getType(),
550 'input_name' => $inputName,
551 'input_value' => $file["tmp_name"],
552 'entity' => "file",
553 'ext' => GetFileExtension($name),
554 'real_url' => $paths["tmp_url"]
555 );
556
557 $info = (new \Bitrix\Main\File\Image($paths["tmp_name"]))->getInfo();
558 if ($info)
559 {
560 $result['entity'] = "image";
561 $result['tmp_url'] = $paths["tmp_url"];
562 if (($mime = $info->getMime()) <> '')
563 $result['type'] = $mime;
564 $result['width'] = $info->getWidth();
565 $result['height'] = $info->getHeight();
566 }
567 }
568 }
569 if (is_array($result) && !empty($this->elementSetts["properties"]))
570 {
571 $request = null;
572 if ($getDataFromRequest === true)
573 {
574 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
575 $result["description"] = $request->isPost() ? $request->getPost($result["description_name"]) : $request->getQuery($result["description_name"]);
576 }
577 foreach ($this->elementSetts["properties"] as $key)
578 {
579 $result[$key."_name"] = self::getInputName($inputName, "_".$key);
580 $result[$key] = (is_null($request) ? $properties[$key] : ($request->isPost() ? $request->getPost($result[$key."_name"]) : $request->getQuery($result[$key."_name"])));
581 }
582 }
583 return $result;
584 }
585
586 private static function getInputName($inputName, $type = "")
587 {
588 if ($type == "")
589 return $inputName;
590 $p = mb_strpos($inputName, "[");
591 return ($p > 0) ? mb_substr($inputName, 0, $p).$type.mb_substr($inputName, $p) : $inputName.$type;
592 }
593
599 public static function prepareFile($file)
600 {
601 $return = null;
602 if (is_array($file) && isset($file["tmp_name"]) && !empty($file["tmp_name"]))
603 {
604
605 }
606 return $file;
607 }
608}
609?>
static includeModule($moduleName)
Definition loader.php:69
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static prepareFile($file)
show($values=array(), $getDataFromRequest=false)
__construct($params=array())
static createInstance($params=array(), $hashIsID=true)
static getSrcWithResize($file=array(), $size=array())