From 21e2c997ce4793036ca408db5509d5182f83290f Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Tue, 7 Jul 2009 00:57:26 +0000 Subject: [PATCH] Commiting changes before I go trying to implement PHPUnit. git-svn-id: http://svn.cleancode.org/svn/pickles@138 4d10bc64-7434-11dc-a737-d2d0f8310089 --- classes/Controller.php | 36 ++++++++++++++++++++++++++---------- classes/DB.php | 16 +++++++++++++++- classes/Display/Smarty.php | 11 +++-------- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/classes/Controller.php b/classes/Controller.php index 3edfb18..d242ade 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -29,7 +29,7 @@ * * The heavy lifter of PICKLES, makes the calls to get the session and * configuration loaded. Loads modules, serves up user authentication when - * the module asks for it, and loads the viewer that the module has requested. + * the module asks for it, and loads the viewer that the module requested. * Default values are present to make things easier on the user. * * @usage new Controller($config); @@ -46,7 +46,7 @@ class Controller extends Object { */ public function __construct($config = null) { parent::__construct(); - + // Creates the core objects that don't need a Config object $error = new Error(); @@ -93,9 +93,15 @@ class Controller extends Object { exit("

{$_SERVER['SERVER_NAME']} is currently down for maintenance

"); } - // Grab the passed in module or use the default - #$module_name = isset($_REQUEST['module']) ? strtr($_REQUEST['module'], '-', '_') : $config->getDefaultModule(); - $module['requested']['name'] = isset($_REQUEST['module']) ? $_REQUEST['module'] : $config->getDefaultModule(); + // Loads the default module + $module['requested']['name'] = $config->getDefaultModule(); + + // Attempts to override the default module + if (isset($_REQUEST['module'])) { + if (strpos($config->templates->main, $_REQUEST['module']) !== 0) { + $module['requested']['name'] = $_REQUEST['module']; + } + } // Checks if we have a display type passed in if (strpos($module['requested']['name'], '.') !== false) { @@ -116,10 +122,11 @@ class Controller extends Object { } /** - * @todo Maybe the logout shouldn't be an internal thing, what if the - * user wanted to call the logout page something else? or better - * yet, they want to next it, like /users/logout? - * @todo May want to make it work from /store/admin/logout and not just from / + * @todo Maybe the logout shouldn't be an internal thing, what if + * the user wanted to call the logout page something else? or + * better yet, they want to next it, like /users/logout? + * @todo May want to make it work from /store/admin/logout and not + * just from / */ if ($module['requested']['name'] == 'logout') { $security = new Security($config, $db); @@ -206,16 +213,25 @@ class Controller extends Object { } } - // If the loaded module has a name, use it to override + // Overrides the name and filename with the passed name if ($module['object']->name != null && $module['requested']['filename'] != $module['object']->name) { $module['requested']['filename'] = $module['object']->name; $module['requested']['name'] = $module['object']->name; } + // Overrides the filename with the passed template if ($module['object']->template != null) { $module['requested']['filename'] = $module['object']->template; } + // Overrides the shared template information with the passed shared template + if ($module['object']->shared_template != null) { + $module['shared']['class_name'] = $module['object']->shared_template; + $module['shared']['filename'] = strtr($module['shared']['class_name'], '_', '/'); + $module['shared']['php_file'] = PICKLES_PATH . 'common/modules/' . $module['shared']['filename'] . '.php'; + $module['shared']['name'] = $module['shared']['filename']; + } + // Sets the display's properties $display->module_name = $module['requested']['name']; $display->module_filename = $module['requested']['filename']; diff --git a/classes/DB.php b/classes/DB.php index 8faa5c4..4584a08 100755 --- a/classes/DB.php +++ b/classes/DB.php @@ -310,7 +310,21 @@ class DB extends Object { if (trim($table) != '') { if (is_array($values)) { foreach ($values as $key => $value) { - $values[$key] = $value == null ? 'NULL' : "'" . mysql_real_escape_string(stripslashes($value), $this->connection) . "'"; + switch ($value) { + case null: + $value = 'NULL'; + break; + + case 'NOW()': + $value = 'NOW()'; + break; + + default: + $value = "'" . mysql_real_escape_string(stripslashes($value), $this->connection) . "'"; + break; + } + + $values[$key] = $value; } $this->execute(" diff --git a/classes/Display/Smarty.php b/classes/Display/Smarty.php index b72448e..e955692 100644 --- a/classes/Display/Smarty.php +++ b/classes/Display/Smarty.php @@ -27,7 +27,7 @@ /** * Smarty Display * - * Displays the associated Smarty templates for the Model. + * Displays the associated Smarty templates for the Module. * * @link http://smarty.net/ */ @@ -94,13 +94,8 @@ class Display_Smarty extends Display_Common { $template = SITE_PATH . '../templates/' . $this->module_filename . '.tpl'; if (!file_exists($template)) { - $shared_template = PICKLES_PATH . 'common/templates/' . ($this->shared_module_filename == false ? $this->module_filename : $this->shared_module_filename) . '.tpl'; - // $shared_template = PICKLES_PATH . 'common/templates/' . ($this->shared_filname == false ? $this->module_filename : $this->shared_filename) . '.tpl'; - - // @todo SUPER HACKINSHIT - if (strstr($this->module_filename, 'store/admin')) { - $shared_template = PICKLES_PATH . 'common/templates/store/admin.tpl'; - } + + $shared_template = PICKLES_PATH . 'common/templates/' . ($this->shared_module_filename == false || $this->template_override == true ? $this->module_filename : $this->shared_module_filename) . '.tpl'; if (file_exists($shared_template)) { $template = $shared_template;