From 4125c033fc1d145203c5790739772a9835776171 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 14 Jun 2012 16:33:16 -0400 Subject: [PATCH] Simplify framework classes, add some category functionality --- app/config/config.php | 10 - app/config/routes.php | 3 + app/modules/meta/controllers/category.php | 93 +++++ app/modules/meta/controllers/section.php | 30 ++ app/modules/meta/controllers/welcome.php | 3 + app/modules/meta/models/model.php | 66 +++- app/modules/meta/models/user_model.php | 3 + app/modules/meta/views/category_detail.php | 23 ++ app/modules/meta/views/genre_detail.php | 2 +- app/modules/meta/views/index.html | 0 app/modules/meta/views/login.php | 15 + assets/css/theme.css | 8 + index.php | 20 +- phpdoc.dist.xml | 7 +- sys/common.php | 52 ++- sys/core/Controller.php | 44 +-- sys/core/MM.php | 70 ---- sys/core/Model.php | 6 +- sys/core/Output.php | 156 -------- sys/core/Page.php | 412 +++++++++++++++------ sys/core/miniMVC.php | 84 ----- sys/meta.sqlite | Bin 7168 -> 0 bytes 22 files changed, 595 insertions(+), 512 deletions(-) create mode 100644 app/modules/meta/controllers/category.php create mode 100644 app/modules/meta/controllers/section.php delete mode 100644 app/modules/meta/views/index.html create mode 100644 app/modules/meta/views/login.php delete mode 100644 sys/core/MM.php delete mode 100644 sys/core/Output.php delete mode 100644 sys/core/miniMVC.php delete mode 100644 sys/meta.sqlite diff --git a/app/config/config.php b/app/config/config.php index ea843d7..0eb3e60 100644 --- a/app/config/config.php +++ b/app/config/config.php @@ -22,16 +22,6 @@ // -------------------------------------------------------------------------- -/* -|-------------------------------------------------------------------------- -| Display Debug backtrace -|-------------------------------------------------------------------------- -| -| If set to TRUE, a backtrace will be displayed along with php errors. -| -*/ -define('SHOW_DEBUG_BACKTRACE', TRUE); - /* |-------------------------------------------------------------------------- | Base Url diff --git a/app/config/routes.php b/app/config/routes.php index 51a2b11..f3f1476 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -35,6 +35,9 @@ return array( 'default_module' => 'meta', 'genre' => 'meta/genre/index', 'genre/add' => 'meta/genre/add', + 'category' => 'meta/category/index', + 'category/add' => 'meta/category/add', + 'category/detail' => 'meta/category/detail', '404_route' => '', ); diff --git a/app/modules/meta/controllers/category.php b/app/modules/meta/controllers/category.php new file mode 100644 index 0000000..0e62ced --- /dev/null +++ b/app/modules/meta/controllers/category.php @@ -0,0 +1,93 @@ +load_model('meta\model'); + + $this->page->build_header(); + } + + /** + * Default controller method + */ + public function index() + { + $id = (int) miniMVC\get_last_segment(); + + if ($id === 0) + { + return miniMVC\show_404(); + } + + $this->detail(); + } + + /** + * Adds a new category + */ + public function add() + { + // Strip away tags for the sake of security + $name = strip_tags($_POST['category']); + $id = (int) $_POST['genre_id']; + + // Make sure the name doesn't already exist. If it does, show an error. + $res = $this->model->add_category($name, $id); + + if ($res === TRUE) + { + $this->page->set_message('success', 'Added new category'); + } + else + { + $this->page->set_message('error', 'Category already exists for this genre'); + } + + // Render the basic page + $this->index(); + } + + /** + * Returns the sections / editing options for a category + */ + public function detail() + { + $id = (int) miniMVC\get_last_segment(); + + $data = array( + 'category' => $this->model->get_category_by_id($id), + 'sections' => $this->model->get_sections($id), + 'category_id' => $id + ); + + $this->load_view('category_detail', $data); + $this->page->build_footer(); + } +} + +// End of genre.php \ No newline at end of file diff --git a/app/modules/meta/controllers/section.php b/app/modules/meta/controllers/section.php new file mode 100644 index 0000000..7260261 --- /dev/null +++ b/app/modules/meta/controllers/section.php @@ -0,0 +1,30 @@ +db->set('category', $cat) - ->set('genre_id', $genre_id) - ->insert('category'); + // Check for duplicates + $query = $this->db->from('category') + ->where('genre_id', $genre_id) + ->where('category', $cat) + ->get(); + + // Fetch the data as a workaround + // for databases that do not support + // grabbing result counts (SQLite / Firebird) + $array = $query->fetchAll(); + if (count($array) === 0) + { + $this->db->set('category', $cat) + ->set('genre_id', $genre_id) + ->insert('category'); + + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------------- @@ -253,6 +271,8 @@ class Model extends \miniMVC\Model { return $genres; } + // -------------------------------------------------------------------------- + /** * Gets the name of the genre from its id * @@ -273,6 +293,46 @@ class Model extends \miniMVC\Model { // -------------------------------------------------------------------------- + /** + * Gets the name of the category from its id + * + * @param int + * @return string + */ + public function get_category_by_id($id) + { + $query = $this->db->select('category') + ->from('category') + ->where('id', (int) $id) + ->get(); + + $row = $query->fetch(\PDO::FETCH_ASSOC); + + return $row['category']; + } + + // -------------------------------------------------------------------------- + + /** + * Gets the name of the section from its id + * + * @param int + * @return string + */ + public function get_section_by_id($id) + { + $query = $this->db->select('section') + ->from('section') + ->where('id', (int) $id) + ->get(); + + $row = $query->fetch(\PDO::FETCH_ASSOC); + + return $row['section']; + } + + // -------------------------------------------------------------------------- + /** * Get the categories for the specified genre * diff --git a/app/modules/meta/models/user_model.php b/app/modules/meta/models/user_model.php index 023837a..34e7d7b 100644 --- a/app/modules/meta/models/user_model.php +++ b/app/modules/meta/models/user_model.php @@ -22,6 +22,9 @@ namespace meta; */ class User_model extends \miniMVC\Model { + /** + * Initialize the User model + */ public function __construct() { parent::__construct(); diff --git a/app/modules/meta/views/category_detail.php b/app/modules/meta/views/category_detail.php index e69de29..e298b1e 100644 --- a/app/modules/meta/views/category_detail.php +++ b/app/modules/meta/views/category_detail.php @@ -0,0 +1,23 @@ +

