public function __construct($params = array())
{
global $USER;
$inputs = array_merge($this->elementSetts, $params);
$this->elementSetts = array(
"name" => $inputs["name"],
"description" => !empty($inputs["description"]),
"delete" => $inputs['delete'] !== false,
"edit" => $inputs['edit'] !== false,
"thumbSize" => 640,
//"properties" => (is_array($inputs) ? $inputs : array()) //TODO It is needed to deal with additional properties
);
if (isset($params['id']))
$this->elementSetts['id'] = $params['id'];
$replace = array(
"/\#MESS_LOADING\#/" => Loc::getMessage("BXU_LoadingProcess"),
"/\#description\#/" => ($this->elementSetts["edit"] == true && $this->elementSetts["description"] == true ? self::$templatePatterns["description"] : ""),
"/\#properties\#/" => "",
"/[nt]+/" => ""
);
$this->templates["uploaded"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["uploaded"]);
$this->templates["unexisted"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["unexisted"]);
$this->templates["new"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["new"]);
$this->templates["unsaved"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["unsaved"]);
$replace = array(
"#input_name#" => $inputs["name"],
"#input_value#" => "",
"#description_name#" => self::getInputName($inputs["name"], "_descr")
);
$this->templates["new"] = str_replace(array_keys($replace), array_values($replace), $this->templates["new"]);
$this->templates["unsavedArray"] = str_replace("#input#", self::$templatePatterns["arrayInput"], $this->templates["unsaved"]);
$this->templates["unsaved"] = str_replace("#input#", self::$templatePatterns["regularInput"], $this->templates["unsaved"]);
$inputs = array_merge($this->uploadSetts, $params);
$this->uploadSetts = array(
"upload" => '',
"uploadType" => "path",
"medialib" =>
isset($inputs['medialib'])
&& $inputs['medialib'] === true
&& COption::GetOptionString('fileman', "use_medialib", "Y") != "N"
,
"fileDialog" =>
(isset($inputs['file_dialog']) && $inputs['file_dialog'] === true)
|| (isset($inputs['fileDialog']) && $inputs['fileDialog'] === true)
,
"cloud" =>
isset($inputs['cloud'])
&& $inputs['cloud'] === true
&& $USER->CanDoOperation("clouds_browse")
&& CModule::IncludeModule("clouds")
&& CCloudStorage::HasActiveBuckets()
,
"maxCount" => isset($params["maxCount"]) && $params["maxCount"] > 0 ? $params["maxCount"] : 0,
"maxSize" => isset($params["maxSize"]) && $params["maxSize"] > 0 ? $params["maxSize"] : 0,
"allowUpload" => $params["allowUpload"] ?? self::UPLOAD_ANY_FILES,
"allowUploadExt" => trim($params["allowUploadExt"] ?? ''),
"allowSort" => isset($params["allowSort"]) && $params["allowSort"] === "N" ? "N" : "Y",
);
if (!in_array(
$this->uploadSetts["allowUpload"],
[
self::UPLOAD_ANY_FILES,
self::UPLOAD_IMAGES,
self::UPLOAD_EXTENTION_LIST,
]
))
{
$this->uploadSetts["allowUpload"] = self::UPLOAD_ANY_FILES;
}
if ($this->uploadSetts["medialib"] === true)
$this->uploadSetts["medialib"] = (BitrixMainLoader::includeModule("fileman") && CMedialib::CanDoOperation('medialib_view_collection', 0));
if($this->uploadSetts["fileDialog"] === true && !$USER->CanDoOperation('fileman_view_file_structure'))
$this->uploadSetts["fileDialog"] = false;
if (empty($this->uploadSetts["allowUploadExt"]) && $this->uploadSetts["allowUpload"] === self::UPLOAD_EXTENTION_LIST)
$this->uploadSetts["allowUpload"] = self::UPLOAD_ANY_FILES;
if (isset($this->elementSetts["id"]))
$this->id = 'bx_file_'.mb_strtolower(preg_replace("/[^a-z0-9]/i", "_", $this->elementSetts["id"]));
else
$this->id = 'bx_file_'.mb_strtolower(preg_replace("/[^a-z0-9]/i", "_", $this->elementSetts["name"]));
if ($inputs['upload'] === true)
{
$this->uploadSetts['upload'] = FileInputReceiver::sign(array(
"id" => ($inputs['uploadType'] === "hash" ? "hash" : "path"),
"allowUpload" => $this->uploadSetts["allowUpload"],
"allowUploadExt" => $this->uploadSetts["allowUploadExt"]
));
$this->uploadSetts['uploadType'] = (in_array($inputs["uploadType"], array(/*"file",*/ "hash", "path")) ? $inputs["uploadType"] : "path");
}
self::$instance = $this;
}