PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/html/html.php

https://gitlab.com/endomorphosis/greenrenaissancejoomla
PHP | 328 lines | 169 code | 39 blank | 120 comment | 22 complexity | ac9e8aea718ec5de70b5c2ddd33feb72 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: html.php 10079 2008-02-28 13:39:08Z ircmaxell $
  4. * @package Joomla.Framework
  5. * @subpackage HTML
  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.
  13. */
  14. /**
  15. * Utility class for all HTML drawing classes
  16. *
  17. * @static
  18. * @package Joomla.Framework
  19. * @subpackage HTML
  20. * @since 1.5
  21. */
  22. class JHTML
  23. {
  24. /**
  25. * Class loader method
  26. *
  27. * Additional arguments may be supplied and are passed to the sub-class.
  28. * Additional include paths are also able to be specified for third-party use
  29. *
  30. * @param string The name of helper method to load, (prefix).(class).function
  31. * prefix and class are optional and can be used to load custom
  32. * html helpers.
  33. */
  34. function _( $type )
  35. {
  36. //Initialise variables
  37. $prefix = 'JHTML';
  38. $file = '';
  39. $func = $type;
  40. // Check to see if we need to load a helper file
  41. $parts = explode('.', $type);
  42. switch(count($parts))
  43. {
  44. case 3 :
  45. {
  46. $prefix = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
  47. $file = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
  48. $func = preg_replace( '#[^A-Z0-9_]#i', '', $parts[2] );
  49. } break;
  50. case 2 :
  51. {
  52. $file = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
  53. $func = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
  54. } break;
  55. }
  56. $className = $prefix.ucfirst($file);
  57. if (!class_exists( $className ))
  58. {
  59. jimport('joomla.filesystem.path');
  60. if ($path = JPath::find(JHTML::addIncludePath(), strtolower($file).'.php'))
  61. {
  62. require_once $path;
  63. if (!class_exists( $className ))
  64. {
  65. JError::raiseWarning( 0, $className.'::' .$func. ' not found in file.' );
  66. return false;
  67. }
  68. }
  69. else
  70. {
  71. JError::raiseWarning( 0, $prefix.$file . ' not supported. File not found.' );
  72. return false;
  73. }
  74. }
  75. if (is_callable( array( $className, $func ) ))
  76. {
  77. $args = func_get_args();
  78. array_shift( $args );
  79. return call_user_func_array( array( $className, $func ), $args );
  80. }
  81. else
  82. {
  83. JError::raiseWarning( 0, $className.'::'.$func.' not supported.' );
  84. return false;
  85. }
  86. }
  87. /**
  88. * Write a <a></a> element
  89. *
  90. * @access public
  91. * @param string The relative URL to use for the href attribute
  92. * @param string The target attribute to use
  93. * @param array An associative array of attributes to add
  94. * @since 1.5
  95. */
  96. function link($url, $text, $attribs = null)
  97. {
  98. if (is_array( $attribs )) {
  99. $attribs = JArrayHelper::toString( $attribs );
  100. }
  101. return '<a href="'.$url.'" '.$attribs.'>'.$text.'</a>';
  102. }
  103. /**
  104. * Write a <img></amg> element
  105. *
  106. * @access public
  107. * @param string The relative or absoluete URL to use for the src attribute
  108. * @param string The target attribute to use
  109. * @param array An associative array of attributes to add
  110. * @since 1.5
  111. */
  112. function image($url, $alt, $attribs = null)
  113. {
  114. if (is_array($attribs)) {
  115. $attribs = JArrayHelper::toString( $attribs );
  116. }
  117. if(strpos($url, 'http') !== 0) {
  118. $url = JURI::root(true).'/'.$url;
  119. };
  120. return '<img src="'.$url.'" alt="'.$alt.'" '.$attribs.' />';
  121. }
  122. /**
  123. * Write a <iframe></iframe> element
  124. *
  125. * @access public
  126. * @param string The relative URL to use for the src attribute
  127. * @param string The target attribute to use
  128. * @param array An associative array of attributes to add
  129. * @param string The message to display if the iframe tag is not supported
  130. * @since 1.5
  131. */
  132. function iframe( $url, $name, $attribs = null, $noFrames = '' )
  133. {
  134. if (is_array( $attribs )) {
  135. $attribs = JArrayHelper::toString( $attribs );
  136. }
  137. return '<iframe src="'.$url.'" '.$attribs.' name="'.$name.'">'.$noFrames.'</iframe>';
  138. }
  139. /**
  140. * Write a <script></script> element
  141. *
  142. * @access public
  143. * @param string The name of the script file
  144. * * @param string The relative or absolute path of the script file
  145. * @param boolean If true, the mootools library will be loaded
  146. * @since 1.5
  147. */
  148. function script($filename, $path = 'media/system/js/', $mootools = true)
  149. {
  150. // Include mootools framework
  151. if($mootools) {
  152. JHTML::_('behavior.mootools');
  153. }
  154. if(strpos($path, 'http') !== 0) {
  155. $path = JURI::root(true).'/'.$path;
  156. };
  157. $document = &JFactory::getDocument();
  158. $document->addScript( $path.$filename );
  159. return;
  160. }
  161. /**
  162. * Write a <link rel="stylesheet" style="text/css" /> element
  163. *
  164. * @access public
  165. * @param string The relative URL to use for the href attribute
  166. * @since 1.5
  167. */
  168. function stylesheet($filename, $path = 'media/system/css/', $attribs = array())
  169. {
  170. if(strpos($path, 'http') !== 0) {
  171. $path = JURI::root(true).'/'.$path;
  172. };
  173. $document = &JFactory::getDocument();
  174. $document->addStylesheet( $path.$filename, 'text/css', null, $attribs );
  175. return;
  176. }
  177. /**
  178. * Returns formated date according to current local and adds time offset
  179. *
  180. * @access public
  181. * @param string date in an US English date format
  182. * @param string format optional format for strftime
  183. * @returns string formated date
  184. * @see strftime
  185. * @since 1.5
  186. */
  187. function date($date, $format = null, $offset = NULL)
  188. {
  189. if ( ! $format ) {
  190. $format = JText::_('DATE_FORMAT_LC1');
  191. }
  192. if(is_null($offset))
  193. {
  194. $config =& JFactory::getConfig();
  195. $offset = $config->getValue('config.offset');
  196. }
  197. $instance =& JFactory::getDate($date);
  198. $instance->setOffset($offset);
  199. return $instance->toFormat($format);
  200. }
  201. /**
  202. * Creates a tooltip with an image as button
  203. *
  204. * @access public
  205. * @param string $tooltip The tip string
  206. * @param string $title The title of the tooltip
  207. * @param string $image The image for the tip, if no text is provided
  208. * @param string $text The text for the tip
  209. * @param string $href An URL that will be used to create the link
  210. * @param boolean depreciated
  211. * @return string
  212. * @since 1.5
  213. */
  214. function tooltip($tooltip, $title='', $image='tooltip.png', $text='', $href='', $link=1)
  215. {
  216. $tooltip = addslashes(htmlspecialchars($tooltip));
  217. $title = addslashes(htmlspecialchars($title));
  218. if ( !$text ) {
  219. $image = JURI::root(true).'/includes/js/ThemeOffice/'. $image;
  220. $text = '<img src="'. $image .'" border="0" alt="'. JText::_( 'Tooltip' ) .'"/>';
  221. } else {
  222. $text = JText::_( $text, true );
  223. }
  224. if($title) {
  225. $title = $title.'::';
  226. }
  227. $style = 'style="text-decoration: none; color: #333;"';
  228. if ( $href ) {
  229. $href = JRoute::_( $href );
  230. $style = '';
  231. $tip = '<span class="editlinktip hasTip" title="'.$title.$tooltip.'" '. $style .'><a href="'. $href .'">'. $text .'</a></span>';
  232. } else {
  233. $tip = '<span class="editlinktip hasTip" title="'.$title.$tooltip.'" '. $style .'>'. $text .'</span>';
  234. }
  235. return $tip;
  236. }
  237. /**
  238. * Displays a calendar control field
  239. *
  240. * @param string The date value
  241. * @param string The name of the text field
  242. * @param string The id of the text field
  243. * @param string The date format
  244. * @param array Additional html attributes
  245. */
  246. function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null)
  247. {
  248. JHTML::_('behavior.calendar'); //load the calendar behavior
  249. if (is_array($attribs)) {
  250. $attribs = JArrayHelper::toString( $attribs );
  251. }
  252. $document =& JFactory::getDocument();
  253. $document->addScriptDeclaration('window.addEvent(\'domready\', function() {Calendar.setup({
  254. inputField : "'.$id.'", // id of the input field
  255. ifFormat : "'.$format.'", // format of the input field
  256. button : "'.$id.'_img", // trigger for the calendar (button ID)
  257. align : "Tl", // alignment (defaults to "Bl")
  258. singleClick : true
  259. });});');
  260. return '<input type="text" name="'.$name.'" id="'.$id.'" value="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" '.$attribs.' />'.
  261. '<img class="calendar" src="'.JURI::root(true).'/templates/system/images/calendar.png" alt="calendar" id="'.$id.'_img" />';
  262. }
  263. /**
  264. * Add a directory where JHTML should search for helpers. You may
  265. * either pass a string or an array of directories.
  266. *
  267. * @access public
  268. * @param string A path to search.
  269. * @return array An array with directory elements
  270. * @since 1.5
  271. */
  272. function addIncludePath( $path='' )
  273. {
  274. static $paths;
  275. if (!isset($paths)) {
  276. $paths = array( JPATH_LIBRARIES.DS.'joomla'.DS.'html'.DS.'html' );
  277. }
  278. // force path to array
  279. settype($path, 'array');
  280. // loop through the path directories
  281. foreach ($path as $dir)
  282. {
  283. if (!empty($dir) && !in_array($dir, $paths)) {
  284. array_unshift($paths, JPath::clean( $dir ));
  285. }
  286. }
  287. return $paths;
  288. }
  289. }