[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/html/ -> html.php (source)

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


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1