本文整理汇总了PHP中Smarty_Internal_Debug::start_cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Debug::start_cache方法的具体用法?PHP Smarty_Internal_Debug::start_cache怎么用?PHP Smarty_Internal_Debug::start_cache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty_Internal_Debug
的用法示例。
在下文中一共展示了Smarty_Internal_Debug::start_cache方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
//.........这里部分代码省略.........
}
$this->cached->isCached($this);
}
if (!$isCacheTpl || !$this->cached->valid) {
if ($isCacheTpl) {
$this->properties['tpl_function'] = [];
}
// render template (not loaded and not in cache)
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this);
}
if (!$this->source->uncompiled) {
// render compiled code
if (!isset($this->compiled)) {
$this->loadCompiled();
}
$content = $this->compiled->render($this);
} else {
$content = $this->source->renderUncompiled($this);
}
if (!$this->source->recompiled && empty($this->properties['file_dependency'][$this->source->uid])) {
$this->properties['file_dependency'][$this->source->uid] = [$this->source->filepath, $this->source->timestamp, $this->source->type];
}
if ($parentIsTpl) {
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
//$this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']);
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($this);
}
// write to cache when necessary
if (!$this->source->recompiled && $isCacheTpl) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$this->cached->updateCache($this, $content, $no_output_filter);
$compile_check = $this->smarty->compile_check;
$this->smarty->compile_check = false;
if ($parentIsTpl) {
$this->properties['tpl_function'] = $this->parent->properties['tpl_function'];
}
if (!$this->cached->processed) {
$this->cached->process($this);
}
$this->smarty->compile_check = $compile_check;
$content = $this->getRenderedTemplateCode();
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
} else {
if (!empty($this->properties['nocache_hash']) && !empty($this->parent->properties['nocache_hash'])) {
// replace nocache_hash
$content = str_replace("{$this->properties['nocache_hash']}", $this->parent->properties['nocache_hash'], $content);
$this->parent->has_nocache_code = $this->parent->has_nocache_code || $this->has_nocache_code;
}
}
} else {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$content = $this->cached->render($this);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
}
if ((!$this->caching || $this->has_nocache_code || $this->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
示例2: getRenderedTemplate
/**
* Returns the rendered HTML output
*
* If the cache is valid the cached content is used, otherwise
* the output is rendered from the compiled template or PHP template source
*
* @return string rendered HTML output
*/
public function getRenderedTemplate()
{
// disable caching for evaluated code
if ($this->resource_object->isEvaluated) {
$this->caching = false;
}
// checks if template exists
$this->isExisting(true);
// read from cache or render
if ($this->rendered_content === null) {
if ($this->isCached) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$this->rendered_content = $this->cache_resource_object->getCachedContents($this, false);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
}
if ($this->isCached === null) {
$this->isCached(false);
}
if (!$this->isCached) {
// render template (not loaded and not in cache)
$this->renderTemplate();
}
}
$this->updateParentVariables();
$this->isCached = null;
return $this->rendered_content;
}
示例3: fetch
//.........这里部分代码省略.........
Smarty_Internal_Debug::start_render($_template);
}
try {
ob_start();
$_template->source->renderUncompiled($_template);
} catch (Exception $e) {
ob_get_clean();
throw $e;
}
} else {
throw new SmartyException("Resource '{$_template->source}->type' must have 'renderUncompiled' method");
}
}
$_output = ob_get_clean();
if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
$_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
}
if ($_template->parent instanceof Smarty_Internal_Template) {
$_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
foreach ($_template->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
$_template->parent->required_plugins[$code][$name][$type] = $data;
}
}
}
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($_template);
}
// write to cache when nessecary
if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
$_template->properties['has_nocache_code'] = false;
// get text between non-cached items
$cache_split = preg_split("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output);
// get non-cached items
preg_match_all("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output, $cache_parts);
$output = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
// escape PHP tags in template content
$output .= preg_replace('/(<%|%>|<\\?php|<\\?|\\?>)/', '<?php echo \'$1\'; ?>', $curr_split);
if (isset($cache_parts[0][$curr_idx])) {
$_template->properties['has_nocache_code'] = true;
// remove nocache tags from cache output
$output .= preg_replace("!/\\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!", '', $cache_parts[0][$curr_idx]);
}
}
if (!$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
}
// rendering (must be done before writing cache file because of {function} nocache handling)
$_smarty_tpl = $_template;
try {
ob_start();
eval("?>" . $output);
$_output = ob_get_clean();
} catch (Exception $e) {
ob_get_clean();
throw $e;
}
// write cache file content
$_template->writeCachedContent($output);
示例4: __construct
/**
* create Cached Object container
*
* @param Smarty_Internal_Template $_template template object
*/
public function __construct(Smarty_Internal_Template $_template)
{
$this->compile_id = $_template->compile_id;
$this->cache_id = $_template->cache_id;
$this->source = $_template->source;
$_template->cached = $this;
$smarty = $_template->smarty;
//
// load resource handler
//
$this->handler = $handler = Smarty_CacheResource::load($smarty);
// Note: prone to circular references
//
// check if cache is valid
//
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) {
$handler->populate($this, $_template);
return;
}
while (true) {
while (true) {
$handler->populate($this, $_template);
if ($this->timestamp === false || $smarty->force_compile || $smarty->force_cache) {
$this->valid = false;
} else {
$this->valid = true;
}
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > $this->timestamp + $_template->cache_lifetime) {
// lifetime expired
$this->valid = false;
}
if ($this->valid || !$_template->smarty->cache_locking) {
break;
}
if (!$this->handler->locked($_template->smarty, $this)) {
$this->handler->acquireLock($_template->smarty, $this);
break 2;
}
}
if ($this->valid) {
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
// load cache file for the following checks
if ($smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
if ($handler->process($_template, $this) === false) {
$this->valid = false;
} else {
$this->processed = true;
}
if ($smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template);
}
} else {
continue;
}
} else {
return;
}
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && time() > $_template->cached->timestamp + $_template->properties['cache_lifetime']) {
$this->valid = false;
}
if (!$this->valid && $_template->smarty->cache_locking) {
$this->handler->acquireLock($_template->smarty, $this);
return;
} else {
return;
}
}
}
示例5: isCached
/**
* Check if cache is valid, lock cache if required
*
* @param \Smarty_Internal_Template $_template
*
* @return bool flag true if cache is valid
*/
public function isCached(Smarty_Internal_Template $_template)
{
if ($this->valid !== null) {
return $this->valid;
}
while (true) {
while (true) {
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
$this->valid = false;
} else {
$this->valid = true;
}
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > $this->timestamp + $_template->cache_lifetime) {
// lifetime expired
$this->valid = false;
}
if ($this->valid && $_template->source->timestamp > $this->timestamp) {
$this->valid = false;
}
if ($this->valid || !$_template->smarty->cache_locking) {
break;
}
if (!$this->handler->locked($_template->smarty, $this)) {
$this->handler->acquireLock($_template->smarty, $this);
break 2;
}
$this->handler->populate($this, $_template);
}
if ($this->valid) {
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
// load cache file for the following checks
if ($_template->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
if ($this->handler->process($_template, $this) === false) {
$this->valid = false;
} else {
$this->processed = true;
}
if ($_template->smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template);
}
} else {
$this->is_locked = true;
continue;
}
} else {
return $this->valid;
}
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && time() > $_template->cached->timestamp + $_template->properties['cache_lifetime']) {
$this->valid = false;
}
if ($_template->smarty->cache_locking) {
if (!$this->valid) {
$this->handler->acquireLock($_template->smarty, $this);
} elseif ($this->is_locked) {
$this->handler->releaseLock($_template->smarty, $this);
}
}
return $this->valid;
}
return $this->valid;
}
示例6: fetch
//.........这里部分代码省略.........
// 'page_today_num' => 1,
// 'lasttime' => 1
// );
// } else {//是当日,累加访问数
// $data2 = array(
// 'id' => $stats_id,
// 'page_count_num' => $stats_info->page_count_num + 1,
// 'page_today_num' => $stats_info->page_today_num + 1
// );
// }
// }
// $resa = $postFun->postsend("http://swap.5067.org/stats.php?key=update_stats", $data2); //更新客户访问统计信息
// }
// }
if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
$_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
}
if ($_template->parent instanceof Smarty_Internal_Template) {
$_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
foreach ($_template->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
$_template->parent->required_plugins[$code][$name][$type] = $data;
}
}
}
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($_template);
}
// write to cache when nessecary
if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
$_template->properties['has_nocache_code'] = false;
// get text between non-cached items
$cache_split = preg_split("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output);
// get non-cached items
preg_match_all("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output, $cache_parts);
$output = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
// escape PHP tags in template content
$output .= preg_replace('/(<%|%>|<\\?php|<\\?|\\?>)/', "<?php echo '\$1'; ?>\n", $curr_split);
if (isset($cache_parts[0][$curr_idx])) {
$_template->properties['has_nocache_code'] = true;
// remove nocache tags from cache output
$output .= preg_replace("!/\\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!", '', $cache_parts[0][$curr_idx]);
}
}
if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
}
// rendering (must be done before writing cache file because of {function} nocache handling)
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $_template;
try {
ob_start();
/// dark edit
\Dark\SmartyView\SmartyEngine::integrateViewComposers($_template);
/// end edit
eval("?>" . $output);
$_output = ob_get_clean();
示例7: fetch
//.........这里部分代码省略.........
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($_template);
}
try {
ob_start();
$_template->source->renderUncompiled($_template);
} catch (Exception $e) {
ob_get_clean();
throw $e;
}
} else {
throw new SmartyException("Resource '{$_template->source}->type' must have 'renderUncompiled' method");
}
}
$_output = ob_get_clean();
if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
$_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
}
if ($_template->parent instanceof Smarty_Internal_Template) {
$_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
foreach ($_template->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
$_template->parent->required_plugins[$code][$name][$type] = $data;
}
}
}
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($_template);
}
if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
$_template->properties['has_nocache_code'] = false;
$cache_split = preg_split("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output);
preg_match_all("!/\\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!s", $_output, $cache_parts);
$output = '';
foreach ($cache_split as $curr_idx => $curr_split) {
$output .= preg_replace('/(<%|%>|<\\?php|<\\?|\\?>)/', '<?php echo \'$1\'; ?>', $curr_split);
if (isset($cache_parts[0][$curr_idx])) {
$_template->properties['has_nocache_code'] = true;
$output .= preg_replace("!/\\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\\*/!", '', $cache_parts[0][$curr_idx]);
}
}
if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
}
$_smarty_tpl = $_template;
try {
ob_start();
eval("?>" . $output);
$_output = ob_get_clean();
} catch (Exception $e) {
ob_get_clean();
throw $e;
}
$_template->writeCachedContent($output);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template);
}
} else {
if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
$_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
$_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
开发者ID:EfncoPlugins,项目名称:web-portal-lite-client-portal-secure-file-sharing-private-messaging,代码行数:67,代码来源:smarty_internal_templatebase.php
示例8: render
//.........这里部分代码省略.........
// disable caching for evaluated code
if ($this->source->recompiled) {
$this->caching = false;
}
$_caching = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
// read from cache or render
if ($_caching && !isset($this->cached)) {
$this->cached = Smarty_Template_Cached::load($this);
}
if (!$_caching || !$this->cached->valid) {
// render template (not loaded and not in cache)
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this, null);
}
if (isset($this->cached)) {
$_savedContext = $this->context;
$this->context = new Smarty_Internal_Context(true);
}
if (!$this->source->uncompiled) {
// render compiled code
if (!isset($this->compiled)) {
$this->compiled = Smarty_Template_Compiled::load($this);
}
$this->compiled->render($this);
} else {
$this->source->renderUncompiled($this);
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($this, null);
}
// write to cache when necessary
if ($_caching && !$this->source->recompiled) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
// write cache file content
if ($runOutputFilter && !$this->context->hasNocacheCode && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$this->cached->writeCachedContent($this, $this->context, Smarty_Internal_Filter_Handler::runFilter('output', $this->context->getContent(), $this));
} else {
$this->cached->writeCachedContent($this, $this->context);
}
$this->context = $_savedContext;
$compile_check = $this->smarty->compile_check;
$this->smarty->compile_check = false;
if (!$this->cached->processed) {
$this->cached->process($this);
}
$this->smarty->compile_check = $compile_check;
$this->cached->compiledTplObj->getRenderedTemplateCode($this);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
}
} else {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$this->cached->render($this);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
}
if ($runOutputFilter && (!$this->caching || $this->context->hasNocacheCode || $this->source->recompiled) && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$this->context->flushBuffer();
$this->context->content = Smarty_Internal_Filter_Handler::runFilter('output', $this->context->content, $this);
}
示例9: renderTemplate
/**
* Render the output using the compiled template or the PHP template source
*
* The rendering process is accomplished by just including the PHP files.
* The only exceptions are evaluated templates (string template). Their code has
* to be evaluated
*/
public function renderTemplate()
{
if ($this->resource_object->usesCompiler) {
if ($this->mustCompile() && $this->compiled_template === null) {
$this->compileTemplateSource();
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this);
}
$_smarty_tpl = $this;
ob_start();
if ($this->resource_object->isEvaluated) {
eval("?>" . $this->compiled_template);
} else {
include $this->getCompiledFilepath();
// check file dependencies at compiled code
if ($this->smarty->compile_check) {
if (!empty($this->properties['file_dependency'])) {
$this->mustCompile = false;
foreach ($this->properties['file_dependency'] as $_file_to_check) {
$this->getResourceTypeName($_file_to_check[0], $resource_type, $resource_name);
if ($resource_type == 'file') {
$mtime = filemtime($_file_to_check[0]);
} else {
$resource_handler = $this->loadTemplateResourceHandler($resource_type);
$mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
}
// If ($mtime != $_file_to_check[1]) {
if ($mtime > $_file_to_check[1]) {
$this->mustCompile = true;
break;
}
}
if ($this->mustCompile) {
// recompile and render again
ob_get_clean();
$this->compileTemplateSource();
ob_start();
include $this->getCompiledFilepath();
}
}
}
}
} else {
if (is_callable(array($this->resource_object, 'renderUncompiled'))) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this);
}
ob_start();
$this->resource_object->renderUncompiled($this);
} else {
throw new Exception("Resource '{$this->resource_type}' must have 'renderUncompiled' methode");
}
}
$this->rendered_content = ob_get_clean();
if (!$this->resource_object->isEvaluated && empty($this->properties['file_dependency'][$this->templateUid])) {
$this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
}
if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) {
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
$this->parent->required_plugins['compiled'] = array_merge($this->parent->required_plugins['compiled'], $this->required_plugins['compiled']);
$this->parent->required_plugins['cache'] = array_merge($this->parent->required_plugins['cache'], $this->required_plugins['cache']);
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($this);
}
// write to cache when nessecary
if (!$this->resource_object->isEvaluated && ($this->caching == SMARTY_CACHING_LIFETIME_SAVED || $this->caching == SMARTY_CACHING_LIFETIME_CURRENT)) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$this->properties['has_nocache_code'] = false;
// get text between non-cached items
$cache_split = preg_split("!/\\*%%SmartyNocache:{$this->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$this->properties['nocache_hash']}%%\\*/!s", $this->rendered_content);
// get non-cached items
preg_match_all("!/\\*%%SmartyNocache:{$this->properties['nocache_hash']}%%\\*\\/(.+?)/\\*/%%SmartyNocache:{$this->properties['nocache_hash']}%%\\*/!s", $this->rendered_content, $cache_parts);
$output = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
// escape PHP tags in template content
$output .= preg_replace('/(<%|%>|<\\?php|<\\?|\\?>)/', '<?php echo \'$1\'; ?>', $curr_split);
if (isset($cache_parts[0][$curr_idx])) {
$this->properties['has_nocache_code'] = true;
// remove nocache tags from cache output
$output .= preg_replace("!/\\*/?%%SmartyNocache:{$this->properties['nocache_hash']}%%\\*/!", '', $cache_parts[0][$curr_idx]);
}
}
// rendering (must be done before writing cache file because of {function} nocache handling)
$_smarty_tpl = $this;
ob_start();
eval("?>" . $output);
$this->rendered_content = ob_get_clean();
// write cache file content
//.........这里部分代码省略.........
示例10: load
/**
* @param Smarty_Internal_Template $_template
*
* @return Smarty_Template_Cached
*/
static function load(Smarty_Internal_Template $_template)
{
$_template->cached = $cached = new Smarty_Template_Cached($_template);
//
// check if cache is valid
//
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) {
$cached->handler->populate($cached, $_template);
return $cached;
}
while (true) {
while (true) {
$cached->handler->populate($cached, $_template);
if ($cached->timestamp === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
$cached->valid = false;
} else {
$cached->valid = true;
}
if ($cached->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > $cached->timestamp + $_template->cache_lifetime) {
// lifetime expired
$cached->valid = false;
}
if ($cached->valid || !$_template->smarty->cache_locking) {
break;
}
if (!$cached->handler->locked($_template->smarty, $cached)) {
$cached->handler->acquireLock($_template->smarty, $cached);
break 2;
}
}
if ($cached->valid) {
if (!$_template->smarty->cache_locking || $cached->handler->locked($_template->smarty, $cached) === null) {
// load cache file for the following checks
if ($_template->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
$cached->process($_template);
if ($_template->smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template);
}
} else {
continue;
}
} else {
return $cached;
}
if ($cached->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && time() > $_template->cached->timestamp + $_template->properties['cache_lifetime']) {
$cached->valid = false;
}
if (!$cached->valid && $_template->smarty->cache_locking) {
$cached->handler->acquireLock($_template->smarty, $cached);
return $cached;
} else {
return $cached;
}
}
}
示例11: renderTemplate
/**
* Render the output using the compiled template or the PHP template source
*
* The rendering process is accomplished by just including the PHP files.
* The only exceptions are evaluated templates (string template). Their code has
* to be evaluated
*/
public function renderTemplate()
{
if ($this->usesCompiler()) {
if ($this->mustCompile() && $this->compiled_template === null) {
$this->compileTemplateSource();
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this);
}
$_smarty_tpl = $this;
ob_start();
if ($this->isEvaluated()) {
eval("?>" . $this->compiled_template);
} else {
include $this->getCompiledFilepath();
// check file dependencies at compiled code
if ($this->smarty->compile_check) {
if (!empty($this->properties['file_dependency'])) {
$this->mustCompile = false;
foreach ($this->properties['file_dependency'] as $_file_to_check) {
$this->getResourceTypeName($_file_to_check[0], $resource_type, $resource_name);
if ($resource_type == 'file') {
$mtime = filemtime($_file_to_check[0]);
} else {
$resource_handler = $this->loadTemplateResourceHandler($resource_type);
$mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
}
// If ($mtime != $_file_to_check[1]) {
if ($mtime > $_file_to_check[1]) {
$this->properties['file_dependency'] = array();
$this->mustCompile = true;
break;
}
}
if ($this->mustCompile) {
// recompile and render again
ob_get_clean();
$this->compileTemplateSource();
ob_start();
include $this->getCompiledFilepath();
}
}
}
}
} else {
if (is_callable(array($this->resource_object, 'renderUncompiled'))) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this);
}
ob_start();
$this->resource_object->renderUncompiled($this);
} else {
throw new Exception("Resource '{$this->resource_type}' must have 'renderUncompiled' methode");
}
}
$this->rendered_content = ob_get_clean();
if (!$this->isEvaluated) {
$this->properties['file_dependency']['F' . abs(crc32($this->getTemplateFilepath()))] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
}
if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) {
// var_dump('merge ', $this->parent->getTemplateFilepath(), $this->parent->properties['file_dependency'], $this->getTemplateFilepath(), $this->properties['file_dependency']);
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($this);
}
// write to cache when nessecary
if (!$this->isEvaluated() && ($this->caching == SMARTY_CACHING_LIFETIME_SAVED || $this->caching == SMARTY_CACHING_LIFETIME_CURRENT)) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
// write rendered template
$this->writeCachedContent($this);
// cache file may contain nocache code. read it back for processing
$this->rendered_content = $this->cache_resource_object->getCachedContents($this);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
}
}