diff options
author | neoraider <devnull@localhost> | 2006-12-14 01:06:02 +0100 |
---|---|---|
committer | neoraider <devnull@localhost> | 2006-12-14 01:06:02 +0100 |
commit | 543336aef16562369c01992817f58e17144c9cad (patch) | |
tree | d49cd8549a836c740df7096ddcf7788ed7920c37 /code | |
parent | 93e1133ee88b03e7cae7318cb19761e698e57b86 (diff) | |
download | neon-543336aef16562369c01992817f58e17144c9cad.tar neon-543336aef16562369c01992817f58e17144c9cad.zip |
Base-Type durch Subst-Erweiterungen unnoetig gemacht; Type-Konzept entfernt.
Diffstat (limited to 'code')
-rw-r--r-- | code/links.inc.php | 2 | ||||
-rw-r--r-- | code/nav.inc.php | 6 | ||||
-rw-r--r-- | code/pages.inc.php | 155 | ||||
-rw-r--r-- | code/subst.inc.php | 39 | ||||
-rw-r--r-- | code/user.inc.php | 2 |
5 files changed, 125 insertions, 79 deletions
diff --git a/code/links.inc.php b/code/links.inc.php index 6c6fcd8..54d1dd9 100644 --- a/code/links.inc.php +++ b/code/links.inc.php @@ -3,7 +3,7 @@ class Links { function GetNeonLink($page, $extra = '', $html = true) { - if($GLOBALS['pages']->HasReadAccess($page, 'c')) { + if($GLOBALS['pages']->HasReadAccess($page)) { if($GLOBALS['user']->login_type == 'url') $ret = 'index.php?page=' . $page . '&login=' . $GLOBALS['user']->login_key . ($extra ? '&' . $extra : ''); diff --git a/code/nav.inc.php b/code/nav.inc.php index 940ced2..7d1e38b 100644 --- a/code/nav.inc.php +++ b/code/nav.inc.php @@ -1,5 +1,5 @@ <?PHP - Uses('links'); + Uses('links', 'user'); class Nav { var $entries = array(); @@ -21,7 +21,9 @@ $this->entries[$entry->parent]->Add(&$this->entries[$key]); } - function ParseNav($gid, $name) { + function ParseNav($name, $gid = NULL) { + if($gid === NULL) $gid = $GLOBALS['user']->getGid(); + $ret = '<ul>'; foreach($this->root_entries[$gid][$name]->children as $entry) diff --git a/code/pages.inc.php b/code/pages.inc.php index 549e24c..8ffe008 100644 --- a/code/pages.inc.php +++ b/code/pages.inc.php @@ -1,99 +1,108 @@ <?PHP - Uses('user', 'templates', 'subst'); + Uses('user', 'templates'); class Pages { var $pages = array(); - function Get($page, $type) { - if(!$this->Exists($page, $type)) + function GetTitle($page) { + if(!$this->Exists($page)) + return $page; + + $pagedata = $this->GetPageData($page); + + $data = $pagedata['data']; + $data['_page'] = $page; + + return $GLOBALS['templates'][$pagedata['template']]->GetTitle($data); + } + + function GetPage($page) { + if(!$this->Exists($page)) return array('title' => $page, - 'content' => Subst('<span class="error">{{The page \'' . $page . '\' does not exist.}}</span>')); + 'content' => '<span class="error">{{The page \'' . $page . '\' does not exist.}}</span>'); - if(!$this->HasReadAccess($page, $type)) + if(!$this->HasReadAccess($page)) return array('title' => $page, - 'content' => Subst('<span class="error">{{The page \'' . $page . '\' is protected.}}</span>')); + 'content' => '<span class="error">{{The page \'' . $page . '\' is protected.}}</span>'); - $pagedata = $this->GetPageData($page, $type); + $pagedata = $this->GetPageData($page); $data = $pagedata['data']; - if($extra) $data = array_merge($data, $extra); $data['_page'] = $page; - $data['_type'] = $type; $ret = $GLOBALS['templates'][$pagedata['template']]->GetPage($data); - return array('title' => Subst($ret['title']), 'content' => Subst($ret['content'])); + return array('title' => $ret['title'], 'content' => $ret['content']); } - function GetEditor($page, $type, $backlink) { - if(!$this->Exists($page, $type)) + function GetEditor($page, $backlink) { + if(!$this->Exists($page)) return array('title' => $page, - 'content' => Subst('<span class="error">{{The page \'' . $page . '\' does not exist.}}</span>')); + 'content' => '<span class="error">{{The page \'' . $page . '\' does not exist.}}</span>'); - if(!$this->HasWriteAccess($page, $type)) + if(!$this->HasWriteAccess($page)) return array('title' => $page, - 'content' => Subst('<span class="error">{{The page \'' . $page . '\' is protected.}}</span>')); + 'content' => '<span class="error">{{The page \'' . $page . '\' is protected.}}</span>'); - $pagedata = $this->GetPageData($page, $type); + $pagedata = $this->GetPageData($page); $data = $pagedata['data']; $data['_page'] = $page; - $data['_type'] = $type; $data['_backlink'] = $backlink; $ret = $GLOBALS['templates'][$pagedata['template']]->GetEditor($data); - return array('title' => Subst($ret['title']), 'content' => Subst($ret['content'])); + return array('title' => $ret['title'], 'content' => $ret['content']); } - function Exists($page, $type) { - if(array_key_exists($page . '.' . $type, $GLOBALS['modules']->pages)) + function Exists($page) { + if(array_key_exists($page, $GLOBALS['modules']->pages)) return true; - $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($page, $type)); + $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ?', $page); return ($res->RecordCount() > 0); } - function HasReadAccess($page, $type) { - if(!$this->Exists($page, $type)) return false; + function HasReadAccess($page) { + if(!$this->Exists($page)) return false; if($GLOBALS['user']->IsAdmin()) return true; $gid = $GLOBALS['user']->gid; - $access = $this->GetAccess($page, $type); + $access = $this->GetAccess($page); return ((hexdec($access[0][$gid/4]) & (1 << ($gid%4))) != 0); } - function HasWriteAccess($page, $type) { - if(!$this->Exists($page, $type)) return false; + function HasWriteAccess($page) { + if(!$this->Exists($page)) return false; if($GLOBALS['user']->IsAdmin()) return true; $gid = $GLOBALS['user']->gid; - $access = $this->GetAccess($page, $type); + $access = $this->GetAccess($page); return ((hexdec($access[1][$gid/4]) & (1 << ($gid%4))) != 0); } - function GetPageData($page, $type) { - if(!$this->Exists($page, $type)) return null; + function GetPageData($page) { + if(!$this->Exists($page)) return null; - if(!array_key_exists($page . '.' . $type, $this->pages)) { - $res = $GLOBALS['db']->Execute('SELECT template, data FROM pages WHERE name = ? AND type = ?', array($page, $type)); + if(!array_key_exists($page, $this->pages)) { + $res = $GLOBALS['db']->Execute('SELECT template, data FROM pages WHERE name = ?', $page); if($res->RecordCount()) { parse_str($res->fields[1], $data); $data = array_map('Unquote', $data); - $this->pages[$page . '.' . $type] = array('name' => $page, 'type' => $type, 'template' => $res->fields[0], + $this->pages[$page] = array('name' => $page, 'template' => $res->fields[0], 'access' => '', 'data' => $data); } else { - $xmldata = $GLOBALS['xmlparser']->ParseFile($GLOBALS['modules']->GetPagePath($page, $type)); + $xmldata = $GLOBALS['xmlparser']->ParseFile($GLOBALS['modules']->GetPagePath($page)); if(!$xmldata) return null; $info = $GLOBALS['xmlparser']->FindTag($xmldata, 'info'); @@ -122,94 +131,94 @@ $data[$field['tag']] = $field['children'][0]; } - $this->pages[$page . '.' . $type] = array('name' => $page, 'type' => $type, 'template' => $template, + $this->pages[$page] = array('name' => $page, 'template' => $template, 'access' => $access, 'data' => $data); } - $res = $GLOBALS['db']->Execute('SELECT readaccess, writeaccess FROM privs WHERE name = ? AND type = ?', array($page, $type)); + $res = $GLOBALS['db']->Execute('SELECT readaccess, writeaccess FROM privs WHERE name = ?', $page); if($res->RecordCount()) - $this->pages[$page . '.' . $type]['access'] = array($res->fields[0], $res->fields[1]); + $this->pages[$page]['access'] = array($res->fields[0], $res->fields[1]); } - return $this->pages[$page . '.' . $type]; + return $this->pages[$page]; } - function Add($name, $type, $template) { - if($this->Exists($name, $type)) return false; + function Add($name, $template) { + if($this->Exists($name)) return false; - $GLOBALS['db']->Execute('INSERT INTO pages (name, template, data, type) VALUES (?, ?, "", ?)', - array($name, $template, $type)); + $GLOBALS['db']->Execute('INSERT INTO pages (name, template, data) VALUES (?, ?, "")', + array($name, $template)); return ($GLOBALS['db']->Affected_Rows() > 0); } - function Edit($page, $type, $data) { + function Edit($page, $data) { $string = ''; foreach($data as $key => $val) $string .= urlencode($key) . '=' . urlencode($val) . '&'; - $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', - array($page, $type)); + $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ?', $page); if($res->RecordCount()) { - $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE name = ? AND type = ?', - array(substr($string, 0, -1), $page, $type)); + $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE name = ?', + array(substr($string, 0, -1), $page)); return true; } - $pagedata = $this->GetPageData($page, $type); + $pagedata = $this->GetPageData($page); - $GLOBALS['db']->Execute('INSERT INTO privs (name, type, readaccess, writeaccess) VALUES (?, ?, ?, ?)', - array($page, $type, $pagedata['access'][0], $pagedata['access'][1])); - $GLOBALS['db']->Execute('INSERT INTO pages (name, template, data, type) VALUES (?, ?, ?, ?)', - array($page, $pagedata['template'], $string, $type)); + $GLOBALS['db']->Execute('INSERT INTO privs (name, readaccess, writeaccess) VALUES (?, ?, ?)', + array($page, $pagedata['access'][0], $pagedata['access'][1])); + $GLOBALS['db']->Execute('INSERT INTO pages (name, template, data) VALUES (?, ?, ?)', + array($page, $pagedata['template'], $string)); return ($GLOBALS['db']->Affected_Rows() > 0); } - function Rename($page, $type, $new_name) { - if($this->Exists($new_name, $type)) return false; + function Rename($page, $new_name) { + if($this->Exists($new_name)) return false; + if(!$this->Exists($page)) return false; - $GLOBALS['db']->Execute('UPDATE privs SET name = ? WHERE name = ? AND type = ?', array($new_name, $page, $type)); - $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE name = ? AND type = ?', array($new_name, $page, $type)); + $GLOBALS['db']->Execute('UPDATE privs SET name = ? WHERE name = ?', array($new_name, $page)); + $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE name = ?', array($new_name, $page)); return ($GLOBALS['db']->Affected_Rows() > 0); } - function Copy($page, $type, $new_name) { - if($this->Exists($new_name, $type)) return false; - if(!$this->Exists($page, $type)) return false; + function Copy($page, $new_name) { + if($this->Exists($new_name)) return false; + if(!$this->Exists($page)) return false; - $pagedata = $this->GetPageData($page, $type); + $pagedata = $this->GetPageData($page); $string = ''; foreach($pagedata['data'] as $key => $val) $string .= urlencode($key) . '=' . urlencode($val) . '&'; - $GLOBALS['db']->Execute('INSERT INTO pages (name, template, data, type) VALUES (?, ?, ?, ?)', - array($new_name, $pagedata['template'], $string, $type)); + $GLOBALS['db']->Execute('INSERT INTO pages (name, template, data) VALUES (?, ?, ?)', + array($new_name, $pagedata['template'], $string)); return ($GLOBALS['db']->Affected_Rows() > 0); } - function Delete($page, $type) { - $GLOBALS['db']->Execute('DELETE FROM privs WHERE name = ? AND type = ?', array($page, $type)); - $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ? AND type = ?', array($page, $type)); + function Delete($page) { + $GLOBALS['db']->Execute('DELETE FROM privs WHERE name = ?', $page); + $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ?', $page); return ($GLOBALS['db']->Affected_Rows() > 0); } function GetList() { - $res = $GLOBALS['db']->Execute('SELECT name, type FROM pages'); + $res = $GLOBALS['db']->Execute('SELECT name FROM pages'); $pages = array(); while($row = $res->FetchRow()) - $pages[$row[0] . '.' . $row[1]] = null; + $pages[$row[0]] = null; $pages = array_keys(array_merge($pages, $this->pages, $GLOBALS['modules']->pages)); @@ -218,27 +227,27 @@ return $pages; } - function GetAccess($page, $type) { - $res = $GLOBALS['db']->Execute('SELECT readaccess, writeaccess FROM privs WHERE name = ? AND type = ?', array($page, $type)); + function GetAccess($page) { + $res = $GLOBALS['db']->Execute('SELECT readaccess, writeaccess FROM privs WHERE name = ?', $page); if($res->RecordCount()) return array($res->fields[0], $res->fields[1]); - $pagedata = $this->GetPageData($page, $type); + $pagedata = $this->GetPageData($page); return $pagedata['access']; } - function SetAccess($page, $type, $access) { - $res = $GLOBALS['db']->Execute('SELECT id FROM privs WHERE name = ? AND type = ?', array($page, $type)); + function SetAccess($page, $access) { + $res = $GLOBALS['db']->Execute('SELECT id FROM privs WHERE name = ?', $page); if($res->RecordCount()) { - $GLOBALS['db']->Execute('UPDATE privs SET readaccess = ?, writeaccess = ? WHERE name = ? AND type = ?', array($access[0], $access[1], $page, $type)); + $GLOBALS['db']->Execute('UPDATE privs SET readaccess = ?, writeaccess = ? WHERE name = ?', array($access[0], $access[1], $page)); return ($GLOBALS['db']->Affected_Rows() > 0); } - $GLOBALS['db']->Execute('INSERT INTO privs (name, type, readaccess, writeaccess) VALUES (?, ?, ?, ?)', array($page, $type, $access[0], $access[1])); + $GLOBALS['db']->Execute('INSERT INTO privs (name, readaccess, writeaccess) VALUES (?, ?, ?)', array($page, $access[0], $access[1])); return ($GLOBALS['db']->Affected_Rows() > 0); } 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); } ?> diff --git a/code/user.inc.php b/code/user.inc.php index cc04268..bbcf4ed 100644 --- a/code/user.inc.php +++ b/code/user.inc.php @@ -15,7 +15,7 @@ $this->gid = $res->fields[1]; $this->name = $res->fields[3]; - $this->type = 'cookie'; + $this->login_type = 'cookie'; $this->login_key = $_COOKIE['login']; } } |