| Current Path : /var/www/element/data/www/greenpr.ru/bitrix3/modules/iblock/classes/general/ |
| Current File : /var/www/element/data/www/greenpr.ru/bitrix3/modules/iblock/classes/general/comp_formatprops.php |
<?
IncludeModuleLangFile(__FILE__);
class CIBlockFormatProperties
{
function GetDisplayValue($arItem, $arProperty, $event1)
{
$arUserTypeFormat = false;
if(strlen($arProperty["USER_TYPE"])>0)
{
$arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]);
if(array_key_exists("GetPublicViewHTML", $arUserType))
$arUserTypeFormat = $arUserType["GetPublicViewHTML"];
}
static $CACHE = array("E"=>array(),"G"=>array());
if($arUserTypeFormat)
{
if($arProperty["MULTIPLE"]=="N" || !is_array($arProperty["~VALUE"]))
$arValues = array($arProperty["~VALUE"]);
else
$arValues = $arProperty["~VALUE"];
}
else
{
if(is_array($arProperty["VALUE"]))
$arValues = $arProperty["VALUE"];
else
$arValues = array($arProperty["VALUE"]);
}
$arDisplayValue = array();
foreach($arValues as $key => $val)
{
if($arUserTypeFormat)
{
$arDisplayValue[] = call_user_func_array($arUserTypeFormat,
array(
$arProperty,
array("VALUE" => $val),
array(),
));
}
elseif($arProperty["PROPERTY_TYPE"] == "E")
{
if(intval($val) > 0)
{
if(!array_key_exists($val, $CACHE["E"]))
{
//USED TO GET "LINKED" ELEMENTS
$arLinkFilter = array (
"ID" => $val,
"ACTIVE" => "Y",
"ACTIVE_DATE" => "Y",
"CHECK_PERMISSIONS" => "Y",
);
$rsLink = CIBlockElement::GetList(array(), $arLinkFilter, false, false, array("ID","IBLOCK_ID","NAME","DETAIL_PAGE_URL"));
$CACHE["E"][$val] = $rsLink->GetNext();
}
if(is_array($CACHE["E"][$val]))
$arDisplayValue[]='<a href="'.$CACHE["E"][$val]["DETAIL_PAGE_URL"].'">'.$CACHE["E"][$val]["NAME"].'</a>';
}
}
elseif($arProperty["PROPERTY_TYPE"] == "G")
{
if(intval($val) > 0)
{
if(!array_key_exists($val, $CACHE["G"]))
{
//USED TO GET SECTIONS NAMES
$arSectionFilter = array (
"ID" => $val,
);
$rsSection = CIBlockSection::GetList(Array(), $arSectionFilter);
$CACHE["G"][$val] = $rsSection->GetNext();
}
if(is_array($CACHE["G"][$val]))
$arDisplayValue[]='<a href="'.$CACHE["G"][$val]["SECTION_PAGE_URL"].'">'.$CACHE["G"][$val]["NAME"].'</a>';
}
}
elseif($arProperty["PROPERTY_TYPE"]=="L")
{
$arDisplayValue[] = $val;
}
elseif($arProperty["PROPERTY_TYPE"]=="F")
{
if($arFile = CFile::GetFileArray($val))
{
if(IsModuleInstalled("statistic"))
$arDisplayValue[] = '<a href="'.htmlspecialchars("/bitrix/redirect.php?event1=".urlencode($event1)."&event2=".urlencode($arFile["SRC"])."&event3=".urlencode($arFile["ORIGINAL_NAME"])."&goto=".urlencode($arFile["SRC"])).'">'.GetMessage('IBLOCK_DOWNLOAD').'</a>';
else
$arDisplayValue[] = '<a href="'.htmlspecialchars($arFile["SRC"]).'">'.GetMessage('IBLOCK_DOWNLOAD').'</a>';
}
}
else
{
$trimmed = trim($val);
if(strpos($trimmed, "http")===0)
{
if(IsModuleInstalled("statistic"))
$arDisplayValue[] = '<a href="'.htmlspecialchars("/bitrix/redirect.php?event1=".urlencode($event1)."&event2=".urlencode($trimmed)."&event3=".urlencode($arItem["NAME"])."&goto=".urlencode($trimmed)).'">'.$trimmed.'</a>';
else
$arDisplayValue[] = '<a href="'.htmlspecialchars($trimmed).'">'.$trimmed.'</a>';
}
elseif(strpos($trimmed, "www")===0)
{
if(IsModuleInstalled("statistic"))
$arDisplayValue[] = '<a href="'.htmlspecialchars("/bitrix/redirect.php?event1=".urlencode($event1)."&event2=".urlencode("http://".$trimmed)."&event3=".urlencode($arItem["NAME"])."&goto=".urlencode("http://".$trimmed)).'">'.$trimmed.'</a>';
else
$arDisplayValue[] = '<a href="'.htmlspecialchars("http://".$val).'">'.$val.'</a>';
}
else
$arDisplayValue[] = $val;
}
}
if(count($arDisplayValue)==1)
$arProperty["DISPLAY_VALUE"] = $arDisplayValue[0];
elseif(count($arDisplayValue)>1)
$arProperty["DISPLAY_VALUE"] = $arDisplayValue;
else
$arProperty["DISPLAY_VALUE"] = false;
return $arProperty;
}
function DateFormat($format, $timestamp)
{
if(LANG=="en")
return date($format, $timestamp);
elseif(preg_match_all("/[FMlD]/", $format, $matches))
{
$ar = preg_split("/[FMlD]/", $format);
$result = "";
foreach($matches[0] as $i=>$match)
{
switch($match)
{
case "F":$match=GetMessage("T_IBLOCK_MONTH_".date("n", $timestamp));break;
case "M":$match=GetMessage("T_IBLOCK_MON_".date("n", $timestamp));break;
case "l":$match=GetMessage("T_IBLOCK_DAY_OF_WEEK_".date("w", $timestamp));break;
case "D":$match=GetMessage("T_IBLOCK_DOW_".date("w", $timestamp));break;
}
$result .= date($ar[$i], $timestamp).$match;
}
$result .= date($ar[count($ar)-1], $timestamp);
return $result;
}
else
return date($format, $timestamp);
}
}
?>