diff options
author | friendica <info@friendica.com> | 2012-05-12 17:57:41 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-07-18 20:40:31 +1000 |
commit | 7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a (patch) | |
tree | a9c3d91209cff770bb4b613b1b95e61a7bbc5a2b /lib/smarty/libs/plugins/shared.literal_compiler_param.php | |
parent | cd727cb26b78a1dade09d510b071446898477356 (diff) | |
download | volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.tar.gz volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.tar.bz2 volse-hubzilla-7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a.zip |
some important stuff we'll need
Diffstat (limited to 'lib/smarty/libs/plugins/shared.literal_compiler_param.php')
-rw-r--r-- | lib/smarty/libs/plugins/shared.literal_compiler_param.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/smarty/libs/plugins/shared.literal_compiler_param.php b/lib/smarty/libs/plugins/shared.literal_compiler_param.php new file mode 100644 index 000000000..dbcd9374c --- /dev/null +++ b/lib/smarty/libs/plugins/shared.literal_compiler_param.php @@ -0,0 +1,33 @@ +<?php +/** + * Smarty plugin + * + * @package Smarty + * @subpackage PluginsShared + */ + +/** + * evaluate compiler parameter + * + * @param array $params parameter array as given to the compiler function + * @param integer $index array index of the parameter to convert + * @param mixed $default value to be returned if the parameter is not present + * @return mixed evaluated value of parameter or $default + * @throws SmartyException if parameter is not a literal (but an expression, variable, …) + * @author Rodney Rehm + */ +function smarty_literal_compiler_param($params, $index, $default=null) +{ + // not set, go default + if (!isset($params[$index])) { + return $default; + } + // test if param is a literal + if (!preg_match('/^([\'"]?)[a-zA-Z0-9]+(\\1)$/', $params[$index])) { + throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time'); + } + + $t = null; + eval("\$t = " . $params[$index] . ";"); + return $t; +} |