194 $inputs = array_merge($this->elementSetts,
$params);
195 $this->elementSetts =
array(
196 "name" => $inputs[
"name"],
197 "description" => !empty($inputs[
"description"]),
198 "delete" => $inputs[
'delete'] !==
false,
199 "edit" => $inputs[
'edit'] !==
false,
204 $this->elementSetts[
'id'] =
$params[
'id'];
206 "/\\#MESS_LOADING\\#/" => Loc::getMessage(
"BXU_LoadingProcess"),
207 "/\\#description\\#/" => ($this->elementSetts[
"edit"] && $this->elementSetts[
"description"] ? self::$templatePatterns[
"description"] :
""),
208 "/\\#properties\\#/" =>
"",
211 $this->templates[
"uploaded"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns[
"uploaded"]);
212 $this->templates[
"unexisted"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns[
"unexisted"]);
213 $this->templates[
"new"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns[
"new"]);
214 $this->templates[
"unsaved"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns[
"unsaved"]);
216 "#input_name#" => $inputs[
"name"],
217 "#input_value#" =>
"",
218 "#description_name#" => self::getInputName($inputs[
"name"],
"_descr")
220 $this->templates[
"new"] = str_replace(array_keys($replace), array_values($replace), $this->templates[
"new"]);
222 $this->templates[
"unsavedArray"] = str_replace(
"#input#", self::$templatePatterns[
"arrayInput"], $this->templates[
"unsaved"]);
223 $this->templates[
"unsaved"] = str_replace(
"#input#", self::$templatePatterns[
"regularInput"], $this->templates[
"unsaved"]);
225 $inputs = array_merge($this->uploadSetts,
$params);
227 $this->uploadSetts =
array(
229 "uploadType" =>
"path",
231 isset($inputs[
'medialib'])
232 && $inputs[
'medialib'] ===
true
233 && \COption::GetOptionString(
'fileman',
"use_medialib",
"Y") !=
"N"
236 (isset($inputs[
'file_dialog']) && $inputs[
'file_dialog'] ===
true)
237 || (isset($inputs[
'fileDialog']) && $inputs[
'fileDialog'] ===
true)
240 isset($inputs[
'cloud'])
241 && $inputs[
'cloud'] ===
true
242 &&
$USER?->CanDoOperation(
"clouds_browse")
243 && \CModule::IncludeModule(
"clouds")
248 "allowUpload" =>
$params[
"allowUpload"] ?? self::UPLOAD_ANY_FILES,
249 "allowUploadExt" => trim(
$params[
"allowUploadExt"] ??
''),
250 "allowSort" => isset(
$params[
"allowSort"]) &&
$params[
"allowSort"] ===
"N" ?
"N" :
"Y",
253 $this->uploadSetts[
"allowUpload"],
255 self::UPLOAD_ANY_FILES,
257 self::UPLOAD_EXTENTION_LIST,
261 $this->uploadSetts[
"allowUpload"] = self::UPLOAD_ANY_FILES;
263 if ($this->uploadSetts[
"medialib"] ===
true)
264 $this->uploadSetts[
"medialib"] = (
Loader::includeModule(
"fileman") && \CMedialib::CanDoOperation(
'medialib_view_collection'));
265 if($this->uploadSetts[
"fileDialog"] ===
true && !
$USER?->CanDoOperation(
'fileman_view_file_structure'))
266 $this->uploadSetts[
"fileDialog"] =
false;
268 if (empty($this->uploadSetts[
"allowUploadExt"]) && $this->uploadSetts[
"allowUpload"] === self::UPLOAD_EXTENTION_LIST)
269 $this->uploadSetts[
"allowUpload"] = self::UPLOAD_ANY_FILES;
270 if (isset($this->elementSetts[
"id"]))
271 $this->
id =
'bx_file_'.mb_strtolower(preg_replace(
"/[^a-z0-9]/i",
"_", $this->elementSetts[
"id"]));
273 $this->
id =
'bx_file_'.mb_strtolower(preg_replace(
"/[^a-z0-9]/i",
"_", $this->elementSetts[
"name"]));
275 if ($inputs[
'upload'] ===
true)
278 "id" => ($inputs[
'uploadType'] ===
"hash" ?
"hash" :
"path"),
279 "allowUpload" => $this->uploadSetts[
"allowUpload"],
280 "allowUploadExt" => $this->uploadSetts[
"allowUploadExt"]
282 $this->uploadSetts[
'uploadType'] = (in_array($inputs[
"uploadType"],
array(
"hash",
"path")) ? $inputs[
"uploadType"] :
"path");
284 self::$instance = $this;
302 public function show($values =
array(), $getDataFromRequest =
false)
307 if (!is_array($values) || array_key_exists(
"tmp_name", $values))
309 $values =
array($this->elementSetts[
"name"] => $values);
312 $pattMaxIndex = mb_strpos($this->elementSetts[
"name"],
"#IND#") > 0 ? str_replace(
"#IND#",
"(\\d+)", preg_quote($this->elementSetts[
"name"])) :
null;
317 $maxIndex = max($maxIndex, intval(
$matches[1]));
319 if (
$res = $this->getFile($fileId,
$inputName, $getDataFromRequest))
321 $t = (isset(
$res[
"fileId"]) &&
$res[
"fileId"] > 0 ? $this->templates[
"uploaded"] : (is_array($fileId) ? $this->templates[
"unsavedArray"] : $this->templates[
"unsaved"]));
325 $t = $this->templates[
"unexisted"];
328 foreach (
$res as $pat => $rep)
332 if (array_key_exists(
"#description#", $patt) && str_contains($patt[
"#description#"],
"""))
334 $patt[
"#description#"] = str_replace(
""",
""", $patt[
"#description#"]);
336 $files .= str_ireplace(array_keys($patt), array_values($patt), $t);
337 $this->files[] =
$res;
341 $canDelete =
true ?
'' :
'adm-fileinput-non-delete';
342 $canEdit = ($this->elementSetts[
"edit"] ?
'' :
'adm-fileinput-non-edit');
344 $settings = \CUserOptions::GetOption(
'main',
'fileinput');
347 "pinDescription" =>
"N",
348 "mode" =>
"mode-pict",
350 array(
"width" => 200,
"height" => 200,
"title" =>
"200x200")
355 if ($this->uploadSetts[
"maxCount"] == 1)
357 if ($this->uploadSetts[
"allowUpload"] === self::UPLOAD_IMAGES)
358 $hintMessage = Loc::getMessage(
"BXU_DNDMessage01");
359 else if ($this->uploadSetts[
"allowUpload"] === self::UPLOAD_EXTENTION_LIST)
360 $hintMessage = Loc::getMessage(
"BXU_DNDMessage02",
array(
"#ext#" =>
htmlspecialcharsbx($this->uploadSetts[
"allowUploadExt"])));
362 $hintMessage = Loc::getMessage(
"BXU_DNDMessage03");
364 if ($this->uploadSetts[
"maxSize"] > 0)
365 $hintMessage .= Loc::getMessage(
"BXU_DNDMessage04",
array(
"#size#" => \CFile::FormatSize($this->uploadSetts[
"maxSize"])));
370 if ($this->uploadSetts[
"allowUpload"] === self::UPLOAD_IMAGES)
371 $hintMessage = Loc::getMessage(
"BXU_DNDMessage1",
array(
"#maxCount#" =>
$maxCount));
372 else if ($this->uploadSetts[
"allowUpload"] == self::UPLOAD_EXTENTION_LIST)
375 $hintMessage = Loc::getMessage(
"BXU_DNDMessage3",
array(
"#maxCount#" =>
$maxCount));
376 if ($this->uploadSetts[
"maxSize"] > 0)
377 $hintMessage .= Loc::getMessage(
"BXU_DNDMessage4",
array(
"#size#" => \CFile::FormatSize($this->uploadSetts[
"maxSize"])));
380 $this->getExtDialogs();
383 if (array_key_exists(
"presets",
$settings))
389 $template = \CUtil::JSEscape($this->templates[
"new"]);
390 $classSingle = (array_key_exists(
"maxCount",
$uploadSetts) && intval(
$uploadSetts[
"maxCount"]) == 1 ?
"adm-fileinput-wrapper-single" :
"");
393 $values = Json::encode($this->files);
399 $settings[
"modePin"] = (isset(
$settings[
"pinDescription"]) &&
$settings[
"pinDescription"] ==
"Y" && $this->elementSetts[
"description"] ?
"mode-with-description" :
"");
401<div
class=
"adm-fileinput-wrapper {$classSingle}">
402<div
class=
"adm-fileinput-btn-panel">
403 <span
class=
"adm-btn add-file-popup-btn" id=
"{$this->id}_add"></span>
404 <div
class=
"adm-fileinput-mode {$settings["mode
"]}" id=
"{$this->id}_mode">
405 <a href=
"#" class=
"mode-pict" id=
"{$this->id}ThumbModePreview" title=
"{$mes["preview
"]}"></a>
406 <a href=
"#" class=
"mode-file" id=
"{$this->id}ThumbModeNonPreview" title=
"{$mes["nonPreview
"]}"></a>
409<div
id=
"{$this->id}_block" class=
"adm-fileinput-area {$canDelete} {$canEdit} {$settings['mode']} {$settings["modePin
"]}">
410 <div
class=
"adm-fileinput-area-container" id=
"{$this->id}_container">{
$files}</div>
411 <span
class=
"adm-fileinput-drag-area-hint" id=
"{$this->id}Notice">{$hintMessage}</span>
417 BX.ready(BX.defer(
function(){
418 new BX.UI.FileInput(
'{$this->id}', {$uploadSetts}, {$elementSetts}, {$values},
'{$template}');
421})(window[
"BX"] ||
top[
"BX"]);