Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.29 KB | None | 0 0
  1. <?
  2. if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
  3. /** @var CBitrixComponent $this */
  4. /** @var array $arParams */
  5. /** @var array $arResult */
  6. /** @var string $componentPath */
  7. /** @var string $componentName */
  8. /** @var string $componentTemplate */
  9. /** @global CDatabase $DB */
  10. /** @global CUser $USER */
  11. /** @global CMain $APPLICATION */
  12.  
  13.  
  14. if(!isset($arParams["CACHE_TIME"]))
  15.     $arParams["CACHE_TIME"] = 36000000;
  16.  
  17. $arParams["ID"] = intval($arParams["ID"]);
  18. $arParams["IBLOCK_ID"] = intval($arParams["IBLOCK_ID"]);
  19.  
  20. $arParams["DEPTH_LEVEL"] = intval($arParams["DEPTH_LEVEL"]);
  21. if($arParams["DEPTH_LEVEL"]<=0)
  22.     $arParams["DEPTH_LEVEL"]=1;
  23.  
  24. $arResult["SECTIONS"] = array();
  25. $arResult["ELEMENT_LINKS"] = array();
  26.  
  27. if($this->StartResultCache())
  28. {
  29.     if(!CModule::IncludeModule("iblock"))
  30.     {
  31.         $this->AbortResultCache();
  32.     }
  33.     else
  34.     {
  35.    
  36.         $arFilter = array(
  37.             "IBLOCK_ID"=>$arParams["IBLOCK_ID"],
  38.             "GLOBAL_ACTIVE"=>"Y",
  39.             "IBLOCK_ACTIVE"=>"Y",
  40.             "<="."DEPTH_LEVEL" => $arParams["DEPTH_LEVEL"],
  41.             "CNT_ACTIVE" => "Y",
  42.         );
  43.         $arOrder = array(
  44.             "left_margin"=>"asc",
  45.         );
  46.  
  47.         $rsSections = CIBlockSection::GetList($arOrder, $arFilter, true, array(
  48.             "ID",
  49.             "DEPTH_LEVEL",
  50.             "NAME",
  51.             "SECTION_PAGE_URL",
  52.         ));
  53.         if($arParams["IS_SEF"] !== "Y")
  54.             $rsSections->SetUrlTemplates("", $arParams["SECTION_URL"]);
  55.         else
  56.             $rsSections->SetUrlTemplates("", $arParams["SEF_BASE_URL"].$arParams["SECTION_PAGE_URL"]);
  57.         while($arSection = $rsSections->GetNext())
  58.         {
  59.             $arResult["SECTIONS"][] = array(
  60.                 "ID" => $arSection["ID"],
  61.                 "DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"],
  62.                 "~NAME" => $arSection["~NAME"],
  63.                 "~SECTION_PAGE_URL" => $arSection["~SECTION_PAGE_URL"],
  64.             );
  65.             $arResult["ELEMENT_LINKS"][$arSection["ID"]] = array();
  66.             //var_dump($arSection["ELEMENT_CNT"]);
  67.            if(0 == $arSection["ELEMENT_CNT"])
  68.            {
  69.              //var_dump($arSection["ID"]);
  70.              unset($arSection["ID"]);
  71.            }
  72.            
  73.         }
  74.        
  75.         $this->EndResultCache();
  76.     }
  77. }
  78.  
  79. //In "SEF" mode we'll try to parse URL and get ELEMENT_ID from it
  80. if($arParams["IS_SEF"] === "Y")
  81. {
  82.     $engine = new CComponentEngine($this);
  83.     if (CModule::IncludeModule('iblock'))
  84.     {
  85.         $engine->addGreedyPart("#SECTION_CODE_PATH#");
  86.         $engine->setResolveCallback(array("CIBlockFindTools", "resolveComponentEngine"));
  87.     }
  88.     $componentPage = $engine->guessComponentPath(
  89.         $arParams["SEF_BASE_URL"],
  90.         array(
  91.             "section" => $arParams["SECTION_PAGE_URL"],
  92.             "detail" => $arParams["DETAIL_PAGE_URL"],
  93.         ),
  94.         $arVariables
  95.     );
  96.     if($componentPage === "detail")
  97.     {
  98.         CComponentEngine::InitComponentVariables(
  99.             $componentPage,
  100.             array("SECTION_ID", "ELEMENT_ID"),
  101.             array(
  102.                 "section" => array("SECTION_ID" => "SECTION_ID"),
  103.                 "detail" => array("SECTION_ID" => "SECTION_ID", "ELEMENT_ID" => "ELEMENT_ID"),
  104.             ),
  105.             $arVariables
  106.         );
  107.         $arParams["ID"] = intval($arVariables["ELEMENT_ID"]);
  108.     }
  109. }
  110.  
  111. if(($arParams["ID"] > 0) && (intval($arVariables["SECTION_ID"]) <= 0) && CModule::IncludeModule("iblock"))
  112. {
  113.     $arSelect = array("ID", "IBLOCK_ID", "DETAIL_PAGE_URL", "IBLOCK_SECTION_ID");
  114.     $arFilter = array(
  115.         "ID" => $arParams["ID"],
  116.         "ACTIVE" => "Y",
  117.         "IBLOCK_ID" => $arParams["IBLOCK_ID"],
  118.     );
  119.     $rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect);
  120.     if(($arParams["IS_SEF"] === "Y") && (strlen($arParams["DETAIL_PAGE_URL"]) > 0))
  121.         $rsElements->SetUrlTemplates($arParams["SEF_BASE_URL"].$arParams["DETAIL_PAGE_URL"]);
  122.     while($arElement = $rsElements->GetNext())
  123.     {
  124.         $arResult["ELEMENT_LINKS"][$arElement["IBLOCK_SECTION_ID"]][] = $arElement["~DETAIL_PAGE_URL"];
  125.     }
  126. }
  127.  
  128. $aMenuLinksNew = array();
  129. $menuIndex = 0;
  130. $previousDepthLevel = 1;
  131. foreach($arResult["SECTIONS"] as $arSection)
  132. {
  133.     if ($menuIndex > 0)
  134.         $aMenuLinksNew[$menuIndex - 1][3]["IS_PARENT"] = $arSection["DEPTH_LEVEL"] > $previousDepthLevel;
  135.     $previousDepthLevel = $arSection["DEPTH_LEVEL"];
  136.  
  137.     $arResult["ELEMENT_LINKS"][$arSection["ID"]][] = urldecode($arSection["~SECTION_PAGE_URL"]);
  138.     $aMenuLinksNew[$menuIndex++] = array(
  139.         htmlspecialcharsbx($arSection["~NAME"]),
  140.         $arSection["~SECTION_PAGE_URL"],
  141.         $arResult["ELEMENT_LINKS"][$arSection["ID"]],
  142.         array(
  143.             "FROM_IBLOCK" => true,
  144.             "IS_PARENT" => false,
  145.             "DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"],
  146.         ),
  147.     );
  148. }
  149.  
  150. return $aMenuLinksNew;
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement