-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change layout so upgrades to system components are easy
- Loading branch information
1 parent
2be0bce
commit 8443ec0
Showing
21 changed files
with
1,282 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2010 Allyn Bauer | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
<?php | ||
|
||
?> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
<?php | ||
require_once("userdata.php"); | ||
|
||
// We extend the UserData class to seperate local changes | ||
// from the global validator | ||
class App_UserData extends UserData { | ||
/* define your custom validators here */ | ||
|
||
/* | ||
function deliverPackage() { | ||
$data = new OpenStruct(); | ||
$data->winsauce = $this->getWinSauce(); | ||
return $data; | ||
// etcs | ||
} | ||
*/ | ||
} | ||
?> |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
class FlashHelper { | ||
function __construct() { | ||
// flashes need a default array to keep track of existing flashes | ||
// that way we don't have to know what they are called, we just pull them out of here | ||
if (!isset($_SESSION['flash'])) { | ||
$_SESSION['flash'] = array(); | ||
} | ||
} | ||
|
||
// return the currently registered flashes | ||
function get_list() { | ||
return array_keys($_SESSION['flash']); | ||
} | ||
|
||
// true if name exists, false if not | ||
function exists($name) { | ||
return in_array($name, $this->get_list()); | ||
} | ||
|
||
// render as HTML | ||
function render() { | ||
$contents = array(); | ||
$count = 0; | ||
foreach($this->get_list() as $name) { | ||
$count++; | ||
$contents[] = "<div id='flash_$count' class='flash $name'><span>{$this->$name}<span></div>"; | ||
} | ||
return implode("\n", $contents); | ||
} | ||
|
||
function __set($name, $value) { | ||
$_SESSION['flash'][$name] = $value; | ||
} | ||
|
||
function __get($name) { | ||
if ($this->exists($name)) { | ||
$contents = $_SESSION['flash'][$name]; | ||
unset($_SESSION['flash'][$name]); | ||
|
||
return $contents; | ||
} else { | ||
return FALSE; | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
//Turn magic quotes off! | ||
ini_set('magic_quotes_gpc', 'off'); | ||
ini_set('magic_quotes_runtime', 'off'); | ||
|
||
define('SYSTEM_ROOT', dirname(dirname(__FILE__))); | ||
$__system__ = constant('SYSTEM_ROOT') . '/system'; | ||
$__lib__ = constant('SYSTEM_ROOT') . '/lib'; | ||
|
||
require_once("$__system__/userdata.php"); | ||
require_once("$__lib__/userdata_app.php"); | ||
$getData = new App_UserData('GET'); | ||
$postData = new App_UserData('POST'); | ||
|
||
// flash! longer then a blink and shorter then a moment | ||
require_once("$__system__/flash.php"); | ||
session_start(); | ||
$flash = new FlashHelper(); | ||
|
||
// SYSTEM FILES | ||
require_once("$__system__/openstruct.php"); | ||
require_once("$__system__/sys.php"); | ||
require_once("$__system__/path_manager.php"); | ||
require_once("$__system__/system_functions.php"); | ||
|
||
// LIB FILES | ||
require_once("$__lib__/database.php"); | ||
require_once("$__lib__/user_functions.php"); | ||
require_once("$__lib__/helpers.php"); | ||
|
||
// SYSTEM USE VARIABLES | ||
$content = ''; // content to render | ||
$data = new OpenStruct(); // data mapped to rendering view | ||
$_error_count = 0; // count of fatal app errors | ||
template('template'); // set the default template | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
class OpenStruct { | ||
private $_data = array(); | ||
|
||
function __set($name, $value) { | ||
$this->_data[$name] = $value; | ||
} | ||
|
||
function __get($name) { | ||
$obj = $this->_data[$name]; | ||
if (!$obj) $obj = FALSE; | ||
return $obj; | ||
} | ||
|
||
function as_ary() { | ||
return $this->_data; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
class PathManager { | ||
function __construct($url) { | ||
$this->url = $this->remove_base_url($url); | ||
} | ||
|
||
function build_route() { | ||
$url = $this->url; // this method is non-destructive of object state | ||
$controller = array_shift($url); | ||
$klass = $this->controller_instance($controller); | ||
$route = NULL; | ||
|
||
// attempt to build a path | ||
if (isset($klass->routes)) { | ||
$routes = $klass->routes; | ||
foreach($routes as $method => $sequence) { | ||
$params = $this->match($sequence); | ||
if ($params) { | ||
$route = new OpenStruct(); | ||
$route->controller = $controller; | ||
$route->action = $method; | ||
$route->params = $params; | ||
} | ||
} | ||
} | ||
|
||
if (empty($route)) { | ||
$route = $this->build_generic_route(); | ||
} | ||
|
||
return $route; | ||
} | ||
|
||
function remove_base_url($url) { | ||
$url = explode('/', $url); | ||
$base = explode('/', constant('WEB_ROOT')); | ||
foreach($base as $bit) { | ||
if ($url[0] == $bit) { | ||
array_shift($url); | ||
} else { | ||
/* error */ | ||
} | ||
} | ||
return $url; | ||
} | ||
|
||
// |route| is the route we're testing matches for | ||
function match($route) { | ||
$base = explode('/', CONSTANT('WEB_ROOT')); | ||
$parts = $this->remove_base_url($route); | ||
$url = $this->url; | ||
|
||
// this method is supposed to route a controller, so we already know what it is | ||
array_shift($url); | ||
|
||
$params = array(); | ||
|
||
if (count($url) === 1 && $url[0] === '') { // route matches '$controller/' (index action) | ||
return $params; | ||
} | ||
|
||
// handle this match | ||
foreach($parts as $piece) { | ||
$url_part = array_shift($url); | ||
if (strpos($piece, ':') === 0) { // style is ':token' | ||
$params[preg_replace('/:/', '', $piece)] = $url_part; | ||
} elseif($url_part != $piece) { | ||
return FALSE; | ||
} | ||
} | ||
if (!empty($params)) return $params; | ||
return FALSE; | ||
} | ||
|
||
// build and return the path parameters | ||
function build_generic_route() { | ||
$parts = $this->url; | ||
$route = new OpenStruct(); | ||
|
||
$controller = array_shift($parts); | ||
if ($controller == '') $controller = 'app'; | ||
|
||
$action = array_shift($parts); | ||
if ($action == '') $action = 'index'; | ||
|
||
$route->controller = $controller; | ||
$route->action = $action; | ||
$route->params = $parts; | ||
|
||
return $route; | ||
} | ||
|
||
// return an instance of the |name| controller, or FALSE if there wasn't one | ||
function controller_instance($name) { | ||
$controller_path = $this->controller_path($name); | ||
$klass = null; | ||
if (file_exists($controller_path)) { | ||
require_once($controller_path); | ||
$klass = ucfirst($name) . 'Controller'; | ||
$klass = new $klass(); | ||
} else { | ||
return FALSE; | ||
} | ||
return $klass; | ||
} | ||
|
||
function controller_path($name) { | ||
return CONSTANT('SYSTEM_ROOT') . "/controllers/$name" . "_controller.php"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/* | ||
Sys is a generic wrapper for global variables. It lets us access global variables in | ||
daughter scopes without having to use $_GLOBALS or 'global'. | ||
t is used like this: | ||
sys()->|global|->|action| | ||
Where |global| is the global identifier. | ||
*/ | ||
|
||
class Sys { | ||
function __get($name) { | ||
global $$name; | ||
return $$name; | ||
} | ||
} | ||
|
||
function sys() { | ||
global $sys; | ||
return $sys; | ||
} | ||
|
||
$sys = new Sys(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* THIS FILE IS FOR FUNCTIONS THAT THE SYSTEM USES AT A CORE LEVEL. | ||
*/ | ||
|
||
// return the contents of a view associated with |name| | ||
function get_view($name) { | ||
$path = CONSTANT('SYSTEM_ROOT') . "/views/$name.php"; | ||
if (!file_exists($path)) return FALSE; | ||
return file_get_contents($path); | ||
} | ||
|
||
// render the template with the current |view| | ||
function render($path) { | ||
$view = $path->controller . '/' . $path->action; | ||
sys()->_view = $view; | ||
$template = get_view($view); | ||
if ($template !== false) sys()->content = $template; // if there's a view file, save it | ||
sys()->data->web_root = constant('WEB_ROOT'); | ||
ob_start(); | ||
|
||
// apply the info in $data in this scope so they can be accsesed in the views | ||
foreach(sys()->data->as_ary() as $key => $val) { | ||
$$key = $val; | ||
} | ||
|
||
// eval the view | ||
eval('?>' . sys()->content . '<?'); | ||
sys()->content = ob_get_contents(); | ||
ob_end_clean(); | ||
require_once(CONSTANT('SYSTEM_ROOT') . '/views/' . sys()->_TEMPLATE); | ||
} |
Oops, something went wrong.