diff --git a/Pickles.php b/Pickles.php
new file mode 100755
index 0000000..38f22c1
--- /dev/null
+++ b/Pickles.php
@@ -0,0 +1,61 @@
+config = Config::getInstance();
+ $this->config->load($site);
+
+ // Generate a generic "site down" message
+ if ($this->config->get('disabled')) {
+ exit("
{$_SERVER['SERVER_NAME']} is currently down for maintenance
");
+ }
+
+ new Controller($controller);
+ }
+
+}
+
+/*
+if (Config::getSession() && !isset($_SESSION)) {
+ session_start();
+}
+
+
+// Use the FCKeditor instead of textareas
+// @todo add a wrapper for these two
+if (Config::getFCKEditor()) {
+ require_once JLIB_PATH . 'common/static/fckeditor/fckeditor.php';
+}
+
+// Load up MagpieRSS is so desired
+if (Config::getMagpieRSS()) {
+ require_once JLIB_PATH . '/var/www/josh/common/contrib/magpierss/rss_fetch.inc';
+}
+
+//Request::load();
+*/
+
+?>
diff --git a/classes/ArrayUtils.php b/classes/ArrayUtils.php
new file mode 100755
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
new file mode 100755
index 0000000..ca34caf
--- /dev/null
+++ b/classes/Config.php
@@ -0,0 +1,44 @@
+ $value) {
+ if ($value == 'true' || $value == array()) {
+ $value = (bool) $value;
+ }
+
+ $this->$variable = $value == array() ? (bool) $value : $value;
+ }
+ }
+
+ return true;
+ }
+ else {
+ Error::addError('Unable to load the configuration file');
+ return false;
+ }
+ }
+
+}
+
+?>
diff --git a/classes/Controller.php b/classes/Controller.php
new file mode 100755
index 0000000..485a2db
--- /dev/null
+++ b/classes/Controller.php
@@ -0,0 +1,83 @@
+session = Session::getInstance();
+ }
+
+ // Grab the passed in model or use the default
+ $name = isset($_REQUEST['model']) ? $_REQUEST['model'] : $this->config->get('navigation', 'default');
+
+ // Load the model
+ $file = '../models/' . $name . '.php';
+ if (file_exists($file)) {
+ require_once $file;
+
+ if (strpos($name, '/') === false) {
+ $class = $name;
+ $section = $name;
+ $event = null;
+ }
+ else {
+ $class = str_replace('/', '_', $name);
+ list($section, $event) = split('/', $name);
+ }
+
+ if (class_exists($class)) {
+ $this->model = new $class;
+
+ if ($this->model->get('auth') === true) {
+ Security::authenticate();
+ }
+
+ $this->model->set('name', $name);
+ $this->model->set('section', $section);
+ $this->model->set('event', $event);
+
+ $this->model->__default();
+ }
+ else {
+ // @todo
+ exit();
+ }
+
+ // Load the viewer
+ $this->viewer = Viewer::factory($this->model);
+ $this->viewer->display();
+ }
+ }
+
+ /*
+
+ if ((isset($_REQUEST['section']) && $_REQUEST['section'] == 'admin')) {
+ }
+
+ // Check if we're accessing an admin sub section and load the logic script
+ if (isset($_REQUEST['section']) && $_REQUEST['section'] != 'admin' && $is_admin) {
+ if ($_REQUEST['section'] == 'admin.logout') {
+ Session::logout();
+ }
+
+ // Add the admin section if we're authenticated
+ if (isset($_SESSION['user_id']) || isset($_SESSION['artist_id'])) {
+ if (Config::get('menu', 'admin') == 'true') {
+ $navigation['admin'] = 'Admin';
+ }
+ }
+
+ */
+
+}
+
+?>
diff --git a/classes/DB.php b/classes/DB.php
new file mode 100755
index 0000000..f9f348e
--- /dev/null
+++ b/classes/DB.php
@@ -0,0 +1,238 @@
+connection)) {
+ $config = Config::getInstance();
+
+ $this->hostname = $config->get('database', 'hostname');
+ $this->username = $config->get('database', 'username');
+ $this->password = $config->get('database', 'password');
+ $this->database = $config->get('database', 'database');
+
+ if (isset($this->hostname) && isset($this->username) && isset($this->password) && isset($this->database)) {
+ $this->connection = @mysql_connect($this->hostname, $this->username, $this->password);
+
+ if (is_resource($this->connection)) {
+ if (!mysql_select_db($this->database, $this->connection)) {
+ Error::addWarning("There was an error selecting the '" . $this->database , "' database");
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else {
+ Error::addError('There was an error connecting to the database server');
+ }
+
+ return false;
+ }
+ else {
+ Error::addError('There was an error loading the configuration');
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public function close() {
+ if (is_resource($this->connection)) {
+ return mysql_close($this->connection);
+ }
+
+ return false;
+ }
+
+ public function execute($sql) {
+ $this->open();
+
+ if (trim($sql) != '') {
+ $this->results = @mysql_query($sql, $this->connection);
+ if (empty($this->results)) {
+ Error::addError('There was an error executing the SQL');
+ Error::addError(mysql_error());
+ }
+ else {
+ return true;
+ }
+ }
+ else {
+ Error::addWarning('There was no SQL to execute');
+ }
+
+ return false;
+ }
+
+ public function getField($sql = null) {
+ if (isset($sql)) {
+ $this->execute($sql);
+ }
+
+ if (is_resource($this->results)) {
+ $results = @mysql_fetch_row($this->results);
+ if (is_array($results)) {
+ return $results[0];
+ }
+ else {
+ Error::addWarning('There is nothing to return');
+ }
+ }
+ else {
+ Error::addError('There is no valid MySQL result resource');
+ }
+
+ return null;
+ }
+
+ public function getRow($sql = null) {
+ if (isset($sql)) {
+ $this->execute($sql);
+ }
+
+ if (is_resource($this->results)) {
+ $results = @mysql_fetch_assoc($this->results);
+ if (is_array($results)) {
+ return $results;
+ }
+ else {
+ Error::addWarning('There is nothing to return');
+ }
+ }
+ else {
+ Error::addError('There is no valid MySQL result resource');
+ }
+
+ return null;
+ }
+
+ public function getArray($sql = null) {
+ if (isset($sql)) {
+ $this->execute($sql);
+ }
+
+ if (is_resource($this->results)) {
+ $return = null;
+ while ($row = mysql_fetch_assoc($this->results)) {
+ if (!is_array($return)) {
+ $return = array();
+ }
+
+ array_push($return, $row);
+ }
+
+ return $return;
+ }
+ else {
+ Error::addError('There is no valid MySQL result resource');
+ }
+
+ return null;
+ }
+
+ public function insert($table, $columnValues) {
+ $this->open();
+
+ if (trim($table) != '') {
+ // @todo Check that the table exists, and possibly check that the columns exist as well
+
+ if (is_array($columnValues)) {
+ foreach ($columnValues as $key => $value) {
+ $columnValues[$key] = $value == null ? 'NULL' : "'" . mysql_real_escape_string(stripslashes($value), $this->connection) . "'";
+ }
+
+ $this->execute("
+ INSERT INTO {$table} (
+ " . implode(array_keys($columnValues), ', ') . "
+ ) VALUES (
+ " . implode($columnValues, ", ") . "
+ );
+ ");
+
+ return mysql_insert_id($this->connection);
+ }
+ else {
+ Error::addError('No data was specified');
+ }
+ }
+ else {
+ Error::addError('No database table was specified');
+ }
+
+ return false;
+ }
+
+ public function update($table, $columnValues, $conditions) {
+ $this->open();
+
+ if (trim($table) != '') {
+ // @todo Check that the table exists, and possibly check that the columns exist as well
+
+ $fields = $where = null;
+ if (is_array($columnValues)) {
+ foreach ($columnValues as $key => $value) {
+ $fields .= ($fields ? ', ' : null) . $key . " = '" . mysql_real_escape_string(stripslashes($value), $this->connection) . "'";
+ }
+
+ if (is_array($conditions)) {
+ foreach ($conditions as $key => $value) {
+ $where = ($where == null) ? 'WHERE ' : ' AND ';
+
+ if ($value == null) {
+ $where .= $key . ' IS NULL';
+ }
+ else {
+ $where .= $key . " = '" . mysql_real_escape_string(stripslashes($value), $this->connection) . "'";
+ }
+ }
+
+ $sql = 'UPDATE ' . $table . ' SET ' . $fields . $where;
+ if ($this->execute($sql)) {
+ return true;
+ }
+ }
+ else {
+ Error::addError('No conditions were specified');
+ }
+ }
+ else {
+ Error::addError('No data was specified');
+ }
+ }
+ else {
+ Error::addError('No database table was specified');
+ }
+
+ return false;
+ }
+
+ public function delete($table, $columnValues, $conditions) {
+
+ }
+
+}
+
+?>
diff --git a/classes/Error.php b/classes/Error.php
new file mode 100755
index 0000000..c4aa548
--- /dev/null
+++ b/classes/Error.php
@@ -0,0 +1,67 @@
+";
+ }
+ }
+
+ if (self::getWarning()) {
+ foreach (self::getWarning() as $error) {
+ echo "{$warning}
";
+ }
+ }
+
+ self::$errors = self::$warnings = null;
+ return true;
+ }
+
+ return false;
+ }
+
+}
+
+?>
diff --git a/classes/ImageUtils.php b/classes/ImageUtils.php
new file mode 100755
index 0000000..e779008
--- /dev/null
+++ b/classes/ImageUtils.php
@@ -0,0 +1,51 @@
+ 75, 'medium' => 150, 'large' => 500);
+ foreach ($sizes as $name => $size) {
+ $temp = imagecreatetruecolor($size, $size);
+ imagecopyresampled($temp, $source, 0, 0, 0, 0, $size, $size, $width, $height);
+ imagejpeg($temp, "{$directory}{$name}.jpg", 85);
+
+ imagedestroy($temp);
+ }
+
+ imagedestroy($source);
+ */
+
+}
+
+?>
diff --git a/classes/Mail.php b/classes/Mail.php
new file mode 100755
index 0000000..2b223ed
--- /dev/null
+++ b/classes/Mail.php
@@ -0,0 +1,47 @@
+get('contact');
+
+ if (!isset($recipients)) {
+ $recipients = $defaults['recipients']['recipient'];
+ }
+
+ if (is_array($recipients)) {
+ $to = null;
+ foreach ($recipients as $recipient) {
+ $to .= (isset($to) ? ',' : '') . $recipient;
+ }
+ }
+ else {
+ $to = $recipients;
+ }
+
+ if (!isset($prefix)) {
+ $prefix = isset($defaults['prefix']) ? $defaults['prefix'] : null;
+ }
+
+ $subject = str_replace("\n", '', (isset($prefix) ? "[{$prefix}] " : '') . $_REQUEST['subject']);
+
+ if (mail($to, $subject, stripslashes($_REQUEST['message']), "From: {$_REQUEST['email']}\r\n")) {
+ $type = 'success';
+ $message = 'Message sent successfully';
+ }
+ else {
+ $type = 'error';
+ $message = 'An unexpected error has occurred';
+ }
+
+ $return = array(
+ 'type' => $type,
+ 'message' => $message
+ );
+
+ return $return;
+ }
+}
+
+?>
diff --git a/classes/Model.php b/classes/Model.php
new file mode 100644
index 0000000..c1f956a
--- /dev/null
+++ b/classes/Model.php
@@ -0,0 +1,37 @@
+db = DB::getInstance();
+ }
+
+ public function getAuth() {
+ return $this->get('auth');
+ }
+
+ public function getData() {
+ return $this->get('data');
+ }
+
+ public function getView() {
+ return $this->get('view');
+ }
+
+ public function __destruct() {
+ parent::__destruct();
+ }
+
+ public function __default() {
+
+ }
+
+}
+
+?>
diff --git a/classes/Object.php b/classes/Object.php
new file mode 100644
index 0000000..6305ade
--- /dev/null
+++ b/classes/Object.php
@@ -0,0 +1,49 @@
+config = Config::getInstance();
+ }
+
+ public function __destruct() {
+
+ }
+
+ /*
+ // @todo maybe later
+ public function __get($variable) {
+ if (!isset($this->data[$variable])) {
+ $this->data[$variable] = null;
+ }
+
+ return $this->data[$variable];
+ }
+ */
+
+ public function get($variable, $array_element = null) {
+ if (isset($this->$variable)) {
+ if (isset($array_element)) {
+ $array = $this->$variable;
+
+ if (isset($array[$array_element])) {
+ return $array[$array_element];
+ }
+ }
+ else {
+ return $this->$variable;
+ }
+ }
+
+ return false;
+ }
+
+ public function set($variable, $value) {
+ $this->$variable = $value;
+ }
+
+}
+
+?>
diff --git a/classes/Request.php b/classes/Request.php
new file mode 100755
index 0000000..729c5f6
--- /dev/null
+++ b/classes/Request.php
@@ -0,0 +1,28 @@
+ $value) {
+ self::$request[$key] = $value;
+ unset($_REQUEST[$key]);
+ }
+ }
+
+ return true;
+ }
+
+ public static function get($variable) {
+ if (isset(self::$request[$variable])) {
+ return self::$request[$variable];
+ }
+
+ return false;
+ }
+
+}
+
+?>
diff --git a/classes/Security.php b/classes/Security.php
new file mode 100644
index 0000000..9d5c8db
--- /dev/null
+++ b/classes/Security.php
@@ -0,0 +1,51 @@
+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 {
+ // Commented out to allow navigation to the page intended
+ //header('Location: /');
+ //exit();
+ }
+ }
+
+ static function logout() {
+ $_SERVER['PHP_AUTH_USER'] = null;
+ $_SESSION['user_id'] = null;
+ $_SESSION['artist_id'] = null;
+ $_SESSION['admin'] = false;
+
+ session_destroy();
+
+ header('Location: /');
+ }
+
+}
+
+?>
diff --git a/classes/Session.php b/classes/Session.php
new file mode 100755
index 0000000..ff646c6
--- /dev/null
+++ b/classes/Session.php
@@ -0,0 +1,59 @@
+id = session_id();
+ }
+
+ public static function getInstance() {
+ if (!self::$instance instanceof Session) {
+ self::$instance = new Session();
+ }
+
+ return self::$instance;
+ }
+
+ public function destroy() {
+ // foreach ($_SESSION as $variable => $value)
+ foreach (array_keys($_SESSION) as $variable) {
+ session_unregister($variable);
+ }
+
+ session_destroy();
+ }
+
+ public function __clone() {
+ trigger_error('Clone is not allowed for ' . __CLASS__, E_USER_ERROR);
+ }
+
+ public function __get($var) {
+ if (!isset($_SESSION[$var])) {
+ $_SESSION[$var] = null;
+ }
+
+ return $_SESSION[$var];
+ }
+
+ function __set($var,$val) {
+ return ($_SESSION[$var] = $val);
+ }
+
+ public function __isset($var) {
+ return isset($_SESSION[$var]) || isset($this->$var);
+ }
+
+ public function __destruct() {
+ session_write_close();
+ }
+}
+
+?>
diff --git a/classes/Singleton.php b/classes/Singleton.php
new file mode 100644
index 0000000..7c507eb
--- /dev/null
+++ b/classes/Singleton.php
@@ -0,0 +1,30 @@
+$variable)) {
+ if (isset($array_element)) {
+ $array = $this->$variable;
+
+ if (isset($array[$array_element])) {
+ return $array[$array_element];
+ }
+ }
+ else {
+ return $this->$variable;
+ }
+ }
+
+ return false;
+ }
+
+ public function set($variable, $value) {
+ $this->$$variable = $value;
+ }
+
+}
+
+?>
diff --git a/classes/Viewer.php b/classes/Viewer.php
new file mode 100644
index 0000000..b5baee9
--- /dev/null
+++ b/classes/Viewer.php
@@ -0,0 +1,14 @@
+getView();
+ return new $class($model);
+ }
+
+}
+
+?>
diff --git a/classes/Viewer/Common.php b/classes/Viewer/Common.php
new file mode 100644
index 0000000..4f0637b
--- /dev/null
+++ b/classes/Viewer/Common.php
@@ -0,0 +1,16 @@
+model = $model;
+ }
+
+ abstract public function display();
+
+}
+
+?>
diff --git a/classes/Viewer/Debug.php b/classes/Viewer/Debug.php
new file mode 100644
index 0000000..1e110e5
--- /dev/null
+++ b/classes/Viewer/Debug.php
@@ -0,0 +1,15 @@
+Debug' . "\n";
+ echo '$_REQUEST
' . "\n";
+ echo '';
+ var_dump($_REQUEST);
+ echo '
';
+ }
+
+}
+
+?>
diff --git a/classes/Viewer/JSON.php b/classes/Viewer/JSON.php
new file mode 100644
index 0000000..07b0f0c
--- /dev/null
+++ b/classes/Viewer/JSON.php
@@ -0,0 +1,18 @@
+model->getData());
+ }
+
+ }
+
+}
+
+?>
diff --git a/classes/Viewer/Smarty.php b/classes/Viewer/Smarty.php
new file mode 100644
index 0000000..4b3092f
--- /dev/null
+++ b/classes/Viewer/Smarty.php
@@ -0,0 +1,83 @@
+template_dir = '../templates/';
+
+ // @todo instead of having this in /tmp (which is Linux-scentric) perhaps move it to a folder in the common dir
+ $temp_path = "/tmp/smarty/{$_SERVER['SERVER_NAME']}/";
+ $cache_dir = $temp_path . 'cache';
+ $compile_dir = $temp_path . 'compile';
+
+ if (!file_exists($cache_dir)) { mkdir($cache_dir, 0777, true); }
+ if (!file_exists($compile_dir)) { mkdir($compile_dir, 0777, true); }
+
+ $smarty->cache_dir = $cache_dir ;
+ $smarty->compile_dir = $compile_dir;
+
+ $smarty->load_filter('output','trimwhitespace');
+
+ // Include custom Smarty functions
+ $directory = PATH . '../../common/smarty/functions/';
+
+ if (is_dir($directory)) {
+ if ($handle = opendir($directory)) {
+ while (($file = readdir($handle)) !== false) {
+ if (!preg_match('/^\./', $file)) {
+ list($type, $name, $ext) = split('\.', $file);
+ require_once $directory . $file;
+ $smarty->register_function($name, "smarty_{$type}_{$name}");
+ }
+ }
+ closedir($handle);
+ }
+ }
+
+ // Pass all of our controller values to Smarty
+ $smarty->assign('navigation', $this->config->get('navigation', 'sections'));
+ $smarty->assign('section', $this->model->get('section'));
+ $smarty->assign('action', $this->model->get('action')); // @todo rename me to event
+ $smarty->assign('admin', $this->config->get('admin', 'sections'));
+ $smarty->assign('template', '../templates/' . $this->model->get('name') . '.tpl'); //$template);
+
+ // Only load the session if it's available
+ if (isset($_SESSION)) {
+ $smarty->assign('session', $_SESSION);
+ }
+
+ $data = $this->model->getData();
+
+ if (isset($data) && is_array($data)) {
+ foreach ($data as $variable => $value) {
+ $smarty->assign($variable, $value);
+ }
+ }
+
+ // Load it up!
+ header('Content-type: text/html; charset=UTF-8');
+ $smarty->display('index.tpl');
+ }
+
+}
+
+?>