Actions

API16

JHtmlImage/site

From Joomla! Documentation

< API16:JHtmlImage
Revision as of 17:51, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Checks to see if an image exists in the current templates image directory. If it does it loads this image. Otherwise the default image is loaded. Also can be used in conjunction with the menulist param to create the chosen image load the default or use no image.

[Edit Descripton]

Description:JHtmlImage/site

Syntax

static site($file, $folder= '/images/system/', $altFile=null, $altFolder= '/images/system/', $alt=null, $attribs=null, $asTag=true)
Parameter Name Default Value Description
$file $file The file name, eg foobar.png.
$folder '/images/system/' $folder The path to the image.
$altFile null $altFile Empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder.
$altFolder '/images/system/' $altFolder Another path. Only used for the contact us form based on the value of the imagelist param.
$alt null $alt Alternative text.
$attribs null $attribs An associative array of attributes to add.
$asTag true $asTag True (default) to display full tag, false to return just the path.

Defined in

libraries/joomla/html/html/image.php

Importing

jimport( 'joomla.html.html.image' );

Source Body

public static function site($file, $folder = '/images/system/', $altFile = null, $altFolder = '/images/system/', $alt = null, $attribs = null, $asTag = true)
{
        static $paths;
        $app = &JFactory::getApplication();
 
        if (!$paths) {
                $paths = array();
        }
 
        if (is_array($attribs)) {
                $attribs = JArrayHelper::toString($attribs);
        }
 
        $cur_template = $app->getTemplate();
 
        // Strip HTML.
        $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8');
 
        if ($altFile) {
                $src = $altFolder . $altFile;
        }
        else if ($altFile == -1) {
                return '';
        }
        else
        {
                $path = JPATH_SITE .'/templates/'. $cur_template .'/images/'. $file;
                if (!isset($paths[$path]))
                {
                        if (file_exists(JPATH_SITE .'/templates/'. $cur_template .'/images/'. $file)) {
                                $paths[$path] = 'templates/'. $cur_template .'/images/'. $file;
                        }
                        else
                        {
                                // Outputs only path to image.
                                $paths[$path] = $folder . $file;
                        }
                }
                $src = $paths[$path];
        }
 
        if (substr($src, 0, 1) == "/") {
                $src = substr_replace($src, '', 0, 1);
        }
 
        // Prepend the base path.
        $src = JURI::base(true).'/'.$src;
 
        // Outputs actual html <img> tag.
        if ($asTag) {
                return '<img src="'. $src .'" alt="'. html_entity_decode($alt, ENT_COMPAT, 'UTF-8') .'" '.$attribs.' />';
        }
 
        return $src;
}

[Edit See Also] SeeAlso:JHtmlImage/site

Examples

<CodeExamplesForm />