From 54c81f769a87634dcde019cb5b331e5c768e43db Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 12:20:39 +0200 Subject: [PATCH] Fixed #24. Sections are now dynamic and modules can now be disabled --- Core/System/class.core.php | 31 ++++++------ Modules/sections/class.sections.php | 74 ++++++++++++++++++++-------- Modules/sections/config.sections.php | 2 +- Modules/sections/moduleInfo.php | 20 ++++++++ 4 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 Modules/sections/moduleInfo.php diff --git a/Core/System/class.core.php b/Core/System/class.core.php index 2f51540..8a59b87 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -81,14 +81,6 @@ class Core { // Load the moduleInfo $cfg = (object) $this->register[$name]; - // Check if the module is enabled - if (isset($cfg->enabled)) { - if (!$cfg->enabled) { - // DO SOMETHING - return false; - } - } - // Check if the module is already loaded. If so, only return a reference, if not, load the module if (in_array($name, $this->loaded_modules)) { // return the link @@ -112,9 +104,9 @@ class Core { require_once($file); $class_name = $cfg->module_class; $msg = "Loading Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "'"; - $msg .= (isset($cfg->version) ? " version:".$cfg->version : ""); - $msg .= (isset($cfg->author) ? " made by ".$cfg->author : ""); - $msg .= (isset($cfg->website) ? " from ".$cfg->website: ""); + $msg .= (isset($cfg->version) ? "; version: ".$cfg->version : ""); + $msg .= (isset($cfg->author) ? "; made by ".$cfg->author : ""); + $msg .= (isset($cfg->website) ? "; from ".$cfg->website: ""); $this->mods->logger->log($msg); } else { // Throw Exception if the file does not exist @@ -177,8 +169,19 @@ class Core { // Append directory $cfg->directory = $mod_dir; - $register[$name] = (array) $cfg; - $this->mods->logger->log("Found module: '".$name."'"); + if (isset($cfg->enabled)) { + if ($cfg->enabled) { + $register[$name] = (array) $cfg; + $this->mods->logger->log("[ON] '".$name."'"); + } else { + $this->mods->logger->log("[OFF] '".$name."'"); + } + } else { + $register[$name] = (array) $cfg; + $this->mods->logger->log("[ON] '".$name."'"); + } + + } else { // Get the name $name = $mod_dirs[$i]; @@ -192,7 +195,7 @@ class Core { $cfg->versions = array(); $cfg->directory = $mod_dir; $register[$name] = (array)$cfg; - $this->mods->logger->log("Found module: '".$name."'"); + $this->mods->logger->log("[ON] '".$name."'"); } } diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index 3224670..41cca0b 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -1,9 +1,14 @@ cfg = $this->config->loadConfigFile('sections', $this->getModulePath()); + // Load the config + $config = $this->config->loadConfigFile('sections', $this->getModulePath()); + + $this->logger->newLevel('Adding module sections', 'Sections'); + // Add the modules to the config + $section_register = array(); + foreach ($this->core->register as $key => $value) { + // Check if the sections value exists in the config file + if (isset($value['sections'])) { + // Check if it is empty + if (!empty($value['sections'])) { + // If not, cycle through all sections + foreach ($value['sections'] as $section_name => $section) { + // Check if the section is already set + if (isset($config->$section_name)) { + // If the priority is higher, replace the section + if ($section->priority > $config->$section_name->priority) { + $config->$section_name = $section; + $this->logger->log('Added section with higher priority: \''.$section_name.'\'', 'Sections'); + } + } else { + $config->$section_name = $section; + $this->logger->log('Added section: \''.$section_name.'\'', 'Sections'); + } + } + } + } + } + + // Apply the changes and log it + $this->cfg = $config; + $this->logger->log('Added all module sections to the config file', 'Sections'); + $this->logger->stopLevel(); // 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, 'routerRouteEvent'), 'routerRouteEvent', EventPriority::NORMAL); $this->events->addListener(array($this, 'layoutLoadEvent'), 'layoutLoadEvent', EventPriority::NORMAL); $this->events->addListener(array($this, 'modelLoadevent'), 'modelLoadEvent', EventPriority::NORMAL); } - /** - * Registers this module in the eventRegister for routerRouteEvent - * @access public - * @param eventRegisterBuildEvent Event - * @return eventRegisterBuildEvent Event - */ - 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 @@ -57,7 +79,12 @@ class Sections extends Module { $layout_name = $event->layout; if ($this->currentSection !== null) { $section = $this->getSection($this->currentSection); - $event->directory = $section['view_path']; + if ($section['module_section']) { + $mod = $this->core->loadMod($section['module_name']); + $event->directory = $mod->getModulePath() . '/Views/'; + } else { + $event->directory = $section['view_path']; + } } return $event; } @@ -72,7 +99,12 @@ class Sections extends Module { $model_name = $event->model; if ($this->currentSection !== null) { $section = $this->getSection($this->currentSection); - $event->directory = $section['model_path']; + if ($section['module_section']) { + $mod = $this->core->loadMod($section['module_name']); + $event->directory = $mod->getModulePath() . '/Models/'; + } else { + $event->directory = $section['model_path']; + } } return $event; } @@ -128,7 +160,7 @@ class Sections extends Module { * @param routerRouteEvent Event * @return routerRouteEvent Event */ - public function routerEvent($event) { + public function routerRouteEvent($event) { $name = $event->controller; $controller = null; $function = null; diff --git a/Modules/sections/config.sections.php b/Modules/sections/config.sections.php index c3388f9..9dd0e94 100644 --- a/Modules/sections/config.sections.php +++ b/Modules/sections/config.sections.php @@ -1 +1 @@ - 'Module\Sections\Main', + 'module_file' => 'class.sections.php', + 'module_name' => 'Sections', + + 'abstract' => false, + 'dependencies' => array(), + 'events' => array('routerRouteEvent', 'layoutLoadEvent', 'modelLoadEvent'), + + 'name' => 'FuzeWorks Sections', + 'description' => 'Submodules for FuzeWorks', + 'author' => 'TechFuze', + 'version' => '1.0.0', + 'website' => 'http://fuzeworks.techfuze.net/', + + 'date_created' => '29-04-2015', + 'date_updated' => '29-04-2015', +);