Cheetah
ChWsbAdminMenu.php
Go to the documentation of this file.
1 <?php
2 
9 {
10  public static function getTopMenu()
11  {
12  $sTmplVarsAddons = '';
13  $aTmplVarsItems = array();
14 
15  $aItems = array();
16  if(count(getLangsArr()) > 1) {
17  $aItems[] = array(
18  'caption' => '_adm_tmi_language',
19  'url' => 'javascript:void(0)',
20  'onclick' => 'showPopupLanguage()',
21  'target' => '',
22  'icon' => 'language'
23  );
24 
25  $sLangName = getCurrentLangName();
26  $sTmplVarsAddons .= $GLOBALS['oFunctions']->getLanguageSwitcher($sLangName);
27  }
28 
29  $aItems = array_merge($aItems, $GLOBALS['MySQL']->getAll("SELECT `caption`, `url`, `target`, `icon` FROM `sys_menu_admin_top` ORDER BY `Order`"));
30  foreach($aItems as $aItem)
31  $aTmplVarsItems[] = array(
32  'caption' => _t($aItem['caption']),
33  'url' => str_replace(
34  array(
35  '{site_url}',
36  '{admin_url}'
37  ),
38  array(
39  $GLOBALS['site']['url'],
40  $GLOBALS['site']['url_admin'],
41  ),
42  $aItem['url']
43  ),
44  'target' => !empty($aItem['target']) ? $aItem['target'] : '_self',
45  'ch_if:show_onclick' => array(
46  'condition' => (isset($aItem['onclick']) && !empty($aItem['onclick'])),
47  'content' => array(
48  'onclick' => (isset($aItem['onclick'])) ? $aItem['onclick'] : ''
49  )
50  ),
51  'icon' => false === strpos($aItem['icon'], '.') ? '<i class="sys-icon ' . $aItem['icon'] . '"></i>' : '<img src="' . $GLOBALS['oAdmTemplate']->getIconUrl($aItem['icon']) . '" alt="' . _t($aItem['caption']) . '" />',
52  );
53 
54  return $GLOBALS['oAdmTemplate']->parseHtmlByName('top_menu.html', array(
55  'ch_repeat:items' => $aTmplVarsItems,
56  'addons' => $sTmplVarsAddons
57  ));
58  }
59 
60  public static function getMainMenu()
61  {
62  if(!isAdmin())
63  return '';
64 
65  $sUri = $_SERVER['REQUEST_URI'];
66  $sPath = parse_url (CH_WSB_URL_ROOT, PHP_URL_PATH);
67  if ($sPath && $sPath != '/' && 0 === strncmp($sPath, $sUri, strlen($sPath)))
68  $sUri = substr($sUri, strlen($sPath) - strlen($sUri));
69  $sUri = CH_WSB_URL_ROOT . trim($sUri, '/');
70  $sFile = basename($_SERVER['PHP_SELF']);
71 
72  $oPermalinks = new ChWsbPermalinks();
73  $aMenu = $GLOBALS['MySQL']->getAll("SELECT `id`, `name`, `title`, `url`, `icon` FROM `sys_menu_admin` WHERE `parent_id`='0' ORDER BY `order`" );
74 
75  $oZ = new ChWsbAlerts('system', 'admin_menu', 0, 0, array(
76  'parent' => false,
77  'menu' => &$aMenu,
78  ));
79  $oZ->alert();
80 
81  $oChWsbAdminMenu = new self();
82 
83  $aItems = array();
84  foreach($aMenu as $aMenuItem) {
85  $aMenuItem['url'] = str_replace(array('{siteUrl}', '{siteAdminUrl}'), array(CH_WSB_URL_ROOT, CH_WSB_URL_ADMIN), $aMenuItem['url']);
86 
87  $bActiveCateg = $sFile == 'index.php' && (!empty($_GET['cat'])) && $_GET['cat'] == $aMenuItem['name'];
88  $aSubmenu = $GLOBALS['MySQL']->getAll("SELECT * FROM `sys_menu_admin` WHERE `parent_id`= ? ORDER BY `order`", [$aMenuItem['id']]);
89 
90  $oZ = new ChWsbAlerts('system', 'admin_menu', 0, 0, array(
91  'parent' => &$aMenuItem,
92  'menu' => &$aSubmenu,
93  ));
94  $oZ->alert();
95 
96  $aSubitems = array();
97  foreach($aSubmenu as $aSubmenuItem) {
98  $aSubmenuItem['url'] = $oPermalinks->permalink($aSubmenuItem['url']);
99  $aSubmenuItem['url'] = str_replace(array('{siteUrl}', '{siteAdminUrl}'), array(CH_WSB_URL_ROOT, CH_WSB_URL_ADMIN), $aSubmenuItem['url']);
100 
101  if(!defined('CH_WSB_ADMIN_INDEX') && $aSubmenuItem['url'] != '' && (strpos($sUri, $aSubmenuItem['url']) !== false || strpos($aSubmenuItem['url'], $sUri) !== false))
102  $bActiveCateg = $bActiveItem = true;
103  else
104  $bActiveItem = false;
105 
106  $sSubItem = $oChWsbAdminMenu->_getMainMenuSubitem($aSubmenuItem, $bActiveItem);
107  if($sSubItem) $aSubitems[] = $sSubItem;
108  }
109 
110  $aItems[] = $oChWsbAdminMenu->_getMainMenuItem($aMenuItem, $aSubitems, $bActiveCateg);
111  }
112 
113  return $GLOBALS['oAdmTemplate']->parseHtmlByName('main_menu.html', array('ch_repeat:items' => $aItems));
114  }
115 
116  public static function getMainMenuLink($sUrl)
117  {
118  if(substr($sUrl, 0, 11) == 'javascript:') {
119  $sLink = 'javascript:void(0);';
120  $sOnClick = 'onclick="' . $sUrl . '"';
121  } else {
122  $sLink = $sUrl;
123  $sOnClick = '';
124  }
125 
126  $aAdminProfile = getProfileInfo();
127  $aVariables = array(
128  'adminLogin' => $aAdminProfile['NickName'],
129  'adminPass' => $aAdminProfile['Password']
130  );
131  $sLink = $GLOBALS['oAdmTemplate']->parseHtmlByContent($sLink, $aVariables, array('{', '}'));
132  $sOnClick = $GLOBALS['oAdmTemplate']->parseHtmlByContent($sOnClick, $aVariables, array('{', '}'));
133 
134  return array($sLink, $sOnClick);
135  }
136 
137  function _getMainMenuItem($aCateg, $aItems, $bActive)
138  {
140  $bSubmenu = !empty($aItems);
141 
142  $sClass = "adm-mm-" . $aCateg['name'];
143  if($bActive && !empty($aItems))
144  $sClass .= ' adm-mmh-opened';
145  else if($bActive && empty($aItems))
146  $sClass .= ' adm-mmh-active';
147 
148  $sLink = "";
149  if(!empty($aCateg['url']))
150  $sLink = $aCateg['url'];
151  else if($aCateg['id'])
152  $sLink = CH_WSB_URL_ADMIN . "index.php?cat=" . $aCateg['name'];
153  else
154  $sLink = CH_WSB_URL_ADMIN . "index.php";
155 
156  return array(
157  'class' => $sClass,
158  'click' => !$bSubmenu ? 'onclick="javascript:window.open(\'' . $sLink . '\', \'_self\')"' : '',
159  'ch_if:icon' => array(
160  'condition' => false !== strpos($aCateg['icon'], '.'),
161  'content' => array(
162  'icon' => $oAdmTemplate->getIconUrl($aCateg['icon'])
163  )
164  ),
165  'ch_if:texticon' => array(
166  'condition' => false === strpos($aCateg['icon'], '.'),
167  'content' => array(
168  'icon' => $aCateg['icon']
169  )
170  ),
171  'ch_if:collapsible' => array(
172  'condition' => !empty($aItems),
173  'content' => array(
174  'class' => $bActive && !empty($aItems) ? 'chevron-up adm-mma-opened' : 'chevron-down'
175  )
176  ),
177  'ch_if:item-text' => array(
178  'condition' => $bActive,
179  'content' => array(
180  'title' => _t($aCateg['title'])
181  )
182  ),
183  'ch_if:item-link' => array(
184  'condition' => !$bActive,
185  'content' => array(
186  'link' => $sLink,
187  'title' => _t($aCateg['title'])
188  )
189  ),
190  'ch_if:submenu' => array(
191  'condition' => $bSubmenu,
192  'content' => array(
193  'id' => $aCateg['id'],
194  'class' => ($bActive && !empty($aItems) ? 'adm-mmi-opened' : ''),
195  'ch_repeat:subitems' => $aItems
196  )
197  )
198  );
199  }
200 
201  function _getMainMenuSubitem($aItem, $bActive)
202  {
204 
205  if(strlen($aItem['check']) > 0) {
206  $oFunction = function() use($aItem) {
207  return eval($aItem['check']);
208  };
209 
210  if(!$oFunction())
211  return '';
212  }
213 
214  if(!$bActive)
215  list($sLink, $sOnClick) = ChWsbAdminMenu::getMainMenuLink($aItem['url']);
216 
217  return array(
218  'class' => $bActive ? 'adm-mmi-active' : '',
219  'ch_if:subicon' => array(
220  'condition' => false !== strpos($aItem['icon'], '.'),
221  'content' => array(
222  'icon' => $oAdmTemplate->getIconUrl($aItem['icon'])
223  )
224  ),
225  'ch_if:textsubicon' => array(
226  'condition' => false === strpos($aItem['icon'], '.'),
227  'content' => array(
228  'icon' => $aItem['icon']
229  )
230  ),
231  'ch_if:subitem-text' => array(
232  'condition' => $bActive,
233  'content' => array(
234  'title' => _t($aItem['title'])
235  )
236  ),
237  'ch_if:subitem-link' => array(
238  'condition' => !$bActive,
239  'content' => array(
240  'link' => empty($sLink) ? '' : $sLink,
241  'onclick' => empty($sOnClick) ? '' : $sOnClick,
242  'title' => 'manage_modules' == $aItem['name'] || 'flash_apps' == $aItem['name'] ? '<b>' . _t($aItem['title']) . '</b>' : _t($aItem['title']),
243  )
244  )
245  );
246  }
247 }
ChWsbAdminMenu
Definition: ChWsbAdminMenu.php:9
$oAdmTemplate
$oAdmTemplate
Definition: admin_design.inc.php:18
getCurrentLangName
if(!defined('CH_SKIP_INSTALL_CHECK')) getCurrentLangName($isSetCookie=true)
Definition: languages.inc.php:36
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
ChWsbAdminMenu\getTopMenu
static getTopMenu()
Definition: ChWsbAdminMenu.php:10
$sUrl
$sUrl
Definition: cart.php:15
php
$oZ
$oZ
Definition: db.php:20
isAdmin
isAdmin()
Definition: index.php:649
ChWsbAlerts
Definition: ChWsbAlerts.php:39
$sFile
$sFile
Definition: index.php:20
$_GET
$_GET['debug']
Definition: index.php:67
ChWsbAdminMenu\_getMainMenuItem
_getMainMenuItem($aCateg, $aItems, $bActive)
Definition: ChWsbAdminMenu.php:137
getLangsArr
getLangsArr( $bAddFlag=false, $bRetIDs=false)
Definition: languages.inc.php:155
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
$aMenu
$aMenu
Definition: categories.php:257
ChWsbAdminMenu\_getMainMenuSubitem
_getMainMenuSubitem($aItem, $bActive)
Definition: ChWsbAdminMenu.php:201
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
ChWsbAdminMenu\getMainMenu
static getMainMenu()
Definition: ChWsbAdminMenu.php:60
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbAdminMenu\getMainMenuLink
static getMainMenuLink($sUrl)
Definition: ChWsbAdminMenu.php:116
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10