Redbean + Smarty update

This commit is contained in:
Robin Kloppe 2014-10-13 11:24:53 +02:00
parent c1b8226466
commit eb0835ff74
122 changed files with 12653 additions and 11637 deletions

View file

@ -2,18 +2,17 @@
/**
* Smarty Internal Plugin Smarty Template Compiler Base
* This file contains the basic classes and methods for compiling Smarty templates with lexer/parser
*
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* @author Uwe Tews
*/
/**
* Main abstract compiler class
*
* @package Smarty
* @package Smarty
* @subpackage Compiler
*/
abstract class Smarty_Internal_TemplateCompilerBase
@ -138,62 +137,72 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* force compilation of complete template as nocache
*
* @var boolean
*/
public $forceNocache = false;
/**
* suppress Smarty header code in compiled template
*
* @var bool
*/
public $suppressHeader = false;
/**
* suppress template property header code in compiled template
*
* @var bool
*/
public $suppressTemplatePropertyHeader = false;
/**
* suppress pre and post filter
*
* @var bool
*/
public $suppressFilter = false;
/**
* flag if compiled template file shall we written
*
* @var bool
*/
public $write_compiled_code = true;
/**
* flag if currently a template function is compiled
*
* @var bool
*/
public $compiles_template_function = false;
/**
* called subfuntions from template function
*
* @var array
*/
public $called_functions = array();
/**
* flags for used modifier plugins
*
* @var array
*/
public $modifier_plugins = array();
/**
* type of already compiled modifier
*
* @var array
*/
public $known_modifier_type = array();
/**
* Methode to compile a Smarty template
* method to compile a Smarty template
*
* @param mixed $_content template source
*
* @return bool true if compiling succeeded, false if it failed
*/
abstract protected function doCompile($_content);
@ -203,14 +212,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function __construct()
{
$this->nocache_hash = str_replace('.', '-', uniqid(rand(), true));
$this->nocache_hash = str_replace(array('.', ','), '-', uniqid(rand(), true));
}
/**
* 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 bool $nocache true is shall be compiled in nocache mode
*
* @return bool true if compiling succeeded, false if it failed
*/
public function compileTemplate(Smarty_Internal_Template $template, $nocache = false)
@ -252,7 +262,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if ($loop || $no_sources) {
$this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
}
$loop++;
$loop ++;
if ($no_sources) {
$this->inheritance_child = true;
} else {
@ -308,13 +318,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Compile Tag
*
* This is a call back from the lexer/parser
* It executes the required compile plugin for the Smarty tag
*
* @param string $tag tag name
* @param array $args array with tag attributes
* @param array $parameter array with compilation parameter
* @param array $args array with tag attributes
* @param array $parameter array with compilation parameter
*
* @throws SmartyCompilerException
* @throws SmartyException
* @return string compiled code
*/
public function compileTag($tag, $args, $parameter = array())
@ -365,18 +377,19 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
}
// not an internal compiler tag
if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
if (strlen($tag) < 6 || substr($tag, - 5) != 'close') {
// check if tag is a registered object
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method'];
if (!in_array($method, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1]))
) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode);
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
} else {
return $this->trigger_template_error('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno);
// throw exception
$this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . $tag . '"', $this->lex->taglineno);
}
}
// check if tag is registered
@ -482,14 +495,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
} else {
// compile closing tag of block function
$base_tag = substr($tag, 0, -5);
$base_tag = substr($tag, 0, - 5);
// check if closing tag is a registered object
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method'];
if (in_array($method, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
} else {
return $this->trigger_template_error('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
// throw exception
$this->trigger_template_error('not allowed closing tag method "' . $method . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
}
}
// registered block tag ?
@ -535,17 +549,17 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
/**
* lazy loads internal compile plugin for tag and calls the compile methode
*
* lazy loads internal compile plugin for tag and calls the compile method
* compile objects cached for reuse.
* class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_Tagname.php
*
* @param string $tag tag name
* @param array $args list of tag attributes
* @param mixed $param1 optional parameter
* @param mixed $param2 optional parameter
* @param mixed $param3 optional parameter
* @param array $args list of tag attributes
* @param mixed $param1 optional parameter
* @param mixed $param2 optional parameter
* @param mixed $param3 optional parameter
*
* @return string compiled code
*/
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
@ -573,8 +587,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Check for plugins and return function name
*
* @param string $pugin_name name of plugin or function
* @param $plugin_name
* @param string $plugin_type type of plugin
*
* @return string call name of function
*/
public function getPlugin($plugin_name, $plugin_type)
@ -633,6 +648,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
*
* @param string $tag name of tag
* @param string $plugin_type type of plugin
*
* @return boolean true if found
*/
public function getPluginFromDefaultHandler($tag, $plugin_type)
@ -676,13 +692,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Inject inline code for nocache template sections
*
* This method gets the content of each template element from the parser.
* If the content is compiled code and it should be not cached the code is injected
* into the rendered output.
*
* @param string $content content of template element
* @param string $content content of template element
* @param boolean $is_code true if content is compiled code
*
* @return string content
*/
public function processNocacheCode($content, $is_code)
@ -719,10 +735,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* push current file and line offset on stack for tracing {block} source lines
*
* @param string $file new filename
* @param string $uid uid of file
* @param string $debug false debug end_compile shall not be called
* @param int $line line offset to source
* @param string $file new filename
* @param string $uid uid of file
* @param int $line line offset to source
* @param bool $debug false debug end_compile shall not be called
*/
public function pushTrace($file, $uid, $line, $debug = true)
{
@ -732,7 +748,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, $this->trace_line_offset));
$this->trace_filepath = $this->smarty->_current_file = $file;
$this->trace_uid = $uid;
$this->trace_line_offset = $line ;
$this->trace_line_offset = $line;
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
}
@ -740,7 +756,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* restore file and line offset
*
*/
public function popTrace()
{
@ -759,14 +775,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* display compiler error messages without dying
*
* If parameter $args is empty it is a parser detected syntax error.
* In this case the parser is called to obtain information about expected tokens.
*
* If parameter $args contains a string this is used as error message
*
* @param string $args individual error message or null
* @param string $line line-number
*
* @throws SmartyCompilerException when an unexpected token is found
*/
public function trigger_template_error($args = null, $line = null)
@ -775,9 +790,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (!isset($line)) {
$line = $this->lex->line;
}
// $line += $this->trace_line_offset;
// $line += $this->trace_line_offset;
$match = preg_split("/\n/", $this->lex->data);
$error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" ';
$error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" ';
if (isset($args)) {
// individual error message
$error_text .= $args;
@ -805,5 +820,4 @@ abstract class Smarty_Internal_TemplateCompilerBase
$e->template = $this->template->source->filepath;
throw $e;
}
}