PageRenderTime 139ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/html/html.php

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