From 543336aef16562369c01992817f58e17144c9cad Mon Sep 17 00:00:00 2001 From: neoraider Date: Thu, 14 Dec 2006 00:06:02 +0000 Subject: Base-Type durch Subst-Erweiterungen unnoetig gemacht; Type-Konzept entfernt. --- code/pages.inc.php | 155 ++++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 73 deletions(-) (limited to 'code/pages.inc.php') 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 @@ 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('{{The page \'' . $page . '\' does not exist.}}')); + 'content' => '{{The page \'' . $page . '\' does not exist.}}'); - if(!$this->HasReadAccess($page, $type)) + if(!$this->HasReadAccess($page)) return array('title' => $page, - 'content' => Subst('{{The page \'' . $page . '\' is protected.}}')); + 'content' => '{{The page \'' . $page . '\' is protected.}}'); - $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('{{The page \'' . $page . '\' does not exist.}}')); + 'content' => '{{The page \'' . $page . '\' does not exist.}}'); - if(!$this->HasWriteAccess($page, $type)) + if(!$this->HasWriteAccess($page)) return array('title' => $page, - 'content' => Subst('{{The page \'' . $page . '\' is protected.}}')); + 'content' => '{{The page \'' . $page . '\' is protected.}}'); - $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); } -- cgit v1.2.3