35 function Init($InitDir, $bMenuExt=
false,
$template=
false, $onlyCurrentDir=
false)
39 $this->
debug !==
false
40 && \
Bitrix\Main\Application::getInstance()->getKernelSession()[
"SESS_SHOW_INCLUDE_TIME_EXEC"] ==
"Y"
43 || \
Bitrix\Main\Application::getInstance()->getKernelSession()[
"SHOW_SQL_STAT"]==
"Y"
48 $this->
debug->Start();
53 $aMenuLinks =
array();
60 $InitDir = str_replace(
"\\",
"/", $InitDir);
72 $site_dir = $arSite[
"DIR"];
77 if($site_dir !==
false && (mb_strlen(trim($Dir,
"/")) < mb_strlen(trim($site_dir,
"/"))))
80 $Dir = rtrim($Dir,
"/");
81 $menu_file_name =
$io->CombinePath(
$_SERVER[
"DOCUMENT_ROOT"], $Dir,
".".$this->type.
".menu.php");
83 if(
$io->FileExists($menu_file_name))
85 include(
$io->GetPhysicalName($menu_file_name));
86 $this->MenuDir = $Dir.
"/";
87 $this->arMenu = $aMenuLinks;
88 $this->
template = $sMenuTemplate;
97 if($pos===
false || $onlyCurrentDir ==
true)
100 $Dir = mb_substr($Dir, 0, $pos + 1);
108 if($site_dir !==
false && (mb_strlen(trim($Dir,
"/")) < mb_strlen(trim($site_dir,
"/"))))
111 $Dir = rtrim($Dir,
"/");
112 $menu_file_name =
$io->CombinePath(
$_SERVER[
"DOCUMENT_ROOT"], $Dir,
".".$this->type.
".menu_ext.php");
114 if(
$io->FileExists($menu_file_name))
116 include(
$io->GetPhysicalName($menu_file_name));
118 $this->MenuDir = $Dir.
"/";
120 $this->MenuExtDir = $Dir.
"/";
121 $this->arMenu = $aMenuLinks;
122 $this->
template = $sMenuTemplate;
131 if($pos===
false || $onlyCurrentDir ==
true)
134 $Dir = mb_substr($Dir, 0, $pos + 1);
141 function RecalcMenu($bMultiSelect =
false, $bCheckSelected =
true)
143 if($this->bMenuCalc !==
false)
160 $this->bMenuCalc =
true;
162 if($this->template <>
'' && file_exists(
$_SERVER[
"DOCUMENT_ROOT"].$this->
template))
164 $this->MenuTemplate =
$_SERVER[
"DOCUMENT_ROOT"].$this->template;
168 if(defined(
"SITE_TEMPLATE_PATH") && file_exists(
$_SERVER[
"DOCUMENT_ROOT"].SITE_TEMPLATE_PATH.
"/".$this->type.
".menu_template.php"))
170 $this->
template = SITE_TEMPLATE_PATH.
"/".$this->type.
".menu_template.php";
171 $this->MenuTemplate =
$_SERVER[
"DOCUMENT_ROOT"].$this->template;
173 elseif(file_exists(
$_SERVER[
"DOCUMENT_ROOT"].BX_PERSONAL_ROOT.
"/php_interface/".LANG.
"/".$this->type.
".menu_template.php"))
175 $this->
template = BX_PERSONAL_ROOT.
"/php_interface/".LANG.
"/".$this->type.
".menu_template.php";
176 $this->MenuTemplate =
$_SERVER[
"DOCUMENT_ROOT"].$this->template;
180 $this->
template = BX_PERSONAL_ROOT.
"/templates/.default/".$this->type.
".menu_template.php";
181 $this->MenuTemplate =
$_SERVER[
"DOCUMENT_ROOT"].$this->template;
185 if(!file_exists($this->MenuTemplate))
187 $this->LAST_ERROR =
"Template ".$this->MenuTemplate.
" is not found.";
193 $bCacheIsAllowed = CACHED_menu!==
false && !
$USER->IsAuthorized() && $this->MenuExtDir ==
'';
204 $arUserRights =
$USER->GetAccessCodes();
208 $cur_selected_len = -1;
209 $previousDepthLevel = -1;
210 $arParents =
array();
212 foreach($this->arMenu as $iMenuItem=>$MenuItem)
214 $TEXT = $MenuItem[0];
218 $LINK = $arMenuCache[$iMenuItem][
"LINK"];
223 if(!preg_match(
"'^(([A-Za-z]+://)|mailto:|javascript:|#)'i", $MenuItem[1]))
225 $LINK =
Rel2Abs($this->MenuDir, $MenuItem[1]);
229 $LINK = $MenuItem[1];
231 $arMenuCache[$iMenuItem][
"LINK"] = $LINK;
234 $bSkipMenuItem =
false;
235 $ADDITIONAL_LINKS = $MenuItem[2] ?? [];
236 $PARAMS = $MenuItem[3] ?? [];
239 if($this->MenuExtDir <>
'' && is_array($PARAMS) && isset($PARAMS[
"FROM_IBLOCK"]))
241 if($previousDepthLevel == -1)
242 $previousDepthLevel = $PARAMS[
"DEPTH_LEVEL"];
244 if($PARAMS[
"DEPTH_LEVEL"] > $previousDepthLevel)
248 $arParents[] =
array(
"INDEX" => $iMenuItem-1,
"DEPTH_LEVEL" => $PARAMS[
"DEPTH_LEVEL"]);
255 && $arParents[
count($arParents)-1][
"DEPTH_LEVEL"] > $PARAMS[
"DEPTH_LEVEL"]
258 array_pop($arParents);
261 $previousDepthLevel = $PARAMS[
"DEPTH_LEVEL"];
263 elseif($previousDepthLevel != -1)
266 $previousDepthLevel = -1;
267 $arParents =
array();
271 if(
count($MenuItem)>4)
273 $CONDITION = $MenuItem[4];
274 if($CONDITION <>
'' && (!eval(
"return ".$CONDITION.
";")))
275 $bSkipMenuItem =
true;
281 if((mb_strpos($LINK,
"?"))!==
false)
283 elseif(str_ends_with($LINK,
"/"))
292 $all_links = $arMenuCache[$iMenuItem][
"LINKS"];
293 if(!is_array($all_links))
294 $all_links =
array();
298 $all_links =
array();
299 if(is_array($ADDITIONAL_LINKS))
301 foreach($ADDITIONAL_LINKS as $link)
303 $tested_link = trim(
Rel2Abs($this->MenuDir, $link));
304 if($tested_link <>
'')
305 $all_links[] = $tested_link;
308 $all_links[] = $LINK;
309 $arMenuCache[$iMenuItem][
"LINKS"] = $all_links;
312 if(preg_match(
"'^(([A-Za-z]+://)|mailto:|javascript:|#)'i", $MenuItem[1]))
318 if(!$bSkipMenuItem && $bCheckSelected)
320 foreach($all_links as $tested_link)
322 if($tested_link ==
'')
332 $PERMISSION = $arMenuCache[$iMenuItem][
"PERM"];
337 if($SELECTED && !$bMultiSelect)
340 $new_len = mb_strlen($tested_link);
341 if($new_len > $cur_selected_len)
343 if($cur_selected !== -1)
344 $result[$cur_selected][
'SELECTED'] =
false;
347 $cur_selected_len = $new_len;
358 && $this->MenuExtDir <>
''
360 && isset($PARAMS[
"FROM_IBLOCK"])
363 foreach($arParents as $parentMenuItem)
365 $parentIndex = $parentMenuItem[
"INDEX"];
367 is_array(
$result[$parentIndex][
"PARAMS"])
368 && isset(
$result[$parentIndex][
"PARAMS"][
"FROM_IBLOCK"])
370 $result[$parentIndex][
"SELECTED"] =
true;
379 "SELECTED" => $SELECTED,
380 "PERMISSION" => $PERMISSION,
381 "ADDITIONAL_LINKS" => $ADDITIONAL_LINKS,
382 "ITEM_TYPE" => $ITEM_TYPE,
383 "ITEM_INDEX" => $ITEM_INDEX,
393 if($bCacheIsAllowed && !$bCached)
402 public static function IsItemSelected($tested_link, $cur_page, $cur_page_no_index)
407 if(mb_strpos($cur_page, $tested_link) === 0 || mb_strpos($cur_page_no_index, $tested_link) === 0)
410 if(($pos = mb_strpos($tested_link,
"?")) !==
false)
412 if(($s = mb_substr($tested_link, 0, $pos)) == $cur_page || $s == $cur_page_no_index)
414 $params = explode(
"&", mb_substr($tested_link, $pos + 1));
418 $eqpos = mb_strpos($param,
"=");
430 $varname = mb_substr($param, 0, $eqpos);
431 $varvalue = urldecode(mb_substr($param, $eqpos + 1));
434 $globvarvalue = (
$GLOBALS[$varname] ??
"");
435 if($globvarvalue != $varvalue)
468 include($this->MenuTemplate);
473 $bShowButtons =
false;
474 $sMenuFile = $this->MenuDir.
".".$this->type.
".menu.php";
477 $menu_perm =
$APPLICATION->GetFileAccessPermission($sMenuFile);
478 $templ_perm =
$APPLICATION->GetFileAccessPermission($this->
template);
479 if($menu_perm >=
"W")
482 "URL"=>
"/bitrix/admin/fileman_menu_edit.php?lang=".LANGUAGE_ID.
"&site=".
SITE_ID.
"&back_url=".urlencode(
$_SERVER[
"REQUEST_URI"]).
"&path=".urlencode($this->MenuDir).
"&name=".$this->type,
487 if($templ_perm>=
"W" &&
$USER->IsAdmin())
490 "URL"=>
"/bitrix/admin/fileman_file_edit.php?lang=".LANGUAGE_ID.
"&site=".
SITE_ID.
"&back_url=".urlencode(
$_SERVER[
"REQUEST_URI"]).
"&full_src=Y&path=".urlencode($this->
template),
491 "ICON"=>
"menu-template",
492 "TITLE"=>
GetMessage(
"MAIN_MENU_TEMPLATE_EDIT")
498 $bShowButtons =
true;
503 $result .= $this->
debug->Output($sMenuFile, $sMenuFile);
531 $sMenuPrologTmp =
"";
536 $m = $this->arMenu[
$i];
541 extract($m, EXTR_OVERWRITE);
552 include($this->MenuTemplate);
555 $sMenuPrologTmp = $sMenuProlog;
559 $result = $sMenuPrologTmp.$result.$sMenuEpilog;
562 $bShowButtons =
false;
563 $sMenuFile = $this->MenuDir.
".".$this->type.
".menu.php";
566 $menu_perm =
$APPLICATION->GetFileAccessPermission($sMenuFile);
567 $templ_perm =
$APPLICATION->GetFileAccessPermission($this->
template);
568 if($menu_perm >=
"W")
571 "URL"=>
"/bitrix/admin/fileman_menu_edit.php?lang=".LANGUAGE_ID.
"&site=".
SITE_ID.
"&back_url=".urlencode(
$_SERVER[
"REQUEST_URI"]).
"&path=".urlencode($this->MenuDir).
"&name=".$this->type,
577 if($templ_perm >=
"W" &&
$USER->IsAdmin())
580 "URL"=>
"/bitrix/admin/fileman_file_edit.php?lang=".LANGUAGE_ID.
"&site=".
SITE_ID.
"&back_url=".urlencode(
$_SERVER[
"REQUEST_URI"]).
"&full_src=Y&path=".urlencode($this->
template),
581 "ICON"=>
"menu-template",
582 "TITLE"=>
GetMessage(
"MAIN_MENU_TEMPLATE_EDIT")
589 $bShowButtons =
true;
594 $result .= $this->
debug->Output($sMenuFile, $sMenuFile);