| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 5 | |
|---|
| 6 | // +-------------------------------------------------------------------+ |
|---|
| 7 | // | WiFiDog Authentication Server | |
|---|
| 8 | // | ============================= | |
|---|
| 9 | // | | |
|---|
| 10 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 11 | // | portal suite. | |
|---|
| 12 | // +-------------------------------------------------------------------+ |
|---|
| 13 | // | PHP version 5 required. | |
|---|
| 14 | // +-------------------------------------------------------------------+ |
|---|
| 15 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 16 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 17 | // +-------------------------------------------------------------------+ |
|---|
| 18 | // | This program is free software; you can redistribute it and/or | |
|---|
| 19 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 20 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 21 | // | the License, or (at your option) any later version. | |
|---|
| 22 | // | | |
|---|
| 23 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 24 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 26 | // | GNU General Public License for more details. | |
|---|
| 27 | // | | |
|---|
| 28 | // | You should have received a copy of the GNU General Public License | |
|---|
| 29 | // | along with this program; if not, contact: | |
|---|
| 30 | // | | |
|---|
| 31 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 32 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 33 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 34 | // | | |
|---|
| 35 | // +-------------------------------------------------------------------+ |
|---|
| 36 | |
|---|
| 37 | /** This file contains the code for the MainUI class, as well as GUI exception handling. |
|---|
| 38 | * @package WiFiDogAuthServer |
|---|
| 39 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 40 | * @copyright 2005-2007 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 41 | * @version Subversion $Id: MainUI.php 1246 2007-07-03 16:35:09Z benoitg $ |
|---|
| 42 | * @link http://www.wifidog.org/ |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | /** |
|---|
| 46 | * Load required files |
|---|
| 47 | */ |
|---|
| 48 | |
|---|
| 49 | require_once('classes/SmartyWifidog.php'); |
|---|
| 50 | |
|---|
| 51 | define('MENU_ITEM_GROUPING','MENU_ITEM_GROUPING'); |
|---|
| 52 | /** |
|---|
| 53 | * Singleton class for managing menu. |
|---|
| 54 | * |
|---|
| 55 | * @package WiFiDogAuthServer |
|---|
| 56 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 57 | * @copyright 2005-2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 58 | */ |
|---|
| 59 | class Menu { |
|---|
| 60 | /** holder for the singleton */ |
|---|
| 61 | private static $object; |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Object for Smarty class |
|---|
| 65 | */ |
|---|
| 66 | private $smarty; |
|---|
| 67 | /** The array from which the menu is generated */ |
|---|
| 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 | * Contructor |
|---|
| 81 | * |
|---|
| 82 | * @return void |
|---|
| 83 | * |
|---|
| 84 | * @access public |
|---|
| 85 | */ |
|---|
| 86 | private function __construct() { |
|---|
| 87 | //$db = AbstractDb :: getObject(); |
|---|
| 88 | // Init Smarty |
|---|
| 89 | $this->smarty = SmartyWifidog :: getObject(); |
|---|
| 90 | |
|---|
| 91 | // Init the menu array |
|---|
| 92 | $this->_menuArray = array('childrens'=>array()); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /** Builds an HTML menu, appends it to $userData*/ |
|---|
| 96 | static private function buildHtmlMenuItemCallback($menuItemArray, $menuItemIndex, &$userData) { |
|---|
| 97 | //echo "buildHtmlMenuItemCallback for: ";pretty_print_r($menuItemArray); |
|---|
| 98 | $html = ''; |
|---|
| 99 | //echo "previous_level: {$userData['previous_level']} current_level: {$menuItemArray['level']}<br/>"; |
|---|
| 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 | if(!empty($menuItemArray['url'])) { |
|---|
| 105 | $html .= "<li><a href='{$menuItemArray['url']}'>{$menuItemArray['title']}</a>\n"; |
|---|
| 106 | } |
|---|
| 107 | else if(!empty($menuItemArray['childrens'])){ |
|---|
| 108 | $html .= "<li><a href='#'>{$menuItemArray['title']}</a>\n"; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | if(!empty($menuItemArray['childrens'])) { |
|---|
| 112 | $html .= "<ul>\n"; |
|---|
| 113 | } else { |
|---|
| 114 | $html .= "\n</li>\n"; |
|---|
| 115 | } |
|---|
| 116 | $userData['previous_level'] = $menuItemArray['level']; |
|---|
| 117 | isset($userData['html'])?$userData['html'].=$html:$userData['html']=$html; |
|---|
| 118 | } |
|---|
| 119 | /** Takes an array_walk_recursive compatible callback. Will be called for each menu item */ |
|---|
| 120 | private function menuArrayWalkRecursiveReal($menuArray, $menuItemIdx, $funcname, &$userdata = null) { |
|---|
| 121 | //echo "menuArrayWalkRecursive called with menuArray:"; pretty_print_r($menuArray); |
|---|
| 122 | $retval = true; |
|---|
| 123 | if(isset($menuArray['path'])){ |
|---|
| 124 | //Only call if we are in a real menu item (and, among other, not at the root) |
|---|
| 125 | //echo "menuArrayWalkRecursive(): Calling callback.<br/>"; |
|---|
| 126 | $retval = call_user_func($funcname, $menuArray, $menuItemIdx, &$userdata); |
|---|
| 127 | } |
|---|
| 128 | foreach ($menuArray['childrens'] as $menuItemIdx => $menuItem) { |
|---|
| 129 | //pretty_print_r($menuItem); |
|---|
| 130 | //echo "Recusively calling for $menuItemIdx<br/>"; |
|---|
| 131 | $retval = $retval & self::menuArrayWalkRecursiveReal($menuItem, $menuItemIdx, $funcname, &$userdata); |
|---|
| 132 | } |
|---|
| 133 | return $retval; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | /** Takes an array_walk_recursive compatible callback. Will be called for each menu item */ |
|---|
| 137 | public function menuArrayWalkRecursive($funcname, &$userdata = null) { |
|---|
| 138 | return self::menuArrayWalkRecursiveReal($this->_menuArray, 0, $funcname, &$userdata); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | public function processHookMenu($classname) { |
|---|
| 142 | require_once("classes/$classname.php"); |
|---|
| 143 | $hookArray = call_user_func(array($classname, 'hookMenu')); |
|---|
| 144 | //pretty_print_r($hookArray); |
|---|
| 145 | foreach($hookArray as $hookArrayItem) { |
|---|
| 146 | |
|---|
| 147 | $parts = explode('/', $hookArrayItem['path']); |
|---|
| 148 | $menuItem=&$this->_menuArray;//This is just for initialisation, the foreach will set it to a leaf of menuitem. |
|---|
| 149 | foreach ($parts as $k => $part) { |
|---|
| 150 | //echo "$k => $part<br/>"; |
|---|
| 151 | if (!isset($menuItem['childrens'][$part])){ |
|---|
| 152 | //echo "$part does not exist, setting it<br/>"; |
|---|
| 153 | $menuItem['childrens'][$part]=array("childrens"=>array(), "level"=>$k); |
|---|
| 154 | } |
|---|
| 155 | $menuItem=&$menuItem['childrens'][$part]; |
|---|
| 156 | } |
|---|
| 157 | $menuItem = array_merge($menuItem, $hookArrayItem); |
|---|
| 158 | //echo "Setting menuItem to hookArrayItem of path {$hookArrayItem['path']}, new _menuArray:<br/>"; |
|---|
| 159 | // pretty_print_r($this->_menuArray); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | public function initMenu() { |
|---|
| 163 | $this->processHookMenu('Server'); |
|---|
| 164 | $this->processHookMenu('Node'); |
|---|
| 165 | $this->processHookMenu('Network'); |
|---|
| 166 | $this->processHookMenu('User'); |
|---|
| 167 | $this->processHookMenu('Content'); |
|---|
| 168 | $this->processHookMenu('NodeList'); |
|---|
| 169 | $this->processHookMenu('Role'); |
|---|
| 170 | $this->processHookMenu('VirtualHost'); |
|---|
| 171 | $this->processHookMenu('ContentTypeFilter'); |
|---|
| 172 | $this->processHookMenu('ProfileTemplate'); |
|---|
| 173 | //pretty_print_r($this->_menuArray); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | public function getUserUI() |
|---|
| 177 | { |
|---|
| 178 | $this->initMenu(); |
|---|
| 179 | $html = ''; |
|---|
| 180 | //Deal with internet explorer's baindeadness. From http://www.htmldog.com/articles/suckerfish/dropdowns/example/vertical.html |
|---|
| 181 | $html .= <<<EOT |
|---|
| 182 | <script type="text/javascript"><!--//--><![CDATA[//><!-- |
|---|
| 183 | |
|---|
| 184 | sfHover = function() { |
|---|
| 185 | var sfEls = document.getElementById("nav").getElementsByTagName("LI"); |
|---|
| 186 | for (var i=0; i<sfEls.length; i++) { |
|---|
| 187 | sfEls[i].onmouseover=function() { |
|---|
| 188 | this.className+=" sfhover"; |
|---|
| 189 | } |
|---|
| 190 | sfEls[i].onmouseout=function() { |
|---|
| 191 | this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | if (window.attachEvent) window.attachEvent("onload", sfHover); |
|---|
| 196 | |
|---|
| 197 | //--><!]]></script> |
|---|
| 198 | EOT; |
|---|
| 199 | $html .= "<ul id='nav'>\n"; |
|---|
| 200 | $userData=null; |
|---|
| 201 | self::menuArrayWalkRecursive(array('Menu','buildHtmlMenuItemCallback'), $userData); |
|---|
| 202 | $html .= $userData['html']; |
|---|
| 203 | if(isset($userData['previous_level']) && $userData['previous_level']>0) { |
|---|
| 204 | $html .= "</ul>\n"; |
|---|
| 205 | } |
|---|
| 206 | $html .= "</ul>\n"; |
|---|
| 207 | //echo htmlspecialchars($userData['html']); |
|---|
| 208 | return $html; |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | /* |
|---|
| 213 | * Local variables: |
|---|
| 214 | * tab-width: 4 |
|---|
| 215 | * c-basic-offset: 4 |
|---|
| 216 | * c-hanging-comment-ender-p: nil |
|---|
| 217 | * End: |
|---|
| 218 | */ |
|---|