| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
require_once('classes/SmartyWifidog.php'); |
|---|
| 50 |
|
|---|
| 51 |
define('MENU_ITEM_GROUPING','MENU_ITEM_GROUPING'); |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
class Menu { |
|---|
| 60 |
|
|---|
| 61 |
private static $object; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
* Object for Smarty class |
|---|
| 65 |
*/ |
|---|
| 66 |
private $smarty; |
|---|
| 67 |
|
|---|
| 68 |
private $menuArray; |
|---|
| 69 |
|
|---|
| 70 |
* Get the MainUI object |
|---|
| 71 |
* @return object The MainUI object |
|---|
| 72 |
*/ |
|---|
| 73 |
public static function &getObject() { |
|---|
| 74 |
if (self :: $object == null) { |
|---|
| 75 |
self :: $object = new self(); |
|---|
| 76 |
} |
|---|
| 77 |
return self :: $object; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
* Constructor |
|---|
| 81 |
* |
|---|
| 82 |
* @return void |
|---|
| 83 |
* |
|---|
| 84 |
* @access public |
|---|
| 85 |
*/ |
|---|
| 86 |
private function __construct() { |
|---|
| 87 |
|
|---|
| 88 |
// Init Smarty |
|---|
| 89 |
$this->smarty = SmartyWifidog :: getObject(); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
$this->_menuArray = array('childrens'=>array()); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
static private function buildHtmlMenuItemCallback($menuItemArray, $menuItemIndex, &$userData) { |
|---|
| 97 |
|
|---|
| 98 |
$html = ''; |
|---|
| 99 |
|
|---|
| 100 |
if(isset($userData['previous_level']) && $userData['previous_level']>$menuItemArray['level']) { |
|---|
| 101 |
$html .= "</ul>\n</li>\n"; |
|---|
| 102 |
} |
|---|
| 103 |
!empty($menuItemArray['title'])?$title=$menuItemArray['title']:$title=$menuItemArray['path']; |
|---|
| 104 |
$class = preg_replace ("/.*?([^\/]*$)/", "$1", $menuItemArray['path']); |
|---|
| 105 |
if(!empty($menuItemArray['url'])) { |
|---|
| 106 |
$html .= "<li class='$class'><a href='{$menuItemArray['url']}'>{$menuItemArray['title']}</a>\n"; |
|---|
| 107 |
} |
|---|
| 108 |
else if(!empty($menuItemArray['childrens'])){ |
|---|
| 109 |
$html .= "<li class='$class'><a href='#'>{$menuItemArray['title']}</a>\n"; |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
if(!empty($menuItemArray['childrens'])) { |
|---|
| 113 |
$html .= "<ul class='$class'>\n"; |
|---|
| 114 |
} else if(!empty($menuItemArray['url'])){ |
|---|
| 115 |
$html .= "\n</li>\n"; |
|---|
| 116 |
} |
|---|
| 117 |
$userData['previous_level'] = $menuItemArray['level']; |
|---|
| 118 |
isset($userData['html'])?$userData['html'].=$html:$userData['html']=$html; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
private static function menuArrayWalkRecursiveReal($menuArray, $menuItemIdx, $funcname, &$userdata = null) { |
|---|
| 122 |
|
|---|
| 123 |
$retval = true; |
|---|
| 124 |
if(isset($menuArray['path'])){ |
|---|
| 125 |
|
|---|
| 126 |
//echo "menuArrayWalkRecursive(): Calling callback.<br/>"; |
|---|
| 127 |
$retval = call_user_func_array($funcname, array($menuArray, $menuItemIdx, &$userdata)); |
|---|
| 128 |
} |
|---|
| 129 |
foreach ($menuArray['childrens'] as $menuItemIdx => $menuItem) { |
|---|
| 130 |
|
|---|
| 131 |
//echo "Recusively calling for $menuItemIdx<br/>"; |
|---|
| 132 |
$retval = $retval & self::menuArrayWalkRecursiveReal($menuItem, $menuItemIdx, $funcname, $userdata); |
|---|
| 133 |
} |
|---|
| 134 |
return $retval; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
public function menuArrayWalkRecursive($funcname, &$userdata = null) { |
|---|
| 139 |
return self::menuArrayWalkRecursiveReal($this->_menuArray, 0, $funcname, $userdata); |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
* output is converted to ISO-8859-1 before sorting to allow strcoll() to be used |
|---|
| 143 |
* for locale-specific sorting. |
|---|
| 144 |
*/ |
|---|
| 145 |
public static function titlestrcoll($object1, $object2) |
|---|
| 146 |
{ |
|---|
| 147 |
|
|---|
| 148 |
return strcoll ( utf8_decode($object1['title']), utf8_decode($object2['title']) ); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
private static function menuArraySort(&$menuArray, $funcname, &$userdata = null) { |
|---|
| 153 |
|
|---|
| 154 |
$retval = true; |
|---|
| 155 |
|
|---|
| 156 |
$retval = uasort($menuArray['childrens'], $funcname); |
|---|
| 157 |
foreach ($menuArray['childrens'] as $menuItemIdx => &$menuItem) { |
|---|
| 158 |
|
|---|
| 159 |
//pretty_print_r($menuItem); |
|---|
| 160 |
//echo "Recusively calling for $menuItemIdx<br/>"; |
|---|
| 161 |
$retval = $retval & self::menuArraySort($menuItem, $funcname, $userdata); |
|---|
| 162 |
} |
|---|
| 163 |
return $retval; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
public function processHookMenu($classname) { |
|---|
| 167 |
require_once("classes/$classname.php"); |
|---|
| 168 |
$hookArray = call_user_func(array($classname, 'hookMenu')); |
|---|
| 169 |
|
|---|
| 170 |
foreach($hookArray as $hookArrayItem) { |
|---|
| 171 |
|
|---|
| 172 |
$parts = explode('/', $hookArrayItem['path']); |
|---|
| 173 |
$menuItem=&$this->_menuArray; |
|---|
| 174 |
foreach ($parts as $k => $part) { |
|---|
| 175 |
|
|---|
| 176 |
if (!isset($menuItem['childrens'][$part])){ |
|---|
| 177 |
|
|---|
| 178 |
$menuItem['childrens'][$part]=array("childrens"=>array(), "level"=>$k); |
|---|
| 179 |
} |
|---|
| 180 |
$menuItem=&$menuItem['childrens'][$part]; |
|---|
| 181 |
} |
|---|
| 182 |
$menuItem = array_merge($menuItem, $hookArrayItem); |
|---|
| 183 |
|
|---|
| 184 |
// pretty_print_r($this->_menuArray); |
|---|
| 185 |
} |
|---|
| 186 |
} |
|---|
| 187 |
public function initMenu() { |
|---|
| 188 |
$this->processHookMenu('Server'); |
|---|
| 189 |
$this->processHookMenu('Node'); |
|---|
| 190 |
$this->processHookMenu('Network'); |
|---|
| 191 |
$this->processHookMenu('User'); |
|---|
| 192 |
$this->processHookMenu('Content'); |
|---|
| 193 |
$this->processHookMenu('NodeList'); |
|---|
| 194 |
$this->processHookMenu('Role'); |
|---|
| 195 |
$this->processHookMenu('VirtualHost'); |
|---|
| 196 |
$this->processHookMenu('ContentTypeFilter'); |
|---|
| 197 |
$this->processHookMenu('ProfileTemplate'); |
|---|
| 198 |
$this->processHookMenu('DependenciesList'); |
|---|
| 199 |
self::menuArraySort($this->_menuArray, array('Menu','titlestrcoll')); |
|---|
| 200 |
|
|---|
| 201 |
} |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
* IE's braindeadness requires a javascript workaround to allow suckerfish menus to work. |
|---|
| 205 |
* |
|---|
| 206 |
* @return HTML markup |
|---|
| 207 |
*/ |
|---|
| 208 |
// static public function getIEWorkaroundJS() { |
|---|
| 209 |
// $html = <<<EOT |
|---|
| 210 |
// <script type="text/javascript"><!--//--><![CDATA[//><!-- |
|---|
| 211 |
// |
|---|
| 212 |
// sfHover = function() { |
|---|
| 213 |
// var sfEls = document.getElementById("nav").getElementsByTagName("LI"); |
|---|
| 214 |
// for (var i=0; i<sfEls.length; i++) { |
|---|
| 215 |
// sfEls[i].onmouseover=function() { |
|---|
| 216 |
// this.className+=" sfhover"; |
|---|
| 217 |
// } |
|---|
| 218 |
// sfEls[i].onmouseout=function() { |
|---|
| 219 |
// //alert(this.className); |
|---|
| 220 |
// this.className=this.className.replace(new RegExp(" sfhover"), ""); |
|---|
| 221 |
// //alert(this.className); |
|---|
| 222 |
// } |
|---|
| 223 |
// } |
|---|
| 224 |
// } |
|---|
| 225 |
// if (window.attachEvent) window.attachEvent("onload", sfHover); |
|---|
| 226 |
// |
|---|
| 227 |
// //--><!]]></script> |
|---|
| 228 |
// EOT; |
|---|
| 229 |
// return $html; |
|---|
| 230 |
// } |
|---|
| 231 |
|
|---|
| 232 |
public function getUserUI() |
|---|
| 233 |
{ |
|---|
| 234 |
$this->initMenu(); |
|---|
| 235 |
$html = ''; |
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
$html .= "<ul id='nav'>\n"; |
|---|
| 239 |
$userData=null; |
|---|
| 240 |
self::menuArrayWalkRecursive(array('Menu','buildHtmlMenuItemCallback'), $userData); |
|---|
| 241 |
$html .= $userData['html']; |
|---|
| 242 |
if(isset($userData['previous_level']) && $userData['previous_level']>0) { |
|---|
| 243 |
$html .= "</ul>\n"; |
|---|
| 244 |
} |
|---|
| 245 |
$html .= "</ul>\n"; |
|---|
| 246 |
$html .= "<br/ class='clearbr'>\n"; |
|---|
| 247 |
|
|---|
| 248 |
return $html; |
|---|
| 249 |
} |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|