Merge branch 'master' into 'master'

New Features and Core Improvements

The following features have been added:

- Writable PHP Config files
- An EventRegister, which allows modules to be loaded at certain events
- Implemented module dependencies
- More PHP Documentation
- Smarty event, allowing plugin registration from other modules
- Various Bugfixes

See merge request !2
This commit is contained in:
Abel Hoogeveen 2015-02-23 22:13:57 +01:00
commit 9c249e0370
20 changed files with 160 additions and 45 deletions

View File

@ -1 +0,0 @@
{"type":"","host":"","database":"","username":"","password":"","prefix":""}

View File

@ -0,0 +1,8 @@
<?php return array (
'type' => '',
'host' => '',
'database' => '',
'username' => '',
'password' => '',
'prefix' => '',
) ;

View File

@ -1 +0,0 @@
{"debug":false,"error_reporting":true}

View File

@ -0,0 +1,4 @@
<?php return array (
'debug' => false,
'error_reporting' => true,
) ;

View File

@ -0,0 +1,5 @@
<?php return array (
'register' =>
array (
),
) ;

View File

@ -1,26 +1,12 @@
<?php
return array(
# Sendmail Settings
'sendmail_enabled' => true,
# SMTP Settings
'smtp_enabled' => false,
'smtp_host' => '',
'smtp_port' => 25,
'smtp_auth' => false,
'smtp_username' => '',
'smtp_password' => '',
/**
* 0 = off
* 1 = client messages
* 2 = client and server messages
*/
'smtp_debug_level' => 0,
# Common sender information
'sender_name' => '',
'sender_mail' => '',
);
?>
<?php return array (
'sendmail_enabled' => true,
'smtp_enabled' => false,
'smtp_host' => '',
'smtp_port' => 25,
'smtp_auth' => false,
'smtp_username' => '',
'smtp_password' => '',
'smtp_debug_level' => 0,
'sender_name' => '',
'sender_mail' => '',
) ;

View File

@ -1 +0,0 @@
{"SITE_URL":"","SITE_DOMAIN":"","SERVER_NAME":"","administrator_mail":"","default_controller":"standard","default_function":"index"}

View File

@ -0,0 +1,8 @@
<?php return array (
'SITE_URL' => '',
'SITE_DOMAIN' => '',
'SERVER_NAME' => '',
'administrator_mail' => '',
'default_controller' => 'standard',
'default_function' => 'index',
) ;

View File

@ -1 +0,0 @@
{"cookie_name":"","urlSelector":""}

View File

@ -0,0 +1,4 @@
<?php return array (
'cookie_name' => '',
'urlSelector' => '',
) ;

View File

@ -30,7 +30,7 @@
<img src='http://myfuze.net/Fuze2tra.png' />
</div>
<div class='col-lg-12 col-md-4 col-sm-12'>
<div class='col-lg-12 col-md-12 col-sm-12'>
<div id='contentPanel' class="panel panel-default" style='display:none'>
<div id='1' class="panel-body" style='display:none'>
<p class="lead">Dear visitor,</p>
@ -44,8 +44,6 @@
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,17 @@
<?php
class EventRegisterBuildEvent extends Event {
public $register = array();
public function init($call){}
public function addEvent($modName, $eventName) {
if (!isset($this->register[$eventName])) {
$this->register[$eventName] = array();
}
$this->register[$eventName][] = $modName;
}
}
?>

View File

@ -13,7 +13,6 @@
* EventPriority::LOW
* EventPriority::LOWEST
*
* @package System\Core
*/
abstract class EventPriority

View File

