Alternc  latest
Alternc logiel libre pour l'hébergement
m_menu.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  ----------------------------------------------------------------------
5  LICENSE
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License (GPL)
9  as published by the Free Software Foundation; either version 2
10  of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  To read the license please visit http://www.gnu.org/copyleft/gpl.html
18  ----------------------------------------------------------------------
19 */
20 
21 /**
22  * This class manage the left menu of AlternC
23  *
24  * @copyright AlternC-Team 2000-2017 https://alternc.com/
25  */
26 class m_menu {
27 
28  /**
29  * get all menus to display,
30  * uses hooks
31  */
32  function getmenu() {
33  global $hooks, $quota, $mem;
34 
35  // Force rebuilding quota, in case of add or edit of the quota and cache not up-to-date
36  $mesq = $quota->getquota("", true); // rebuild quota
37  // Get menu objects
38  $lsto = $hooks->invoke('hook_menu');
39 
40  // Get system menu
41  $sm = $this->system_menu();
42 
43  // Merge it !
44  $lst = array_merge($sm, $lsto);
45 
46  // Sort it
47  uasort($lst, 'm_menu::order_menu');
48 
49  // Get user specific menu visibility options
50  $mop = $mem->session_tempo_params_get('menu_toggle');
51 
52  foreach ($lst as $k => $v) {
53 
54  if (empty($v)) {
55  unset($lst[$k]);
56  continue;
57  }
58 
59  // Set the javascript toggle link for menu asking for it
60  if ($v['link'] == 'toggle') {
61  $lst[$k]['link'] = 'javascript:menu_toggle(\'menu-' . $k . '\');';
62  }
63 
64  // Be sure that the default visibility is true
65  if (!isset($lst[$k]['visibility'])) {
66  $lst[$k]['visibility'] = true;
67  }
68 
69  // Set the user's specific visibility option
70  if (isset($mop["menu-$k"])) {
71  if ($mop["menu-$k"] == "hidden") {
72  $lst[$k]['visibility'] = false;
73  }
74  if ($mop["menu-$k"] == "visible") {
75  $lst[$k]['visibility'] = true;
76  }
77  }
78 
79  if (isset($mesq[$k])) { // if there are some quota for this class
80  // Hide the menu if there are none and not allowed to create
81  if ($mesq[$k]['t'] < 1 && $mesq[$k]['u'] < 1) {
82  unset($lst[$k]);
83  continue;
84  }
85 
86  // Set the quota in the menu object
87  $lst[$k]['quota_used'] = $mesq[$k]['u'];
88  $lst[$k]['quota_total'] = $mesq[$k]['t'];
89  } // end if there are some quota for this class
90  }
91 
92  return $lst;
93  }
94 
95  /**
96  * utilitary function used by usort() to order menus
97  */
98  function order_menu($a, $b) {
99  return $a['pos'] > $b['pos'];
100  }
101 
102  /**
103  * some menus that don't have an attached class
104  */
105  function system_menu() {
106  global $help_baseurl, $lang_translation, $locales;
107 
108  $m = array(
109  'home' =>
110  array(
111  'title' => _("Home / Information"),
112  'link' => 'main.php',
113  'pos' => 0,
114  ),
115  'logout' =>
116  array(
117  'title' => _("Logout"),
118  'link' => 'mem_logout.php',
119  'pos' => 170,
120  ),
121  'help' =>
122  array(
123  'title' => _("Online help"),
124  'target' => 'help',
125  'link' => $help_baseurl,
126  'pos' => 140,
127  ),
128  'lang' =>
129  array(
130  'title' => _("Languages"),
131  'visibility' => false,
132  'link' => 'toggle',
133  'links' => array(),
134  'pos' => 150,
135  )
136  );
137  foreach ($locales as $l) {
138  $m['lang']['links'][] = array('txt' => (isset($lang_translation[$l])) ? $lang_translation[$l] : $l, 'url' => "/login.php?setlang=$l");
139  }
140  return $m;
141  }
142 
143 } /* Class m_menu */
$hooks
Definition: bootstrap.php:74
$mem
Definition: bootstrap.php:71
This class manage the left menu of AlternC.
Definition: m_menu.php:26
system_menu()
some menus that don't have an attached class
Definition: m_menu.php:105
getmenu()
get all menus to display, uses hooks
Definition: m_menu.php:32
order_menu($a, $b)
utilitary function used by usort() to order menus
Definition: m_menu.php:98
$help_baseurl
Definition: config.php:68