00001 <?php
00038 class tpNavigation extends Plugin
00039 {
00043 function tpNavigation() {
00044 $this->Plugin();
00045 $this->depend('html');
00046 }
00047
00048 function menu($config=false, $config_file='navigation.php')
00049 {
00050 if(!$config) {
00051 require_once(DIR_FS_APP.DS.'config'.DS.$config_file);
00052 $config = $NAV_MENU;
00053 unset($NAV_MENU);
00054
00055 if(defined('MODULES')) {
00056 foreach(explode(' ', MODULES) as $modname) {
00057 $modpath = DIR_FS_APP.DS.'modules'.DS.$modname.DS.'config'.DS;
00058 if(file_exists($modpath.$config_file)) {
00059 require_once($modpath.$config_file);
00060 $config += $NAV_MENU;
00061 unset($NAV_MENU);
00062 }
00063 }
00064 }
00065 }
00066
00067 $out = '<ul class="nav">';
00068 foreach($config as $label=>$item) {
00069 $out .= $this->_submenu($label, $item, true);
00070 }
00071 $out .= '</ul>';
00072 return $out;
00073 }
00074
00075 function _is_active($menu)
00076 {
00077 foreach($menu as $label=>$item) {
00078 if(isset($menu['base']) && preg_match("|^{$menu['base']}|", url(CURRENT_URL))) return true;
00079 if(isset($item['menu']) && $this->_is_active($item['menu'])) return true;
00080 if(isset($item['url']) && $item['url'] == url(CURRENT_URL)) return true;
00081 }
00082 return false;
00083 }
00084
00085 function _submenu($label, $menu, $toplevel)
00086 {
00087 $ret = '';
00088 if(!empty($menu['access'])) {
00089 if(substr($menu['access'], 0, 1) == '!' && a(substr($menu['access'], 1))) return '';
00090 if(substr($menu['access'], 0, 1) != '!' && !a($menu['access'])) return '';
00091 }
00092 if(isset($menu['menu'])) {
00093
00094
00095 $a = $this->_is_active($menu['menu']) ? 'current' : '';
00096
00097
00098 $ret .= '<li><a href="#" class="'.$a.'">'.$label.'</a>';
00099 $ret .= '<ul>';
00100 foreach($menu['menu'] as $sublabel=>$subitem) {
00101 $ret .= $this->_submenu($sublabel, $subitem, false);
00102 }
00103 $ret .= '</ul></li>';
00104 } else if(isset($menu['url'])) {
00105 $a = array();
00106 if($toplevel) {
00107 if(url(CURRENT_URL) == $menu['url']) {
00108 $a['class'] = 'current';
00109 } else if(isset($menu['base']) && preg_match("|^{$menu['base']}|", url(CURRENT_URL))) {
00110 $a['class'] = 'current';
00111 }
00112 }
00113 $ret .= '<li>'.$this->depends->html->link($label, $menu['url'], '', false, $a).'</li>';
00114 } else {
00115
00116 $ret .= '<li></li>';
00117 }
00118 return $ret;
00119 }
00120
00121 }
00122
00123 ?>