PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/menu/templates/catalog_horizontal_old/result_modifier.php

https://gitlab.com/alexprowars/bitrix
PHP | 250 lines | 231 code | 18 blank | 1 comment | 63 complexity | a691ec93f6f7b2170f3113ba555159e2 MD5 | raw file
  1. <?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
  2. if (empty($arResult))
  3. return;
  4. if (isset($arParams["MENU_THEME"]) && !empty($arParams["MENU_THEME"]))
  5. {
  6. $arAvailableThemes = array();
  7. $dir = trim(preg_replace("'[\\\\/]+'", "/", dirname(__FILE__)."/themes/"));
  8. if (is_dir($dir) && $directory = opendir($dir))
  9. {
  10. while (($file = readdir($directory)) !== false)
  11. {
  12. if ($file != "." && $file != ".." && is_dir($dir.$file))
  13. $arAvailableThemes[] = $file;
  14. }
  15. closedir($directory);
  16. }
  17. if ($arParams["MENU_THEME"] == "site")
  18. {
  19. $solution = COption::GetOptionString("main", "wizard_solution", "", SITE_ID);
  20. if ($solution == "eshop")
  21. {
  22. $theme = COption::GetOptionString("main", "wizard_eshop_adapt_theme_id", "blue", SITE_ID);
  23. $arParams["MENU_THEME"] = (in_array($theme, $arAvailableThemes)) ? $theme : "blue";
  24. }
  25. }
  26. else
  27. {
  28. $arParams["MENU_THEME"] = (in_array($arParams["MENU_THEME"], $arAvailableThemes)) ? $arParams["MENU_THEME"] : "blue";
  29. }
  30. }
  31. else
  32. {
  33. $arParams["MENU_THEME"] = "blue";
  34. }
  35. if(!function_exists("FillAllPicturesAndDescriptions"))
  36. {
  37. function FillAllPicturesAndDescriptions(&$arAllItems, $arMenuItemsIDs)
  38. {
  39. //find picture or description for the first level, if it hasn't
  40. foreach ($arMenuItemsIDs as $itemIdLevel_1=>$arLevels2)
  41. {
  42. if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] || !$arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
  43. {
  44. foreach($arLevels2 as $itemIdLevel_2=>$arLevels3)
  45. {
  46. if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_2]["PARAMS"]["picture_src"])
  47. {
  48. $arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] = $arAllItems[$itemIdLevel_2]["PARAMS"]["picture_src"];
  49. }
  50. if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["description"] && $arAllItems[$itemIdLevel_2]["PARAMS"]["description"])
  51. {
  52. $arAllItems[$itemIdLevel_1]["PARAMS"]["description"] = $arAllItems[$itemIdLevel_2]["PARAMS"]["description"];
  53. }
  54. if ($arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
  55. break;
  56. }
  57. if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] || !$arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
  58. {
  59. foreach($arLevels2 as $itemIdLevel_2=>$arLevels3)
  60. {
  61. foreach($arLevels3 as $itemIdLevel_3)
  62. {
  63. if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_3]["PARAMS"]["picture_src"])
  64. {
  65. $arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] = $arAllItems[$itemIdLevel_3]["PARAMS"]["picture_src"];
  66. }
  67. if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["description"] && $arAllItems[$itemIdLevel_3]["PARAMS"]["description"])
  68. {
  69. $arAllItems[$itemIdLevel_1]["PARAMS"]["description"] = $arAllItems[$itemIdLevel_3]["PARAMS"]["description"];
  70. }
  71. if ($arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"])
  72. break;
  73. }
  74. if ($arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
  75. break;
  76. }
  77. }
  78. }
  79. }
  80. foreach($arAllItems as $itemID=>$arItem)
  81. {
  82. if ($arItem["DEPTH_LEVEL"] == "1")
  83. {
  84. if ($arItem["IS_PARENT"])
  85. {
  86. $pictureLevel_1 = $arItem["PARAMS"]["picture_src"];
  87. $descriptionLevel_1 = $arItem["PARAMS"]["description"];
  88. }
  89. $arAllItems[$itemID] = $arItem;
  90. }
  91. elseif($arItem["DEPTH_LEVEL"] == "2")
  92. {
  93. if (!$arItem["PARAMS"]["picture_src"])
  94. $arItem["PARAMS"]["picture_src"] = $pictureLevel_1;
  95. if (!$arItem["PARAMS"]["description"])
  96. $arItem["PARAMS"]["description"] = $descriptionLevel_1;
  97. if ($arItem["IS_PARENT"])
  98. {
  99. $pictureLevel_2 = $arItem["PARAMS"]["picture_src"];
  100. $descriptionLevel_2 = $arItem["PARAMS"]["description"];
  101. }
  102. $arAllItems[$itemID] = $arItem;
  103. }
  104. elseif($arItem["DEPTH_LEVEL"] == "3")
  105. {
  106. if (!$arItem["PARAMS"]["picture_src"])
  107. $arItem["PARAMS"]["picture_src"] = $pictureLevel_2;
  108. if (!$arItem["PARAMS"]["description"])
  109. $arItem["PARAMS"]["description"] = $descriptionLevel_2;
  110. $arAllItems[$itemID] = $arItem;
  111. }
  112. }
  113. }
  114. }
  115. $arSectionsInfo = array();
  116. if (IsModuleInstalled("iblock"))
  117. {
  118. $arFilter = array(
  119. "TYPE" => "catalog",
  120. "SITE_ID" => SITE_ID,
  121. "ACTIVE" => "Y"
  122. );
  123. $obCache = new CPHPCache();
  124. if ($obCache->InitCache(36000, serialize($arFilter), "/iblock/menu"))
  125. {
  126. $arSectionsInfo = $obCache->GetVars();
  127. }
  128. elseif ($obCache->StartDataCache())
  129. {
  130. if (CModule::IncludeModule("iblock"))
  131. {
  132. $dbIBlock = CIBlock::GetList(array('SORT' => 'ASC', 'ID' => 'ASC'), $arFilter);
  133. $dbIBlock = new CIBlockResult($dbIBlock);
  134. $curIblockID = 0;
  135. if ($arIBlock = $dbIBlock->GetNext())
  136. {
  137. $dbSections = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $arIBlock["ID"]), false, array("ID", "SECTION_PAGE_URL", "PICTURE", "DESCRIPTION"));
  138. while($arSections = $dbSections->GetNext())
  139. {
  140. $pictureSrc = CFile::GetFileArray($arSections["PICTURE"]);
  141. if ($pictureSrc)
  142. $arResizePicture = CFile::ResizeImageGet(
  143. $arSections["PICTURE"],
  144. array("width" => 240, 'height'=>700),
  145. BX_RESIZE_IMAGE_PROPORTIONAL,
  146. true
  147. );
  148. $arSectionsInfo[crc32($arSections["SECTION_PAGE_URL"])]["PICTURE"] = $pictureSrc ? $arResizePicture["src"] : false;
  149. $arSectionsInfo[crc32($arSections["SECTION_PAGE_URL"])]["DESCRIPTION"] = $arSections["DESCRIPTION"];
  150. }
  151. if(defined("BX_COMP_MANAGED_CACHE"))
  152. {
  153. global $CACHE_MANAGER;
  154. $CACHE_MANAGER->StartTagCache("/iblock/menu");
  155. $CACHE_MANAGER->RegisterTag("iblock_id_".$arIBlock["ID"]);
  156. $CACHE_MANAGER->EndTagCache();
  157. }
  158. }
  159. }
  160. $obCache->EndDataCache($arSectionsInfo);
  161. }
  162. }
  163. $arMenuItemsIDs = array();
  164. $arAllItems = array();
  165. foreach($arResult as $key=>$arItem)
  166. {
  167. if($arItem["DEPTH_LEVEL"] > $arParams["MAX_LEVEL"])
  168. {
  169. unset($arResult[$key]);
  170. continue;
  171. }
  172. $arItem["PARAMS"]["item_id"] = crc32($arItem["LINK"]);
  173. $arItem["PARAMS"]["picture_src"] = $arSectionsInfo[$arItem["PARAMS"]["item_id"]]["PICTURE"];
  174. $arItem["PARAMS"]["description"] = $arSectionsInfo[$arItem["PARAMS"]["item_id"]]["DESCRIPTION"];
  175. if ($arItem["DEPTH_LEVEL"] == "1")
  176. {
  177. $arMenuItemsIDs[$arItem["PARAMS"]["item_id"]] = array();
  178. if ($arItem["IS_PARENT"])
  179. {
  180. $curItemLevel_1 = $arItem["PARAMS"]["item_id"];
  181. }
  182. $arAllItems[$arItem["PARAMS"]["item_id"]] = $arItem;
  183. }
  184. elseif($arItem["DEPTH_LEVEL"] == "2")
  185. {
  186. $arMenuItemsIDs[$curItemLevel_1][$arItem["PARAMS"]["item_id"]] = array();
  187. if ($arItem["IS_PARENT"])
  188. {
  189. $curItemLevel_2 = $arItem["PARAMS"]["item_id"];
  190. }
  191. $arAllItems[$arItem["PARAMS"]["item_id"]] = $arItem;
  192. }
  193. elseif($arItem["DEPTH_LEVEL"] == "3")
  194. {
  195. $arMenuItemsIDs[$curItemLevel_1][$curItemLevel_2][] = $arItem["PARAMS"]["item_id"];
  196. $arAllItems[$arItem["PARAMS"]["item_id"]] = $arItem;
  197. }
  198. }
  199. FillAllPicturesAndDescriptions($arAllItems, $arMenuItemsIDs);
  200. $arMenuStructure = array();
  201. foreach ($arMenuItemsIDs as $itemIdLevel_1=>$arLevels2)
  202. {
  203. $countItemsInRow = 18;
  204. $arMenuStructure[$itemIdLevel_1] = array();
  205. $countLevels2 = count($arLevels2);
  206. if ($countLevels2 > 0)
  207. {
  208. for ($i=1; $i<=3; $i++)
  209. {
  210. $sumElementsInRow = 0;
  211. foreach($arLevels2 as $itemIdLevel_2=>$arLevels3)
  212. {
  213. $sumElementsInRow+= count($arLevels3) + 1;
  214. $arMenuStructure[$itemIdLevel_1][$i][$itemIdLevel_2] = $arLevels3;
  215. if ($sumElementsInRow > $countItemsInRow)
  216. $countItemsInRow = $sumElementsInRow;
  217. unset($arLevels2[$itemIdLevel_2]);
  218. $tmpCount = 0;
  219. foreach($arLevels2 as $tmpItemIdLevel_2=>$arTmpLevels3)
  220. {
  221. $tmpCount+= 1 + count($arTmpLevels3);
  222. }
  223. if ($tmpCount <= $countItemsInRow*(3-$i) && $countItemsInRow<=$sumElementsInRow)
  224. break;
  225. }
  226. }
  227. }
  228. }
  229. $arResult = array();
  230. $arResult["ALL_ITEMS"] = $arAllItems;
  231. $arResult["ALL_ITEMS_ID"] = $arMenuItemsIDs;
  232. $arResult["MENU_STRUCTURE"] = $arMenuStructure;