Пример #1
0
 public 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);
                 $menu->disableDebug();
                 $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) {
                         $this->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
//Include menu_ext.php
$arParams["USE_EXT"] = isset($arParams["USE_EXT"]) && $arParams["USE_EXT"] == "Y" ? true : false;
$arParams["DELAY"] = isset($arParams["DELAY"]) && $arParams["DELAY"] == "Y" ? "Y" : "N";
//Allow multiple highlightning of current item in menu
$arParams["ALLOW_MULTI_SELECT"] = $arParams["ALLOW_MULTI_SELECT"] == "Y";
//Find current menu item in RecalcMenu(). Cach ID depends on this parameter too
$arParams["CACHE_SELECTED_ITEMS"] = $arParams["CACHE_SELECTED_ITEMS"] != "N" && $arParams["CACHE_SELECTED_ITEMS"] !== false;
$curDir = $APPLICATION->GetCurDir();
if ($this->startResultCache(false, false, $arParams["MENU_CACHE_USE_USERS"] === "Y" ? $this->getGenerationCachePath($USER->GetID()) : false)) {
    if (defined("BX_COMP_MANAGED_CACHE")) {
        $CACHE_MANAGER->registerTag("bitrix: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) {
        $this->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;