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,
201 if (isset($params[
'id']))
202 $this->elementSetts[
'id'] = $params[
'id'];
205 "/\\#description\\#/" => ($this->elementSetts[
"edit"] ==
true && $this->elementSetts[
"description"] ==
true ? self::$templatePatterns[
"description"] :
""),
206 "/\\#properties\\#/" =>
"",
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"]);
214 "#input_name#" => $inputs[
"name"],
215 "#input_value#" =>
"",
216 "#description_name#" => self::getInputName($inputs[
"name"],
"_descr")
218 $this->templates[
"new"] = str_replace(array_keys($replace), array_values($replace), $this->templates[
"new"]);
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"]);
223 $inputs = array_merge($this->uploadSetts, $params);
225 $this->uploadSetts = array(
227 "uploadType" =>
"path",
229 isset($inputs[
'medialib'])
230 && $inputs[
'medialib'] ===
true
231 && \COption::GetOptionString(
'fileman',
"use_medialib",
"Y") !=
"N"
234 (isset($inputs[
'file_dialog']) && $inputs[
'file_dialog'] ===
true)
235 || (isset($inputs[
'fileDialog']) && $inputs[
'fileDialog'] ===
true)
238 isset($inputs[
'cloud'])
239 && $inputs[
'cloud'] ===
true
240 && $USER->CanDoOperation(
"clouds_browse")
241 && \CModule::IncludeModule(
"clouds")
242 && \CCloudStorage::HasActiveBuckets()
244 "maxCount" => isset($params[
"maxCount"]) && $params[
"maxCount"] > 0 ? $params[
"maxCount"] : 0,
245 "maxSize" => isset($params[
"maxSize"]) && $params[
"maxSize"] > 0 ? $params[
"maxSize"] : 0,
247 "allowUploadExt" => trim($params[
"allowUploadExt"] ??
''),
248 "allowSort" => isset($params[
"allowSort"]) && $params[
"allowSort"] ===
"N" ?
"N" :
"Y",
251 $this->uploadSetts[
"allowUpload"],
253 self::UPLOAD_ANY_FILES,
255 self::UPLOAD_EXTENTION_LIST,
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;
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"]));
271 $this->
id =
'bx_file_'.mb_strtolower(preg_replace(
"/[^a-z0-9]/i",
"_", $this->elementSetts[
"name"]));
273 if ($inputs[
'upload'] ===
true)
276 "id" => ($inputs[
'uploadType'] ===
"hash" ?
"hash" :
"path"),
277 "allowUpload" => $this->uploadSetts[
"allowUpload"],
278 "allowUploadExt" => $this->uploadSetts[
"allowUploadExt"]
280 $this->uploadSetts[
'uploadType'] = (in_array($inputs[
"uploadType"], array(
"hash",
"path")) ? $inputs[
"uploadType"] :
"path");
282 self::$instance = $this;
300 public function show($values = array(), $getDataFromRequest =
false)
302 \CJSCore::Init(array(
'fileinput'));
305 if (!is_array($values) || array_key_exists(
"tmp_name", $values))
307 $values = array($this->elementSetts[
"name"] => $values);
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)
313 if ($pattMaxIndex && preg_match(
"/".$pattMaxIndex.
"/", $inputName, $matches))
315 $maxIndex = max($maxIndex, intval($matches[1]));
317 if ($res = $this->getFile($fileId, $inputName, $getDataFromRequest))
319 $t = (isset($res[
"fileId"]) && $res[
"fileId"] > 0 ? $this->templates[
"uploaded"] : (is_array($fileId) ? $this->templates[
"unsavedArray"] : $this->templates[
"unsaved"]));
322 $res = $this->formFile($fileId, $inputName);
323 $t = $this->templates[
"unexisted"];
326 foreach ($res as $pat => $rep)
328 $patt[
"#".$pat.
"#"] = htmlspecialcharsbx($rep);
330 if (array_key_exists(
"#description#", $patt) && strpos($patt[
"#description#"],
""") !==
false)
332 $patt[
"#description#"] = str_replace(
""",
""", $patt[
"#description#"]);
334 $files .= str_ireplace(array_keys($patt), array_values($patt), $t);
335 $this->files[] = $res;
339 $canDelete =
true ?
'' :
'adm-fileinput-non-delete';
340 $canEdit = ($this->elementSetts[
"edit"] ?
'' :
'adm-fileinput-non-edit');
342 $settings = \CUserOptions::GetOption(
'main',
'fileinput');
343 $settings = (is_array($settings) ? $settings : array(
345 "pinDescription" =>
"N",
346 "mode" =>
"mode-pict",
348 array(
"width" => 200,
"height" => 200,
"title" =>
"200x200")
353 if ($this->uploadSetts[
"maxCount"] == 1)
355 if ($this->uploadSetts[
"allowUpload"] === self::UPLOAD_IMAGES)
357 else if ($this->uploadSetts[
"allowUpload"] === self::UPLOAD_EXTENTION_LIST)
358 $hintMessage =
Loc::getMessage(
"BXU_DNDMessage02", array(
"#ext#" => htmlspecialcharsbx($this->uploadSetts[
"allowUploadExt"])));
362 if ($this->uploadSetts[
"maxSize"] > 0)
363 $hintMessage .=
Loc::getMessage(
"BXU_DNDMessage04", array(
"#size#" => \CFile::FormatSize($this->uploadSetts[
"maxSize"])));
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));
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"])));
378 $this->getExtDialogs();
381 if (array_key_exists(
"presets", $settings))
384 $uploadSetts[
"presetActive"] = $settings[
"presetActive"];
387 $template = \CUtil::JSEscape($this->templates[
"new"]);
388 $classSingle = (array_key_exists(
"maxCount",
$uploadSetts) && intval(
$uploadSetts[
"maxCount"]) == 1 ?
"adm-fileinput-wrapper-single" :
"");
391 $values = \CUtil::PhpToJSObject($this->files);
393 "preview" => GetMessage(
"BXU_Preview"),
394 "nonPreview" => GetMessage(
"BXU_NonPreview")
397 $settings[
"modePin"] = (isset($settings[
"pinDescription"]) && $settings[
"pinDescription"] ==
"Y" && $this->elementSetts[
"description"] ?
"mode-with-description" :
"");
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>
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>
415 BX.ready(
BX.defer(
function(){
419})(window[
"BX"] || top[
"BX"]);
580 $result[$key] = (is_null($request) ? $properties[$key] : ($request->isPost() ? $request->getPost($result[$key.
"_name"]) : $request->getQuery($result[$key.
"_name"])));
591 return ($p > 0) ? mb_substr($inputName, 0, $p).$type.mb_substr($inputName, $p) : $inputName.$type;