Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/template/template.php

Documentation is available at template.php

  1. <?php
  2. /**
  3. @version        $Id: template.php 6472 2007-02-03 10:47:26Z pasamio $
  4. @package        Joomla.Framework
  5. @subpackage    Template
  6. @copyright    Copyright (C) 2005 - 2007 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. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. jimport('pattemplate.patTemplate');
  19.  
  20. /**
  21.  * Template class, provides an easy interface to parse and display a template file
  22.  *
  23.  * @author         Johan Janssens <[email protected]>
  24.  * @package     Joomla.Framework
  25.  * @subpackage        Template
  26.  * @since        1.5
  27.  * @see            patTemplate
  28.  */
  29.  
  30. class JTemplate extends patTemplate
  31. {
  32.     /**
  33.      * The path of the template file
  34.      *
  35.      * @var        string 
  36.      * @access    private
  37.      */
  38.     var $_file '';
  39.  
  40.  
  41.     /**
  42.      * A hack to support __construct() on PHP 4
  43.      * Hint: descendant classes have no PHP4 class_name() constructors,
  44.      * so this constructor gets called first and calls the top-layer __construct()
  45.      * which (if present) should call parent::__construct()
  46.      *
  47.      * @return Object 
  48.      */
  49.     function JTemplate()
  50.     {
  51.         $args func_get_args();
  52.         call_user_func_array(array(&$this'__construct')$args);
  53.     }
  54.  
  55.     /**
  56.     * Class constructor
  57.     *
  58.     * The type influences the tags you are using in your templates.
  59.     *
  60.     * @access    protected
  61.     */
  62.     function __construct()
  63.     {
  64.         parent::patTemplate();
  65.  
  66.         //set the namespace
  67.         $this->setNamespace'jtmpl' );
  68.  
  69.         //add module directories
  70.         $this->addModuleDir('Function',        dirname(__FILE__)DS'module'DS .'function');
  71.         $this->addModuleDir('Modifier',     dirname(__FILE__)DS'module'DS .'modifier');
  72.  
  73.         //set root template directory
  74.         $this->setRootdirname(__FILE__)DS'tmpl' );
  75.     }
  76.  
  77.     /**
  78.      * Returns a reference to a global Template object, only creating it
  79.      * if it doesn't already exist.
  80.      *
  81.     * @param    string    $type (either html or tex)
  82.     * @return jtemplate A template object
  83.     * @since 1.5
  84.     */
  85.     function &getInstance$type 'html' )
  86.     {
  87.         static $instances;
  88.  
  89.         if (!isset$instances )) {
  90.             $instances array();
  91.         }
  92.  
  93.         $signature serialize(array($type));
  94.  
  95.         if (empty($instances[$signature])) {
  96.             $instances[$signaturenew JTemplate($type);
  97.         }
  98.  
  99.         return $instances[$signature];
  100.     }
  101.  
  102.     /**
  103.      * Parse a file
  104.      *
  105.      * @access public
  106.      * @param string     $file    The filename
  107.      */
  108.     function parse$file )
  109.     {
  110.         $this->_file $file//store the file for later usage
  111.         $this->readTemplatesFromInput$file );
  112.     }
  113.  
  114.     /**
  115.      * Execute and display a the template
  116.      *
  117.      * @access public
  118.      * @param string     $name        The name of the template
  119.      */
  120.     function display$name )
  121.     {
  122.         $this->displayParsedTemplate$name );
  123.     }
  124.  
  125.     /**
  126.      * Returns a parsed template
  127.      *
  128.      * @access public
  129.      * @param string     $name        The name of the template
  130.      */
  131.     function fetch$name )
  132.     {
  133.         $result $this->getParsedTemplate($nametrue);
  134.  
  135.         /**
  136.          * error happened
  137.          */
  138.         if (patErrorManager::isError($result)) {
  139.             return $result;
  140.         }
  141.  
  142.         return $result;
  143.     }
  144.  
  145.    /**
  146.     * enable a template cache
  147.     *
  148.     * A template cache will improve performace, as the templates
  149.     * do not have to be read on each request.
  150.     *
  151.     * @access    public
  152.     * @param    string        name of the template cache
  153.     * @param    string        folder to store the cached files
  154.     * @return    boolean        true on success, patError otherwise
  155.     */
  156.     function enableTemplateCache$handler$folder )
  157.     {
  158.         $info array(
  159.             'cacheFolder'     => $folder,
  160.             'lifetime'         => 'auto',
  161.             'prefix'        => 'global__',
  162.             'filemode'         => 0755
  163.         );
  164.         $result $this->useTemplateCache'File'$info );
  165.  
  166.         return $result;
  167.     }
  168.  
  169.     /**
  170.      * Set the prefix of the template cache
  171.      *
  172.      * @access    public
  173.      * @param    string        the prefix of the template cache
  174.      * @return    boolean        true on success, patError otherwise
  175.      */
  176.     function setTemplateCachePrefix$prefix )
  177.     {
  178.         if (!$this->_tmplCache{
  179.             return false;
  180.         }
  181.  
  182.         $this->_tmplCache->_params['prefix'$prefix;
  183.         return true;
  184.     }
  185.  
  186.     /**
  187.     * load from template cache
  188.     *
  189.     * @access    private
  190.     * @param    string    name of the input (filename, shm segment, etc.)
  191.     * @param    string    driver that is used as reader, you may also pass a Reader object
  192.     * @param    array    options for the reader
  193.     * @param    string    cache key
  194.     * @return    array|boolean   either an array containing the templates, or false
  195.     */
  196.     function _loadTemplatesFromCache$input&$reader$options$key )
  197.     {
  198.         $stat    =    &$this->loadModule'Stat''File' );
  199.         $stat->setOptions$options );
  200.  
  201.         /**
  202.          * get modification time
  203.          */
  204.         $modTime    $stat->getModificationTime$this->_file );
  205.         $templates    $this->_tmplCache->load$key$modTime );
  206.  
  207.         return $templates;
  208.     }
  209. }
  210. ?>

Documentation generated on Mon, 05 Mar 2007 21:29:02 +0000 by phpDocumentor 1.3.1