本文整理汇总了PHP中Smarty_Internal_Filter_Handler类的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Filter_Handler类的具体用法?PHP Smarty_Internal_Filter_Handler怎么用?PHP Smarty_Internal_Filter_Handler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Smarty_Internal_Filter_Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compileTemplate
public function compileTemplate(Smarty_Internal_Template $template)
{
if (empty($template->properties['nocache_hash'])) {
$template->properties['nocache_hash'] = $this->nocache_hash;
} else {
$this->nocache_hash = $template->properties['nocache_hash'];
}
$this->nocache = false;
$this->tag_nocache = false;
$this->template = $template;
$this->template->has_nocache_code = false;
$this->smarty->_current_file = $saved_filepath = $this->template->source->filepath;
$template_header = '';
if (!$this->suppressHeader) {
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
}
do {
$this->abort_and_recompile = false;
$_content = $template->source->content;
if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
if ($_content == '') {
if ($this->suppressTemplatePropertyHeader) {
$code = '';
} else {
$code = $template_header . $template->createTemplateCodeFrame();
}
return $code;
}
$_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile);
$this->template->source->filepath = $saved_filepath;
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template);
self::$_tag_objects = array();
$merged_code = '';
if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) {
foreach ($this->merged_templates as $code) {
$merged_code .= $code;
}
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template);
}
}
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
}
if ($this->suppressTemplatePropertyHeader) {
$code = $_compiled_code . $merged_code;
} else {
$code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code;
}
unset($template->source->content);
return $code;
}
开发者ID:EfncoPlugins,项目名称:web-portal-lite-client-portal-secure-file-sharing-private-messaging,代码行数:56,代码来源:smarty_internal_templatecompilerbase.php
示例2: fetch
//.........这里部分代码省略.........
$_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'; ?>\n", $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;
}
}
} else {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
}
try {
ob_start();
array_unshift($_template->_capture_stack, array());
$_template->properties['unifunc']($_template);
if (isset($_template->_capture_stack[0][0])) {
$_template->capture_error();
}
array_shift($_template->_capture_stack);
示例3: fetch
//.........这里部分代码省略.........
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();
} catch (Exception $e) {
ob_get_clean();
throw $e;
}
// write cache file content
$_template->writeCachedContent($output);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template);
}
} else {
// var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
// replace 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;
}
}
} else {
if ($this->smarty->debugging) {
示例4: exit
if (!defined('SMARTY_DIR')) {
exit('no direct access allowed');
}
$_smarty_tpl->decodeProperties(array('file_dependency' => array('2500a64b55407e6ad4a402f576366b3f3c5c80d2' => array(0 => '/Users/zhangwenhan/web/www/backend/missy-blue/app/admin/templates/left.html', 1 => 1402727411, 2 => 'file')), 'nocache_hash' => '611926147539bec0604c207-13318892', 'function' => array(), 'has_nocache_code' => false));
/*/%%SmartyHeaderCode%%*/
if (!is_callable('smarty_function_createUrl')) {
include '/Users/zhangwenhan/web/www/backend/missy-blue/libs/view/myplugins/function.createUrl.php';
}
?>
<!-- 树状菜单 -->
<!--
<h1 class="item1">XX管理</h1>
<div class="block">
<ul>
<li><a href="<?php
echo Smarty_Internal_Filter_Handler::runFilter('variable', @URL_ROOT, $_smarty_tpl, true);
?>
index.php?c=xx&a=xx">xx管理</a></li>
</ul>
</div>
-->
<div id="menutree" class="ui-menutree">
<!--
<h1 class="menu-itemHeader menu-extension">测试管理</h1>
<div class="menu-itemCont">
<ul>
<li><a href="<?php
echo smarty_function_createUrl(array('controller' => 'test', 'action' => 'view'), $_smarty_tpl);
?>
">测试列表</a></li>
</ul>
开发者ID:guojianing,项目名称:dagger2,代码行数:31,代码来源:2500a64b55407e6ad4a402f576366b3f3c5c80d2.file.left.html.php
示例5: compileTemplate
/**
* Method to compile a Smarty template
*
* @param Smarty_Internal_Template $template template object to compile
* @return bool true if compiling succeeded, false if it failed
*/
public function compileTemplate(Smarty_Internal_Template $template)
{
if (empty($template->properties['nocache_hash'])) {
$template->properties['nocache_hash'] = $this->nocache_hash;
} else {
$this->nocache_hash = $template->properties['nocache_hash'];
}
// flag for nochache sections
$this->nocache = false;
$this->tag_nocache = false;
// save template object in compiler class
$this->template = $template;
// reset has noche code flag
$this->template->has_nocache_code = false;
$this->smarty->_current_file = $saved_filepath = $this->template->source->filepath;
// template header code
$template_header = '';
if (!$this->suppressHeader) {
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
}
do {
// flag for aborting current and start recompile
$this->abort_and_recompile = false;
// get template source
$_content = $template->source->content;
// run prefilter if required
if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
// on empty template just return header
if ($_content == '') {
if ($this->suppressTemplatePropertyHeader) {
$code = '';
} else {
$code = $template_header . $template->createTemplateCodeFrame();
}
return $code;
}
// call compiler
$_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile);
$this->template->source->filepath = $saved_filepath;
// free memory
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template);
self::$_tag_objects = array();
// return compiled code to template object
$merged_code = '';
if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) {
foreach ($this->merged_templates as $code) {
$merged_code .= $code;
}
// run postfilter if required on merged code
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template);
}
}
// run postfilter if required on compiled template code
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
}
if ($this->suppressTemplatePropertyHeader) {
$code = $_compiled_code . $merged_code;
} else {
$code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code;
}
return $code;
}
示例6: matchParentTemplateSource
/**
* Find matches in all parent template source
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*/
public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
// search parent compiler template source
$nextCompiler = $compiler;
while ($nextCompiler !== $nextCompiler->parent_compiler) {
$nextCompiler = $nextCompiler->parent_compiler;
if ($compiler !== $nextCompiler) {
// get template source
$_content = $nextCompiler->template->source->getContent();
if ($_content != '') {
// run pre filter if required
if (isset($nextCompiler->smarty->autoload_filters['pre']) || isset($nextCompiler->smarty->registered_filters['pre'])) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $nextCompiler->template);
}
$this->matchProperty($_content);
}
}
}
}
示例7: render
/**
* render template
*
* @param bool $merge_tpl_vars if true parent template variables merged in to local scope
* @param bool $no_output_filter if true do not run output filter
* @param bool $display true: display, false: fetch null: subtemplate
*
* @throws Exception
* @throws SmartyException
* @return string rendered template output
*/
public function render($merge_tpl_vars = false, $no_output_filter = true, $display = null)
{
$parentIsTpl = isset($this->parent) && $this->parent->_objType == 2;
if ($this->smarty->debugging) {
$this->smarty->_debug->start_template($this, $display);
}
// checks if template exists
if (!$this->source->exists) {
if ($parentIsTpl) {
$parent_resource = " in '{$this->parent->template_resource}'";
} else {
$parent_resource = '';
}
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
}
$save_tpl_vars = null;
$save_config_vars = null;
// merge all variable scopes into template
if ($merge_tpl_vars) {
// save local variables
$save_tpl_vars = $this->tpl_vars;
$save_config_vars = $this->config_vars;
$ptr_array = array($this);
$ptr = $this;
while (isset($ptr->parent)) {
$ptr_array[] = $ptr = $ptr->parent;
}
$ptr_array = array_reverse($ptr_array);
$parent_ptr = reset($ptr_array);
$tpl_vars = $parent_ptr->tpl_vars;
$config_vars = $parent_ptr->config_vars;
while ($parent_ptr = next($ptr_array)) {
if (!empty($parent_ptr->tpl_vars)) {
$tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);
}
if (!empty($parent_ptr->config_vars)) {
$config_vars = array_merge($config_vars, $parent_ptr->config_vars);
}
}
if (!empty(Smarty::$global_tpl_vars)) {
$tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);
}
$this->tpl_vars = $tpl_vars;
$this->config_vars = $config_vars;
}
// check URL debugging control
if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
$this->smarty->_debug->debugUrl($this);
}
// disable caching for evaluated code
if ($this->source->handler->recompiled) {
$this->caching = false;
}
// read from cache or render
$isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
if ($isCacheTpl) {
if (!isset($this->cached)) {
$this->loadCached();
}
$this->cached->render($this, $no_output_filter);
} elseif ($this->source->handler->uncompiled) {
$this->source->render($this);
} else {
if (!isset($this->compiled)) {
$this->loadCompiled();
}
$this->compiled->render($this);
}
$content = null;
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$content = Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this);
}
// display or fetch
if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) {
$this->cached->cacheModifiedCheck($this, isset($content) ? $content : ob_get_clean());
} else {
echo isset($content) ? $content : ob_get_clean();
}
if ($this->smarty->debugging) {
$this->smarty->_debug->end_template($this);
}
// debug output
if ($this->smarty->debugging) {
$this->smarty->_debug->display_debug($this, true);
}
if ($merge_tpl_vars) {
// restore local variables
$this->tpl_vars = $save_tpl_vars;
//.........这里部分代码省略.........
示例8: compileTemplate
/**
* Methode to compile a Smarty template
*
* @param $template template object to compile
* @return bool true if compiling succeeded, false if it failed
*/
public function compileTemplate($template)
{
if (empty($template->properties['nocache_hash'])) {
$template->properties['nocache_hash'] = $this->nocache_hash;
} else {
$this->nocache_hash = $template->properties['nocache_hash'];
}
// flag for nochache sections
$this->nocache = false;
$this->tag_nocache = false;
// save template object in compiler class
$this->template = $template;
$this->smarty->_current_file = $this->template->getTemplateFilepath();
// template header code
$template_header = '';
if (!$template->suppressHeader) {
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->getTemplateFilepath() . "\" */ ?>\n";
}
do {
// flag for aborting current and start recompile
$this->abort_and_recompile = false;
// get template source
$_content = $template->getTemplateSource();
// run prefilter if required
if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) {
$template->template_source = $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
// on empty template just return header
if ($_content == '') {
if ($template->suppressFileDependency) {
$template->compiled_template = '';
} else {
$template->compiled_template = $template_header . $template->createPropertyHeader();
}
return true;
}
// call compiler
$_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile);
// return compiled code to template object
if ($template->suppressFileDependency) {
$template->compiled_template = $_compiled_code;
} else {
$template->compiled_template = $template_header . $template->createPropertyHeader() . $_compiled_code;
}
// run postfilter if required
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $template);
}
}
示例9: fetch
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $ |null $parent next higher level of Smarty variables
* @return string rendered template output
*/
public function fetch($template, $cache_id = null, $compile_id = null, $parent = null)
{
if (is_object($cache_id)) {
$parent = $cache_id;
$cache_id = null;
}
if ($parent === null) {
// get default Smarty data object
$parent = $this;
}
// create template object if necessary
$template instanceof $this->template_class ? $_template = $template : ($_template = $this->createTemplate($template, $cache_id, $compile_id, $parent));
$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) ? $this->error_reporting : error_reporting() & ~E_NOTICE);
// return redered template
if (isset($this->autoload_filters['output']) || isset($this->registered_filters['output'])) {
$_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $this);
} else {
$_output = $_template->getRenderedTemplate();
}
$_template->rendered_content = null;
error_reporting($_smarty_old_error_level);
return $_output;
}
示例10: endGetData
return true;
}
function endGetData(obj, data) {
switch (obj.data('opt_id')) {
case '***':
//do samething;
break;
}
return true;
}
</script>
</div>
</div>
<!--content end-->
<!-- footer -->
<div class="footer">
<p>Copyright © 1996-<?php
echo Smarty_Internal_Filter_Handler::runFilter('variable', date('Y'), $_smarty_tpl, true);
?>
SINA Corporation, All Rights Reserved</p>
<p></p>
<p>新浪公司 <a href="http://www.sina.com.cn/intro/copyright.shtml">版权所有</a></p>
</div>
<!-- end footer -->
</div>
<script type="text/javascript" src="/js/admin/common.js"></script>
</body>
</html>
开发者ID:guojianing,项目名称:dagger2,代码行数:30,代码来源:47a43bdad6749b02b80b3e9cf02f7ce50c05814c.file.Comment.html.php
示例11: create
/**
* Create code frame for compiled and cached templates
*
* @param Smarty_Internal_Template $_template
* @param array $properties
* @param string $content optional template content
* @param string $header
* @param bool $cache flag for cache file
*
* @return string
* @throws \SmartyException
*/
public static function create(Smarty_Internal_Template $_template, $properties, $content = '', $header = '', $cache = false)
{
// build property code
$hash = str_replace(array('.', ','), '_', uniqid('', true));
$class = "__Code_{$hash}_";
$output = "<?php\n\n";
$output .= $header . "\n\n";
$output .= "if (!class_exists('{$class}',false)) {\n";
$output .= "class {$class} extends Smarty_Internal_Runtime \n";
$output .= "{\n";
$version = Smarty::SMARTY_VERSION;
$output .= "public \$version = '{$version}';\n";
$output .= "public \$hash = '{$hash}';\n";
foreach ($properties as $name => $value) {
$output .= "public \${$name} = " . var_export($value, true) . ";\n";
}
$output .= "public function render (\$_smarty_tpl) {\n";
$output .= $content;
$output .= "}\n";
if (!$cache) {
if (!empty($_template->compiler->templateFunctionCode)) {
$i = 0;
while (isset($_template->compiler->templateFunctionCode[$i])) {
// run postfilter if required on compiled template code
if ((isset($_template->smarty->autoload_filters['post']) || isset($_template->smarty->registered_filters['post'])) && !$_template->compiler->suppressFilter) {
$output .= Smarty_Internal_Filter_Handler::runFilter('post', $_template->compiler->templateFunctionCode[$i], $_template);
} else {
$output .= $_template->compiler->templateFunctionCode[$i];
}
unset($_template->compiler->templateFunctionCode[$i]);
$output .= "\n";
$i++;
}
}
if (!empty($_template->compiler->mergedSubTemplatesCode)) {
foreach ($_template->compiler->mergedSubTemplatesCode as $name => $code) {
unset($_template->compiler->mergedSubTemplatesCode[$name]);
$output .= $code;
$output .= "\n";
}
}
} else {
if (isset($_template->context)) {
foreach ($_template->context->templateFunctions as $name => $funcParam) {
if (is_file($funcParam['compiled_filepath'])) {
// read compiled file
$code = file_get_contents($funcParam['compiled_filepath']);
// grab template function
if (preg_match("/\\/\\* {$funcParam['method']} \\*\\/\\s*public\\s*([\\S\\s]*?)\\/\\*\\/ {$funcParam['method']} \\*\\//", $code, $match)) {
unset($code);
$output .= $match[0] . "\n";
}
}
}
}
}
$output .= "/* - end class - */\n}";
$output .= "\n}\n";
$output .= "\$this->compiledClass = '{$class}';\n";
return self::format_string($output);
}
示例12: preFilter
/**
* Run optional prefilter
*
* @param string $_content template source
*
* @return string
* @throws \SmartyException
*/
public function preFilter($_content)
{
// run pre filter if required
if ($_content != '' && (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre']))) {
return Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $this->template);
} else {
return $_content;
}
}
示例13: compileTemplate
/**
* Method to compile a Smarty template
*
* @param Smarty_Internal_Template $template template object to compile
* @param bool $nocache true is shall be compiled in nocache mode
*
* @param Smarty_Internal_TemplateCompilerBase $parent_compiler
*
* @return bool true if compiling succeeded, false if it failed
* @throws \SmartyException
*/
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
{
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
$nocache = isset($nocache) ? $nocache : false;
// flag for nochache sections
$this->nocache = $nocache;
$this->tag_nocache = false;
// save template object in compiler class
$this->template = $template;
// template header code
$template_header = '';
if (!$this->suppressHeader) {
$template_header .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */\n";
}
if ($isExtendsResource = !empty($this->template->source->components)) {
// we have array of inheritance templates by extends: resource
$this->sources = array_reverse($template->source->components);
}
// the $this->sources array can get additional elements while compiling by the {extends} tag
if (!$isExtendsResource) {
$this->inheritance_child = $this->template->source->isChild;
$this->smarty->_current_file = $this->template->source->filepath;
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
}
if (!($this->template->source->recompiled || $this->template->source->type == 'string' || $this->template->source->type == 'extends')) {
$this->parent_compiler->resourceInfo[$this->template->source->uid] = $this->template->source->getResourceInfo($this->template);
}
}
do {
// flag for aborting current and start recompile
$this->abort_and_recompile = false;
if ($isExtendsResource) {
$_content = '';
} else {
// get template source
$_content = $this->template->source->content;
}
if ($_content != '') {
// run prefilter if required
if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
}
// call compiler
$_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this->template);
}
// free memory
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex);
self::$_tag_objects = array();
// return compiled code to template object
// run postfilter if required on compiled template code
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') {
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
}
// unset content because template inheritance could have replace source with parent code
unset($template->source->content);
$this->parent_compiler = null;
$this->template = null;
if ($this->suppressTemplatePropertyHeader) {
return $_compiled_code;
} else {
$properties = array('resourceInfo' => $this->resourceInfo, 'isInheritanceChild' => $this->inheritance_child);
if (isset($this->templateProperties['tpl_function'])) {
$properties['templateFunctions'] = $this->templateProperties['tpl_function'];
}
if (isset($this->templateProperties['block_function'])) {
$properties['blockFunctions'] = $this->templateProperties['block_function'];
}
foreach ($this->plugins as $tmp) {
foreach ($tmp as $plugin) {
$properties['plugins'][$plugin['file']] = $plugin['function'];
}
}
foreach ($this->nocachePlugins as $tmp) {
foreach ($tmp as $plugin) {
$properties['nocachePlugins'][$plugin['file']] = $plugin['function'];
}
}
return Smarty_Internal_Extension_CodeFrame::create($template, $properties, $_compiled_code, $template_header);
}
}
示例14: compileTemplate
/**
* Method to compile a Smarty template
*
* @param Smarty_Internal_Template $template template object to compile
* @param bool $nocache true is shall be compiled in nocache mode
* @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler
*
* @return bool true if compiling succeeded, false if it failed
* @throws \Exception
*/
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null)
{
if (property_exists($template->smarty, 'plugin_search_order')) {
$this->plugin_search_order = $template->smarty->plugin_search_order;
}
// save template object in compiler class
$this->template = $template;
$this->savedSource = $this->template->source;
try {
if (isset($this->template->smarty->security_policy)) {
$this->php_handling = $this->template->smarty->security_policy->php_handling;
} else {
$this->php_handling = $this->template->smarty->php_handling;
}
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
$nocache = isset($nocache) ? $nocache : false;
if (empty($template->compiled->nocache_hash)) {
$template->compiled->nocache_hash = $this->nocache_hash;
} else {
$this->nocache_hash = $template->compiled->nocache_hash;
}
// template header code
$template_header = '';
if (!$this->suppressHeader) {
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
}
$_compiled_code = '';
$this->smarty->_current_file = $this->template->source->filepath;
if ($this->smarty->debugging) {
$this->smarty->_debug->start_compile($this->template);
}
$this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->getTimeStamp(), $this->template->source->type);
// compile for child template?
$this->inheritance_child = $this->template->isChild;
// flag for nochache sections
$this->nocache = $nocache;
$this->tag_nocache = false;
// reset has nocache code flag
$this->template->compiled->has_nocache_code = false;
$this->has_variable_string = false;
$this->prefix_code = array();
// get template source
if (!empty($this->template->source->components)) {
// we have array of inheritance templates by extends: resource
$this->sources = array_reverse($template->source->components);
$_content = '';
} else {
// get template source
$_content = $this->template->source->getContent();
}
if ($_content != '') {
// run pre filter if required
if ($_content != '' && ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter)) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
}
// call compiler
$_compiled_code = $this->doCompile($_content, true);
if ($this->smarty->debugging) {
$this->smarty->_debug->end_compile($this->template);
}
// free memory
$this->parser = null;
// restore source
$this->template->source = $this->savedSource;
$this->savedSource = null;
$this->smarty->_current_file = $this->template->source->filepath;
// return compiled code to template object
$merged_code = '';
if (!empty($this->mergedSubTemplatesCode)) {
foreach ($this->mergedSubTemplatesCode as $code) {
$merged_code .= $code;
}
}
// run post filter if required on compiled template code
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') {
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
}
if ($this->suppressTemplatePropertyHeader) {
$_compiled_code .= $merged_code;
} else {
$_compiled_code = $template_header . Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code;
}
if (!empty($this->templateFunctionCode)) {
// run post filter if required on compiled template code
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter) {
$_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template);
} else {
$_compiled_code .= $this->templateFunctionCode;
//.........这里部分代码省略.........
示例15: fetch
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $ |null $parent next higher level of Smarty variables
* @return string rendered template output
*/
public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false)
{
if (is_object($cache_id)) {
$parent = $cache_id;
$cache_id = null;
}
if ($parent === null) {
// get default Smarty data object
$parent = $this;
}
array_push($this->block_data_stack, $this->block_data);
$this->block_data = array();
// create template object if necessary
$template instanceof $this->template_class ? $_template = $template : ($_template = $this->createTemplate($template, $cache_id, $compile_id, $parent));
$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(isset($this->error_reporting) ? $this->error_reporting : error_reporting() & ~E_NOTICE);
// obtain data for cache modified check
if ($this->cache_modified_check && $this->caching && $display) {
$_isCached = $_template->isCached() && !$_template->has_nocache_code;
if ($_isCached) {
$_gmt_mtime = gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT';
} else {
$_gmt_mtime = '';
}
}
// return redered template
if (isset($this->autoload_filters['output']) || isset($this->registered_filters['output'])) {
$_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $this, $_template);
} else {
$_output = $_template->getRenderedTemplate();
}
$_template->rendered_content = null;
error_reporting($_smarty_old_error_level);
// display or fetch
if ($display) {
if ($this->caching && $this->cache_modified_check) {
$_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
if ($_isCached && $_gmt_mtime == $_last_modified_date) {
if (php_sapi_name() == 'cgi') {
header('Status: 304 Not Modified');
} else {
header('HTTP/1.1 304 Not Modified');
}
} else {
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT');
echo $_output;
}
} else {
echo $_output;
}
// debug output
if ($this->debugging) {
Smarty_Internal_Debug::display_debug($this);
}
$this->block_data = array_pop($this->block_data_stack);
return;
} else {
// return fetched content
$this->block_data = array_pop($this->block_data_stack);
return $_output;
}
}