Merge branch 'master' into Issue_#9;_Recreate_Models
This commit is contained in:
commit
5ceaa4868b
@ -2,6 +2,7 @@
|
|||||||
'SITE_URL' => '',
|
'SITE_URL' => '',
|
||||||
'SITE_DOMAIN' => '',
|
'SITE_DOMAIN' => '',
|
||||||
'SERVER_NAME' => '',
|
'SERVER_NAME' => '',
|
||||||
|
'registers_update_interval' => 3600,
|
||||||
'administrator_mail' => '',
|
'administrator_mail' => '',
|
||||||
'default_controller' => 'standard',
|
'default_controller' => 'standard',
|
||||||
'default_function' => 'index',
|
'default_function' => 'index',
|
||||||
|
0
Application/Config/config.modregister.php
Normal file
0
Application/Config/config.modregister.php
Normal file
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
* Sections module, see usage documentation
|
||||||
* @author TechFuze
|
* @author TechFuze
|
||||||
*/
|
*/
|
||||||
class Sections extends Module {
|
class Sections extends Module {
|
||||||
@ -18,10 +19,10 @@ class Sections extends Module {
|
|||||||
*/
|
*/
|
||||||
private $currentSection = null;
|
private $currentSection = null;
|
||||||
|
|
||||||
public function __construct(&$core) {
|
/**
|
||||||
parent::__construct($core);
|
* Loads the module and registers the events
|
||||||
}
|
* @access public
|
||||||
|
*/
|
||||||
public function onLoad() {
|
public function onLoad() {
|
||||||
// Load module configuration
|
// Load module configuration
|
||||||
$this->cfg = $this->config->loadConfigFile('sections', $this->getModulePath());
|
$this->cfg = $this->config->loadConfigFile('sections', $this->getModulePath());
|
||||||
@ -31,13 +32,55 @@ class Sections extends Module {
|
|||||||
$this->events->addListener(array($this, 'routerEvent'), 'routerRouteEvent', EventPriority::NORMAL);
|
$this->events->addListener(array($this, 'routerEvent'), 'routerRouteEvent', EventPriority::NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers this module in the eventRegister for routerRouteEvent
|
||||||
|
* @access public
|
||||||
|
* @param eventRegisterBuildEvent Event
|
||||||
|
* @return eventRegisterBuildEvent Event
|
||||||
|
*/
|
||||||
public function eventRegisterBuild($event) {
|
public function eventRegisterBuild($event) {
|
||||||
$event->addEvent('sections', 'routerRouteEvent');
|
$event->addEvent('sections', 'routerRouteEvent');
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function routerEvent($event) {
|
/**
|
||||||
|
* Add a section to the config file
|
||||||
|
* @access public
|
||||||
|
* @param String section_name, name of the section
|
||||||
|
* @param Boolean module_section wether this is a module_section
|
||||||
|
* @param String module_name to use when this is a module_section
|
||||||
|
* @param String Controller_path, where to find the controllers for this section
|
||||||
|
* @param String Model_path, where to find the models for this section
|
||||||
|
* @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,
|
||||||
|
);
|
||||||
|
$this->config->set('sections', $name, $data, $this->getModulePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a section from the config file
|
||||||
|
* @access public
|
||||||
|
* @param String section_name, name of the section to remove
|
||||||
|
*/
|
||||||
|
public function removeSection($name) {
|
||||||
|
$this->config->set('sections', $name, null, $this->getModulePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get's called on routerRouteEvent. Redirects when a section is found
|
||||||
|
* @access public
|
||||||
|
* @param routerRouteEvent Event
|
||||||
|
* @return routerRouteEvent Event
|
||||||
|
*/
|
||||||
|
public function routerEvent($event) {
|
||||||
$name = $event->controller;
|
$name = $event->controller;
|
||||||
$controller = null;
|
$controller = null;
|
||||||
$function = null;
|
$function = null;
|
||||||
@ -50,12 +93,12 @@ class Sections extends Module {
|
|||||||
$this->currentSection = $name;
|
$this->currentSection = $name;
|
||||||
|
|
||||||
// Logic here, first for module sections
|
// Logic here, first for module sections
|
||||||
if ($section->module_section) {
|
if ($section['module_section']) {
|
||||||
$this->core->loadMod($section->module_name);
|
$mod = $this->core->loadMod($section['module_name']);
|
||||||
$event->directory = $this->mods->{$section->module_name}->getModulePath() . "/Controller/";
|
$event->directory = $mod->getModulePath() . "/Controller/";
|
||||||
} else {
|
} else {
|
||||||
// Now for regular sections
|
// Now for regular sections
|
||||||
$event->directory = $section->controller_path;
|
$event->directory = $section['controller_path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the path so it matches the new regime
|
// Move the path so it matches the new regime
|
||||||
@ -68,6 +111,8 @@ class Sections extends Module {
|
|||||||
|
|
||||||
// And finally set the controller, if no parameters are set, load the default function
|
// And finally set the controller, if no parameters are set, load the default function
|
||||||
$controller = (!empty($event->function) ? $event->function : $this->config->main->default_controller );
|
$controller = (!empty($event->function) ? $event->function : $this->config->main->default_controller );
|
||||||
|
} else {
|
||||||
|
$this->logger->log("No section was found with name: '".$name."'", 'Sections');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($controller !== null)$event->controller = $controller;
|
if($controller !== null)$event->controller = $controller;
|
||||||
@ -77,22 +122,23 @@ class Sections extends Module {
|
|||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves section information from the config file
|
||||||
|
* @access public
|
||||||
|
* @param String section_name, name of the section
|
||||||
|
* @return Array section_information or null
|
||||||
|
*/
|
||||||
public function __get($name){
|
public function __get($name){
|
||||||
// Something given?
|
// Something given?
|
||||||
if(empty($name)) {
|
if(empty($name)) {
|
||||||
|
|
||||||
// Currently in a section?
|
// Currently in a section?
|
||||||
if($this->currentSection !== null){
|
if($this->currentSection !== null){
|
||||||
|
|
||||||
// Return that one then
|
// Return that one then
|
||||||
return $this->cfg[$this->currentSection];
|
return $this->cfg[$this->currentSection];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emptiness...
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return element $name of the config file
|
// Return element $name of the config file
|
||||||
if (isset($this->cfg->$name)) {
|
if (isset($this->cfg->$name)) {
|
||||||
$section = $this->cfg->$name;
|
$section = $this->cfg->$name;
|
||||||
|
@ -17,6 +17,11 @@ class Module extends Bus {
|
|||||||
*/
|
*/
|
||||||
protected $moduleName = 'placeholder';
|
protected $moduleName = 'placeholder';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var String name used in the mod array
|
||||||
|
*/
|
||||||
|
protected $linkName = 'placeholder';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -59,4 +64,22 @@ class Module extends Bus {
|
|||||||
if($this->modulePath === null)
|
if($this->modulePath === null)
|
||||||
$this->modulePath = $modulePath;
|
$this->modulePath = $modulePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the link name of the module. The link name is the address in the module array so that the module can self reference.
|
||||||
|
* @access public
|
||||||
|
* @param String link name
|
||||||
|
*/
|
||||||
|
public function setModuleLinkName($linkName) {
|
||||||
|
$this->linkName = $linkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name that is required to load itself, eg 'exampleauthor/examplemodulename' or 'techfuze/cms'
|
||||||
|
* @access public
|
||||||
|
* @param String module name
|
||||||
|
*/
|
||||||
|
public function setModuleName($modName) {
|
||||||
|
$this->moduleName = $modName;
|
||||||
|
}
|
||||||
}
|
}
|
@ -87,7 +87,6 @@ class Config extends Bus{
|
|||||||
public function set($name, $key, $value, $directory = null) {
|
public function set($name, $key, $value, $directory = null) {
|
||||||
$dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/");
|
$dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/");
|
||||||
$file = $dir . 'config.' . strtolower($name).".php";
|
$file = $dir . 'config.' . strtolower($name).".php";
|
||||||
$file2 = $dir . 'config.' . strtolower($name).".enc.cfg";
|
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
$DECODED = require($file);
|
$DECODED = require($file);
|
||||||
if (!is_array($DECODED)) {
|
if (!is_array($DECODED)) {
|
||||||
|
@ -11,6 +11,7 @@ class Core {
|
|||||||
|
|
||||||
public $mods;
|
public $mods;
|
||||||
private $loaded = false;
|
private $loaded = false;
|
||||||
|
private $register;
|
||||||
|
|
||||||
## START/STOP
|
## START/STOP
|
||||||
public function init() {
|
public function init() {
|
||||||
@ -21,6 +22,14 @@ class Core {
|
|||||||
// Load core functionality
|
// Load core functionality
|
||||||
$this->mods = new stdClass();
|
$this->mods = new stdClass();
|
||||||
$this->loadStartupFiles();
|
$this->loadStartupFiles();
|
||||||
|
|
||||||
|
$this->mods->events->fireEvent('coreStartEvent');
|
||||||
|
// Mod register exists, check if expired
|
||||||
|
if ( ( date('U') - $this->mods->config->main->registers_last_update) > $this->mods->config->main->registers_update_interval) {
|
||||||
|
$this->mods->logger->log("Registers have expired. Updating...", 'Core');
|
||||||
|
$this->buildModRegister();
|
||||||
|
$this->mods->events->buildEventRegister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadStartupFiles() {
|
public function loadStartupFiles() {
|
||||||
@ -55,65 +64,143 @@ class Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
## MODLOADING
|
## MODLOADING
|
||||||
public function loadMod($name) {
|
public function loadMod($name, $version = null) {
|
||||||
// Class name
|
$CLASS = $this->loadModule($name);
|
||||||
$class_name = ucfirst($name);
|
if (!isset($this->mods->{strtolower($CLASS[1])})) {
|
||||||
// Check if mod is already loaded
|
return $this->mods->{strtolower($CLASS[1])} = &$CLASS[0];
|
||||||
if (!isset($this->mods->$name)) {
|
}
|
||||||
// Check if class is already included
|
}
|
||||||
|
|
||||||
// If the class is not loaded, load it
|
public function getMod($name, $version = null) {
|
||||||
if (!class_exists($class_name)) {
|
$CLASS = $this->loadModule($name);
|
||||||
|
return $CLASS[0];
|
||||||
|
}
|
||||||
|
|
||||||
// If the mod is in the top mod directory, load it directly
|
private function loadModule($name, $version = null) {
|
||||||
$file = FUZEPATH . "/Core/Mods/class.".$class_name.".php";
|
// Load the register if not loaded yet
|
||||||
if (file_exists($file)) {
|
if (!isset($this->mods->config->modregister->register)) {
|
||||||
$this->mods->logger->log("Loading module '".$class_name."'");
|
$this->buildModRegister();
|
||||||
$path = FUZEPATH . "/Core/Mods/class.".$class_name.".php";
|
} else {
|
||||||
require_once($file);
|
|
||||||
|
|
||||||
// If not, and a mod config file is found, follow that
|
$this->register = $this->mods->config->modregister->register;
|
||||||
} elseif ( file_exists(FUZEPATH . "/Core/Mods/".strtolower($name)."/moduleInfo.php" )) {
|
|
||||||
// Load the config file
|
|
||||||
$cfg = (object) require(FUZEPATH . "/Core/Mods/".strtolower($name)."/moduleInfo.php");
|
|
||||||
|
|
||||||
// Load the class name and file
|
|
||||||
$class_file = FUZEPATH . "/Core/Mods/".strtolower($name)."/" . $cfg->module_file;
|
|
||||||
$class_name = $cfg->module_class;
|
|
||||||
|
|
||||||
// Load the dependencies first
|
|
||||||
$deps = (isset($cfg->dependencies) ? $cfg->dependencies : array());
|
|
||||||
for ($i=0; $i < count($deps); $i++) {
|
|
||||||
$this->loadMod($deps[$i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = FUZEPATH . "/Core/Mods/".strtolower($name)."/";
|
|
||||||
$this->mods->logger->log("Loading Module '".$cfg->name."' v".$cfg->version." made by '".$cfg->author."' : '".$cfg->website."'");
|
|
||||||
|
|
||||||
require_once($class_file);
|
|
||||||
|
|
||||||
// If no config file found, but a main class is, load that
|
|
||||||
} elseif ( file_exists(FUZEPATH . "/Core/Mods/".strtolower($name)."/class.".$class_name.".php") ){
|
|
||||||
$this->mods->logger->log("Loading module '".$class_name."'");
|
|
||||||
$path = FUZEPATH . "/Core/Mods/".strtolower($name)."/";
|
|
||||||
require_once(FUZEPATH . "/Core/Mods/".strtolower($name)."/class.".$class_name.".php");
|
|
||||||
|
|
||||||
// Otherwise Abort
|
|
||||||
} else {
|
|
||||||
// MOD NOT FOUND
|
|
||||||
throw new Exception("Requested mod '".$name."' was not found", 1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create class object
|
|
||||||
$CLASS = new $class_name($this);
|
|
||||||
if (method_exists($CLASS, 'setModulePath')) {
|
|
||||||
$CLASS->setModulePath($path);
|
|
||||||
}
|
|
||||||
$this->mods->{strtolower($name)} = &$CLASS;
|
|
||||||
$CLASS->onLoad();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The basic module path
|
||||||
|
$path = FUZEPATH . "/Core/Mods/";
|
||||||
|
|
||||||
|
// Chech if the requested module is set
|
||||||
|
if (isset($this->register[$name])) {
|
||||||
|
// Check if the config file is loaded
|
||||||
|
if (!empty($this->register[$name])) {
|
||||||
|
// Load the config file
|
||||||
|
$cfg = (object) $this->register[$name];
|
||||||
|
|
||||||
|
// Check if the module is enabled, otherwise abort
|
||||||
|
if (isset($cfg->enabled)) {
|
||||||
|
if (!$cfg->enabled) {
|
||||||
|
// Module is disabled
|
||||||
|
throw new Exception("Module '".$name."' is not enabled!", 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a specific version is requested
|
||||||
|
if (isset($version)) {
|
||||||
|
if (isset($cfg->versions)) {
|
||||||
|
if (isset($cfg->versions[$version])) {
|
||||||
|
$ncfg = (object) $cfg->versions[$version];
|
||||||
|
foreach ($ncfg as $key => $value) {
|
||||||
|
$cfg->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or load the main version
|
||||||
|
$file = $cfg->directory . $cfg->module_file;
|
||||||
|
|
||||||
|
// Load the dependencies before the module loads
|
||||||
|
$deps = (isset($cfg->dependencies) ? $cfg->dependencies : array());
|
||||||
|
for ($i=0; $i < count($deps); $i++) {
|
||||||
|
$this->loadMod($deps[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the file exists
|
||||||
|
if (file_exists($file)) {
|
||||||
|
// And load it
|
||||||
|
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: "");
|
||||||
|
$this->mods->logger->log($msg);
|
||||||
|
} else {
|
||||||
|
// Throw Exception if the file does not exist
|
||||||
|
throw new Exception("Requested mod '".$name."' could not be loaded. Class file not found", 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Throw Exception if the module has an invalid config file
|
||||||
|
throw new Exception("Requested mod '".$name."' could not be loaded. Invalid config", 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Throw Exception if the module is not defined
|
||||||
|
throw new Exception("Requested mod '".$name."' was not found", 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create class object
|
||||||
|
$CLASS = new $class_name($this);
|
||||||
|
if (method_exists($CLASS, 'setModulePath')) {
|
||||||
|
$CLASS->setModulePath($cfg->directory);
|
||||||
|
}
|
||||||
|
if (method_exists($CLASS, 'setModuleLinkName')) {
|
||||||
|
$CLASS->setModuleLinkName($cfg->module_name);
|
||||||
|
}
|
||||||
|
if (method_exists($CLASS, 'setModuleName')) {
|
||||||
|
$CLASS->setModuleName($name);
|
||||||
|
}
|
||||||
|
$CLASS->onLoad();
|
||||||
|
return array($CLASS, $cfg->module_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildModRegister() {
|
||||||
|
$this->mods->logger->newLevel("Building Mod Register", 'Core');
|
||||||
|
$dir = FUZEPATH . "Core/Mods/";
|
||||||
|
$mods = array_values(array_diff(scandir($dir), array('..', '.')));
|
||||||
|
$register = array();
|
||||||
|
for ($i=0; $i < count($mods); $i++) {
|
||||||
|
$mod_dir = $dir . $mods[$i] . "/";
|
||||||
|
if (file_exists($mod_dir . "/moduleInfo.php")) {
|
||||||
|
$cfg = (object) require($mod_dir . "/moduleInfo.php");
|
||||||
|
$name = "";
|
||||||
|
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
|
||||||
|
$name .= strtolower($cfg->module_name);
|
||||||
|
|
||||||
|
// Append directory
|
||||||
|
$cfg->directory = $mod_dir;
|
||||||
|
$register[$name] = (array) $cfg;
|
||||||
|
} else {
|
||||||
|
// Get the name
|
||||||
|
$name = $mods[$i];
|
||||||
|
|
||||||
|
// Build a dynamic module config
|
||||||
|
$cfg = new stdClass();
|
||||||
|
$cfg->module_class = ucfirst($name);
|
||||||
|
$cfg->module_file = 'class.'.strtolower($name).".php";
|
||||||
|
$cfg->module_name = $name;
|
||||||
|
$cfg->dependencies = array();
|
||||||
|
$cfg->versions = array();
|
||||||
|
$cfg->directory = $mod_dir;
|
||||||
|
$register[$name] = (array)$cfg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->mods->logger->stopLevel();
|
||||||
|
$this->mods->config->set('modregister', 'register', $register);
|
||||||
|
$this->mods->config->set('main', 'registers_last_update', date('U'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,11 +156,12 @@ class Events extends Bus{
|
|||||||
public function buildEventRegister() {
|
public function buildEventRegister() {
|
||||||
$this->logger->newLevel("Building Event Register", 'Events');
|
$this->logger->newLevel("Building Event Register", 'Events');
|
||||||
$dir = FUZEPATH . "/Core/Mods/";
|
$dir = FUZEPATH . "/Core/Mods/";
|
||||||
$mods = array_values(array_diff(scandir($dir), array('..', '.')));
|
$mods = $this->config->modregister->register;
|
||||||
for ($i=0; $i < count($mods); $i++) {
|
foreach ($mods as $key => $value) {
|
||||||
$this->core->loadMod($mods[$i]);
|
try {
|
||||||
|
$this->core->loadMod($key);
|
||||||
|
} catch (Exception $e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = $this->fireEvent('eventRegisterBuildEvent', '');
|
$event = $this->fireEvent('eventRegisterBuildEvent', '');
|
||||||
$this->config->set('eventregister', 'register', $event->register);
|
$this->config->set('eventregister', 'register', $event->register);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user