static function GetULRsFromIBlockID($IBLOCK_ID, $params = array())
{
$IBLOCK_ID = intval($IBLOCK_ID);
if ($IBLOCK_ID <= 0)
return false;
$params = (is_array($params) ? $params : array());
$params["path"] = trim(!!$params["path"] ? $params["path"] : (!!$params["PATH"] ? $params["PATH"] : ""));
if (empty($params["path"]))
{
$params["path"] = CIBlock::GetArrayByID($IBLOCK_ID, "DETAIL_PAGE_URL");
}
// Params for socialnetwork
static $arExtranetSite = false;
static $defSite = false;
$params["SECTION_ID"] = intval($params["SECTION_ID"]); // root section id
$params["ELEMENT_ID"] = intval($params["ELEMENT_ID"]);
$arSection = (is_array($params["SECTION"]) ? $params["SECTION"] : array()); // root section
$arElement = (is_array($params["ELEMENT"]) ? $params["ELEMENT"] : array());
if (empty($arSection))
{
if ($params["SECTION_ID"] > 0)
{
$arSection = CIBlockSection::GetList(array(),
array(
"ID" => $params["SECTION_ID"],
'CHECK_PERMISSIONS' => 'N'
),
false,
array('ID', 'IBLOCK_ID', 'SOCNET_GROUP_ID', 'CREATED_BY')
)->fetch();
}
else
{
if ($params["ELEMENT_ID"] > 0 && empty($arElement))
$arElement = CIBlockElement::GetList(array(), array('ID' => $params["ELEMENT_ID"]), false, false,
array('ID', 'IBLOCK_SECTION_ID', 'IBLOCK_CODE', 'IBLOCK_ID'))->fetch();
if (!empty($arElement) && $arElement["IBLOCK_SECTION_ID"] > 0)
{
$res = CWebDavSymlinkHelper::getNavChain($IBLOCK_ID, $arElement["IBLOCK_SECTION_ID"]);
if (!!$res)
$arSection = reset($res);
}
}
}
if (empty($arSection) || $arSection["IBLOCK_ID"] != $IBLOCK_ID)
{
$arSection = array(); $arElement = array();
}
// Params for socialnetwork /
if (mb_strpos($params["path"], "#SITE_DIR#") !== false)
$params["path"] = str_replace("#SITE_DIR#", SITE_DIR, $params["path"]);
else if (array_key_exists("SITE_ID", $params) && CModule::IncludeModule('extranet') && (CExtranet::GetExtranetSiteID() == $params["SITE_ID"]))
{
if($arExtranetSite === false)
{
$rsSites = CSite::GetByID(SITE_ID);
$arExtranetSite = $rsSites->Fetch();
unset($rsSites);
}
if ( $arExtranetSite )
{
if($defSite === false)
{
$defSite = CSite::GetDefSite();
}
$params["path"] = $arExtranetSite["DIR"] . $params["path"];
}
}
$SEF_FOLDER = "/";
$SEF_URL_TEMPLATES = array();
$arUrlRewrite = CUrlRewriter::GetList(!empty($params["path"]) ? array("QUERY" => str_replace("//", "/", $params["path"])) : array());
$entity = false;
foreach($arUrlRewrite as $arRule)
{
if (! in_array($arRule["ID"], array(
"bitrix:webdav",
"bitrix:socialnetwork",
"bitrix:socialnetwork_user",
"bitrix:socialnetwork_group")))
continue;
$arComponents = WDGetComponentsOnPage($arRule["PATH"]);
$firstMet = !empty($params["path"]);
foreach ($arComponents as $arComponent)
{
if ($arComponent["COMPONENT_NAME"] == $arRule["ID"])
{
$SEF_FOLDER = $arComponent["PARAMS"]["SEF_FOLDER"];
if (mb_strpos($arRule["ID"], "bitrix:socialnetwork") === 0)
{
if ($arRule["ID"] == "bitrix:socialnetwork" &&
$arComponent["PARAMS"]["FILES_GROUP_IBLOCK_ID"] == $arComponent["PARAMS"]["FILES_USER_IBLOCK_ID"] &&
($firstMet || $arComponent["PARAMS"]["FILES_USER_IBLOCK_ID"] == $IBLOCK_ID))
{
$entity = ($arSection["SOCNET_GROUP_ID"] > 0 ? "group" : "user");
}
else if ( ($firstMet || $arComponent["PARAMS"]["FILES_USER_IBLOCK_ID"] == $IBLOCK_ID) &&
($arRule["ID"] == "bitrix:socialnetwork_user" || $arRule["ID"] == "bitrix:socialnetwork") )
{
$entity = "user";
}
else if ( ($firstMet || $arComponent["PARAMS"]["FILES_GROUP_IBLOCK_ID"] == $IBLOCK_ID) &&
($arRule["ID"] == "bitrix:socialnetwork_group" || $arRule["ID"] == "bitrix:socialnetwork") )
{
$entity = "group";
}
if (!!$entity)
{
$SEF_URL_TEMPLATES = ($entity == "user" ?
array(
"path" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["user_files"],
"view" => "user/#user_id#/files/element/view/#element_id#/",
"edit" => "user/#user_id#/files/element/edit/#element_id#/#action#/",
"history" => "user/#user_id#/files/element/history/#element_id#/",
"history_get" => "user/#user_id#/files/element/historyget/#element_id#/#element_name#"
) :
array(
"path" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["group_files"],
"view" => "group/#group_id#/files/element/view/#element_id#/",
"edit" => "group/#group_id#/files/element/edit/#element_id#/#action#/",
"history" => "group/#group_id#/files/element/history/#element_id#/",
"history_get" => "group/#group_id#/files/element/historyget/#element_id#/#element_name#"
)
);
}
}
else if ($arRule["ID"] == "bitrix:webdav" && ($firstMet || $arComponent["PARAMS"]["IBLOCK_ID"] == $IBLOCK_ID))
{
$entity = "lib";
$SEF_URL_TEMPLATES = array(
"path" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["sections"],
"view" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["element"],
"edit" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["element_edit"],
"history" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["element_history"],
"history_get" => $arComponent["PARAMS"]["SEF_URL_TEMPLATES"]["element_history_get"]
);
}
if (!!$entity)
{
$SEF_URL_TEMPLATES["component"] = $arRule["ID"];
break 2;
}
}
}
}
$repl = array("#id#", "#ELEMENT_ID#", "#element_id#", "#name#", "#ELEMENT_NAME#", "#element_name#", "#action#", "//");
$patt = array("#ELEMENT_ID#", "#ELEMENT_ID#", "#ELEMENT_ID#", "#ELEMENT_NAME#", "#ELEMENT_NAME#", "#ELEMENT_NAME#", "#ACTION#", "/");
if ($entity != "lib")
{
$repl[] = "#SOCNET_USER_ID#"; $patt[] = "#USER_ID#";
$repl[] = "#socnet_user_id#"; $patt[] = "#USER_ID#";
$repl[] = "#user_id#"; $patt[] = "#USER_ID#";
$repl[] = "#SOCNET_GROUP_ID#"; $patt[] = "#GROUP_ID#";
$repl[] = "#socnet_group_id#"; $patt[] = "#GROUP_ID#";
$repl[] = "#group_id#"; $patt[] = "#GROUP_ID#";
$repl[] = "#SOCNET_OBJECT_ID#"; $patt[] = "#SOCNET_OBJECT#";
$repl[] = "#socnet_object_id#"; $patt[] = "#SOCNET_OBJECT#";
$repl[] = "#socnet_object#"; $patt[] = "#SOCNET_OBJECT#";
if (!empty($arSection))
{
$repl[] = "#USER_ID#"; $patt[] = $arSection["CREATED_BY"];
$repl[] = "#GROUP_ID#"; $patt[] = $arSection["SOCNET_GROUP_ID"];
$patt[] = "#SOCNET_OBJECT#"; $patt[] = ($arSection["SOCNET_GROUP_ID"] > 0 ? "group" : "user");
}
}
if (!empty($arElement))
{
$repl[] = "#ID#"; $patt[] = $arElement["ID"];
$repl[] = "#ELEMENT_ID#"; $patt[] = $arElement["ID"];
$repl[] = "#NAME#"; $patt[] = $arElement["NAME"];
$repl[] = "#ELEMENT_NAME#"; $patt[] = $arElement["NAME"];
}
foreach($SEF_URL_TEMPLATES as $key => $val)
$SEF_URL_TEMPLATES[$key] = str_replace($repl, $patt, $SEF_FOLDER ."/". $val);
$SEF_URL_TEMPLATES["path"] = str_replace(array("#path#", "#PATH#"), "", $SEF_URL_TEMPLATES["path"]);
$SEF_URL_TEMPLATES["delete_dropped"] = str_replace("#ACTION#", "delete_dropped", $SEF_URL_TEMPLATES["edit"]);
$SEF_URL_TEMPLATES["edit"] = str_replace("#ACTION#", "edit", $SEF_URL_TEMPLATES["edit"]);
$SEF_URL_TEMPLATES["entity"] = $entity;
return $SEF_URL_TEMPLATES;
}