Skip to content

Commit

Permalink
Extensions + mysqli conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Hoffman committed Mar 11, 2016
1 parent 4387e71 commit f5de490
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 79 deletions.
39 changes: 6 additions & 33 deletions crumb/MVC/class.controller.php
Expand Up @@ -13,9 +13,6 @@ class controller extends crumbMVC {
/* The view class we'll have attached at our controller's hip */
private $view;

/* Was this controller cleared */
private $cleared;

/* __construct
* When the class fires up we want to show any layout stuff right off
*/
Expand All @@ -33,28 +30,25 @@ public function __construct() {
* This is the function crumbMVC calls after it calls the action method
*/
public function __tail() {
if(isset($this->layout_bottom) && !$this->cleared) {
if(isset($this->layout_bottom)) {
/* If there are bottom layouts to show, show them */
$this->view->loadLayout($this->layout_bottom, $this->layout_vars);
}
if(!$this->cleared) $this->view->showSaved();
}

/* load
* load a new model and instantiate it with the name of the model as the
* property name
* @param string $model The name of the model
*/
public function load($model, $name = null) {
public function load($model) {
global $APP_MODELS;
try {
/* Include the model first */
$this->includeModel($model, $APP_MODELS, true);
$model = $this->getPieceName($model);
/* Then instantiate it */
if($name == null) $name = $model;
else $name = $name;
$this->$name = new $model;
$this->$model = new $model;
} catch(Exception $e) {
throw $e;
}
Expand All @@ -66,29 +60,8 @@ public function load($model, $name = null) {
* @param array $vars The variables we want to acces in our view
*/
protected function show($view, $vars = null) {
$this->view->saveVariables($vars);
$this->view->save($view);
}

protected function run($controller, $paramaters = null, $action = '__index') {
$this->view->clearSaved();
$this->cleared = true;

$route_exists = true;
if(!$this->controllerExists($controller) ||
!$this->actionExists($controller, $action)) {
$route_exists = false;
}
/* If the route doesn't exist, and we're in production mode show the 404
* controller
*/
if(!$route_exists && CRUMB_MODE) {
$controller = CONTROLLER_404;
$action = ACTION_404;
}
/* Include and load our controller / action with the paramaters in tow */
$this->includeController($controller);
$this->loadController($controller, $action, $paramaters);
$this->view->setVariables($vars);
$this->view->load($view);
}
}
?>
15 changes: 8 additions & 7 deletions crumb/MVC/class.crumbMVC.php
Expand Up @@ -35,13 +35,13 @@ public function __construct($scan_controllers=false,
/* Find controllers, models, and views if applicable */
if($scan_controllers) {
$this->scrubTree(APP_BUILD_ROOT.DS.'controllers',
&$APP_CONTROLLERS);
$APP_CONTROLLERS);
}
if($scan_models) {
$this->scrubTree(APP_BUILD_ROOT.DS.'models', &$APP_MODELS, '/');
$this->scrubTree(APP_BUILD_ROOT.DS.'models', $APP_MODELS, '/');
}
if($scan_views) {
$this->scrubTree(APP_BUILD_ROOT.DS.'views', &$APP_VIEWS, '/');
$this->scrubTree(APP_BUILD_ROOT.DS.'views', $APP_VIEWS, '/');
}
}

Expand Down Expand Up @@ -99,6 +99,7 @@ private function includePiece($piece, $PIECES, $type='controller') {
/* The filename based on the piece name */
$file = trim($piece, DS);
/* If the file name is a key in the $PIECES array */

if(in_array($file, array_keys($PIECES))) {
/* Then the actual file path we're looking for becomes apparent,
* require it
Expand Down Expand Up @@ -206,6 +207,7 @@ public function loadSupport($file) {
/* $file will be an array because it should have been processed by the
* routing class
*/

if(is_array($file)) {
/* Build the actual file name from the array */
$file_name = '';
Expand All @@ -228,8 +230,7 @@ public function loadSupport($file) {
/* read the file off, this prevents against the browser
* prompting a download
*/
if(!mimeType::isTextType($mime_type)) readfile($file);
else require_once($file);
readfile($file);
exit();
}
}
Expand All @@ -254,11 +255,11 @@ private function scrubTree($dir, &$store, $path='') {
/* If it is, and it's not hidden */
if(!empty($path)) {
/* Recursive call, adding to the $path */
$this->scrubTree($dir_path, &$store,
$this->scrubTree($dir_path, $store,
trim($path.DS.$dir_name, DS));
} else {
/* Recursive call, ignoring the $path */
$this->scrubTree($dir_path, &$store, $sdir);
$this->scrubTree($dir_path, $store, $sdir);
}
}
/* If it's a file, not a directory */
Expand Down
7 changes: 0 additions & 7 deletions crumb/MVC/class.mimeType.php
Expand Up @@ -89,17 +89,10 @@ public function getMimeType($filename) {
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
} elseif(function_exists('system')) {
$type = system(trim('file -bi '.escapeshellarg($f)));
return $type;
} else {
/* Otherwise, let the browser guess */
return 'application/octet-stream';
}
}

public function isTextType($type) {
return in_array($type, array('text/html', 'text/css', 'application/javascript'));
}
}
?>
28 changes: 2 additions & 26 deletions crumb/MVC/class.view.php
Expand Up @@ -16,30 +16,6 @@ class view extends crumbMVC {
private $crumb_var_names = array('APP_CONTROLLERS',
'APP_MODELS',
'APP_VIEWS');
private $views = array();
private $vars = array();

public function save($view) {
$this->views[] = $view;
}

public function saveVariables($vars) {
$this->vars[] = $vars;
}

public function showSaved() {
foreach($this->vars as $vars) {
$this->setVariables($vars);
}
foreach($this->views as $view) {
$this->load($view);
}
}

public function clearSaved() {
$this->views = array();
$this->vars = array();
}

/* load
* load up a view
Expand Down Expand Up @@ -73,8 +49,8 @@ public function load($view) {
public function loadLayout($layout, $vars) {
if(!empty($layout)) {
foreach($layout as $file) {
$this->saveVariables($vars);
$this->save($file);
$this->setVariables($vars);
$this->load($file);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crumb/routing/class.routing.php
Expand Up @@ -23,6 +23,8 @@ class routing {

/* The URI exploded by DS */
private $path;
/* The request URI */
public $request;
/* Where is the routs file located your our app */
private $routes_file;
/* The paramaters end of the URI */
Expand Down Expand Up @@ -70,6 +72,7 @@ public function breakURI($URI, $base) {
}
/* Get that route back from $routeAndParams */
$break_URI = $routeAndParams[0];
$this->request = $break_URI;
if(is_array($routes)) {
foreach($routes as $alias => $route) {
/* For all the routes in routes.php find the aliases
Expand Down
8 changes: 4 additions & 4 deletions crumb/unload.php
Expand Up @@ -4,8 +4,6 @@
* Copyleft: Dustin Hoffman, 2009
* Contact: dustin.hoffman@breefield.com
*/

session_start();

/* Basic package for including controller, model, and view classes */
require_once('MVC/class.crumbMVC.php');
Expand All @@ -25,12 +23,15 @@
define('APP_BUILD_ROOT', FS_ROOT.trim(BASE_URL.DS, DS).DS.trim(APP_ROOT, DS));
/* If you need to call something from the root of your appliction space */
function root() { return rtrim(ROOT.trim(BASE_URL, DS), DS).DS; }
function assets() { return root().'assets/'; }

/* Create a routing object and pass it our URI so we can get the controller
* action, and paramaters passed in our URI
*/
$routing = new routing(APP_BUILD_ROOT);
$route = $routing->breakURI($_SERVER['REQUEST_URI'], BUILD_URI);
define('REQUEST', $routing->request);
function self() { return root().trim(REQUEST, DS); }
$controller = $routing->getControllerName();
$action = $routing->getActionName();
$paramaters = $routing->getParamaters();
Expand All @@ -42,7 +43,6 @@ function root() { return rtrim(ROOT.trim(BASE_URL, DS), DS).DS; }
* file)
*/
$crumb_mvc->loadSupport($route);

/* Check to see if the route passed in the URI actually pertains to files
* that exist in our app
*/
Expand All @@ -51,6 +51,7 @@ function root() { return rtrim(ROOT.trim(BASE_URL, DS), DS).DS; }
!$crumb_mvc->actionExists($controller, $action)) {
$route_exists = false;
}

/* If the route doesn't exist, and we're in production mode show the 404
* controller
*/
Expand All @@ -62,7 +63,6 @@ function root() { return rtrim(ROOT.trim(BASE_URL, DS), DS).DS; }
$crumb_mvc->includeController($controller);
$crumb_mvc->loadController($controller, $action, $paramaters);
} catch(Exception $e) {

/* This is the error output section of CRUMB, feel free to change
* FUTURE ADDITION: Log to file in CRUMB directory
*/
Expand Down
8 changes: 6 additions & 2 deletions index.php
Expand Up @@ -3,7 +3,7 @@
/* Leave this empty if you'll be developing from the root of your website
* or webapp.
*/
define('BASE_URL', '');
define('BASE_URL', 'bm-timelapse');

/* This is where *your* folders and files sit, leave it blank if they are
* directly adjacent to CRUMB_DIR
Expand Down Expand Up @@ -35,7 +35,11 @@
define('ACTION_404', 'is404');

/* Error display mode */
define('CRUMB_MODE', 0);
define('CRUMB_MODE', 1);
error_reporting(E_ALL);

/* Include Path */
set_include_path(get_include_path().PATH_SEPARATOR.'./'.PATH_SEPARATOR.'./'.APP_ROOT);

/* This brings everything together */
require_once(CRUMB_DIR.'/unload.php');
Expand Down

0 comments on commit f5de490

Please sign in to comment.