stashing PCRE modifications

This commit is contained in:
rodneyrehm
2011-12-18 17:21:44 +00:00
parent d0b6b69f7c
commit 75c271079d
15 changed files with 731 additions and 688 deletions

View File

@@ -1,6 +1,10 @@
===== trunk =====
18.12.2011
- 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
- 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

View File

@@ -84,7 +84,7 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
continue;
}
// 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
if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;

View File

@@ -177,7 +177,7 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if ($labels) {
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 . '">';
} else {
$_output .= '<label>';

View File

@@ -165,7 +165,7 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if ($labels) {
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 . '">';
} else {
$_output .= '<label>';

View File

@@ -130,7 +130,7 @@ function smarty_function_mailto($params, $template)
}
$address_encode = '';
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]);
} else {
$address_encode .= $address[$x];

View File

@@ -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 );
} else {
// 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
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) {
$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;
}
@@ -49,16 +49,16 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$string = strtolower($string);
}
// 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
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) {
$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;
}

View File

@@ -21,7 +21,7 @@
function smarty_modifier_spacify($string, $spacify_char = ' ')
{
// 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));
}
?>

View File

@@ -32,7 +32,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (mb_strlen($string, SMARTY_RESOURCE_CHAR_SET) > $length) {
$length -= min($length, mb_strlen($etc, SMARTY_RESOURCE_CHAR_SET));
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) {
return mb_substr($string, 0, $length, SMARTY_RESOURCE_CHAR_SET) . $etc;

View File

@@ -21,7 +21,7 @@
function smarty_modifiercompiler_count_characters($params, $compiler)
{
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$ */) {
return 'mb_strlen(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET)';

View File

@@ -22,7 +22,7 @@
function smarty_modifiercompiler_count_sentences($params, $compiler)
{
// 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)';
}
?>

View File

@@ -21,9 +21,9 @@
function smarty_modifiercompiler_count_words($params, $compiler)
{
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
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
return 'str_word_count(' . $params[0] . ')';

View File

@@ -27,7 +27,7 @@ function smarty_modifiercompiler_strip($params, $compiler)
if (!isset($params[1])) {
$params[1] = "' '";
}
return "preg_replace('!\s+!u', {$params[1]},{$params[0]})";
return "preg_replace('!\s+!" . SMARTY_PREG_MODIFIER . "', {$params[1]},{$params[0]})";
}
?>

View File

@@ -22,7 +22,7 @@ if(!function_exists('smarty_mb_wordwrap')) {
function smarty_mb_wordwrap($str, $width=75, $break="\n", $cut=false)
{
// 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;
$t = '';
$_previous = false;
@@ -37,14 +37,14 @@ if(!function_exists('smarty_mb_wordwrap')) {
$length = 0;
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
$t .= $break;
}
}
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);
$length += $token_length;

View File

@@ -1,34 +1,34 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Base
*
* This file contains the basic shared methodes for template handling
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
* Smarty Internal Plugin Smarty Template Base
*
* This file contains the basic shared methodes for template handling
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
/**
* Class with shared template methodes
*
* @package Smarty
* @subpackage Template
*/
* Class with shared template methodes
*
* @package Smarty
* @subpackage Template
*/
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
/**
* 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 $parent next higher level of Smarty variables
* @param bool $display true: display, false: fetch
* @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
* @return string rendered template output
*/
* 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 $parent next higher level of Smarty variables
* @param bool $display true: display, false: fetch
* @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
* @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)
{
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
*
* @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 $parent next higher level of Smarty variables
*/
* displays a 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 $parent next higher level of Smarty variables
*/
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
// display template
@@ -375,14 +375,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
}
/**
* test if cache is valid
*
* @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 $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @return boolean cache status
*/
* test if cache is valid
*
* @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 $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @return boolean cache status
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
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
*
* @param object $parent next higher level of Smarty variables
* @returns Smarty_Data data object
*/
* creates a data object
*
* @param object $parent next higher level of Smarty variables
* @returns Smarty_Data data object
*/
public function createData($parent = null)
{
return new Smarty_Data($parent, $this);
}
/**
* Registers plugin to be used in templates
*
* @param string $type plugin type
* @param string $tag name of template tag
* @param callback $callback PHP callback to register
* @param boolean $cacheable if true (default) this fuction is cachable
* @param array $cache_attr caching attributes if any
* @throws SmartyException when the plugin tag is invalid
*/
* Registers plugin to be used in templates
*
* @param string $type plugin type
* @param string $tag name of template tag
* @param callback $callback PHP callback to register
* @param boolean $cacheable if true (default) this fuction is cachable
* @param array $cache_attr caching attributes if any
* @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)
{
if (isset($this->smarty->registered_plugins[$type][$tag])) {
@@ -428,78 +429,94 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
} else {
$this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
}
return $this;
}
/**
* Unregister Plugin
*
* @param string $type of plugin
* @param string $tag name of plugin
*/
* Unregister Plugin
*
* @param string $type 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)
{
if (isset($this->smarty->registered_plugins[$type][$tag])) {
unset($this->smarty->registered_plugins[$type][$tag]);
}
return $this;
}
/**
* Registers a resource to fetch a template
*
* @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)
*/
* Registers a resource to fetch a template
*
* @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)
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function registerResource($type, $callback)
{
$this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
return $this;
}
/**
* Unregisters a resource
*
* @param string $type name of resource type
*/
* Unregisters a resource
*
* @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)
{
if (isset($this->smarty->registered_resources[$type])) {
unset($this->smarty->registered_resources[$type]);
}
return $this;
}
/**
* Registers a cache resource to cache a template's output
*
* @param string $type name of cache resource type
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
*/
* Registers a cache resource to cache a template's output
*
* @param string $type name of cache resource type
* @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)
{
$this->smarty->registered_cache_resources[$type] = $callback;
return $this;
}
/**
* Unregisters a cache resource
*
* @param string $type name of cache resource type
*/
* Unregisters a cache resource
*
* @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)
{
if (isset($this->smarty->registered_cache_resources[$type])) {
unset($this->smarty->registered_cache_resources[$type]);
}
return $this;
}
/**
* Registers object to be used in templates
*
* @param string $object name of template object
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
* @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
*/
* Registers object to be used in templates
*
* @param string $object name of template object
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
* @param array $block_functs list of methods that are block format
* @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())
{
// test if allowed methodes callable
@@ -521,15 +538,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
// register the object
$this->smarty->registered_objects[$object_name] =
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
return $this;
}
/**
* return a reference to a registered object
*
* @param string $name object name
* @return object
* @throws SmartyException if no such object is found
*/
* return a reference to a registered object
*
* @param string $name object name
* @return object
* @throws SmartyException if no such object is found
*/
public function getRegisteredObject($name)
{
if (!isset($this->smarty->registered_objects[$name])) {
@@ -542,24 +560,28 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
}
/**
* unregister an object
*
* @param string $name object name
* @throws SmartyException if no such object is found
*/
* unregister an object
*
* @param string $name object name
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unregisterObject($name)
{
unset($this->smarty->registered_objects[$name]);
return;
if (isset($this->smarty->registered_objects[$name])) {
unset($this->smarty->registered_objects[$name]);
}
return $this;
}
/**
* Registers static classes to be used in templates
*
* @param string $class name of template class
* @param string $class_impl the referenced PHP class to register
* @throws SmartyException if $class_impl does not refer to an existing class
*/
* Registers static classes to be used in templates
*
* @param string $class name of template class
* @param string $class_impl the referenced PHP class to register
* @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)
{
// test if exists
@@ -568,14 +590,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
}
// register the class
$this->smarty->registered_classes[$class_name] = $class_impl;
return $this;
}
/**
* Registers a default plugin handler
*
* @param callable $callback class/method name
* @throws SmartyException if $callback is not callable
*/
* Registers a default plugin handler
*
* @param callable $callback class/method name
* @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)
{
if (is_callable($callback)) {
@@ -583,14 +607,17 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
} else {
throw new SmartyException("Default plugin handler '$callback' not callable");
}
return $this;
}
/**
* Registers a default template handler
*
* @param callable $callback class/method name
* @throws SmartyException if $callback is not callable
*/
* Registers a default template handler
*
* @param callable $callback class/method name
* @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)
{
if (is_callable($callback)) {
@@ -598,14 +625,17 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
} else {
throw new SmartyException("Default template handler '$callback' not callable");
}
return $this;
}
/**
* Registers a default template handler
*
* @param callable $callback class/method name
* @throws SmartyException if $callback is not callable
*/
* Registers a default template handler
*
* @param callable $callback class/method name
* @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)
{
if (is_callable($callback)) {
@@ -613,38 +643,46 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
} else {
throw new SmartyException("Default config handler '$callback' not callable");
}
return $this;
}
/**
* Registers a filter function
*
* @param string $type filter type
* @param callback $callback
*/
* Registers a filter function
*
* @param string $type filter type
* @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)
{
$this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
return $this;
}
/**
* Unregisters a filter function
*
* @param string $type filter type
* @param callback $callback
*/
* Unregisters a filter function
*
* @param string $type filter type
* @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)
{
$name = $this->_get_filter_name($callback);
if (isset($this->smarty->registered_filters[$type][$name])) {
unset($this->smarty->registered_filters[$type][$name]);
}
return $this;
}
/**
* Return internal filter name
*
* @param callback $function_name
*/
* Return internal filter name
*
* @param callback $function_name
* @return string internal filter name
*/
public function _get_filter_name($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
*
* @param string $type filter type
* @param string $name filter name
* @return bool
*/
* load a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
* @throws SmartyException if filter could not be loaded
*/
public function loadFilter($type, $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");
return false;
}
/**
* unload a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
* @return bool
*/
* unload a filter of specified type and name
*
* @param string $type filter type
* @param string $name filter name
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function unloadFilter($type, $name)
{
$_filter_name = "smarty_{$type}filter_{$name}";
if (isset($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
*
* @param string $match match string
* @return string replacemant
*/
* preg_replace callback to convert camelcase getter/setter to underscore property names
*
* @param string $match match string
* @return string replacemant
*/
private function replaceCamelcase($match) {
return "_" . strtolower($match[1]);
}
/**
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*/
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*/
public function __call($name, $args)
{
static $_prefixes = array('set' => true, 'get' => true);