1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class SystemMenuHandler
23: {
24: 25: 26: 27:
28: private $_menutop = array();
29: private $_menutabs = array();
30: private $_obj;
31: private $_header;
32: private $_subheader;
33:
34: 35: 36:
37: public function __construct()
38: {
39: $xoops = Xoops::getInstance();
40: $this->_obj = $xoops->module;
41: }
42:
43: public function getAddon($addon)
44: {
45: $this->_obj = $addon;
46: }
47:
48: 49: 50:
51: public function addMenuTop($link, $name = "")
52: {
53: $this->_menutop[] = array('link' => $link, 'name' => $name);
54: }
55:
56: public function addMenuTopArray($options, $multi = true)
57: {
58: if (is_array($options)) {
59: if ($multi == true) {
60: foreach ($options as $k => $v) {
61: $this->addOptionTop($k, $v);
62: }
63: } else {
64: foreach ($options as $k) {
65: $this->addOptiontop($k, $k);
66: }
67: }
68: }
69: }
70:
71: 72: 73:
74: public function addMenuTabs($link, $name = "")
75: {
76: $this->_menutabs[] = array('link' => $link, 'name' => $name, 'current' => 0);
77: }
78:
79: public function addMenuTabsArray($options, $multi = true)
80: {
81: if (is_array($options)) {
82: if ($multi == true) {
83: foreach ($options as $k => $v) {
84: $this->addMenuTabsTop($k, $v);
85: }
86: } else {
87: foreach ($options as $k) {
88: $this->addMenuTabsTop($k, $k);
89: }
90: }
91: }
92: }
93:
94: public function addHeader($value)
95: {
96: $this->_header = $value;
97: }
98:
99: public function addSubHeader($value)
100: {
101: $this->_subheader = $value;
102: }
103:
104: public function breadcrumb_nav($basename = "Home")
105: {
106: global $bc_site, $bc_label;
107: $site = $bc_site;
108: $return_str = "<a href=\"/\">$basename</a>";
109: $str = substr(dirname(Xoops::getInstance()->getEnv('PHP_SELF')), 1);
110:
111: $arr = split('/', $str);
112: $num = count($arr);
113:
114: if ($num > 1) {
115: foreach ($arr as $val) {
116: $return_str .= ' > <a href="' . $site . $val . '/">' . $bc_label[$val] . '</a>';
117: $site .= $val . '/';
118: }
119: } else {
120: if ($num == 1) {
121: $arr = $str;
122: $return_str .= ' > <a href="' . $bc_site . $arr . '/">' . $bc_label[$arr] . '</a>';
123: }
124: }
125:
126: return $return_str;
127: }
128:
129: public function render($currentoption = 1, $display = true)
130: {
131: $xoops = Xoops::getInstance();
132: $xoops->tpl()->assign('xo_module_menu_top', $this->_menutop);
133: $this->_menutabs[$currentoption]['current'] = 1;
134: $xoops->tpl()->assign('xo_module_menu_tab', $this->_menutabs);
135:
136:
137:
138:
139: return;
140:
141: global $modversion;
142: $_dirname = $this->_obj->getVar('dirname');
143: $i = 0;
144:
145: 146: 147:
148: foreach ($this->_menutabs as $k => $menus) {
149: $menuItems[] = $menus;
150: }
151: $breadcrumb = $menuItems[$currentoption];
152: $menuItems[$currentoption] = 'current';
153:
154:
155: $menu = "<div id='buttontop_mod'>";
156: $menu .= "<table style='width: 100%; padding: 0;' cellspacing='0'>\n<tr>";
157: $menu .= "<td style='font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;'>";
158: foreach ($this->_menutop as $k => $v) {
159: $menu .= " <a href=\"$k\">$v</a> |";
160: }
161: $menu = substr($menu, 0, -1);
162:
163: $menu .= "</td>";
164: $menu .= "<td style='text-align: right;'><strong>" . $this->_obj->getVar('name') . "</strong> : " . $breadcrumb . "</td>";
165: $menu .= "</tr>\n</table>\n";
166: $menu .= "</div>\n";
167: $menu .= "<div id='buttonbar_mod'><ul>";
168: foreach ($this->_menutabs as $k => $v) {
169: $menu .= "<li id='" . $menuItems[$i] . "'><a href='" . \XoopsBaseConfig::get('url') . "/modules/" . $this->_obj->getVar('dirname') . "/" . $k . "'><span>$v</span></a></li>\n";
170: ++$i;
171: }
172: $menu .= "</ul>\n</div>\n";
173: if ($this->_header) {
174: $menu .= "<h4 class='admin_header'>";
175: if (isset($modversion['name'])) {
176: if ($modversion['image'] && $this->_obj->getVar('mid') == 1) {
177: $system_image = \XoopsBaseConfig::get('url') . '/modules/system/images/system/' . $modversion['image'];
178: } else {
179: $system_image = \XoopsBaseConfig::get('url') . '/modules/' . $_dirname . '/images/' . $modversion['image'];
180: }
181: $menu .= "<img src='$system_image' align='middle' height='32' width='32' alt='' />";
182: $menu .= " " . $modversion['name'] . "</h4>\n";
183: } else {
184: $menu .= " " . $this->_header . "</h4>\n";
185: }
186: }
187: if ($this->_subheader) {
188: $menu .= "<div class='admin_subheader'>" . $this->_subheader . "</div>\n";
189: }
190: $menu .= '<div class="clear"> </div>';
191: unset($this->_obj);
192: if ($display == true) {
193: echo $menu;
194: } else {
195: return $menu;
196: }
197: }
198: }
199: