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.php39
1 files changed, 37 insertions, 2 deletions
diff --git a/code/subst.inc.php b/code/subst.inc.php
index 9696ec9..fc999ff 100644
--- a/code/subst.inc.php
+++ b/code/subst.inc.php
@@ -1,13 +1,48 @@
<?PHP
+ Uses('pages', 'nav');
+
+
$GLOBALS['messages'] = array();
if($GLOBALS['config']['language'] != 'en') @include('lang/' . $GLOBALS['config']['language'] . '.inc.php');
- function Subst($data) {
+ function Subst($data, $env = array()) {
$subst = array_map(create_function('$key', 'return \'(\\{\\{\' . $key . \'\\}\\})\';'), array_keys($GLOBALS['messages']));
+ 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($subst, $GLOBALS['messages'], $data);
- return preg_replace('({{(.+?)}})', '$1', $data);
+ return preg_replace(array('((^|[^\\{])\\{\\{([^\\{]|$))', '((^|[^\\}])\\}\\}([^\\}]|$))', '((\\{)\\{(\\{))', '((\\})\\}(\\}))'), '$1$2', $data);
}
?>