XOOPS  2.6.0
menus_block.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
21 {
22  $block = array();
25 
26  /* @var $decorator MenusDecoratorInterface */
28 
29  foreach ($decorators as $decorator) {
30  $decorator->start();
31  }
32 
33  $menu_id = $options[0];
34  $criteria = new CriteriaCompo(new Criteria('mid', $menu_id));
35  $criteria->setSort('weight');
36  $criteria->setOrder('ASC');
37  //get menus as an array with ids as keys
38  $menus = $helper->getHandlerMenu()->getAll($criteria, null, false, false);
39  unset($criteria);
40 
41  foreach ($menus as $key => $menu) {
42  $hasAccess = true;
43  foreach ($decorators as $decorator) {
44  $decorator->hasAccess($menu, $hasAccess);
45  }
46  if (!$hasAccess) {
47  unset($menus[$key]);
48  }
49  }
50 
51  $count = count($menus);
52  if ($count == 0) {
53  return $block;
54  }
55 
56  foreach ($menus as $key => $menu) {
57  foreach ($decorators as $decorator) {
58  $decorator->decorateMenu($menu);
59  }
60  $menus[$key] = $menu;
61  }
62 
63  foreach ($decorators as $decorator) {
64  $decorator->end($menus);
65  }
66 
67  $builder = new MenusBuilder($menus);
68  $block = $builder->render();
69 
70  /*--------------------------------------------------------------*/
71  //default files to load
72  $css = array();
73  $js = array();
74 
75  //get extra files from skins
76  $skin = $options[1];
77  $skin_info = $helper->getSkinInfo($skin, $options[2]);
78 
79  if (isset($skin_info['css'])) {
80  $css = array_merge($css, $skin_info['css']);
81  }
82 
83  if (isset($skin_info['js'])) {
84  $js = array_merge($js, $skin_info['js']);
85  }
86 
87  if ($helper->getConfig('assign_method') == 'xoopstpl') {
88  $tpl_vars = '';
89  foreach ($css as $file) {
90  $tpl_vars .= "\n" . '<link rel="stylesheet" type="text/css" media="all" href="' . $file . '" />';
91  }
92 
93  foreach ($js as $file) {
94  $tpl_vars .= "\n" . '<script type="text/javascript" src="' . $file . '"></script>';
95  }
96 
97  if (isset($skin_info['header'])) {
98  $tpl_vars .= "\n" . $skin_info['header'];
99  }
100 
101  $xoops->tpl()->assign('xoops_module_header', $tpl_vars . @$xoops->tpl()->getTemplateVars("xoops_module_header"));
102  } else {
103  foreach ($css as $file) {
104  $xoops->theme()->addStylesheet($file);
105  }
106 
107  foreach ($js as $file) {
108  $xoops->theme()->addScript($file);
109  }
110 
111  if (isset($skin_info['header'])) {
112  $xoops->tpl()->assign('xoops_footer', @$xoops->tpl()->getTemplateVars("xoops_footer") . "\n" . $skin_info['header']);
113  }
114  }
115 
116  $blockTpl = new XoopsTpl();
117  $blockTpl->assign('block', $block);
118  $blockTpl->assign('config', $skin_info['config']);
119  $blockTpl->assign('skinurl', $skin_info['url']);
120  $blockTpl->assign('skinpath', $skin_info['path']);
121 
122  $block['content'] = $blockTpl->fetch($skin_info['template']);
123 
124  if ($options[3] == 'template') {
125  $xoops->tpl()->assign('xoops_menu_' . $options[4], $block['content']);
126  $block = array();
127  }
128 
129  return $block;
130 }
131 
133 {
134  //Unique ID
135  if (!$options[4] || (isset($_GET['op']) && $_GET['op'] == 'clone')) {
136  $options[4] = uniqid();
137  }
138 
140  $helper->loadLanguage('admin');
141 
142  $criteria = new CriteriaCompo();
143  $criteria->setSort('title');
144  $criteria->setOrder('ASC');
145  $menus = $helper->getHandlerMenus()->getList($criteria);
146  unset($criteria);
147 
148  if (count($menus) == 0) {
149  $form = "<a href='" . $helper->url('admin/admin_menus.php') . "'>" . _AM_MENUS_MSG_NOMENUS . "</a>";
150  return $form;
151  }
152 
153  //Menu
154  $form = new Xoops\Form\BlockForm();
155  $element = new Xoops\Form\Select(_MB_MENUS_SELECT_MENU, 'options[0]', $options[0], 1);
156  $element->addOptionArray($menus);
157  $element->setDescription(_MB_MENUS_SELECT_MENU_DSC);
158  $form->addElement($element);
159 
160  //Skin
161  $temp_skins = XoopsLists::getDirListAsArray(\XoopsBaseConfig::get('root-path') . "/modules/menus/skins/", "");
162  $skins_options = array();
163  foreach ($temp_skins as $skin) {
164  if (XoopsLoad::fileExists($helper->path('skins/' . $skin . '/skin_version.php'))) {
165  $skins_options[$skin] = $skin;
166  }
167  }
168  $element = new Xoops\Form\Select(_MB_MENUS_SELECT_SKIN, 'options[1]', $options[1], 1);
169  $element->addOptionArray($skins_options);
170  $element->setDescription(_MB_MENUS_SELECT_SKIN_DSC);
171  $form->addElement($element);
172 
173  //Use skin from,theme
174  $element = new Xoops\Form\RadioYesNo(_MB_MENUS_USE_THEME_SKIN, 'options[2]', $options[2]);
175  $element->setDescription(_MB_MENUS_USE_THEME_SKIN_DSC);
176  $form->addElement($element);
177 
178  //Display method
179  $display_options = array(
182  );
183  $element = new Xoops\Form\Select(_MB_MENUS_DISPLAY_METHOD, 'options[3]', $options[3], 1);
184  $element->addOptionArray($display_options);
185  $element->setDescription(sprintf(_MB_MENUS_DISPLAY_METHOD_DSC, $options[4]));
186  $form->addElement($element);
187 
188  //Unique ID
189  $element = new Xoops\Form\Text(_MB_MENUS_UNIQUEID, 'options[4]', 2, 20, $options[4]);
190  $element->setDescription(_MB_MENUS_UNIQUEID_DSC);
191  $form->addElement($element);
192 
193  return $form->render();
194 }
195 
197 {
198  $block = array();
201 
202  $module_handler = $xoops->getHandlerModule();
203  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
204  $criteria->add(new Criteria('isactive', 1));
205  $criteria->add(new Criteria('weight', 0, '>'));
206  $modules = $module_handler->getObjectsArray($criteria, true);
207  $moduleperm_handler = $xoops->getHandlerGroupperm();
208  $groups = $xoops->getUserGroups();
209  $read_allowed = $moduleperm_handler->getItemIds('module_read', $groups);
210  $menus = array();
211  $menu = $helper->getHandlerMenu()->create();
212  $menu->setVar('id', 1);
213  $menu->setVar('pid', 0);
214  $menu->setVar('alt_title', _MB_MENUS_HOME);
215  $menu->setVar('title', _MB_MENUS_HOME);
216  $menu->setVar('link', \XoopsBaseConfig::get('url'));
217  $menu->setVar('image', 'icon-home');
218  $menus[] = $menu->getValues();
219  foreach (array_keys($modules) as $i) {
220  if (in_array($i, $read_allowed)) {
221  /* @var $plugin MenusPluginInterface */
222  $menu = $helper->getHandlerMenu()->create();
223  $menu->setVar('id', $i);
224  $menu->setVar('pid', 0);
225  $menu->setVar('title', $modules[$i]->getVar('name'));
226  $menu->setVar('alt_title', $modules[$i]->getVar('name'));
227  $menu->setVar('link', \XoopsBaseConfig::get('url') . '/modules/' . $modules[$i]->getVar('dirname'));
228  $menu->setVar('image', 'icon-tags');
229  $menus[] = $menu->getValues();
230  if ($xoops->isModule() && $xoops->module->getVar('dirname') == $modules[$i]->getVar('dirname') && $plugin = \Xoops\Module\Plugin::getPlugin($modules[$i]->getVar('dirname'), 'menus')) {
231  $sublinks = $plugin->subMenus();
232  $j = -1;
233  foreach ($sublinks as $sublink) {
234  $menu = $helper->getHandlerMenu()->create();
235  $menu->setVar('id', $j);
236  $menu->setVar('pid', $i);
237  $menu->setVar('title', $sublink['name']);
238  $menu->setVar('alt_title', $sublink['name']);
239  $menu->setVar('link', \XoopsBaseConfig::get('url') . '/modules/' . $modules[$i]->getVar('dirname') . '/'. $sublink['url']);
240  $menus[] = $menu->getValues();
241  $j--;
242  }
243  }
244  }
245  }
246  $builder = new MenusBuilder($menus);
247  $block = $builder->render();
248 
249  $skin_info = $helper->getSkinInfo('mainmenu', false);
250  $blockTpl = new XoopsTpl();
251  $blockTpl->assign('block', $block);
252  $blockTpl->assign('config', $skin_info['config']);
253  $blockTpl->assign('skinurl', $skin_info['url']);
254  $blockTpl->assign('skinpath', $skin_info['path']);
255 
256  $block['content'] = $blockTpl->fetch($skin_info['template']);
257 
258  return $block;
259 }
const _MB_MENUS_SELECT_MENU_DSC
Definition: blocks.php:7
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$read_allowed
Definition: userinfo.php:188
const _MB_MENUS_DISPLAY_METHOD_BLOCK
Definition: blocks.php:16
$options['editor']
const _MB_MENUS_DISPLAY_METHOD_TEMPLATE
Definition: blocks.php:17
static getInstance()
Definition: helper.php:34
$form
Definition: xoops_code.php:21
$xoops
Definition: admin.php:25
const _MB_MENUS_UNIQUEID_DSC
Definition: blocks.php:13
$menu
static fileExists($file)
Definition: xoopsload.php:506
static get($name)
const _MB_MENUS_HOME
Definition: blocks.php:19
const _MB_MENUS_UNIQUEID
Definition: blocks.php:12
const _MB_MENUS_SELECT_SKIN_DSC
Definition: blocks.php:9
$groups
$modules
Definition: userinfo.php:185
$helper
static getAvailableDecorators()
Definition: decorator.php:40
$criteria
const _MB_MENUS_DISPLAY_METHOD_DSC
Definition: blocks.php:15
const _AM_MENUS_MSG_NOMENUS
Definition: admin.php:38
$module_handler
Definition: main.php:55
const _MB_MENUS_USE_THEME_SKIN_DSC
Definition: blocks.php:11
const _MB_MENUS_SELECT_SKIN
Definition: blocks.php:8
$moduleperm_handler
Definition: cp_header.php:31
$j
Definition: help.php:169
const _MB_MENUS_DISPLAY_METHOD
Definition: blocks.php:14
const _MB_MENUS_SELECT_MENU
Definition: blocks.php:6
const _MB_MENUS_USE_THEME_SKIN
Definition: blocks.php:10
$menu_id
Definition: admin_menu.php:59