From 8a50ba8d4da5a941d7df50bf06019dfab0c26b57 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Fri, 14 Mar 2008 13:07:25 +0000 Subject: [PATCH] Added a new controller class and some other cool new shit. git-svn-id: http://svn.cleancode.org/svn/pickles@13 4d10bc64-7434-11dc-a737-d2d0f8310089 --- classes/ArrayUtils.php | 21 +++++++++ classes/Config.php | 16 ++++++- classes/Controller.php | 88 ++++++++++++++++++++++++++++++++++++ config/verynicenoise.com.ini | 13 ------ config/verynicenoise.com.xml | 29 ++++++++++++ static/css/reset.css | 53 ++++++++++++++++++++++ 6 files changed, 205 insertions(+), 15 deletions(-) create mode 100644 classes/ArrayUtils.php delete mode 100755 config/verynicenoise.com.ini create mode 100755 config/verynicenoise.com.xml create mode 100644 static/css/reset.css diff --git a/classes/ArrayUtils.php b/classes/ArrayUtils.php new file mode 100644 index 0000000..3e08580 --- /dev/null +++ b/classes/ArrayUtils.php @@ -0,0 +1,21 @@ + $value) { + if (is_object($value)) { + $object[$key] = self::object2array($value); + } + } + + return $object; + } + +} + +?> diff --git a/classes/Config.php b/classes/Config.php index eb9071e..8310287 100755 --- a/classes/Config.php +++ b/classes/Config.php @@ -10,6 +10,9 @@ class Config { if (file_exists('/var/www/josh/common/config/' . $site . '.ini')) { return true; } + else if (file_exists('/var/www/josh/common/config/' . $site . '.xml')) { + return true; + } else { return false; } @@ -22,8 +25,17 @@ class Config { self::$data = parse_ini_file($file, true); } else { - Error::addError('Unable to load the configuration file'); - return false; + $file = str_replace('ini', 'xml', $file); + + if (file_exists($file)) { + $xml = ArrayUtils::object2array(simplexml_load_file($file)); + + self::$data = $xml; + } + else { + Error::addError('Unable to load the configuration file'); + return false; + } } return true; diff --git a/classes/Controller.php b/classes/Controller.php index e69de29..dce145c 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -0,0 +1,88 @@ +assign('sections', $sections); + $smarty->assign('section', $section); + $smarty->assign('action', $action); + $smarty->assign('template', $template); + + header('Content-type: text/html; charset=UTF-8'); + $smarty->display('index.tpl'); + } + + private function authenticate() { + if (isset($_SERVER['PHP_AUTH_USER'])) { + $from = ' + FROM user + WHERE email = "' . $_SERVER['PHP_AUTH_USER'] . '" + AND password = "' . md5($_SERVER['PHP_AUTH_PW']) . '" + AND admin = 1; + '; + + DB::execute('SELECT COUNT(id) ' . $from); + if (DB::getField() != 0) { + DB::execute('SELECT id ' . $from); + $_SESSION['user_id'] = DB::getField(); + } + else { + $_SESSION['user_id'] = null; + } + } + + if (!isset($_SESSION['user_id'])) { + header('WWW-Authenticate: Basic realm="Site Admin"'); + header('HTTP/1.0 401 Unauthorized'); + exit('No shirt, no shoes, no salvation. Access denied.'); + } + else { + header('Location: /'); + exit(); + } + } + +} + +?> diff --git a/config/verynicenoise.com.ini b/config/verynicenoise.com.ini deleted file mode 100755 index b7f7d80..0000000 --- a/config/verynicenoise.com.ini +++ /dev/null @@ -1,13 +0,0 @@ -debug = false -disable = false -fckeditor = false -session = false -smarty = true -magpierss = false - -[database] -hostname = "localhost" -username = "verynicenoise" -password = "v3ryn1c3n0153" -database = "verynicenoise" - diff --git a/config/verynicenoise.com.xml b/config/verynicenoise.com.xml new file mode 100755 index 0000000..e5aa65a --- /dev/null +++ b/config/verynicenoise.com.xml @@ -0,0 +1,29 @@ + + + + + + true + + + localhost + verynicenoise + v3ryn1c3n0153 + verynicenoise + + home + + Home + About + Releases + Artists + Shop + Contact + + + News + Releases + Artists + Shop + + diff --git a/static/css/reset.css b/static/css/reset.css new file mode 100644 index 0000000..1c85489 --- /dev/null +++ b/static/css/reset.css @@ -0,0 +1,53 @@ +/* http://meyerweb.com/eric/tools/css/reset/ */ +/* v1.0 | 20080212 */ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, font, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-size: 100%; + vertical-align: baseline; + background: transparent; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} + +/* remember to define focus styles! */ +:focus { + outline: 0; +} + +/* remember to highlight inserts somehow! */ +ins { + text-decoration: none; +} +del { + text-decoration: line-through; +} + +/* tables still need 'cellspacing="0"' in the markup */ +table { + border-collapse: collapse; + border-spacing: 0; +}