summaryrefslogtreecommitdiffstats
path: root/code/subst.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'code/subst.inc.php')
-rw-r--r--code/subst.inc.php47
1 files changed, 14 insertions, 33 deletions
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);