diff --git a/Core/Events/event.layoutLoadEvent.php b/Core/Events/event.layoutLoadEvent.php new file mode 100644 index 0000000..60fc338 --- /dev/null +++ b/Core/Events/event.layoutLoadEvent.php @@ -0,0 +1,13 @@ +layout = $layout; + } +} + +?> \ No newline at end of file diff --git a/Core/System/class.core.php b/Core/System/class.core.php index b2c171d..b533b5a 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -92,6 +92,9 @@ class Core { $CLASS->onLoad(); return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS; + } else { + $c = &$this->mods->{strtolower($data['moduleLinkName'])}; + return $c; } } @@ -104,7 +107,7 @@ class Core { } // The basic module path - $path = FUZEPATH . "/Core/Mods/"; + $path = FUZEPATH . "Modules/"; // Chech if the requested module is set if (isset($this->register[$name])) { @@ -185,7 +188,7 @@ class Core { public function buildModRegister() { $this->mods->logger->newLevel("Building Mod Register", 'Core'); - $dir = FUZEPATH . "Core/Mods/"; + $dir = FUZEPATH . "Modules/"; $mods = array_values(array_diff(scandir($dir), array('..', '.'))); $register = array(); for ($i=0; $i < count($mods); $i++) { @@ -199,6 +202,7 @@ class Core { // Append directory $cfg->directory = $mod_dir; $register[$name] = (array) $cfg; + $this->mods->logger->log("Found module: '".$name."'"); } else { // Get the name $name = $mods[$i]; @@ -212,6 +216,7 @@ class Core { $cfg->versions = array(); $cfg->directory = $mod_dir; $register[$name] = (array)$cfg; + $this->mods->logger->log("Found module: '".$name."'"); } } diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 8551276..be8bb26 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -155,7 +155,7 @@ class Events extends Bus{ // Event Preparation: public function buildEventRegister() { $this->logger->newLevel("Building Event Register", 'Events'); - $dir = FUZEPATH . "/Core/Mods/"; + $dir = FUZEPATH . "/Modules/"; $mods = $this->config->modregister->register; foreach ($mods as $key => $value) { try { diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index d2dc8c3..f6aeb89 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -72,11 +72,15 @@ class Layout extends Bus { return $this->title; } - public function view($view = "default", $dir = null) { + public function view($view = "default") { // Chech if Smarty is loaded if (!$this->loaded) $this->load(); + $event = $this->events->fireEvent('layoutLoadEvent', $view); + $directory = ($event->directory === null ? FUZEPATH . "/Application/Views" : $event->directory); + $view = ($event->layout === null ? $view : $event->layout); + // Set the file name and location $vw = explode('/', $view); if (count($vw) == 1) { @@ -98,8 +102,7 @@ class Layout extends Bus { } // Set the directory - $dir = (!isset($dir) ? FUZEPATH . "/Application/" . '/Views' : $dir); - $this->Smarty['main']->setTemplateDir($dir); + $this->Smarty['main']->setTemplateDir($directory); // Set the title $this->Smarty['main']->assign('title', $this->title); @@ -107,7 +110,7 @@ class Layout extends Bus { // Get the viewdir // @TODO: Fix this for custom directories $one = FUZEPATH; - $two = $dir . "/"; + $two = $directory . "/"; $count_one = strlen($one); $count_two = strlen($two); $length_three = $count_two - $count_one; @@ -122,26 +125,26 @@ class Layout extends Bus { }catch (\SmartyException $e){ // Throw error on failure - $this->logger->logError('Could not load view '.$dir.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); - throw new Exception\Layout('Could not load view '.$dir.'/'.$vw); + $this->logger->logError('Could not load view '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); + throw new Exception\Layout('Could not load view '.$directory.'/'.$vw); } } - public function get($view = "default", $dir = "") { + public function get($view = "default", $directory = "") { // Chech if Smarty is loaded if (!$this->loaded) $this->load(); // Set the directory - $dir = ($dir == "" ? FUZEPATH . "/Application/" . '/Views' : $dir); - $this->Smarty['main']->setTemplateDir($dir); + $directory = ($directory == "" ? FUZEPATH . "/Application/" . '/Views' : $directory); + $this->Smarty['main']->setTemplateDir($directory); // Set the title $this->Smarty['main']->assign('title', $this->title); // Get the viewdir $one = FUZEPATH; - $two = $dir . "/"; + $two = $directory . "/"; $count_one = strlen($one); $count_two = strlen($two); $length_three = $count_two - $count_one; @@ -155,8 +158,8 @@ class Layout extends Bus { }catch (\SmartyException $e){ // Throw error on failure - $this->logger->logError('Could not load view '.$dir.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); - throw new Exception\Layout('Could not load view '.$dir.'/view.'.$view.'.tpl'); + $this->logger->logError('Could not load view '.$directory.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); + throw new Exception\Layout('Could not load view '.$directory.'/view.'.$view.'.tpl'); } } } \ No newline at end of file diff --git a/Core/Mods/database/class.database.php b/Modules/database/class.database.php similarity index 100% rename from Core/Mods/database/class.database.php rename to Modules/database/class.database.php diff --git a/Core/Mods/databasemodel/class.model.php b/Modules/databasemodel/class.model.php similarity index 100% rename from Core/Mods/databasemodel/class.model.php rename to Modules/databasemodel/class.model.php diff --git a/Core/Mods/databasemodel/moduleInfo.php b/Modules/databasemodel/moduleInfo.php similarity index 100% rename from Core/Mods/databasemodel/moduleInfo.php rename to Modules/databasemodel/moduleInfo.php diff --git a/Core/Mods/router/class.router.php b/Modules/router/class.router.php similarity index 100% rename from Core/Mods/router/class.router.php rename to Modules/router/class.router.php diff --git a/Core/Mods/sections/class.sections.php b/Modules/sections/class.sections.php similarity index 68% rename from Core/Mods/sections/class.sections.php rename to Modules/sections/class.sections.php index 9ef404a..3224670 100644 --- a/Core/Mods/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -30,6 +30,8 @@ class Sections extends Module { // Register Events $this->events->addListener(array($this, 'eventRegisterBuild'), 'eventRegisterBuildEvent', EventPriority::NORMAL); $this->events->addListener(array($this, 'routerEvent'), 'routerRouteEvent', EventPriority::NORMAL); + $this->events->addListener(array($this, 'layoutLoadEvent'), 'layoutLoadEvent', EventPriority::NORMAL); + $this->events->addListener(array($this, 'modelLoadevent'), 'modelLoadEvent', EventPriority::NORMAL); } /** @@ -40,6 +42,38 @@ class Sections extends Module { */ public function eventRegisterBuild($event) { $event->addEvent('sections', 'routerRouteEvent'); + $event->addEvent('sections', 'layoutLoadEvent'); + $event->addEvent('sections', 'modelLoadEvent'); + return $event; + } + + /** + * Redirects layouts to the new section + * @access public + * @param layoutLoadEvent Event + * @return layoutLoadEvent Event + */ + public function layoutLoadEvent($event) { + $layout_name = $event->layout; + if ($this->currentSection !== null) { + $section = $this->getSection($this->currentSection); + $event->directory = $section['view_path']; + } + return $event; + } + + /** + * Redirects models to the new section + * @access public + * @param layoutLoadEvent Event + * @return layoutLoadEvent Event + */ + public function modelLoadEvent($event) { + $model_name = $event->model; + if ($this->currentSection !== null) { + $section = $this->getSection($this->currentSection); + $event->directory = $section['model_path']; + } return $event; } @@ -54,14 +88,28 @@ class Sections extends Module { * @param String View_path, where to find the views for this section */ public function addSection($name, $module_section = false, $module_name = null, $controller_path = null, $model_path = null, $view_path = null) { - $data = array( - 'name' => $name, - 'module_section' => $module_section, - 'module_name' => $module_name, - 'controller_path' => FUZEPATH . $controller_path, - 'model_path' => FUZEPATH . $model_path, - 'view_path' => FUZEPATH . $view_path, - ); + if ($module_section) { + $m = $this->core->loadMod($module_name); + $m_dir = $m->getModulePath(); + $data = array( + 'name' => $name, + 'module_section' => $module_section, + 'module_name' => $module_name, + 'controller_path' => $m_dir . '/Controller/', + 'model_path' => $m_dir . '/Models/', + 'view_path' => $m_dir . '/Views/', + ); + } else { + $data = array( + 'name' => $name, + 'module_section' => $module_section, + 'module_name' => $module_name, + 'controller_path' => FUZEPATH . $controller_path, + 'model_path' => FUZEPATH . $model_path, + 'view_path' => FUZEPATH . $view_path, + ); + } + $this->config->set('sections', $name, $data, $this->getModulePath()); } @@ -122,6 +170,18 @@ class Sections extends Module { return $event; } + /** + * Load a section file + * @access public + * @param String section name + * @return Array Section + */ + public function getSection($name) { + if (isset($this->cfg->$name)) { + return $this->cfg->$name; + } + } + /** * Retrieves section information from the config file * @access public diff --git a/Core/Mods/sections/config.sections.php b/Modules/sections/config.sections.php similarity index 100% rename from Core/Mods/sections/config.sections.php rename to Modules/sections/config.sections.php