Fixed #24. Sections are now dynamic and modules can now be disabled
This commit is contained in:
parent
ba84fa5cef
commit
54c81f769a
@ -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."'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Module\Sections;
|
||||
use \Module;
|
||||
use \EventPriority;
|
||||
|
||||
/**
|
||||
* Sections module, see usage documentation
|
||||
* @author TechFuze
|
||||
*/
|
||||
class Sections extends Module {
|
||||
class Main extends Module {
|
||||
|
||||
/**
|
||||
* The config holder for this module. Holds an StdObject
|
||||
@ -24,29 +29,46 @@ class Sections extends Module {
|
||||
* @access public
|
||||
*/
|
||||
public function onLoad() {
|
||||
// Load module configuration
|
||||
$this->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;
|
||||
|
@ -1 +1 @@
|
||||
<?php return 1;
|
||||
<?php return array() ;
|
20
Modules/sections/moduleInfo.php
Normal file
20
Modules/sections/moduleInfo.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
'module_class' => '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',
|
||||
);
|
Loading…
Reference in New Issue
Block a user