mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
stashing PCRE modifications
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
===== trunk =====
|
===== trunk =====
|
||||||
18.12.2011
|
18.12.2011
|
||||||
- bufix strings ending with " in multiline strings of config files failed to compile {isse 67)
|
- bufix strings ending with " in multiline strings of config files failed to compile {isse 67)
|
||||||
|
- added chaining to Smarty_Internal_Templatebase
|
||||||
|
- changed unloadFilter() to not return a boolean in favor of chaining and API conformity
|
||||||
|
- bugfix unregisterObject() raised notice when object to unregister did not exist
|
||||||
|
- added SMARTY_PREG_MODIFIER for proper PCRE charset handling (Forum Topic 20452)
|
||||||
|
|
||||||
17.12.2011
|
17.12.2011
|
||||||
- improvement of compiling speed by new handling of plain text blocks in the lexer/parser (issue 68)
|
- improvement of compiling speed by new handling of plain text blocks in the lexer/parser (issue 68)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -84,7 +84,7 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// convert mult. spaces & special chars to single space
|
// convert mult. spaces & special chars to single space
|
||||||
$_paragraph = preg_replace(array('!\s+!u', '!(^\s+)|(\s+$)!u'), array(' ', ''), $_paragraph);
|
$_paragraph = preg_replace(array('!\s+!' . SMARTY_PREG_MODIFIER, '!(^\s+)|(\s+$)!' . SMARTY_PREG_MODIFIER), array(' ', ''), $_paragraph);
|
||||||
// indent first line
|
// indent first line
|
||||||
if ($indent_first > 0) {
|
if ($indent_first > 0) {
|
||||||
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
|
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
|
||||||
|
@@ -177,7 +177,7 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
|
|||||||
|
|
||||||
if ($labels) {
|
if ($labels) {
|
||||||
if ($label_ids) {
|
if ($label_ids) {
|
||||||
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!u', '_', $name . '_' . $value));
|
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . SMARTY_PREG_MODIFIER, '_', $name . '_' . $value));
|
||||||
$_output .= '<label for="' . $_id . '">';
|
$_output .= '<label for="' . $_id . '">';
|
||||||
} else {
|
} else {
|
||||||
$_output .= '<label>';
|
$_output .= '<label>';
|
||||||
|
@@ -165,7 +165,7 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
|
|||||||
|
|
||||||
if ($labels) {
|
if ($labels) {
|
||||||
if ($label_ids) {
|
if ($label_ids) {
|
||||||
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!u', '_', $name . '_' . $value));
|
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . SMARTY_PREG_MODIFIER, '_', $name . '_' . $value));
|
||||||
$_output .= '<label for="' . $_id . '">';
|
$_output .= '<label for="' . $_id . '">';
|
||||||
} else {
|
} else {
|
||||||
$_output .= '<label>';
|
$_output .= '<label>';
|
||||||
|
@@ -130,7 +130,7 @@ function smarty_function_mailto($params, $template)
|
|||||||
}
|
}
|
||||||
$address_encode = '';
|
$address_encode = '';
|
||||||
for ($x = 0, $_length = strlen($address); $x < $_length; $x++) {
|
for ($x = 0, $_length = strlen($address); $x < $_length; $x++) {
|
||||||
if (preg_match('!\w!u', $address[$x])) {
|
if (preg_match('!\w!' . SMARTY_PREG_MODIFIER, $address[$x])) {
|
||||||
$address_encode .= '%' . bin2hex($address[$x]);
|
$address_encode .= '%' . bin2hex($address[$x]);
|
||||||
} else {
|
} else {
|
||||||
$address_encode .= $address[$x];
|
$address_encode .= $address[$x];
|
||||||
|
@@ -30,17 +30,17 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
|
|||||||
$upper_string = mb_convert_case( $string, MB_CASE_TITLE, SMARTY_RESOURCE_CHAR_SET );
|
$upper_string = mb_convert_case( $string, MB_CASE_TITLE, SMARTY_RESOURCE_CHAR_SET );
|
||||||
} else {
|
} else {
|
||||||
// uppercase word breaks
|
// uppercase word breaks
|
||||||
$upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!ueS", "stripslashes('\\1').mb_convert_case(stripslashes('\\2'),MB_CASE_UPPER, SMARTY_RESOURCE_CHAR_SET)", $string);
|
$upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!eS" . SMARTY_PREG_MODIFIER, "stripslashes('\\1').mb_convert_case(stripslashes('\\2'),MB_CASE_UPPER, SMARTY_RESOURCE_CHAR_SET)", $string);
|
||||||
}
|
}
|
||||||
// check uc_digits case
|
// check uc_digits case
|
||||||
if (!$uc_digits) {
|
if (!$uc_digits) {
|
||||||
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!u", $string, $matches, PREG_OFFSET_CAPTURE)) {
|
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . SMARTY_PREG_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
|
||||||
foreach($matches[1] as $match) {
|
foreach($matches[1] as $match) {
|
||||||
$upper_string = substr_replace($upper_string, mb_strtolower($match[0], SMARTY_RESOURCE_CHAR_SET), $match[1], strlen($match[0]));
|
$upper_string = substr_replace($upper_string, mb_strtolower($match[0], SMARTY_RESOURCE_CHAR_SET), $match[1], strlen($match[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$upper_string = preg_replace("!((^|\s)['\"])(\w)!ue", "stripslashes('\\1').mb_convert_case(stripslashes('\\3'),MB_CASE_UPPER, SMARTY_RESOURCE_CHAR_SET)", $upper_string);
|
$upper_string = preg_replace("!((^|\s)['\"])(\w)!e" . SMARTY_PREG_MODIFIER, "stripslashes('\\1').mb_convert_case(stripslashes('\\3'),MB_CASE_UPPER, SMARTY_RESOURCE_CHAR_SET)", $upper_string);
|
||||||
return $upper_string;
|
return $upper_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,16 +49,16 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
|
|||||||
$string = strtolower($string);
|
$string = strtolower($string);
|
||||||
}
|
}
|
||||||
// uppercase (including hyphenated words)
|
// uppercase (including hyphenated words)
|
||||||
$upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!ueS", "stripslashes('\\1').ucfirst(stripslashes('\\2'))", $string);
|
$upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!eS" . SMARTY_PREG_MODIFIER, "stripslashes('\\1').ucfirst(stripslashes('\\2'))", $string);
|
||||||
// check uc_digits case
|
// check uc_digits case
|
||||||
if (!$uc_digits) {
|
if (!$uc_digits) {
|
||||||
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!u", $string, $matches, PREG_OFFSET_CAPTURE)) {
|
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . SMARTY_PREG_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
|
||||||
foreach($matches[1] as $match) {
|
foreach($matches[1] as $match) {
|
||||||
$upper_string = substr_replace($upper_string, strtolower($match[0]), $match[1], strlen($match[0]));
|
$upper_string = substr_replace($upper_string, strtolower($match[0]), $match[1], strlen($match[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$upper_string = preg_replace("!((^|\s)['\"])(\w)!ue", "stripslashes('\\1').strtoupper(stripslashes('\\3'))", $upper_string);
|
$upper_string = preg_replace("!((^|\s)['\"])(\w)!e" . SMARTY_PREG_MODIFIER, "stripslashes('\\1').strtoupper(stripslashes('\\3'))", $upper_string);
|
||||||
return $upper_string;
|
return $upper_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
function smarty_modifier_spacify($string, $spacify_char = ' ')
|
function smarty_modifier_spacify($string, $spacify_char = ' ')
|
||||||
{
|
{
|
||||||
// well… what about charsets besides latin and UTF-8?
|
// well… what about charsets besides latin and UTF-8?
|
||||||
return implode($spacify_char, preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY));
|
return implode($spacify_char, preg_split('//' . SMARTY_PREG_MODIFIER, $string, -1, PREG_SPLIT_NO_EMPTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@@ -32,7 +32,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
|
|||||||
if (mb_strlen($string, SMARTY_RESOURCE_CHAR_SET) > $length) {
|
if (mb_strlen($string, SMARTY_RESOURCE_CHAR_SET) > $length) {
|
||||||
$length -= min($length, mb_strlen($etc, SMARTY_RESOURCE_CHAR_SET));
|
$length -= min($length, mb_strlen($etc, SMARTY_RESOURCE_CHAR_SET));
|
||||||
if (!$break_words && !$middle) {
|
if (!$break_words && !$middle) {
|
||||||
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1, SMARTY_RESOURCE_CHAR_SET));
|
$string = preg_replace('/\s+?(\S+)?$/' . SMARTY_PREG_MODIFIER, '', mb_substr($string, 0, $length + 1, SMARTY_RESOURCE_CHAR_SET));
|
||||||
}
|
}
|
||||||
if (!$middle) {
|
if (!$middle) {
|
||||||
return mb_substr($string, 0, $length, SMARTY_RESOURCE_CHAR_SET) . $etc;
|
return mb_substr($string, 0, $length, SMARTY_RESOURCE_CHAR_SET) . $etc;
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
function smarty_modifiercompiler_count_characters($params, $compiler)
|
function smarty_modifiercompiler_count_characters($params, $compiler)
|
||||||
{
|
{
|
||||||
if (!isset($params[1]) || $params[1] != 'true') {
|
if (!isset($params[1]) || $params[1] != 'true') {
|
||||||
return 'preg_match_all(\'/[^\s]/u\',' . $params[0] . ', $tmp)';
|
return 'preg_match_all(\'/[^\s]/' . SMARTY_PREG_MODIFIER . '\',' . $params[0] . ', $tmp)';
|
||||||
}
|
}
|
||||||
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||||
return 'mb_strlen(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET)';
|
return 'mb_strlen(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET)';
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
function smarty_modifiercompiler_count_sentences($params, $compiler)
|
function smarty_modifiercompiler_count_sentences($params, $compiler)
|
||||||
{
|
{
|
||||||
// find periods, question marks, exclamation marks with a word before but not after.
|
// find periods, question marks, exclamation marks with a word before but not after.
|
||||||
return 'preg_match_all("#\w[\.\?\!](\W|$)#uS", ' . $params[0] . ', $tmp)';
|
return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . SMARTY_PREG_MODIFIER . '", ' . $params[0] . ', $tmp)';
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@@ -21,9 +21,9 @@
|
|||||||
function smarty_modifiercompiler_count_words($params, $compiler)
|
function smarty_modifiercompiler_count_words($params, $compiler)
|
||||||
{
|
{
|
||||||
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) {
|
||||||
// return 'preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp)';
|
// return 'preg_match_all(\'#[\w\pL]+#' . SMARTY_PREG_MODIFIER . '\', ' . $params[0] . ', $tmp)';
|
||||||
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
|
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
|
||||||
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/u\', ' . $params[0] . ', $tmp)';
|
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . SMARTY_PREG_MODIFIER . '\', ' . $params[0] . ', $tmp)';
|
||||||
}
|
}
|
||||||
// no MBString fallback
|
// no MBString fallback
|
||||||
return 'str_word_count(' . $params[0] . ')';
|
return 'str_word_count(' . $params[0] . ')';
|
||||||
|
@@ -27,7 +27,7 @@ function smarty_modifiercompiler_strip($params, $compiler)
|
|||||||
if (!isset($params[1])) {
|
if (!isset($params[1])) {
|
||||||
$params[1] = "' '";
|
$params[1] = "' '";
|
||||||
}
|
}
|
||||||
return "preg_replace('!\s+!u', {$params[1]},{$params[0]})";
|
return "preg_replace('!\s+!" . SMARTY_PREG_MODIFIER . "', {$params[1]},{$params[0]})";
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@@ -22,7 +22,7 @@ if(!function_exists('smarty_mb_wordwrap')) {
|
|||||||
function smarty_mb_wordwrap($str, $width=75, $break="\n", $cut=false)
|
function smarty_mb_wordwrap($str, $width=75, $break="\n", $cut=false)
|
||||||
{
|
{
|
||||||
// break words into tokens using white space as a delimiter
|
// break words into tokens using white space as a delimiter
|
||||||
$tokens = preg_split('!(\s)!uS', $str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
$tokens = preg_split('!(\s)!S' . SMARTY_PREG_MODIFIER, $str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
||||||
$length = 0;
|
$length = 0;
|
||||||
$t = '';
|
$t = '';
|
||||||
$_previous = false;
|
$_previous = false;
|
||||||
@@ -37,14 +37,14 @@ if(!function_exists('smarty_mb_wordwrap')) {
|
|||||||
$length = 0;
|
$length = 0;
|
||||||
|
|
||||||
if ($cut) {
|
if ($cut) {
|
||||||
$_tokens = preg_split('!(.{' . $width . '})!uS', $_token, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
$_tokens = preg_split('!(.{' . $width . '})!S' . SMARTY_PREG_MODIFIER, $_token, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
||||||
// broken words go on a new line
|
// broken words go on a new line
|
||||||
$t .= $break;
|
$t .= $break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($_tokens as $token) {
|
foreach ($_tokens as $token) {
|
||||||
$_space = !!preg_match('!^\s$!uS', $token);
|
$_space = !!preg_match('!^\s$!S' . SMARTY_PREG_MODIFIER, $token);
|
||||||
$token_length = mb_strlen($token, SMARTY_RESOURCE_CHAR_SET);
|
$token_length = mb_strlen($token, SMARTY_RESOURCE_CHAR_SET);
|
||||||
$length += $token_length;
|
$length += $token_length;
|
||||||
|
|
||||||
|
@@ -1,34 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Smarty Template Base
|
* Smarty Internal Plugin Smarty Template Base
|
||||||
*
|
*
|
||||||
* This file contains the basic shared methodes for template handling
|
* This file contains the basic shared methodes for template handling
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Template
|
* @subpackage Template
|
||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class with shared template methodes
|
* Class with shared template methodes
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Template
|
* @subpackage Template
|
||||||
*/
|
*/
|
||||||
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches a rendered Smarty template
|
* fetches a rendered Smarty template
|
||||||
*
|
*
|
||||||
* @param string $template the resource handle of the template file or template object
|
* @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 $cache_id cache id to be used with this template
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @param bool $display true: display, false: fetch
|
* @param bool $display true: display, false: fetch
|
||||||
* @param bool $merge_tpl_vars if true parent template variables merged in to local scope
|
* @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 $no_output_filter if true do not run output filter
|
||||||
* @return string rendered template output
|
* @return string rendered template output
|
||||||
*/
|
*/
|
||||||
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
|
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
|
||||||
{
|
{
|
||||||
if ($template === null && $this instanceof $this->template_class) {
|
if ($template === null && $this instanceof $this->template_class) {
|
||||||
@@ -361,13 +361,13 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays a Smarty template
|
* displays a Smarty template
|
||||||
*
|
*
|
||||||
* @param string $template the resource handle of the template file or template object
|
* @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 $cache_id cache id to be used with this template
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
*/
|
*/
|
||||||
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||||
{
|
{
|
||||||
// display template
|
// display template
|
||||||
@@ -375,14 +375,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test if cache is valid
|
* test if cache is valid
|
||||||
*
|
*
|
||||||
* @param string|object $template the resource handle of the template file or template object
|
* @param string|object $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 $cache_id cache id to be used with this template
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @return boolean cache status
|
* @return boolean cache status
|
||||||
*/
|
*/
|
||||||
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||||
{
|
{
|
||||||
if ($template === null && $this instanceof $this->template_class) {
|
if ($template === null && $this instanceof $this->template_class) {
|
||||||
@@ -399,26 +399,27 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a data object
|
* creates a data object
|
||||||
*
|
*
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @returns Smarty_Data data object
|
* @returns Smarty_Data data object
|
||||||
*/
|
*/
|
||||||
public function createData($parent = null)
|
public function createData($parent = null)
|
||||||
{
|
{
|
||||||
return new Smarty_Data($parent, $this);
|
return new Smarty_Data($parent, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers plugin to be used in templates
|
* Registers plugin to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $type plugin type
|
* @param string $type plugin type
|
||||||
* @param string $tag name of template tag
|
* @param string $tag name of template tag
|
||||||
* @param callback $callback PHP callback to register
|
* @param callback $callback PHP callback to register
|
||||||
* @param boolean $cacheable if true (default) this fuction is cachable
|
* @param boolean $cacheable if true (default) this fuction is cachable
|
||||||
* @param array $cache_attr caching attributes if any
|
* @param array $cache_attr caching attributes if any
|
||||||
* @throws SmartyException when the plugin tag is invalid
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
* @throws SmartyException when the plugin tag is invalid
|
||||||
|
*/
|
||||||
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||||
@@ -428,78 +429,94 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
} else {
|
} else {
|
||||||
$this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
|
$this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister Plugin
|
* Unregister Plugin
|
||||||
*
|
*
|
||||||
* @param string $type of plugin
|
* @param string $type of plugin
|
||||||
* @param string $tag name of plugin
|
* @param string $tag name of plugin
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function unregisterPlugin($type, $tag)
|
public function unregisterPlugin($type, $tag)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||||
unset($this->smarty->registered_plugins[$type][$tag]);
|
unset($this->smarty->registered_plugins[$type][$tag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a resource to fetch a template
|
* Registers a resource to fetch a template
|
||||||
*
|
*
|
||||||
* @param string $type name of resource type
|
* @param string $type name of resource type
|
||||||
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
|
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function registerResource($type, $callback)
|
public function registerResource($type, $callback)
|
||||||
{
|
{
|
||||||
$this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
|
$this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a resource
|
* Unregisters a resource
|
||||||
*
|
*
|
||||||
* @param string $type name of resource type
|
* @param string $type name of resource type
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function unregisterResource($type)
|
public function unregisterResource($type)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_resources[$type])) {
|
if (isset($this->smarty->registered_resources[$type])) {
|
||||||
unset($this->smarty->registered_resources[$type]);
|
unset($this->smarty->registered_resources[$type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a cache resource to cache a template's output
|
* Registers a cache resource to cache a template's output
|
||||||
*
|
*
|
||||||
* @param string $type name of cache resource type
|
* @param string $type name of cache resource type
|
||||||
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
|
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function registerCacheResource($type, Smarty_CacheResource $callback)
|
public function registerCacheResource($type, Smarty_CacheResource $callback)
|
||||||
{
|
{
|
||||||
$this->smarty->registered_cache_resources[$type] = $callback;
|
$this->smarty->registered_cache_resources[$type] = $callback;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a cache resource
|
* Unregisters a cache resource
|
||||||
*
|
*
|
||||||
* @param string $type name of cache resource type
|
* @param string $type name of cache resource type
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function unregisterCacheResource($type)
|
public function unregisterCacheResource($type)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_cache_resources[$type])) {
|
if (isset($this->smarty->registered_cache_resources[$type])) {
|
||||||
unset($this->smarty->registered_cache_resources[$type]);
|
unset($this->smarty->registered_cache_resources[$type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers object to be used in templates
|
* Registers object to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $object name of template object
|
* @param string $object name of template object
|
||||||
* @param object $object_impl the referenced PHP object to register
|
* @param object $object_impl the referenced PHP object to register
|
||||||
* @param array $allowed list of allowed methods (empty = all)
|
* @param array $allowed list of allowed methods (empty = all)
|
||||||
* @param boolean $smarty_args smarty argument format, else traditional
|
* @param boolean $smarty_args smarty argument format, else traditional
|
||||||
* @param array $block_methods list of block-methods
|
* @param array $block_methods list of block-methods
|
||||||
* @param array $block_functs list of methods that are block format
|
* @param array $block_functs list of methods that are block format
|
||||||
* @throws SmartyException if any of the methods in $allowed or $block_methods are invalid
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
* @throws SmartyException if any of the methods in $allowed or $block_methods are invalid
|
||||||
|
*/
|
||||||
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||||
{
|
{
|
||||||
// test if allowed methodes callable
|
// test if allowed methodes callable
|
||||||
@@ -521,15 +538,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
// register the object
|
// register the object
|
||||||
$this->smarty->registered_objects[$object_name] =
|
$this->smarty->registered_objects[$object_name] =
|
||||||
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
|
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a reference to a registered object
|
* return a reference to a registered object
|
||||||
*
|
*
|
||||||
* @param string $name object name
|
* @param string $name object name
|
||||||
* @return object
|
* @return object
|
||||||
* @throws SmartyException if no such object is found
|
* @throws SmartyException if no such object is found
|
||||||
*/
|
*/
|
||||||
public function getRegisteredObject($name)
|
public function getRegisteredObject($name)
|
||||||
{
|
{
|
||||||
if (!isset($this->smarty->registered_objects[$name])) {
|
if (!isset($this->smarty->registered_objects[$name])) {
|
||||||
@@ -542,24 +560,28 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unregister an object
|
* unregister an object
|
||||||
*
|
*
|
||||||
* @param string $name object name
|
* @param string $name object name
|
||||||
* @throws SmartyException if no such object is found
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unregisterObject($name)
|
public function unregisterObject($name)
|
||||||
{
|
{
|
||||||
unset($this->smarty->registered_objects[$name]);
|
if (isset($this->smarty->registered_objects[$name])) {
|
||||||
return;
|
unset($this->smarty->registered_objects[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers static classes to be used in templates
|
* Registers static classes to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $class name of template class
|
* @param string $class name of template class
|
||||||
* @param string $class_impl the referenced PHP class to register
|
* @param string $class_impl the referenced PHP class to register
|
||||||
* @throws SmartyException if $class_impl does not refer to an existing class
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
* @throws SmartyException if $class_impl does not refer to an existing class
|
||||||
|
*/
|
||||||
public function registerClass($class_name, $class_impl)
|
public function registerClass($class_name, $class_impl)
|
||||||
{
|
{
|
||||||
// test if exists
|
// test if exists
|
||||||
@@ -568,14 +590,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
// register the class
|
// register the class
|
||||||
$this->smarty->registered_classes[$class_name] = $class_impl;
|
$this->smarty->registered_classes[$class_name] = $class_impl;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default plugin handler
|
* Registers a default plugin handler
|
||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
* @throws SmartyException if $callback is not callable
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
* @throws SmartyException if $callback is not callable
|
||||||
|
*/
|
||||||
public function registerDefaultPluginHandler($callback)
|
public function registerDefaultPluginHandler($callback)
|
||||||
{
|
{
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
@@ -583,14 +607,17 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
} else {
|
} else {
|
||||||
throw new SmartyException("Default plugin handler '$callback' not callable");
|
throw new SmartyException("Default plugin handler '$callback' not callable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default template handler
|
* Registers a default template handler
|
||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
* @throws SmartyException if $callback is not callable
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
* @throws SmartyException if $callback is not callable
|
||||||
|
*/
|
||||||
public function registerDefaultTemplateHandler($callback)
|
public function registerDefaultTemplateHandler($callback)
|
||||||
{
|
{
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
@@ -598,14 +625,17 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
} else {
|
} else {
|
||||||
throw new SmartyException("Default template handler '$callback' not callable");
|
throw new SmartyException("Default template handler '$callback' not callable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default template handler
|
* Registers a default template handler
|
||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
* @throws SmartyException if $callback is not callable
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
* @throws SmartyException if $callback is not callable
|
||||||
|
*/
|
||||||
public function registerDefaultConfigHandler($callback)
|
public function registerDefaultConfigHandler($callback)
|
||||||
{
|
{
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
@@ -613,38 +643,46 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
} else {
|
} else {
|
||||||
throw new SmartyException("Default config handler '$callback' not callable");
|
throw new SmartyException("Default config handler '$callback' not callable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a filter function
|
* Registers a filter function
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param callback $callback
|
* @param callback $callback
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function registerFilter($type, $callback)
|
public function registerFilter($type, $callback)
|
||||||
{
|
{
|
||||||
$this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
|
$this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a filter function
|
* Unregisters a filter function
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param callback $callback
|
* @param callback $callback
|
||||||
*/
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
|
*/
|
||||||
public function unregisterFilter($type, $callback)
|
public function unregisterFilter($type, $callback)
|
||||||
{
|
{
|
||||||
$name = $this->_get_filter_name($callback);
|
$name = $this->_get_filter_name($callback);
|
||||||
if (isset($this->smarty->registered_filters[$type][$name])) {
|
if (isset($this->smarty->registered_filters[$type][$name])) {
|
||||||
unset($this->smarty->registered_filters[$type][$name]);
|
unset($this->smarty->registered_filters[$type][$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return internal filter name
|
* Return internal filter name
|
||||||
*
|
*
|
||||||
* @param callback $function_name
|
* @param callback $function_name
|
||||||
*/
|
* @return string internal filter name
|
||||||
|
*/
|
||||||
public function _get_filter_name($function_name)
|
public function _get_filter_name($function_name)
|
||||||
{
|
{
|
||||||
if (is_array($function_name)) {
|
if (is_array($function_name)) {
|
||||||
@@ -657,12 +695,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load a filter of specified type and name
|
* load a filter of specified type and name
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param string $name filter name
|
* @param string $name filter name
|
||||||
* @return bool
|
* @throws SmartyException if filter could not be loaded
|
||||||
*/
|
*/
|
||||||
public function loadFilter($type, $name)
|
public function loadFilter($type, $name)
|
||||||
{
|
{
|
||||||
$_plugin = "smarty_{$type}filter_{$name}";
|
$_plugin = "smarty_{$type}filter_{$name}";
|
||||||
@@ -677,43 +715,41 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new SmartyException("{$type}filter \"{$name}\" not callable");
|
throw new SmartyException("{$type}filter \"{$name}\" not callable");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unload a filter of specified type and name
|
* unload a filter of specified type and name
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param string $name filter name
|
* @param string $name filter name
|
||||||
* @return bool
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unloadFilter($type, $name)
|
public function unloadFilter($type, $name)
|
||||||
{
|
{
|
||||||
$_filter_name = "smarty_{$type}filter_{$name}";
|
$_filter_name = "smarty_{$type}filter_{$name}";
|
||||||
if (isset($this->smarty->registered_filters[$type][$_filter_name])) {
|
if (isset($this->smarty->registered_filters[$type][$_filter_name])) {
|
||||||
unset ($this->smarty->registered_filters[$type][$_filter_name]);
|
unset ($this->smarty->registered_filters[$type][$_filter_name]);
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* preg_replace callback to convert camelcase getter/setter to underscore property names
|
* preg_replace callback to convert camelcase getter/setter to underscore property names
|
||||||
*
|
*
|
||||||
* @param string $match match string
|
* @param string $match match string
|
||||||
* @return string replacemant
|
* @return string replacemant
|
||||||
*/
|
*/
|
||||||
private function replaceCamelcase($match) {
|
private function replaceCamelcase($match) {
|
||||||
return "_" . strtolower($match[1]);
|
return "_" . strtolower($match[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle unknown class methods
|
* Handle unknown class methods
|
||||||
*
|
*
|
||||||
* @param string $name unknown method-name
|
* @param string $name unknown method-name
|
||||||
* @param array $args argument array
|
* @param array $args argument array
|
||||||
*/
|
*/
|
||||||
public function __call($name, $args)
|
public function __call($name, $args)
|
||||||
{
|
{
|
||||||
static $_prefixes = array('set' => true, 'get' => true);
|
static $_prefixes = array('set' => true, 'get' => true);
|
||||||
|
Reference in New Issue
Block a user