From d8edab617c02409178e82a59ce704d7da5de6d9a Mon Sep 17 00:00:00 2001 From: neoraider Date: Sun, 5 Mar 2006 00:01:01 +0000 Subject: Anstatt der defined-Abfragen wird jetzt require_once benutzt. --- code/db.inc.php | 20 +++---- code/handlers.inc.php | 18 +++--- code/links.inc.php | 104 ++++++++++++++++---------------- code/message.inc.php | 40 ++++++------- code/nav.inc.php | 160 ++++++++++++++++++++++++-------------------------- code/pages.inc.php | 108 ++++++++++++++++------------------ code/user.inc.php | 142 ++++++++++++++++++++++---------------------- code/util.inc.php | 40 ++++++------- 8 files changed, 300 insertions(+), 332 deletions(-) (limited to 'code') diff --git a/code/db.inc.php b/code/db.inc.php index d5d2107..57547cd 100644 --- a/code/db.inc.php +++ b/code/db.inc.php @@ -1,14 +1,10 @@ PConnect($config['server'], $config['user'], - $config['password'], $config['db']); - } + require_once('config/config.inc.php'); + + require_once('adodb/adodb.inc.php'); + + + $GLOBALS['db'] = &ADONewConnection($config['driver']); + $GLOBALS['db']->PConnect($config['server'], $config['user'], + $config['password'], $config['db']); ?> diff --git a/code/handlers.inc.php b/code/handlers.inc.php index 018402e..5410de0 100644 --- a/code/handlers.inc.php +++ b/code/handlers.inc.php @@ -1,13 +1,9 @@ diff --git a/code/links.inc.php b/code/links.inc.php index c207945..e118160 100644 --- a/code/links.inc.php +++ b/code/links.inc.php @@ -1,64 +1,60 @@ HasAccess($page, 'c')) { - if($GLOBALS['user']->GetLoginType() == 'url') - return 'index.php?page=' . $page . '&login=' . $GLOBALS['user']->GetLoginKey(); + require_once('code/user.inc.php'); + + class Links { + function GetNeonLink($page) { + if($GLOBALS['pages']->HasAccess($page, 'c')) { + if($GLOBALS['user']->GetLoginType() == 'url') + return 'index.php?page=' . $page . '&login=' . $GLOBALS['user']->GetLoginKey(); - return 'index.php?page=' . $page; - } - - return ''; + return 'index.php?page=' . $page; } - - function GetExternalLink($link) { - return $link; - } - - function GetMailtoLink($address) { - return 'mailto:' . $address; - } - - function GetNavPage($page) { - if($GLOBALS['pages']->HasAccess($page, 'n')) { - $page = $GLOBALS['pages']->Get($page, 'n'); - return $page['content']; - } - return ''; + return ''; + } + + function GetExternalLink($link) { + return $link; + } + + function GetMailtoLink($address) { + return 'mailto:' . $address; + } + + function GetNavPage($page) { + if($GLOBALS['pages']->HasAccess($page, 'n')) { + $page = $GLOBALS['pages']->Get($page, 'n'); + return $page['content']; } - function ParseNavLink($text, $link) { - if(!$link) return $text; - - switch($link[0]) { - case ':': - $ret = $this->GetNeonLink(substr($link, 1)); - - if($ret) - return '' . $text . ''; - - return $text; - case '@': - return '' . $text . ''; - case '!': - $ret = $this->GetNavPage(substr($link, 1)); - - if($ret) - return $ret; - - return $text; - default: - return '' . $text . ''; - } - } + return ''; } - $links = new Links; + function ParseNavLink($text, $link) { + if(!$link) return $text; + + switch($link[0]) { + case ':': + $ret = $this->GetNeonLink(substr($link, 1)); + + if($ret) + return '' . $text . ''; + + return $text; + case '@': + return '' . $text . ''; + case '!': + $ret = $this->GetNavPage(substr($link, 1)); + + if($ret) + return $ret; + + return $text; + default: + return '' . $text . ''; + } + } } + + $GLOBALS['links'] = new Links; ?> diff --git a/code/message.inc.php b/code/message.inc.php index c351e70..8ac8a0e 100644 --- a/code/message.inc.php +++ b/code/message.inc.php @@ -1,25 +1,21 @@ ' . Subst($GLOBALS['message'][$type], $data) . ''; - } + require_once('config/config.inc.php'); + + require_once('code/util.inc.php'); + + $message['Error'] = 'Error'; + $message['PageNotFound'] = 'The page \'$page\' does not exist.'; + $message['Forbidden'] = 'The page \'$page\' is protected.'; + $message['InternalError'] = 'An internal error has occourred.'; + $message['LoginError'] = 'Login failed. Username or password is wrong.'; + + if($config['language'] != 'en') @include('lang/' . $config['language'] . '.inc.php'); + + function Message($type, $data = array()) { + return Subst($GLOBALS['message'][$type], $data); + } + + function ErrorMessage($type, $data = array()) { + return '' . Subst($GLOBALS['message'][$type], $data) . ''; } ?> diff --git a/code/nav.inc.php b/code/nav.inc.php index 642efe0..0a28cba 100644 --- a/code/nav.inc.php +++ b/code/nav.inc.php @@ -1,100 +1,96 @@ Execute('SELECT * FROM nav ORDER BY id'); - function Nav() { - $res = $GLOBALS['db']->Execute('SELECT * FROM nav ORDER BY id'); - - while(!$res->EOF) { - $this->entries[$res->fields[0]] = new NavEntry($res->fields[1], $res->fields[2], $res->fields[3]); - - $res->MoveNext(); - } - - foreach($this->entries as $entry) - if($entry->GetParentId() != 0) - $this->entries[$entry->GetParentId()]->Add($entry); + while(!$res->EOF) { + $this->entries[$res->fields[0]] = new NavEntry($res->fields[1], $res->fields[2], $res->fields[3]); + + $res->MoveNext(); } - function ParseEntries() { - $ret = ''; - - return $ret; - } + foreach($this->entries as $entry) + if($entry->GetParentId() != 0) + $this->entries[$entry->GetParentId()]->Add($entry); } - class NavEntry { - var $parent, $text, $link; - var $children = array(); + function ParseEntries() { + $ret = ''; - function GetChildren() { - return $this->children; - } + return $ret; + } + } + + class NavEntry { + var $parent, $text, $link; + var $children = array(); + + function NavEntry($parent, $text, $link) { + $this->parent = $parent; + $this->text = $text; + $this->link = $link; + } + + function Add($entry) { + array_push($this->children, $entry); + } + + function GetChildren() { + return $this->children; + } + + function GetParentId() { + return $this->parent; + } + + function GetText() { + return $this->text; + } + + function GetLink() { + return $this->link; + } + + function Parse() { + $ccount = 0; + $ret = '
  • '; - function GetParentId() { - return $this->parent; - } + $a = $GLOBALS['links']->ParseNavLink($this->text, $this->link); - function GetText() { - return $this->text; - } + $ret .= $a; - function GetLink() { - return $this->link; + if(count($this->children) > 0) { + $ret .= ''; } - function Parse() { - $ccount = 0; - $ret = '
  • '; - - $a = $GLOBALS['links']->ParseNavLink($this->text, $this->link); - - $ret .= $a; - - if(count($this->children) > 0) { - $ret .= ''; - } - - if(!$ccount && $a == $this->text) - return ''; - - return $ret . '
  • '; - } + if(!$ccount && $a == $this->text) + return ''; + + return $ret . ''; } - - $nav = new Nav; } + + $GLOBALS['nav'] = new Nav; ?> diff --git a/code/pages.inc.php b/code/pages.inc.php index 710bb44..ca0dbc1 100644 --- a/code/pages.inc.php +++ b/code/pages.inc.php @@ -1,65 +1,61 @@ Exists($name, $type)) + return array('title' => $name, + 'content' => ErrorMessage('PageNotFound', array('page' => $name))); + + $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type)); + + if(!$this->HasAccess($name, $type)) + return array('title' => $name, + 'content' => ErrorMessage('Forbidden', array('page' => $name))); + + parse_str($res->fields[2], $data); + $data = array_map('Unquote', $data); + if($extra) $data = array_merge($data, $extra); + $data['_id'] = $res->fields[0]; + $data['_page'] = $name; + + return $GLOBALS['handlers'][$res->fields[1]]->Get($data); + } - class Pages { - function Get($name, $type, $extra = null) { - if(!$this->Exists($name, $type)) - return array('title' => $name, - 'content' => ErrorMessage('PageNotFound', array('page' => $name))); - - $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type)); - - if(!$this->HasAccess($name, $type)) - return array('title' => $name, - 'content' => ErrorMessage('Forbidden', array('page' => $name))); - - parse_str($res->fields[2], $data); - $data = array_map('Unquote', $data); - if($extra) $data = array_merge($data, $extra); - $data['_id'] = $res->fields[0]; - $data['_page'] = $name; - - return $GLOBALS['handlers'][$res->fields[1]]->Get($data); - } + function Edit($name, $type) { + if(!$this->Exists($name, $type)) + return array('title' => $name, + 'content' => ErrorMessage('PageNotFound', array('page' => $name))); - function Edit($name, $type) { - if(!$this->Exists($name, $type)) - return array('title' => $name, - 'content' => ErrorMessage('PageNotFound', array('page' => $name))); - - $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type)); - - if(!$GLOBALS['user']->IsAdmin()) - return array('title' => $name, - 'content' => ErrorMessage('Forbidden', array('page' => $name))); - - parse_str($res->fields[2], $data = null); - $data = array_map('Unquote', $data); - $data['_id'] = $res->fields[0]; - $data['_page'] = $name; - - return $this->Get($res->fields[1], 'e', array('_data' => $data)); - } + $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type)); - function Exists($name, $type) { - $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type)); - - return ($res->RecordCount() > 0); - } + if(!$GLOBALS['user']->IsAdmin()) + return array('title' => $name, + 'content' => ErrorMessage('Forbidden', array('page' => $name))); - function HasAccess($name, $type) { - $gid = $GLOBALS['user']->GetGid(); - $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type)); - - return ($GLOBALS['user']->IsAdmin() || (ord($res->fields[0][$gid/8]) & (1 << ($gid%8))) != 0); - } + parse_str($res->fields[2], $data = null); + $data = array_map('Unquote', $data); + $data['_id'] = $res->fields[0]; + $data['_page'] = $name; + + return $this->Get($res->fields[1], 'e', array('_data' => $data)); + } + + function Exists($name, $type) { + $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type)); + + return ($res->RecordCount() > 0); } - $pages = new Pages; + function HasAccess($name, $type) { + $gid = $GLOBALS['user']->GetGid(); + $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type)); + + return ($GLOBALS['user']->IsAdmin() || (ord($res->fields[0][$gid/8]) & (1 << ($gid%8))) != 0); + } } + + $GLOBALS['pages'] = new Pages; ?> diff --git a/code/user.inc.php b/code/user.inc.php index 3cd39bf..5aa76d5 100644 --- a/code/user.inc.php +++ b/code/user.inc.php @@ -1,99 +1,95 @@ Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', - array(substr($_COOKIE['login'], 32), - substr($_COOKIE['login'], 0, 32))); - - if($res->RecordCount() && $res->fields[2]) { - $this->uid = $res->fields[0]; - $this->gid = $res->fields[1]; - - $this->type = 'cookie'; - $this->key = $_COOKIE['login']; - } - } - - if($this->uid == 0 && $_GET['login']) { - $res = $GLOBALS['db']->Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', - array(substr($_GET['login'], 32), - substr($_GET['login'], 0, 32))); + function User() { + if($_COOKIE['login']) { + $res = $GLOBALS['db']->Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', + array(substr($_COOKIE['login'], 32), + substr($_COOKIE['login'], 0, 32))); + + if($res->RecordCount() && $res->fields[2]) { + $this->uid = $res->fields[0]; + $this->gid = $res->fields[1]; - if($res->RecordCount() && $res->fields[2]) { - $this->uid = $res->fields[0]; - $this->gid = $res->fields[1]; - - $this->type = 'url'; - $this->key = $_GET['login']; - } + $this->type = 'cookie'; + $this->key = $_COOKIE['login']; } } - function Login($name, $pass) { - $res = $GLOBALS['db']->Execute('SELECT id, gid FROM users WHERE user = ? AND password = ?', array($name, $pass)); - - if($res->RecordCount()) { - $id = $res->fields[0]; - $sid = md5(uniqid($name . " * " . $pass . " * " . rand())); + if($this->uid == 0 && $_GET['login']) { + $res = $GLOBALS['db']->Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', + array(substr($_GET['login'], 32), + substr($_GET['login'], 0, 32))); - $GLOBALS['db']->Execute('UPDATE users SET sid = ? WHERE id = ?', array($sid, $id)); - - $this->uid = $id; + if($res->RecordCount() && $res->fields[2]) { + $this->uid = $res->fields[0]; $this->gid = $res->fields[1]; $this->type = 'url'; - $this->key = $sid . $id; - - setcookie('login', $this->key); - - return $id; + $this->key = $_GET['login']; } - - return 0; } + } + + function Login($name, $pass) { + $res = $GLOBALS['db']->Execute('SELECT id, gid FROM users WHERE user = ? AND password = ?', array($name, $pass)); - function Logout() { - $GLOBALS['db']->Execute('UPDATE users SET sid = \'\' WHERE id = ?', $this->uid); + if($res->RecordCount()) { + $id = $res->fields[0]; + $sid = md5(uniqid($name . " * " . $pass . " * " . rand())); - $this->uid = 0; - $this->gid = 0; + $GLOBALS['db']->Execute('UPDATE users SET sid = ? WHERE id = ?', array($sid, $id)); - $this->type = ''; - $this->key = ''; + $this->uid = $id; + $this->gid = $res->fields[1]; - setcookie('login'); + $this->type = 'url'; + $this->key = $sid . $id; + + setcookie('login', $this->key); + + return $id; } - function IsAdmin() { - return ($this->uid != 0 && $this->gid == 0); - } + return 0; + } + + function Logout() { + $GLOBALS['db']->Execute('UPDATE users SET sid = \'\' WHERE id = ?', $this->uid); - function GetUid() { - return $this->uid; - } + $this->uid = 0; + $this->gid = 0; - function GetGid() { - return $this->gid; - } + $this->type = ''; + $this->key = ''; - function GetLoginType() { - return $this->type; - } + setcookie('login'); + } + + function IsAdmin() { + return ($this->uid != 0 && $this->gid == 0); + } - function GetLoginKey() { - return $this->key; - } + function GetUid() { + return $this->uid; + } + + function GetGid() { + return $this->gid; } - $user = new User; + function GetLoginType() { + return $this->type; + } + + function GetLoginKey() { + return $this->key; + } } + + $GLOBALS['user'] = new User; ?> diff --git a/code/util.inc.php b/code/util.inc.php index 724f8bd..194102f 100644 --- a/code/util.inc.php +++ b/code/util.inc.php @@ -1,27 +1,23 @@ $value) - $tr['$' . $key] = $value; - - krsort($tr); - - return strtr($string, $tr); - } + foreach($subst as $key => $value) + $tr['$' . $key] = $value; - if(get_magic_quotes_gpc()) { - function Unquote($string) { - return stripslashes($string); - } - } - else { - function Unquote($string) { - return $string; - } - } + krsort($tr); + + return strtr($string, $tr); + } + + if(get_magic_quotes_gpc()) { + function Unquote($string) { + return stripslashes($string); + } + } + else { + function Unquote($string) { + return $string; + } } ?> -- cgit v1.2.3