1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
menu.php
См. документацию.
1<?php
2
9
10IncludeModuleLangFile(__FILE__);
11
12class CMenu
13{
14 var $type = "left";
15 var $arMenu = array();
16 var $bMenuCalc = false;
17 var $MenuDir = "";
18 var $MenuExtDir = "";
19 var $MenuTemplate = "";
20 var $template = "";
21 var $LAST_ERROR = "";
23 var $debug = null;
24
25 public function __construct($type="left")
26 {
27 $this->type = $type;
28 }
29
30 function disableDebug()
31 {
32 $this->debug = false;
33 }
34
35 function Init($InitDir, $bMenuExt=false, $template=false, $onlyCurrentDir=false)
36 {
37 global $USER;
38 if(
39 $this->debug !== false
40 && \Bitrix\Main\Application::getInstance()->getKernelSession()["SESS_SHOW_INCLUDE_TIME_EXEC"] == "Y"
41 && (
42 $USER->IsAdmin()
43 || \Bitrix\Main\Application::getInstance()->getKernelSession()["SHOW_SQL_STAT"]=="Y"
44 )
45 )
46 {
47 $this->debug = new CDebugInfo(false);
48 $this->debug->Start();
49 }
50
52
53 $aMenuLinks = array();
54 $bFounded = false;
55 if($template === false)
56 $sMenuTemplate = '';
57 else
58 $sMenuTemplate = $template;
59
60 $InitDir = str_replace("\\", "/", $InitDir);
61 $Dir = $InitDir;
62
63 $site_dir = false;
64 if(defined("SITE_DIR") && SITE_DIR <> '')
65 {
66 $site_dir = SITE_DIR;
67 }
68 elseif(array_key_exists("site", $_REQUEST) && $_REQUEST["site"] <> '')
69 {
70 $rsSites = CSite::GetByID($_REQUEST["site"]);
71 if($arSite = $rsSites->Fetch())
72 $site_dir = $arSite["DIR"];
73 }
74
75 while($Dir <> '')
76 {
77 if($site_dir !== false && (mb_strlen(trim($Dir, "/")) < mb_strlen(trim($site_dir, "/"))))
78 break;
79
80 $Dir = rtrim($Dir, "/");
81 $menu_file_name = $io->CombinePath($_SERVER["DOCUMENT_ROOT"], $Dir, ".".$this->type.".menu.php");
82
83 if($io->FileExists($menu_file_name))
84 {
85 include($io->GetPhysicalName($menu_file_name));
86 $this->MenuDir = $Dir."/";
87 $this->arMenu = $aMenuLinks;
88 $this->template = $sMenuTemplate;
89 $bFounded = true;
90 break;
91 }
92
93 if($Dir == "")
94 break;
95
96 $pos = bxstrrpos($Dir, "/");
97 if($pos===false || $onlyCurrentDir == true)
98 break;
99
100 $Dir = mb_substr($Dir, 0, $pos + 1);
101 }
102
103 if($bMenuExt)
104 {
105 $Dir = $InitDir;
106 while($Dir <> '')
107 {
108 if($site_dir !== false && (mb_strlen(trim($Dir, "/")) < mb_strlen(trim($site_dir, "/"))))
109 break;
110
111 $Dir = rtrim($Dir, "/");
112 $menu_file_name = $io->CombinePath($_SERVER["DOCUMENT_ROOT"], $Dir, ".".$this->type.".menu_ext.php");
113
114 if($io->FileExists($menu_file_name))
115 {
116 include($io->GetPhysicalName($menu_file_name));
117 if(!$bFounded)
118 $this->MenuDir = $Dir."/";
119
120 $this->MenuExtDir = $Dir."/";
121 $this->arMenu = $aMenuLinks;
122 $this->template = $sMenuTemplate;
123 $bFounded = true;
124 break;
125 }
126
127 if($Dir == "")
128 break;
129
130 $pos = bxstrrpos($Dir, "/");
131 if($pos===false || $onlyCurrentDir == true)
132 break;
133
134 $Dir = mb_substr($Dir, 0, $pos + 1);
135 }
136 }
137
138 return $bFounded;
139 }
140
141 function RecalcMenu($bMultiSelect = false, $bCheckSelected = true)
142 {
143 if($this->bMenuCalc !== false)
144 return true;
145
152
153 $result = array();
154
155 $cur_page = $APPLICATION->GetCurPage(true);
156 $cur_page_no_index = $APPLICATION->GetCurPage(false);
157
158 $APPLICATION->_menu_recalc_counter++;
159
160 $this->bMenuCalc = true;
161
162 if($this->template <> '' && file_exists($_SERVER["DOCUMENT_ROOT"].$this->template))
163 {
164 $this->MenuTemplate = $_SERVER["DOCUMENT_ROOT"].$this->template;
165 }
166 else
167 {
168 if(defined("SITE_TEMPLATE_PATH") && file_exists($_SERVER["DOCUMENT_ROOT"].SITE_TEMPLATE_PATH."/".$this->type.".menu_template.php"))
169 {
170 $this->template = SITE_TEMPLATE_PATH."/".$this->type.".menu_template.php";
171 $this->MenuTemplate = $_SERVER["DOCUMENT_ROOT"].$this->template;
172 }
173 elseif(file_exists($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/php_interface/".LANG."/".$this->type.".menu_template.php"))
174 {
175 $this->template = BX_PERSONAL_ROOT."/php_interface/".LANG."/".$this->type.".menu_template.php";
176 $this->MenuTemplate = $_SERVER["DOCUMENT_ROOT"].$this->template;
177 }
178 else
179 {
180 $this->template = BX_PERSONAL_ROOT."/templates/.default/".$this->type.".menu_template.php";
181 $this->MenuTemplate = $_SERVER["DOCUMENT_ROOT"].$this->template;
182 }
183 }
184
185 if(!file_exists($this->MenuTemplate))
186 {
187 $this->LAST_ERROR = "Template ".$this->MenuTemplate." is not found.";
188 return false;
189 }
190
191 $arMenuCache = [];
192 $bCached = false;
193 $bCacheIsAllowed = CACHED_menu!==false && !$USER->IsAuthorized() && $this->MenuExtDir == '';
194 if($bCacheIsAllowed)
195 {
196 $cache_id = $_SERVER["DOCUMENT_ROOT"].",".$this->MenuDir.",,".$this->type;
197 if($CACHE_MANAGER->Read(CACHED_menu, $cache_id, "menu"))
198 {
199 $arMenuCache = $CACHE_MANAGER->Get($cache_id);
200 $bCached = true;
201 }
202 }
203
204 $arUserRights = $USER->GetAccessCodes();
205 $ITEM_INDEX = -1;
206
207 $cur_selected = -1;
208 $cur_selected_len = -1;
209 $previousDepthLevel = -1;
210 $arParents = array(); //Stack of menu items
211
212 foreach($this->arMenu as $iMenuItem=>$MenuItem)
213 {
214 $TEXT = $MenuItem[0];
215
216 if($bCached)
217 {
218 $LINK = $arMenuCache[$iMenuItem]["LINK"];
219 }
220 else
221 {
222 //if the link is relative let's transform it to absolute
223 if(!preg_match("'^(([A-Za-z]+://)|mailto:|javascript:|#)'i", $MenuItem[1]))
224 {
225 $LINK = Rel2Abs($this->MenuDir, $MenuItem[1]);
226 }
227 else
228 {
229 $LINK = $MenuItem[1];
230 }
231 $arMenuCache[$iMenuItem]["LINK"] = $LINK;
232 }
233
234 $bSkipMenuItem = false;
235 $ADDITIONAL_LINKS = $MenuItem[2] ?? [];
236 $PARAMS = $MenuItem[3] ?? [];
237
238 //Calculate menu items stack for iblock items only
239 if($this->MenuExtDir <> '' && is_array($PARAMS) && isset($PARAMS["FROM_IBLOCK"]))
240 {
241 if($previousDepthLevel == -1)
242 $previousDepthLevel = $PARAMS["DEPTH_LEVEL"];
243
244 if($PARAMS["DEPTH_LEVEL"] > $previousDepthLevel)
245 {
246 //Deeper into sections tree
247 if($iMenuItem > 0)
248 $arParents[] = array("INDEX" => $iMenuItem-1, "DEPTH_LEVEL" => $PARAMS["DEPTH_LEVEL"]);
249 }
250 else
251 {
252 //Unwind parents stack
253 while(
254 !empty($arParents)
255 && $arParents[count($arParents)-1]["DEPTH_LEVEL"] > $PARAMS["DEPTH_LEVEL"]
256 )
257 {
258 array_pop($arParents);
259 }
260 }
261 $previousDepthLevel = $PARAMS["DEPTH_LEVEL"];
262 }
263 elseif($previousDepthLevel != -1)
264 {
265 //End of tree, so reset the stack
266 $previousDepthLevel = -1;
267 $arParents = array();
268 }
269
270
271 if(count($MenuItem)>4)
272 {
273 $CONDITION = $MenuItem[4];
274 if($CONDITION <> '' && (!eval("return ".$CONDITION.";")))
275 $bSkipMenuItem = true;
276 }
277
278 if(!$bSkipMenuItem)
279 $ITEM_INDEX++;
280
281 if((mb_strpos($LINK, "?"))!==false)
282 $ITEM_TYPE = "U";
283 elseif(str_ends_with($LINK, "/"))
284 $ITEM_TYPE = "D";
285 else
286 $ITEM_TYPE = "P";
287
288 $SELECTED = false;
289
290 if($bCached)
291 {
292 $all_links = $arMenuCache[$iMenuItem]["LINKS"];
293 if(!is_array($all_links))
294 $all_links = array();
295 }
296 else
297 {
298 $all_links = array();
299 if(is_array($ADDITIONAL_LINKS))
300 {
301 foreach($ADDITIONAL_LINKS as $link)
302 {
303 $tested_link = trim(Rel2Abs($this->MenuDir, $link));
304 if($tested_link <> '')
305 $all_links[] = $tested_link;
306 }
307 }
308 $all_links[] = $LINK;
309 $arMenuCache[$iMenuItem]["LINKS"] = $all_links;
310 }
311
312 if(preg_match("'^(([A-Za-z]+://)|mailto:|javascript:|#)'i", $MenuItem[1]))
313 {
314 $PERMISSION = "Z";
315 }
316 else
317 {
318 if(!$bSkipMenuItem && $bCheckSelected)
319 {
320 foreach($all_links as $tested_link)
321 {
322 if($tested_link == '')
323 continue;
324
325 $SELECTED = self::IsItemSelected($tested_link, $cur_page, $cur_page_no_index);
326 if($SELECTED)
327 break;
328 }
329 }
330
331 if($bCached)
332 $PERMISSION = $arMenuCache[$iMenuItem]["PERM"];
333 else
334 $arMenuCache[$iMenuItem]["PERM"] = $PERMISSION = $APPLICATION->GetFileAccessPermission(GetFileFromURL($LINK), $arUserRights);
335 }
336
337 if($SELECTED && !$bMultiSelect)
338 {
340 $new_len = mb_strlen($tested_link);
341 if($new_len > $cur_selected_len)
342 {
343 if($cur_selected !== -1)
344 $result[$cur_selected]['SELECTED'] = false;
345
346 $cur_selected = count($result);
347 $cur_selected_len = $new_len;
348 }
349 else
350 {
351 $SELECTED = false;
352 }
353 }
354
355 //Adjust selection for iblock sections tree
356 if(
357 $SELECTED
358 && $this->MenuExtDir <> ''
359 && is_array($PARAMS)
360 && isset($PARAMS["FROM_IBLOCK"])
361 )
362 {
363 foreach($arParents as $parentMenuItem)
364 {
365 $parentIndex = $parentMenuItem["INDEX"];
366 if(
367 is_array($result[$parentIndex]["PARAMS"])
368 && isset($result[$parentIndex]["PARAMS"]["FROM_IBLOCK"])
369 )
370 $result[$parentIndex]["SELECTED"] = true;
371 }
372 }
373
374 if(!$bSkipMenuItem)
375 {
376 $r = array(
377 "TEXT" => $TEXT,
378 "LINK" => $LINK,
379 "SELECTED" => $SELECTED,
380 "PERMISSION" => $PERMISSION,
381 "ADDITIONAL_LINKS" => $ADDITIONAL_LINKS,
382 "ITEM_TYPE" => $ITEM_TYPE,
383 "ITEM_INDEX" => $ITEM_INDEX,
384 "PARAMS" => $PARAMS
385 );
386
387 $result[] = $r;
388 }
389 }
390
391 $this->arMenu = $result;
392
393 if($bCacheIsAllowed && !$bCached)
394 {
396 $CACHE_MANAGER->Set($cache_id, $arMenuCache);
397 }
398
399 return true;
400 }
401
402 public static function IsItemSelected($tested_link, $cur_page, $cur_page_no_index)
403 {
404 //"/admin/"
405 //"/admin/index.php"
406 //"/admin/index.php?module=mail"
407 if(mb_strpos($cur_page, $tested_link) === 0 || mb_strpos($cur_page_no_index, $tested_link) === 0)
408 return true;
409
410 if(($pos = mb_strpos($tested_link, "?")) !== false)
411 {
412 if(($s = mb_substr($tested_link, 0, $pos)) == $cur_page || $s == $cur_page_no_index)
413 {
414 $params = explode("&", mb_substr($tested_link, $pos + 1));
415 $bOK = true;
416 foreach($params as $param)
417 {
418 $eqpos = mb_strpos($param, "=");
419 $varvalue = "";
420 if($eqpos === false)
421 {
422 $varname = $param;
423 }
424 elseif($eqpos == 0)
425 {
426 continue;
427 }
428 else
429 {
430 $varname = mb_substr($param, 0, $eqpos);
431 $varvalue = urldecode(mb_substr($param, $eqpos + 1));
432 }
433
434 $globvarvalue = ($GLOBALS[$varname] ?? "");
435 if($globvarvalue != $varvalue)
436 {
437 $bOK = false;
438 break;
439 }
440 }
441
442 if($bOK)
443 return true;
444 }
445 }
446 return false;
447 }
448
449 function GetMenuHtmlEx()
450 {
455 global $USER, $DB, $APPLICATION; // must be!
456
457 if(!$this->RecalcMenu())
458 return false;
459
460 // $arMENU - menu array copy
461 // $arMENU_LINK - reference to menu array
463 $arMENU_LINK = $MENU_ITEMS = &$this->arMenu;
465 $arMENU = $this->arMenu;
466 $sMenu = "";
467
468 include($this->MenuTemplate);
469
470 $result = $sMenu;
471
472 $arIcons = array();
473 $bShowButtons = false;
474 $sMenuFile = $this->MenuDir.".".$this->type.".menu.php";
475 if($APPLICATION->GetShowIncludeAreas())
476 {
477 $menu_perm = $APPLICATION->GetFileAccessPermission($sMenuFile);
478 $templ_perm = $APPLICATION->GetFileAccessPermission($this->template);
479 if($menu_perm >= "W")
480 {
481 $arIcons[] = array(
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,
483 "ICON"=>"menu-edit",
484 "TITLE"=>GetMessage("MAIN_MENU_EDIT")
485 );
486 }
487 if($templ_perm>="W" && $USER->IsAdmin())
488 {
489 $arIcons[] = array(
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")
493 );
494 }
495 if(!empty($arIcons))
496 {
497 $result = $APPLICATION->IncludeStringBefore().$result;
498 $bShowButtons = true;
499 }
500 }
501
502 if($this->debug)
503 $result .= $this->debug->Output($sMenuFile, $sMenuFile);
504
505 if($bShowButtons)
506 $result .= $APPLICATION->IncludeStringAfter($arIcons);
507
508 return $result;
509 }
510
511
512 function GetMenuHtml()
513 {
518 global $USER, $DB, $APPLICATION; // must be!
519
520 if(!$this->RecalcMenu())
521 return false;
522
523 // $arMENU - menu array copy
524 // $arMENU_LINK - reference to menu array
526 $arMENU_LINK = $MENU_ITEMS = &$this->arMenu;
528 $arMENU = $this->arMenu;
529
530 $result = "";
531 $sMenuPrologTmp = "";
532 $sMenuEpilog = "";
533 $n = count($this->arMenu);
534 for($i = 0; $i < $n; $i++)
535 {
536 $m = $this->arMenu[$i];
537 $sMenuBody = "";
538 $sMenuProlog = "";
539 $sMenuEpilog = "";
540 $ITEM_INDEX = 0;
541 extract($m, EXTR_OVERWRITE);
542
543 // $TEXT - item text
544 // $LINK - item link
545 // $SELECTED - is item highlighed
546 // $PERMISSION - linked page permission
547 // $ADDITIONAL_LINKS - additional links for highlighting
548 // $ITEM_TYPE - "D" - directory, "P" - page
549 // $ITEM_INDEX - item number
550 // $PARAMS - additional parameters
551
552 include($this->MenuTemplate);
553
554 if($ITEM_INDEX == 0)
555 $sMenuPrologTmp = $sMenuProlog;
556 $result .= $sMenuBody;
557 }
558
559 $result = $sMenuPrologTmp.$result.$sMenuEpilog;
560
561 $arIcons = array();
562 $bShowButtons = false;
563 $sMenuFile = $this->MenuDir.".".$this->type.".menu.php";
564 if($APPLICATION->GetShowIncludeAreas())
565 {
566 $menu_perm = $APPLICATION->GetFileAccessPermission($sMenuFile);
567 $templ_perm = $APPLICATION->GetFileAccessPermission($this->template);
568 if($menu_perm >= "W")
569 {
570 $arIcons[] = array(
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,
572 "ICON"=>"menu-edit",
573 "TITLE"=>GetMessage("MAIN_MENU_EDIT")
574 );
575 }
576
577 if($templ_perm >= "W" && $USER->IsAdmin())
578 {
579 $arIcons[] = array(
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")
583 );
584 }
585
586 if(!empty($arIcons))
587 {
588 $result = $APPLICATION->IncludeStringBefore().$result;
589 $bShowButtons = true;
590 }
591 }
592
593 if($this->debug)
594 $result .= $this->debug->Output($sMenuFile, $sMenuFile);
595
596 if($bShowButtons)
597 $result .= $APPLICATION->IncludeStringAfter($arIcons);
598
599 return $result;
600 }
601}
global $APPLICATION
Определения include.php:80
static GetInstance()
Определения virtual_io.php:60
Определения debuginfo.php:17
Определения menu.php:13
__construct($type="left")
Определения menu.php:25
Init($InitDir, $bMenuExt=false, $template=false, $onlyCurrentDir=false)
Определения menu.php:35
$MenuDir
Определения menu.php:17
GetMenuHtml()
Определения menu.php:512
static IsItemSelected($tested_link, $cur_page, $cur_page_no_index)
Определения menu.php:402
$MenuTemplate
Определения menu.php:19
$debug
Определения menu.php:23
RecalcMenu($bMultiSelect=false, $bCheckSelected=true)
Определения menu.php:141
$type
Определения menu.php:14
$LAST_ERROR
Определения menu.php:21
$template
Определения menu.php:20
$MenuExtDir
Определения menu.php:18
disableDebug()
Определения menu.php:30
$bMenuCalc
Определения menu.php:16
GetMenuHtmlEx()
Определения menu.php:449
$arMenu
Определения menu.php:15
global $CACHE_MANAGER
Определения clear_component_cache.php:7
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$rsSites
Определения options.php:477
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$io
Определения csv_new_run.php:98
const SITE_DIR(!defined('LANG'))
Определения include.php:72
$GLOBALS[ 'DB'] debug
Определения start.php:56
GetFileFromURL($page, $get_index_page=null)
Определения tools.php:3218
bxstrrpos($haystack, $needle)
Определения tools.php:3292
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
const SITE_ID
Определения sonet_set_content_view.php:12
$GLOBALS['_____370096793']
Определения update_client.php:1
$n
Определения update_log.php:107