Actions

API15

JHTMLImage/site

From Joomla! Documentation

< API15:JHTMLImage
Revision as of 16:21, 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

site($file, $folder='/images/M_images/', $altFile=NULL, $altFolder='/images/M_images/', $alt=NULL, $attribs=null, $asTag=1)
Parameter Name Default Value Description
$file The file name, eg foobar.png
$folder '/images/M_images/' The path to the image
$altFile NULL empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder
$altFolder '/images/M_images/' Another path. Only used for the contact us form based on the value of the imagelist parm
$alt NULL Alt text
$attribs null An associative array of attributes to add
$asTag 1 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

function site( $file, $folder='/images/M_images/', $altFile=NULL, $altFolder='/images/M_images/', $alt=NULL, $attribs = null, $asTag = 1)
{
        static $paths;
        global $mainframe;
 
        if (!$paths) {
                $paths = array();
        }
 
        if (is_array( $attribs )) {
                $attribs = JArrayHelper::toString( $attribs );
        }
 
        $cur_template = $mainframe->getTemplate();
 
        if ( $altFile )
        {
                // $param allows for an alternative file to be used
                $src = $altFolder . $altFile;
        }
        else if ( $altFile == -1 )
        {
                // Comes from an image list param field with 'Do not use' selected
                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 ) .'" '.$attribs.' />';
        }
 
        return $src;
}

[Edit See Also] SeeAlso:JHTMLImage/site

Examples

<CodeExamplesForm />