Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatefileresource.php
Go to the documentation of this file.
1 <?php
19 class eZTemplateFileResource
20 {
28 public function __construct( $name = "file", $servesStaticData = true )
29 {
30 $this->Name = $name;
31 $this->ServesStaticData = $servesStaticData;
32 $this->TemplateCache = array();
33 }
34
38 function resourceName()
39 {
40 return $this->Name;
41 }
42
43 /*
44 \return true if this resource handler servers static data,
45 this means that the data can be cached by the template system.
46 */
47 function servesStaticData()
48 {
49 return $this->ServesStaticData;
50 }
51
52 function templateNodeTransformation( $functionName, &$node,
53 $tpl, &$resourceData, $parameters, $namespaceValue )
54 {
55 if ( $this->Name != 'file' )
56 return false;
57 $file = $resourceData['template-name'];
58 if ( !file_exists( $file ) )
59 return false;
60 $newNodes = array();
61 $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( $resourceData['resource'],
62 $file, $file,
63 eZTemplate::RESOURCE_FETCH, false,
64 $node[4],
65 array(),
66 $namespaceValue );
67 return $newNodes;
68 }
69
79 function cacheKey( $keyData, $res, $templatePath, &$extraParameters )
80 {
81 $key = md5( $keyData );
82 return $key;
83 }
84
88 function hasCachedProcessTree( $keyData, $uri, $res, $templatePath, &$extraParameters, $timestamp )
89 {
90 return false;
91 $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
92 if ( eZTemplateTreeCache::canRestoreCache( $key, $timestamp, $templatePath ) )
93 eZTemplateTreeCache::restoreCache( $key, $templatePath );
94 return eZTemplateTreeCache::cachedTree( $key, $uri, $res, $templatePath, $extraParameters );
95 }
96
100 function compileTemplate( $tpl, $keyData, $uri, $res, $templatePath, &$extraParameters, &$resourceData )
101 {
102 $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
103 return eZTemplateCompiler::compileTemplate( $tpl, $key, $resourceData );
104 }
105
109 function executeCompiledTemplate( $tpl, &$textElements,
110 $keyData, $uri, $resourceData, $templatePath,
111 &$extraParameters, $timestamp,
112 $rootNamespace, $currentNamespace )
113 {
114 $key = $this->cacheKey( $keyData, $resourceData, $templatePath, $extraParameters );
115 return eZTemplateCompiler::executeCompilation( $tpl, $textElements, $key, $resourceData,
116 $rootNamespace, $currentNamespace );
117 }
118
122 function hasCompiledTemplate( $keyData, $uri, &$resourceData, $templatePath, &$extraParameters, $timestamp )
123 {
124 $key = $this->cacheKey( $keyData, $resourceData, $templatePath, $extraParameters );
125 return eZTemplateCompiler::hasCompiledTemplate( $key, $timestamp, $resourceData );
126 }
127
131 function canCompileTemplate( $tpl, &$resourceData, &$extraParameters )
132 {
133 return eZTemplateCompiler::isCompilationEnabled();
134 }
135
139 function cachedTemplateTree( $keyData, $uri, $res, $templatePath, &$extraParameters, $timestamp )
140 {
141 $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
142 if ( eZTemplateTreeCache::canRestoreCache( $key, $timestamp, $templatePath ) )
143 eZTemplateTreeCache::restoreCache( $key, $templatePath );
144 return eZTemplateTreeCache::cachedTree( $key, $uri, $res, $templatePath, $extraParameters );
145 }
146
150 function setCachedTemplateTree( $keyData, $uri, $res, $templatePath, &$extraParameters, &$root )
151 {
152 $key = $this->cacheKey( $keyData, $res, $templatePath, $extraParameters );
153 eZTemplateTreeCache::setCachedTree( $key, $uri, $res, $templatePath, $extraParameters, $root );
154 eZTemplateTreeCache::storeCache( $key, $templatePath );
155 }
156
161 function handleResource( $tpl, &$resourceData, $method, &$extraParameters )
162 {
163 return $this->handleResourceData( $tpl, $this, $resourceData, $method, $extraParameters );
164 }
165
173 function handleResourceData( $tpl, $handler, &$resourceData, $method, &$extraParameters )
174 {
175 // &$templateRoot, &$text, &$tstamp, $uri, $resourceName, &$path, &$keyData
176 $templateRoot =& $resourceData['root-node'];
177 $text =& $resourceData['text'];
178 $tstamp =& $resourceData['time-stamp'];
179 $uri =& $resourceData['uri'];
180 $resourceName =& $resourceData['resource'];
181 $path =& $resourceData['template-filename'];
182 $keyData =& $resourceData['key-data'];
183 $localeData =& $resourceData['locales'];
184
185 if ( !file_exists( $path ) )
186 return false;
187 $tstamp = filemtime( $path );
188 $result = false;
189 $canCache = true;
190 $templateRoot = null;
191 if ( !$handler->servesStaticData() )
192 $canCache = false;
193 if ( !$tpl->isCachingAllowed() )
194 $canCache = false;
195 $keyData = 'file:' . $path;
196 if ( $method == eZTemplate::RESOURCE_FETCH )
197 {
198 if ( $canCache )
199 {
200 if ( $handler->hasCompiledTemplate( $keyData, $uri, $resourceData, $path, $extraParameters, $tstamp ) )
201 {
202 $resourceData['compiled-template'] = true;
203 return true;
204 }
205 }
206 if ( $canCache )
207 $templateRoot = $handler->cachedTemplateTree( $keyData, $uri, $resourceName, $path, $extraParameters, $tstamp );
208
209 if ( $templateRoot !== null )
210 return true;
211
212 if ( is_readable( $path ) )
213 {
214 $text = file_get_contents( $path );
215 $text = preg_replace( "/\n|\r\n|\r/", "\n", $text );
216 $tplINI = $tpl->ini();
217 $charset = $tplINI->variable( 'CharsetSettings', 'DefaultTemplateCharset' );
218 $locales = array();
219 $pos = strpos( $text, "\n" );
220 if ( $pos !== false )
221 {
222 $line = substr( $text, 0, $pos );
223 if ( preg_match( "/^\{\*\?template(.+)\?\*\}/", $line, $tpl_arr ) )
224 {
225 $args = explode( " ", trim( $tpl_arr[1] ) );
226 foreach ( $args as $arg )
227 {
228 $vars = explode( '=', trim( $arg ) );
229 switch ( $vars[0] ) {
230 case 'charset': {
231 $val = $vars[1];
232 if ( $val[0] == '"' and
233 strlen( $val ) > 0 and
234 $val[strlen($val)-1] == '"' )
235 {
236 $val = substr( $val, 1, strlen($val) - 2 );
237 }
238 $charset = $val;
239 } break;
240 case 'locale': {
241 $val = $vars[1];
242 if ( $val[0] == '"' and
243 strlen( $val ) > 0 and
244 $val[strlen($val)-1] == '"' )
245 {
246 $val = substr( $val, 1, strlen($val) - 2 );
247 }
248 $locales = explode( ',', $val );
249 } break;
250 }
251 }
252 }
253 }
254
255 /* Setting locale to allow standard PHP functions to handle
256 * strtoupper/lower() */
257 $defaultLocale = trim( $tplINI->variable( 'CharsetSettings', 'DefaultTemplateLocale' ) );
258 if ( $defaultLocale != '' )
259 {
260 $locales = array_merge( $locales, explode( ',', $defaultLocale ) );
261 }
262 $localeData = $locales;
263 if ( $locales && count( $locales ) )
264 {
265 setlocale( LC_CTYPE, $locales );
266 }
267
268 if ( eZTemplate::isDebugEnabled() )
269 eZDebug::writeNotice( "$path, $charset" );
270 $codec = eZTextCodec::instance( $charset, false, false );
271 if ( $codec )
272 {
273 eZDebug::accumulatorStart( 'template_resource_conversion', 'template_total', 'String conversion in template resource' );
274 $text = $codec->convertString( $text );
275 eZDebug::accumulatorStop( 'template_resource_conversion' );
276 }
277 $result = true;
278 }
279 }
280 else if ( $method == eZTemplate::RESOURCE_QUERY )
281 $result = true;
282 return $result;
283 }
284
287 public $Name;
289 public $ServesStaticData;
291 public $TemplateCache;
292 }
293
294 ?>
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1361
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1389
eZTemplateCompiler\compileTemplate
static compileTemplate( $tpl, $key, &$resourceData)
Definition: eztemplatecompiler.php:465
eZTemplateCompiler\executeCompilation
static executeCompilation( $tpl, &$textElements, $key, &$resourceData, $rootNamespace, $currentNamespace)
Definition: eztemplatecompiler.php:387
eZTemplateCompiler\isCompilationEnabled
static isCompilationEnabled()
Definition: eztemplatecompiler.php:97
eZTemplateCompiler\hasCompiledTemplate
static hasCompiledTemplate( $key, $timestamp, &$resourceData)
Definition: eztemplatecompiler.php:352
eZTemplateFileResource
Handles filesystem retrieval of templates.
Definition: eztemplatefileresource.php:20
eZTemplateFileResource\hasCompiledTemplate
hasCompiledTemplate( $keyData, $uri, &$resourceData, $templatePath, &$extraParameters, $timestamp)
Definition: eztemplatefileresource.php:122
eZTemplateFileResource\servesStaticData
servesStaticData()
Definition: eztemplatefileresource.php:47
eZTemplateFileResource\canCompileTemplate
canCompileTemplate( $tpl, &$resourceData, &$extraParameters)
Definition: eztemplatefileresource.php:131
eZTemplateFileResource\setCachedTemplateTree
setCachedTemplateTree( $keyData, $uri, $res, $templatePath, &$extraParameters, &$root)
Definition: eztemplatefileresource.php:150
eZTemplateFileResource\__construct
__construct( $name="file", $servesStaticData=true)
Definition: eztemplatefileresource.php:28
eZTemplateFileResource\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, &$resourceData, $parameters, $namespaceValue)
Definition: eztemplatefileresource.php:52
eZTemplateFileResource\resourceName
resourceName()
Definition: eztemplatefileresource.php:38
eZTemplateFileResource\cachedTemplateTree
cachedTemplateTree( $keyData, $uri, $res, $templatePath, &$extraParameters, $timestamp)
Definition: eztemplatefileresource.php:139
eZTemplateFileResource\$Name
$Name
Definition: eztemplatefileresource.php:287
eZTemplateFileResource\$ServesStaticData
$ServesStaticData
True if the data served from this resource is static, ie it can be cached properly.
Definition: eztemplatefileresource.php:289
eZTemplateFileResource\$TemplateCache
$TemplateCache
The cache for templates.
Definition: eztemplatefileresource.php:291
eZTemplateFileResource\handleResource
handleResource( $tpl, &$resourceData, $method, &$extraParameters)
Definition: eztemplatefileresource.php:161
eZTemplateFileResource\compileTemplate
compileTemplate( $tpl, $keyData, $uri, $res, $templatePath, &$extraParameters, &$resourceData)
Definition: eztemplatefileresource.php:100
eZTemplateFileResource\executeCompiledTemplate
executeCompiledTemplate( $tpl, &$textElements, $keyData, $uri, $resourceData, $templatePath, &$extraParameters, $timestamp, $rootNamespace, $currentNamespace)
Definition: eztemplatefileresource.php:109
eZTemplateFileResource\cacheKey
cacheKey( $keyData, $res, $templatePath, &$extraParameters)
Definition: eztemplatefileresource.php:79
eZTemplateFileResource\hasCachedProcessTree
hasCachedProcessTree( $keyData, $uri, $res, $templatePath, &$extraParameters, $timestamp)
Definition: eztemplatefileresource.php:88
eZTemplateFileResource\handleResourceData
handleResourceData( $tpl, $handler, &$resourceData, $method, &$extraParameters)
Definition: eztemplatefileresource.php:173
eZTemplateNodeTool\createResourceAcquisitionNode
static createResourceAcquisitionNode( $resourceName, $templateName, $fileName, $method, $extraParameters, $placement=false, $parameters=array(), $newRootNamespace=false, $resourceVariableName=false)
Definition: eztemplatenodetool.php:527
eZTemplateTreeCache\restoreCache
static restoreCache( $key, $templateFilepath)
Definition: eztemplatetreecache.php:181
eZTemplateTreeCache\setCachedTree
static setCachedTree( $originalKey, $uri, $res, $templatePath, &$extraParameters, &$root)
Definition: eztemplatetreecache.php:74
eZTemplateTreeCache\storeCache
static storeCache( $key, $templateFilepath)
Definition: eztemplatetreecache.php:212
eZTemplateTreeCache\cachedTree
static cachedTree( $key, $uri, $res, $templatePath, &$extraParameters)
Definition: eztemplatetreecache.php:54
eZTemplateTreeCache\canRestoreCache
static canRestoreCache( $key, $timestamp, $templateFilepath)
Definition: eztemplatetreecache.php:159
eZTemplate\isDebugEnabled
static isDebugEnabled()
Definition: eztemplate.php:2467
eZTemplate\RESOURCE_QUERY
const RESOURCE_QUERY
Definition: eztemplate.php:201
eZTemplate\RESOURCE_FETCH
const RESOURCE_FETCH
Definition: eztemplate.php:200
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: eztextcodec.php:446
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.