From 638519c5a3d67c721613de3d31a9b4bad0d28a49 Mon Sep 17 00:00:00 2001 From: Christian Weber Date: Fri, 13 Jul 2007 12:57:16 +0000 Subject: Move static function it_text_transmogrify into object, call with it_text::transmogrify() --- text.class | 61 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/text.class b/text.class index dffe5de..de5e906 100644 --- a/text.class +++ b/text.class @@ -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); } @@ -217,6 +217,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() -- cgit v1.2.3