diff --git a/classes/Config.php b/classes/Config.php index ca787ea..abeec3f 100755 --- a/classes/Config.php +++ b/classes/Config.php @@ -199,9 +199,9 @@ class Config extends Object { $additional = null; - if (strpos($requested_module, '/') !== false) { - list($requested_module, $additional) = split('/', $requested_module, 2); - $additional = '/' . $additional; + if (strpos($requested_module, '_') !== false) { + list($requested_module, $additional) = split('_', $requested_module, 2); + $additional = '_' . $additional; } if (isset($this->modules->shared->module)) { @@ -219,7 +219,8 @@ class Config extends Object { } } - return 'home'; + return false; + //return 'home'; } /** diff --git a/classes/Controller.php b/classes/Controller.php index 0319387..96cc66e 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -107,45 +107,31 @@ class Controller extends Object { } else { // Loads the requested module's information - $module_file = '../modules/' . $module_name . '.php'; - - /** - * @todo Rename "section" to something like "current" or "selected" - * @todo Figure out WTF "event" is being used for - */ - if (strpos($module_name, '/') === false) { - $class = $module_name; - $section = $module_name; - $event = null; - } - else { - $class = strtr($module_name, '/', '_'); - list($section, $event) = split('/', $module_name); - } + $module_filename = $module_name; + $module_file = '../modules/' . $module_filename . '.php'; + $module_class = strtr($module_filename, '/', '_'); + $module_name = split('_', $module_class); // Establishes the shared module information - $shared_module_name = $config->getSharedModule($module_name); - $shared_module_file = PICKLES_PATH . 'modules/' . $shared_module_name . '.php'; + $shared_module_filename = $config->getSharedModule($module_class); + $shared_module_file = PICKLES_PATH . 'common/modules/' . $shared_module_filename . '.php'; + $shared_module_class = strtr($shared_module_filename, '/', '_'); + $shared_module_name = split('_', $shared_module_class); // Tries to load the site level module if (file_exists($module_file)) { require_once $module_file; - if (class_exists($class)) { - $module = new $class($config, $db, $mailer, $error); + if (class_exists($module_class)) { + $module = new $module_class($config, $db, $mailer, $error); } } // Tries to load the shared module else if (file_exists($shared_module_file) && $shared_module_name != false) { - if (strpos($shared_module_name, '/') === false) { - $class = $shared_module_name; - } - else { - $class = strtr($shared_module_name, '/', '_'); - } + require_once $shared_module_file; - if (class_exists($class)) { - $module = new $class($config, $db, $mailer, $error); + if (class_exists($shared_module_class)) { + $module = new $shared_module_class($config, $db, $mailer, $error); } } // Loads the stock module @@ -176,11 +162,6 @@ class Controller extends Object { $display_class = 'Display_' . $display_type; $display = new $display_class($config, $error); - // Sets the display's properties - $display->module_name = $module_name; - $display->shared_name = $shared_module_name; - $display->section = $section; - // Potentially establishes caching $caching = $module->getCaching(); if ($caching) { @@ -208,6 +189,20 @@ class Controller extends Object { } } + // If the loaded module has a name, use it to override + if ($module->name != null && $module_filename != $module->name) { + $module_filename = $module->name; + $module_file = '../modules/' . $module_filename . '.php'; + $module_class = strtr($module_filename, '/', '_'); + $module_name = split('_', $module_class); + } + + // Sets the display's properties + $display->module_filename = $module_filename; + $display->module_name = $module_name; + $display->shared_module_filename = $shared_module_filename; + $display->shared_module_name = $shared_module_name; + // Loads the module data into the display to be rendered /** * @todo perhaps make this a passed variable diff --git a/classes/DB.php b/classes/DB.php index f13ca11..dbc319c 100755 --- a/classes/DB.php +++ b/classes/DB.php @@ -62,10 +62,12 @@ class DB extends Object { $this->error = $error; - $this->hostname = $config->database->hostname; - $this->username = $config->database->username; - $this->password = $config->database->password; - $this->database = $config->database->database; + if (isset($config->database)) { + $this->hostname = $config->database->hostname; + $this->username = $config->database->username; + $this->password = $config->database->password; + $this->database = $config->database->database; + } } /** diff --git a/classes/Display/Smarty.php b/classes/Display/Smarty.php index 9245ece..94fff63 100644 --- a/classes/Display/Smarty.php +++ b/classes/Display/Smarty.php @@ -56,7 +56,7 @@ class Display_Smarty extends Display_Common { public function prepare() { // Enables caching - if ($this->caching == true) { + if ($this->caching === true) { $this->smarty->caching = 1; $this->smarty->compile_check = true; @@ -83,38 +83,41 @@ class Display_Smarty extends Display_Common { closedir($handle); } } - - // Establishes the template names - $template = SITE_PATH . '../templates/' . $this->module_name . '.tpl'; - $shared_template = PICKLES_PATH . 'templates/' . $this->shared_name . '.tpl'; - - /** - * @todo There's a bug with the store home page since it's a redirect - */ - if (!file_exists($template)) { - if (file_exists($shared_template)) { - $template = $shared_template; - } - } - - $this->template = $template; } /** * Render the Smarty generated pages */ public function render() { + + // Establishes the template names + $template = SITE_PATH . '../templates/' . $this->module_filename . '.tpl'; + + if (!file_exists($template)) { + $shared_template = PICKLES_PATH . 'common/templates/' . ($this->shared_filname == false ? $this->module_filename : $this->shared_filename) . '.tpl'; + + if (file_exists($shared_template)) { + $template = $shared_template; + } + } + + $this->template = $template; - $cache_id = isset($this->cache_id) ? $this->cache_id : $this->module_name; + $cache_id = isset($this->cache_id) ? $this->cache_id : $this->module_filename; $template = $this->smarty->template_exists('index.tpl') ? 'index.tpl' : $this->template; if (!$this->smarty->is_cached($template, $cache_id)) { - // Pass all of our controller values to Smarty - $this->smarty->assign('section', $this->section); - $this->smarty->assign('module', $this->module_name); - $this->smarty->assign('template', $this->template); + // Build the combined module name array and assign it + $module = $this->module_name; + array_unshift($module, $this->module_filename); + $this->smarty->assign('module', $module); + + // Only assign the template if it's not the index, this avoids an infinite loop. + if ($this->template != 'index.tpl') { + $this->smarty->assign('template', $this->template); + } // Loads the data from the config $data = $this->config->getPublicData(); diff --git a/common/models/home.php b/common/models/home.php deleted file mode 100644 index 00d04b0..0000000 --- a/common/models/home.php +++ /dev/null @@ -1,8 +0,0 @@ -data['featured'] = $this->db->getRow('SELECT id, name, teaser FROM products WHERE featured = "Y" AND id = 30 ORDER BY RAND() LIMIT 1;'); - - foreach (array('gif', 'jpg', 'png') as $extension) { - if (file_exists(getcwd() . '/images/products/' . $this->data['featured']['id'] . '/medium.' . $extension)) { - $this->data['featured']['image'] = $extension; - } - } - - $this->data['top_sellers'] = $this->db->getArray('SELECT id, name FROM products ORDER BY RAND() LIMIT 10;'); - } -} - -?> diff --git a/common/modules/home.php b/common/modules/home.php new file mode 100644 index 0000000..8b03daf --- /dev/null +++ b/common/modules/home.php @@ -0,0 +1,10 @@ +data['cart'] = $_SESSION['cart']; + $this->cart = $_SESSION['cart']; // Loads the navigation - $config = Config::getInstance(); - $this->data['subnav'] = $config->store->sections; + $this->subnav = $config->store->sections; // Loads the categories $categories = $this->db->getArray('SELECT id, name, permalink FROM categories WHERE parent_id IS NULL AND visible = "Y" ORDER BY weight;'); @@ -44,18 +44,17 @@ class store extends Model { } } - $this->data['categories'] = $categories; + $this->categories = $categories; } public function __default() { // Forces store/home as the first page you get when only /store is called - $object = new store_home(); + $object = new store_home($this->config, $this->db, $this->mailer, $this->error); $object->__default(); $this->data = $object->data; - $this->set('name', 'store/home'); + $this->name = 'store/home'; } - } ?> diff --git a/common/models/store/cart.php b/common/modules/store/cart.php similarity index 85% rename from common/models/store/cart.php rename to common/modules/store/cart.php index bd24eaa..0836f45 100644 --- a/common/models/store/cart.php +++ b/common/modules/store/cart.php @@ -15,8 +15,10 @@ class store_cart extends store { + protected $display = DISPLAY_SMARTY; + public function __default() { - $this->data['cart'] = $_SESSION['cart']; + $this->cart = $_SESSION['cart']; } } diff --git a/common/models/store/cart/add.php b/common/modules/store/cart/add.php similarity index 100% rename from common/models/store/cart/add.php rename to common/modules/store/cart/add.php diff --git a/common/models/store/category.php b/common/modules/store/category.php similarity index 77% rename from common/models/store/category.php rename to common/modules/store/category.php index 04f1e3b..e64a146 100644 --- a/common/models/store/category.php +++ b/common/modules/store/category.php @@ -1,6 +1,8 @@ db->getRow(' @@ -9,7 +11,7 @@ class store_category extends store { WHERE permalink = "' . $_REQUEST['permalink'] . '"; '); - $this->data['category'] = $category; + $this->category = $category; } } diff --git a/common/modules/store/home.php b/common/modules/store/home.php new file mode 100644 index 0000000..eabffaf --- /dev/null +++ b/common/modules/store/home.php @@ -0,0 +1,24 @@ +featured = $this->db->getRow('SELECT id, name, teaser FROM products WHERE featured = "Y" AND id = 30 ORDER BY RAND() LIMIT 1;'); + + foreach (array('gif', 'jpg', 'png') as $extension) { + if (file_exists(getcwd() . '/images/products/' . $this->featured['id'] . '/medium.' . $extension)) { + $this->featured['image'] = $extension; + } + } + + $this->top_sellers = $this->db->getArray('SELECT id, name FROM products ORDER BY RAND() LIMIT 10;'); + } +} + +?> diff --git a/common/templates/store/cart.tpl b/common/templates/store/cart.tpl index 99f5b97..1d8fc81 100644 --- a/common/templates/store/cart.tpl +++ b/common/templates/store/cart.tpl @@ -1,6 +1,6 @@
- {include file="../../pickles/templates/store/navigation.tpl"}

- {include file="../../pickles/templates/store/categories.tpl"} + {include file="../../pickles/common/templates/store/navigation.tpl"}

+ {include file="../../pickles/common/templates/store/categories.tpl"}
diff --git a/common/templates/store/categories.tpl b/common/templates/store/categories.tpl index 19deccf..68c8968 100644 --- a/common/templates/store/categories.tpl +++ b/common/templates/store/categories.tpl @@ -1,6 +1,6 @@ -
+
{foreach from=$categories item=parent_category} -
+

{$parent_category.name}

    diff --git a/common/templates/store/category.tpl b/common/templates/store/category.tpl index 40a2764..07a2a13 100644 --- a/common/templates/store/category.tpl +++ b/common/templates/store/category.tpl @@ -1,6 +1,6 @@
    - {include file="../../pickles/templates/store/navigation.tpl"}

    - {include file="../../pickles/templates/store/categories.tpl"} + {include file="../../pickles/common/templates/store/navigation.tpl"}

    + {include file="../../pickles/common/templates/store/categories.tpl"}
    diff --git a/common/templates/store/home.tpl b/common/templates/store/home.tpl index 95a5dc6..3da9ca5 100644 --- a/common/templates/store/home.tpl +++ b/common/templates/store/home.tpl @@ -1,8 +1,8 @@
    - {include file="../../pickles/templates/store/navigation.tpl"}

    - {include file="../../pickles/templates/store/categories.tpl"} + {include file="../../pickles/common/templates/store/navigation.tpl"}

    + {include file="../../pickles/common/templates/store/categories.tpl"}
    - {include file="../../pickles/templates/store/featured_product.tpl"}

    - {include file="../../pickles/templates/store/top_sellers.tpl"} + {include file="../../pickles/common/templates/store/featured_product.tpl"}

    + {include file="../../pickles/common/templates/store/top_sellers.tpl"}
    diff --git a/common/templates/store/navigation.tpl b/common/templates/store/navigation.tpl index 83d5008..f75eeac 100644 --- a/common/templates/store/navigation.tpl +++ b/common/templates/store/navigation.tpl @@ -1,11 +1,11 @@ -
    - +
diff --git a/common/templates/store/top_sellers.tpl b/common/templates/store/top_sellers.tpl index b35f62c..f23bff0 100644 --- a/common/templates/store/top_sellers.tpl +++ b/common/templates/store/top_sellers.tpl @@ -1,4 +1,4 @@ -
+

Top Sellers

{section name=product loop=$top_sellers start=0 loop=5 step=1} diff --git a/pickles.php b/pickles.php index 8f764c1..b3743a6 100755 --- a/pickles.php +++ b/pickles.php @@ -64,7 +64,7 @@ function __autoload($class) { $filename = str_replace('_', '/', $class) . '.php'; $class_file = PICKLES_PATH . 'classes/' . $filename; - $module_file = PICKLES_PATH . 'modules/' . $filename; + $module_file = PICKLES_PATH . 'common/modules/' . $filename; // Loads the class file if (file_exists($class_file)) {