From 13644bec358f3e51a085337c75aaaa2b9704bfbe Mon Sep 17 00:00:00 2001 From: neoraider Date: Sun, 5 Mar 2006 17:38:05 +0000 Subject: Seiten-Verwaltung intern ueberarbeitet. --- code/links.inc.php | 2 +- code/pages.inc.php | 128 ++++++++++++++++++++++++++++++++++++++++++----------- code/user.inc.php | 24 ++-------- 3 files changed, 106 insertions(+), 48 deletions(-) (limited to 'code') diff --git a/code/links.inc.php b/code/links.inc.php index 9fbaae3..5c48f54 100644 --- a/code/links.inc.php +++ b/code/links.inc.php @@ -4,7 +4,7 @@ class Links { function GetNeonLink($page, $extra = '', $html = true) { if($GLOBALS['pages']->HasAccess($page, 'c')) { - if($GLOBALS['user']->GetLoginType() == 'url') + if($GLOBALS['user']->login_type == 'url') $ret = 'index.php?page=' . $page . '&login=' . $GLOBALS['user']->GetLoginKey() . ($extra ? '&' . $extra : ''); diff --git a/code/pages.inc.php b/code/pages.inc.php index 09cd525..d57bb17 100644 --- a/code/pages.inc.php +++ b/code/pages.inc.php @@ -4,58 +4,132 @@ require_once('code/handlers.inc.php'); class Pages { - function Get($name, $type, $extra = null) { - if(!$this->Exists($name, $type)) - return array('title' => $name, - 'content' => ErrorMessage('PageNotFound', array('page' => $name))); + function Get($page, $type = null, $extra = null) { + if(!$this->Exists($page, $type)) + return array('title' => $page, + 'content' => ErrorMessage('PageNotFound', array('page' => $page))); - $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type)); + if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE name = ? AND type = ?', array($page, $type)); + else $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE id = ?', $page); - if(!$this->HasAccess($name, $type)) - return array('title' => $name, - 'content' => ErrorMessage('Forbidden', array('page' => $name))); + if(!$this->HasAccess($page, $type)) + return array('title' => $res->fields[1], + 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1]))); - parse_str($res->fields[2], $data); + parse_str($res->fields[4], $data); $data = array_map('Unquote', $data); if($extra) $data = array_merge($data, $extra); $data['_id'] = $res->fields[0]; - $data['_page'] = $name; + $data['_page'] = $res->fields[1]; + $data['_type'] = $res->fields[2]; - return $GLOBALS['handlers'][$res->fields[1]]->Get($data); + return $GLOBALS['handlers'][$res->fields[3]]->Get($data); } - function Edit($name, $type) { - if(!$this->Exists($name, $type)) - return array('title' => $name, - 'content' => ErrorMessage('PageNotFound', array('page' => $name))); + function GetEditor($page, $type = null) { + if(!$this->Exists($page, $type)) + return array('title' => $page, + 'content' => ErrorMessage('PageNotFound', array('page' => $page))); - $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type)); + if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE name = ? AND type = ?', array($page, $type)); + else $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE id = ?', $page); if(!$GLOBALS['user']->IsAdmin()) - return array('title' => $name, - 'content' => ErrorMessage('Forbidden', array('page' => $name))); + return array('title' => $res->fields[1], + 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1]))); - parse_str($res->fields[2], $data = null); + parse_str($res->fields[4], $data = null); $data = array_map('Unquote', $data); $data['_id'] = $res->fields[0]; - $data['_page'] = $name; - $data['_type'] = $type; + $data['_page'] = $res->fields[1]; + $data['_type'] = $res->fields[2]; - return $this->Get($res->fields[1], 'e', array('_data' => $data)); + return $this->Get($res->fields[3], 'e', array('_data' => $data)); } - function Exists($name, $type) { - $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type)); + function GetName($id) { + $res = $GLOBALS['db']->Execute('SELECT name FROM pages WHERE id = ?', $id); + + return $res->fields[0]; + } + + function GetType($id) { + $res = $GLOBALS['db']->Execute('SELECT type FROM pages WHERE id = ?', $id); + + return $res->fields[0]; + } + + function Exists($page, $type = null) { + if($type) $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($page, $type)); + else $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE id = ?', $page); return ($res->RecordCount() > 0); } - function HasAccess($name, $type) { - $gid = $GLOBALS['user']->GetGid(); - $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type)); + function HasAccess($page, $type = null) { + $gid = $GLOBALS['user']->gid; + if($type) $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($page, $type)); + else $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE id = ?', $page); return ($GLOBALS['user']->IsAdmin() || (ord($res->fields[0][$gid/8]) & (1 << ($gid%8))) != 0); } + + function Add($name, $handler, $type) { + if($this->Exists($name, $type)) return 0; + + $GLOBALS['db']->Execute('INSERT INTO pages (name, handler, access, data, type) VALUES (?, ?, 0, "", ?)', + array($name, $handler, $type)); + + return $GLOBALS['db']->Insert_ID(); + } + + function Edit($page, $data, $type = null) { + $string = ''; + + foreach($data as $key => $val) + $string .= urlencode($key) . '=' . urlencode($val) . '&'; + + if($type) $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE name = ? AND type = ?', + array(substr($string, 0, -1), $page, $type)); + else $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE id = ?', + array(substr($string, 0, -1), $page)); + } + + function Rename($page, $new_name, $type = null) { + if($type) { + if($this->Exists($new_name, $type)) return; + + $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE name = ? AND type = ?', array($new_name, $page, $type)); + } + else { + if($this->Exists($new_name, $this->GetType($type))) return; + + $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE id = ?', array($new_name, $page)); + } + } + + function Copy($page, $new_name, $type = null) { + if($type) { + if($this->Exists($new_name, $type)) return; + + $res = $GLOBALS['db']->Execute('SELECT * FROM pages WHERE name = ? AND type = ?', array($page, $type)); + } + else { + if($this->Exists($new_name, $this->GetType($type))) return; + + $res = $GLOBALS['db']->Execute('SELECT handler, data, type FROM pages WHERE id = ?', $page); + } + + $GLOBALS['db']->Execute('INSERT INTO pages (name, handler, access, data, type) VALUES (?, ?, 0, ?, ?)', + array($new_name, $res->fields[0], $res->fields[1], $res->fields[2])); + + return $GLOBALS['db']->Insert_ID(); + } + + function Delete($page, $type = null) { + if($type) $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ? AND type = ?', array($page, $type)); + else $GLOBALS['db']->Execute('DELETE FROM pages WHERE id = ?', $page); + } } $GLOBALS['pages'] = new Pages; diff --git a/code/user.inc.php b/code/user.inc.php index 5aa76d5..373c5e8 100644 --- a/code/user.inc.php +++ b/code/user.inc.php @@ -3,7 +3,7 @@ class User { var $uid = 0, $gid = 0; - var $key = '', $type = ''; + var $key = '', $login_type = ''; function User() { if($_COOKIE['login']) { @@ -29,7 +29,7 @@ $this->uid = $res->fields[0]; $this->gid = $res->fields[1]; - $this->type = 'url'; + $this->login_type = 'url'; $this->key = $_GET['login']; } } @@ -47,7 +47,7 @@ $this->uid = $id; $this->gid = $res->fields[1]; - $this->type = 'url'; + $this->login_type = 'url'; $this->key = $sid . $id; setcookie('login', $this->key); @@ -64,7 +64,7 @@ $this->uid = 0; $this->gid = 0; - $this->type = ''; + $this->login_type = ''; $this->key = ''; setcookie('login'); @@ -73,22 +73,6 @@ function IsAdmin() { return ($this->uid != 0 && $this->gid == 0); } - - function GetUid() { - return $this->uid; - } - - function GetGid() { - return $this->gid; - } - - function GetLoginType() { - return $this->type; - } - - function GetLoginKey() { - return $this->key; - } } $GLOBALS['user'] = new User; -- cgit v1.2.3