Moved Modules to a new directory, makes more sense. Also started adding events for the renewed sections, see #19 and #18

This commit is contained in:
Abel Hoogeveen 2015-03-20 10:20:30 +01:00
parent 91740236e7
commit 9b3bf5fc20
10 changed files with 68 additions and 15 deletions

View File

@ -0,0 +1,13 @@
<?php
class LayoutLoadEvent extends Event {
public $directory;
public $layout;
public function init($layout){
$this->layout = $layout;
}
}
?>

View File

@ -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."'");
}
}

View File

@ -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 {

View File

@ -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');
}
}
}

View File

@ -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;
}