diff options
Diffstat (limited to 'text.class')
-rw-r--r-- | text.class | 61 |
1 files changed, 31 insertions, 30 deletions
@@ -142,7 +142,7 @@ function text($label, $raw = null, $language = null) */ function etext($label, $values = null, $language = null) { - return it_text_transmogrify($this->text($label, null, $language), $values); + return $this->transmogrify($this->text($label, null, $language), $values); } @@ -218,6 +218,36 @@ function set($label, $text = null, $language = null) /** + * Replaces variables of the form {obj.var} with value, e.g. {user.name} + * NOTE: Invalid object names or non-existing variables are simply deleted. + */ +function transmogrify($text, $values = null) +{ + while (preg_match('/{([\w.]+)}/', $text, $regs)) + { + $path = explode('.', $regs[1]); + if ($values) + $value =& $values; + else + $value =& $GLOBALS; + + # Recurse into nested arrays/object members + foreach ($path as $key) + { + if (is_object($value)) + $value =& $value->$key; + else + $value =& $value[$key]; + } + + $text = str_replace($regs[0], $value, $text); + } + + return $text; +} + + +/** * when running it_text in debug mode, you can use this to die (internal_error) * in case there were unknown labels with a list of all unknown labels */ @@ -337,35 +367,6 @@ function dump_php() * Globally available functions without need for object */ -/** - * Replaces variables of the form {obj.var} with value, e.g. {user.name} - * NOTE: Invalid object names or non-existing variables are simply deleted. - */ -function it_text_transmogrify($text, $values = null) -{ - while (preg_match('/{([\w.]+)}/', $text, $regs)) - { - $path = explode('.', $regs[1]); - if ($values) - $value =& $values; - else - $value =& $GLOBALS; - - /* Recurse into nested arrays/object members */ - foreach ($path as $key) - { - if (is_object($value)) - $value =& $value->$key; - else - $value =& $value[$key]; - } - - $text = str_replace($regs[0], $value, $text); - } - - return $text; -} - /* * Shortcut to $it_text->Text() |