diff options
author | Urban Müller | 2011-09-14 13:25:45 +0000 |
---|---|---|
committer | Urban Müller | 2011-09-14 13:25:45 +0000 |
commit | eeb26db00c41f8aae3c96404a898cd2ae4a317ee (patch) | |
tree | a780a5dabb491040a3fa925b67262d067f21f4d4 /it_text.class | |
parent | e004b6c4f1267f80f1d920fe937eba8a50fda303 (diff) | |
download | itools-eeb26db00c41f8aae3c96404a898cd2ae4a317ee.tar.gz itools-eeb26db00c41f8aae3c96404a898cd2ae4a317ee.tar.bz2 itools-eeb26db00c41f8aae3c96404a898cd2ae4a317ee.zip |
fix endless loop, improve performance
Diffstat (limited to 'it_text.class')
-rw-r--r-- | it_text.class | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/it_text.class b/it_text.class index b986e97..3264169 100644 --- a/it_text.class +++ b/it_text.class @@ -218,30 +218,30 @@ function set($label, $text = null, $language = null) */ function transmogrify($text, $values = null) { - while (preg_match('/{([\w.]+)}/', $text, $regs)) + foreach (preg_split('/{([\w.]+)}/', $text, -1, PREG_SPLIT_DELIM_CAPTURE) as $idx => $part) { - $path = explode('.', $regs[1]); - if ($values) - $value =& $values; + if ($idx % 2 == 0) # even offsets are between delimiters + $result .= $part; else - $value =& $GLOBALS; - - # Recurse into nested arrays/object members - foreach ($path as $key) { - if (is_object($value)) - $value =& $value->$key; - else - $value =& $value[$key]; + $value = $values ? $values : $GLOBALS; + foreach (explode(".", $part) as $key) + { + if (is_object($value)) + $value =& $value->$key; + else + $value =& $value[$key]; + } + + $result .= $value; } - - $text = str_replace($regs[0], $value, $text); } - return $text; + return $result; } + /** * Re-create php text file from $this->statictext * @return true if successful, false if not (usually if file is not writeable by user www) |