From bd1a484f2b99ed8feba6fdce9b7f62c991d362ac Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 11 Jan 2012 14:49:26 -0500 Subject: [PATCH] More header comments\! --- app/config/config.php | 13 +++++++++ app/config/db.php | 12 ++++++++ app/config/routes.php | 12 ++++++++ assets/css.php | 16 +++++++++++ assets/js.php | 17 +++++++++++ sys/db.php | 32 ++++++--------------- sys/miniMVC.php | 61 ++++++++++++++++++++++++++++++++++++++- sys/output.php | 32 +++++++++++++-------- sys/page.php | 66 ++++--------------------------------------- 9 files changed, 164 insertions(+), 97 deletions(-) diff --git a/app/config/config.php b/app/config/config.php index 6c3eca0..e84a638 100644 --- a/app/config/config.php +++ b/app/config/config.php @@ -1,4 +1,17 @@ array( diff --git a/app/config/routes.php b/app/config/routes.php index 75675ed..639b82f 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -1,4 +1,16 @@ PDO::ERRMODE_EXCEPTION, ); - if( ! isset($persist)) - { - unset($opts[PDO::ATTR_PERSISTENT]); - } - $options = $opts + $options; - - try - { - parent::__construct($dsn, $user, $pass, $options); - } - catch(Exception $e) - { - if($e->getMessage() !== "The auto-commit mode cannot be changed for this driver") - { - get_last_error(); - } - } - + + // Let's try connecting now! + parent::__construct($dsn, $user, $pass, $options); + } // -------------------------------------------------------------------------- diff --git a/sys/miniMVC.php b/sys/miniMVC.php index c9e55fa..45c3bca 100644 --- a/sys/miniMVC.php +++ b/sys/miniMVC.php @@ -12,10 +12,15 @@ // -------------------------------------------------------------------------- +/** + * There should be a generic "Object" class, stdClass is dumb + */ +class Object extends stdClass {} + /** * Parent class of base class, contains much of the magic */ -class JSObject { +class JSObject extends Object{ /** * Constructor for creating the objects @@ -353,6 +358,60 @@ class MM_Controller extends miniMVC { $this->$file = new $file; } } + + /** + * Function for loading a view + * + * @param string $file + * @param array $data + * @return mixed + */ + function load_view($file, $data, $return=FALSE) + { + $path = ""; + + // The module is the lower of the class name + // need to figure out a way to allow multiple controllers + // in one module + $module = strtolower(get_class($this)); + + $not_modules = array('miniMVC', 'page', 'db', 'output'); + + // If it's a module, look in the module view folder + if( ! in_array($module, $not_modules)) + { + $path = MOD_PATH . "{$module}/views/{$file}.php"; + } + + // If it's not a module, or doesn't exist in the module view folder + // look in the app view folder + if( ! is_file($path)) + { + $path = APP_PATH . "views/{$file}.php"; + } + + // Contain the content for buffering + ob_start(); + + // Extract the data array + extract($data); + + // Include the file + include($path); + + $buffer = ob_get_contents(); + ob_end_clean(); + + if($return == TRUE) + { + return $buffer; + } + else + { + $this->output->append_output($buffer); + } + + } } // -------------------------------------------------------------------------- diff --git a/sys/output.php b/sys/output.php index a8f7a55..87353f2 100644 --- a/sys/output.php +++ b/sys/output.php @@ -38,24 +38,32 @@ class Output extends JSObject{ // Set headers foreach($this->headers as $key => $val) { - if( ! empty( $key or $val)) + if( ! isset($val)) { - if( ! isset($val)) - { - @header($key); - } - else - { - @header("$key: $val"); - } - } + @header($key); + } + else + { + @header("$key: $val"); + } } } if( ! empty($this->buffer)) { - // Compression is good! - ob_start("ob_gzhandler"); + if(function_exists('error_get_last')) + { + if(is_null(error_get_last())) + { + // Compression is good! + ob_start("ob_gzhandler"); + } + } + else + { + ob_start(); + } + echo $this->buffer; ob_end_flush(); } diff --git a/sys/page.php b/sys/page.php index 41316a1..cedda35 100644 --- a/sys/page.php +++ b/sys/page.php @@ -34,8 +34,8 @@ class Page $this->body_id = ""; $this->base = ""; - $mm =& miniMVC::get_instance(); - $this->output =& $mm->output; + $this->mm =& miniMVC::get_instance(); + $this->output =& $this->mm->output; } // -------------------------------------------------------------------------- @@ -352,7 +352,7 @@ class Page $this->_headers($xhtml, $html5); //Output Header - $this->load_view('header', $data); + $this->mm->load_view('header', $data); return $this; } @@ -369,7 +369,7 @@ class Page $data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : ''; - $this->load_view('footer', $data); + $this->mm->load_view('footer', $data); } // -------------------------------------------------------------------------- @@ -411,7 +411,7 @@ class Page $data['stat_class'] = $type; $data['message'] = $message; - return $this->load_view('message', $data, $return); + return $this->mm->load_view('message', $data, $return); } // -------------------------------------------------------------------------- @@ -440,7 +440,7 @@ class Page function render($view, $data=array()) { $this->build_header(); - $this->load_view($view, $data); + $this->mm->load_view($view, $data); $this->build_footer(); } @@ -502,60 +502,6 @@ class Page return $string; } - - /** - * Function for loading a view - * - * @param string $file - * @param array $data - * @return mixed - */ - function load_view($file, $data, $return=FALSE) - { - $path = ""; - - // The module is the lower of the class name - // need to figure out a way to allow multiple controllers - // in one module - $module = strtolower(get_class($this)); - - $not_modules = array('miniMVC', 'page', 'db', 'output'); - - // If it's a module, look in the module view folder - if( ! in_array($module, $not_modules)) - { - $path = MOD_PATH . "{$module}/views/{$file}.php"; - } - - // If it's not a module, or doesn't exist in the module view folder - // look in the app view folder - if( ! is_file($path)) - { - $path = APP_PATH . "views/{$file}.php"; - } - - // Contain the content for buffering - ob_start(); - - // Extract the data array - extract($data); - - // Include the file - include($path); - - $buffer = ob_get_contents(); - ob_end_clean(); - - if($return == TRUE) - { - return $buffer; - } - else - { - $this->output->append_output($buffer); - } - - } } // End of page.php \ No newline at end of file