diff options
author | neoraider <devnull@localhost> | 2006-12-16 22:35:01 +0100 |
---|---|---|
committer | neoraider <devnull@localhost> | 2006-12-16 22:35:01 +0100 |
commit | 60599b407610796c65bbbafc88a8fe5b29f37c7a (patch) | |
tree | 81ec2498f79f5ee89038cec575d954f0ca31dbbc | |
parent | 543336aef16562369c01992817f58e17144c9cad (diff) | |
download | neon-60599b407610796c65bbbafc88a8fe5b29f37c7a.tar neon-60599b407610796c65bbbafc88a8fe5b29f37c7a.zip |
-rw-r--r-- | code/subst.inc.php | 47 | ||||
-rw-r--r-- | config/SQL/base.sql | 1 | ||||
-rw-r--r-- | index.php | 16 |
3 files changed, 25 insertions, 39 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); diff --git a/config/SQL/base.sql b/config/SQL/base.sql index 3d970d4..d380f35 100644 --- a/config/SQL/base.sql +++ b/config/SQL/base.sql @@ -13,7 +13,6 @@ CREATE TABLE `base` ( -- INSERT INTO `base` (`id`, `code`) VALUES (1, '<div id="nav">{{$nav:default}}</div>'); -INSERT INTO `base` (`id`, `code`) VALUES (0, '</head><body>'); INSERT INTO `base` (`id`, `code`) VALUES (-2, '<title>{{$config:title}}{{$title:{{$current_page}}}}</title>'); INSERT INTO `base` (`id`, `code`) VALUES (-1, '<link rel="stylesheet" type="text/css" href="styles/{{$config:default_style}}/style.css" />'); INSERT INTO `base` (`id`, `code`) VALUES (3, '<div id="content">'); @@ -11,19 +11,25 @@ if($_GET['page']) $page = Unquote($_GET['page']); else $page = $GLOBALS['config']['home']; - $res = $GLOBALS['db']->Execute('SELECT code FROM base ORDER BY id'); + $res = $GLOBALS['db']->Execute('SELECT id, code FROM base ORDER BY id'); - $base = ''; + $env = array('current_page' => $page); + if($_GET['mode'] == 'edit') $env['current_page'] = '$editor:' . $page; + + $content = ''; + $body = false; while(!$res->EOF) { - $base .= $res->fields[0]; + if($body == false && $res->fields[0] > 0) { + $body = true; + $content .= '</head><body>'; + } + $content .= Subst($res->fields[1], $env); $res->MoveNext(); } $env = array('current_page' => $page); if($_GET['mode'] == 'edit') $env['current_page'] = '$editor:' . $page; - $content = Subst($base, $env); - echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?> |