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