meta

+

+ +

Category Sections

+ + +
" method="post"> +
+ Add Section +
+ +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/app/modules/meta/views/genre_detail.php b/app/modules/meta/views/genre_detail.php index 14639b0..dd13578 100644 --- a/app/modules/meta/views/genre_detail.php +++ b/app/modules/meta/views/genre_detail.php @@ -4,7 +4,7 @@

Genre Categories

diff --git a/app/modules/meta/views/index.html b/app/modules/meta/views/index.html deleted file mode 100644 index e69de29..0000000 diff --git a/app/modules/meta/views/login.php b/app/modules/meta/views/login.php new file mode 100644 index 0000000..cecdcca --- /dev/null +++ b/app/modules/meta/views/login.php @@ -0,0 +1,15 @@ +

meta

+

Login

+ +
+
+
+
+ +
+
+ +
 
+
+
+
\ No newline at end of file diff --git a/assets/css/theme.css b/assets/css/theme.css index 4bb1aa0..96a0191 100644 --- a/assets/css/theme.css +++ b/assets/css/theme.css @@ -8,6 +8,14 @@ html, body { margin: 0 auto; } +a { + text-decoration:none; +} + +a:hover { + text-decoration:underline; +} + /* form styles */ form dt, form dd { display:inline-block; diff --git a/index.php b/index.php index 7e564e9..7217fdf 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2011 - 2012 * @link https://github.com/aviat4ion/miniMVC - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- @@ -19,24 +19,12 @@ * @package miniMVC * @subpackage App */ - + // -------------------------------------------------------------------------- namespace miniMVC; - -// Set as either DEVELOPMENT or PRODUCTION -// DEVELOPMENT enables error reporting -// PRODUCTION disables error reporting -define('ENVIRONMENT', 'DEVELOPMENT'); -if(ENVIRONMENT == 'DEVELOPMENT') -{ - error_reporting(-1); -} -else if(ENVIRONMENT == 'PRODUCTION') -{ - error_reporting(0); -} +error_reporting(-1); // Set the default paths define('MM_BASE_PATH', __DIR__); @@ -53,4 +41,4 @@ require(MM_SYS_PATH . 'common.php'); // And away we go! init(); -// End of index.php \ No newline at end of file +// End of index.php \ No newline at end of file diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml index 8b6632b..6a7f6a2 100644 --- a/phpdoc.dist.xml +++ b/phpdoc.dist.xml @@ -1,6 +1,6 @@ - miniMVC + meta docs @@ -16,11 +16,12 @@ assets app/config app/views - sys/db/tests + sys/db tests/* assets/* - sys/db/tests/* + sys/db/* app/config/* app/views/* + */views/* \ No newline at end of file diff --git a/sys/common.php b/sys/common.php index 7e20391..2d626cb 100644 --- a/sys/common.php +++ b/sys/common.php @@ -79,7 +79,7 @@ function shutdown() $error = error_get_last(); // types of errors that are fatal - $fatal = [E_ERROR, E_PARSE, E_RECOVERABLE_ERROR]; + $fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR); // Display pretty error page if (in_array($error['type'], $fatal)) @@ -308,6 +308,9 @@ function init() // Load Database classes require_once(MM_SYS_PATH . 'db/autoload.php'); + // Load the page class + $GLOBALS['page'] = new \miniMVC\Page(); + // Map to the appropriate module/controller/function route(); } @@ -327,6 +330,40 @@ function get_last_segment() // -------------------------------------------------------------------------- +/** + * Call a method in another controller + * + * @param string + * @param string + * @param args + */ +function call_controller_method($controller, $method="index", $args=array()) +{ + // Load the routes config file + $routes = include(MM_APP_PATH . 'config/routes.php'); + + // Set the default route + $module = $routes['default_module']; + $class = $routes['default_controller']; + + // Split the controller into module/controller if possible + $parts = explode('/', $controller); + + if (count($parts) === 2) + { + list($module, $class) = $parts; + } + else + { + $class = $parts[0]; + } + + // Call the method + run($module, $class, $method, $args); +} + +// -------------------------------------------------------------------------- + /** * Gets an array of the segments of the current url * @@ -463,14 +500,17 @@ function route() return; } +// -------------------------------------------------------------------------- + /** * Instantiate the appropriate controller * * @param string * @param string * @param string + * @param array */ -function run($module, $controller, $func) +function run($module, $controller, $func, $args = array()) { $path = MM_MOD_PATH . "{$module}/controllers/{$controller}.php"; @@ -484,10 +524,13 @@ function run($module, $controller, $func) if (in_array($func, $methods)) { // Define the name of the current module for file loading - define('MM_MOD', $module); + if ( ! defined('MM_MOD')) + { + define('MM_MOD', $module); + } $class = new $controller(); - return call_user_func([&$class, $func]); + return call_user_func_array(array(&$class, $func), $args); } } @@ -495,5 +538,4 @@ function run($module, $controller, $func) show_404(); } - // End of common.php \ No newline at end of file diff --git a/sys/core/Controller.php b/sys/core/Controller.php index 5d0d6c0..f9ca849 100644 --- a/sys/core/Controller.php +++ b/sys/core/Controller.php @@ -21,7 +21,7 @@ namespace miniMVC; * @package miniMVC * @subpackage System */ -class Controller extends miniMVC { +class Controller { /** * Instance of Page class @@ -37,10 +37,8 @@ class Controller extends miniMVC { */ public function __construct() { - parent::__construct(); - // Create the page object - $this->page = new Page($this); + $this->page = $GLOBALS['page']; } // -------------------------------------------------------------------------- @@ -52,7 +50,7 @@ class Controller extends miniMVC { * @param array $args * @return void */ - public function load_model($file, $args=[]) + public function load_model($file, $args=array()) { $segments = explode('\\', $file); $file_name = end($segments); @@ -87,41 +85,9 @@ class Controller extends miniMVC { * @param bool $return * @return mixed */ - public function load_view($file, array $data=[], $return=FALSE) + public function load_view($file, array $data=array(), $return=FALSE) { - $path = ""; - - // The module is set via the router - $module = strtolower(MM_MOD); - $path = MM_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 = MM_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->page->append_output($buffer); - } + return $this->page->load_view($file, $data, $return); } } diff --git a/sys/core/MM.php b/sys/core/MM.php deleted file mode 100644 index 306f24f..0000000 --- a/sys/core/MM.php +++ /dev/null @@ -1,70 +0,0 @@ - &$value) - { - $this->$name = $value; - } - } - - // -------------------------------------------------------------------------- - - /** - * Allow calling of array methods on the object and - * dynamic methods - * - * @param string $name - * @param array $params - * @return mixed - */ - public function __call($name, $params = array()) - { - // Allow array operations on the object - if (substr($name, 0, 6) === 'array_' && is_callable($name)) - { - $args = array_merge($this->getArrayCopy(), $args); - return call_user_func_array($name, $args); - } - - // Allow dynamic method calls - if (is_callable($this->$name)) - { - //Call the dynamic function - return call_user_func_array($this->$name, $params); - } - } -} - -// End of MM.php \ No newline at end of file diff --git a/sys/core/Model.php b/sys/core/Model.php index f27bb94..d3778ee 100644 --- a/sys/core/Model.php +++ b/sys/core/Model.php @@ -8,7 +8,7 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2011 - 2012 * @link https://github.com/aviat4ion/miniMVC - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- @@ -21,7 +21,7 @@ namespace miniMVC; * @package miniMVC * @subpackage System */ -class Model extends miniMVC { +class Model extends \ArrayObject { /** * Initialize the model class @@ -31,7 +31,7 @@ class Model extends miniMVC { */ public function __construct(array $args = array()) { - parent::__construct($args); + parent::__construct($args, \ArrayObject::STD_PROP_LIST | \ArrayObject::ARRAY_AS_PROPS); } } diff --git a/sys/core/Output.php b/sys/core/Output.php deleted file mode 100644 index 383132c..0000000 --- a/sys/core/Output.php +++ /dev/null @@ -1,156 +0,0 @@ -buffer = ""; - $this->headers = array(); - } - - // -------------------------------------------------------------------------- - - /** - * PHP magic method called when ending the script - * Used for outputing HTML - * - * @return void - */ - public function __destruct() - { - if ( ! empty($this->headers)) - { - // Set headers - foreach($this->headers as $key => $val) - { - if ( ! isset($val)) - { - @header($key); - } - else - { - @header("$key: $val"); - } - } - } - - if ( ! empty($this->buffer)) - { - if (is_null(error_get_last())) - { - // Compression is good! - ob_start("ob_gzhandler"); - } - else - { - ob_start(); - } - - echo $this->buffer; - ob_end_flush(); - } - } - - // -------------------------------------------------------------------------- - - /** - * Sets a header for later output - * - * @param string $key - * @param string $val - */ - public function set_header($key, $val) - { - $this->headers[$key] = $val; - } - - // -------------------------------------------------------------------------- - - /** - * Adds text to the output buffer - * - * @param string $string - */ - public function append_output($string) - { - $this->buffer .= $string; - } - - // -------------------------------------------------------------------------- - - /** - * Sets the output buffer - * - * @param string $string - */ - public function set_output($string) - { - $this->buffer = $string; - } - - // -------------------------------------------------------------------------- - - /** - * Sends headers and then removes them - */ - public function flush_headers() - { - // Set headers - foreach ($this->headers as $key => &$val) - { - if ( ! isset($val)) - { - @header($key); - } - else - { - @header("{$key}: {$val}"); - } - } - - // Empty headers - $this->headers = array(); - } -} - -// End of Output.php \ No newline at end of file diff --git a/sys/core/Page.php b/sys/core/Page.php index 48fea5d..b3bf7e4 100644 --- a/sys/core/Page.php +++ b/sys/core/Page.php @@ -8,9 +8,9 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2011 - 2012 * @link https://github.com/aviat4ion/miniMVC - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ - + // -------------------------------------------------------------------------- namespace miniMVC; @@ -24,7 +24,7 @@ namespace miniMVC; * @package miniMVC * @subpackage System */ -class Page extends Output { +class Page { /** * Meta tags @@ -32,70 +32,83 @@ class Page extends Output { * @var string */ private $meta; - + /** * JS tags for the header * * @var string */ - private $head_js; - + private $head_js; + /** * JS tags for the footer * * @var string */ - private $foot_js; - + private $foot_js; + /** * CSS tags for the page * * @var string */ - private $css; - + private $css; + /** * Page title * * @var string */ - private $title; - + private $title; + /** * Additional header tags * * @var string */ - private $head_tags; - + private $head_tags; + /** * Class(es) to apply to the main body tag * * @var string */ - private $body_class; - + private $body_class; + /** * Id to apply to the body tag * * @var string */ - private $body_id; - + private $body_id; + /** * Base tag * * @var string */ private $base; - + + /** + * Content for outputting + * + * @var string + */ + private $buffer; + + /** + * HTTP headers to send + * + * @var array + */ + private $headers; + /** * Set up the page class * - * @param object * @return void */ - public function __construct(&$controller) + public function __construct() { $this->meta = ""; $this->head_js = ""; @@ -106,22 +119,69 @@ class Page extends Output { $this->body_class = ""; $this->body_id = ""; $this->base = ""; - - $this->mm = $controller; + $this->buffer = ""; + $this->headers = array(); } - + // -------------------------------------------------------------------------- - + /** - * call the parent destructor + * PHP magic method called when ending the script + * Used for outputing HTML + * + * @return void */ public function __destruct() { - parent::__destruct(); + if ( ! empty($this->headers)) + { + // Set headers + foreach($this->headers as $key => $val) + { + if ( ! isset($val)) + { + @header($key); + } + else + { + @header("$key: $val"); + } + } + } + + if ( ! empty($this->buffer)) + { + $errors = error_get_last(); + if (empty($errors)) + { + // Compression is good! + ob_start("ob_gzhandler"); + } + else + { + ob_start(); + } + + echo $this->buffer; + + // Check if a buffer exists + // so that it doesn't throw a notice + if (ob_get_level > 0) + { + ob_end_flush(); + } + + + } + else + { + echo 'No content'; + } } - + + // -------------------------------------------------------------------------- - + /** * Sets server headers and doctype * @@ -136,40 +196,40 @@ class Page extends Output { { $this->set_header("Cache-Control", "must-revalidate, public"); $mime = ""; - + //Variable for accept keyword $accept = ( ! empty($_SERVER['HTTP_ACCEPT'])) ? $_SERVER['HTTP_ACCEPT'] : ""; - + //Predefine doctype $doctype_string = ($html5 == TRUE) ? '' : ''; - + //Predefine charset $charset = "UTF-8"; - + $mime = "text/html"; - + if ($html5 == FALSE) { $doctype_string = ''; } - + $doctype_string .= ""; - + // finally, output the mime type and prolog type $this->set_header("Content-Type", "{$mime};charset={$charset}"); $this->set_header("X-UA-Compatible", "chrome=1, IE=edge"); $this->set_output($doctype_string); - + return $this; } - + // -------------------------------------------------------------------------- - + /** * Set Meta * * Sets meta tags, with codeigniter native meta tag helper - * + * * @param array $meta * @return Page */ @@ -178,9 +238,9 @@ class Page extends Output { $this->meta .= $this->_meta($meta); return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets minified javascript group in header * @@ -194,15 +254,15 @@ class Page extends Output { { return $this; } - + $file = SCRIPT_PATH . $group; $file .= ($debug == TRUE) ? "/debug/1" : ""; $this->head_js .= $this->script_tag($file, FALSE); return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets a minified css group * @param string $group @@ -210,18 +270,18 @@ class Page extends Output { */ public function set_css_group($group) { - $link = [ + $link = array( 'href' => STYLE_PATH . $group, 'rel' => 'stylesheet', 'type' => 'text/css' - ]; + ); $this->css .= $this->_link_tag($link); - + return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets a minified javascript group for the page footer * @@ -236,9 +296,9 @@ class Page extends Output { $this->foot_js .= $this->script_tag($file, FALSE); return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets html title string * @@ -248,14 +308,14 @@ class Page extends Output { public function set_title($title = "") { $title = ($title == "") ? DEFAULT_TITLE : $title; - + $this->title = $title; - + return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets custom body class * @@ -267,9 +327,9 @@ class Page extends Output { $this->body_class = $class; return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets custom body id * @@ -281,9 +341,9 @@ class Page extends Output { $this->body_id = $id; return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets custom base href * @@ -295,9 +355,9 @@ class Page extends Output { $this->base = $href; return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets custom css tags * @@ -310,24 +370,24 @@ class Page extends Output { { $path = CONTENT_DOMAIN; $css_file = "{$path}/css/{$name}.css"; - + if ($domain == FALSE) { $css_file = $name; } - - $this->css_tags .= $this->_link_tag([ + + $this->css_tags .= $this->_link_tag(array( 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => $media, 'href' => $css_file, - ]); - + )); + return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets a custom tag in the header * @@ -339,9 +399,9 @@ class Page extends Output { $this->head_tags .= $tag; return $this; } - + // -------------------------------------------------------------------------- - + /** * Sets custom page header * @@ -351,17 +411,17 @@ class Page extends Output { public function build_header($html5 = TRUE) { $data = array(); - + //Set Meta Tags - $this->meta = ($html5 == TRUE) - ? ''. $this->meta - : $this->_meta([ + $this->meta = ($html5 == TRUE) + ? ''. $this->meta + : $this->_meta(array( 'http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8', - ]) . $this->meta; - + )) . $this->meta; + $data['meta'] = $this->meta; - + //Set CSS if ($this->css !== "") { @@ -373,50 +433,50 @@ class Page extends Output { $this->set_css_group(DEFAULT_CSS_GROUP); $data['css'] = $this->css; } - + //Set head javascript $data['head_js'] = ( ! empty($this->head_js)) ? $this->head_js : ""; - + //Set Page Title $data['title'] = ($this->title !== '') ? $this->title : DEFAULT_TITLE; - + //Set Body Class $data['body_class'] = $this->body_class; - + //Set Body Id $data['body_id'] = $this->body_id; - + //Set Base HREF $data['base'] = $this->base; - + //Set individual head tags $data['head_tags'] = $this->head_tags; - + //Set Server Headers and Doctype $this->_headers($html5); - + //Output Header - $this->mm->load_view('header', $data); - + $this->load_view('header', $data); + return $this; } - + // -------------------------------------------------------------------------- - + /** * Builds common footer with any additional js */ public function build_footer() { $data = array(); - + $data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : ''; - - $this->mm->load_view('footer', $data); + + $this->load_view('footer', $data); } - + // -------------------------------------------------------------------------- - + /** * Script Tag * @@ -430,19 +490,19 @@ class Page extends Output { { $path = CONTENT_DOMAIN; $js_file = "{$path}/js/{$js}.js"; - + if ($domain == FALSE) { $js_file = $js; } - + $tag = ''; - + return $tag; } - + // -------------------------------------------------------------------------- - + /** * Set Message * @@ -456,26 +516,26 @@ class Page extends Output { { $data['stat_class'] = $type; $data['message'] = $message; - - return $this->mm->load_view('message', $data, $return); + + return $this->load_view('message', $data, $return); } - + // -------------------------------------------------------------------------- - + /** * Redirect 303 * * Shortcut function for 303 redirect * @param string $url */ - function redirect_303($url) + public function redirect_303($url) { $this->set_header("HTTP/1.1 303 See Other"); $this->set_header("Location:" . $url); } - + // -------------------------------------------------------------------------- - + /** * Render * @@ -483,30 +543,30 @@ class Page extends Output { * @param string $view * @param array $data */ - function render($view, $data=array()) + public function render($view, $data=array()) { $this->build_header(); - $this->mm->load_view($view, $data); + $this->load_view($view, $data); $this->build_footer(); } - + // -------------------------------------------------------------------------- - + /** * Output String * * Similar to render(), this is a shortcut - * to output a string in the body of the + * to output a string in the body of the * page. * @param string $string */ - function output_string($string) + public function output_string($string) { $this->build_header(); $this->append_output($string); $this->build_footer(); } - + // -------------------------------------------------------------------------- /** @@ -518,17 +578,17 @@ class Page extends Output { private function _meta($params) { $string = " &$v) { $string .= $k.'="'.$v.'" '; } - + $string .= " />"; - + return $string; } - + // -------------------------------------------------------------------------- /** @@ -536,20 +596,128 @@ class Page extends Output { * * @param array $params * @return string - */ + */ private function _link_tag($params) { $string = " &$v) { $string .= $k . '="'.$v.'" '; } - + $string .= "/>"; - + return $string; } + + // -------------------------------------------------------------------------- + + /** + * Function for loading a view + * + * @param string $file + * @param array $data + * @param bool $return + * @return mixed + */ + public function load_view($file, array $data=array(), $return=FALSE) + { + $path = ""; + + // The module is set via the router + $module = strtolower(MM_MOD); + $path = MM_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 = MM_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->append_output($buffer); + } + } + + // -------------------------------------------------------------------------- + + /** + * Sets a header for later output + * + * @param string $key + * @param string $val + */ + public function set_header($key, $val) + { + $this->headers[$key] = $val; + } + + // -------------------------------------------------------------------------- + + /** + * Adds text to the output buffer + * + * @param string $string + */ + public function append_output($string) + { + $this->buffer .= $string; + } + + // -------------------------------------------------------------------------- + + /** + * Sets the output buffer + * + * @param string $string + */ + public function set_output($string) + { + $this->buffer = $string; + } + + // -------------------------------------------------------------------------- + + /** + * Sends headers and then removes them + */ + public function flush_headers() + { + // Set headers + foreach ($this->headers as $key => &$val) + { + if ( ! isset($val)) + { + @header($key); + } + else + { + @header("{$key}: {$val}"); + } + } + + // Empty headers + $this->headers = array(); + } } // End of page.php \ No newline at end of file diff --git a/sys/core/miniMVC.php b/sys/core/miniMVC.php deleted file mode 100644 index 8899538..0000000 --- a/sys/core/miniMVC.php +++ /dev/null @@ -1,84 +0,0 @@ -ir7biK?7TGdAtZIX#69F>yhJHxu1#!>w!1m+ z&^PG|j6TC&V6aChy-s%Qt~P0*%_&5}vgFVDKK;L+ENtBW+O-)aW6wXc7-@h4fDn8p z1OTwctHP_qD@^)Po0fbBjOX zSGduDVJD7h#(YfA8JYWg_5Hn1_4*u>l!>j*88HXV(~tIpbty-pL=gl8ffXfC;dw)J z3-}?5ARq{=0)Y}l7{;FgaXN53e7fFQ7f1S;qbAan!JU-TQ@pkFJ9K%^`PEH43c zw=N^_vGs+tJja>+wR%-V;9bkHsmn;)9ee8%AJO;5?A-Dx>Cnr7=Ub{8G+^TWzr0H? VlnVlj5)k`;QG&u>5LjLU{{R8_9%%po