9 $bUseFileDialog =
false,
11 $bShowDescInput =
false,
12 $bShowDelInput =
true,
13 $curFileIds =
array(),
33 private static function Init($showInfo,
$inputName, $maxCount =
false)
35 self::$bMultiple =
false;
36 self::$bUseUpload =
false;
37 self::$bUseMedialib =
false;
38 self::$bUseFileDialog =
false;
39 self::$bUseCloud =
false;
40 self::$bShowDelInput =
false;
41 self::$bShowDescInput =
false;
42 self::$bViewMode =
false;
43 self::$maxCount = $maxCount;
44 self::$showInfo = $showInfo;
46 self::$maxPreviewWidth = max((isset($showInfo[
'MAX_SIZE'][
'W']) ? $showInfo[
'MAX_SIZE'][
'W'] : 200), 40);
47 self::$maxPreviewHeight = max((isset($showInfo[
'MAX_SIZE'][
'H']) ? $showInfo[
'MAX_SIZE'][
'H'] : 200), 40);
49 self::$minPreviewWidth = min((isset($showInfo[
'MIN_SIZE'][
'W']) ? $showInfo[
'MIN_SIZE'][
'W'] : 120), 500);
50 self::$minPreviewHeight = min((isset($showInfo[
'MIN_SIZE'][
'H']) ? $showInfo[
'MIN_SIZE'][
'H'] : 100), 500);
52 self::$jsId =
'bx_file_'.mb_strtolower(preg_replace(
"/[^a-z0-9]/i",
"_",
$inputName));
62 public static function Show(
74 $uploadInput = $inputs[
'upload'] ===
true ?
array() : $inputs[
'upload'];
75 $medialibInput = $inputs[
'medialib'] ===
true ?
array() : $inputs[
'medialib'];
76 $fileDialogInput = $inputs[
'file_dialog'] ===
true ?
array() : $inputs[
'file_dialog'];
77 $cloudInput = $inputs[
'cloud'] ===
true ?
array() : $inputs[
'cloud'];
79 self::Init($showInfo, $strInputName);
82 if(is_array($uploadInput))
84 self::$bUseUpload =
true;
85 if(!array_key_exists(
"NAME", $uploadInput))
86 $uploadInput[
"NAME"] = $strInputName;
90 if(COption::GetOptionString(
'fileman',
"use_medialib",
"Y") !=
"N" && is_array($medialibInput))
92 self::$bUseMedialib =
true;
93 if(!array_key_exists(
"NAME", $medialibInput))
94 $medialibInput[
"NAME"] = $strInputName;
98 if(is_array($fileDialogInput))
100 self::$bUseFileDialog =
true;
101 if(!array_key_exists(
"NAME", $fileDialogInput))
102 $fileDialogInput[
"NAME"] = $strInputName;
107 is_array($cloudInput)
108 &&
$USER->CanDoOperation(
"clouds_browse")
109 && CModule::IncludeModule(
"clouds")
113 self::$bUseCloud =
true;
114 if(!array_key_exists(
"NAME", $cloudInput))
115 $cloudInput[
"NAME"] = $strInputName;
118 if($inputs[
'description'] !==
false)
120 self::$bShowDescInput =
true;
121 self::$descInputName = isset($inputs[
'description'][
"NAME"]) ? $inputs[
'description'][
"NAME"] : self::GetInputName($strInputName,
"_descr");
124 if($inputs[
'del'] !==
false)
126 self::$bShowDelInput =
true;
127 self::$delInputName = isset($inputs[
'del'][
"NAME"]) ? $inputs[
'del'][
"NAME"] : self::GetInputName($strInputName,
"_del");
131 self::$curFileIds = is_array($strFileId) && !array_key_exists(
"tmp_name", $strFileId)? $strFileId :
array($strFileId);
132 self::$curFiles =
array();
133 self::$bFileExists =
false;
135 foreach(self::$curFileIds as $fileId)
137 if (is_array($fileId))
139 if (mb_strlen($fileId ??
'') <= 1 && intval($fileId) === 0)
142 self::$bFileExists =
true;
143 if($arFile = self::GetFile($fileId))
145 $arFile[
'FILE_NOT_FOUND'] =
false;
146 if (self::$bShowDescInput && isset($inputs[
'description'][
'VALUE']))
147 $arFile[
'DESCRIPTION'] = $inputs[
'description'][
'VALUE'];
152 'FILE_NOT_FOUND' =>
true,
153 'DEL_NAME' => self::$delInputName
156 self::$curFiles[] = $arFile;
159 self::$bViewMode = self::IsViewMode();
160 if (self::$bViewMode)
161 self::$bShowDelInput =
false;
163 if (!self::$bViewMode || self::$bFileExists)
166 'upload' => self::$bUseUpload,
167 'medialib' => self::$bUseMedialib,
168 'file_dialog' => self::$bUseFileDialog,
169 'cloud' => self::$bUseCloud,
170 'del' => self::$bShowDelInput,
171 'description' => self::$bShowDescInput
174 self::$arInputs =
array(
175 'upload' => $uploadInput,
176 'medialib' => $medialibInput,
177 'file_dialog' => $fileDialogInput,
178 'cloud' => $cloudInput
181 self::DisplayControl($inputs);
199 $inputNameTemplate =
"",
209 self::Init($showInfo, $inputNameTemplate, $maxCount);
210 self::$bMultiple =
true;
212 $arDescInput = (is_array($inputs[
'description']) && isset($inputs[
'description'][
'VALUES']) && isset($inputs[
'description'][
'NAME_TEMPLATE'])) ? $inputs[
'description'] :
false;
215 'upload' => $inputs[
'upload'] ===
true,
216 'medialib' => $inputs[
'medialib'] ===
true && COption::GetOptionString(
'fileman',
"use_medialib",
"Y") !=
"N",
217 'file_dialog' => $inputs[
'file_dialog'] ===
true,
219 'del' => $inputs[
'del'] !==
false,
220 'description' => $inputs[
'description'] ===
true || $arDescInput
223 self::$bUseUpload = $inputs[
'upload'];
224 self::$bUseMedialib = $inputs[
'medialib'];
225 self::$bUseFileDialog = $inputs[
'file_dialog'];
226 self::$bUseCloud = $inputs[
'cloud'];
227 self::$bShowDelInput = $inputs[
'del'];
228 self::$bShowDescInput = $inputs[
'description'];
229 self::$inputNameTemplate = $inputNameTemplate;
231 self::$bViewMode = self::IsViewMode();
232 if (self::$bViewMode)
233 self::$bShowDelInput =
false;
235 if (self::$bShowDelInput)
236 self::$delInputName = self::GetInputName($inputNameTemplate,
"_del");
238 if (self::$bShowDescInput)
240 self::$descInputName =
'';
242 self::$descInputName = $arDescInput[
'NAME_TEMPLATE'];
244 if (empty(self::$descInputName))
245 self::$descInputName = self::GetInputName($inputNameTemplate,
"_descr");
249 self::$curFiles =
array();
250 self::$bFileExists =
false;
254 reset($arDescInput[
'VALUES']);
259 if (mb_strlen($fileId) <= 1 && intval($fileId) === 0)
262 self::$bFileExists =
true;
263 if($arFile = self::GetFile($fileId))
265 $arFile[
'FILE_NOT_FOUND'] =
false;
267 $arFile[
'DEL_NAME'] = self::GetInputName(
$inputName,
'_del');
268 $arFile[
'DESC_NAME'] = self::GetInputName(
$inputName,
'_descr');
272 $arFile[
'DESC_NAME'] = key($arDescInput[
'VALUES']);
273 $arFile[
'DESCRIPTION'] = current($arDescInput[
'VALUES']);
274 next($arDescInput[
'VALUES']);
280 'FILE_NOT_FOUND' =>
true,
282 'DEL_NAME' => self::GetInputName(
$inputName,
'_del'),
283 'DESC_NAME' => self::GetInputName(
$inputName,
'_descr')
287 self::$curFiles[] = $arFile;
290 self::DisplayControl($inputs);
297 private static function GetFile($fileId =
"")
299 $arFile = CFile::GetFileArray($fileId);
302 if(!is_array($arFile) && $fileId !=
"")
304 $strFilePath =
$_SERVER[
"DOCUMENT_ROOT"].$fileId;
305 if(
$io->FileExists($strFilePath))
307 $flTmp =
$io->GetFile($strFilePath);
310 "FILE_SIZE" => $flTmp->GetFileSize(),
314 $arImageSize = CFile::GetImageSize($strFilePath);
315 if(is_array($arImageSize))
317 $arFile[
"WIDTH"] = intval($arImageSize[0]);
318 $arFile[
"HEIGHT"] = intval($arImageSize[1]);
321 elseif(self::$showInfo[
'IMAGE'] ==
'N')
325 "FORMATED_SIZE" =>
'',
334 $sImagePath = isset($arFile[
"PATH"]) ? $arFile[
"PATH"] : $arFile[
"SRC"];
336 $arFile[
"HANDLER_ID"]
337 || (defined(
"BX_IMG_SERVER") && mb_substr($sImagePath, 0, mb_strlen(BX_IMG_SERVER)) === BX_IMG_SERVER)
338 ||
$io->FileExists(
$_SERVER[
"DOCUMENT_ROOT"].$sImagePath)
342 $arFile[
"IS_IMAGE"] = $arFile[
"WIDTH"] > 0 && $arFile[
"HEIGHT"] > 0 && self::$showInfo[
'IMAGE'] !=
'N';
345 if ($arFile[
"CONTENT_TYPE"] && $arFile[
"IS_IMAGE"] && mb_strpos($arFile[
"CONTENT_TYPE"],
'application') !==
false)
347 $arFile[
"IS_IMAGE"] =
false;
350 unset($arFile[
"MODULE_ID"], $arFile[
"CONTENT_TYPE"], $arFile[
"SUBDIR"], $arFile[
"~src"]);
357 private static function DisplayControl($inputs =
array())
359 self::$menuNew =
array();
360 self::$menuExist =
array();
362 if ($inputs[
'upload'])
364 self::$menuNew[] =
array(
"ID" =>
"upload",
"GLOBAL_ICON" =>
"adm-menu-upload-pc",
"TEXT" =>
GetMessage(
"ADM_FILE_UPLOAD"),
"CLOSE_ON_CLICK" =>
false);
365 self::$menuExist[] =
array(
"ID" =>
"upload",
"GLOBAL_ICON" =>
"adm-menu-upload-pc",
"TEXT" =>
GetMessage(
"ADM_FILE_NEW_UPLOAD"),
"CLOSE_ON_CLICK" =>
false);
367 if ($inputs[
'medialib'])
369 self::$menuNew[] =
array(
"TEXT" =>
GetMessage(
"ADM_FILE_MEDIALIB"),
"GLOBAL_ICON" =>
"adm-menu-upload-medialib",
"ONCLICK" =>
"OpenMedialibDialog".self::$jsId.
"()");
370 self::$menuExist[] =
array(
"TEXT" =>
GetMessage(
"ADM_FILE_NEW_MEDIALIB"),
"GLOBAL_ICON" =>
"adm-menu-upload-medialib",
"ONCLICK" =>
"OpenMedialibDialog".self::$jsId.
"()");
372 if ($inputs[
'file_dialog'])
374 self::$menuNew[] =
array(
"TEXT" =>
GetMessage(
"ADM_FILE_SITE"),
"GLOBAL_ICON" =>
"adm-menu-upload-site",
"ONCLICK" =>
"OpenFileDialog".self::$jsId.
"()");
375 self::$menuExist[] =
array(
"TEXT" =>
GetMessage(
"ADM_FILE_NEW_SITE"),
"GLOBAL_ICON" =>
"adm-menu-upload-site",
"ONCLICK" =>
"OpenFileDialog".self::$jsId.
"()");
378 if ($inputs[
'cloud'])
380 self::$menuNew[] =
array(
"TEXT" =>
GetMessage(
"ADM_FILE_CLOUD"),
"GLOBAL_ICON" =>
"adm-menu-upload-cloud",
"ONCLICK" =>
"OpenCloudDialog".self::$jsId.
"()");
381 self::$menuExist[] =
array(
"TEXT" =>
GetMessage(
"ADM_FILE_NEW_CLOUD"),
"GLOBAL_ICON" =>
"adm-menu-upload-cloud",
"ONCLICK" =>
"OpenCloudDialog".self::$jsId.
"()");
386 'fileExists' => self::$bFileExists,
387 'files' => self::$curFiles,
388 'menuNew' => self::$menuNew,
389 'menuExist' => self::$menuExist,
390 'multiple' => self::$bMultiple,
391 'useUpload' => self::$bUseUpload,
392 'useMedialib' => self::$bUseMedialib,
393 'useFileDialog' => self::$bUseFileDialog,
394 'useCloud' => self::$bUseCloud,
395 'delName' => self::$delInputName,
396 'descName' => self::$descInputName,
397 'inputSize' => self::$inputSize,
398 'minPreviewHeight' => self::$minPreviewHeight,
399 'minPreviewWidth' => self::$minPreviewWidth,
400 'showDesc' => self::$bShowDescInput,
401 'showDel' => self::$bShowDelInput,
402 'maxCount' => self::$maxCount,
403 'viewMode' => self::$bViewMode
406 if (self::$bMultiple)
407 $arConfig[
'inputNameTemplate'] = self::$inputNameTemplate;
409 $arConfig[
'inputs'] = self::$arInputs;
411 if (self::$bUseCloud)
412 $arConfig[
'cloudDialogPath'] =
'/bitrix/admin/clouds_file_search.php?lang='.LANGUAGE_ID.
'&n=';
416 ?><div
class=
"adm-input-file-control" id=
"<?= self::$jsId.'_cont'?>"><?
417 if (!self::$bViewMode)
418 self::DisplayDialogs();
420 if (self::$bFileExists)
421 foreach(self::$curFiles as $ind => $arFile)
422 self::DisplayFile($arFile, $ind);
425 var topWindow = BX.PageObject.getRootWindow();
426 (topWindow.BX.file_input) ?
new topWindow.BX.file_input(<?= CUtil::PHPToJSObject($arConfig)?>) :
new BX.file_input(<?= CUtil::PHPToJSObject($arConfig)?>)
430 <div
id=
"<?= self::$jsId.'_ie_bogus_container'?>"><input type=
"hidden" value=
"" /></div>
434 private static function DisplayDialogs()
436 if(self::$bUseMedialib)
438 CMedialib::ShowDialogScript(
array(
439 "event" =>
"OpenMedialibDialog".self::$jsId,
440 "arResultDest" =>
array(
441 "FUNCTION_NAME" =>
"SetValueFromMedialib".self::$jsId,
446 if (self::$bUseFileDialog)
451 "event" =>
"OpenFileDialog".self::$jsId,
452 "arResultDest" =>
array(
"FUNCTION_NAME" =>
"SetValueFromFileDialog".self::$jsId),
453 "arPath" =>
array(
"SITE" =>
SITE_ID,
"PATH" =>
"/upload"),
456 "showUploadTab" =>
true,
457 "allowAllFiles" =>
true,
458 "SaveConfig" =>
true,
464 private static function DisplayFile($arFile =
array(), $ind = 0)
466 $hintId = self::$jsId.
'_file_disp_'.$ind;
467 $bNotFound = $arFile[
'FILE_NOT_FOUND'];
474 $sImagePath = isset($arFile[
"PATH"]) ? $arFile[
"PATH"] : $arFile[
"SRC"];
475 $descName = isset($arFile[
'DESC_NAME']) ? $arFile[
'DESC_NAME'] : self::$descInputName;
477 if ($arFile[
'FORMATED_SIZE'] !=
'')
478 $hint .=
'<span class="adm-input-file-hint-row">'.GetMessage(
'ADM_FILE_INFO_SIZE').
': '.$arFile[
'FORMATED_SIZE'].
'</span>';
480 if ($arFile[
'IS_IMAGE'])
481 $hint .=
'<span class="adm-input-file-hint-row">'.GetMessage(
'ADM_FILE_INFO_DIM').
': '.$arFile[
'WIDTH'].
'x'.$arFile[
'HEIGHT'].
'</span>';
482 if ($sImagePath !=
'')
483 $hint .=
'<span class="adm-input-file-hint-row">'.GetMessage(
'ADM_FILE_INFO_LINK').
': <a href="'.
CHTTP::urnEncode($sImagePath,
"UTF-8").
'">'.
htmlspecialcharsbx($sImagePath).
'</a></span>';
485 if (!self::$bShowDescInput && $arFile[
'DESCRIPTION'] !=
"")
486 $hint .=
'<span class="adm-input-file-hint-row">'.GetMessage(
'ADM_FILE_DESCRIPTION').
': '.
htmlspecialcharsbx($arFile[
'DESCRIPTION']).
'</span>';
488 ?><span
class=
"adm-input-file-exist-cont" id=
"<?= self::$jsId?>_file_cont_<?= $ind?>">
489 <div
class=
"adm-input-file-ex-wrap<?if(self::$bMultiple){echo ' adm-input-cont-bordered';}?>">
494 <span
id=
"<?= self::$jsId.'_file_404_'.$ind?>" class=
"adm-input-file-not-found">
499 elseif ($arFile[
'IS_IMAGE'])
503 <span
id=
"<?= $hintId?>" class=
"adm-input-file-preview" style=
"<?if(self::$minPreviewWidth > 0){echo 'min-width: '.self::$minPreviewWidth.'px;';}?> <?if(self::$minPreviewHeight > 0){echo 'min-height:'.self::$minPreviewHeight.'px;';}?>">
504 <?=
CFile::Show2Images($file[
'src'], $arFile[
'SRC'], self::$maxPreviewWidth, self::$maxPreviewHeight);?><?
505 if (!self::IsViewMode() || self::$bShowDelInput)
507 ?><div
id=
"<?= self::$jsId.'_file_del_lbl_'.$ind?>" class=
"adm-input-file-del-lbl"><?=
GetMessage
508 (
'ADM_FILE_DELETED_TITLE')?></div><?
515 $val = !empty($arFile[
'FILE_NAME']) ? $arFile[
'FILE_NAME'] : $sImagePath;
517 <a
id=
"<?= $hintId?>" href=
"<?= htmlspecialcharsbx($arFile['SRC'])?>" class=
"adm-input-file-name"><?=
htmlspecialcharsbx(
$val)?></a>
525 new (BX.PageObject.getRootWindow()).BX.CHint({
526 parent: (BX.PageObject.getRootWindow()).BX(
"<?= $hintId?>"),
532 hint:
'<?= CUtil::JSEscape($hint)?>'
538 if (!self::$bViewMode)
539 self::ShowOpenerMenuHtml(self::$jsId.
'_menu_'.$ind, $ind);
541 if (!$bNotFound && self::$bShowDescInput)
544 <div
id=
"<?= self::$jsId.'_file_desc_'.$ind?>" class=
"adm-input-file-desc-inp-cont" <?
if($arFile[
'DESCRIPTION'] ==
""){echo
'style="display: none;"';}?>>
545 <input name=
"<?= $descName?>" class=
"adm-input" type=
"text" value=
"<?= htmlspecialcharsbx($arFile['DESCRIPTION'])?>" size=
"<?= self::$inputSize?>" placeholder=
"<?= GetMessage("ADM_FILE_DESC
")?>" <?
if(self::$bViewMode){echo
' disabled="disabled"';}?>>
555 private static function ShowOpenerMenuHtml($id,
$data=
false)
557 ?><span <?
if(
$data !==
false){echo
'data-bx-meta="'.$data.
'"';}?>
id=
"<?= $id?>" class=
"adm-btn add-file-popup-btn"></span><?
568 private static function IsViewMode()
570 return !self::$bUseUpload && !self::$bUseMedialib && !self::$bUseFileDialog && !self::$bUseCloud;
static ResizeImageGet($file, $arSize, $resizeType=BX_RESIZE_IMAGE_PROPORTIONAL, $bInitSizes=false, $arFilters=false, $bImmediate=false, $jpgQuality=false)
static Show2Images($strImage1, $strImage2, $iMaxW=0, $iMaxH=0, $sParams=false, $sPopupTitle=false, $iSizeWHTTP=0, $iSizeHHTTP=0)
const BX_RESIZE_IMAGE_PROPORTIONAL
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)