@ -4,8 +4,6 @@
* Class Module
*
* Abstract Class for modules
*
* @package System\Core
*/
class Module extends Bus {

View File

@ -1,26 +1,49 @@
<?php
/**
* Config Module
*
* This class gives access to the config files. Allows for reading and editting
*/
class Config extends Bus{
/**
* Wether or not the database is active at the moment
* @access public
* @var Boolean true on active database
*/
public $dbActive = false;
/**
* Class Constructor
* @access public
* @param FuzeWorks Core Reference
*/
public function __construct(&$core) {
parent::__construct($core);
}
/**
* Get's called when the class get's loaded. Does nothing
* @access public
*/
public function onLoad() {}
/**
* Reads a config file and returns it as object
* @access public
* @param String config file name
* @param String directory, default is Application/Config
* @throws \Exception on file not found
* @return StdObject of config
*/
public function loadConfigFile($name, $directory = null) {
$dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/");
$file = $dir . 'config.' . strtolower($name).".php";
$file2 = $dir . 'config.' . strtolower($name).".enc.cfg";
if (file_exists($file)) {
$DECODED = (object) require($file);
return $DECODED;
} elseif (file_exists($file2)) {
$data = file_get_contents($file2);
return json_decode($data);
} else {
$this->core->loadMod('database');
if ($this->dbActive) {
@ -53,6 +76,45 @@ class Config extends Bus{
}
}
/**
* Change a value in the config, wherever this is saved
* @access public
* @param String filename
* @param String config key
* @param String/Array config value
* @param String directory, default is Application/Config
*/
public function set($name, $key, $value, $directory = null) {
$dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/");
$file = $dir . 'config.' . strtolower($name).".php";
$file2 = $dir . 'config.' . strtolower($name).".enc.cfg";
if (file_exists($file)) {
$DECODED = require($file);
if (!is_array($DECODED)) {
$DECODED = array();
}
if (is_null($value)) {
unset($DECODED[$key]);
} else {
$DECODED[$key] = $value;
}
if (is_writable($file)) {
$config = var_export($DECODED, true);
file_put_contents($file, "<?php return $config ;");
}
} else {
throw new Exception("Config file '".strtolower($name)."' was not found", 1);
return false;
}
}
/**
* Magic config getter
* @access public
* @param String config file name
* @return StdObject of config
*/
public function __get($name) {
return $this->loadConfigFile($name);
}

View File

@ -75,11 +75,22 @@ class Core {
// If not, and a mod config file is found, follow that
} 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

View File

@ -6,7 +6,6 @@
/**
* @name Events
* @package Core
*/
class Events extends Bus{
@ -112,6 +111,14 @@ class Events extends Bus{
$this->logger->log("Checking for Listeners");
// Read the event register for listeners
$register = $this->config->eventregister->register;
if (isset($register[$eventName])) {
for ($i=0; $i < count($register[$eventName]); $i++) {
$this->core->loadMod($register[$eventName][$i]);
}
}
//There are listeners for this event
if(isset($this->listeners[$eventName])) {
//Loop from the highest priority to the lowest
@ -145,8 +152,20 @@ class Events extends Bus{
return $event;
}
// Event Preparation:
public function buildEventRegister() {
$this->logger->newLevel("Building Event Register", 'Events');
$dir = FUZEPATH . "/Core/Mods/";
$mods = array_values(array_diff(scandir($dir), array('..', '.')));
for ($i=0; $i < count($mods); $i++) {
$this->core->loadMod($mods[$i]);
}
$event = $this->fireEvent('eventRegisterBuildEvent', '');
$this->config->set('eventregister', 'register', $event->register);
$this->logger->stopLevel();
}
}
class NotifierEvent extends Event {}

View File

@ -4,7 +4,7 @@ class Layout extends Bus {
private $Smarty = array();
private $title = "";
private $loaded = false;
public $loaded = false;
public function __construct(&$core) {
parent::__construct($core);
@ -25,6 +25,7 @@ class Layout extends Bus {
$this->Smarty['main'] = $this->getSmartyBasicVars($this->Smarty['main']);
$this->loaded = true;
$this->mods->events->fireEvent('smartyLoadEvent');
}
public function getSmartyBasicVars($Smarty) {

View File

@ -17,11 +17,11 @@ class Logger extends Bus{
set_Exception_handler(array($this, "exceptionHandler"));
error_reporting(false);
}
$this->events->addListener(array($this, 'onCoreShutdownEvent'), 'coreShutdownEvent', EventPriority::LOWEST);
$this->events->addListener(array($this, 'shutdown'), 'coreShutdownEvent', EventPriority::LOWEST);
$this->newLevel("Logger Initiated");
}
public function onCoreShutdownEvent() {
public function shutdown() {
// Load last error if thrown
$errfile = "Unknown file";
$errstr = "shutdown";

View File

@ -1,7 +1,6 @@
<?php
/**
* @author FuzeNetwork
* @package files
*/
class Models extends Bus{