- Модуль: forum
- Путь к файлу: ~/bitrix/modules/forum/classes/general/functions.php
- Класс: forumTextParser
- Вызов: forumTextParser::convert_attachment
function convert_attachment($fileID = "", $p = "", $type = "", $text = "")
{
if (is_array($fileID))
{
$text = $fileID[0];
$p = $fileID[3];
$fileID = $fileID[2];
}
$fileID = intval($fileID);
$type = mb_strtolower(empty($type)? $this->type : $type);
$type = (in_array($type, array("html", "mail", "bbcode", "rss")) ? $type : "html");
$this->arFiles = (is_array($this->arFiles) ? $this->arFiles : array($this->arFiles));
if ($fileID <= 0 || (!array_key_exists($fileID, $this->arFiles) && !in_array($fileID, $this->arFiles)))
return $text;
if (!array_key_exists($fileID, $this->arFiles) && in_array($fileID, $this->arFiles)): // array(fileID10, fileID12, fileID14)
unset($this->arFiles[array_search($fileID, $this->arFiles)]);
$this->arFiles[$fileID] = $fileID; // array(fileID10 => fileID10, fileID12 => fileID12, fileID14 => fileID14)
endif;
if (!is_array($this->arFiles[$fileID]))
$this->arFiles[$fileID] = CFile::GetFileArray($fileID); // array(fileID10 => array about file, ....)
if (!is_array($this->arFiles[$fileID])): // if file does not exist
unset($this->arFiles[$fileID]);
return $text;
endif;
if (!array_key_exists($fileID, $this->arFilesParsed) || empty($this->arFilesParsed[$fileID][$type]))
{
$arFile = $this->arFiles[$fileID];
if ($type == "html" || $type == "rss")
{
$width = 0; $height = 0;
if (preg_match_all("/width=(?Pd+)|height=(?Pd+)/is".BX_UTF_PCRE_MODIFIER, $p, $matches)):
$width = intval(!empty($matches["width"][0]) ? $matches["width"][0] : $matches["width"][1]);
$height = intval(!empty($matches["height"][0]) ? $matches["height"][0] : $matches["height"][1]);
endif;
$arFile[$type] = $GLOBALS["APPLICATION"]->IncludeComponent(
"bitrix:forum.interface",
"show_file",
Array(
"FILE" => $arFile,
"SHOW_MODE" => ($type == "html" ? "THUMB" : "RSS"),
"SIZE" => array("width" => $width, "height" => $height),
"MAX_SIZE" => array("width" => $this->imageWidth, "height" => $this->imageHeight),
"HTML_SIZE"=> array("width" => $this->imageHtmlWidth, "height" => $this->imageHtmlHeight),
"CONVERT" => "N",
"NAME_TEMPLATE" => $this->userNameTemplate,
"FAMILY" => "FORUM",
"SINGLE" => "Y",
"RETURN" => "Y"),
$this->component,
array("HIDE_ICONS" => "Y"));
}
else
{
$path = '/bitrix/components/bitrix/forum.interface/show_file.php?fid='.$arFile["ID"];
$bIsImage = (CFile::CheckImageFile(CFile::MakeFileArray($fileID)) === null);
// $path = ($bIsImage && !empty($arFile["SRC"]) ? $arFile["SRC"] : !$bIsImage && !empty($arFile["URL"]) ? $arFile["URL"] : $path);
$path = preg_replace("'(?serverName) : $path));
switch ($type)
{
case "bbcode":
$arFile["bbcode"] = ($bIsImage ? '[IMG]'.$path.'[/IMG]' : '[URL='.$path.']'.$arFile["ORIGINAL_NAME"].'[/URL]');
break;
case "mail":
$arFile["mail"] = $arFile["ORIGINAL_NAME"].($bIsImage ? " (IMAGE: ".$path.")" : " (URL: ".$path.")");
break;
}
}
$this->arFilesParsed[$fileID] = $arFile;
}
$this->arFilesIDParsed[] = $fileID;
return $this->arFilesParsed[$fileID][$type];
}