3 * @version $Id: html.php 5538 2013-01-10 09:53:17Z fishbone $
4 * @package Joomla.Framework
6 * @copyright Copyright (C) 2005 - 2007 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.
16 * Utility class for all HTML drawing classes
19 * @package Joomla.Framework
28 * Additional arguments may be supplied and are passed to the sub-class.
29 * Additional include paths are also able to be specified for third-party use
31 * @param string The name of helper method to load, (prefix).(class).function
32 * prefix and class are optional and can be used to load custom
35 public static function _( $type )
39 //Initialise variables
44 // Check to see if we need to load a helper file
45 $parts = explode('.', $type);
51 $prefix = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
52 $file = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
53 $func = preg_replace( '#[^A-Z0-9_]#i', '', $parts[2] );
58 $file = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
59 $func = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
63 $className = $prefix.ucfirst($file);
64 if (!class_exists( $className ))
66 if ($path = $gEnvManager->getJoomlaRootPath() . '/class/html/' . strtolower($file) . '.php')
70 if (!class_exists( $className ))
72 JError::raiseWarning( 0, $className.'::' .$func. ' not found in file.' );
78 JError::raiseWarning( 0, $prefix.$file . ' not supported. File not found.' );
83 if (is_callable( array( $className, $func ) ))
85 $args = func_get_args();
87 return call_user_func_array( array( $className, $func ), $args );
91 JError::raiseWarning( 0, $className.'::'.$func.' not supported.' );
97 * Write a <a></a> element
100 * @param string The relative URL to use for the href attribute
101 * @param string The target attribute to use
102 * @param array An associative array of attributes to add
105 public static function link($url, $text, $attribs = null)
107 if (is_array( $attribs )) {
108 $attribs = JArrayHelper::toString( $attribs );
111 return '<a href="'.$url.'" '.$attribs.'>'.$text.'</a>';
115 * Write a <img></amg> element
118 * @param string The relative or absoluete URL to use for the src attribute
119 * @param string The target attribute to use
120 * @param array An associative array of attributes to add
123 public static function image($url, $alt, $attribs = null)
125 if (is_array($attribs)) {
126 $attribs = JArrayHelper::toString( $attribs );
129 if(strpos($url, 'http') !== 0) {
130 $url = JURI::root(true).'/'.$url;
133 return '<img src="'.$url.'" alt="'.$alt.'" '.$attribs.' />';
137 * Write a <iframe></iframe> element
140 * @param string The relative URL to use for the src attribute
141 * @param string The target attribute to use
142 * @param array An associative array of attributes to add
143 * @param string The message to display if the iframe tag is not supported
146 public static function iframe( $url, $name, $attribs = null, $noFrames = '' )
148 if (is_array( $attribs )) {
149 $attribs = JArrayHelper::toString( $attribs );
152 return '<iframe src="'.$url.'" '.$attribs.' name="'.$name.'">'.$noFrames.'</iframe>';
156 * Write a <script></script> element
159 * @param string The name of the script file
160 * * @param string The relative or absolute path of the script file
161 * @param boolean If true, the mootools library will be loaded
164 public static function script($filename, $path = 'media/system/js/', $mootools = true)
166 // Include mootools framework
168 JHTML::_('behavior.mootools');
171 if(strpos($path, 'http') !== 0) {
172 $path = JURI::root(true).'/'.$path;
175 $document = &JFactory::getDocument();
176 $document->addScript( $path.$filename );
181 * Write a <link rel="stylesheet" style="text/css" /> element
184 * @param string The relative URL to use for the href attribute
187 public static function stylesheet($filename, $path = 'media/system/css/', $attribs = array())
189 if(strpos($path, 'http') !== 0) {
190 $path = JURI::root(true).'/'.$path;
193 $document = &JFactory::getDocument();
194 $document->addStylesheet( $path.$filename, 'text/css', null, $attribs );
199 * Returns formated date according to current local and adds time offset
202 * @param string date in an US English date format
203 * @param string format optional format for strftime
204 * @returns string formated date
208 /* public static function date($date, $format = null, $offset = NULL)
211 $format = JText::_('DATE_FORMAT_LC1');
215 $config =& JFactory::getConfig();
216 $offset = $config->getValue('config.offset');
218 $instance =& JFactory::getDate($date);
219 $instance->setOffset($offset);
221 return $instance->toFormat($format);
224 * Returns formated date according to a given format and time zone.
226 * @param string $input String in a format accepted by date(), defaults to "now".
227 * @param string $format The date format specification string (see {@link PHP_MANUAL#date})
228 * @param mixed $tz Time zone to be used for the date. Special cases: boolean true for user
229 * setting, boolean false for server setting.
230 * @param boolean $gregorian True to use Gregorian calenar
232 * @return string A date translated by the given format and time zone.
237 public static function date($input = 'now', $format = null, $tz = true, $gregorian = false)
239 // Get some system objects.
240 // $config = JFactory::getConfig();
241 // $user = JFactory::getUser();
243 // UTC date converted to user time zone.
246 // Get a date object based on UTC.
247 $date = JFactory::getDate($input, 'UTC');
249 // Set the correct time zone based on the user configuration.
250 $date->setTimeZone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
252 // UTC date converted to server time zone.
253 elseif ($tz === false)
255 // Get a date object based on UTC.
256 $date = JFactory::getDate($input, 'UTC');
258 // Set the correct time zone based on the server configuration.
259 $date->setTimeZone(new DateTimeZone($config->get('offset')));
261 // No date conversion.
262 elseif ($tz === null)
264 $date = JFactory::getDate($input);
266 // UTC date converted to given time zone.
269 // Get a date object based on UTC.
270 $date = JFactory::getDate($input, 'UTC');
272 // Set the correct time zone based on the server configuration.
273 $date->setTimeZone(new DateTimeZone($tz));
276 // If no format is given use the default locale based format.
279 $format = JText::_('DATE_FORMAT_LC1');
281 // $format is an existing language key
282 elseif (JFactory::getLanguage()->hasKey($format))
284 $format = JText::_($format);
289 return $date->format($format, true);
293 return $date->calendar($format, true);
298 * Creates a tooltip with an image as button
301 * @param string $tooltip The tip string
302 * @param string $title The title of the tooltip
303 * @param string $image The image for the tip, if no text is provided
304 * @param string $text The text for the tip
305 * @param string $href An URL that will be used to create the link
306 * @param boolean depreciated
310 public static function tooltip($tooltip, $title='', $image='tooltip.png', $text='', $href='', $link=1)
312 $tooltip = addslashes(htmlspecialchars($tooltip));
313 $title = addslashes(htmlspecialchars($title));
316 $image = JURI::root(true).'/includes/js/ThemeOffice/'. $image;
317 $text = '<img src="'. $image .'" border="0" alt="'. JText::_( 'Tooltip' ) .'"/>';
319 $text = JText::_( $text, true );
323 $title = $title.'::';
326 $style = 'style="text-decoration: none; color: #333;"';
329 $href = JRoute::_( $href );
331 $tip = '<span class="editlinktip hasTip" title="'.$title.$tooltip.'" '. $style .'><a href="'. $href .'">'. $text .'</a></span>';
333 $tip = '<span class="editlinktip hasTip" title="'.$title.$tooltip.'" '. $style .'>'. $text .'</span>';
340 * Displays a calendar control field
342 * @param string The date value
343 * @param string The name of the text field
344 * @param string The id of the text field
345 * @param string The date format
346 * @param array Additional html attributes
348 public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null)
350 JHTML::_('behavior.calendar'); //load the calendar behavior
352 if (is_array($attribs)) {
353 $attribs = JArrayHelper::toString( $attribs );
355 $document =& JFactory::getDocument();
356 $document->addScriptDeclaration('window.addEvent(\'domready\', function() {Calendar.setup({
357 inputField : "'.$id.'", // id of the input field
358 ifFormat : "'.$format.'", // format of the input field
359 button : "'.$id.'_img", // trigger for the calendar (button ID)
360 align : "Tl", // alignment (defaults to "Bl")
364 return '<input type="text" name="'.$name.'" id="'.$id.'" value="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" '.$attribs.' />'.
365 '<img class="calendar" src="'.JURI::root(true).'/templates/system/images/calendar.png" alt="calendar" id="'.$id.'_img" />';
369 * Add a directory where JHTML should search for helpers. You may
370 * either pass a string or an array of directories.
373 * @param string A path to search.
374 * @return array An array with directory elements
377 public static function addIncludePath( $path='' )
381 if (!isset($paths)) {
382 $paths = array( JPATH_LIBRARIES.DS.'joomla'.DS.'html'.DS.'html' );
385 // force path to array
386 settype($path, 'array');
388 // loop through the path directories
389 /* foreach ($path as $dir)
391 if (!empty($dir) && !in_array($dir, $paths)) {
392 array_unshift($paths, JPath::clean( $dir ));