From 60599b407610796c65bbbafc88a8fe5b29f37c7a Mon Sep 17 00:00:00 2001 From: neoraider Date: Sat, 16 Dec 2006 21:35:01 +0000 Subject: Subst() optimiert. --- code/subst.inc.php | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'code/subst.inc.php') diff --git a/code/subst.inc.php b/code/subst.inc.php index fc999ff..16d1220 100644 --- a/code/subst.inc.php +++ b/code/subst.inc.php @@ -6,41 +6,22 @@ if($GLOBALS['config']['language'] != 'en') @include('lang/' . $GLOBALS['config']['language'] . '.inc.php'); - function Subst($data, $env = array()) { - $subst = array_map(create_function('$key', 'return \'(\\{\\{\' . $key . \'\\}\\})\';'), array_keys($GLOBALS['messages'])); + function subst_page($data, $env) { + $data = preg_replace('((^|[^\\{])\\{\\{\\$config:([^\\{\\}]+?)\\}\\})e', '\'$1\' . $GLOBALS[\'config\'][\'$2\']', $data); + $data = preg_replace('((^|[^\\{])\\{\\{\\$([^:\\{\\}]+?)\\}\\})e', '\'$1\' . $env[\'$2\']', $data); - while(preg_match('((?:^|[^\\{])\\{\\{\\$(?:config|nav|page|title):.+?\\}\\})', $data)) { - while(preg_match('((?:^|[^\\{])\\{\\{\\$nav:.+?\\}\\})', $data)) { - $data = preg_replace('((^|[^\\{])\\{\\{\\$config:([^\\{\\}]+?)\\}\\})e', '\'$1\' . $GLOBALS[\'config\'][\'$2\']', $data); - $data = preg_replace('((^|[^\\{])\\{\\{\\$([^:\\{\\}]+?)\\}\\})e', '\'$1\' . $env[\'$2\']', $data); - - $data = preg_replace('((^|[^\\{])\\{\\{\\$nav:(.+?)\\}\\})e', '\'$1\' . $GLOBALS[\'nav\']->ParseNav(\'$2\')', $data); - } - - while(preg_match('((?:^|[^\\{])\\{\\{\\$title:.+?\\}\\})', $data)) { - $data = preg_replace('((^|[^\\{])\\{\\{\\$config:([^\\{\\}]+?)\\}\\})e', '\'$1\' . $GLOBALS[\'config\'][\'$2\']', $data); - $data = preg_replace('((^|[^\\{])\\{\\{\\$([^:\\{\\}]+?)\\}\\})e', '\'$1\' . $env[\'$2\']', $data); - - $data = preg_replace('((^|[^\\{])\\{\\{\\$title:(.+?)\\}\\})e', '\'$1\' . $GLOBALS[\'pages\']->GetTitle(\'$2\')', $data); - } - - while(preg_match('((?:^|[^\\{])\\{\\{\\$page:\\$editor:.+?\\}\\})', $data)) { - $data = preg_replace('((^|[^\\{])\\{\\{\\$config:([^\\{\\}]+?)\\}\\})e', '\'$1\' . $GLOBALS[\'config\'][\'$2\']', $data); - $data = preg_replace('((^|[^\\{])\\{\\{\\$([^:\\{\\}]+?)\\}\\})e', '\'$1\' . $env[\'$2\']', $data); - - $data = preg_replace_callback('((^|[^\\{])\\{\\{\\$page:\\$editor:(.+?)\\}\\})', create_function('$match', '$ret = $GLOBALS[\'pages\']->GetEditor($match[2], $GLOBALS[\'links\']->GetNeonLink($match[2])); return $match[1] . $ret[\'content\'];'), $data); - } - - while(preg_match('((?:^|[^\\{])\\{\\{\\$page:.+?\\}\\})', $data)) { - $data = preg_replace('((^|[^\\{])\\{\\{\\$config:([^\\{\\}]+?)\\}\\})e', '\'$1\' . $GLOBALS[\'config\'][\'$2\']', $data); - $data = preg_replace('((^|[^\\{])\\{\\{\\$([^:\\{\\}]+?)\\}\\})e', '\'$1\' . $env[\'$2\']', $data); - - $data = preg_replace_callback('((^|[^\\{])\\{\\{\\$page:(.+?)\\}\\})', create_function('$match', '$ret = $GLOBALS[\'pages\']->GetPage($match[2]); return $match[1] . $ret[\'content\'];'), $data); - } - - $data = preg_replace('((^|[^\\{])\\{\\{\\$config:(.+?)\\}\\})e', '\'$1\' . $GLOBALS[\'config\'][\'$2\']', $data); - } + $data = preg_replace('((^|[^\\{])\\{\\{\\$nav:(.+?)\\}\\})e', '\'$1\' . subst_page($GLOBALS[\'nav\']->ParseNav(\'$2\'), $env)', $data); + $data = preg_replace('((^|[^\\{])\\{\\{\\$title:(.+?)\\}\\})e', '\'$1\' . $GLOBALS[\'pages\']->GetTitle(\'$2\')', $data); + $data = preg_replace_callback('((^|[^\\{])\\{\\{\\$page:\\$editor:(.+?)\\}\\})', create_function('$match', '$ret = $GLOBALS[\'pages\']->GetEditor($match[2], $GLOBALS[\'links\']->GetNeonLink($match[2])); return $match[1] . subst_page($ret[\'content\'], $page);'), $data); + $data = preg_replace_callback('((^|[^\\{])\\{\\{\\$page:(.+?)\\}\\})', create_function('$match', '$ret = $GLOBALS[\'pages\']->GetPage($match[2]); return $match[1] . subst_page($ret[\'content\'], $env);'), $data); + return $data; + } + + function Subst($data, $env = array()) { + $data = subst_page($data, $env); + + $subst = array_map(create_function('$key', 'return \'(\\{\\{\' . $key . \'\\}\\})\';'), array_keys($GLOBALS['messages'])); $data = preg_replace($subst, $GLOBALS['messages'], $data); return preg_replace(array('((^|[^\\{])\\{\\{([^\\{]|$))', '((^|[^\\}])\\}\\}([^\\}]|$))', '((\\{)\\{(\\{))', '((\\})\\}(\\}))'), '$1$2', $data); -- cgit v1.2.3