mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
rename parse tree class names to Smarty_Internal_ParseTree....
This commit is contained in:
@@ -113,7 +113,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
$compiler->inheritance = true;
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser);
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
|
@@ -65,7 +65,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
$compiler->compiles_template_function = true;
|
||||
// Init temporary context
|
||||
$compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser);
|
||||
$compiler->template->has_nocache_code = false;
|
||||
$compiler->template->caching = true;
|
||||
return true;
|
||||
@@ -106,7 +106,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$compiler->compiles_template_function = false;
|
||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['called_functions'] = $compiler->called_functions;
|
||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['source_uid'] = $compiler->template->source->uid;
|
||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['uid'] = $compiler->template->source->uid;
|
||||
$compiler->called_functions = array();
|
||||
$_parameter = $_attr;
|
||||
unset($_parameter['name']);
|
||||
@@ -127,7 +127,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser);
|
||||
|
||||
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}";
|
||||
$_funcNameCaching = $_funcName . '_nocache';
|
||||
@@ -154,18 +154,15 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
|
||||
}
|
||||
//$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
||||
$output .= "ob_start();\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= $_paramsCode;
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}";
|
||||
$output .= "\$params = var_export(\$params, true);\n";
|
||||
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_variable(\\\$value);\n}\n?>";
|
||||
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_variable(\\\$value);\n}\n?>";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>";
|
||||
// $output .= $compiler->makeNocacheCode("\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\nforeach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n");
|
||||
// $output .= substr($compiler->processNocacheCode('<?php ' . "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n" . $_paramsCode . "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n" . "? >\n", true), 6);
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree( $_functionCode);
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($_functionCode);
|
||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
$output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;\n";
|
||||
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value) if(!isset(\\\$_smarty_tpl->tpl_vars[\\\$key])) \\\$_smarty_tpl->tpl_vars[\\\$key] = \\\$value;?>";
|
||||
@@ -173,8 +170,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$output .= "<?php echo str_replace('{$compiler->template->properties['nocache_hash']}', \$_smarty_tpl->properties['nocache_hash'], ob_get_clean());\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$_functionCode = new _smarty_tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php()));
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php()));
|
||||
}
|
||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['call_name'] = $_funcName;
|
||||
$output = "<?php\n";
|
||||
@@ -195,13 +192,13 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}?>";
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($_functionCode);
|
||||
$output = "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n";
|
||||
$output .= "foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php();
|
||||
// restore old buffer
|
||||
$compiler->parser->current_buffer = $saved_data[1];
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
abstract class _smarty_parsetree
|
||||
abstract class Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Parser object
|
||||
@@ -44,319 +44,4 @@ abstract class _smarty_parsetree
|
||||
abstract public function to_smarty_php();
|
||||
}
|
||||
|
||||
/**
|
||||
* A complete smarty tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_tag extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Saved block nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $saved_block_nesting;
|
||||
|
||||
/**
|
||||
* Create parse tree buffer for Smarty tag
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
$this->saved_block_nesting = $parser->block_nesting_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return complied code that loads the evaluated output of buffer content into a temporary variable
|
||||
*
|
||||
* @return string template code
|
||||
*/
|
||||
public function assign_to_var()
|
||||
{
|
||||
$var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number);
|
||||
$this->parser->compiler->prefix_code[] = sprintf("<?php ob_start();\n%s\n%s=ob_get_clean();?>", preg_replace(array('/^\s*<\?php\s+/', '/\s*\?>\s*$/'), '', $this->data), $var);
|
||||
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Code fragment inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_code extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for code fragment
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content in parentheses
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return sprintf("(%s)", $this->data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_doublequoted extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for double quoted string subtrees
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param _smarty_parsetree $subtree parsetree buffer
|
||||
*/
|
||||
public function __construct($parser, _smarty_parsetree $subtree)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->subtrees[] = $subtree;
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param _smarty_parsetree $subtree parsetree buffer
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
$last_subtree = count($this->subtrees) - 1;
|
||||
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
|
||||
if ($subtree instanceof _smarty_code) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';
|
||||
} elseif ($subtree instanceof _smarty_dq_content) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>';
|
||||
} else {
|
||||
$this->subtrees[$last_subtree]->data .= $subtree->data;
|
||||
}
|
||||
} else {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge subtree buffer content together
|
||||
*
|
||||
* @return string compiled template code
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->subtrees as $subtree) {
|
||||
if ($code !== "") {
|
||||
$code .= ".";
|
||||
}
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$more_php = $subtree->assign_to_var();
|
||||
} else {
|
||||
$more_php = $subtree->to_smarty_php();
|
||||
}
|
||||
|
||||
$code .= $more_php;
|
||||
|
||||
if (!$subtree instanceof _smarty_dq_content) {
|
||||
$this->parser->compiler->has_variable_string = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw chars as part of a double quoted string.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_dq_content extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer with string content
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data string section
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content as double quoted string
|
||||
*
|
||||
* @return string doubled quoted string
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return '"' . $this->data . '"';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template element
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_template_buffer extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Array of template elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subtrees = Array();
|
||||
|
||||
/**
|
||||
* Create root of parse tree for template elements
|
||||
*
|
||||
* @param object $parser parse object
|
||||
*/
|
||||
public function __construct($parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param _smarty_parsetree $subtree
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
if (!empty($subtree->subtrees)) {
|
||||
$this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
|
||||
} else if ($subtree->data !== '') {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and merge subtree buffers together
|
||||
*
|
||||
* @return string template code content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
|
||||
if ($this->subtrees[$key] instanceof _smarty_text) {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof _smarty_text || $this->subtrees[$key + 1]->data == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[$key]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$subtree .= $this->subtrees[$key]->to_smarty_php();
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
}
|
||||
$code .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<\/?script)/', "<?php echo '\$1'; ?>\n", $subtree);
|
||||
continue;
|
||||
}
|
||||
if ($this->subtrees[$key] instanceof _smarty_tag) {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof _smarty_tag || $this->subtrees[$key + 1]->data == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[$key]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$newCode = $this->subtrees[$key]->to_smarty_php();
|
||||
if ((preg_match('/^\s*<\?php\s+/', $newCode) && preg_match('/\s*\?>\s*$/', $subtree))) {
|
||||
$subtree = preg_replace('/\s*\?>\s*$/', "", $subtree);
|
||||
$subtree .= preg_replace('/^\s*<\?php\s+/', '', $newCode);
|
||||
} else {
|
||||
$subtree .= $newCode;
|
||||
}
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
}
|
||||
$code .= $subtree;
|
||||
continue;
|
||||
}
|
||||
$code .= $this->subtrees[$key]->to_smarty_php();
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* template text
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_text extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create template text buffer
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data text
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return strint text
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
42
libs/sysplugins/smarty_internal_parsetree_code.php
Normal file
42
libs/sysplugins/smarty_internal_parsetree_code.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Code fragment inside a tag .
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Code extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for code fragment
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content in parentheses
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return sprintf("(%s)", $this->data);
|
||||
}
|
||||
}
|
85
libs/sysplugins/smarty_internal_parsetree_dq.php
Normal file
85
libs/sysplugins/smarty_internal_parsetree_dq.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for double quoted string subtrees
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param Smarty_Internal_ParseTree $subtree parsetree buffer
|
||||
*/
|
||||
public function __construct($parser, Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->subtrees[] = $subtree;
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param Smarty_Internal_ParseTree $subtree parsetree buffer
|
||||
*/
|
||||
public function append_subtree(Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
$last_subtree = count($this->subtrees) - 1;
|
||||
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Code) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';
|
||||
} elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>';
|
||||
} else {
|
||||
$this->subtrees[$last_subtree]->data .= $subtree->data;
|
||||
}
|
||||
} else {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge subtree buffer content together
|
||||
*
|
||||
* @return string compiled template code
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->subtrees as $subtree) {
|
||||
if ($code !== "") {
|
||||
$code .= ".";
|
||||
}
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$more_php = $subtree->assign_to_var();
|
||||
} else {
|
||||
$more_php = $subtree->to_smarty_php();
|
||||
}
|
||||
|
||||
$code .= $more_php;
|
||||
|
||||
if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
|
||||
$this->parser->compiler->has_variable_string = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
43
libs/sysplugins/smarty_internal_parsetree_dqcontent.php
Normal file
43
libs/sysplugins/smarty_internal_parsetree_dqcontent.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Raw chars as part of a double quoted string.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_DqContent extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer with string content
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data string section
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content as double quoted string
|
||||
*
|
||||
* @return string doubled quoted string
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return '"' . $this->data . '"';
|
||||
}
|
||||
}
|
63
libs/sysplugins/smarty_internal_parsetree_tag.php
Normal file
63
libs/sysplugins/smarty_internal_parsetree_tag.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* A complete smarty tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Saved block nesting level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $saved_block_nesting;
|
||||
|
||||
/**
|
||||
* Create parse tree buffer for Smarty tag
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
$this->saved_block_nesting = $parser->block_nesting_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return complied code that loads the evaluated output of buffer content into a temporary variable
|
||||
*
|
||||
* @return string template code
|
||||
*/
|
||||
public function assign_to_var()
|
||||
{
|
||||
$var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number);
|
||||
$this->parser->compiler->prefix_code[] = sprintf("<?php ob_start();\n%s\n%s=ob_get_clean();?>", preg_replace(array('/^\s*<\?php\s+/', '/\s*\?>\s*$/'), '', $this->data), $var);
|
||||
|
||||
return $var;
|
||||
}
|
||||
}
|
101
libs/sysplugins/smarty_internal_parsetree_template.php
Normal file
101
libs/sysplugins/smarty_internal_parsetree_template.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Template element
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Array of template elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subtrees = Array();
|
||||
|
||||
/**
|
||||
* Create root of parse tree for template elements
|
||||
*
|
||||
* @param object $parser parse object
|
||||
*/
|
||||
public function __construct($parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param Smarty_Internal_ParseTree $subtree
|
||||
*/
|
||||
public function append_subtree(Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
if (!empty($subtree->subtrees)) {
|
||||
$this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
|
||||
} else if ($subtree->data !== '') {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and merge subtree buffers together
|
||||
*
|
||||
* @return string template code content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
|
||||
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text || $this->subtrees[$key + 1]->data == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[$key]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$subtree .= $this->subtrees[$key]->to_smarty_php();
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
}
|
||||
$code .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<\/?script)/', "<?php echo '\$1'; ?>\n", $subtree);
|
||||
continue;
|
||||
}
|
||||
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag || $this->subtrees[$key + 1]->data == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[$key]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$newCode = $this->subtrees[$key]->to_smarty_php();
|
||||
if ((preg_match('/^\s*<\?php\s+/', $newCode) && preg_match('/\s*\?>\s*$/', $subtree))) {
|
||||
$subtree = preg_replace('/\s*\?>\s*$/', "\n", $subtree);
|
||||
$subtree .= preg_replace('/^\s*<\?php\s+/', '', $newCode);
|
||||
} else {
|
||||
$subtree .= $newCode;
|
||||
}
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
}
|
||||
$code .= $subtree;
|
||||
continue;
|
||||
}
|
||||
$code .= $this->subtrees[$key]->to_smarty_php();
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
}
|
40
libs/sysplugins/smarty_internal_parsetree_text.php
Normal file
40
libs/sysplugins/smarty_internal_parsetree_text.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
* *
|
||||
* template text
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
|
||||
{
|
||||
/**
|
||||
* Create template text buffer
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data text
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return string text
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
@@ -8,11 +8,6 @@
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
include 'smarty_internal_parsetree.php';
|
||||
|
||||
/**
|
||||
* Class SmartyTemplateCompiler
|
||||
*
|
||||
|
Reference in New Issue
Block a user