[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3  * @version        $Id: image.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  // no direct access
  16  defined( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  /**
  19   * Utility class working with images
  20   *
  21   * @static
  22   * @package     Joomla.Framework
  23   * @subpackage    HTML
  24   * @since        1.5
  25   */
  26  class JHTMLImage
  27  {
  28      /**
  29      * Checks to see if an image exists in the current templates image directory
  30       * if it does it loads this image.  Otherwise the default image is loaded.
  31      * Also can be used in conjunction with the menulist param to create the chosen image
  32      * load the default or use no image
  33      *
  34      * @param    string    The file name, eg foobar.png
  35      * @param    string    The path to the image
  36      * @param    int        empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder
  37      * @param    string    Another path.  Only used for the contact us form based on the value of the imagelist parm
  38      * @param    string    Alt text
  39      * @param    array    An associative array of attributes to add
  40      * @param    boolean    True (default) to display full tag, false to return just the path
  41      */
  42  	function site( $file, $folder='/images/M_images/', $altFile=NULL, $altFolder='/images/M_images/', $alt=NULL, $attribs = null, $asTag = 1)
  43      {
  44          static $paths;
  45          global $mainframe;
  46  
  47          if (!$paths) {
  48              $paths = array();
  49          }
  50  
  51          if (is_array( $attribs )) {
  52              $attribs = JArrayHelper::toString( $attribs );
  53          }
  54  
  55          $cur_template = $mainframe->getTemplate();
  56  
  57          if ( $altFile )
  58          {
  59              // $param allows for an alternative file to be used
  60              $src = $altFolder . $altFile;
  61          }
  62          else if ( $altFile == -1 )
  63          {
  64              // Comes from an image list param field with 'Do not use' selected
  65              return '';
  66          } else {
  67              $path = JPATH_SITE .'/templates/'. $cur_template .'/images/'. $file;
  68              if (!isset( $paths[$path] ))
  69              {
  70                  if ( file_exists( JPATH_SITE .'/templates/'. $cur_template .'/images/'. $file ) ) {
  71                      $paths[$path] = 'templates/'. $cur_template .'/images/'. $file;
  72                  } else {
  73                      // outputs only path to image
  74                      $paths[$path] = $folder . $file;
  75                  }
  76              }
  77              $src = $paths[$path];
  78          }
  79  
  80          if (substr($src, 0, 1 ) == "/") {
  81              $src = substr_replace($src, '', 0, 1);
  82          }
  83  
  84          // Prepend the base path
  85          $src = JURI::base(true).'/'.$src;
  86  
  87          // outputs actual html <img> tag
  88          if ($asTag) {
  89              return '<img src="'. $src .'" alt="'. html_entity_decode( $alt ) .'" '.$attribs.' />';
  90          }
  91  
  92          return $src;
  93      }
  94  
  95      /**
  96      * Checks to see if an image exists in the current templates image directory
  97      * if it does it loads this image.  Otherwise the default image is loaded.
  98      * Also can be used in conjunction with the menulist param to create the chosen image
  99      * load the default or use no image
 100      *
 101      * @param    string    The file name, eg foobar.png
 102      * @param    string    The path to the image
 103      * @param    int        empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder
 104      * @param    string    Another path.  Only used for the contact us form based on the value of the imagelist parm
 105      * @param    string    Alt text
 106      * @param    array    An associative array of attributes to add
 107      * @param    boolean    True (default) to display full tag, false to return just the path
 108      */
 109  	function administrator( $file, $directory='/images/', $param=NULL, $param_directory='/images/', $alt = NULL, $attribs = null, $type = 1 )
 110      {
 111          global $mainframe;
 112  
 113          if (is_array( $attribs )) {
 114              $attribs = JArrayHelper::toString( $attribs );
 115          }
 116  
 117          $cur_template = $mainframe->getTemplate();
 118  
 119          // strip html
 120          $alt    = html_entity_decode( $alt );
 121  
 122          if ( $param ) {
 123              $image = $param_directory . $param;
 124          } else if ( $param == -1 ) {
 125              $image = '';
 126          } else {
 127              if ( file_exists( JPATH_ADMINISTRATOR .'/templates/'. $cur_template .'/images/'. $file ) ) {
 128                  $image = 'templates/'. $cur_template .'/images/'. $file;
 129              } else {
 130                  // compability with previous versions
 131                  if ( substr($directory, 0, 14 )== "/administrator" ) {
 132                      $image = substr($directory,15) . $file;
 133                  } else {
 134                      $image = $directory . $file;
 135                  }
 136              }
 137          }
 138  
 139          if (substr($image, 0, 1 ) == "/") {
 140              $image = substr_replace($image, '', 0, 1);
 141          }
 142  
 143          // Prepend the base path
 144          $image = JURI::base(true).'/'.$image;
 145  
 146          // outputs actual html <img> tag
 147          if ( $type ) {
 148              $image = '<img src="'. $image .'" alt="'. $alt .'" '.$attribs.' />';
 149          }
 150  
 151          return $image;
 152      }
 153  }


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