Actions

API15

JHTML/

From Joomla! Documentation

< API15:JHTML
Revision as of 11:34, 25 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

Class loader method

[Edit Descripton]

Description:JHTML/

Syntax

_($type)
Parameter Name Default Value Description
$type The name of helper method to load, (prefix).(class).function prefix and class are optional and can be used to load custom html helpers.

Defined in

libraries/joomla/html/html.php

Importing

jimport( 'joomla.html.html' );

Source Body

function _( $type )
{
        //Initialise variables
        $prefix = 'JHTML';
        $file   = '';
        $func   = $type;
 
        // Check to see if we need to load a helper file
        $parts = explode('.', $type);
 
        switch(count($parts))
        {
                case 3 :
                {
                        $prefix         = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
                        $file           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
                        $func           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[2] );
                } break;
 
                case 2 :
                {
                        $file           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
                        $func           = preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
                } break;
        }
 
        $className      = $prefix.ucfirst($file);
 
        if (!class_exists( $className ))
        {
                jimport('joomla.filesystem.path');
                if ($path = JPath::find(JHTML::addIncludePath(), strtolower($file).'.php'))
                {
                        require_once $path;
 
                        if (!class_exists( $className ))
                        {
                                JError::raiseWarning( 0, $className.'::' .$func. ' not found in file.' );
                                return false;
                        }
                }
                else
                {
                        JError::raiseWarning( 0, $prefix.$file . ' not supported. File not found.' );
                        return false;
                }
        }
 
        if (is_callable( array( $className, $func ) ))
        {
                $temp = func_get_args();
                array_shift( $temp );
                $args = array();
                foreach ($temp as $k => $v) {
                    $args[] = &$temp[$k];
                }
                return call_user_func_array( array( $className, $func ), $args );
        }
        else
        {
                JError::raiseWarning( 0, $className.'::'.$func.' not supported.' );
                return false;
        }
}

[Edit See Also] SeeAlso:JHTML/

Examples

<CodeExamplesForm />