From 9b3bf5fc209e041fee4411de469680d91fc3e402 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Fri, 20 Mar 2015 10:20:30 +0100 Subject: [PATCH 01/14] Moved Modules to a new directory, makes more sense. Also started adding events for the renewed sections, see #19 and #18 --- Core/Events/event.layoutLoadEvent.php | 13 ++++++++ Core/System/class.core.php | 9 ++++-- Core/System/class.events.php | 2 +- Core/System/class.layout.php | 27 +++++++++------- .../database/class.database.php | 0 .../databasemodel/class.model.php | 0 .../databasemodel/moduleInfo.php | 0 .../Mods => Modules}/router/class.router.php | 0 .../sections/class.sections.php | 32 +++++++++++++++++++ .../sections/config.sections.php | 0 10 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 Core/Events/event.layoutLoadEvent.php rename {Core/Mods => Modules}/database/class.database.php (100%) rename {Core/Mods => Modules}/databasemodel/class.model.php (100%) rename {Core/Mods => Modules}/databasemodel/moduleInfo.php (100%) rename {Core/Mods => Modules}/router/class.router.php (100%) rename {Core/Mods => Modules}/sections/class.sections.php (83%) rename {Core/Mods => Modules}/sections/config.sections.php (100%) diff --git a/Core/Events/event.layoutLoadEvent.php b/Core/Events/event.layoutLoadEvent.php new file mode 100644 index 0000000..60fc338 --- /dev/null +++ b/Core/Events/event.layoutLoadEvent.php @@ -0,0 +1,13 @@ +layout = $layout; + } +} + +?> \ No newline at end of file diff --git a/Core/System/class.core.php b/Core/System/class.core.php index b2c171d..b533b5a 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -92,6 +92,9 @@ class Core { $CLASS->onLoad(); return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS; + } else { + $c = &$this->mods->{strtolower($data['moduleLinkName'])}; + return $c; } } @@ -104,7 +107,7 @@ class Core { } // The basic module path - $path = FUZEPATH . "/Core/Mods/"; + $path = FUZEPATH . "Modules/"; // Chech if the requested module is set if (isset($this->register[$name])) { @@ -185,7 +188,7 @@ class Core { public function buildModRegister() { $this->mods->logger->newLevel("Building Mod Register", 'Core'); - $dir = FUZEPATH . "Core/Mods/"; + $dir = FUZEPATH . "Modules/"; $mods = array_values(array_diff(scandir($dir), array('..', '.'))); $register = array(); for ($i=0; $i < count($mods); $i++) { @@ -199,6 +202,7 @@ class Core { // Append directory $cfg->directory = $mod_dir; $register[$name] = (array) $cfg; + $this->mods->logger->log("Found module: '".$name."'"); } else { // Get the name $name = $mods[$i]; @@ -212,6 +216,7 @@ class Core { $cfg->versions = array(); $cfg->directory = $mod_dir; $register[$name] = (array)$cfg; + $this->mods->logger->log("Found module: '".$name."'"); } } diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 8551276..be8bb26 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -155,7 +155,7 @@ class Events extends Bus{ // Event Preparation: public function buildEventRegister() { $this->logger->newLevel("Building Event Register", 'Events'); - $dir = FUZEPATH . "/Core/Mods/"; + $dir = FUZEPATH . "/Modules/"; $mods = $this->config->modregister->register; foreach ($mods as $key => $value) { try { diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index d2dc8c3..f6aeb89 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -72,11 +72,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 ? FUZEPATH . "/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,8 +102,7 @@ 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); @@ -107,7 +110,7 @@ class Layout extends Bus { // Get the viewdir // @TODO: Fix this for custom directories $one = FUZEPATH; - $two = $dir . "/"; + $two = $directory . "/"; $count_one = strlen($one); $count_two = strlen($two); $length_three = $count_two - $count_one; @@ -122,26 +125,26 @@ class Layout extends Bus { }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(), 'FuzeWorks->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 == "" ? FUZEPATH . "/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 . "/"; + $two = $directory . "/"; $count_one = strlen($one); $count_two = strlen($two); $length_three = $count_two - $count_one; @@ -155,8 +158,8 @@ class Layout extends Bus { }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(), 'FuzeWorks->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/Mods/database/class.database.php b/Modules/database/class.database.php similarity index 100% rename from Core/Mods/database/class.database.php rename to Modules/database/class.database.php diff --git a/Core/Mods/databasemodel/class.model.php b/Modules/databasemodel/class.model.php similarity index 100% rename from Core/Mods/databasemodel/class.model.php rename to Modules/databasemodel/class.model.php diff --git a/Core/Mods/databasemodel/moduleInfo.php b/Modules/databasemodel/moduleInfo.php similarity index 100% rename from Core/Mods/databasemodel/moduleInfo.php rename to Modules/databasemodel/moduleInfo.php diff --git a/Core/Mods/router/class.router.php b/Modules/router/class.router.php similarity index 100% rename from Core/Mods/router/class.router.php rename to Modules/router/class.router.php diff --git a/Core/Mods/sections/class.sections.php b/Modules/sections/class.sections.php similarity index 83% rename from Core/Mods/sections/class.sections.php rename to Modules/sections/class.sections.php index 9ef404a..2409b41 100644 --- a/Core/Mods/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -30,6 +30,8 @@ class Sections extends Module { // 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, 'layoutLoadEvent'), 'layoutLoadEvent', EventPriority::NORMAL); + $this->events->addListener(array($this, 'modelLoadevent'), 'modelLoadEvent', EventPriority::NORMAL); } /** @@ -40,6 +42,36 @@ class Sections extends Module { */ 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 + * @param layoutLoadEvent Event + * @return layoutLoadEvent Event + */ + public function layoutLoadEvent($event) { + $layout_name = $event->layout; + if ($this->currentSection !== null) { + $event->directory = $this->view_path; + } + return $event; + } + + /** + * Redirects models to the new section + * @access public + * @param layoutLoadEvent Event + * @return layoutLoadEvent Event + */ + public function modelLoadEvent($event) { + $model_name = $event->model; + if ($this->currentSection !== null) { + $event->directory = $this->model_path; + } return $event; } diff --git a/Core/Mods/sections/config.sections.php b/Modules/sections/config.sections.php similarity index 100% rename from Core/Mods/sections/config.sections.php rename to Modules/sections/config.sections.php From 71547eec26e0274fe7f9876570e9b5a49e1f0cc6 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Fri, 20 Mar 2015 11:41:09 +0100 Subject: [PATCH 02/14] Bugfix where sections does not load correct viewdir and modeldir. --- Modules/sections/class.sections.php | 48 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index 2409b41..3224670 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -56,7 +56,8 @@ class Sections extends Module { public function layoutLoadEvent($event) { $layout_name = $event->layout; if ($this->currentSection !== null) { - $event->directory = $this->view_path; + $section = $this->getSection($this->currentSection); + $event->directory = $section['view_path']; } return $event; } @@ -70,7 +71,8 @@ class Sections extends Module { public function modelLoadEvent($event) { $model_name = $event->model; if ($this->currentSection !== null) { - $event->directory = $this->model_path; + $section = $this->getSection($this->currentSection); + $event->directory = $section['model_path']; } return $event; } @@ -86,14 +88,28 @@ class Sections extends Module { * @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, - ); + if ($module_section) { + $m = $this->core->loadMod($module_name); + $m_dir = $m->getModulePath(); + $data = array( + 'name' => $name, + 'module_section' => $module_section, + 'module_name' => $module_name, + 'controller_path' => $m_dir . '/Controller/', + 'model_path' => $m_dir . '/Models/', + 'view_path' => $m_dir . '/Views/', + ); + } else { + $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()); } @@ -154,6 +170,18 @@ class Sections extends Module { return $event; } + /** + * Load a section file + * @access public + * @param String section name + * @return Array Section + */ + public function getSection($name) { + if (isset($this->cfg->$name)) { + return $this->cfg->$name; + } + } + /** * Retrieves section information from the config file * @access public From 8c1a7afda544201128de13531edcc0b78fe46f26 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 22 Apr 2015 11:31:29 +0200 Subject: [PATCH 03/14] Fix for #28 and #23. This patch removes the mod and event registers so that modules can now be loaded dynamicly instead of using a global configuration file. --- Application/Config/config.eventregister.php | 5 -- Application/Config/config.main.php | 1 - Application/Config/config.modregister.php | 0 Core/Events/event.eventRegisterBuildEvent.php | 17 ------ Core/System/class.core.php | 59 +++++++++---------- Core/System/class.events.php | 26 ++++---- 6 files changed, 44 insertions(+), 64 deletions(-) delete mode 100644 Application/Config/config.eventregister.php delete mode 100644 Application/Config/config.modregister.php delete mode 100644 Core/Events/event.eventRegisterBuildEvent.php 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/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/System/class.core.php b/Core/System/class.core.php index b533b5a..7774cd4 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -11,7 +11,7 @@ class Core { public $mods; private $loaded = false; - private $register; + public $register; ## START/STOP public function init() { @@ -23,12 +23,12 @@ class Core { $this->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; } } @@ -99,13 +99,6 @@ class Core { } 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 . "Modules/"; @@ -186,14 +179,20 @@ class Core { 'moduleName' => $name); } - public function buildModRegister() { - $this->mods->logger->newLevel("Building Mod Register", 'Core'); - $dir = FUZEPATH . "Modules/"; - $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 = FUZEPATH . "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)."/" : ""); @@ -203,11 +202,11 @@ class Core { $cfg->directory = $mod_dir; $register[$name] = (array) $cfg; $this->mods->logger->log("Found module: '".$name."'"); - } else { + } 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"; @@ -217,12 +216,12 @@ class Core { $cfg->directory = $mod_dir; $register[$name] = (array)$cfg; $this->mods->logger->log("Found module: '".$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 be8bb26..e3a98be 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -112,7 +112,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,18 +154,22 @@ class Events extends Bus{ // Event Preparation: public function buildEventRegister() { - $this->logger->newLevel("Building Event Register", 'Events'); - $dir = FUZEPATH . "/Modules/"; - $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; } } From e877d103c854e6777891d64af8a485621f77b11b Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 22 Apr 2015 12:11:28 +0200 Subject: [PATCH 04/14] Implemented renewed modloading, so that modules do not get loaded multiple times --- Core/System/class.core.php | 164 ++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 95 deletions(-) diff --git a/Core/System/class.core.php b/Core/System/class.core.php index 7774cd4..db165c5 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -9,9 +9,16 @@ if (!defined('FUZESYSPATH')) { // Framework class Core { - public $mods; - private $loaded = false; + public $mods; public $register; + + /** + * An array which modules are loaded, and should not be loaded again + * @access private + * @var Array of module names + */ + private $loaded_modules = array(); + private $loaded = false; ## START/STOP public function init() { @@ -64,119 +71,86 @@ class Core { $this->mods->events->fireEvent('coreShutdownEvent'); } - ## MODLOADING - public function loadMod($name, $version = null) { - // Get class information - $data = $this->loadModule($name, $version); - - // 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; - } else { - $c = &$this->mods->{strtolower($data['moduleLinkName'])}; - return $c; - } - } - - private function loadModule($name, $version = null) { - // The basic module path + public function loadMod($name) { + // Where the modules are $path = FUZEPATH . "Modules/"; - // 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 + // Check if the module is enabled if (isset($cfg->enabled)) { if (!$cfg->enabled) { - // Module is disabled - throw new Exception("Module '".$name."' is not enabled!", 1); + // DO SOMETHING 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; - } + // 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 + $c = &$this->mods->{strtolower($cfg->name)}; + 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()); + 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($cfg->name); + } + if (method_exists($CLASS, 'setModuleName')) { + $CLASS->setModuleName($name); + } + $CLASS->onLoad(); + + // 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 buildRegister() { From ba84fa5cef73c7b9ff75031eb89484d982111ba1 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 22 Apr 2015 12:16:14 +0200 Subject: [PATCH 05/14] Messages when a module is already loaded, and loaded modules get correctly registered --- Core/System/class.core.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Core/System/class.core.php b/Core/System/class.core.php index db165c5..2f51540 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -92,7 +92,9 @@ class Core { // 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 - $c = &$this->mods->{strtolower($cfg->name)}; + $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 @@ -144,11 +146,12 @@ class Core { } $CLASS->onLoad(); + // Add to the loaded modules + $this->loaded_modules[] = $name; + // Return a reference return $this->mods->{strtolower($cfg->module_name)} = &$CLASS; } - - } } } From 54c81f769a87634dcde019cb5b331e5c768e43db Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 12:20:39 +0200 Subject: [PATCH 06/14] Fixed #24. Sections are now dynamic and modules can now be disabled --- Core/System/class.core.php | 31 ++++++------ Modules/sections/class.sections.php | 74 ++++++++++++++++++++-------- Modules/sections/config.sections.php | 2 +- Modules/sections/moduleInfo.php | 20 ++++++++ 4 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 Modules/sections/moduleInfo.php diff --git a/Core/System/class.core.php b/Core/System/class.core.php index 2f51540..8a59b87 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -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."'"); } } diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index 3224670..41cca0b 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -1,9 +1,14 @@ 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; diff --git a/Modules/sections/config.sections.php b/Modules/sections/config.sections.php index c3388f9..9dd0e94 100644 --- a/Modules/sections/config.sections.php +++ b/Modules/sections/config.sections.php @@ -1 +1 @@ - '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', +); From 156f4a3460a57a8f5c50dc7bbc0423508a5132e5 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 13:46:33 +0200 Subject: [PATCH 07/14] Did the MVC Rewrite. Each component now has events. Fixes #9 , #10 , #20 --- Core/Events/event.controllerLoadEvent.php | 20 ++++++++++++++++++ Core/Events/event.modelLoadEvent.php | 13 ++++++++++++ Core/System/class.models.php | 7 ++++--- Modules/router/class.router.php | 25 +++++++++++++++++------ index.php | 1 + 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 Core/Events/event.controllerLoadEvent.php create mode 100644 Core/Events/event.modelLoadEvent.php diff --git a/Core/Events/event.controllerLoadEvent.php b/Core/Events/event.controllerLoadEvent.php new file mode 100644 index 0000000..63d3553 --- /dev/null +++ b/Core/Events/event.controllerLoadEvent.php @@ -0,0 +1,20 @@ +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.modelLoadEvent.php b/Core/Events/event.modelLoadEvent.php new file mode 100644 index 0000000..0c8f0ce --- /dev/null +++ b/Core/Events/event.modelLoadEvent.php @@ -0,0 +1,13 @@ +model = $model; + } +} + +?> \ No newline at end of file diff --git a/Core/System/class.models.php b/Core/System/class.models.php index 0abf1e0..1e4b574 100644 --- a/Core/System/class.models.php +++ b/Core/System/class.models.php @@ -14,9 +14,10 @@ class Models extends Bus{ } public function loadModel($name, $directory = null){ - if($directory === null){ - $directory = FUZEPATH . "/Application/Models"; - } + // Model load event + $event = $this->events->fireEvent('modelLoadEvent', $name); + $directory = ($event->directory === null ? FUZEPATH . "/Application/Models" : $event->directory); + $name = ($event->model === null ? $name : $event->model); $file = $directory.'/model.'.$name.'.php'; if (isset($this->model_types[$name])) { diff --git a/Modules/router/class.router.php b/Modules/router/class.router.php index 1b1c7a4..e7208d5 100644 --- a/Modules/router/class.router.php +++ b/Modules/router/class.router.php @@ -5,9 +5,10 @@ class Router extends Bus { public $controller = null; public $controllerName = null; public $function = null; - private $route = array(); - private $parameters = array(); - private $path; + public $route = array(); + public $parameters = array(); + public $directory; + public $path; public function __construct(&$core) { parent::__construct($core); @@ -90,9 +91,6 @@ class Router extends Bus { $this->function = ($event->function === null || empty($event->function) ? $this->config->main->default_function : $event->function); $this->parameters = $event->parameters; $this->directory = ($event->directory === null || empty($event->directory) ? FUZEPATH . "/Application/Controller/" : $event->directory); - - // Load the controller - $this->loadController(); } /** @@ -100,6 +98,21 @@ class Router extends Bus { * @access public */ public function loadController() { + // Initate the controllerLoadEvent + $event = $this->events->fireEvent('controllerLoadEvent', + $this->route, + $this->controllerName, + $this->function, + $this->parameters, + $this->directory + ); + + $this->route = ($event->route === null ? $this->route : $event->route); + $this->controllerName = ($event->controllerName === null ? $this->controllerName : $event->controllerName); + $this->function = ($event->function === null ? $this->function : $event->function); + $this->parameters = ($event->parameters === null ? $this->parameters : $event->parameters); + $this->directory = ($event->directory === null ? $this->directory : $event->directory); + $file = $this->directory . "controller.".strtolower($this->controllerName).".php"; $this->logger->log("Loading controller from file: '".$file."'"); diff --git a/index.php b/index.php index 4053923..5d28680 100644 --- a/index.php +++ b/index.php @@ -12,5 +12,6 @@ $core->init(); $core->loadMod('router'); $core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) ); $core->mods->router->route(); +$core->mods->router->loadController(); ?> \ No newline at end of file From 7a5ac7cfad5cefe37c3c5a267889dc21c6806ecf Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 16:15:50 +0200 Subject: [PATCH 08/14] Fix for #31. Low priority for Sections. --- Modules/sections/class.sections.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index 41cca0b..9be87b5 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -64,9 +64,9 @@ class Main extends Module { $this->logger->stopLevel(); // Register Events - $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); + $this->events->addListener(array($this, 'routerRouteEvent'), 'routerRouteEvent', EventPriority::LOWEST); + $this->events->addListener(array($this, 'layoutLoadEvent'), 'layoutLoadEvent', EventPriority::LOWEST); + $this->events->addListener(array($this, 'modelLoadevent'), 'modelLoadEvent', EventPriority::LOWEST); } /** From c5318a2e99ece72483ed17f5bfb686b9cfbad187 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 17:18:33 +0200 Subject: [PATCH 09/14] Added new namespaces as described in Issue #37. The following namespaces are used: \FuzeWorks for Core classes \Controller for controller classes \Model for model classes \Module for modules Also did the following changes: - DatabaseModel now loads the database module as a dependency - DatabaseModel is no longer abstract because of ModelServer - Implemented a new mechanism for model types in the name of a ModelServer. This interface requires a Model Type Server to return a Model parent class based on a given type - Added a backtrace to the logger class for easy and fast debugging And that was it for this commit --- .../Controller/controller.standard.php | 3 +++ Application/Models/model.example.php | 3 +++ Core/Events/event.controllerLoadEvent.php | 2 ++ Core/Events/event.layoutLoadEvent.php | 2 ++ Core/Events/event.modelLoadEvent.php | 2 ++ Core/Events/event.routerRouteEvent.php | 2 ++ Core/System/class.abstract.bus.php | 2 ++ Core/System/class.abstract.event.php | 2 ++ Core/System/class.abstract.eventPriority.php | 2 ++ Core/System/class.abstract.model.php | 18 ++++++++++++---- Core/System/class.abstract.module.php | 2 ++ Core/System/class.config.php | 3 +++ Core/System/class.core.php | 10 ++++++++- Core/System/class.events.php | 9 +++++--- Core/System/class.layout.php | 3 +++ Core/System/class.logger.php | 21 +++++++++++++++++++ Core/System/class.models.php | 4 +++- Modules/database/class.database.php | 6 +++++- Modules/databasemodel/class.model.php | 14 +++++++++++-- Modules/databasemodel/moduleInfo.php | 7 +++++-- Modules/router/class.router.php | 6 ++++-- Modules/sections/class.sections.php | 4 ++-- Modules/sections/moduleInfo.php | 2 ++ index.php | 2 +- 24 files changed, 112 insertions(+), 19 deletions(-) diff --git a/Application/Controller/controller.standard.php b/Application/Controller/controller.standard.php index 644309c..a17d212 100644 --- a/Application/Controller/controller.standard.php +++ b/Application/Controller/controller.standard.php @@ -1,5 +1,8 @@ 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 @@ setModulePath($cfg->directory); } if (method_exists($CLASS, 'setModuleLinkName')) { - $CLASS->setModuleLinkName($cfg->name); + $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 diff --git a/Core/System/class.events.php b/Core/System/class.events.php index e3a98be..53bd4ba 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -3,7 +3,10 @@ * @author FuzeNetwork * @package files */ - + +namespace FuzeWorks; +use \Exception; + /** * @name Events */ @@ -84,10 +87,10 @@ class Events extends Bus{ // No event arguments? Looks like an 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!"); } } } diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index f6aeb89..0539d6e 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -1,5 +1,8 @@ getTraceAsString()); + // reverse array to make steps line up chronologically + $trace = array_reverse($trace); + array_shift($trace); // remove {main} + array_pop($trace); // remove call to this method + $length = count($trace); + $result = array(); + + for ($i = 0; $i < $length; $i++) + { + $result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering + } + + return "\t" . implode("
", $result); + } + /* =========================================LOGGING METHODS==============================================================*/ diff --git a/Core/System/class.models.php b/Core/System/class.models.php index 1e4b574..0386e00 100644 --- a/Core/System/class.models.php +++ b/Core/System/class.models.php @@ -3,6 +3,8 @@ * @author FuzeNetwork */ +namespace FuzeWorks; + class Models extends Bus{ private $models_array = array(); @@ -25,7 +27,7 @@ class Models extends Bus{ $this->models_array[$name] = $this->model_types[$name]; } elseif (file_exists($file)){ require_once($file); - $model = ucfirst($name); + $model = "\Model\\" . ucfirst($name); $this->logger->logInfo('Loading Model: '.$model, $model); $this->models_array[$name] = new $model($this->core); } else{ diff --git a/Modules/database/class.database.php b/Modules/database/class.database.php index c7cacd3..5e077a3 100644 --- a/Modules/database/class.database.php +++ b/Modules/database/class.database.php @@ -1,6 +1,10 @@ core->loadMod('database'); + } + + public function onLoad() {} + + public function giveModel($type) { + return new DatabaseModel($this->core); } public function select(){ diff --git a/Modules/databasemodel/moduleInfo.php b/Modules/databasemodel/moduleInfo.php index aafc5dc..f4c85d6 100644 --- a/Modules/databasemodel/moduleInfo.php +++ b/Modules/databasemodel/moduleInfo.php @@ -1,11 +1,12 @@ 'DatabaseModel', + 'module_class' => 'Module\DatabaseModel', 'module_file' => 'class.model.php', 'module_name' => 'databasemodel', - 'abstract' => true, + 'abstract' => false, + 'dependencies' => array('database'), 'name' => 'DatabaseModel', 'description' => 'Abstract type for easy database queries', @@ -15,4 +16,6 @@ return array( 'date_created' => '26-02-2015', 'date_updated' => '26-02-2015', + + 'enabled' => true, ); diff --git a/Modules/router/class.router.php b/Modules/router/class.router.php index e7208d5..bf5e37d 100644 --- a/Modules/router/class.router.php +++ b/Modules/router/class.router.php @@ -1,6 +1,8 @@ controllerName))) require_once($file); - $this->controllerClass = ucfirst($this->controllerName); + $this->controllerClass = "\Controller\\" . ucfirst($this->controllerName); $this->controller = new $this->controllerClass($this->core); if (method_exists($this->controller, $this->function) || method_exists($this->controller, '__call')) { diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index 9be87b5..d5f99a1 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -1,8 +1,8 @@ '29-04-2015', 'date_updated' => '29-04-2015', + + 'enabled' => true, ); diff --git a/index.php b/index.php index 5d28680..a6c445f 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ if (!defined('FUZEPATH')) { require_once( dirname(__FILE__) . "/Core/System/class.core.php"); // Load it -$core = new Core(); +$core = new \FuzeWorks\Core(); $core->init(); $core->loadMod('router'); $core->mods->router->setPath( (isset($_GET['path']) ? $_GET['path'] : null) ); From 39d2982cf16a94dae0c61b5d2c1c0b5488816924 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 17:49:33 +0200 Subject: [PATCH 10/14] Added more documentation and implemented the Logger::backtrace into fatal errors --- Core/System/class.config.php | 4 ++-- Core/System/class.core.php | 7 +++++-- Core/System/class.events.php | 12 ++++++++++-- Core/System/class.layout.php | 8 ++++++++ Core/System/class.logger.php | 16 +++++++++++++++- Core/System/class.models.php | 6 ++++++ 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Core/System/class.config.php b/Core/System/class.config.php index 540285b..f16d69b 100644 --- a/Core/System/class.config.php +++ b/Core/System/class.config.php @@ -4,9 +4,9 @@ namespace FuzeWorks; use \Exception; /** - * Config Module + * Config Class * - * This class gives access to the config files. Allows for reading and editting + * This class gives access to the config files. Can read and write .php files with an array in a file */ class Config extends Bus{ diff --git a/Core/System/class.core.php b/Core/System/class.core.php index be4bff2..5d40ed3 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -9,8 +9,11 @@ if (!defined('FUZESYSPATH')) { define( 'FUZESYSPATH', dirname(__FILE__) . '/' ); } -// NotifierEvent, base event -// Framework +/** + * FuzeWorks Core + * + * Holds all the modules and starts the framework. Allows for starting and managing modules + */ class Core { public $mods; diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 53bd4ba..18e3212 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -8,8 +8,16 @@ 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; diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index 0539d6e..3f942a3 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -3,6 +3,14 @@ namespace FuzeWorks; use \Exception; +/** + * Layout Class + * + * The Layout class is a wrapper for the Smarty Template engine. Smarty loads .tpl files and variables, and converts them to HTML. + * See the Smarty documentation for more information + * This class typically loads files from Application/Views unless specified otherwise. + * + */ class Layout extends Bus { private $Smarty = array(); diff --git a/Core/System/class.logger.php b/Core/System/class.logger.php index 0feb59f..479b1f2 100644 --- a/Core/System/class.logger.php +++ b/Core/System/class.logger.php @@ -3,6 +3,12 @@ namespace FuzeWorks; use \Exception; +/** + * Logger Class + * + * The main tool to handle errors and exceptions. Provides some tools for debugging and tracking where errors take place + * All fatal errors get catched by this class and get displayed if configured to do so. + */ class Logger extends Bus{ public $infoErrors = array(); @@ -40,6 +46,7 @@ class Logger extends Bus{ // Log it! $this->errorHandler($errno, $errstr, $errfile, $errline); + $this->logInfo($this->backtrace()); } if ($this->mods->config->error->debug == true || $this->print_to_screen) { @@ -91,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 '

