2015-05-14 10:43:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-08-29 15:43:13 +00:00
|
|
|
* FuzeWorks
|
|
|
|
*
|
|
|
|
* The FuzeWorks MVC PHP FrameWork
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 TechFuze
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author TechFuze
|
|
|
|
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
|
|
|
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
|
|
|
* @link http://fuzeworks.techfuze.net
|
|
|
|
* @since Version 0.0.1
|
|
|
|
* @version Version 0.0.1
|
2015-05-14 10:43:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace FuzeWorks;
|
|
|
|
use \stdClass;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modules Class
|
2015-08-29 15:43:13 +00:00
|
|
|
* @package net.techfuze.fuzeworks.core
|
|
|
|
* @author Abel Hoogeveen <abel@techfuze.net>
|
|
|
|
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
|
2015-05-14 10:43:11 +00:00
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
class Modules {
|
2015-05-14 10:43:11 +00:00
|
|
|
|
2015-10-11 18:14:49 +00:00
|
|
|
/**
|
|
|
|
* A register of all the existing module headers.
|
|
|
|
*
|
|
|
|
* The module headers contain information required to loading the module
|
|
|
|
* @var Array
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static $register;
|
2015-10-11 18:14:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of all the loaded modules
|
|
|
|
* @var array
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static $modules = array();
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-11 18:14:49 +00:00
|
|
|
* An array with the names of all modules that are loaded, and should not be loaded again
|
2015-05-14 10:43:11 +00:00
|
|
|
* @access private
|
|
|
|
* @var Array of module names
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
private static $loaded_modules = array();
|
2015-05-14 10:43:11 +00:00
|
|
|
|
2015-10-11 18:14:49 +00:00
|
|
|
/**
|
|
|
|
* An array which holds the routes to module to load them quickly
|
|
|
|
* @access private
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $module_routes = array();
|
|
|
|
|
2015-05-14 10:43:11 +00:00
|
|
|
/**
|
2015-09-05 19:47:35 +00:00
|
|
|
* Retrieves a module and returns it.
|
|
|
|
* If a module is already loaded, it returns a reference to the loaded version
|
|
|
|
* @param String $name Name of the module
|
|
|
|
* @return \FuzeWorks\Module Module The module
|
2015-10-11 18:14:49 +00:00
|
|
|
* @throws \FuzeWorks\ModuleException
|
2015-05-14 10:43:11 +00:00
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static function get($name) {
|
2015-05-14 10:43:11 +00:00
|
|
|
// Where the modules are
|
|
|
|
$path = "Modules/";
|
|
|
|
|
|
|
|
// Check if the requested module is registered
|
2015-09-05 19:47:35 +00:00
|
|
|
if (isset(self::$register[$name])) {
|
|
|
|
if (!empty(self::$register[$name])) {
|
2015-05-14 10:43:11 +00:00
|
|
|
// Load the moduleInfo
|
2015-09-05 19:47:35 +00:00
|
|
|
$cfg = (object) self::$register[$name];
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Check if the module is disabled
|
|
|
|
if (isset($cfg->meta)) {
|
|
|
|
throw new ModuleException("Requested mod '".$name."' could not be loaded. Not enabled", 1);
|
2015-08-29 15:43:13 +00:00
|
|
|
return false;
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the module is already loaded. If so, only return a reference, if not, load the module
|
2015-09-05 19:47:35 +00:00
|
|
|
if (in_array($name, self::$loaded_modules)) {
|
2015-05-14 10:43:11 +00:00
|
|
|
// return the link
|
|
|
|
$msg = "Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "' is already loaded";
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log($msg);
|
|
|
|
$c = self::$modules[strtolower($cfg->module_name)];
|
2015-05-14 10:43:11 +00:00
|
|
|
return $c;
|
|
|
|
} else {
|
|
|
|
// Load the module
|
|
|
|
$file = $cfg->directory ."/". $cfg->module_file;
|
|
|
|
|
|
|
|
// Load the dependencies before the module loads
|
|
|
|
$deps = (isset($cfg->dependencies) ? $cfg->dependencies : array());
|
2015-08-29 15:43:13 +00:00
|
|
|
for ($i=0; $i < count($deps); $i++) {
|
2015-09-05 19:47:35 +00:00
|
|
|
self::get($deps[$i]);
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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: "");
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log($msg);
|
2015-05-14 10:43:11 +00:00
|
|
|
} else {
|
|
|
|
// Throw Exception if the file does not exist
|
|
|
|
throw new ModuleException("Requested mod '".$name."' could not be loaded. Class file not found", 1);
|
2015-08-29 15:43:13 +00:00
|
|
|
return false;
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it is an abstract module, load an StdClass for the module address
|
|
|
|
if (isset($cfg->abstract)) {
|
|
|
|
if ($cfg->abstract) {
|
|
|
|
$CLASS = new stdClass();
|
2015-09-05 19:47:35 +00:00
|
|
|
return self::$modules[strtolower($cfg->module_name)] = &$CLASS;
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the module class
|
|
|
|
$class_name = $cfg->module_class;
|
2015-09-05 19:47:35 +00:00
|
|
|
$CLASS = new $class_name();
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Apply default methods
|
|
|
|
if (method_exists($CLASS, 'setModulePath')) {
|
|
|
|
$CLASS->setModulePath($cfg->directory);
|
|
|
|
}
|
|
|
|
if (method_exists($CLASS, 'setModuleLinkName')) {
|
|
|
|
$CLASS->setModuleLinkName(strtolower($cfg->module_name));
|
|
|
|
}
|
|
|
|
if (method_exists($CLASS, 'setModuleName')) {
|
|
|
|
$CLASS->setModuleName($name);
|
|
|
|
}
|
|
|
|
if (method_exists($CLASS, 'setModuleConfig')) {
|
2015-08-02 16:40:00 +00:00
|
|
|
// Append the config file to the module CFG (accessable through $this->cfg)
|
|
|
|
if (file_exists($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php")) {
|
|
|
|
$data = (object) include($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php");
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$cfg->$key = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-14 10:43:11 +00:00
|
|
|
$CLASS->setModuleConfig($cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!method_exists($CLASS, 'onLoad')) {
|
|
|
|
throw new ModuleException("Module '".$name."' does not have an onLoad() method! Invalid module", 1);
|
|
|
|
}
|
|
|
|
$CLASS->onLoad();
|
|
|
|
|
|
|
|
// Add to the loaded modules
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$loaded_modules[] = $name;
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Return a reference
|
2015-09-05 19:47:35 +00:00
|
|
|
return self::$modules[strtolower($cfg->module_name)] = &$CLASS;
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 18:14:49 +00:00
|
|
|
/**
|
|
|
|
* Set the value of a module config or moduleInfo.php
|
|
|
|
* @param String $file File to edit
|
|
|
|
* @param String $key Key to edit
|
|
|
|
* @param Mixed $value Value to set
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
private static function setModuleValue($file, $key, $value) {
|
2015-05-14 10:43:11 +00:00
|
|
|
if (file_exists($file) && is_writable($file)) {
|
|
|
|
$cfg = require($file);
|
|
|
|
$cfg[$key] = $value;
|
|
|
|
$config = var_export($cfg, true);
|
|
|
|
file_put_contents($file, "<?php return $config ;");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-11 18:14:49 +00:00
|
|
|
* Add a module using a moduleInfo.php file
|
|
|
|
*
|
|
|
|
* @param String Path to moduleInfo.php file
|
2015-05-14 10:43:11 +00:00
|
|
|
* @throws FuzeWorks\ModuleException
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static function addModule($moduleInfo_file) {
|
2015-05-14 10:43:11 +00:00
|
|
|
$file = $moduleInfo_file;
|
|
|
|
$directory = dirname($file);
|
|
|
|
if (file_exists($file)) {
|
|
|
|
$cfg = (object) require($file);
|
|
|
|
$cfg->directory = $directory;
|
|
|
|
|
|
|
|
// Define the module name
|
|
|
|
$name = "";
|
|
|
|
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
|
|
|
|
$name .= strtolower($cfg->module_name);
|
|
|
|
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log("Adding module: '".$name."'");
|
|
|
|
if (isset(self::$register[$name])) {
|
|
|
|
Logger::logError("Module '".$name."' can not be added. Module is already loaded");
|
2015-05-14 10:43:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check wether the module is enabled or no
|
|
|
|
if (isset($cfg->enabled)) {
|
|
|
|
if ($cfg->enabled) {
|
|
|
|
// Copy all the data into the register and enable
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$register[$name] = (array) $cfg;
|
|
|
|
Logger::log("[ON] '".$name."'");
|
2015-05-14 10:43:11 +00:00
|
|
|
} else {
|
|
|
|
// If not, copy all the basic data so that it can be enabled in the future
|
|
|
|
$cfg2 = new StdClass();
|
|
|
|
$cfg2->module_name = $cfg->module_name;
|
|
|
|
$cfg2->directory = $cfg->directory;
|
|
|
|
$cfg2->meta = $cfg;
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$register[$name] = (array)$cfg2;
|
|
|
|
Logger::log("[OFF] '".$name."'");
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Copy all the data into the register and enable
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$register[$name] = (array) $cfg;
|
|
|
|
Logger::log("[ON] '".$name."'");
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new ModuleException("Could not add module. '$moduleInfo_file' does not exist", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-11 18:14:49 +00:00
|
|
|
* Enables a module when it is disabled
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param String Module name
|
|
|
|
* @param boolean true for permanent enable
|
2015-05-14 10:43:11 +00:00
|
|
|
* @throws FuzeWorks\ModuleException
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static function enableModule($name, $permanent = true) {
|
|
|
|
if (isset(self::$register[$name])) {
|
2015-05-14 10:43:11 +00:00
|
|
|
// Change the register
|
2015-09-05 19:47:35 +00:00
|
|
|
$info = (object) self::$register[$name];
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Do nothing if it is already enabled
|
|
|
|
if (isset($info->enabled)) {
|
|
|
|
if ($info->enabled) {
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::logWarning("Could not enable module '".$name."'. Module is already enabled.");
|
2015-05-14 10:43:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise move data from meta to the module config
|
|
|
|
$info = $info->meta;
|
|
|
|
$info->enabled = true;
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$register[$name] = (array)$info;
|
2015-05-14 10:43:11 +00:00
|
|
|
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log("Enabled module '".$name."'");
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Enable it permanently if so desired
|
|
|
|
if ($permanent) {
|
|
|
|
$file = $info->directory . "/moduleInfo.php";
|
2015-09-05 19:47:35 +00:00
|
|
|
self::setModuleValue($file, 'enabled', true);
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reload the eventRegister
|
2015-09-05 19:47:35 +00:00
|
|
|
Events::buildEventRegister();
|
2015-05-14 10:43:11 +00:00
|
|
|
} else {
|
|
|
|
throw new ModuleException("Could not enable module '".$name."'. Module does not exist.", 1);
|
2015-08-29 15:43:13 +00:00
|
|
|
}
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-11 18:14:49 +00:00
|
|
|
* Disableds a module when it is enabled
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param String Module name
|
|
|
|
* @param boolean true for permanent disable
|
2015-05-14 10:43:11 +00:00
|
|
|
* @throws FuzeWorks\ModuleException
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static function disableModule($name, $permanent = true) {
|
|
|
|
if (isset(self::$register[$name])) {
|
|
|
|
$info = (object) self::$register[$name];
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Do nothing if it is already disabled
|
|
|
|
if (isset($info->meta)) {
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::logWarning("Could not disable module '".$name."'. Module is already disabled.");
|
2015-05-14 10:43:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$disabled = new StdClass();
|
|
|
|
$disabled->meta = $info;
|
|
|
|
$disabled->directory = $info->directory;
|
|
|
|
$disabled->module_name = $info->module_name;
|
|
|
|
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$register[$name] = (array)$disabled;
|
|
|
|
Logger::log("Disabled module '".$name."'");
|
2015-05-14 10:43:11 +00:00
|
|
|
if ($permanent) {
|
|
|
|
$file = $info->directory . "/moduleInfo.php";
|
2015-09-05 19:47:35 +00:00
|
|
|
self::setModuleValue($file, 'enabled', false);
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reload the eventRegister
|
2015-09-05 19:47:35 +00:00
|
|
|
Events::buildEventRegister();
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Remove the existence of the module
|
2015-09-05 19:47:35 +00:00
|
|
|
unset(self::$modules[strtolower($cfg->module_name)]);
|
2015-05-14 10:43:11 +00:00
|
|
|
} else {
|
|
|
|
throw new ModuleException("Could not disable module '".$name."'. Module does not exist.", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-11 18:14:49 +00:00
|
|
|
/**
|
|
|
|
* Create a register with all the module headers from all the existing modules.
|
|
|
|
*
|
|
|
|
* Used to correctly load all modules
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-09-05 19:47:35 +00:00
|
|
|
public static function buildRegister() {
|
|
|
|
Logger::newLevel("Loading Module Headers", 'Core');
|
2015-05-14 10:43:11 +00:00
|
|
|
|
|
|
|
// Get all the module directories
|
|
|
|
$dir = "Modules/";
|
|
|
|
$mod_dirs = array();
|
|
|
|
$mod_dirs = array_values(array_diff(scandir($dir), array('..', '.')));
|
|
|
|
|
|
|
|
// Build the module register
|
|
|
|
$register = array();
|
2015-08-29 15:43:13 +00:00
|
|
|
for ($i=0; $i < count($mod_dirs); $i++) {
|
2015-05-14 10:43:11 +00:00
|
|
|
$mod_dir = $dir . $mod_dirs[$i] . "/";
|
|
|
|
// If a moduleInfo.php exists, load it
|
|
|
|
if (file_exists($mod_dir . "/moduleInfo.php")) {
|
|
|
|
// Load the configuration file
|
|
|
|
$cfg = (object) require($mod_dir . "/moduleInfo.php");
|
|
|
|
|
|
|
|
// Define the module name
|
|
|
|
$name = "";
|
|
|
|
$name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : "");
|
|
|
|
$name .= strtolower($cfg->module_name);
|
|
|
|
|
|
|
|
// Get the module directory
|
|
|
|
$cfg->directory = $mod_dir;
|
|
|
|
|
|
|
|
// Check wether the module is enabled or no
|
|
|
|
if (isset($cfg->enabled)) {
|
|
|
|
if ($cfg->enabled) {
|
|
|
|
// Copy all the data into the register and enable
|
|
|
|
$register[$name] = (array) $cfg;
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log("[ON] '".$name."'");
|
2015-08-29 19:07:17 +00:00
|
|
|
|
|
|
|
// Add all module aliases if available
|
|
|
|
if (isset($cfg->aliases)) {
|
|
|
|
foreach ($cfg->aliases as $alias) {
|
|
|
|
$register[$alias] = (array) $cfg;
|
2015-09-05 16:57:55 +00:00
|
|
|
unset($register[$alias]['events']);
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log(" '".$alias."' (alias of '".$name."')");
|
2015-08-29 19:07:17 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-11 18:14:49 +00:00
|
|
|
|
|
|
|
// If routes are present, add them to the router
|
|
|
|
if (isset($cfg->routes)) {
|
|
|
|
foreach ($cfg->routes as $route) {
|
|
|
|
// Create the route and callable and parse them
|
|
|
|
$callable = array('\FuzeWorks\Modules', 'moduleCallable');
|
|
|
|
Router::addRoute($route, $callable, true);
|
|
|
|
self::$module_routes[$route] = $name;
|
|
|
|
}
|
|
|
|
}
|
2015-05-14 10:43:11 +00:00
|
|
|
} else {
|
|
|
|
// If not, copy all the basic data so that it can be enabled in the future
|
|
|
|
$cfg2 = new StdClass();
|
|
|
|
$cfg2->module_name = $cfg->module_name;
|
|
|
|
$cfg2->directory = $cfg->directory;
|
|
|
|
$cfg2->meta = $cfg;
|
|
|
|
$register[$name] = (array)$cfg2;
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log("[OFF] '".$name."'");
|
2015-08-29 19:07:17 +00:00
|
|
|
|
|
|
|
// Add all module aliases if available
|
|
|
|
if (isset($cfg->aliases)) {
|
|
|
|
foreach ($cfg->aliases as $alias) {
|
|
|
|
$register[$alias] = (array) $cfg2;
|
2015-09-05 16:57:55 +00:00
|
|
|
unset($register[$alias]['events']);
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log(" '".$alias."' (alias of '".$name."')");
|
2015-08-29 19:07:17 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Copy all the data into the register and enable
|
|
|
|
$register[$name] = (array) $cfg;
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log("[ON] '".$name."'");
|
2015-08-29 19:07:17 +00:00
|
|
|
|
|
|
|
// Add all module aliases if available
|
|
|
|
if (isset($cfg->aliases)) {
|
|
|
|
foreach ($cfg->aliases as $alias) {
|
|
|
|
$register[$alias] = (array) $cfg;
|
2015-09-05 16:57:55 +00:00
|
|
|
unset($register[$alias]['events']);
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log(" '".$alias."' (alias of '".$name."')");
|
2015-08-29 19:07:17 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If no details are specified, create a basic module
|
|
|
|
$name = $mod_dirs[$i];
|
|
|
|
|
|
|
|
// Build a default 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;
|
|
|
|
|
|
|
|
// Apply it
|
|
|
|
$register[$name] = (array)$cfg;
|
2015-09-05 19:47:35 +00:00
|
|
|
Logger::log("[ON] '".$name."'");
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 19:47:35 +00:00
|
|
|
self::$register = $register;
|
|
|
|
Logger::stopLevel();
|
2015-08-29 15:43:13 +00:00
|
|
|
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 18:14:49 +00:00
|
|
|
/**
|
|
|
|
* The Module Callable
|
|
|
|
*
|
|
|
|
* When a module listens for a specific routing path, this callable get's called.
|
|
|
|
* After this the module can handle the request with the route() function in the module's root directory
|
|
|
|
* @access public
|
|
|
|
* @param array Regex matches
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function moduleCallable($matches = array()){
|
|
|
|
// First detect what module is attached to this route
|
|
|
|
Logger::newLevel('Module callable called!');
|
|
|
|
|
|
|
|
// Get the route
|
|
|
|
$route = !empty($matches['route']) ? $matches['route'] : null;
|
|
|
|
|
|
|
|
// See if the route exists
|
|
|
|
if (isset(self::$module_routes[$route])) {
|
|
|
|
Logger::log("Module '".self::$module_routes[$route]."' matched given route");
|
|
|
|
|
|
|
|
// Load the module
|
|
|
|
$mod = self::get(self::$module_routes[$route]);
|
|
|
|
unset($matches['route']);
|
|
|
|
$mod->route($matches);
|
|
|
|
} else {
|
|
|
|
Logger::logError("Route did not match known module. Fatal error");
|
|
|
|
return Logger::http_error(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger::stopLevel();
|
|
|
|
}
|
|
|
|
|
2015-05-14 10:43:11 +00:00
|
|
|
}
|
2015-08-29 15:43:13 +00:00
|
|
|
|
2015-05-14 10:43:11 +00:00
|
|
|
?>
|