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
This commit is contained in:
parent
b76d848d46
commit
8a50ba8d4d
6 changed files with 205 additions and 15 deletions
21
classes/ArrayUtils.php
Normal file
21
classes/ArrayUtils.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class ArrayUtils {
|
||||
|
||||
public static function object2array($object) {
|
||||
if (is_object($object)) {
|
||||
$object = (array)$object;
|
||||
}
|
||||
|
||||
foreach ($object as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
$object[$key] = self::object2array($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
class Controller {
|
||||
|
||||
public function __construct() {
|
||||
global $smarty;
|
||||
|
||||
$sections = Config::get('sections');
|
||||
|
||||
if (isset($_REQUEST['section']) && in_array($_REQUEST['section'], array_keys($sections))) {
|
||||
$section = $_REQUEST['section'];
|
||||
|
||||
if (isset($_REQUEST['action'])) {
|
||||
$action = $_REQUEST['action'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$section = Config::get('default');
|
||||
$action = '';
|
||||
}
|
||||
|
||||
$file = '../logic/' . $section . ($action ? '.' . $action : null) . '.php';
|
||||
$template = $section . ($action ? '.' . $action : null) . '.tpl';
|
||||
|
||||
if (file_exists('../logic/' . $file)) {
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!file_exists('../templates/' . $template)) {
|
||||
$section = Config::get('default');
|
||||
$action = '';
|
||||
|
||||
$file = '../logic/' . $section . ($action ? '.' . $action : null) . '.php';
|
||||
$template = $section . ($action ? '.' . $action : null) . '.tpl';
|
||||
|
||||
if (file_exists('../logic/' . $file)) {
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
if (!file_exists('../templates/' . $template)) {
|
||||
// This would be considered a critical error
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$smarty->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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -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"
|
||||
|
29
config/verynicenoise.com.xml
Executable file
29
config/verynicenoise.com.xml
Executable file
|
@ -0,0 +1,29 @@
|
|||
<config>
|
||||
<debug></debug>
|
||||
<disable></disable>
|
||||
<fckeditor></fckeditor>
|
||||
<session></session>
|
||||
<smarty>true</smarty>
|
||||
<magpierss></magpierss>
|
||||
<database>
|
||||
<hostname>localhost</hostname>
|
||||
<username>verynicenoise</username>
|
||||
<password>v3ryn1c3n0153</password>
|
||||
<database>verynicenoise</database>
|
||||
</database>
|
||||
<default>home</default>
|
||||
<sections>
|
||||
<home>Home</home>
|
||||
<about>About</about>
|
||||
<releases>Releases</releases>
|
||||
<artists>Artists</artists>
|
||||
<shop>Shop</shop>
|
||||
<contact>Contact</contact>
|
||||
</sections>
|
||||
<admin>
|
||||
<news>News</news>
|
||||
<releases>Releases</releases>
|
||||
<artists>Artists</artists>
|
||||
<shop>Shop</shop>
|
||||
</admin>
|
||||
</config>
|
53
static/css/reset.css
Normal file
53
static/css/reset.css
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue