diff options
author | neoraider <devnull@localhost> | 2006-03-05 01:01:01 +0100 |
---|---|---|
committer | neoraider <devnull@localhost> | 2006-03-05 01:01:01 +0100 |
commit | d8edab617c02409178e82a59ce704d7da5de6d9a (patch) | |
tree | 59a6f6fdc26dd908d69f730a418e6a303015c384 /code | |
parent | b7cab9a930cf9ab53e5d11764cd560c7d9ef1632 (diff) | |
download | neon-d8edab617c02409178e82a59ce704d7da5de6d9a.tar neon-d8edab617c02409178e82a59ce704d7da5de6d9a.zip |
Anstatt der defined-Abfragen wird jetzt require_once benutzt.
Diffstat (limited to 'code')
-rw-r--r-- | code/db.inc.php | 20 | ||||
-rw-r--r-- | code/handlers.inc.php | 18 | ||||
-rw-r--r-- | code/links.inc.php | 104 | ||||
-rw-r--r-- | code/message.inc.php | 40 | ||||
-rw-r--r-- | code/nav.inc.php | 160 | ||||
-rw-r--r-- | code/pages.inc.php | 108 | ||||
-rw-r--r-- | code/user.inc.php | 142 | ||||
-rw-r--r-- | code/util.inc.php | 40 |
8 files changed, 300 insertions, 332 deletions
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 @@ <?PHP - if(!defined('DB_INC')) { - define('DB_INC', 1); - - require_once('config/config.inc.php'); - - require_once('adodb/adodb.inc.php'); - - - $db = &ADONewConnection($config['driver']); - $db->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 @@ <?PHP - if(!defined('HANDLERS_INC')) { - define('HANDLERS_INC', 1); - - $dir = opendir('handlers'); - - while($file = readdir($dir)) - if($file[0] != '.' && substr($file, -8) == '.inc.php') - include('handlers/' . $file); - - closedir($dir); - } + $dir = opendir('handlers'); + + while($file = readdir($dir)) + if($file[0] != '.' && substr($file, -8) == '.inc.php') + include('handlers/' . $file); + + closedir($dir); ?> 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 @@ <?PHP - if(!defined('LINKS_INC')) { - define('LINKS_INC', 1); - - 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(); + 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 '<a href="' . $ret . '">' . $text . '</a>'; - - return $text; - case '@': - return '<a href="' . $this->GetMailtoLink(substr($link, 1)) . '">' . $text . '</a>'; - case '!': - $ret = $this->GetNavPage(substr($link, 1)); - - if($ret) - return $ret; - - return $text; - default: - return '<a href="' . $this->GetExternalLink($link) . '">' . $text . '</a>'; - } - } + 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 '<a href="' . $ret . '">' . $text . '</a>'; + + return $text; + case '@': + return '<a href="' . $this->GetMailtoLink(substr($link, 1)) . '">' . $text . '</a>'; + case '!': + $ret = $this->GetNavPage(substr($link, 1)); + + if($ret) + return $ret; + + return $text; + default: + return '<a href="' . $this->GetExternalLink($link) . '">' . $text . '</a>'; + } + } } + + $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 @@ <?PHP - if(!defined('MESSAGE_INC')) { - define('MESSAGE_INC', 1); - - 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 '<span class="error">' . Subst($GLOBALS['message'][$type], $data) . '</span>'; - } + 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 '<span class="error">' . Subst($GLOBALS['message'][$type], $data) . '</span>'; } ?> 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 @@ <?PHP - if(!defined('NAV_INC')) { - define('NAV_INC', 1); + require_once('code/links.inc.php'); + + class Nav { + var $entries = array(); - require_once('code/links.inc.php'); - - class Nav { - var $entries = array(); + function Nav() { + $res = $GLOBALS['db']->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 = '<ul>'; - - foreach($this->entries as $entry) - if($entry->GetParentId() == 0) - $ret .= $entry->Parse(); - - $ret .= '</ul>'; - - 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 = '<ul>'; - function NavEntry($parent, $text, $link) { - $this->parent = $parent; - $this->text = $text; - $this->link = $link; - } + foreach($this->entries as $entry) + if($entry->GetParentId() == 0) + $ret .= $entry->Parse(); - function Add($entry) { - array_push($this->children, $entry); - } + $ret .= '</ul>'; - 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 = '<li>'; - 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 .= '<ul>'; + + foreach($this->children as $child) { + $cret = $child->Parse(); + + if($cret) { + $ret .= $cret; + + $ccount++; + } + } + + $ret .= '</ul>'; } - function Parse() { - $ccount = 0; - $ret = '<li>'; - - $a = $GLOBALS['links']->ParseNavLink($this->text, $this->link); - - $ret .= $a; - - if(count($this->children) > 0) { - $ret .= '<ul>'; - - foreach($this->children as $child) { - $cret = $child->Parse(); - - if($cret) { - $ret .= $cret; - - $ccount++; - } - } - - $ret .= '</ul>'; - } - - if(!$ccount && $a == $this->text) - return ''; - - return $ret . '</li>'; - } + if(!$ccount && $a == $this->text) + return ''; + + return $ret . '</li>'; } - - $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 @@ <?PHP - if(!defined('PAGES_INC')) { - define('PAGES_INC', 1); - - require_once('code/db.inc.php'); - require_once('code/user.inc.php'); - require_once('code/handlers.inc.php'); + require_once('code/db.inc.php'); + require_once('code/user.inc.php'); + 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))); + + $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 @@ <?PHP - if(!defined('USER_INC')) { - define('USER_INC', 1); + require_once('code/db.inc.php'); + + class User { + var $uid = 0, $gid = 0; + var $key = '', $type = ''; - require_once('code/db.inc.php'); - - class User { - var $uid = 0, $gid = 0; - var $key = '', $type = ''; - - 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]; - - $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 @@ <?PHP - if(!defined('UTIL_INC')) { - define('UTIL_INC', 1); + function Subst($string, $subst = array()) { + $tr['$$'] = '$'; - function Subst($string, $subst = array()) { - $tr['$$'] = '$'; - - foreach($subst as $key => $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; + } } ?> |