1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\XoopsTpl;
13:
14: 15: 16: 17: 18: 19: 20:
21:
22: function menus_block_show($options)
23: {
24: $block = array();
25: $xoops = Xoops::getInstance();
26: $helper = Xoops::getModuleHelper('menus');
27:
28:
29: $decorators = MenusDecorator::getAvailableDecorators();
30:
31: foreach ($decorators as $decorator) {
32: $decorator->start();
33: }
34:
35: $menu_id = $options[0];
36: $criteria = new CriteriaCompo(new Criteria('mid', $menu_id));
37: $criteria->setSort('weight');
38: $criteria->setOrder('ASC');
39:
40: $menus = $helper->getHandlerMenu()->getAll($criteria, null, false, false);
41: unset($criteria);
42:
43: foreach ($menus as $key => $menu) {
44: $hasAccess = true;
45: foreach ($decorators as $decorator) {
46: $decorator->hasAccess($menu, $hasAccess);
47: }
48: if (!$hasAccess) {
49: unset($menus[$key]);
50: }
51: }
52:
53: $count = count($menus);
54: if ($count == 0) {
55: return $block;
56: }
57:
58: foreach ($menus as $key => $menu) {
59: foreach ($decorators as $decorator) {
60: $decorator->decorateMenu($menu);
61: }
62: $menus[$key] = $menu;
63: }
64:
65: foreach ($decorators as $decorator) {
66: $decorator->end($menus);
67: }
68:
69: $builder = new MenusBuilder($menus);
70: $block = $builder->render();
71:
72:
73:
74: $css = array();
75: $js = array();
76:
77:
78: $skin = $options[1];
79: $skin_info = $helper->getSkinInfo($skin, $options[2]);
80:
81: if (isset($skin_info['css'])) {
82: $css = array_merge($css, $skin_info['css']);
83: }
84:
85: if (isset($skin_info['js'])) {
86: $js = array_merge($js, $skin_info['js']);
87: }
88:
89: if ($helper->getConfig('assign_method') === 'xoopstpl') {
90: $tpl_vars = '';
91: foreach ($css as $file) {
92: $tpl_vars .= "\n" . '<link rel="stylesheet" type="text/css" media="all" href="' . $file . '" />';
93: }
94:
95: foreach ($js as $file) {
96: $tpl_vars .= "\n" . '<script type="text/javascript" src="' . $file . '"></script>';
97: }
98:
99: if (isset($skin_info['header'])) {
100: $tpl_vars .= "\n" . $skin_info['header'];
101: }
102:
103: $xoops->tpl()->assign('xoops_module_header', $tpl_vars . @$xoops->tpl()->getTemplateVars("xoops_module_header"));
104: } else {
105: foreach ($css as $file) {
106: $xoops->theme()->addStylesheet($file);
107: }
108:
109: foreach ($js as $file) {
110: $xoops->theme()->addScript($file);
111: }
112:
113: if (isset($skin_info['header'])) {
114: $xoops->tpl()->assign('xoops_footer', @$xoops->tpl()->getTemplateVars("xoops_footer") . "\n" . $skin_info['header']);
115: }
116: }
117:
118: $blockTpl = new XoopsTpl();
119: $blockTpl->assign('block', $block);
120: $blockTpl->assign('config', $skin_info['config']);
121: $blockTpl->assign('skinurl', $skin_info['url']);
122: $blockTpl->assign('skinpath', $skin_info['path']);
123:
124: $block['content'] = $blockTpl->fetch($skin_info['template']);
125:
126: if ($options[3] === 'template') {
127: $xoops->tpl()->assign('xoops_menu_' . $options[4], $block['content']);
128: $block = array();
129: }
130:
131: return $block;
132: }
133:
134: function menus_block_edit($options)
135: {
136:
137: if (!$options[4] || (isset($_GET['op']) && $_GET['op'] === 'clone')) {
138: $options[4] = uniqid();
139: }
140:
141: $helper = Xoops::getModuleHelper('menus');
142: $helper->loadLanguage('admin');
143:
144: $criteria = new CriteriaCompo();
145: $criteria->setSort('title');
146: $criteria->setOrder('ASC');
147: $menus = $helper->getHandlerMenus()->getList($criteria);
148: unset($criteria);
149:
150: if (count($menus) == 0) {
151: $form = "<a href='" . $helper->url('admin/admin_menus.php') . "'>" . _AM_MENUS_MSG_NOMENUS . "</a>";
152: return $form;
153: }
154:
155:
156: $form = new Xoops\Form\BlockForm();
157: $element = new Xoops\Form\Select(_MB_MENUS_SELECT_MENU, 'options[0]', $options[0], 1);
158: $element->addOptionArray($menus);
159: $element->setDescription(_MB_MENUS_SELECT_MENU_DSC);
160: $form->addElement($element);
161:
162:
163: $temp_skins = XoopsLists::getDirListAsArray(\XoopsBaseConfig::get('root-path') . "/modules/menus/skins/", "");
164: $skins_options = array();
165: foreach ($temp_skins as $skin) {
166: if (XoopsLoad::fileExists($helper->path('skins/' . $skin . '/skin_version.php'))) {
167: $skins_options[$skin] = $skin;
168: }
169: }
170: $element = new Xoops\Form\Select(_MB_MENUS_SELECT_SKIN, 'options[1]', $options[1], 1);
171: $element->addOptionArray($skins_options);
172: $element->setDescription(_MB_MENUS_SELECT_SKIN_DSC);
173: $form->addElement($element);
174:
175:
176: $element = new Xoops\Form\RadioYesNo(_MB_MENUS_USE_THEME_SKIN, 'options[2]', $options[2]);
177: $element->setDescription(_MB_MENUS_USE_THEME_SKIN_DSC);
178: $form->addElement($element);
179:
180:
181: $display_options = array(
182: 'block' => _MB_MENUS_DISPLAY_METHOD_BLOCK,
183: 'template' => _MB_MENUS_DISPLAY_METHOD_TEMPLATE
184: );
185: $element = new Xoops\Form\Select(_MB_MENUS_DISPLAY_METHOD, 'options[3]', $options[3], 1);
186: $element->addOptionArray($display_options);
187: $element->setDescription(sprintf(_MB_MENUS_DISPLAY_METHOD_DSC, $options[4]));
188: $form->addElement($element);
189:
190:
191: $element = new Xoops\Form\Text(_MB_MENUS_UNIQUEID, 'options[4]', 2, 20, $options[4]);
192: $element->setDescription(_MB_MENUS_UNIQUEID_DSC);
193: $form->addElement($element);
194:
195: return $form->render();
196: }
197:
198: function menus_mainmenu_show()
199: {
200: $block = array();
201: $xoops = Xoops::getInstance();
202: $helper = Xoops::getModuleHelper('menus');
203:
204: $module_handler = $xoops->getHandlerModule();
205: $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
206: $criteria->add(new Criteria('isactive', 1));
207: $criteria->add(new Criteria('weight', 0, '>'));
208: $modules = $module_handler->getObjectsArray($criteria, true);
209: $moduleperm_handler = $xoops->getHandlerGroupPermission();
210: $groups = $xoops->getUserGroups();
211: $read_allowed = $moduleperm_handler->getItemIds('module_read', $groups);
212: $menus = array();
213: $menu = $helper->getHandlerMenu()->create();
214: $menu->setVar('id', 1);
215: $menu->setVar('pid', 0);
216: $menu->setVar('alt_title', _MB_MENUS_HOME);
217: $menu->setVar('title', _MB_MENUS_HOME);
218: $menu->setVar('link', \XoopsBaseConfig::get('url'));
219: $menu->setVar('image', 'icon-home');
220: $menus[] = $menu->getValues();
221: foreach (array_keys($modules) as $i) {
222: if (in_array($i, $read_allowed)) {
223:
224: $menu = $helper->getHandlerMenu()->create();
225: $menu->setVar('id', $i);
226: $menu->setVar('pid', 0);
227: $menu->setVar('title', $modules[$i]->getVar('name'));
228: $menu->setVar('alt_title', $modules[$i]->getVar('name'));
229: $menu->setVar('link', \XoopsBaseConfig::get('url') . '/modules/' . $modules[$i]->getVar('dirname'));
230: $menu->setVar('image', 'icon-tags');
231: $menus[] = $menu->getValues();
232: if ($xoops->isModule() && $xoops->module->getVar('dirname') == $modules[$i]->getVar('dirname') && $plugin = \Xoops\Module\Plugin::getPlugin($modules[$i]->getVar('dirname'), 'menus')) {
233: $sublinks = $plugin->subMenus();
234: $j = -1;
235: foreach ($sublinks as $sublink) {
236: $menu = $helper->getHandlerMenu()->create();
237: $menu->setVar('id', $j);
238: $menu->setVar('pid', $i);
239: $menu->setVar('title', $sublink['name']);
240: $menu->setVar('alt_title', $sublink['name']);
241: $menu->setVar('link', \XoopsBaseConfig::get('url') . '/modules/' . $modules[$i]->getVar('dirname') . '/'. $sublink['url']);
242: $menus[] = $menu->getValues();
243: $j--;
244: }
245: }
246: }
247: }
248: $builder = new MenusBuilder($menus);
249: $block = $builder->render();
250:
251: $skin_info = $helper->getSkinInfo('mainmenu', false);
252: $blockTpl = new XoopsTpl();
253: $blockTpl->assign('block', $block);
254: $blockTpl->assign('config', $skin_info['config']);
255: $blockTpl->assign('skinurl', $skin_info['url']);
256: $blockTpl->assign('skinpath', $skin_info['path']);
257:
258: $block['content'] = $blockTpl->fetch($skin_info['template']);
259:
260: return $block;
261: }
262: