diff --git a/Application/Config/config.eventregister.php b/Application/Config/config.eventregister.php deleted file mode 100644 index 7d849f6..0000000 --- a/Application/Config/config.eventregister.php +++ /dev/null @@ -1,5 +0,0 @@ - - array ( - ), -) ; \ No newline at end of file diff --git a/Application/Config/config.main.php b/Application/Config/config.main.php index 118ca4b..76e258c 100644 --- a/Application/Config/config.main.php +++ b/Application/Config/config.main.php @@ -2,7 +2,6 @@ 'SITE_URL' => '', 'SITE_DOMAIN' => '', 'SERVER_NAME' => '', - 'registers_update_interval' => 3600, 'administrator_mail' => '', 'default_controller' => 'standard', 'default_function' => 'index', diff --git a/Application/Config/config.modregister.php b/Application/Config/config.modregister.php deleted file mode 100644 index e69de29..0000000 diff --git a/Application/Controller/controller.standard.php b/Application/Controller/controller.standard.php index 644309c..90ebfc5 100644 --- a/Application/Controller/controller.standard.php +++ b/Application/Controller/controller.standard.php @@ -1,6 +1,9 @@ route = $route; + $this->controllerName = $controllerName; + $this->function = $function; + $this->parameters = $parameters; + $this->directory = $directory; + } +} + +?> \ No newline at end of file diff --git a/Core/Events/event.eventRegisterBuildEvent.php b/Core/Events/event.eventRegisterBuildEvent.php deleted file mode 100644 index 4c3d2d9..0000000 --- a/Core/Events/event.eventRegisterBuildEvent.php +++ /dev/null @@ -1,17 +0,0 @@ -register[$eventName])) { - $this->register[$eventName] = array(); - } - $this->register[$eventName][] = $modName; - } -} - -?> \ No newline at end of file diff --git a/Core/Events/event.layoutLoadEvent.php b/Core/Events/event.layoutLoadEvent.php new file mode 100644 index 0000000..04f2514 --- /dev/null +++ b/Core/Events/event.layoutLoadEvent.php @@ -0,0 +1,15 @@ +layout = $layout; + } +} + +?> \ No newline at end of file diff --git a/Core/Events/event.modelLoadEvent.php b/Core/Events/event.modelLoadEvent.php new file mode 100644 index 0000000..ef5c08a --- /dev/null +++ b/Core/Events/event.modelLoadEvent.php @@ -0,0 +1,15 @@ +model = $model; + } +} + +?> \ No newline at end of file diff --git a/Core/Events/event.routerRouteEvent.php b/Core/Events/event.routerRouteEvent.php index ba4b34a..4441290 100644 --- a/Core/Events/event.routerRouteEvent.php +++ b/Core/Events/event.routerRouteEvent.php @@ -1,5 +1,7 @@ connect($this->getSystemDbSettings()); - $this->config->dbActive = true; - } - - public function connect($params = array()) { - if (isset($params['type'])) { - $type = $params['type']; - } else { - throw (new Exception("No database type given")); - } - - if (isset($params['datb'])) { - $database = $params['datb']; - } else { - throw (new Exception("No database given. Can not connect without database.")); - } - - if (isset($params['host'])) { - $host = $params['host']; - } else { - throw (new Exception("No database host given. Can not connect without hostname.")); - } - - $username = $params['user']; - $password = $params['pass']; - $this->prefix = $params['prefix']; - - if (isset($params['options'])) { - $options = $params['options']; - } else { - $options = null; - } - - - $DSN_FINAL = ""; - - switch ($type) { - case 'MYSQL': - $DSN = "mysql:host="; - $DSN2 = ";dbname="; - - // Check if charset is required - if (isset($extraOptions)) { - if (isset($extraOptions->charset)) { - $DSN3 = ";charset=" . $extraOptions->charset; - } else { - $DSN3 = ";"; - } - } else { - $DSN3 = ";"; - } - $DSN_FINAL = $DSN . $host . $DSN2 . $database . $DSN3; - break; - case 'sqlite': - $DSN = 'sqlite:' . $host . ($database != '' ? ";dbname=" .$database : ""); - $DSN_FINAL = $DSN; - break; - default: - throw (new Exception("Unknown database type given: '" . $type . "'")); - break; - } - - // Try and connect - try{ - $this->mods->logger->logInfo("Connecting to '" . $DSN_FINAL. "'", "Database", __FILE__, __LINE__); - $this->DBH = new \PDO($DSN_FINAL, $username, $password, $options); - $this->DBH->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - - $this->mods->logger->logInfo("Connected!", "Database", __FILE__, __LINE__); - }catch(\PDOException $e){ - throw (new Exception('Could not connect to the database: "'. $e->getMessage() . '"')); - } - } - - public function __call($name, $params) { - if ($this->is_active()) { - return call_user_func_array(array($this->DBH, $name), $params); - } else { - $this->connect($this->getSystemDbSettings()); - return call_user_func_array(array($this->DBH, $name), $params); - } - } - - public function __get($name) { - if ($this->is_active()) { - return $this->DBH->$name; - } else { - $this->connect($this->getSystemDbSettings()); - return $this->DBH->$name; - } - } - - public function __set($name, $value) { - if ($this->is_active()) { - $this->DBH->$name = $value; - } else { - $this->connect($this->getSystemDbSettings()); - $this->DBH->$name = $value; - } - } - - public function is_active() { - if($this->DBH === null){ - return false; - } else { - return true; - } - } - - public function getPrefix() { - return $this->prefix; - } - - /** - * Retrieve an array of the system DB settings. This is the configuration in the config file of FuzeWorks - * @access public - * @return DBSettings array - */ - public function getSystemDbSettings() { - $dbsettings = array( - 'type' => $this->mods->config->database->type, - 'host' => $this->mods->config->database->host, - 'user' => $this->mods->config->database->username, - 'pass' => $this->mods->config->database->password, - 'datb' => $this->mods->config->database->database, - 'prefix' => $this->mods->config->database->prefix, - ); - return $dbsettings; - } -} - - -?> \ No newline at end of file diff --git a/Core/Mods/sections/class.sections.php b/Core/Mods/sections/class.sections.php deleted file mode 100644 index 9ef404a..0000000 --- a/Core/Mods/sections/class.sections.php +++ /dev/null @@ -1,154 +0,0 @@ -cfg = $this->config->loadConfigFile('sections', $this->getModulePath()); - - // Register Events - $this->events->addListener(array($this, 'eventRegisterBuild'), 'eventRegisterBuildEvent', 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) { - $event->addEvent('sections', 'routerRouteEvent'); - return $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; - $controller = null; - $function = null; - $parameters = array(); - $section = $this->{$name}; - - if ($section !== null) { - // Section found - $this->logger->log("Section found with name: '".$name."'", 'Sections'); - $this->currentSection = $name; - - // Logic here, first for module sections - if ($section['module_section']) { - $mod = $this->core->loadMod($section['module_name']); - $event->directory = $mod->getModulePath() . "/Controller/"; - } else { - // Now for regular sections - $event->directory = $section['controller_path']; - } - - // Move the path so it matches the new regime - if (count($event->parameters) > 0) { - $function = $event->parameters[0]; - $parameters = array_slice($event->parameters, 1); - } else { - $function = $this->config->main->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 ); - } else { - $this->logger->log("No section was found with name: '".$name."'", 'Sections'); - } - - if($controller !== null)$event->controller = $controller; - if($function !== null)$event->function = $function; - if(count($parameters) !== 0)$event->parameters = $parameters; - - 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){ - // Something given? - if(empty($name)) { - // Currently in a section? - if($this->currentSection !== null){ - // Return that one then - return $this->cfg[$this->currentSection]; - } - return null; - } - - // Return element $name of the config file - if (isset($this->cfg->$name)) { - $section = $this->cfg->$name; - } else { - $section = null; - } - - return $section; - } - -} - -?> \ No newline at end of file diff --git a/Core/Mods/sections/config.sections.php b/Core/Mods/sections/config.sections.php deleted file mode 100644 index c3388f9..0000000 --- a/Core/Mods/sections/config.sections.php +++ /dev/null @@ -1 +0,0 @@ -fields = $table_fields; } - - public function toPHP() { - $values = array(); - foreach ($this->fields as $key => $value) { - $values[] = '"'.$value.'"'; - } - $values = implode(', ', $values); - $text = 'VALUES: array('.$values.') - TABLE: '.$this->table; - echo $text; - } } ?> \ No newline at end of file diff --git a/Core/System/class.abstract.bus.php b/Core/System/class.abstract.bus.php index 58e6552..2be7358 100644 --- a/Core/System/class.abstract.bus.php +++ b/Core/System/class.abstract.bus.php @@ -1,5 +1,7 @@ core->loadMod($module_name); + $this->parentClass = $mod->giveController($controller_type); + } + + /** + * Retrieves a value from the controller class + * @access public + * @param Any key + * @return Any value from the controller class + */ + public function __get($name) { + return $this->parentClass->$name; + } + + /** + * Sets a value in the controller class + * @access public + * @param Any key + * @param Any value + */ + public function __set($name, $value) { + $this->parentClass->$name = $value; + } + + /** + * Calls a function in the controller class + * @access public + * @param String function_name + * @param Array values + * @return Function return + */ + public function __call($name, $params) { + return call_user_func_array(array($this->parentClass, $name), $params); + } +} \ No newline at end of file diff --git a/Core/System/class.abstract.event.php b/Core/System/class.abstract.event.php index f203e02..1cd8210 100644 --- a/Core/System/class.abstract.event.php +++ b/Core/System/class.abstract.event.php @@ -1,5 +1,7 @@ \ No newline at end of file diff --git a/Core/System/class.abstract.eventPriority.php b/Core/System/class.abstract.eventPriority.php index cf70665..018adf2 100644 --- a/Core/System/class.abstract.eventPriority.php +++ b/Core/System/class.abstract.eventPriority.php @@ -1,5 +1,7 @@ core->loadMod($module_name); - $this->parentClass = new $class_name($this->core); + protected function setType($module_name, $model_type) { + $mod = $this->core->loadMod($module_name); + $this->parentClass = $mod->giveModel($model_type); } /** diff --git a/Core/System/class.abstract.module.php b/Core/System/class.abstract.module.php index 0003a7c..fa1550c 100644 --- a/Core/System/class.abstract.module.php +++ b/Core/System/class.abstract.module.php @@ -1,5 +1,7 @@ core->loadMod('database'); + $this->core->loadMod('techfuze/database'); if ($this->dbActive) { // Fetch me a query of 5 $prefix = $this->mods->database->getPrefix(); @@ -85,7 +88,7 @@ class Config extends Bus{ * @param String directory, default is Application/Config */ public function set($name, $key, $value, $directory = null) { - $dir = (isset($directory) ? $directory : FUZEPATH . "Application//config/"); + $dir = (isset($directory) ? $directory : "Application/config/"); $file = $dir . 'config.' . strtolower($name).".php"; if (file_exists($file)) { $DECODED = require($file); diff --git a/Core/System/class.core.php b/Core/System/class.core.php index b2c171d..4aaa1f4 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -1,20 +1,32 @@ mods = new stdClass(); $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(); + $this->buildRegister(); + $this->mods->events->buildEventRegister(); + + $event = $this->mods->events->fireEvent('coreStartEvent'); + if ($event->isCancelled()) { + return true; } } @@ -37,18 +49,19 @@ class Core { return; // Load core abstracts - require_once(FUZESYSPATH . "/class.abstract.bus.php"); - require_once(FUZESYSPATH . "/class.abstract.event.php"); - require_once(FUZESYSPATH . "/class.abstract.module.php"); - require_once(FUZESYSPATH . "/class.abstract.model.php"); - require_once(FUZESYSPATH . "/class.abstract.eventPriority.php"); + require_once("Core/System/class.abstract.bus.php"); + require_once("Core/System/class.abstract.event.php"); + require_once("Core/System/class.abstract.module.php"); + require_once("Core/System/class.abstract.model.php"); + require_once("Core/System/class.abstract.controller.php"); + require_once("Core/System/class.abstract.eventPriority.php"); // Load the core classes - require_once(FUZESYSPATH . "/class.config.php"); - require_once(FUZESYSPATH . "/class.logger.php"); - require_once(FUZESYSPATH . "/class.models.php"); - require_once(FUZESYSPATH . "/class.layout.php"); - require_once(FUZESYSPATH . "/class.events.php"); + require_once("Core/System/class.config.php"); + require_once("Core/System/class.logger.php"); + require_once("Core/System/class.models.php"); + require_once("Core/System/class.layout.php"); + require_once("Core/System/class.events.php"); // Load them $this->mods->events = new Events ($this); @@ -64,133 +77,101 @@ class Core { $this->mods->events->fireEvent('coreShutdownEvent'); } - ## MODLOADING - public function loadMod($name, $version = null) { - // Get class information - $data = $this->loadModule($name, $version); + public function loadMod($name) { + // Where the modules are + $path = "Modules/"; - // If it is an abstract class, create and StdClass - if (empty($data)) { - return $this->mods->{strtolower($name)} = new StdClass(); - } - - // Otherwise load the class - $class_name = $data['className']; - - // Create the class object if not created yet - if (!isset($this->mods->{strtolower($data['moduleLinkName'])})) { - $CLASS = new $class_name($this); - if (method_exists($CLASS, 'setModulePath')) { - $CLASS->setModulePath($data['modulePath']); - } - if (method_exists($CLASS, 'setModuleLinkName')) { - $CLASS->setModuleLinkName($data['moduleLinkName']); - } - if (method_exists($CLASS, 'setModuleName')) { - $CLASS->setModuleName($data['moduleName']); - } - $CLASS->onLoad(); - - return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS; - } - } - - private function loadModule($name, $version = null) { - // Load the register if not loaded yet - if (!isset($this->mods->config->modregister->register)) { - $this->buildModRegister(); - } else { - $this->register = $this->mods->config->modregister->register; - } - - // The basic module path - $path = FUZEPATH . "/Core/Mods/"; - - // Chech if the requested module is set + // Check if the requested module is registered if (isset($this->register[$name])) { - // Check if the config file is loaded if (!empty($this->register[$name])) { - // Load the config file + // Load the moduleInfo $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 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 + $msg = "Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "' is already loaded"; + $this->mods->logger->log($msg); + $c = &$this->mods->{strtolower($cfg->module_name)}; + return $c; + } else { + // Load the module + $file = $cfg->directory . $cfg->module_file; - // 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; - } + // 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; + } + + // If it is an abstract module, load an StdClass for the module address + if (isset($cfg->abstract)) { + if ($cfg->abstract) { + $CLASS = new stdClass(); + return $this->mods->{strtolower($cfg->module_name)} = &$CLASS; } } - } - // 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); + // Load the module class $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; + $CLASS = new $class_name($this); + + // 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, 'onLoad')) { + throw new Exception("Module '".$name."' does not have an onLoad() method! Invalid module", 1); + } + $CLASS->onLoad(); + + // Add to the loaded modules + $this->loaded_modules[] = $name; + + // Return a reference + return $this->mods->{strtolower($cfg->module_name)} = &$CLASS; } - } 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; - } - - // If it is an abstract module, return an StdClass for the memory address - if (isset($cfg->abstract)) { - if ($cfg->abstract) { - $c = new stdClass(); - return array(); } } - - return array('className' => $class_name, - 'modulePath' => $cfg->directory, - 'moduleLinkName' => $cfg->module_name, - 'moduleName' => $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")) { + public function buildRegister() { + $this->mods->logger->newLevel("Loading Module Headers", 'Core'); + + // 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(); + for ($i=0; $i < count($mod_dirs); $i++) { + $mod_dir = $dir . $mod_dirs[$i] . "/"; + // If a moduleInfo.php exists, load it + if (file_exists($mod_dir . "/moduleInfo.php")) { $cfg = (object) require($mod_dir . "/moduleInfo.php"); $name = ""; $name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : ""); @@ -198,12 +179,24 @@ class Core { // Append directory $cfg->directory = $mod_dir; - $register[$name] = (array) $cfg; - } else { + 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 = $mods[$i]; + $name = $mod_dirs[$i]; - // Build a dynamic module config + // Build a default module config $cfg = new stdClass(); $cfg->module_class = ucfirst($name); $cfg->module_file = 'class.'.strtolower($name).".php"; @@ -212,12 +205,13 @@ class Core { $cfg->versions = array(); $cfg->directory = $mod_dir; $register[$name] = (array)$cfg; - } - } + $this->mods->logger->log("[ON] '".$name."'"); + } + } - $this->mods->logger->stopLevel(); - $this->mods->config->set('modregister', 'register', $register); - $this->mods->config->set('main', 'registers_last_update', date('U')); + $this->register = $register; + $this->mods->logger->stopLevel(); + } } diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 8551276..b12d8ec 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -3,10 +3,21 @@ * @author FuzeNetwork * @package files */ - + +namespace FuzeWorks; +use \Exception; + /** - * @name Events -*/ + * Event Class + * + * Controls FuzeWorks Events. Events are classes that get loaded during special moments in the program. + * These Event objects get send to so-called 'listeners', which can modify the event object, and eventually return them to invoker. + * Typically an event process goes like this: + * - Event get's called + * - Event object is created + * - Event object is send to all listeners in order of EventPriority + * - Event is returned + */ class Events extends Bus{ private $listeners; @@ -71,23 +82,23 @@ class Events extends Bus{ ## EVENTS public function fireEvent($input) { if (is_string($input)) { - // STRING + // If the input is a string $eventClass = $input; $eventName = $input; if(!class_exists($eventClass)){ // Check if the file even exists - $file = FUZEPATH . "/Core/Events/event.".$eventName.".php"; + $file = "Core/Events/event.".$eventName.".php"; if(file_exists($file)){ // Load the file require_once($file); }else{ - // No event arguments? Looks like an notify-event + // No event arguments? Looks like a notify-event if(func_num_args() == 1){ // Load notify-event-class - $eventClass = 'NotifierEvent'; + $eventClass = '\FuzeWorks\NotifierEvent'; }else{ // No notify-event: we tried all we could - throw new \Exception("Event ".$eventName." could not be found!"); + throw new Exception("Event ".$eventName." could not be found!"); } } } @@ -112,7 +123,7 @@ class Events extends Bus{ $this->logger->log("Checking for Listeners"); // Read the event register for listeners - $register = $this->config->eventregister->register; + $register = $this->register; if (isset($register[$eventName])) { for ($i=0; $i < count($register[$eventName]); $i++) { $this->core->loadMod($register[$eventName][$i]); @@ -154,22 +165,24 @@ class Events extends Bus{ // Event Preparation: public function buildEventRegister() { - $this->logger->newLevel("Building Event Register", 'Events'); - $dir = FUZEPATH . "/Core/Mods/"; - $mods = $this->config->modregister->register; - foreach ($mods as $key => $value) { - try { - $this->core->loadMod($key); - } catch (Exception $e) {} + $event_register = array(); + foreach ($this->core->register as $key => $value) { + if (isset($value['events'])) { + if (!empty($value['events'])) { + for ($i=0; $i < count($value['events']); $i++) { + if (isset($event_register[$value['events'][$i]])) { + $event_register[$value['events'][$i]][] = $key; + } else { + $event_register[$value['events'][$i]] = array($key); + } + } + } + } } - $event = $this->fireEvent('eventRegisterBuildEvent', ''); - $this->config->set('eventregister', 'register', $event->register); - $this->logger->stopLevel(); + $this->register = $event_register; } } -class NotifierEvent extends Event {} - ?> \ No newline at end of file diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index d2dc8c3..94f28e0 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -1,5 +1,16 @@ setCompileDir(FUZEPATH . "/Core/Cache/Compile"); - $Smarty->setCacheDir(FUZEPATH . "/Core/Cache/"); + $Smarty->setCompileDir("Core/Cache/Compile"); + $Smarty->setCacheDir("Core/Cache/"); $Smarty->assign('siteURL', $this->config->main->SITE_URL); $Smarty->assign('serverName', $this->config->main->SERVER_NAME); $Smarty->assign('siteDomain', $this->config->main->SITE_DOMAIN); @@ -72,11 +83,15 @@ class Layout extends Bus { return $this->title; } - public function view($view = "default", $dir = null) { + public function view($view = "default") { // Chech if Smarty is loaded if (!$this->loaded) $this->load(); + $event = $this->events->fireEvent('layoutLoadEvent', $view); + $directory = ($event->directory === null ? "Application/Views" : $event->directory); + $view = ($event->layout === null ? $view : $event->layout); + // Set the file name and location $vw = explode('/', $view); if (count($vw) == 1) { @@ -98,65 +113,54 @@ class Layout extends Bus { } // Set the directory - $dir = (!isset($dir) ? FUZEPATH . "/Application/" . '/Views' : $dir); - $this->Smarty['main']->setTemplateDir($dir); + $this->Smarty['main']->setTemplateDir($directory); // Set the title $this->Smarty['main']->assign('title', $this->title); // Get the viewdir - // @TODO: Fix this for custom directories - $one = FUZEPATH; - $two = $dir . "/"; - $count_one = strlen($one); - $count_two = strlen($two); - $length_three = $count_two - $count_one; - $three = $this->config->main->SITE_URL . "/" . substr($two, -$length_three); - $this->layout->assign('viewDir', $three); + $viewDir = $this->config->main->SITE_URL . "/" . substr($directory . "/", -strlen($directory . "/")); + $this->layout->assign('viewDir', $viewDir); try{ // Load the page $this->Smarty['main']->display($vw); - $this->logger->logInfo("VIEW LOAD: '".$vw."'", "FuzeWorks->Layout", __FILE__, __LINE__); + $this->logger->logInfo("VIEW LOAD: '".$vw."'", "Layout", __FILE__, __LINE__); }catch (\SmartyException $e){ // Throw error on failure - $this->logger->logError('Could not load view '.$dir.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); - throw new Exception\Layout('Could not load view '.$dir.'/'.$vw); + $this->logger->logError('Could not load view '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'Layout', __FILE__, __LINE__); + throw new Exception\Layout('Could not load view '.$directory.'/'.$vw); } } - public function get($view = "default", $dir = "") { + public function get($view = "default", $directory = "") { // Chech if Smarty is loaded if (!$this->loaded) $this->load(); // Set the directory - $dir = ($dir == "" ? FUZEPATH . "/Application/" . '/Views' : $dir); - $this->Smarty['main']->setTemplateDir($dir); + $directory = ($directory == "" ? "Application/" . '/Views' : $directory); + $this->Smarty['main']->setTemplateDir($directory); // Set the title $this->Smarty['main']->assign('title', $this->title); // Get the viewdir - $one = FUZEPATH; - $two = $dir . "/"; - $count_one = strlen($one); - $count_two = strlen($two); - $length_three = $count_two - $count_one; - $three = $this->config->main->SITE_URL . "/" . substr($two, -$length_three); - $this->layout->assign('viewdir', $three); + $viewDir = $this->config->main->SITE_URL . "/" . substr($directory . "/", -strlen($directory . "/")); + $this->layout->assign('viewDir', $viewDir); + try{ // Load the page return $this->Smarty['main']->fetch('view.'.$view.'.tpl'); - $this->logger->logInfo("VIEW LOAD: 'view.".$view.'.tpl'."'", "FuzeWorks->Layout", __FILE__, __LINE__); + $this->logger->logInfo("VIEW LOAD: 'view.".$view.'.tpl'."'", "Layout", __FILE__, __LINE__); }catch (\SmartyException $e){ // Throw error on failure - $this->logger->logError('Could not load view '.$dir.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); - throw new Exception\Layout('Could not load view '.$dir.'/view.'.$view.'.tpl'); + $this->logger->logError('Could not load view '.$directory.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'Layout', __FILE__, __LINE__); + throw new Exception\Layout('Could not load view '.$directory.'/view.'.$view.'.tpl'); } } } \ No newline at end of file diff --git a/Core/System/class.logger.php b/Core/System/class.logger.php index 4839074..7f5f126 100644 --- a/Core/System/class.logger.php +++ b/Core/System/class.logger.php @@ -1,5 +1,14 @@ errorHandler($errno, $errstr, $errfile, $errline); + $this->logInfo($this->backtrace()); } if ($this->mods->config->error->debug == true || $this->print_to_screen) { @@ -88,6 +98,13 @@ class Logger extends Bus{ } public function logToScreen() { + // Send a screenLogEvent, allows for new screen log designs + $event = $this->mods->events->fireEvent('screenLogEvent'); + if ($event->isCancelled()) { + return false; + } + + // Otherwise just load it echo '