- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/ui/fileinput.php
- Класс: BitrixMainUIFileInput
- Вызов: FileInput::show
public function show($values = array(), $getDataFromRequest = false)
{
CJSCore::Init(array('fileinput'));
$files = '';
if (!is_array($values) || array_key_exists("tmp_name", $values))
{
$values = array($this->elementSetts["name"] => $values);
}
$maxIndex = 0;
$pattMaxIndex = mb_strpos($this->elementSetts["name"], "#IND#") > 0 ? str_replace("#IND#", "(\d+)", preg_quote($this->elementSetts["name"])) : null;
foreach($values as $inputName => $fileId)
{
if ($pattMaxIndex && preg_match("/".$pattMaxIndex."/", $inputName, $matches))
{
$maxIndex = max($maxIndex, intval($matches[1]));
}
if ($res = $this->getFile($fileId, $inputName, $getDataFromRequest))
{
$t = (isset($res["fileId"]) && $res["fileId"] > 0 ? $this->templates["uploaded"] : (is_array($fileId) ? $this->templates["unsavedArray"] : $this->templates["unsaved"]));
if (!is_array($res))
{
$res = $this->formFile($fileId, $inputName);
$t = $this->templates["unexisted"];
}
$patt = array();
foreach ($res as $pat => $rep)
{
$patt["#".$pat."#"] = htmlspecialcharsbx($rep);
}
if (array_key_exists("#description#", $patt) && strpos($patt["#description#"], """) !== false)
{
$patt["#description#"] = str_replace(""", """, $patt["#description#"]);
}
$files .= str_ireplace(array_keys($patt), array_values($patt), $t);
$this->files[] = $res;
}
}
$canDelete = true ? '' : 'adm-fileinput-non-delete'; // In case we can not delete files
$canEdit = ($this->elementSetts["edit"] ? '' : 'adm-fileinput-non-edit');
$settings = CUserOptions::GetOption('main', 'fileinput');
$settings = (is_array($settings) ? $settings : array(
"frameFiles" => "N",
"pinDescription" => "N",
"mode" => "mode-pict",
"presets" => array(
array("width" => 200, "height" => 200, "title" => "200x200")
),
"presetActive" => 0
));
if ($this->uploadSetts["maxCount"] == 1)
{
if ($this->uploadSetts["allowUpload"] === self::UPLOAD_IMAGES)
$hintMessage = Loc::getMessage("BXU_DNDMessage01");
else if ($this->uploadSetts["allowUpload"] === self::UPLOAD_EXTENTION_LIST)
$hintMessage = Loc::getMessage("BXU_DNDMessage02", array("#ext#" => htmlspecialcharsbx($this->uploadSetts["allowUploadExt"])));
else
$hintMessage = Loc::getMessage("BXU_DNDMessage03");
if ($this->uploadSetts["maxSize"] > 0)
$hintMessage .= Loc::getMessage("BXU_DNDMessage04", array("#size#" => CFile::FormatSize($this->uploadSetts["maxSize"])));
}
else
{
$maxCount = ($this->uploadSetts["maxCount"] > 0 ? GetMessage("BXU_DNDMessage5", array("#maxCount#" => htmlspecialcharsbx($this->uploadSetts["maxCount"]))) : "");
if ($this->uploadSetts["allowUpload"] === self::UPLOAD_IMAGES)
$hintMessage = Loc::getMessage("BXU_DNDMessage1", array("#maxCount#" => $maxCount));
else if ($this->uploadSetts["allowUpload"] == self::UPLOAD_EXTENTION_LIST)
$hintMessage = Loc::getMessage("BXU_DNDMessage2", array("#ext#" => htmlspecialcharsbx($this->uploadSetts["allowUploadExt"]), "#maxCount#" => $maxCount));
else
$hintMessage = Loc::getMessage("BXU_DNDMessage3", array("#maxCount#" => $maxCount));
if ($this->uploadSetts["maxSize"] > 0)
$hintMessage .= Loc::getMessage("BXU_DNDMessage4", array("#size#" => CFile::FormatSize($this->uploadSetts["maxSize"])));
}
$this->getExtDialogs();
$uploadSetts = $this->uploadSetts + $settings;
if (array_key_exists("presets", $settings))
{
$uploadSetts["presets"] = $settings["presets"];
$uploadSetts["presetActive"] = $settings["presetActive"];
}
$uploadSetts["maxIndex"] = $maxIndex;
$template = CUtil::JSEscape($this->templates["new"]);
$classSingle = (array_key_exists("maxCount", $uploadSetts) && intval($uploadSetts["maxCount"]) == 1 ? "adm-fileinput-wrapper-single" : "");
$uploadSetts = CUtil::PhpToJSObject($uploadSetts);
$elementSetts = CUtil::PhpToJSObject($this->elementSetts);
$values = CUtil::PhpToJSObject($this->files);
$mes = array(
"preview" => GetMessage("BXU_Preview"),
"nonPreview" => GetMessage("BXU_NonPreview")
);
$settings["modePin"] = (isset($settings["pinDescription"]) && $settings["pinDescription"] == "Y" && $this->elementSetts["description"] ? "mode-with-description" : "");
$t = <<
HTML;
return $t;
}