- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/wizard_site.php
- Класс: CWizard
- Вызов: CWizard::__InstallStructure
function __InstallStructure()
{
global $APPLICATION;
if ($this->structureID == '')
return;
$arStructure = $this->GetStructure(
Array(
"SERVICE_ID" => $this->serviceID,
"SITE_ID" => $this->siteID
)
);
//If the main module was not included
require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include.php");
$arStructure = $this->__GetNewStructure($this->structureID, $arStructure);
function __CreateMenuItem($arPage)
{
return "n".
" Array(n".
" "".$arPage["NAME"]."", n".
" "".$arPage["LINK"]."", n".
" Array(), n".
" Array(), n".
" ""n".
" ),";
}
function __GetFileName($fileName, $postFix)
{
if ($postFix == "")
return $fileName;
$position = mb_strrpos($fileName, ".");
if ($position !== false)
$fileName = mb_substr($fileName, 0, $position).$postFix.mb_substr($fileName, $position);
return $fileName;
}
$rootMenuType = (isset($this->arStructure["SETTINGS"]) && isset($this->arStructure["SETTINGS"]["ROOT_MENU_TYPE"])
? $this->arStructure["SETTINGS"]["ROOT_MENU_TYPE"]
: "top"
);
$childMenuType = (isset($this->arStructure["SETTINGS"]) && isset($this->arStructure["SETTINGS"]["CHILD_MENU_TYPE"])
? $this->arStructure["SETTINGS"]["CHILD_MENU_TYPE"]
: "left"
);
$strRootMenu = "";
$arFileToMove = Array();
$arPageCnt = Array();
foreach ($arStructure as $rootPageID => $arPage)
{
//Item type "service"
if (isset($arPage["TYPE"]) && mb_strtoupper($arPage["TYPE"]) == "SERVICE")
{
$strRootMenu .= __CreateMenuItem($arPage);
}
else
{
if (isset($arPage["CHILD"]) && is_array($arPage["CHILD"]) && !empty($arPage["CHILD"]))
{
$strLeftMenu = "";
if ( ($position = mb_strrpos($rootPageID, "-")) !== false)
$rootPageID = mb_substr($rootPageID, $position + 1, mb_strlen($rootPageID));
//Root item
$arFileToMove[] = Array(
$_SERVER["DOCUMENT_ROOT"].$this->path."/".$arPage["FILE"],
$_SERVER["DOCUMENT_ROOT"]."/".$rootPageID."/index.php"
);
$arPage["LINK"] = "/".$rootPageID."/";
$strRootMenu .= __CreateMenuItem($arPage);
//Child items
$arSubPageCnt = Array();
foreach ($arPage["CHILD"] as $subPageID => $arSubPage)
{
$fileName = basename($arSubPage["FILE"]);
if (array_key_exists($fileName, $arSubPageCnt))
(int)$arSubPageCnt[$fileName]++;
else
$arSubPageCnt[$fileName] = "";
$fileName = __GetFileName($fileName, $arSubPageCnt[$fileName]);
$arFileToMove[] = Array(
$_SERVER["DOCUMENT_ROOT"].$this->path."/".$arSubPage["FILE"],
$_SERVER["DOCUMENT_ROOT"]."/".$rootPageID."/".$fileName
);
$arSubPage["LINK"] = "/".$rootPageID."/".$fileName;
$strLeftMenu .= __CreateMenuItem($arSubPage);
}
if ($strLeftMenu <> '')
{
$strSectionName = "$sSectionName = "".$arPage["NAME"]."";n";
$APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"]."/".$rootPageID."/.section.php", "<"."?n".$strSectionName."?".">");
$strLeftMenu = "$aMenuLinks = Array(".$strLeftMenu."n);";
$APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"]."/".$rootPageID."/.".$childMenuType.".menu.php", "<"."?n".$strLeftMenu."n?".">");
}
}
else
{
$fileName = basename($arPage["FILE"]);
if (array_key_exists($fileName, $arPageCnt))
(int)$arPageCnt[$fileName]++;
else
$arPageCnt[$fileName] = "";
$fileName = __GetFileName($fileName, $arPageCnt[$fileName]);
$arFileToMove[] = Array(
$_SERVER["DOCUMENT_ROOT"].$this->path."/".$arPage["FILE"],
$_SERVER["DOCUMENT_ROOT"]."/".$fileName,
);
$arPage["LINK"] = "/".$fileName;
$strRootMenu .= __CreateMenuItem($arPage);
}
}
}
//Save top menu
if ($strRootMenu <> '')
{
$strRootMenu = "$aMenuLinks = Array(".$strRootMenu."n);";
$APPLICATION->SaveFileContent($_SERVER["DOCUMENT_ROOT"]."/.".$rootMenuType.".menu.php", "<"."?n".$strRootMenu."n?".">");
}
//Copy files for menu items
foreach ($arFileToMove as $arFile)
CopyDirFiles($arFile[0], $arFile[1]);
}