コード例 #1
0
 function _GetChildMenuRecursive(&$arMenu, &$arResult, $menuType, $use_ext, $menuTemplate, $currentLevel, $maxLevel, $bMultiSelect, $bCheckSelected)
 {
     if ($currentLevel > $maxLevel) {
         return;
     }
     for ($menuIndex = 0, $menuCount = count($arMenu); $menuIndex < $menuCount; $menuIndex++) {
         //Menu from iblock (bitrix:menu.sections)
         if (is_array($arMenu[$menuIndex]["PARAMS"]) && isset($arMenu[$menuIndex]["PARAMS"]["FROM_IBLOCK"])) {
             $iblockSectionLevel = intval($arMenu[$menuIndex]["PARAMS"]["DEPTH_LEVEL"]);
             if ($currentLevel > 1) {
                 $iblockSectionLevel = $iblockSectionLevel + $currentLevel - 1;
             }
             $arResult[] = $arMenu[$menuIndex] + array("DEPTH_LEVEL" => $iblockSectionLevel, "IS_PARENT" => $arMenu[$menuIndex]["PARAMS"]["IS_PARENT"]);
             continue;
         }
         //Menu from files
         $subMenuExists = false;
         if ($currentLevel < $maxLevel) {
             //directory link only
             $bDir = false;
             if (!preg_match("'^(([a-z]+://)|mailto:|javascript:)'i", $arMenu[$menuIndex]["LINK"])) {
                 if (substr($arMenu[$menuIndex]["LINK"], -1) == "/") {
                     $bDir = true;
                 }
             }
             if ($bDir) {
                 $menu = new CMenu($menuType);
                 $success = $menu->Init($arMenu[$menuIndex]["LINK"], $use_ext, $menuTemplate, $onlyCurrentDir = true);
                 $subMenuExists = $success && count($menu->arMenu) > 0;
                 if ($subMenuExists) {
                     $menu->RecalcMenu($bMultiSelect, $bCheckSelected);
                     $arResult[] = $arMenu[$menuIndex] + array("DEPTH_LEVEL" => $currentLevel, "IS_PARENT" => count($menu->arMenu) > 0);
                     if ($arMenu[$menuIndex]["SELECTED"]) {
                         $arResult["menuType"] = $menuType;
                         $arResult["menuDir"] = $arMenu[$menuIndex]["LINK"];
                     }
                     if (count($menu->arMenu) > 0) {
                         _GetChildMenuRecursive($menu->arMenu, $arResult, $menuType, $use_ext, $menuTemplate, $currentLevel + 1, $maxLevel, $bMultiSelect, $bCheckSelected);
                     }
                 }
             }
         }
         if (!$subMenuExists) {
             $arResult[] = $arMenu[$menuIndex] + array("DEPTH_LEVEL" => $currentLevel, "IS_PARENT" => false);
         }
     }
 }
コード例 #2
0
}
global $CACHE_MANAGER;
if ($arParams["MENU_CACHE_TIME"] && $CACHE_MANAGER->Read($arParams["MENU_CACHE_TIME"], $strCacheID, "menu")) {
    $arResult = $CACHE_MANAGER->Get($strCacheID);
} else {
    if ($arParams["MENU_CACHE_TIME"] && defined("BX_COMP_MANAGED_CACHE")) {
        $CACHE_MANAGER->StartTagCache("managed:menu");
    }
    //Read root menu
    $menu = new CMenu($arParams["ROOT_MENU_TYPE"]);
    $menu->Init($curDir, $arParams["USE_EXT"], $componentPath . "/stub.php");
    $menu->RecalcMenu($arParams["ALLOW_MULTI_SELECT"], $arParams["CACHE_SELECTED_ITEMS"]);
    $arResult = array();
    //Read child menu recursive
    if ($arParams["MAX_LEVEL"] > 1) {
        _GetChildMenuRecursive($menu->arMenu, $arResult, $arParams["CHILD_MENU_TYPE"], $arParams["USE_EXT"], $menu->template, $currentLevel = 1, $arParams["MAX_LEVEL"], $arParams["ALLOW_MULTI_SELECT"], $arParams["CACHE_SELECTED_ITEMS"]);
        if ($arParams["SHOW_LAST_LEVEL_BUTTONS"] != "Y") {
            $arResult["menuDir"] = $menu->MenuDir;
            $arResult["menuType"] = $menu->type;
        } else {
            $arResult["initMenuDir"] = $menu->MenuDir;
            $arResult["initMenuType"] = $menu->type;
        }
    } else {
        $arResult = $menu->arMenu;
        $arResult["menuDir"] = $menu->MenuDir;
        $arResult["menuType"] = $menu->type;
        for ($menuIndex = 0, $menuCount = count($menu->arMenu); $menuIndex < $menuCount; $menuIndex++) {
            //Menu from iblock (bitrix:menu.sections)
            if (is_array($arResult[$menuIndex]["PARAMS"]) && isset($arResult[$menuIndex]["PARAMS"]["FROM_IBLOCK"])) {
                $arResult[$menuIndex]["DEPTH_LEVEL"] = $arResult[$menuIndex]["PARAMS"]["DEPTH_LEVEL"];