| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: toolbar.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla.Framework 5 * @subpackage HTML 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 //Register the session storage class with the loader 19 JLoader::register('JButton', dirname(__FILE__).DS.'toolbar'.DS.'button.php'); 20 21 /** 22 * ToolBar handler 23 * 24 * @package Joomla.Framework 25 * @subpackage HTML 26 * @since 1.5 27 */ 28 class JToolBar extends JObject 29 { 30 /** 31 * Toolbar name 32 * 33 * @access private 34 * @var string 35 */ 36 var $_name = array (); 37 38 /** 39 * Toolbar array 40 * 41 * @access private 42 * @var array 43 */ 44 var $_bar = array (); 45 46 /** 47 * Loaded buttons 48 * 49 * @access private 50 * @var array 51 */ 52 var $_buttons = array (); 53 54 /** 55 * Directories, where button types can be stored 56 * 57 * @access private 58 * @var array 59 */ 60 var $_buttonPath = array (); 61 62 /** 63 * Constructor 64 * 65 * @access protected 66 * @param string The toolbar name 67 * @var string The type of setup file 68 */ 69 function __construct($name = 'toolbar') 70 { 71 $this->_name = $name; 72 73 // Set base path to find buttons 74 $this->_buttonPath[] = dirname(__FILE__).DS.'toolbar'.DS.'button'; 75 76 } 77 78 /** 79 * Returns a reference to a global JToolBar object, only creating it if it 80 * doesn't already exist. 81 * 82 * This method must be invoked as: 83 * <pre> $toolbar = & JToolBar::getInstance( $name );</pre> 84 * 85 * @access public 86 * @param string $name The name of the toolbar. 87 * @return JToolBar The JToolBar object. 88 */ 89 function & getInstance($name = 'toolbar') 90 { 91 static $instances; 92 93 if (!isset ($instances)) { 94 $instances = array (); 95 } 96 97 if (empty ($instances[$name])) { 98 $instances[$name] = new JToolBar($name); 99 } 100 101 return $instances[$name]; 102 } 103 104 /** 105 * Set a value 106 * 107 * @access public 108 * @param string The name of the param 109 * @param string The value of the parameter 110 * @return string The set value 111 */ 112 function appendButton() 113 { 114 // Push button onto the end of the toolbar array 115 $btn = func_get_args(); 116 array_push($this->_bar, $btn); 117 return true; 118 } 119 120 /** 121 * Get a value 122 * 123 * @access public 124 * @param string The name of the param 125 * @param mixed The default value if not found 126 * @return string 127 */ 128 function prependButton() 129 { 130 // Insert button into the front of the toolbar array 131 $btn = func_get_args(); 132 array_unshift($this->_bar, $btn); 133 return true; 134 } 135 136 /** 137 * Render 138 * 139 * @access public 140 * @param string The name of the control, or the default text area if a setup file is not found 141 * @return string HTML 142 */ 143 function render() 144 { 145 $html = array (); 146 147 // Start toolbar div 148 $html[] = '<div class="toolbar" id="'.$this->_name.'">'; 149 $html[] = '<table class="toolbar"><tr>'; 150 151 // Render each button in the toolbar 152 foreach ($this->_bar as $button) { 153 $html[] = $this->renderButton($button); 154 } 155 156 // End toolbar div 157 $html[] = '</tr></table>'; 158 $html[] = '</div>'; 159 160 return implode("\n", $html); 161 } 162 163 /** 164 * Render a parameter type 165 * 166 * @param object A param tag node 167 * @param string The control name 168 * @return array Any array of the label, the form element and the tooltip 169 */ 170 function renderButton( &$node ) 171 { 172 // Get the button type 173 $type = $node[0]; 174 175 $button = & $this->loadButtonType($type); 176 177 /** 178 * Error Occurred 179 */ 180 if ($button === false) { 181 return JText::_('Button not defined for type').' = '.$type; 182 } 183 return $button->render($node); 184 } 185 186 /** 187 * Loads a button type 188 * 189 * @access public 190 * @param string buttonType 191 * @return object 192 * @since 1.5 193 */ 194 function & loadButtonType($type, $new = false) 195 { 196 $false = false; 197 198 $signature = md5($type); 199 if (isset ($this->_buttons[$signature]) && $new === false) { 200 return $this->_buttons[$signature]; 201 } 202 203 if (!class_exists('JButton')) 204 { 205 JError::raiseWarning( 'SOME_ERROR_CODE', 'Could not load button base class.' ); 206 return $false; 207 } 208 209 $buttonClass = 'JButton'.$type; 210 if (!class_exists($buttonClass)) 211 { 212 if (isset ($this->_buttonPath)) { 213 $dirs = $this->_buttonPath; 214 } else { 215 $dirs = array (); 216 } 217 218 $file = JFilterInput::clean(str_replace('_', DS, strtolower($type)).'.php', 'path'); 219 220 jimport('joomla.filesystem.path'); 221 if ($buttonFile = JPath::find($dirs, $file)) { 222 include_once $buttonFile; 223 } else { 224 JError::raiseWarning('SOME_ERROR_CODE', "Could not load module $buttonClass ($buttonFile)."); 225 return $false; 226 } 227 } 228 229 if (!class_exists($buttonClass)) 230 { 231 //return JError::raiseError( 'SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass." ); 232 return $false; 233 } 234 $this->_buttons[$signature] = new $buttonClass($this); 235 236 return $this->_buttons[$signature]; 237 } 238 239 /** 240 * Add a directory where JToolBar should search for button types 241 * 242 * You may either pass a string or an array of directories. 243 * 244 * {@link JParameter} will be searching for an element type in the same order you 245 * added them. If the parameter type cannot be found in the custom folders, 246 * it will look in JParameter/types. 247 * 248 * @access public 249 * @param string|array directory or directories to search. 250 * @since 1.5 251 */ 252 function addButtonPath($path) 253 { 254 if (is_array($path)) { 255 $this->_buttonPath = array_merge($this->_buttonPath, $path); 256 } else { 257 array_push($this->_buttonPath, $path); 258 } 259 } 260 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |