diff --git a/lib/config.php b/lib/config.php
index 1c68feb..faa166a 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -22,7 +22,7 @@
define("LIB_DIR", dirname(__FILE__));
define("COOKIE_DOMAIN", "");
-// Set the default controller hte user is directed to (aka homepage).
+// Set the default controller the user is directed to (aka homepage).
define('ROUTER_DEFAULT_CONTROLLER', 'site');
define('ROUTER_DEFAULT_ACTION', 'home');
@@ -33,4 +33,5 @@
require_once(LIB_DIR."/helpers.php");
require_once(LIB_DIR."/models/cache.php");
require_once(LIB_DIR."/models/user.php");
-require_once(LIB_DIR."/models/template.php");
\ No newline at end of file
+require_once(LIB_DIR."/models/template.php");
+
diff --git a/lib/controllers/app.php b/lib/controllers/app.php
index b1a24ff..a96aff0 100644
--- a/lib/controllers/app.php
+++ b/lib/controllers/app.php
@@ -16,10 +16,10 @@
class App {
- /**
- * Main constructor function, used to initialize the models, connect to the DB and
- * route the user to where they need to go.
- */
+ /**
+ * Main constructor function, used to initialize the models, connect to the DB and
+ * route the user to where they need to go.
+ */
function __construct(){
global $template, $user, $db;
@@ -29,10 +29,10 @@ function __construct(){
// Connect to the database.
try {
// If your application uses MySQL, use the following line instead:
- // $db = new PDO("mssql:host=$host;dbname=$dbname, $user, $pass");
- $db = new PDO('sqlite:' . BASE_DIR . '/db/sqlite.db');
+ // $db = new PDO("mysql:host=$host;dbname=$dbname, $user, $pass");
+ $db = new PDO('sqlite:' . BASE_DIR . '/db/sqlite.db');
} catch (Exception $e) {
- die($e);
+ die($e);
}
// Check to see if the 'user' table exists and if not, create it.
@@ -47,10 +47,10 @@ function __construct(){
$this->router();
}
- /**
- * Figure out where the user is trying to get to and route them to the
- * appropriate controller/action.
- */
+ /**
+ * Figure out where the user is trying to get to and route them to the
+ * appropriate controller/action.
+ */
function router() {
// Create a new Router instance.
@@ -94,24 +94,24 @@ function router() {
}else Site::load_page('home');
}
- /**
- * Check to see if the proper tables exist in the database and if not,
- * create them.
- */
+ /**
+ * Check to see if the proper tables exist in the database and if not,
+ * create them.
+ */
function check_db() {
global $db;
$sql = 'CREATE TABLE IF NOT EXISTS users (
- id INTEGER PRIMARY KEY,
- name TEXT,
- email TEXT,
- password TEXT,
- create_ip TEXT,
- create_date TEXT,
- status INTEGER
- )';
+ id INTEGER PRIMARY KEY,
+ name TEXT,
+ email TEXT,
+ password TEXT,
+ create_ip TEXT,
+ create_date TEXT,
+ status INTEGER
+ )';
$query = $db->prepare($sql);
$query->execute();
}
}
-?>
\ No newline at end of file
+
diff --git a/lib/controllers/router.php b/lib/controllers/router.php
index 5942d3d..149e109 100644
--- a/lib/controllers/router.php
+++ b/lib/controllers/router.php
@@ -15,96 +15,95 @@
*/
class Router {
- public $request_uri;
- public $routes;
- public $controller, $controller_name;
- public $action, $id;
- public $params;
- public $route_found = false;
-
- public function __construct() {
- $request = $_SERVER['REQUEST_URI'];
- $pos = strpos($request, '?');
- if ($pos) $request = substr($request, 0, $pos);
-
- $this->request_uri = $request;
- $this->routes = array();
- }
-
- public function map($rule, $target=array(), $conditions=array()) {
- $this->routes[$rule] = new Route($rule, $this->request_uri, $target, $conditions);
- }
-
- public function default_routes() {
- $this->map('/:controller');
- $this->map('/:controller/:action');
- $this->map('/:controller/:action/:id');
- }
-
- private function set_route($route) {
- $this->route_found = true;
- $params = $route->params;
- $this->controller = $params['controller']; unset($params['controller']);
- $this->action = $params['action']; unset($params['action']);
- $this->id = $params['id'];
- $this->params = array_merge($params, $_GET);
-
- if (empty($this->controller)) $this->controller = ROUTER_DEFAULT_CONTROLLER;
- if (empty($this->action)) $this->action = ROUTER_DEFAULT_ACTION;
- if (empty($this->id)) $this->id = null;
-
- $w = explode('_', $this->controller);
- foreach($w as $k => $v) $w[$k] = ucfirst($v);
- $this->controller_name = implode('', $w);
- }
-
- public function execute() {
- foreach($this->routes as $route) {
- if ($route->is_matched) {
- $this->set_route($route);
- break;
- }
- }
- }
+ public $request_uri;
+ public $routes;
+ public $controller, $controller_name;
+ public $action, $id;
+ public $params;
+ public $route_found = false;
+
+ public function __construct() {
+ $request = $_SERVER['REQUEST_URI'];
+ $pos = strpos($request, '?');
+ if ($pos) $request = substr($request, 0, $pos);
+
+ $this->request_uri = $request;
+ $this->routes = array();
+ }
+
+ public function map($rule, $target=array(), $conditions=array()) {
+ $this->routes[$rule] = new Route($rule, $this->request_uri, $target, $conditions);
+ }
+
+ public function default_routes() {
+ $this->map('/:controller');
+ $this->map('/:controller/:action');
+ $this->map('/:controller/:action/:id');
+ }
+
+ private function set_route($route) {
+ $this->route_found = true;
+ $params = $route->params;
+ $this->controller = $params['controller']; unset($params['controller']);
+ $this->action = $params['action']; unset($params['action']);
+ $this->id = $params['id'];
+ $this->params = array_merge($params, $_GET);
+
+ if (empty($this->controller)) $this->controller = ROUTER_DEFAULT_CONTROLLER;
+ if (empty($this->action)) $this->action = ROUTER_DEFAULT_ACTION;
+ if (empty($this->id)) $this->id = null;
+
+ $w = explode('_', $this->controller);
+ foreach($w as $k => $v) $w[$k] = ucfirst($v);
+ $this->controller_name = implode('', $w);
+ }
+
+ public function execute() {
+ foreach($this->routes as $route) {
+ if ($route->is_matched) {
+ $this->set_route($route);
+ break;
+ }
+ }
+ }
}
-
+
class Route {
- public $is_matched = false;
- public $params;
- public $url;
- private $conditions;
-
- function __construct($url, $request_uri, $target, $conditions) {
- $this->url = $url;
- $this->params = array();
- $this->conditions = $conditions;
- $p_names = array(); $p_values = array();
-
- preg_match_all('@:([\w]+)@', $url, $p_names, PREG_PATTERN_ORDER);
- $p_names = $p_names[0];
-
- $url_regex = preg_replace_callback('@:[\w]+@', array($this, 'regex_url'), $url);
- $url_regex .= '/?';
-
- if (preg_match('@^' . $url_regex . '$@', $request_uri, $p_values)) {
- array_shift($p_values);
- foreach($p_names as $index => $value) $this->params[substr($value,1)] = urldecode($p_values[$index]);
- foreach($target as $key => $value) $this->params[$key] = $value;
- $this->is_matched = true;
- }
-
- unset($p_names); unset($p_values);
- }
-
- function regex_url($matches) {
- $key = str_replace(':', '', $matches[0]);
- if (array_key_exists($key, $this->conditions)) {
- return '('.$this->conditions[$key].')';
- }
- else {
- return '([a-zA-Z0-9_\+\-%]+)';
- }
- }
+ public $is_matched = false;
+ public $params;
+ public $url;
+ private $conditions;
+
+ function __construct($url, $request_uri, $target, $conditions) {
+ $this->url = $url;
+ $this->params = array();
+ $this->conditions = $conditions;
+ $p_names = array(); $p_values = array();
+
+ preg_match_all('@:([\w]+)@', $url, $p_names, PREG_PATTERN_ORDER);
+ $p_names = $p_names[0];
+
+ $url_regex = preg_replace_callback('@:[\w]+@', array($this, 'regex_url'), $url);
+ $url_regex .= '/?';
+
+ if (preg_match('@^' . $url_regex . '$@', $request_uri, $p_values)) {
+ array_shift($p_values);
+ foreach($p_names as $index => $value) $this->params[substr($value,1)] = urldecode($p_values[$index]);
+ foreach($target as $key => $value) $this->params[$key] = $value;
+ $this->is_matched = true;
+ }
+
+ unset($p_names); unset($p_values);
+ }
+
+ function regex_url($matches) {
+ $key = str_replace(':', '', $matches[0]);
+ if (array_key_exists($key, $this->conditions)) {
+ return '('.$this->conditions[$key].')';
+ }
+ else {
+ return '([a-zA-Z0-9_\+\-%]+)';
+ }
+ }
}
-?>
\ No newline at end of file
diff --git a/lib/controllers/site.php b/lib/controllers/site.php
index 259fc93..c25514b 100644
--- a/lib/controllers/site.php
+++ b/lib/controllers/site.php
@@ -14,11 +14,11 @@
class Site {
- /**
- * Loads a particular page from the 'site' directory in views
- *
- * @param $name The name of the page to load (should match filename)
- */
+ /**
+ * Loads a particular page from the 'site' directory in views
+ *
+ * @param $name The name of the page to load (should match filename)
+ */
public static function load_page($name){
global $template;
$standard = array("faq", "terms", "about");
@@ -27,3 +27,4 @@ public static function load_page($name){
$template->render("site", $name, true);
}
}
+
diff --git a/lib/controllers/user.php b/lib/controllers/user.php
index 0541b49..ed0978d 100644
--- a/lib/controllers/user.php
+++ b/lib/controllers/user.php
@@ -15,9 +15,9 @@
class User {
- /**
- * Default user profile page.
- */
+ /**
+ * Default user profile page.
+ */
function index(){
global $template, $user;
login_required();
@@ -28,12 +28,12 @@ function index(){
$template->render("user","profile",true);
}
- /**
- * Login page.
- *
- * Sends the user to the homepage if they're already logged in. If they try to
- * login, validates their info and redirects them to homepage.
- */
+ /**
+ * Login page.
+ *
+ * Sends the user to the homepage if they're already logged in. If they try to
+ * login, validates their info and redirects them to homepage.
+ */
function login(){
global $user, $template;
if($user->is_logged)
@@ -52,11 +52,11 @@ function login(){
$template->render("user","login",true);
}
- /**
- * Logout page.
- *
- * Simply logs the user out if they're logged in, then renders the login page.
- */
+ /**
+ * Logout page.
+ *
+ * Simply logs the user out if they're logged in, then renders the login page.
+ */
function logout(){
global $user, $template;
if($user->is_logged()){
@@ -66,9 +66,9 @@ function logout(){
return_to('user/login');
}
- /**
- * Edit profile page.
- */
+ /**
+ * Edit profile page.
+ */
function edit(){
global $user, $template;
login_required();
@@ -82,9 +82,9 @@ function edit(){
$template->render("user","edit",true);
}
- /**
- * User registration page.
- */
+ /**
+ * User registration page.
+ */
function register(){
global $user, $template;
if($_POST){
@@ -102,5 +102,5 @@ function register(){
$template->set_title('Register');
$template->render("user","register",true);
}
+}
-}
\ No newline at end of file
diff --git a/lib/helpers.php b/lib/helpers.php
index f0baeac..b79f9b9 100644
--- a/lib/helpers.php
+++ b/lib/helpers.php
@@ -58,4 +58,3 @@ function __($id) {
echo $template->variables[$id];
}
-?>
\ No newline at end of file
diff --git a/lib/models/cache.php b/lib/models/cache.php
index 9f2c3e5..0b0ffcf 100644
--- a/lib/models/cache.php
+++ b/lib/models/cache.php
@@ -19,82 +19,82 @@
class CacheModel {
- var $cacheDir = "./cache";
- var $cacheTime = 21600; // 6 hours = 6*60*60
- var $caching = false;
- var $cacheFile;
- var $cacheFileName;
+ var $cacheDir = "./cache";
+ var $cacheTime = 21600; // 6 hours = 6*60*60
+ var $caching = false;
+ var $cacheFile;
+ var $cacheFileName;
- /**
- * Create an md5 hash of the currently requested URL, set the filename based on the hash.
- */
- function __construct(){
- // Hash the requested URI.
- $this->cacheFile = md5($_SERVER['REQUEST_URI']);
+ /**
+ * Create an md5 hash of the currently requested URL, set the filename based on the hash.
+ */
+ function __construct(){
+ // Hash the requested URI.
+ $this->cacheFile = md5($_SERVER['REQUEST_URI']);
- // Set the filename using the hash.
- $this->cacheFileName = $this->cacheDir.'/'.$this->cacheFile.'.cache';
+ // Set the filename using the hash.
+ $this->cacheFileName = $this->cacheDir.'/'.$this->cacheFile.'.cache';
- // If the cache directory doesn't exist, create it and set correct permissions.
- if(!is_dir($this->cacheDir)) {
- mkdir($this->cacheDir, 0755);
- }
- }
-
- /**
- * Starts the cache object; must call this function at the beginning of the content/page
- * you are trying to cache, then call the end function at the (duh) end of it.
- */
- function start(){
- global $do_not_cache;
+ // If the cache directory doesn't exist, create it and set correct permissions.
+ if(!is_dir($this->cacheDir)) {
+ mkdir($this->cacheDir, 0755);
+ }
+ }
- // Get the current URI and identify the current request.
- $location = explode('/',$_SERVER['REQUEST_URI']);
+ /**
+ * Starts the cache object; must call this function at the beginning of the content/page
+ * you are trying to cache, then call the end function at the (duh) end of it.
+ */
+ function start(){
+ global $do_not_cache;
- // If this page isn't in the "Do not cache" list, and caching is enabled, either
- // start the cache process if the previous cache is older than cacheTime or doesn't exist,
- // or else just render the existing cache file.
- if(!in_array($location[0],$do_not_cache) && CACHE_ENABLE){
- if(file_exists($this->cacheFileName) && (time() - filemtime($this->cacheFileName)) < $this->cacheTime){
- $this->caching = false;
- echo file_get_contents($this->cacheFileName);
- exit();
- }else{
- $this->caching = true;
- ob_start();
- }
- }
- }
-
- /**
- * Starts the cache object; must call this function at the beginning of the content/page
- * you are trying to cache, then call the end function at the (duh) end of it.
- */
- function end(){
- if($this->caching){
- file_put_contents($this->cacheFileName,ob_get_contents());
- ob_end_flush();
- }
- }
-
- /**
- * This function deletes the cache file for the current URI.
- */
- function purge(){
- if(file_exists($this->cacheFile) && is_writable($this->cacheDir)) unlink($this->cacheFile);
- }
-
- /**
- * This function deletes all of the cache files in the cache directory.
- */
- function purge_all(){
- if(!$dirhandle = @opendir($this->cacheDir)) return;
- while(false != ($filename = readdir($dirhandle))){
- if(substr($filename,-4) == '.cache') {
- $filename = $this->cacheDir. "/". $filename;
- unlink($filename);
- }
- }
- }
+ // Get the current URI and identify the current request.
+ $location = explode('/',$_SERVER['REQUEST_URI']);
+
+ // If this page isn't in the "Do not cache" list, and caching is enabled, either
+ // start the cache process if the previous cache is older than cacheTime or doesn't exist,
+ // or else just render the existing cache file.
+ if(!in_array($location[0],$do_not_cache) && CACHE_ENABLE){
+ if(file_exists($this->cacheFileName) && (time() - filemtime($this->cacheFileName)) < $this->cacheTime){
+ $this->caching = false;
+ echo file_get_contents($this->cacheFileName);
+ exit();
+ }else{
+ $this->caching = true;
+ ob_start();
+ }
+ }
+ }
+
+ /**
+ * Starts the cache object; must call this function at the beginning of the content/page
+ * you are trying to cache, then call the end function at the (duh) end of it.
+ */
+ function end(){
+ if($this->caching){
+ file_put_contents($this->cacheFileName,ob_get_contents());
+ ob_end_flush();
+ }
+ }
+
+ /**
+ * This function deletes the cache file for the current URI.
+ */
+ function purge(){
+ if(file_exists($this->cacheFile) && is_writable($this->cacheDir)) unlink($this->cacheFile);
+ }
+
+ /**
+ * This function deletes all of the cache files in the cache directory.
+ */
+ function purge_all(){
+ if(!$dirhandle = @opendir($this->cacheDir)) return;
+ while(false != ($filename = readdir($dirhandle))){
+ if(substr($filename,-4) == '.cache') {
+ $filename = $this->cacheDir. "/". $filename;
+ unlink($filename);
+ }
+ }
+ }
}
-?>
\ No newline at end of file
+
diff --git a/lib/models/template.php b/lib/models/template.php
index 75d561f..f9de9f3 100644
--- a/lib/models/template.php
+++ b/lib/models/template.php
@@ -15,132 +15,131 @@
class TemplateModel {
- var $variables = array();
- var $title;
- var $msg;
- var $msg_type;
-
- /**
- * Simple function used to load template views. If only a view/model is specified,
- * load only the file from the base template directory. If an action is specified,
- * the file/model name is expected to also be the name of the folder in which the
- * actual view file is being held.
- *
- * @param $file The name of the view/model file
- * @param $action When specified, name of the file ($file used as dir name).
- * This param is optional.
- */
- function load($file, $action = null){
- global $template, $user;
-
- // If an action is specified, include the specific action.
- $file = LIB_DIR . "/views/" . $file;
- if($action) {
- $file .= '/'.$action;
- }
- $file .= ".php";
-
- // Load the view file only if it exists.
- if(file_exists($file)) {
- include_once $file;
- }
- }
-
- /**
- * Renders default template views, based on the model and action supplied (including
- * header and footer views).
- *
- * @param $model The name of the model file
- * @param $action When specified, name of the file ($file used as dir name)
- * @param $html When specified, name of the file ($file used as dir name)
- * @param $caching_enabled (optional): When specified, name of the file ($file used as dir name)
- */
- function render($model, $action = null, $html = false, $caching_enabled = true){
-
- $this->load("header");
-
- // Start caching everything rendered. We start this after the
- // header, since the header may contain user session information
- // that shouldn't be cached.
- if($caching_enabled) {
- $cache = new CacheModel;
- $cache->start();
- }
-
- // Add a container DIV to the view HTML about to be inclued.
- if($html) {
- echo '
';
- }
-
- // Load this specific view
- $this->load($model, $action);
-
- // Close the container DIV.
- if($html) echo '
';
-
- $this->load("footer");
-
- // Stop caching.
- if($caching_enabled) {
- $cache->end();
- }
-
- }
-
- /**
- * Used to assign variables that can be used in the template files.
- *
- * @param $name Name of the variable to be assigned
- * @param $value String or Array object
- */
- function assign($name, $value){
- $this->variables[$name] = $value;
- }
-
- /**
- * Used to assign the page title of the rendered HTML file.
- *
- * @param $title Title of the rendered HTML file ()
- */
- function set_title($title){
- $this->title = $title;
- }
-
- /**
- * This function prints the page title that has been set in the controller,
- * should only be used in the header view.
- */
- function page_title(){
- if($this->title) $str = $this->title.' - '.APP_NAME.'.com';
- else $str = APP_NAME.'.com - '.APP_KEYWORDS;
- echo $str;
- }
-
- /**
- * Set any status or error messages to be passed into the view files.
- *
- * @param $the_msg The message to be displayed in the status box.
- * @param $type Type of message, either 'success' or 'error' -
- * passed into the DIV object as a class (used for styling).
- */
- function set_msg($the_msg, $type = null){
- $this->msg = $the_msg;
- $this->msg_type = $type;
- }
-
- /**
- * Displays the status or error message in the template.
- */
- function get_msg(){
- if($this->msg_type) {
- $style = "success";
- } else {
- $style = "error";
- }
- if($this->msg) {
- echo "
".$this->msg."
\n";
- }
- }
-
+ var $variables = array();
+ var $title;
+ var $msg;
+ var $msg_type;
+
+ /**
+ * Simple function used to load template views. If only a view/model is specified,
+ * load only the file from the base template directory. If an action is specified,
+ * the file/model name is expected to also be the name of the folder in which the
+ * actual view file is being held.
+ *
+ * @param $file The name of the view/model file
+ * @param $action When specified, name of the file ($file used as dir name).
+ * This param is optional.
+ */
+ function load($file, $action = null){
+ global $template, $user;
+
+ // If an action is specified, include the specific action.
+ $file = LIB_DIR . "/views/" . $file;
+ if($action) {
+ $file .= '/'.$action;
+ }
+ $file .= ".php";
+
+ // Load the view file only if it exists.
+ if(file_exists($file)) {
+ include_once $file;
+ }
+ }
+
+ /**
+ * Renders default template views, based on the model and action supplied (including
+ * header and footer views).
+ *
+ * @param $model The name of the model file
+ * @param $action When specified, name of the file ($file used as dir name)
+ * @param $html When specified, name of the file ($file used as dir name)
+ * @param $caching_enabled (optional): When specified, name of the file ($file used as dir name)
+ */
+ function render($model, $action = null, $html = false, $caching_enabled = true){
+
+ $this->load("header");
+
+ // Start caching everything rendered. We start this after the
+ // header, since the header may contain user session information
+ // that shouldn't be cached.
+ if($caching_enabled) {
+ $cache = new CacheModel;
+ $cache->start();
+ }
+
+ // Add a container DIV to the view HTML about to be inclued.
+ if($html) {
+ echo '
';
+ }
+
+ // Load this specific view
+ $this->load($model, $action);
+
+ // Close the container DIV.
+ if($html) echo '
';
+
+ $this->load("footer");
+
+ // Stop caching.
+ if($caching_enabled) {
+ $cache->end();
+ }
+
+ }
+
+ /**
+ * Used to assign variables that can be used in the template files.
+ *
+ * @param $name Name of the variable to be assigned
+ * @param $value String or Array object
+ */
+ function assign($name, $value){
+ $this->variables[$name] = $value;
+ }
+
+ /**
+ * Used to assign the page title of the rendered HTML file.
+ *
+ * @param $title Title of the rendered HTML file ()
+ */
+ function set_title($title){
+ $this->title = $title;
+ }
+
+ /**
+ * This function prints the page title that has been set in the controller,
+ * should only be used in the header view.
+ */
+ function page_title(){
+ if($this->title) $str = $this->title.' - '.APP_NAME.'.com';
+ else $str = APP_NAME.'.com - '.APP_KEYWORDS;
+ echo $str;
+ }
+
+ /**
+ * Set any status or error messages to be passed into the view files.
+ *
+ * @param $the_msg The message to be displayed in the status box.
+ * @param $type Type of message, either 'success' or 'error' -
+ * passed into the DIV object as a class (used for styling).
+ */
+ function set_msg($the_msg, $type = null){
+ $this->msg = $the_msg;
+ $this->msg_type = $type;
+ }
+
+ /**
+ * Displays the status or error message in the template.
+ */
+ function get_msg(){
+ if($this->msg_type) {
+ $style = "success";
+ } else {
+ $style = "error";
+ }
+ if($this->msg) {
+ echo "
".$this->msg."
\n";
+ }
+ }
}
-?>
\ No newline at end of file
+
diff --git a/lib/models/user.php b/lib/models/user.php
index ae43a95..9706206 100644
--- a/lib/models/user.php
+++ b/lib/models/user.php
@@ -15,338 +15,338 @@
class UserModel {
- var $user_id;
- var $name;
- var $email;
- var $password;
- var $ok;
- var $msg;
- var $is_logged;
-
- /**
- * Set all internal variables to 'Guest' status, then check to see if
- * a user session or cookie exists.
- */
- function __construct(){
- global $db;
-
- $this->user_id = 0;
- $this->email = "Guest";
- $this->name = "Guest";
- $this->ok = false;
-
- if(!$this->check_session()) $this->check_cookie();
-
- return $this->ok;
- }
-
- /**
- * This function checks to see whether or not a PHP Session is set.
- */
- function check_session(){
- if(!empty($_SESSION['auth_email']) && !empty($_SESSION['auth_secret']))
- return $this->check($_SESSION['auth_email'], $_SESSION['auth_secret']);
- else
- return false;
- }
-
-
- /**
- * Check to see if any cookies exist on the user's computer/browser.
- */
- function check_cookie(){
- if(!empty($_COOKIE['auth_email']) && !empty($_COOKIE['auth_secret']))
- return $this->check($_COOKIE['auth_email'], $_COOKIE['auth_secret']);
- else
- return false;
- }
-
- /**
- * Create a user and by default, log them in once the account has been created.
- *
- * @param $info An array that contains the following info about the user:
- * - name, email, password, password2 (password repeated), status (optional)
- * @param $login Bool, whether or not to log the user in after creating account.
- */
- function create($info,$login = true){
- global $db;
-
- // Hash the password using the salt specified in config.php
- $password = md5($info['password'] . PASSWORD_SALT);
-
- // If user status isn't set, assume default status (1)
- $status = $info['status'] ? $info['status'] : 1;
-
- // Store the IP address that the user create's the account with.
- $create_ip = $_SERVER['REMOTE_ADDR'];
-
- // Reset flag used for error detection.
- $this->ok = false;
-
- // Validate all of the user input fields.
- if(!$info['name'] || !$info['email'] || !$info['password'] || !$info['password2']){
- $this->msg = "Error! All fields are required.";
- return false;
- }elseif($info['password'] != $info['password2']){
- $this->msg = "Error! Passwords do not match.";
- return false;
- }elseif(!$this->validEmail($info['email'])){
- $this->msg = "Error! Please enter a valid e-mail address.";
- return false;
- }
-
- // Check to see if a user with that email address already exists.
- $query = $db->prepare("SELECT id, password FROM users WHERE email = :email");
- $query->execute([':email'=>$email]);
- if($query->rowCount() == 1){
- $this->msg = "Error! E-mail address is already in use.";
- }else{
- // User doesn't exist, so create a new account!
- $query = $db->prepare("INSERT INTO users (name, email, password, status, create_ip) VALUES (:name, :email, :password, :status, :create_ip)");
- $query->execute([':name'=>$info['name'],':email'=>$info['email'],':password'=>$password,':status'=>$status,':create_ip'=>$create_ip]);
- $this->msg = "User successfully added.";
- $this->ok = true;
- if($login) $this->login($info['email'],$info['password']);
- return true;
- }
- return false;
- }
-
- /**
- * Update a user's information.
- *
- * @param $info An array that contains the following info about the user:
- * - name, email, password, password2 (password repeated), status (optional)
- */
- function update($info) {
- global $db;
-
- // Reset our error detection flag, which is used to set the status message later on.
- $this->ok = false;
-
- // Validate email address again.
- if(!$this->validEmail($info['email'])) {
- $this->msg = "Error! Please enter a valid e-mail address.";
- return false;
- }
-
- // Start building the SQL query with the data submitted so far.
- $sql = "name = :name, email = :email";
- $exec = [':name'=>$info['name'], ':email'=>$info['email']];
-
- // If a password has been entered, validate it, re-hash it and add it to the SQL query.
- if($info['password']){
- if($info['password'] != $info['password2']){
- $this->msg = "Error! Passwords do not match.";
- return false;
- }
- $password = md5($info['password'] . PASSWORD_SALT);
- $sql .= ", password = :password";
- $exec[':password'] = $password;
- }
-
- // Create the finalized SQL query that will update our database.
- $sql = "UPDATE users SET ".$sql." WHERE id = :id";
- $exec[':id'] = $this->user_id;
- $query = $db->prepare($sql);
-
- // Successfully updated the user data.
- if($query->execute($exec)) {
- // Let the user know via a cheeky message (OK not really cheeky).
- $this->msg = "Info successfully updated.";
-
- // Set user status flag back to true, peace has been restored.
- $this->ok = true;
-
- // Set new email and password info in the session and cookies.
- $_SESSION['auth_email'] = $email;
- if($info['password']) $_SESSION['auth_secret'] = $password;
- setcookie("auth_email", $email, time()+60*60*24*30, "/", COOKIE_DOMAIN);
- if($info['password']) setcookie("auth_secret", $password, time()+60*60*24*30, "/", COOKIE_DOMAIN);
-
- // Update local variables to reflect new changes.
- $this->name = $info['name'];
- $this->email = $info['email'];
-
- return true;
- } else {
- // There seems to have been a problem with the query somewhere.
- $this->msg = "There was a problem, please try again.";
- }
- return false;
- }
-
- /**
- * Function used to let hte user login, checking their email and password against
- * what's stored in the database.
- *
- * @param $email The user's email address.
- * @param $password The user's password, directly from POST.
- */
- function login($email, $password) {
- global $db;
-
- // One of the fields is missing, deliver an error message.
- if(!$email || !$password) {
- $this->msg = "Error! Both E-mail and Password are required to login.";
- return false;
- }
-
- // Get user data using the email address supplied.
- $query = $db->prepare("SELECT id, password, name FROM users WHERE email = :email");
- $query->execute([':email'=>$email]);
-
- // Set our user flag to false.
- $this->ok = false;
-
- // Fetch all results and process the data if the row exists.
- $results = $query->fetchAll();
- if(count($results) == 1) {
- // Get the salted and hashed password stored in the database.
- $db_password = $results[0]['password'];
-
- // Salt the current password and if it matches the stored password,
- // proceed with logging in the user.
- if(md5($password . PASSWORD_SALT) == $db_password) {
-
- // Set session and cookie information.
- $_SESSION['auth_email'] = $email;
- $_SESSION['auth_secret'] = md5($results[0]['id'] . $results[0]['email']);
- setcookie("auth_email", $email, time()+60*60*24*30, "/", COOKIE_DOMAIN);
- setcookie("auth_secret", md5($results[0]['id'] . $results[0]['email']), time()+60*60*24*30, "/", COOKIE_DOMAIN);
-
- // Set local variables with the user's info.
- $this->user_id = $results[0]['id'];
- $this->name = $results[0]['name'];
- $this->email = $email;
- $this->ok = true;
- $this->is_logged = true;
-
- // Set status message.
- $this->msg = "Login Successful!";
-
- return true;
- } else {
- $this->msg = "Error! Password is incorrect.";
- }
- } else {
- $this->msg = "Error! User does not exist.";
- }
- return false;
- }
-
- /**
- * This function checks the session/cookie info to see if it's real by comparing it
- * to what is stored in the database.
- *
- * @param $email The user's email address stored in session/cookie.
- * @param $secret The user's secret hash, a combination of their user id (from DB)
- * and their email address.
- */
- function check($email, $secret) {
- global $db;
-
- // Get the user's info from the database.
- $query = $db->prepare("SELECT id, password, name FROM users WHERE email = :email");
- $query->execute([':email'=>$email]);
-
- $results = $query->fetchAll();
- if(count($results) == 1)
- {
- if(md5($results[0]['id'] . $results[0]['email']) == $secret) {
- $this->user_id = $results[0]['id'];
- $this->email = $email;
- $this->name = $results[0]['name'];
- $this->ok = true;
- $this->is_logged = true;
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check to see if the user is logged in based on their session data.
- */
- function is_logged(){
- if($this->check($_SESSION['auth_email'], $_SESSION['auth_secret'])) return true;
- else return false;
- }
-
- /**
- * Get a user's information from the database.
- *
- * @param $field The field value to retrieve (if left blank, will return complete row)
- * @param $email The user's email address. If not specified, will load current user's info.
- */
- function get_info($field = "*", $email = null){
- global $db;
-
- if(!$email) $email = $this->email;
- $query = $db->query("SELECT $field FROM users WHERE email = '$email'");
- $query->execute();
- $results = $db->fetchAll();
- if($field == "*") return $results[0];
- else return $results[0][$field];
- }
-
- /**
- * Log out the current user by setting all the local variables to their
- * default values and resetting our PHP session and cookie info.
- */
- function logout(){
- $this->user_id = 0;
- $this->email = "Guest";
- $this->name = "Guest";
- $this->ok = true;
- $this->msg = "You have been logged out!";
- $this->is_logged = false;
-
- $_SESSION['auth_email'] = "";
- $_SESSION['auth_secret'] = "";
- setcookie("auth_email", "", time() - 3600, "/", COOKIE_DOMAIN);
- setcookie("auth_secret", "", time() - 3600, "/", COOKIE_DOMAIN);
- }
-
- /**
- * Validate the user's email address.
- * Courtesy LinuxJournal.com : http://www.linuxjournal.com/article/9585?page=0,3
- *
- * @param $email The email address to validate.
- */
- function validEmail($email){
- $isValid = true;
- $atIndex = strrpos($email, "@");
- if (is_bool($atIndex) && !$atIndex){
- $isValid = false;
- }
- else{
- $domain = substr($email, $atIndex+1);
- $local = substr($email, 0, $atIndex);
- $localLen = strlen($local);
- $domainLen = strlen($domain);
- if ($localLen < 1 || $localLen > 64){
- $isValid = false;
- }else if ($domainLen < 1 || $domainLen > 255){
- $isValid = false;
- }else if ($local[0] == '.' || $local[$localLen-1] == '.'){
- $isValid = false;
- }else if (preg_match('/\\.\\./', $local)){
- $isValid = false;
- }else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)){
- $isValid = false;
- }else if (preg_match('/\\.\\./', $domain)){
- $isValid = false;
- }else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))){
- if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))){
- $isValid = false;
- }
- }
- if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){
- $isValid = false;
- }
- }
- return $isValid;
- }
+ var $user_id;
+ var $name;
+ var $email;
+ var $password;
+ var $ok;
+ var $msg;
+ var $is_logged;
+
+ /**
+ * Set all internal variables to 'Guest' status, then check to see if
+ * a user session or cookie exists.
+ */
+ function __construct(){
+ global $db;
+
+ $this->user_id = 0;
+ $this->email = "Guest";
+ $this->name = "Guest";
+ $this->ok = false;
+
+ if(!$this->check_session()) $this->check_cookie();
+
+ return $this->ok;
+ }
+
+ /**
+ * This function checks to see whether or not a PHP Session is set.
+ */
+ function check_session(){
+ if(!empty($_SESSION['auth_email']) && !empty($_SESSION['auth_secret']))
+ return $this->check($_SESSION['auth_email'], $_SESSION['auth_secret']);
+ else
+ return false;
+ }
+
+
+ /**
+ * Check to see if any cookies exist on the user's computer/browser.
+ */
+ function check_cookie(){
+ if(!empty($_COOKIE['auth_email']) && !empty($_COOKIE['auth_secret']))
+ return $this->check($_COOKIE['auth_email'], $_COOKIE['auth_secret']);
+ else
+ return false;
+ }
+
+ /**
+ * Create a user and by default, log them in once the account has been created.
+ *
+ * @param $info An array that contains the following info about the user:
+ * - name, email, password, password2 (password repeated), status (optional)
+ * @param $login Bool, whether or not to log the user in after creating account.
+ */
+ function create($info,$login = true){
+ global $db;
+
+ // Hash the password using the salt specified in config.php
+ $password = md5($info['password'] . PASSWORD_SALT);
+
+ // If user status isn't set, assume default status (1)
+ $status = $info['status'] ? $info['status'] : 1;
+
+ // Store the IP address that the user create's the account with.
+ $create_ip = $_SERVER['REMOTE_ADDR'];
+
+ // Reset flag used for error detection.
+ $this->ok = false;
+
+ // Validate all of the user input fields.
+ if(!$info['name'] || !$info['email'] || !$info['password'] || !$info['password2']){
+ $this->msg = "Error! All fields are required.";
+ return false;
+ }elseif($info['password'] != $info['password2']){
+ $this->msg = "Error! Passwords do not match.";
+ return false;
+ }elseif(!$this->validEmail($info['email'])){
+ $this->msg = "Error! Please enter a valid e-mail address.";
+ return false;
+ }
+
+ // Check to see if a user with that email address already exists.
+ $query = $db->prepare("SELECT id, password FROM users WHERE email = :email");
+ $query->execute([':email'=>$email]);
+ if($query->rowCount() == 1){
+ $this->msg = "Error! E-mail address is already in use.";
+ }else{
+ // User doesn't exist, so create a new account!
+ $query = $db->prepare("INSERT INTO users (name, email, password, status, create_ip) VALUES (:name, :email, :password, :status, :create_ip)");
+ $query->execute([':name'=>$info['name'],':email'=>$info['email'],':password'=>$password,':status'=>$status,':create_ip'=>$create_ip]);
+ $this->msg = "User successfully added.";
+ $this->ok = true;
+ if($login) $this->login($info['email'],$info['password']);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Update a user's information.
+ *
+ * @param $info An array that contains the following info about the user:
+ * - name, email, password, password2 (password repeated), status (optional)
+ */
+ function update($info) {
+ global $db;
+
+ // Reset our error detection flag, which is used to set the status message later on.
+ $this->ok = false;
+
+ // Validate email address again.
+ if(!$this->validEmail($info['email'])) {
+ $this->msg = "Error! Please enter a valid e-mail address.";
+ return false;
+ }
+
+ // Start building the SQL query with the data submitted so far.
+ $sql = "name = :name, email = :email";
+ $exec = [':name'=>$info['name'], ':email'=>$info['email']];
+
+ // If a password has been entered, validate it, re-hash it and add it to the SQL query.
+ if($info['password']){
+ if($info['password'] != $info['password2']){
+ $this->msg = "Error! Passwords do not match.";
+ return false;
+ }
+ $password = md5($info['password'] . PASSWORD_SALT);
+ $sql .= ", password = :password";
+ $exec[':password'] = $password;
+ }
+
+ // Create the finalized SQL query that will update our database.
+ $sql = "UPDATE users SET ".$sql." WHERE id = :id";
+ $exec[':id'] = $this->user_id;
+ $query = $db->prepare($sql);
+
+ // Successfully updated the user data.
+ if($query->execute($exec)) {
+ // Let the user know via a cheeky message (OK not really cheeky).
+ $this->msg = "Info successfully updated.";
+
+ // Set user status flag back to true, peace has been restored.
+ $this->ok = true;
+
+ // Set new email and password info in the session and cookies.
+ $_SESSION['auth_email'] = $email;
+ if($info['password']) $_SESSION['auth_secret'] = $password;
+ setcookie("auth_email", $email, time()+60*60*24*30, "/", COOKIE_DOMAIN);
+ if($info['password']) setcookie("auth_secret", $password, time()+60*60*24*30, "/", COOKIE_DOMAIN);
+
+ // Update local variables to reflect new changes.
+ $this->name = $info['name'];
+ $this->email = $info['email'];
+
+ return true;
+ } else {
+ // There seems to have been a problem with the query somewhere.
+ $this->msg = "There was a problem, please try again.";
+ }
+ return false;
+ }
+
+ /**
+ * Function used to let the user login, checking their email and password against
+ * what's stored in the database.
+ *
+ * @param $email The user's email address.
+ * @param $password The user's password, directly from POST.
+ */
+ function login($email, $password) {
+ global $db;
+
+ // One of the fields is missing, deliver an error message.
+ if(!$email || !$password) {
+ $this->msg = "Error! Both E-mail and Password are required to login.";
+ return false;
+ }
+
+ // Get user data using the email address supplied.
+ $query = $db->prepare("SELECT id, password, name FROM users WHERE email = :email");
+ $query->execute([':email'=>$email]);
+
+ // Set our user flag to false.
+ $this->ok = false;
+
+ // Fetch all results and process the data if the row exists.
+ $results = $query->fetchAll();
+ if(count($results) == 1) {
+ // Get the salted and hashed password stored in the database.
+ $db_password = $results[0]['password'];
+
+ // Salt the current password and if it matches the stored password,
+ // proceed with logging in the user.
+ if(md5($password . PASSWORD_SALT) == $db_password) {
+
+ // Set session and cookie information.
+ $_SESSION['auth_email'] = $email;
+ $_SESSION['auth_secret'] = md5($results[0]['id'] . $results[0]['email']);
+ setcookie("auth_email", $email, time()+60*60*24*30, "/", COOKIE_DOMAIN);
+ setcookie("auth_secret", md5($results[0]['id'] . $results[0]['email']), time()+60*60*24*30, "/", COOKIE_DOMAIN);
+
+ // Set local variables with the user's info.
+ $this->user_id = $results[0]['id'];
+ $this->name = $results[0]['name'];
+ $this->email = $email;
+ $this->ok = true;
+ $this->is_logged = true;
+
+ // Set status message.
+ $this->msg = "Login Successful!";
+
+ return true;
+ } else {
+ $this->msg = "Error! Password is incorrect.";
+ }
+ } else {
+ $this->msg = "Error! User does not exist.";
+ }
+ return false;
+ }
+
+ /**
+ * This function checks the session/cookie info to see if it's real by comparing it
+ * to what is stored in the database.
+ *
+ * @param $email The user's email address stored in session/cookie.
+ * @param $secret The user's secret hash, a combination of their user id (from DB)
+ * and their email address.
+ */
+ function check($email, $secret) {
+ global $db;
+
+ // Get the user's info from the database.
+ $query = $db->prepare("SELECT id, password, name FROM users WHERE email = :email");
+ $query->execute([':email'=>$email]);
+
+ $results = $query->fetchAll();
+ if(count($results) == 1)
+ {
+ if(md5($results[0]['id'] . $results[0]['email']) == $secret) {
+ $this->user_id = $results[0]['id'];
+ $this->email = $email;
+ $this->name = $results[0]['name'];
+ $this->ok = true;
+ $this->is_logged = true;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check to see if the user is logged in based on their session data.
+ */
+ function is_logged(){
+ if($this->check($_SESSION['auth_email'], $_SESSION['auth_secret'])) return true;
+ else return false;
+ }
+
+ /**
+ * Get a user's information from the database.
+ *
+ * @param $field The field value to retrieve (if left blank, will return complete row)
+ * @param $email The user's email address. If not specified, will load current user's info.
+ */
+ function get_info($field = "*", $email = null){
+ global $db;
+
+ if(!$email) $email = $this->email;
+ $query = $db->query("SELECT $field FROM users WHERE email = '$email'");
+ $query->execute();
+ $results = $db->fetchAll();
+ if($field == "*") return $results[0];
+ else return $results[0][$field];
+ }
+
+ /**
+ * Log out the current user by setting all the local variables to their
+ * default values and resetting our PHP session and cookie info.
+ */
+ function logout(){
+ $this->user_id = 0;
+ $this->email = "Guest";
+ $this->name = "Guest";
+ $this->ok = true;
+ $this->msg = "You have been logged out!";
+ $this->is_logged = false;
+
+ $_SESSION['auth_email'] = "";
+ $_SESSION['auth_secret'] = "";
+ setcookie("auth_email", "", time() - 3600, "/", COOKIE_DOMAIN);
+ setcookie("auth_secret", "", time() - 3600, "/", COOKIE_DOMAIN);
+ }
+
+ /**
+ * Validate the user's email address.
+ * Courtesy LinuxJournal.com : http://www.linuxjournal.com/article/9585?page=0,3
+ *
+ * @param $email The email address to validate.
+ */
+ function validEmail($email){
+ $isValid = true;
+ $atIndex = strrpos($email, "@");
+ if (is_bool($atIndex) && !$atIndex){
+ $isValid = false;
+ }
+ else{
+ $domain = substr($email, $atIndex+1);
+ $local = substr($email, 0, $atIndex);
+ $localLen = strlen($local);
+ $domainLen = strlen($domain);
+ if ($localLen < 1 || $localLen > 64){
+ $isValid = false;
+ }else if ($domainLen < 1 || $domainLen > 255){
+ $isValid = false;
+ }else if ($local[0] == '.' || $local[$localLen-1] == '.'){
+ $isValid = false;
+ }else if (preg_match('/\\.\\./', $local)){
+ $isValid = false;
+ }else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)){
+ $isValid = false;
+ }else if (preg_match('/\\.\\./', $domain)){
+ $isValid = false;
+ }else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))){
+ if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))){
+ $isValid = false;
+ }
+ }
+ if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){
+ $isValid = false;
+ }
+ }
+ return $isValid;
+ }
}
-?>
+
diff --git a/lib/views/site/about.php b/lib/views/site/about.php
index 3720f6d..3aa0e91 100644
--- a/lib/views/site/about.php
+++ b/lib/views/site/about.php
@@ -2,7 +2,7 @@
About
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod nulla non sem varius at semper libero malesuada.
-
+
Duis laoreet nibh non leo fringilla luctus. Nam vitae arcu purus, ut facilisis elit. Vivamus at purus metus, ut venenatis nisi. Sed sed sem tortor. Mauris et pellentesque odio. Phasellus sit amet velit fringilla nibh dapibus tincidunt non at metus. Integer feugiat arcu elit. Donec at elementum elit. Cras faucibus ligula a erat egestas ut volutpat neque convallis. Pellentesque pretium libero in velit suscipit in mollis orci posuere. Donec velit magna, ultrices eu tincidunt sit amet, lacinia non quam.
-
-
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam erat volutpat. Sed viverra, nisi in rhoncus varius, diam tellus placerat magna, ac pharetra quam massa tempor arcu. Mauris accumsan eros non orci lacinia laoreet. Pellentesque pretium tempor tempus.
\ No newline at end of file
+
+
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam erat volutpat. Sed viverra, nisi in rhoncus varius, diam tellus placerat magna, ac pharetra quam massa tempor arcu. Mauris accumsan eros non orci lacinia laoreet. Pellentesque pretium tempor tempus.
Sorry, we couldn't find that page. Please check the URL or try again later.
-
\ No newline at end of file
+
diff --git a/lib/views/site/terms.php b/lib/views/site/terms.php
index 9763fdf..e9103dd 100644
--- a/lib/views/site/terms.php
+++ b/lib/views/site/terms.php
@@ -1,4 +1,4 @@
Please login to view your order status or support requests.
-
+
\ No newline at end of file
+
diff --git a/lib/views/user/profile.php b/lib/views/user/profile.php
index a90f0bd..42a6bc5 100644
--- a/lib/views/user/profile.php
+++ b/lib/views/user/profile.php
@@ -1,6 +1,6 @@
Your Profile
-
+
@@ -15,4 +15,4 @@
************
- Update Information
\ No newline at end of file
+ Update Information
diff --git a/static/css/main.css b/static/css/main.css
index 6ccb53e..6c3a96c 100644
--- a/static/css/main.css
+++ b/static/css/main.css
@@ -16,4 +16,4 @@ ul.simplenav li { float: left; margin-left: 5px; }
.status { padding: 5px; border: 2px solid #ccc; background: #f3f3f3; }
.status.error { border-color: #f1e4e4; background: #fcf8f8; }
-.status.success { border-color: #e5eed7; background: #f2f7e8; }
\ No newline at end of file
+.status.success { border-color: #e5eed7; background: #f2f7e8; }