FuzeWorks debug log

'; $layer = 0; for($i = 0; $i < count($this->Logs); $i++){ @@ -131,7 +145,7 @@ class Logger extends Bus{ $result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering } - return "\t" . implode("
", $result); + return "BACKTRACE:
\t" . implode("
", $result)."
"; } /* =========================================LOGGING METHODS==============================================================*/ diff --git a/Core/System/class.models.php b/Core/System/class.models.php index 0386e00..2e093e8 100644 --- a/Core/System/class.models.php +++ b/Core/System/class.models.php @@ -5,6 +5,12 @@ namespace FuzeWorks; +/** + * Models Class + * + * Simple loader class for MVC Models. Typically loads models from Application/Models unless otherwise specified. + * If a model is not found, it will load a DatabaseModel type which will analyze the database and can directly be used. + */ class Models extends Bus{ private $models_array = array(); From f074bce5455ba386adc9689d4bc9e8c8287cd61a Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 29 Apr 2015 19:36:38 +0200 Subject: [PATCH 11/14] Added Controller Abstract for multiple parent classes of controller --- .../Controller/controller.standard.php | 4 +- Core/System/class.abstract.controller.php | 78 +++++++++++++++++++ Core/System/class.core.php | 1 + 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 Core/System/class.abstract.controller.php diff --git a/Application/Controller/controller.standard.php b/Application/Controller/controller.standard.php index a17d212..90ebfc5 100644 --- a/Application/Controller/controller.standard.php +++ b/Application/Controller/controller.standard.php @@ -1,9 +1,9 @@ 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.core.php b/Core/System/class.core.php index 5d40ed3..7aae968 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -55,6 +55,7 @@ class Core { 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.controller.php"); require_once(FUZESYSPATH . "/class.abstract.eventPriority.php"); // Load the core classes From b10561df6d1a0d218a8661f0f932e0fac62d5f67 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Thu, 30 Apr 2015 21:19:07 +0200 Subject: [PATCH 12/14] Updated the database to a higher standard according to issue #33 and #32 Also moved the NotifierEvent into another file, the event abstract and gave the interpret model a namespace. --- Core/System/Models/model.interpret.php | 13 +- Core/System/class.abstract.event.php | 2 + Core/System/class.config.php | 2 +- Core/System/class.events.php | 6 +- Modules/database/class.database.php | 160 +++++++++---------------- Modules/database/moduleInfo.php | 23 ++++ Modules/databasemodel/moduleInfo.php | 2 +- 7 files changed, 86 insertions(+), 122 deletions(-) create mode 100644 Modules/database/moduleInfo.php diff --git a/Core/System/Models/model.interpret.php b/Core/System/Models/model.interpret.php index 3dc6cbc..dfa41da 100644 --- a/Core/System/Models/model.interpret.php +++ b/Core/System/Models/model.interpret.php @@ -1,5 +1,7 @@ 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.event.php b/Core/System/class.abstract.event.php index e119043..1cd8210 100644 --- a/Core/System/class.abstract.event.php +++ b/Core/System/class.abstract.event.php @@ -19,4 +19,6 @@ class Event { } } +class NotifierEvent extends Event {} + ?> \ No newline at end of file diff --git a/Core/System/class.config.php b/Core/System/class.config.php index f16d69b..7e35fcf 100644 --- a/Core/System/class.config.php +++ b/Core/System/class.config.php @@ -48,7 +48,7 @@ class Config extends Bus{ $DECODED = (object) require($file); return $DECODED; } else { - $this->core->loadMod('database'); + $this->core->loadMod('techfuze/database'); if ($this->dbActive) { // Fetch me a query of 5 $prefix = $this->mods->database->getPrefix(); diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 18e3212..12c5226 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -82,7 +82,7 @@ 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)){ @@ -92,7 +92,7 @@ class Events extends Bus{ // 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 = '\FuzeWorks\NotifierEvent'; @@ -184,7 +184,5 @@ class Events extends Bus{ } } -class NotifierEvent extends Event {} - ?> \ No newline at end of file diff --git a/Modules/database/class.database.php b/Modules/database/class.database.php index 5e077a3..bdc5c9a 100644 --- a/Modules/database/class.database.php +++ b/Modules/database/class.database.php @@ -1,11 +1,16 @@ connect($this->getSystemDbSettings()); $this->config->dbActive = true; } - public function connect($params = array()) { - if (isset($params['type'])) { - $type = $params['type']; + public function connect($config = null) { + // If nothing is given, connect to database from the main config, otherwise use the served configuration + if (is_null($config)) { + $db = $this->mods->config->database; } else { - throw (new Exception("No database type given")); + $db = $config; } - - 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; + + // Get the DSN for popular types of databases or a custom DSN + switch (strtolower($db->type)) { + case 'mysql': + $dsn = "mysql:host=".$db->host.";"; + $dsn .= (!empty($db->database) ? "dbname=".$db->database.";" : ""); break; - case 'sqlite': - $DSN = 'sqlite:' . $host . ($database != '' ? ";dbname=" .$database : ""); - $DSN_FINAL = $DSN; - break; - default: - throw (new Exception("Unknown database type given: '" . $type . "'")); + case 'custom': + $dsn = $db->dsn; 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); + try { + $this->mods->logger->logInfo("Connecting to '".$dsn."'", "Database"); + // And create the connection + $this->DBH = new PDO($dsn, $db->username, $db->password, (isset($db->options) ? $db->options : null)); + $this->DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->mods->logger->logInfo("Connected to database", "Database"); - $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); + // And set the prefix + $this->prefix = $db->prefix; + } catch (Exception $e) { + throw (new Exception('Could not connect to the database: "'. $e->getMessage() . '"')); } } - 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 getPrefix() { + return $this->prefix; } public function is_active() { @@ -123,25 +67,31 @@ class Database extends Module { } } - public function getPrefix() { - return $this->prefix; + public function __call($name, $params) { + if ($this->is_active()) { + return call_user_func_array(array($this->DBH, $name), $params); + } else { + $this->connect(); + return call_user_func_array(array($this->DBH, $name), $params); + } } - /** - * 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; + public function __get($name) { + if ($this->is_active()) { + return $this->DBH->$name; + } else { + $this->connect(); + return $this->DBH->$name; + } + } + + public function __set($name, $value) { + if ($this->is_active()) { + $this->DBH->$name = $value; + } else { + $this->connect(); + $this->DBH->$name = $value; + } } } diff --git a/Modules/database/moduleInfo.php b/Modules/database/moduleInfo.php new file mode 100644 index 0000000..705ba7c --- /dev/null +++ b/Modules/database/moduleInfo.php @@ -0,0 +1,23 @@ + 'Module\Database\Main', + 'module_file' => 'class.database.php', + 'module_name' => 'Database', + + 'abstract' => false, + 'dependencies' => array(), + 'events' => array(), + 'sections' => array(), + + 'name' => 'FuzeWorks Database Module', + 'description' => 'PDO Wrapper class for FuzeWorks', + 'author' => 'TechFuze', + 'version' => '1.0.0', + 'website' => 'http://fuzeworks.techfuze.net/', + + 'date_created' => '30-04-2015', + 'date_updated' => '30-04-2015', + + 'enabled' => true, +); diff --git a/Modules/databasemodel/moduleInfo.php b/Modules/databasemodel/moduleInfo.php index f4c85d6..81b6c58 100644 --- a/Modules/databasemodel/moduleInfo.php +++ b/Modules/databasemodel/moduleInfo.php @@ -6,7 +6,7 @@ return array( 'module_name' => 'databasemodel', 'abstract' => false, - 'dependencies' => array('database'), + 'dependencies' => array('techfuze/database'), 'name' => 'DatabaseModel', 'description' => 'Abstract type for easy database queries', From 881dcb0ae56e4bce91a7c1b0caffe15797dbc259 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Fri, 1 May 2015 17:59:40 +0200 Subject: [PATCH 13/14] Fixed a few logging errors --- Core/System/class.layout.php | 8 ++++---- Core/System/class.logger.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index 3f942a3..229dfae 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -132,11 +132,11 @@ class Layout extends Bus { // 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 '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); + $this->logger->logError('Could not load view '.$directory.'/'.$vw.' :: ' . $e->getMessage(), 'Layout', __FILE__, __LINE__); throw new Exception\Layout('Could not load view '.$directory.'/'.$vw); } } @@ -165,11 +165,11 @@ class Layout extends Bus { // 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 '.$directory.'/view.'.$view.'.tpl :: ' . $e->getMessage(), 'FuzeWorks->Layout', __FILE__, __LINE__); + $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'); } } diff --git a/Core/System/class.logger.php b/Core/System/class.logger.php index 479b1f2..7f5f126 100644 --- a/Core/System/class.logger.php +++ b/Core/System/class.logger.php @@ -302,8 +302,8 @@ class Logger extends Bus{ 511 => 'Network Authentication Required' ); - $this->logError('HTTP-error '.$errno.' called', 'FuzeWorks->Logger'); - $this->logInfo('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'FuzeWorks->Logger', __FILE__, __LINE__); + $this->logError('HTTP-error '.$errno.' called', 'Logger'); + $this->logInfo('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'Logger', __FILE__, __LINE__); header('HTTP/1.1 '.$errno.' '.$http_codes[$errno]); } From 630e207efceae6d5facdfcfb6c5bf8d97ef1d72d Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Fri, 1 May 2015 20:53:23 +0200 Subject: [PATCH 14/14] Removed FUZEPATH and FUZESYSPATH since it actually is pretty stupid --- Core/System/class.config.php | 4 ++-- Core/System/class.core.php | 34 ++++++++++++++--------------- Core/System/class.events.php | 2 +- Core/System/class.layout.php | 30 +++++++++---------------- Core/System/class.models.php | 4 ++-- Modules/router/class.router.php | 2 +- Modules/sections/class.sections.php | 6 ++--- index.php | 4 ---- 8 files changed, 35 insertions(+), 51 deletions(-) diff --git a/Core/System/class.config.php b/Core/System/class.config.php index 7e35fcf..4b810be 100644 --- a/Core/System/class.config.php +++ b/Core/System/class.config.php @@ -41,7 +41,7 @@ class Config extends Bus{ * @return StdObject of config */ public function loadConfigFile($name, $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)) { @@ -88,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 7aae968..4aaa1f4 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -4,11 +4,6 @@ namespace FuzeWorks; use \stdClass; use \Exception; -if (!defined('FUZESYSPATH')) { - define('STARTTIME', microtime(true)); - define( 'FUZESYSPATH', dirname(__FILE__) . '/' ); -} - /** * FuzeWorks Core * @@ -29,6 +24,9 @@ class Core { ## START/STOP public function init() { + if (!defined('STARTTIME')) { + define('STARTTIME', microtime(true)); + } // Load basics ignore_user_abort(true); register_shutdown_function(array($this, "shutdown")); @@ -51,19 +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.controller.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); @@ -81,7 +79,7 @@ class Core { public function loadMod($name) { // Where the modules are - $path = FUZEPATH . "Modules/"; + $path = "Modules/"; // Check if the requested module is registered if (isset($this->register[$name])) { @@ -164,7 +162,7 @@ class Core { $this->mods->logger->newLevel("Loading Module Headers", 'Core'); // Get all the module directories - $dir = FUZEPATH . "Modules/"; + $dir = "Modules/"; $mod_dirs = array(); $mod_dirs = array_values(array_diff(scandir($dir), array('..', '.'))); diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 12c5226..b12d8ec 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -87,7 +87,7 @@ class Events extends Bus{ $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); diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index 229dfae..94f28e0 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -23,7 +23,7 @@ class Layout extends Bus { private function load() { // Load Smarty - $smartyDir = FUZEPATH . "/Core/System/Smarty"; + $smartyDir = "Core/System/Smarty"; if (!defined('SMARTY_DIR')) { define('SMARTY_DIR', $smartyDir . DIRECTORY_SEPARATOR . "libs" . DIRECTORY_SEPARATOR); @@ -40,8 +40,8 @@ class Layout extends Bus { } public function getSmartyBasicVars($Smarty) { - $Smarty->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); @@ -89,7 +89,7 @@ class Layout extends Bus { $this->load(); $event = $this->events->fireEvent('layoutLoadEvent', $view); - $directory = ($event->directory === null ? FUZEPATH . "/Application/Views" : $event->directory); + $directory = ($event->directory === null ? "Application/Views" : $event->directory); $view = ($event->layout === null ? $view : $event->layout); // Set the file name and location @@ -119,14 +119,8 @@ class Layout extends Bus { $this->Smarty['main']->assign('title', $this->title); // Get the viewdir - // @TODO: Fix this for custom directories - $one = FUZEPATH; - $two = $directory . "/"; - $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{ @@ -147,20 +141,16 @@ class Layout extends Bus { $this->load(); // Set the directory - $directory = ($directory == "" ? FUZEPATH . "/Application/" . '/Views' : $directory); + $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 = $directory . "/"; - $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 diff --git a/Core/System/class.models.php b/Core/System/class.models.php index 2e093e8..b414037 100644 --- a/Core/System/class.models.php +++ b/Core/System/class.models.php @@ -24,7 +24,7 @@ class Models extends Bus{ public function loadModel($name, $directory = null){ // Model load event $event = $this->events->fireEvent('modelLoadEvent', $name); - $directory = ($event->directory === null ? FUZEPATH . "/Application/Models" : $event->directory); + $directory = ($event->directory === null ? "Application/Models" : $event->directory); $name = ($event->model === null ? $name : $event->model); $file = $directory.'/model.'.$name.'.php'; @@ -38,7 +38,7 @@ class Models extends Bus{ $this->models_array[$name] = new $model($this->core); } else{ $this->logger->logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'Models'); - require_once(FUZEPATH . "/Core/System/Models/model.interpret.php"); + require_once("Core/System/Models/model.interpret.php"); $this->logger->logInfo('Loading Model: interprated databasemodel', 'Models'); $model = new Interpret($this->core); $model->table($name); diff --git a/Modules/router/class.router.php b/Modules/router/class.router.php index bf5e37d..cf30d71 100644 --- a/Modules/router/class.router.php +++ b/Modules/router/class.router.php @@ -92,7 +92,7 @@ class Router extends Module { $this->controllerName = ($event->controller === null || empty($event->controller) ? $this->config->main->default_controller : $event->controller); $this->function = ($event->function === null || empty($event->function) ? $this->config->main->default_function : $event->function); $this->parameters = $event->parameters; - $this->directory = ($event->directory === null || empty($event->directory) ? FUZEPATH . "/Application/Controller/" : $event->directory); + $this->directory = ($event->directory === null || empty($event->directory) ? "Application/Controller/" : $event->directory); } /** diff --git a/Modules/sections/class.sections.php b/Modules/sections/class.sections.php index d5f99a1..7c8222d 100644 --- a/Modules/sections/class.sections.php +++ b/Modules/sections/class.sections.php @@ -136,9 +136,9 @@ class Main extends Module { '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, + 'controller_path' => $controller_path, + 'model_path' => $model_path, + 'view_path' => $view_path, ); } diff --git a/index.php b/index.php index a6c445f..89e32ed 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,5 @@