diff --git a/.gitignore b/.gitignore index 3ee2e9c..2ea46dc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ build/ Modules/admin/themes/adminlte2.1/plugins/ Modules/admin/themes/adminlte2.1/dist/ Modules/admin/themes/adminlte2.1/bootstrap/ +doc +nbproject diff --git a/Application/Config/config.contact.php b/Application/Config/config.contact.php index c0c1cf2..d8d8382 100644 --- a/Application/Config/config.contact.php +++ b/Application/Config/config.contact.php @@ -1,4 +1,6 @@ - '', 'contact_name' => '', 'contact_adress' => '', @@ -6,5 +8,5 @@ 'contact_postal_code' => '', 'contact_region' => '', 'contact_country' => '', - 'contact_city' => '' -) ; \ No newline at end of file + 'contact_city' => '', +); diff --git a/Application/Config/config.core.php b/Application/Config/config.core.php index dc9bc1d..7bb47f9 100644 --- a/Application/Config/config.core.php +++ b/Application/Config/config.core.php @@ -1,4 +1,6 @@ - true, - 'composer_autoloader' => '' -) ; \ No newline at end of file + 'composer_autoloader' => '', +); diff --git a/Application/Config/config.database.php b/Application/Config/config.database.php index 8cf8c3c..47478cf 100644 --- a/Application/Config/config.database.php +++ b/Application/Config/config.database.php @@ -1,4 +1,6 @@ - '', 'host' => '', 'database' => '', @@ -6,4 +8,4 @@ 'password' => '', 'prefix' => '', 'debug' => false, -) ; \ No newline at end of file +); diff --git a/Application/Config/config.error.php b/Application/Config/config.error.php index 6611cc0..251acec 100644 --- a/Application/Config/config.error.php +++ b/Application/Config/config.error.php @@ -1,4 +1,6 @@ - false, 'error_reporting' => true, -) ; \ No newline at end of file +); diff --git a/Application/Config/config.main.php b/Application/Config/config.main.php index bca8227..13b044a 100644 --- a/Application/Config/config.main.php +++ b/Application/Config/config.main.php @@ -1,4 +1,6 @@ - '', 'SITE_DOMAIN' => '', 'SERVER_NAME' => '', @@ -6,4 +8,4 @@ 'administrator_mail' => '', 'default_controller' => 'standard', 'default_function' => 'index', -) ; \ No newline at end of file +); diff --git a/Application/Config/config.routes.php b/Application/Config/config.routes.php index dd2353a..87c3540 100644 --- a/Application/Config/config.routes.php +++ b/Application/Config/config.routes.php @@ -1,8 +1,9 @@ .*?))$/' => array( // 'controller' => 'home' // ), '/^(?P.*?)(|\/(?P.*?)(|\/(?P.*?)))$/', -); \ No newline at end of file +); diff --git a/Application/Controller/controller.standard.php b/Application/Controller/controller.standard.php index 354c4eb..f177be3 100644 --- a/Application/Controller/controller.standard.php +++ b/Application/Controller/controller.standard.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Application\Controller; -use \FuzeWorks\ControllerAbstract; -use \FuzeWorks\Layout; + +use FuzeWorks\ControllerAbstract; +use FuzeWorks\Layout; /** * The default controller of FuzeWorks. @@ -38,23 +41,20 @@ use \FuzeWorks\Layout; * This controller gets loaded when the '/' path is provided, eg. the home page. * By default, the index function gets loaded. * - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Standard extends ControllerAbstract { - - /** - * The default function of FuzeWorks. - * - * This code gets loaded for the Home page - * @param array $path The path provided by the HTTP Server - * @return void - */ - public function index($path = null) { - Layout::view('home'); - } +class Standard extends ControllerAbstract +{ + /** + * The default function of FuzeWorks. + * + * This code gets loaded for the Home page + * + * @param array $path The path provided by the HTTP Server + */ + public function index($path = null) + { + Layout::view('home'); + } } - - -?> \ No newline at end of file diff --git a/Application/Models/model.example.php b/Application/Models/model.example.php index eaea6a8..4519098 100644 --- a/Application/Models/model.example.php +++ b/Application/Models/model.example.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Application\Model; -use \FuzeWorks\Model; + +use FuzeWorks\Model; /** - * Example model to show how to use models + * Example model to show how to use models. * * This model connects to an example table if present in the database - * @package net.techfuze.fuzeworks.application.model - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Example extends Model{ - - public function __construct(&$core){ +class Example extends Model +{ + public function __construct(&$core) + { parent::__construct($core); $this->setType('core/databaseutils', 'Model'); - $this->table = 'example'; + $this->table = 'example'; } } - -?> \ No newline at end of file diff --git a/Application/Models/model.sqltable.php b/Application/Models/model.sqltable.php index 112b22d..0cadbda 100644 --- a/Application/Models/model.sqltable.php +++ b/Application/Models/model.sqltable.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Application\Model; -use \FuzeWorks\Model; + +use FuzeWorks\Model; /** - * SQLTable model + * SQLTable model. * * This model connects to the querybuilder and is used to quickly interact with SQL tables. * * Start building a query AND DON'T FORGET TO USE setTable() before executing the query - * @package net.techfuze.fuzeworks.application.model - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Sqltable extends Model{ - - public function __construct(){ - - $this->setType('core/databaseutils', 'Model'); - $this->fields = '*'; - $this->table = 'table'; +class Sqltable extends Model +{ + public function __construct() + { + $this->setType('core/databaseutils', 'Model'); + $this->fields = '*'; + $this->table = 'table'; } -} \ No newline at end of file +} diff --git a/Application/Views/errors/view.404.php b/Application/Views/errors/view.404.php index 5d8c4d6..98c765d 100644 --- a/Application/Views/errors/view.404.php +++ b/Application/Views/errors/view.404.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ ?> - Page not found - - + -
-
-
- +
+
+
+ -
-
-
-
- - +
+
+
+
+ + - -
+ start(); + function start() { + $("#contentPanel").fadeIn(500); + $("#1").fadeIn(500); + } + + \ No newline at end of file diff --git a/Application/Views/view.home.php b/Application/Views/view.home.php index 089c06a..4756d12 100644 --- a/Application/Views/view.home.php +++ b/Application/Views/view.home.php @@ -1,6 +1,6 @@ . * * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * * @link http://fuzeworks.techfuze.net * @since Version 0.0.1 + * * @version Version 0.0.1 */ ?> - FuzeWorks - Home - - + -
-
-
- -
- - +
+
+
+
+ + - -
+ start(); + function start() { + $("#contentPanel").fadeIn(500); + $("#1").fadeIn(500); + } + + \ No newline at end of file diff --git a/Application/class.init.php b/Application/class.init.php index 90bd565..c071c0a 100644 --- a/Application/class.init.php +++ b/Application/class.init.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Application; -use \FuzeWorks\Bus; + +use FuzeWorks\Bus; /** - * Class init + * Class init. * * This class will be loaded before the a controller is loaded. Handy to do some we-need-to-do-this-all-the-time-things like setting locales or importing functions. * Can also be used to authenticate users and provide all views with sessionData. * Will only be loaded if the default callable is used. - * @package net.techfuze.fuzeworks.application - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Init extends Bus { - - /** - * Constructor - * - * @param \FuzeWorks\Core $core Pointer to core class - */ - public function __construct(&$core){ +class Init extends Bus +{ + /** + * Constructor. + * + * @param \FuzeWorks\Core $core Pointer to core class + */ + public function __construct(&$core) + { parent::__construct($core); } } - -?> \ No newline at end of file diff --git a/Core/Events/event.layoutLoadViewEvent.php b/Core/Events/event.layoutLoadViewEvent.php index 754e4f7..59b2720 100644 --- a/Core/Events/event.layoutLoadViewEvent.php +++ b/Core/Events/event.layoutLoadViewEvent.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks\Event; -use \FuzeWorks\Event; + +use FuzeWorks\Event; /** * Event that gets loaded when a view is loaded. * * Use this to cancel the loading of a view, or change the file or engine of a view * - * @package net.techfuze.fuzeworks.core.event - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class LayoutLoadViewEvent extends Event { - - /** - * The directory of the view to be loaded - * @var string - */ +class LayoutLoadViewEvent extends Event +{ + /** + * The directory of the view to be loaded. + * + * @var string + */ public $directory; /** - * The file of the view to be loaded + * The file of the view to be loaded. + * * @var string */ public $file; /** - * The engine the file will be loaded with + * The engine the file will be loaded with. + * * @var object */ public $engine; /** - * The assigned variables to the template + * The assigned variables to the template. + * * @var array */ public $assigned_variables; - public function init($file, $directory, $engine, $assigned_variables){ + public function init($file, $directory, $engine, $assigned_variables) + { $this->file = $file; $this->directory = $directory; $this->engine = $engine; $this->assigned_variables = $assigned_variables; } } - -?> \ No newline at end of file diff --git a/Core/Events/event.modelLoadEvent.php b/Core/Events/event.modelLoadEvent.php index ca84af9..78185e7 100644 --- a/Core/Events/event.modelLoadEvent.php +++ b/Core/Events/event.modelLoadEvent.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks\Event; -use \FuzeWorks\Event; + +use FuzeWorks\Event; /** * Event that gets loaded when a model is loaded. * * Use this to cancel the loading of a model, or change the model to be loaded * - * @package net.techfuze.fuzeworks.core.event - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class ModelLoadEvent extends Event { - - /** - * The directory the model gets loaded from - * @var string|null - */ +class ModelLoadEvent extends Event +{ + /** + * The directory the model gets loaded from. + * + * @var string|null + */ public $directory = null; /** - * The name of the model to be loaded + * The name of the model to be loaded. + * * @var string|null */ public $model = null; - public function init($model, $directory){ + public function init($model, $directory) + { $this->model = $model; $this->directory = $directory; } } - -?> \ No newline at end of file diff --git a/Core/Events/event.routerLoadCallableEvent.php b/Core/Events/event.routerLoadCallableEvent.php index d8d8d98..e9e42ea 100644 --- a/Core/Events/event.routerLoadCallableEvent.php +++ b/Core/Events/event.routerLoadCallableEvent.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks\Event; -use \FuzeWorks\Event; + +use FuzeWorks\Event; /** - * Class routerLoadCallableEvent + * Class routerLoadCallableEvent. * * Called when a callable is about to be loaded * - * @package net.techfuze.fuzeworks.core.event - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class routerLoadCallableEvent extends Event{ - +class routerLoadCallableEvent extends Event +{ /** * @var callable The callable */ @@ -53,15 +55,16 @@ class routerLoadCallableEvent extends Event{ public $matches = array(); /** - * The route which was matched + * The route which was matched. + * * @var null|string */ public $route = null; - public function init($callable, $matches, $route){ - + public function init($callable, $matches, $route) + { $this->callable = $callable; - $this->matches = $matches; - $this->route = $route; + $this->matches = $matches; + $this->route = $route; } -} \ No newline at end of file +} diff --git a/Core/Events/event.routerRouteEvent.php b/Core/Events/event.routerRouteEvent.php index b40b3a6..55ca521 100644 --- a/Core/Events/event.routerRouteEvent.php +++ b/Core/Events/event.routerRouteEvent.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks\Event; -use \FuzeWorks\Event; + +use FuzeWorks\Event; /** - * Class routerRouteEvent + * Class routerRouteEvent. * * Fired after the router has extracted the path, and is about to find out what route matches the path. * * This Event is usefull for adding routes. * - * @package net.techfuze.fuzeworks.core.event - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class routerRouteEvent extends Event{ - +class routerRouteEvent extends Event +{ /** * @var array The routing table */ public $routes; /** - * @var boolean Whether the callable will be loaded directly after or not + * @var bool Whether the callable will be loaded directly after or not */ public $loadCallable; /** - * The current path input to FuzeWorks + * The current path input to FuzeWorks. + * * @var null|string */ public $path; - public function init($routes, $loadCallable, $path){ - - $this->routes = $routes; + public function init($routes, $loadCallable, $path) + { + $this->routes = $routes; $this->loadCallable = $loadCallable; - $this->path = $path; + $this->path = $path; } -} \ No newline at end of file +} diff --git a/Core/Events/event.routerSetPathEvent.php b/Core/Events/event.routerSetPathEvent.php index fceb9d5..ec716b4 100644 --- a/Core/Events/event.routerSetPathEvent.php +++ b/Core/Events/event.routerSetPathEvent.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks\Event; -use \FuzeWorks\Event; + +use FuzeWorks\Event; /** - * Class routerSetPathEvent + * Class routerSetPathEvent. * * Fired when the router's path is changing * - * @package net.techfuze.fuzeworks.core.event - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class routerSetPathEvent extends Event{ - - /** - * The path to be set to the router - * @var string The new path - */ - public $path; - - public function init($path){ +class routerSetPathEvent extends Event +{ + /** + * The path to be set to the router. + * + * @var string The new path + */ + public $path; + public function init($path) + { $this->path = $path; } } - -?> \ No newline at end of file diff --git a/Core/System/class.abstract.controllerabstract.php b/Core/System/class.abstract.controllerabstract.php index 8d178a8..91aa890 100644 --- a/Core/System/class.abstract.controllerabstract.php +++ b/Core/System/class.abstract.controllerabstract.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Abstract class ControllerAbstract + * Abstract class ControllerAbstract. * * At this point does nothing, can be extended in the future to allow special controller functions - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -abstract class ControllerAbstract {} \ No newline at end of file +abstract class ControllerAbstract +{ +} diff --git a/Core/System/class.abstract.event.php b/Core/System/class.abstract.event.php index c249817..3a1e818 100644 --- a/Core/System/class.abstract.event.php +++ b/Core/System/class.abstract.event.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Class Event + * Class Event. * * A simple class for events. The only current purpose is to be able to cancel events, but it can be easily extended. - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Event { - - private $cancelled = false; +class Event +{ + private $cancelled = false; /** - * @return boolean True if the event is cancelled, false if the event is not cancelled + * @return bool True if the event is cancelled, false if the event is not cancelled */ - public function isCancelled() { - return $this->cancelled; - } + public function isCancelled() + { + return $this->cancelled; + } /** - * @param boolean $cancelled True if the event is cancelled, false if the event is not cancelled + * @param bool $cancelled True if the event is cancelled, false if the event is not cancelled */ - public function setCancelled($cancelled) { - if ($cancelled == true){ + public function setCancelled($cancelled) + { + if ($cancelled == true) { $this->cancelled = true; - } else{ + } else { $this->cancelled = false; } } @@ -64,11 +68,11 @@ class Event { namespace FuzeWorks\Event; /** - * Simple event which will notify components of an event, but does not contain any data - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Simple event which will notify components of an event, but does not contain any data. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class NotifierEvent extends \FuzeWorks\Event {} - -?> \ No newline at end of file +class NotifierEvent extends \FuzeWorks\Event +{ +} diff --git a/Core/System/class.abstract.eventPriority.php b/Core/System/class.abstract.eventPriority.php index c5cc745..6cd314e 100644 --- a/Core/System/class.abstract.eventPriority.php +++ b/Core/System/class.abstract.eventPriority.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Class EventPriority + * Class EventPriority. * * The EventPriority is an "enum" which gives priorities an integer value, the higher the integer value, the lower the * priority. The available priorities are, from highest to lowest: @@ -42,42 +44,41 @@ namespace FuzeWorks; * EventPriority::NORMAL * EventPriority::LOW * EventPriority::LOWEST - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ - abstract class EventPriority { - - const LOWEST = 5; - const LOW = 4; - const NORMAL = 3; - const HIGH = 2; - const HIGHEST = 1; - const MONITOR = 0; + const LOWEST = 5; + const LOW = 4; + const NORMAL = 3; + const HIGH = 2; + const HIGHEST = 1; + const MONITOR = 0; /** - * Returns the string of the priority based on the integer + * Returns the string of the priority based on the integer. + * * @param $intPriorty + * * @return bool|string A bool when the integer isn't a priority. If the integer is a priority, the name is returned */ - static function getPriority($intPriorty){ - - switch($intPriorty){ - + public static function getPriority($intPriorty) + { + switch ($intPriorty) { case 5: - return "EventPriority::LOWEST"; + return 'EventPriority::LOWEST'; case 4: - return "EventPriority::LOW"; + return 'EventPriority::LOW'; case 3: - return "EventPriority::NORMAL"; + return 'EventPriority::NORMAL'; case 2: - return "EventPriority::HIGH"; + return 'EventPriority::HIGH'; case 1: - return "EventPriority::HIGHEST"; + return 'EventPriority::HIGHEST'; case 0: - return "EventPriority::MONITOR"; + return 'EventPriority::MONITOR'; default: return false; } @@ -85,21 +86,23 @@ abstract class EventPriority /** * Returns the highest priority - * This function is needed for the firing of events in the right order, + * This function is needed for the firing of events in the right order,. + * * @return int */ - static function getHighestPriority(){ - - return EventPriority::MONITOR; + public static function getHighestPriority() + { + return self::MONITOR; } /** * Returns the lowest priority - * This function is needed for the firing of events in the right order, + * This function is needed for the firing of events in the right order,. + * * @return int */ - static function getLowestPriority(){ - - return EventPriority::LOWEST; + public static function getLowestPriority() + { + return self::LOWEST; } -} \ No newline at end of file +} diff --git a/Core/System/class.abstract.model.php b/Core/System/class.abstract.model.php index 777f55e..f2e72db 100644 --- a/Core/System/class.abstract.model.php +++ b/Core/System/class.abstract.model.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** * Interface for a Module that gives abstract model types - * A model server must contain the methods from this interface in order to correctly serve models - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * A model server must contain the methods from this interface in order to correctly serve models. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -interface ModelServer { - public function giveModel($type); +interface ModelServer +{ + public function giveModel($type); } /** - * Abstract class Model + * Abstract class Model. * * Abstract for a model data representation, loads the correct parent type - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -abstract class Model { +abstract class Model +{ + /** + * The parent class holder object + * Requests get redirected to this class. + * + * @var Parent Object + */ + private $parentClass; - /** - * The parent class holder object - * Requests get redirected to this class - * @access private - * @var Parent Object - */ - private $parentClass; + /** + * Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model. + * + * @param string Module_name, the name of the module where the model can be found + * @param string Model_type, model type to return + */ + protected function setType($module_name, $model_type) + { + $mod = Modules::get($module_name); + $this->parentClass = $mod->giveModel($model_type); + } - /** - * Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model - * @access protected - * @param String Module_name, the name of the module where the model can be found - * @param String Model_type, model type to return - */ - protected function setType($module_name, $model_type) { - $mod = Modules::get($module_name); - $this->parentClass = $mod->giveModel($model_type); - } + /** + * Retrieves a value from the model class. + * + * @param Any key + * + * @return Any value from the model class + */ + public function __get($name) + { + return $this->parentClass->$name; + } - /** - * Retrieves a value from the model class - * @access public - * @param Any key - * @return Any value from the model class - */ - public function __get($name) { - return $this->parentClass->$name; - } + /** + * Sets a value in the model class. + * + * @param Any key + * @param Any value + */ + public function __set($name, $value) + { + $this->parentClass->$name = $value; + } - /** - * Sets a value in the model class - * @access public - * @param Any key - * @param Any value - */ - public function __set($name, $value) { - $this->parentClass->$name = $value; - } - - /** - * Calls a function in the model 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 + /** + * Calls a function in the model class. + * + * @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); + } +} diff --git a/Core/System/class.abstract.module.php b/Core/System/class.abstract.module.php index cb526fc..ecc6560 100644 --- a/Core/System/class.abstract.module.php +++ b/Core/System/class.abstract.module.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Trait Module + * Trait Module. * * Contains all the methods modules should have - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -trait Module { +trait Module +{ + /** + * @var null|string Relative path to the module + */ + protected static $modulePath = null; - /** - * @var null|string Relative path to the module - */ - protected static $modulePath = null; + /** + * @var string Internal name of the module + */ + protected static $moduleName = 'placeholder'; - /** - * @var string Internal name of the module - */ - protected static $moduleName = 'placeholder'; + /** + * @var string name used in the mod array + */ + protected static $linkName = 'placeholder'; - /** - * @var String name used in the mod array - */ - protected static $linkName = 'placeholder'; + /** + * @var moduleInfo object of the module + */ + protected static $cfg; - /** - * @var moduleInfo object of the module - */ - protected static $cfg; - - /** - * @var array Advertisements send from other modules - */ - protected static $advertisements = array(); - - /** - * Returns the name of the module - * - * @return string Returns the name of the module - */ - public static function getModuleName(){ + /** + * @var array Advertisements send from other modules + */ + protected static $advertisements = array(); + /** + * Returns the name of the module. + * + * @return string Returns the name of the module + */ + public static function getModuleName() + { return self::$moduleName; } - /** - * Returns the path to the module - * @return null|string - */ - public static function getModulePath(){ - + /** + * Returns the path to the module. + * + * @return null|string + */ + public static function getModulePath() + { return self::$modulePath; } /** - * Returns the config of the module (moduleInfo.php) - * @access public - * @return stdClass module config + * Returns the config of the module (moduleInfo.php). + * + * @return stdClass module config */ - public static function getModuleConfig() { - return self::$cfg; + public static function getModuleConfig() + { + return self::$cfg; } - /** - * Changes the path to the location of the module - * - * This function can only be executed once, because when the path has been set this function won't save changes anymore. - * This prevents modules or other systems to mess with modules and their stability. - * - * @param string $modulePath - */ - public static function setModulePath($modulePath = null){ + /** + * Changes the path to the location of the module. + * + * This function can only be executed once, because when the path has been set this function won't save changes anymore. + * This prevents modules or other systems to mess with modules and their stability. + * + * @param string $modulePath + */ + public static function setModulePath($modulePath = null) + { // Only allow one change of this variable from outside - if(self::$modulePath === null) + if (self::$modulePath === null) { self::$modulePath = $modulePath; + } } /** * Set the link name of the module. The link name is the address in the module array so that the module can self reference. - * @access public - * @param String link name + * + * @param string link name */ - public static function setModuleLinkName($linkName) { - self::$linkName = $linkName; + public static function setModuleLinkName($linkName) + { + self::$linkName = $linkName; } /** - * The name that is required to load itself, eg 'exampleauthor/examplemodulename' or 'techfuze/cms' - * @access public - * @param String module name + * The name that is required to load itself, eg 'exampleauthor/examplemodulename' or 'techfuze/cms'. + * + * @param string module name */ - public static function setModuleName($modName) { - self::$moduleName = $modName; + public static function setModuleName($modName) + { + self::$moduleName = $modName; } /** - * Add the moduleInfo.php to the module for direct interaction - * @access public + * Add the moduleInfo.php to the module for direct interaction. + * * @param stdClass module config */ - public static function setModuleConfig($config) { - self::$cfg = $config; + public static function setModuleConfig($config) + { + self::$cfg = $config; } /** - * Set a value in the modules moduleInfo.php - * @access protected - * @param Mixed config Key - * @param Mixed config value + * Set a value in the modules moduleInfo.php. + * + * @param mixed config Key + * @param mixed config value */ - public static function setConfigValue($key, $value) { - $file = self::getModulePath() . "moduleInfo.php"; - self::$cfg->$key = $value; + public static function setConfigValue($key, $value) + { + $file = self::getModulePath().'moduleInfo.php'; + self::$cfg->$key = $value; - // Check if the module path is set yet - if (self::getModulePath() == null) { - Logger::logWarning("Could not write module config. ModulePath is not set", get_class($this)); - return false; - } + // Check if the module path is set yet + if (self::getModulePath() == null) { + Logger::logWarning('Could not write module config. ModulePath is not set', get_class($this)); - if (file_exists($file) && is_writable($file)) { - $config = var_export($this->cfg, true); - file_put_contents($file, "cfg, true); + file_put_contents($file, "$key; - } -} \ No newline at end of file + /** + * Get the advertisements with a specific name. + * + * @param string $advertiseName AdvertisementName + * + * @return array AdvertisementData + */ + public static function getAdvertisements($advertiseName) + { + return self::$advertisements[$advertiseName]; + } + + /** + * Return a value from the module configuration. + * + * @param mixed config Key + * + * @return mixed config value + */ + public static function getConfigValue($key) + { + return self::$cfg->$key; + } +} diff --git a/Core/System/class.config.php b/Core/System/class.config.php index c29b8ef..3f755f9 100644 --- a/Core/System/class.config.php +++ b/Core/System/class.config.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; -use \PDOException; -use \FuzeWorks\ORM\ConfigFileORM; -use \FuzeWorks\ORM\ConfigDatabaseORM; +use PDOException; +use FuzeWorks\ORM\ConfigFileORM; +use FuzeWorks\ORM\ConfigDatabaseORM; /** - * Config Class + * Config Class. * * This class gives access to the config files. It allows you to open configurations and edit them. * This class is extensible, but not yet from the outside - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Config { +class Config +{ + /** + * whether or not the database is active at the moment. + * + * @var bool true on active database + */ + public static $dbActive = false; - /** - * whether or not the database is active at the moment - * @access public - * @var Boolean true on active database - */ - public static $dbActive = false; + /** + * All loaded Config files. + * + * @var array of ConfigORM + */ + private static $cfg = array(); - /** - * All loaded Config files - * @var Array of ConfigORM - */ - private static $cfg = array(); + /** + * Loads a config file and returns it as an object. + * + * @param string config file name + * @param string directory, default is Application/Config + * + * @throws \Exception on file not found + * + * @return \FuzeWorks\ORM\ConfigORM of config + */ + public static function loadConfigFile($name, $directory = null) + { + $dir = (isset($directory) ? $directory : 'Application/Config/'); + $file = $dir.'config.'.strtolower($name).'.php'; - /** - * Loads a config file and returns it as an object - * @access public - * @param String config file name - * @param String directory, default is Application/Config - * @throws \Exception on file not found - * @return \FuzeWorks\ORM\ConfigORM of config - */ - public static function loadConfigFile($name, $directory = null) { - $dir = (isset($directory) ? $directory : "Application/Config/"); - $file = $dir . 'config.' . strtolower($name).".php"; + // If already loaded, return a reference to the ORM + if (isset(self::$cfg[$name])) { + return $cfg = self::$cfg[$name]; + } - // If already loaded, return a reference to the ORM - if (isset(self::$cfg[$name])) { - return $cfg = self::$cfg[$name]; - } + // Is this the real file? + if (file_exists($file)) { + // Is it just reference? + return $cfg = self::$cfg[$name] = new ConfigFileORM($file); + } else { + // Caught in a datastream + $module = Modules::get('core/database'); + // No escape from dbactive + if (self::$dbActive) { + // Open your stream + $dborm = new ConfigDatabaseORM($module, $name); + // Lookup for success + if ($dborm->success) { + // And see + return $cfg = self::$cfg[$name] = $dborm; + } + } - // Is this the real file? - if (file_exists($file)) { - // Is it just reference? - return $cfg = self::$cfg[$name] = new ConfigFileORM($file); - } else { - // Caught in a datastream - $module = Modules::get('core/database'); - // No escape from dbactive - if (self::$dbActive) { - // Open your stream - $dborm = new ConfigDatabaseORM($module, $name); - // Lookup for the success - if ($dborm->success) { - // And see - return $cfg = self::$cfg[$name] = $dborm; - } - } + // I'm just a poor exception + throw new ConfigException("Config file '".strtolower($name)."' was not found", 1); - // I'm just a poor exception - throw new ConfigException("Config file '".strtolower($name)."' was not found", 1); + // I need no returnee + return false; + } + } - // I need no returnee - return false; - } - } - - /** - * Magic config getter - * @access public - * @param String config file name - * @return \FuzeWorks\ORM\ConfigORM of config - */ - public static function get($name) { - return self::loadConfigFile($name); - } + /** + * Magic config getter. + * + * @param string config file name + * + * @return \FuzeWorks\ORM\ConfigORM of config + */ + public static function get($name) + { + return self::loadConfigFile($name); + } } namespace FuzeWorks\ORM; -use \Iterator; + +use Iterator; /** * Abstract ConfigORM class. * * This class implements the iterator, so a config file can be accessed using foreach. * A file can also be returned using toArray(), so it will be converted to an array - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -abstract class ConfigORM implements Iterator { +abstract class ConfigORM implements Iterator +{ + /** + * The original state of a config file. Can be reverted to using revert(). + * + * @var StdObject Config file + */ + protected $originalCfg; - /** - * The original state of a config file. Can be reverted to using revert() - * @var StdObject Config file - */ - protected $originalCfg; + /** + * The current state of a config file. + * + * @var StdObject Config file + */ + protected $cfg; - /** - * The current state of a config file. - * @var StdObject Config file - */ - protected $cfg; + /** + * Revert to the original conditions of the config file. + */ + public function revert() + { + $this->cfg = $this->originalCfg; + } - /** - * Revert to the original conditions of the config file. - */ - public function revert() { - $this->cfg = $this->originalCfg; - } + /** + * Checks if a requested key is set in the config file. + * + * @param string $name Parameter name + * + * @return bool true on isset, false on not + */ + public function __isset($name) + { + return isset($this->cfg[$name]); + } - /** - * Checks if a requested key is set in the config file - * @param String $name Parameter name - * @return boolean true on isset, false on not - */ - public function __isset($name) { - return isset($this->cfg[$name]); - } + /** + * Return a value from a config file. + * + * @param string $name Key of the requested entry + * + * @return mixed Value of the requested entry + */ + public function __get($name) + { + return $this->cfg[$name]; + } - /** - * Return a value from a config file - * @param String $name Key of the requested entry - * @return Mixed Value of the requested entry - */ - public function __get($name) { - return $this->cfg[$name]; - } + /** + * Sets an entry in the config file. + * + * @param string $name Key of the entry + * @param mixed $value Value of the entry + */ + public function __set($name, $value) + { + $this->cfg[$name] = $value; + } - /** - * Sets an entry in the config file - * @param String $name Key of the entry - * @param Mixed $value Value of the entry - */ - public function __set($name, $value) { - $this->cfg[$name] = $value; - } + /** + * Unset a value in a config file. + * + * @param string Key of the entry + */ + public function __unset($name) + { + unset($this->cfg[$name]); + } - /** - * Unset a value in a config file - * @param String Key of the entry - */ - public function __unset($name) { - unset($this->cfg[$name]); - } + /** + * Iterator method. + */ + public function rewind() + { + return reset($this->cfg); + } - /** - * Iterator method - */ - public function rewind() { - return reset($this->cfg); - } + /** + * Iterator method. + */ + public function current() + { + return current($this->cfg); + } - /** - * Iterator method - */ - public function current() { - return current($this->cfg); - } + /** + * Iterator method. + */ + public function key() + { + return key($this->cfg); + } - /** - * Iterator method - */ - public function key() { - return key($this->cfg); - } + /** + * Iterator method. + */ + public function next() + { + return next($this->cfg); + } - /** - * Iterator method - */ - public function next() { - return next($this->cfg); - } + /** + * Iterator method. + */ + public function valid() + { + return key($this->cfg) !== null; + } - /** - * Iterator method - */ - public function valid() { - return key($this->cfg) !== null; - } - - /** - * Returns the config file as an array - * @return Array Config file - */ - public function toArray() { - return $this->cfg; - } + /** + * Returns the config file as an array. + * + * @return array Config file + */ + public function toArray() + { + return $this->cfg; + } } /** - * ORM class for config files in a database + * ORM class for config files in a database. * * Handles entries in the database of FuzeWorks and is able to dynamically update them when requested - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class ConfigDatabaseORM extends ConfigORM { +class ConfigDatabaseORM extends ConfigORM +{ + /** + * The current connection to the database. + * + * @var \FuzeWorks\Database Database Connection + */ + private $dbh; - /** - * The current connection to the database - * @var \FuzeWorks\Database Database Connection - */ - private $dbh; + /** + * whether the database connection has been successfully established. + * + * @var bool true on success + */ + public $success = false; - /** - * whether the database connection has been successfully established - * @var boolean true on success - */ - public $success = false; + /** + * The current filename. + * + * @var string filename + */ + private $file; - /** - * The current filename - * @var String filename - */ - private $file; + /** + * Sets up the class and the connection to the database. + * + * @param \FuzeWorks\Database $db The Database connection + * @param string $filename The current filename + * + * @throws ConfigException on fatal error + */ + public function __construct($db, $filename) + { + $this->dbh = $db; + $this->cfg = $this->openDb($filename); + $this->originalCfg = $this->cfg; + $this->file = $filename; + } - /** - * Sets up the class and the connection to the database - * @param \FuzeWorks\Database $db The Database connection - * @param String $filename The current filename - * @throws ConfigException on fatal error - */ - public function __construct($db, $filename) { - $this->dbh = $db; - $this->cfg = $this->openDb($filename); - $this->originalCfg = $this->cfg; - $this->file = $filename; - } - - /** - * Opens up a database connection with the requested filename - * @param String $name Name of the file - * @return Array Content of the file - * @throws ConfigException on fatal error - */ - private function openDb($name) { - $prefix = $this->dbh->getPrefix(); - try{ - $stmnt = $this->dbh->prepare("SELECT * FROM ".$prefix."config WHERE `file` = ?"); + /** + * Opens up a database connection with the requested filename. + * + * @param string $name Name of the file + * + * @return array Content of the file + * + * @throws ConfigException on fatal error + */ + private function openDb($name) + { + $prefix = $this->dbh->getPrefix(); + try { + $stmnt = $this->dbh->prepare('SELECT * FROM '.$prefix.'config WHERE `file` = ?'); $stmnt->execute(array($name)); - } catch (PDOException $e){ + } catch (PDOException $e) { throw new ConfigException('Could not execute SQL-query due PDO-exception '.$e->getMessage()); } // Fetch results $result = $stmnt->fetchAll(\PDO::FETCH_ASSOC); $return = array(); - for ($i=0; $i < count($result); $i++) { - $return[ $result[$i]['key'] ] = $result[$i]['value']; + for ($i = 0; $i < count($result); ++$i) { + $return[ $result[$i]['key'] ] = $result[$i]['value']; } // Return if found in DB if (!empty($return)) { - $this->success = true; - return (array) $return; + $this->success = true; + + return (array) $return; } - } + } - /** - * Write config updates to the database - * @throws ConfigException on fatal error - */ - private function writeDb() { - // First arrays of all the fields that need to change - $changed_fields = array(); - $removed_fields = array(); - $new_fields = array(); + /** + * Write config updates to the database. + * + * @throws ConfigException on fatal error + */ + private function writeDb() + { + // First arrays of all the fields that need to change + $changed_fields = array(); + $removed_fields = array(); + $new_fields = array(); - // First check for changed and new feeds - foreach ($this->cfg as $key => $value) { - if (isset($this->originalCfg[$key])) { - if ($this->originalCfg[$key] != $value) { - // Changed field - $changed_fields[$key] = $value; - } - } else { - // New field - $new_fields[$key] = $value; - } - } + // First check for changed and new feeds + foreach ($this->cfg as $key => $value) { + if (isset($this->originalCfg[$key])) { + if ($this->originalCfg[$key] != $value) { + // Changed field + $changed_fields[$key] = $value; + } + } else { + // New field + $new_fields[$key] = $value; + } + } - // Then check for removed fields - foreach ($this->originalCfg as $key => $value) { - if (!isset($this->cfg[$key])) { - $removed_fields[$key] = $value; - } - } + // Then check for removed fields + foreach ($this->originalCfg as $key => $value) { + if (!isset($this->cfg[$key])) { + $removed_fields[$key] = $value; + } + } - // First for the removed values - $prefix = $this->dbh->getPrefix(); - try { - $stmnt = $this->dbh->prepare("DELETE FROM ".$prefix."config WHERE `file` = :file AND `key` = :key"); - foreach ($removed_fields as $key => $value) { - $stmnt->execute(array('file' => $this->file, 'key' => $key)); - } - } catch (PDOException $e) { - throw new ConfigException("Could not change config due to PDOException: " . $e->getMessage(), 1); - } + // First for the removed values + $prefix = $this->dbh->getPrefix(); + try { + $stmnt = $this->dbh->prepare('DELETE FROM '.$prefix.'config WHERE `file` = :file AND `key` = :key'); + foreach ($removed_fields as $key => $value) { + $stmnt->execute(array('file' => $this->file, 'key' => $key)); + } + } catch (PDOException $e) { + throw new ConfigException('Could not change config due to PDOException: '.$e->getMessage(), 1); + } - // Then for the changed values - try { - $stmnt = $this->dbh->prepare("UPDATE ".$prefix."config SET `value` = :value WHERE `file` = :file AND `key` = :key"); - foreach ($changed_fields as $key => $value) { - $stmnt->execute(array('file' => $this->file, 'key' => $key, 'value' => $value)); - } - } catch (PDOException $e) { - throw new ConfigException("Could not change config due to PDOException: " . $e->getMessage(), 1); - } - - // And finally for the new values - try { - $stmnt = $this->dbh->prepare("INSERT INTO ".$prefix."config (`file`,`key`,`value`) VALUES (:file,:key,:value)"); - foreach ($new_fields as $key => $value) { - $stmnt->execute(array('file' => $this->file, 'key' => $key, 'value' => $value)); - } - } catch (PDOException $e) { - throw new ConfigException("Could not change config due to PDOException: " . $e->getMessage(), 1); - } - - } - - /** - * Write updates of the config file to the database - * @throws ConfigException on fatal error - */ - public function commit() { - $this->writeDb(); - } + // Then for the changed values + try { + $stmnt = $this->dbh->prepare('UPDATE '.$prefix.'config SET `value` = :value WHERE `file` = :file AND `key` = :key'); + foreach ($changed_fields as $key => $value) { + $stmnt->execute(array('file' => $this->file, 'key' => $key, 'value' => $value)); + } + } catch (PDOException $e) { + throw new ConfigException('Could not change config due to PDOException: '.$e->getMessage(), 1); + } + // And finally for the new values + try { + $stmnt = $this->dbh->prepare('INSERT INTO '.$prefix.'config (`file`,`key`,`value`) VALUES (:file,:key,:value)'); + foreach ($new_fields as $key => $value) { + $stmnt->execute(array('file' => $this->file, 'key' => $key, 'value' => $value)); + } + } catch (PDOException $e) { + throw new ConfigException('Could not change config due to PDOException: '.$e->getMessage(), 1); + } + } + /** + * Write updates of the config file to the database. + * + * @throws ConfigException on fatal error + */ + public function commit() + { + $this->writeDb(); + } } /** - * ORM class for config files in PHP files + * ORM class for config files in PHP files. * * Handles entries in the config directory of FuzeWorks and is able to dynamically update them when requested - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class ConfigFileORM extends ConfigORM { +class ConfigFileORM extends ConfigORM +{ + /** + * The current filename. + * + * @var string filename + */ + private $file; - /** - * The current filename - * @var String filename - */ - private $file; + /** + * Sets up the class and the connection to the PHP file. + * + * @param string $filename The current filename + * + * @throws ConfigException on fatal error + */ + public function __construct($file) + { + if (file_exists($file)) { + $this->file = $file; + $this->openFile($file); + $this->originalCfg = $this->cfg; + } else { + throw new ConfigException('Could not load config file. Config file does not exist', 1); + } + } - /** - * Sets up the class and the connection to the PHP file - * @param String $filename The current filename - * @throws ConfigException on fatal error - */ - public function __construct($file) { - if (file_exists($file)) { - $this->file = $file; - $this->openFile($file); - $this->originalCfg = $this->cfg; - } else { - throw new ConfigException("Could not load config file. Config file does not exist", 1); - } - } + /** + * Opens the file and returns the data. + * + * @param string $file Name of the config file + * + * @return array Content of the file + */ + private function openFile($file) + { + $this->cfg = (array) include $file; + } - /** - * Opens the file and returns the data - * @param String $file Name of the config file - * @return Array Content of the file - */ - private function openFile($file) { - $this->cfg = (array) require($file); - } + /** + * Updates the config file and writes it to the database. + * + * @throws ConfigException on fatal error + */ + private function writeFile() + { + // Implement writing here + if (is_writable($this->file)) { + $config = var_export($this->cfg, true); + file_put_contents($this->file, "file)) { - $config = var_export($this->cfg, true); - file_put_contents($this->file, "writeFile(); - } + /** + * Updates the config file and writes it. + * + * @throws ConfigException on fatal error + */ + public function commit() + { + $this->writeFile(); + } } - -?> \ No newline at end of file diff --git a/Core/System/class.core.php b/Core/System/class.core.php index c1fb215..bb6ea08 100644 --- a/Core/System/class.core.php +++ b/Core/System/class.core.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; -use \stdClass; /** - * FuzeWorks Core + * FuzeWorks Core. * * Holds all the modules and starts the framework. Allows for starting and managing modules - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Core { - - /** - * The current version of the framework - * @access public - * @var String Framework version - */ - public static $version = "0.0.1"; +class Core +{ + /** + * The current version of the framework. + * + * @var string Framework version + */ + public static $version = '0.0.1'; /** * @var bool Whether the files has been loaded @@ -54,131 +55,133 @@ class Core { private static $loaded = false; /** - * Working directory of the Framework + * Working directory of the Framework. * * This is required to make the shutdown function working under Apache webservers - * @var String $cwd + * + * @var string */ public static $cwd; - /** - * Initializes the core - * - * @throws \Exception - */ - public static function init() { - // Defines the time the framework starts. Used for timing functions in the framework - if (!defined('STARTTIME')) { - define('STARTTIME', microtime(true)); - } + /** + * Initializes the core. + * + * @throws \Exception + */ + public static function init() + { + // Defines the time the framework starts. Used for timing functions in the framework + if (!defined('STARTTIME')) { + define('STARTTIME', microtime(true)); + } - // Load basics - ignore_user_abort(true); - register_shutdown_function(array('\FuzeWorks\Core', "shutdown")); + // Load basics + ignore_user_abort(true); + register_shutdown_function(array('\FuzeWorks\Core', 'shutdown')); - // Load core functionality - self::loadStartupFiles(); + // Load core functionality + self::loadStartupFiles(); - // Load the config file of the FuzeWorks core - $config = Config::get('core'); + // Load the config file of the FuzeWorks core + $config = Config::get('core'); - // Load the logger - Logger::init(); + // Load the logger + Logger::init(); - // And initialize the router paths - Router::init(); + // And initialize the router paths + Router::init(); - // Build all the registers for correct operation - Modules::buildRegister(); + // Build all the registers for correct operation + Modules::buildRegister(); - // Load Composer - if ($config->enable_composer) { - $file = ($config->composer_autoloader != '' ? $config->composer_autoloader : 'vendor/autoload.php'); - self::loadComposer($file); - } + // Load Composer + if ($config->enable_composer) { + $file = ($config->composer_autoloader != '' ? $config->composer_autoloader : 'vendor/autoload.php'); + self::loadComposer($file); + } - // And fire the coreStartEvent - $event = Events::fireEvent('coreStartEvent'); - if ($event->isCancelled()) { - return true; - } + // And fire the coreStartEvent + $event = Events::fireEvent('coreStartEvent'); + if ($event->isCancelled()) { + return true; + } - // Set the CWD for usage in the shutdown function+ - self::$cwd = getcwd(); - } + // Set the CWD for usage in the shutdown function+ + self::$cwd = getcwd(); + } - /** - * Load all the files of the FuzeWorks Framework. - */ - private static function loadStartupFiles() { - if (self::$loaded) - return; + /** + * Load all the files of the FuzeWorks Framework. + */ + private static function loadStartupFiles() + { + if (self::$loaded) { + return; + } - // Load core abstracts - require_once("Core/System/class.exceptions.php"); - require_once("Core/System/class.abstract.event.php"); + // Load core abstracts + include_once 'Core/System/class.exceptions.php'; + include_once 'Core/System/class.abstract.event.php'; - // Load the core classes - require_once("Core/System/class.config.php"); - require_once("Core/System/class.abstract.eventPriority.php"); - require_once("Core/System/class.events.php"); - require_once("Core/System/class.logger.php"); - require_once("Core/System/class.abstract.model.php"); - require_once("Core/System/class.models.php"); - require_once("Core/System/class.layout.php"); - require_once("Core/System/class.abstract.controllerabstract.php"); - require_once("Core/System/class.router.php"); - require_once("Core/System/class.abstract.module.php"); - require_once("Core/System/class.modules.php"); + // Load the core classes + include_once 'Core/System/class.config.php'; + include_once 'Core/System/class.abstract.eventPriority.php'; + include_once 'Core/System/class.events.php'; + include_once 'Core/System/class.logger.php'; + include_once 'Core/System/class.abstract.model.php'; + include_once 'Core/System/class.models.php'; + include_once 'Core/System/class.layout.php'; + include_once 'Core/System/class.abstract.controllerabstract.php'; + include_once 'Core/System/class.router.php'; + include_once 'Core/System/class.abstract.module.php'; + include_once 'Core/System/class.modules.php'; - // Create the module holder - new Config(); - new Logger(); - new Events(); - new Models(); - new Layout(); - new Router(); - new Modules(); + // Create the module holder + new Config(); + new Logger(); + new Events(); + new Models(); + new Layout(); + new Router(); + new Modules(); self::$loaded = true; - } + } - /** - * Stop FuzeWorks and run all shutdown functions. - * - * Afterwards run the Logger shutdown function in order to possibly display the log - * @access public - * @return void - */ - public static function shutdown() { - // Fix Apache bug where CWD is changed upon shutdown - chdir(self::$cwd); + /** + * Stop FuzeWorks and run all shutdown functions. + * + * Afterwards run the Logger shutdown function in order to possibly display the log + */ + public static function shutdown() + { + // Fix Apache bug where CWD is changed upon shutdown + chdir(self::$cwd); - // Fire the Shutdown event - Events::fireEvent('coreShutdownEvent'); + // Fire the Shutdown event + Events::fireEvent('coreShutdownEvent'); - // And end the logger - Logger::shutdown(); - } + // And end the logger + Logger::shutdown(); + } - /** - * Load composer if it is present - * @access private - * @param String directory of composer autoload file (optional) - * @return boolean true on success, false on failure - */ - private static function loadComposer($file = "vendor/autoload.php") { - if (file_exists($file)) { - require($file); - Logger::log('Loaded Composer'); - return true; - } - Logger::log('Failed to load Composer. File \''.$file.'\' not found'); - return false; - } + /** + * Load composer if it is present. + * + * @param string directory of composer autoload file (optional) + * + * @return bool true on success, false on failure + */ + private static function loadComposer($file = 'vendor/autoload.php') + { + if (file_exists($file)) { + include $file; + Logger::log('Loaded Composer'); + return true; + } + Logger::log('Failed to load Composer. File \''.$file.'\' not found'); + return false; + } } - - -?> \ No newline at end of file diff --git a/Core/System/class.events.php b/Core/System/class.events.php index 99f0470..083a541 100644 --- a/Core/System/class.events.php +++ b/Core/System/class.events.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Class Events + * Class Events. * * FuzeWorks is built in a way that almost every core-event can be manipulated by modules. This class provides various ways to hook into the core (or other modules) * and manipulate the outcome of the functions. Modules and core actions can 'fire' an event and modules can 'hook' into that event. Let's take a look at the example below: @@ -48,163 +50,181 @@ namespace FuzeWorks; * * $event->title = date('H:i:s ').$event->title; * - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Events { - +class Events +{ /** - * Array of classes that can handle events + * Array of classes that can handle events. + * * @var array */ - public static $listeners = array(); + public static $listeners = array(); /** - * Whether the event system is enabled or not + * Whether the event system is enabled or not. + * * @var array */ private static $enabled = true; /** - * A register with all the events and associated modules which should be loaded upon eventFire + * A register with all the events and associated modules which should be loaded upon eventFire. + * * @var array */ public static $register; /** - * Adds a function as listener + * Adds a function as listener. * * @param mixed callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net} - * @param String $eventName The name of the event - * @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest) + * @param string $eventName The name of the event + * @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest) + * * @see EventPriority * * @throws EventException */ - public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL){ - if(EventPriority::getPriority($priority) == false) - throw new Exception("Unknown priority " . $priority); + public static function addListener($callback, $eventName, $priority = EventPriority::NORMAL) + { + if (EventPriority::getPriority($priority) == false) { + throw new Exception('Unknown priority '.$priority); + } - if(!isset(self::$listeners[$eventName])) + if (!isset(self::$listeners[$eventName])) { self::$listeners[$eventName] = array(); + } - if(!isset(self::$listeners[$eventName][$priority])) - self::$listeners[$eventName][$priority] = array(); + if (!isset(self::$listeners[$eventName][$priority])) { + self::$listeners[$eventName][$priority] = array(); + } self::$listeners[$eventName][$priority][] = $callback; } /** - * Removes a function as listener + * Removes a function as listener. * * @param mixed callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net} - * @param String $eventName The name of the event - * @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest) + * @param string $eventName The name of the event + * @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest) + * * @see EventPriority * * @throws EventException */ - public static function removeListener($callback, $eventName, $priority = EventPriority::NORMAL){ - if(EventPriority::getPriority($priority) == false) - throw new Exception("Unknown priority " . $priority); + public static function removeListener($callback, $eventName, $priority = EventPriority::NORMAL) + { + if (EventPriority::getPriority($priority) == false) { + throw new Exception('Unknown priority '.$priority); + } - if(!isset(self::$listeners[$eventName])) + if (!isset(self::$listeners[$eventName])) { return; + } - if(!isset(self::$listeners[$eventName][$priority])) + if (!isset(self::$listeners[$eventName][$priority])) { return; + } - foreach(self::$listeners[$eventName][$priority] as $i => $_callback){ - - if($_callback == $callback) { + foreach (self::$listeners[$eventName][$priority] as $i => $_callback) { + if ($_callback == $callback) { unset(self::$listeners[$eventName][$priority][$i]); + return; } } } - /** - * Fires an Event + /** + * Fires an Event. * * The Event gets created, passed around and then returned to the issuer. - * @param Mixed $input Object for direct event, string for system event or notifierEvent - * @return \FuzeWorks\Event The Event + * + * @param mixed $input Object for direct event, string for system event or notifierEvent + * + * @return \FuzeWorks\Event The Event */ - public static function fireEvent($input) { - if (is_string($input)) { - // If the input is a string - $eventClass = $input; - $eventName = $input; - if(!class_exists($eventClass)){ - // Check if the file even exists - $file = "Core/Events/event.".$eventName.".php"; - if(file_exists($file)){ - // Load the file - $eventClass = "\FuzeWorks\Event\\" . $eventClass; - require_once($file); - }else{ - // No event arguments? Looks like a notify-event - if(func_num_args() == 1){ - // Load notify-event-class - $eventClass = '\FuzeWorks\Event\NotifierEvent'; - }else{ - // No notify-event: we tried all we could - throw new Exception("Event ".$eventName." could not be found!"); - } - } - } + public static function fireEvent($input) + { + if (is_string($input)) { + // If the input is a string + $eventClass = $input; + $eventName = $input; + if (!class_exists($eventClass)) { + // Check if the file even exists + $file = 'Core/Events/event.'.$eventName.'.php'; + if (file_exists($file)) { + // Load the file + $eventClass = "\FuzeWorks\Event\\".$eventClass; + include_once $file; + } else { + // No event arguments? Looks like a notify-event + if (func_num_args() == 1) { + // Load notify-event-class + $eventClass = '\FuzeWorks\Event\NotifierEvent'; + } else { + // No notify-event: we tried all we could + throw new Exception('Event '.$eventName.' could not be found!'); + } + } + } - $event = new $eventClass($this); - } elseif (is_object($input)) { - $eventName = get_class($input); - $eventName = explode('\\', $eventName); - $eventName = end($eventName); - $event = $input; - } else { - // INVALID EVENT - return false; - } + $event = new $eventClass($this); + } elseif (is_object($input)) { + $eventName = get_class($input); + $eventName = explode('\\', $eventName); + $eventName = end($eventName); + $event = $input; + } else { + // INVALID EVENT + return false; + } - Logger::newLevel("Firing Event: '".$eventName."'"); - Logger::log('Initializing Event'); + Logger::newLevel("Firing Event: '".$eventName."'"); + Logger::log('Initializing Event'); - if (func_num_args() > 1) - call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1)); + if (func_num_args() > 1) { + call_user_func_array(array($event, 'init'), array_slice(func_get_args(), 1)); + } // Do not run if the event system is disabled if (!self::$enabled) { - Logger::log("Event system is disabled"); + Logger::log('Event system is disabled'); Logger::stopLevel(); + return $event; } - Logger::log("Checking for Listeners"); + Logger::log('Checking for Listeners'); // Read the event register for listeners $register = self::$register; if (isset($register[$eventName])) { - for ($i=0; $i < count($register[$eventName]); $i++) { + for ($i = 0; $i < count($register[$eventName]); ++$i) { Modules::get($register[$eventName][$i]); } } //There are listeners for this event - if(isset(self::$listeners[$eventName])) { + if (isset(self::$listeners[$eventName])) { //Loop from the highest priority to the lowest - for ($priority = EventPriority::getHighestPriority(); $priority <= EventPriority::getLowestPriority(); $priority++) { + for ($priority = EventPriority::getHighestPriority(); $priority <= EventPriority::getLowestPriority(); ++$priority) { //Check for listeners in this priority if (isset(self::$listeners[$eventName][$priority])) { - $listeners = self::$listeners[$eventName][$priority]; - Logger::newLevel('Found listeners with priority ' . EventPriority::getPriority($priority)); + $listeners = self::$listeners[$eventName][$priority]; + Logger::newLevel('Found listeners with priority '.EventPriority::getPriority($priority)); //Fire the event to each listener foreach ($listeners as $callback) { if (is_callable($callback)) { Logger::newLevel('Firing function'); - } elseif(!is_string($callback[0])) - Logger::newLevel('Firing ' . get_class($callback[0]) . '->' . $callback[1]); - else - Logger::newLevel('Firing ' . join('->', $callback)); + } elseif (!is_string($callback[0])) { + Logger::newLevel('Firing '.get_class($callback[0]).'->'.$callback[1]); + } else { + Logger::newLevel('Firing '.implode('->', $callback)); + } try { call_user_func($callback, $event); } catch (ModuleException $e) { @@ -218,26 +238,26 @@ class Events { } } - Logger::stopLevel(); - return $event; - } + Logger::stopLevel(); + + return $event; + } /** - * Enables the event system + * Enables the event system. */ - public static function enable() { - Logger::log("Enabled the Event system"); + public static function enable() + { + Logger::log('Enabled the Event system'); self::$enabled = true; } /** - * Disables the event system + * Disables the event system. */ - public static function disable() { - Logger::log("Disabled the Event system"); + public static function disable() + { + Logger::log('Disabled the Event system'); self::$enabled = false; } } - - -?> \ No newline at end of file diff --git a/Core/System/class.exceptions.php b/Core/System/class.exceptions.php index 837ddf5..01f8566 100644 --- a/Core/System/class.exceptions.php +++ b/Core/System/class.exceptions.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Class Exception - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class Exception. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Exception extends \Exception{} +class Exception extends \Exception +{ +} /** - * Class LayoutException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class LayoutException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class LayoutException extends Exception{} +class LayoutException extends Exception +{ +} /** - * Class ConfigException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class ConfigException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class ConfigException extends Exception{} +class ConfigException extends Exception +{ +} /** - * Class ModelException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class ModelException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class ModelException extends Exception{} +class ModelException extends Exception +{ +} /** - * Class LoggerException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class LoggerException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class LoggerException extends Exception{} +class LoggerException extends Exception +{ +} /** - * Class RouterException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class RouterException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class RouterException extends Exception{} +class RouterException extends Exception +{ +} /** - * Class CoreException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class CoreException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class CoreException extends Exception{} +class CoreException extends Exception +{ +} /** - * Class EventException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class EventException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class EventException extends Exception{} +class EventException extends Exception +{ +} /** - * Class DatabaseException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class DatabaseException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class DatabaseException extends Exception{} +class DatabaseException extends Exception +{ +} /** - * Class ModuleException - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class ModuleException. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class ModuleException extends Exception{} \ No newline at end of file +class ModuleException extends Exception +{ +} diff --git a/Core/System/class.layout.php b/Core/System/class.layout.php index e8bd640..f16fe10 100644 --- a/Core/System/class.layout.php +++ b/Core/System/class.layout.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; -use \FuzeWorks\TemplateEngine\JSONEngine; -use \FuzeWorks\TemplateEngine\PHPEngine; -use \FuzeWorks\TemplateEngine\SmartyEngine; -use \FuzeWorks\TemplateEngine\TemplateEngine; + +use FuzeWorks\TemplateEngine\JSONEngine; +use FuzeWorks\TemplateEngine\PHPEngine; +use FuzeWorks\TemplateEngine\SmartyEngine; +use FuzeWorks\TemplateEngine\TemplateEngine; /** * Layout and Template Manager for FuzeWorks. - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Layout { +class Layout +{ + /** + * The file to be loaded by the layout manager. + * + * @var null|string + */ + public static $file = null; - /** - * The file to be loaded by the layout manager - * @var null|string - */ - public static $file = null; + /** + * The directory of the file to be loaded by the layout manager. + * + * @var string + */ + public static $directory = 'Application/Views'; - /** - * The directory of the file to be loaded by the layout manager - * @var string - */ - public static $directory = 'Application/Views'; + /** + * All assigned currently assigned to the template. + * + * @var array Associative Assigned Variable Array + */ + private static $assigned_variables = array(); - /** - * All assigned currently assigned to the template - * @var Array Associative Assigned Variable Array - */ - private static $assigned_variables = array(); + /** + * All engines that can be used for templates. + * + * @var array of engines + */ + private static $engines = array(); - /** - * All engines that can be used for templates - * @var array of engines - */ - private static $engines = array(); + /** + * All file extensions that can be used and are bound to a template engine. + * + * @var array of names of engines + */ + private static $file_extensions = array(); - /** - * All file extensions that can be used and are bound to a template engine - * @var array of names of engines - */ - private static $file_extensions = array(); + /** + * whether the template engines are already called. + * + * @var bool True if loaded + */ + private static $engines_loaded = false; - /** - * whether the template engines are already called. - * @var boolean True if loaded - */ - private static $engines_loaded = false; + /** + * The currently selected template engine. + * + * @var string name of engine + */ + private static $current_engine; - /** - * The currently selected template engine - * @var String name of engine - */ - private static $current_engine; + /** + * Retrieve a template file using a string and a directory and immediatly echo it. + * + * What template file gets loaded depends on the template engine that is being used. + * PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file. + * You can also provide no particular engine, and the manager will decide what template to load. + * Remember that doing so will result in a LayoutException when multiple compatible files are found. + * + * @param string $file File to load + * @param string $directory Directory to load it from + * + * @throws LayoutException On error + */ + public static function view($file, $directory = null) + { + $directory = (is_null($directory) ? self::$directory : $directory); + echo self::get($file, $directory); - /** - * Retrieve a template file using a string and a directory and immediatly echo it. - * - * What template file gets loaded depends on the template engine that is being used. - * PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file. - * You can also provide no particular engine, and the manager will decide what template to load. - * Remember that doing so will result in a LayoutException when multiple compatible files are found. - * @param String $file File to load - * @param string $directory Directory to load it from - * @return void - * @throws LayoutException On error - */ - public static function view($file, $directory = null) { - $directory = (is_null($directory) ? self::$directory : $directory); - echo self::get($file, $directory); - return; - } + return; + } + /** + * Retrieve a template file using a string and a directory. + * + * What template file gets loaded depends on the template engine that is being used. + * PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file. + * You can also provide no particular engine, and the manager will decide what template to load. + * Remember that doing so will result in a LayoutException when multiple compatible files are found. + * + * @param string $file File to load + * @param string $directory Directory to load it from + * + * @return string The output of the template + * + * @throws LayoutException On error + */ + public static function get($file, $directory = null) + { + $directory = (is_null($directory) ? self::$directory : $directory); + Logger::newLevel("Loading template file '".$file."' in '".$directory."'"); - /** - * Retrieve a template file using a string and a directory. - * - * What template file gets loaded depends on the template engine that is being used. - * PHP for example uses .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php file. - * You can also provide no particular engine, and the manager will decide what template to load. - * Remember that doing so will result in a LayoutException when multiple compatible files are found. - * @param String $file File to load - * @param string $directory Directory to load it from - * @return String The output of the template - * @throws LayoutException On error - */ - public static function get($file, $directory = null) { - $directory = (is_null($directory) ? self::$directory : $directory); - Logger::newLevel("Loading template file '".$file."' in '".$directory."'"); + // First load the template engines + self::loadTemplateEngines(); - // First load the template engines - self::loadTemplateEngines(); + // First retrieve the filepath + if (is_null(self::$current_engine)) { + self::setFileFromString($file, $directory, array_keys(self::$file_extensions)); + } else { + self::setFileFromString($file, $directory, self::$current_engine->getFileExtensions()); + } - // First retrieve the filepath - if (is_null(self::$current_engine)) { - self::setFileFromString($file, $directory, array_keys(self::$file_extensions)); - } else { - self::setFileFromString($file, $directory, self::$current_engine->getFileExtensions()); - } + // Then assign some basic variables for the template + self::$assigned_variables['viewDir'] = Config::get('main')->SITE_URL.preg_replace('#/+#', '/', substr(self::$directory.'/', -strlen(self::$directory.'/'))); + self::$assigned_variables['siteURL'] = Config::get('main')->SITE_URL; + self::$assigned_variables['siteLogo'] = Config::get('main')->SITE_LOGO_URL; + self::$assigned_variables['serverName'] = Config::get('main')->SERVER_NAME; + self::$assigned_variables['siteDomain'] = Config::get('main')->SITE_DOMAIN; + self::$assigned_variables['adminMail'] = Config::get('main')->administrator_mail; + self::$assigned_variables['contact'] = Config::get('contact')->toArray(); - // Then assign some basic variables for the template - self::$assigned_variables['viewDir'] = Config::get('main')->SITE_URL . preg_replace('#/+#','/', substr(self::$directory . "/", -strlen(self::$directory . "/") ) ); - self::$assigned_variables['siteURL'] = Config::get('main')->SITE_URL; - self::$assigned_variables['siteLogo'] = Config::get('main')->SITE_LOGO_URL; - self::$assigned_variables['serverName'] = Config::get('main')->SERVER_NAME; - self::$assigned_variables['siteDomain'] = Config::get('main')->SITE_DOMAIN; - self::$assigned_variables['adminMail'] = Config::get('main')->administrator_mail; - self::$assigned_variables['contact'] = Config::get('contact')->toArray(); + // Select an engine if one is not already selected + if (is_null(self::$current_engine)) { + self::$current_engine = self::getEngineFromExtension(self::getExtensionFromFile(self::$file)); + } - // Select an engine if one is not already selected - if (is_null(self::$current_engine)) { - self::$current_engine = self::getEngineFromExtension( self::getExtensionFromFile(self::$file) ); - } + self::$current_engine->setDirectory(self::$directory); - self::$current_engine->setDirectory(self::$directory); - - // And run an Event to see what other parts have to say about it + // And run an Event to see what other parts have to say about it $event = Events::fireEvent('layoutLoadViewEvent', self::$file, self::$directory, self::$current_engine, self::$assigned_variables); // The event has been cancelled - if($event->isCancelled()){ - + if ($event->isCancelled()) { return false; } @@ -158,550 +173,637 @@ class Layout { self::$current_engine = $event->engine; self::$assigned_variables = $event->assigned_variables; - Logger::stopLevel(); + Logger::stopLevel(); - // And finally run it - if (file_exists($event->file)) - return self::$current_engine->get($event->file, self::$assigned_variables); + // And finally run it + if (file_exists($event->file)) { + return self::$current_engine->get($event->file, self::$assigned_variables); + } - throw new LayoutException("The requested file was not found", 1); - } + throw new LayoutException('The requested file was not found', 1); + } - /** - * Retrieve a Template Engine from a File Extension - * @param String $extension File extention to look for - * @return Object Template Engine - */ - public static function getEngineFromExtension($extension) { - if (isset(self::$file_extensions[strtolower($extension)])) { - return self::$engines[ self::$file_extensions[strtolower($extension)]]; - } + /** + * Retrieve a Template Engine from a File Extension. + * + * @param string $extension File extention to look for + * + * @return object Template Engine + */ + public static function getEngineFromExtension($extension) + { + if (isset(self::$file_extensions[strtolower($extension)])) { + return self::$engines[ self::$file_extensions[strtolower($extension)]]; + } - throw new LayoutException("Could not get Template Engine. No engine has corresponding file extension", 1); - } + throw new LayoutException('Could not get Template Engine. No engine has corresponding file extension', 1); + } - /** - * Retrieve the extension from a file string - * @param String $fileString The path to the file - * @return String Extension of the file - */ - public static function getExtensionFromFile($fileString) { - return substr($fileString, strrpos($fileString, '.') + 1); - } + /** + * Retrieve the extension from a file string. + * + * @param string $fileString The path to the file + * + * @return string Extension of the file + */ + public static function getExtensionFromFile($fileString) + { + return substr($fileString, strrpos($fileString, '.') + 1); + } - /** - * Converts a view string to a file using the directory and the used extensions. - * - * It will detect whether the file exists and choose a file according to the provided extensions - * @param String $string The string used by a controller. eg: 'dashboard/home' - * @param String $directory The directory to search in for the template - * @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc. - * @return String Filepath of the template - * @throws LayoutException On error - */ - public static function getFileFromString($string, $directory, $extensions = array()) { - $directory = preg_replace('#/+#','/',(!is_null($directory) ? $directory : self::$directory) . "/"); + /** + * Converts a view string to a file using the directory and the used extensions. + * + * It will detect whether the file exists and choose a file according to the provided extensions + * + * @param string $string The string used by a controller. eg: 'dashboard/home' + * @param string $directory The directory to search in for the template + * @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc. + * + * @return string Filepath of the template + * + * @throws LayoutException On error + */ + public static function getFileFromString($string, $directory, $extensions = array()) + { + $directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : self::$directory).'/'); - if (!file_exists($directory)) { - throw new LayoutException("Could not get file. Directory does not exist", 1); - } + if (!file_exists($directory)) { + throw new LayoutException('Could not get file. Directory does not exist', 1); + } - // Set the file name and location - $viewSelector = explode('/', $string); - if (count($viewSelector) == 1) { - $viewSelector = 'view.'.$viewSelector[0]; - } else { - // Get last file - $file = end($viewSelector); + // Set the file name and location + $viewSelector = explode('/', $string); + if (count($viewSelector) == 1) { + $viewSelector = 'view.'.$viewSelector[0]; + } else { + // Get last file + $file = end($viewSelector); - // Reset to start - reset($viewSelector); + // Reset to start + reset($viewSelector); - // Remove last value - array_pop($viewSelector); + // Remove last value + array_pop($viewSelector); - $viewSelector[] = 'view.'.$file; + $viewSelector[] = 'view.'.$file; - // And create the final value - $viewSelector = implode('/', $viewSelector); - } + // And create the final value + $viewSelector = implode('/', $viewSelector); + } - // Then try and select a file - $fileSelected = false; - $selectedFile = null; - foreach ($extensions as $extension) { - $file = $directory . $viewSelector .".". strtolower($extension); - $file = preg_replace('#/+#','/',$file); - if (file_exists($file) && !$fileSelected) { - $selectedFile = $file; - $fileSelected = true; - Logger::log("Found matching file: '". $file . "'"); - } elseif (file_exists($file) && $fileSelected) { - throw new LayoutException("Could not select template. Multiple valid extensions detected. Can not choose.", 1); - } - } + // Then try and select a file + $fileSelected = false; + $selectedFile = null; + foreach ($extensions as $extension) { + $file = $directory.$viewSelector.'.'.strtolower($extension); + $file = preg_replace('#/+#', '/', $file); + if (file_exists($file) && !$fileSelected) { + $selectedFile = $file; + $fileSelected = true; + Logger::log("Found matching file: '".$file."'"); + } elseif (file_exists($file) && $fileSelected) { + throw new LayoutException('Could not select template. Multiple valid extensions detected. Can not choose.', 1); + } + } - // And choose what to output - if (!$fileSelected) { - throw new LayoutException("Could not select template. No matching file found."); - } + // And choose what to output + if (!$fileSelected) { + throw new LayoutException('Could not select template. No matching file found.'); + } - return $selectedFile; - } + return $selectedFile; + } - /** - * Converts a view string to a file using the directory and the used extensions. - * It also sets the file variable of this class. - * - * It will detect whether the file exists and choose a file according to the provided extensions - * @param String $string The string used by a controller. eg: 'dashboard/home' - * @param String $directory The directory to search in for the template - * @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc. - * @return String Filepath of the template - * @throws LayoutException On error - */ - public static function setFileFromString($string, $directory, $extensions = array()) { - self::$file = self::getFileFromString($string, $directory, $extensions); - self::$directory = preg_replace('#/+#','/',(!is_null($directory) ? $directory : self::$directory) . "/"); - } + /** + * Converts a view string to a file using the directory and the used extensions. + * It also sets the file variable of this class. + * + * It will detect whether the file exists and choose a file according to the provided extensions + * + * @param string $string The string used by a controller. eg: 'dashboard/home' + * @param string $directory The directory to search in for the template + * @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc. + * + * @return string Filepath of the template + * + * @throws LayoutException On error + */ + public static function setFileFromString($string, $directory, $extensions = array()) + { + self::$file = self::getFileFromString($string, $directory, $extensions); + self::$directory = preg_replace('#/+#', '/', (!is_null($directory) ? $directory : self::$directory).'/'); + } - /** - * Get the current file to be loaded - * @return null|string Path to the file - */ - public static function getFile() { - return self::$file; - } + /** + * Get the current file to be loaded. + * + * @return null|string Path to the file + */ + public static function getFile() + { + return self::$file; + } - /** - * Set the file to be loaded - * @param string $file Path to the file - */ - public static function setFile($file) { - self::$file = $file; - } + /** + * Set the file to be loaded. + * + * @param string $file Path to the file + */ + public static function setFile($file) + { + self::$file = $file; + } - /** - * Get the directory of the file to be loaded - * @return null|string Path to the directory - */ - public static function getDirectory() { - return self::$directory; - } + /** + * Get the directory of the file to be loaded. + * + * @return null|string Path to the directory + */ + public static function getDirectory() + { + return self::$directory; + } - /** - * Set the directory of the file to be loaded - * @param string $directory Path to the directory - */ - public static function setDirectory($directory) { - self::$directory = $directory; - } + /** + * Set the directory of the file to be loaded. + * + * @param string $directory Path to the directory + */ + public static function setDirectory($directory) + { + self::$directory = $directory; + } - /** - * Assign a variable for the template - * @param String $key Key of the variable - * @param Mixed $value Value of the variable - */ - public static function assign($key, $value) { - self::$assigned_variables[$key] = $value; - } + /** + * Assign a variable for the template. + * + * @param string $key Key of the variable + * @param mixed $value Value of the variable + */ + public static function assign($key, $value) + { + self::$assigned_variables[$key] = $value; + } - /** - * Set the title of the template - * @param String $title title of the template - */ - public static function setTitle($title) { - self::$assigned_variables['title'] = $title; - } + /** + * Set the title of the template. + * + * @param string $title title of the template + */ + public static function setTitle($title) + { + self::$assigned_variables['title'] = $title; + } - /** - * Get the title of the template - * @return String title of the template - */ - public static function getTitle() { - return self::$assigned_variables['title']; - } + /** + * Get the title of the template. + * + * @return string title of the template + */ + public static function getTitle() + { + return self::$assigned_variables['title']; + } - /** - * Set the engine for the next layout - * @param String $name Name of the template engine - * @return boolean true on success - * @throws \FuzeWorks\LayoutException on error - */ - public static function setEngine($name) { - self::loadTemplateEngines(); - if (isset(self::$engines[$name])) { - self::$current_engine = self::$engines[$name]; - Logger::log('Set the Template Engine to ' . $name); - return true; - } - throw new LayoutException("Could not set engine. Engine does not exist", 1); - } + /** + * Set the engine for the next layout. + * + * @param string $name Name of the template engine + * + * @return bool true on success + * + * @throws \FuzeWorks\LayoutException on error + */ + public static function setEngine($name) + { + self::loadTemplateEngines(); + if (isset(self::$engines[$name])) { + self::$current_engine = self::$engines[$name]; + Logger::log('Set the Template Engine to '.$name); - /** - * Get a loaded template engine - * @param String $name Name of the template engine - * @return Object Object that implements \FuzeWorks\TemplateEngine - */ - public static function getEngine($name) { - self::loadTemplateEngines(); - if (isset(self::$engines[$name])) { - return self::$engines[$name]; - } - throw new LayoutException("Could not return engine. Engine does not exist", 1); - } + return true; + } + throw new LayoutException('Could not set engine. Engine does not exist', 1); + } - /** - * Register a new template engine - * @param Object $engineClass Object that implements the \FuzeWorks\TemplateEngine - * @param String $engineName Name of the template engine - * @param Array $engineFileExtensions File extensions this template engine should be used for - * @return boolean true on success - * @throws \FuzeWorks\LayoutException On error - */ - public static function registerEngine($engineClass, $engineName, $engineFileExtensions = array()) { - // First check if the engine already exists - if (isset(self::$engines[$engineName])) { - throw new LayoutException("Could not register engine. Engine '".$engineName."' already registered", 1); - } + /** + * Get a loaded template engine. + * + * @param string $name Name of the template engine + * + * @return object Object that implements \FuzeWorks\TemplateEngine + */ + public static function getEngine($name) + { + self::loadTemplateEngines(); + if (isset(self::$engines[$name])) { + return self::$engines[$name]; + } + throw new LayoutException('Could not return engine. Engine does not exist', 1); + } - // Then check if the object is correct - if ($engineClass instanceof TemplateEngine) { - // Install it - self::$engines[$engineName] = $engineClass; + /** + * Register a new template engine. + * + * @param object $engineClass Object that implements the \FuzeWorks\TemplateEngine + * @param string $engineName Name of the template engine + * @param array $engineFileExtensions File extensions this template engine should be used for + * + * @return bool true on success + * + * @throws \FuzeWorks\LayoutException On error + */ + public static function registerEngine($engineClass, $engineName, $engineFileExtensions = array()) + { + // First check if the engine already exists + if (isset(self::$engines[$engineName])) { + throw new LayoutException("Could not register engine. Engine '".$engineName."' already registered", 1); + } - // Then define for what file extensions this Template Engine will work - if (!is_array($engineFileExtensions)) { - throw new LayoutException("Could not register engine. File extensions must be an array", 1); - } + // Then check if the object is correct + if ($engineClass instanceof TemplateEngine) { + // Install it + self::$engines[$engineName] = $engineClass; - // Then install them - foreach ($engineFileExtensions as $extension) { - if (isset(self::$file_extensions[strtolower($extension)])) { - throw new LayoutException("Could not register engine. File extension already bound to engine", 1); - } + // Then define for what file extensions this Template Engine will work + if (!is_array($engineFileExtensions)) { + throw new LayoutException('Could not register engine. File extensions must be an array', 1); + } - // And add it - self::$file_extensions[strtolower($extension)] = $engineName; - } + // Then install them + foreach ($engineFileExtensions as $extension) { + if (isset(self::$file_extensions[strtolower($extension)])) { + throw new LayoutException('Could not register engine. File extension already bound to engine', 1); + } - // And log it - Logger::log('Registered Template Engine: ' . $engineName); - return true; - } + // And add it + self::$file_extensions[strtolower($extension)] = $engineName; + } - throw new LayoutException("Could not register engine. Engine must implement \FuzeWorks\TemplateEngine", 1); - } + // And log it + Logger::log('Registered Template Engine: '.$engineName); - /** - * Load the template engines by sending a layoutLoadEngineEvent - */ - public static function loadTemplateEngines() { - if (!self::$engines_loaded) { - Events::fireEvent('layoutLoadEngineEvent'); + return true; + } - // Load the engines provided in this file - self::registerEngine(new PHPEngine(), 'PHP', array('php')); - self::registerEngine(new SmartyEngine(), 'Smarty', array('tpl')); - self::registerEngine(new JsonEngine(), 'JSON', array('json')); - self::$engines_loaded = true; - } - } + throw new LayoutException("Could not register engine. Engine must implement \FuzeWorks\TemplateEngine", 1); + } - /** - * Calls a function in the current Template engine - * @param String $name Name of the function to be called - * @param Paramaters $params Parameters to be used - * @return Mixed Function output - */ - public static function __callStatic($name, $params) { - // First load the template engines - self::loadTemplateEngines(); + /** + * Load the template engines by sending a layoutLoadEngineEvent. + */ + public static function loadTemplateEngines() + { + if (!self::$engines_loaded) { + Events::fireEvent('layoutLoadEngineEvent'); - if (!is_null(self::$current_engine)) { - // Call user func array here - return call_user_func_array(array(self::$current_engine, $name), $params); - } - throw new LayoutException("Could not access Engine. Engine not loaded", 1); - } + // Load the engines provided in this file + self::registerEngine(new PHPEngine(), 'PHP', array('php')); + self::registerEngine(new SmartyEngine(), 'Smarty', array('tpl')); + self::registerEngine(new JsonEngine(), 'JSON', array('json')); + self::$engines_loaded = true; + } + } - /** - * Resets the layout manager to its default state - */ - public static function reset() { - if (!is_null(self::$current_engine)) { - self::$current_engine->reset(); - } - self::$current_engine = null; - self::$assigned_variables = array(); - Logger::log("Reset the layout manager to its default state"); - } + /** + * Calls a function in the current Template engine. + * + * @param string $name Name of the function to be called + * @param Paramaters $params Parameters to be used + * + * @return mixed Function output + */ + public static function __callStatic($name, $params) + { + // First load the template engines + self::loadTemplateEngines(); + + if (!is_null(self::$current_engine)) { + // Call user func array here + return call_user_func_array(array(self::$current_engine, $name), $params); + } + throw new LayoutException('Could not access Engine. Engine not loaded', 1); + } + + /** + * Resets the layout manager to its default state. + */ + public static function reset() + { + if (!is_null(self::$current_engine)) { + self::$current_engine->reset(); + } + self::$current_engine = null; + self::$assigned_variables = array(); + Logger::log('Reset the layout manager to its default state'); + } } namespace FuzeWorks\TemplateEngine; -use \FuzeWorks\LayoutException; -use \Smarty; + +use FuzeWorks\LayoutException; +use Smarty; /** - * Interface that all Template Engines must follow - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Interface that all Template Engines must follow. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -interface TemplateEngine { - /** - * Set the directory of the current template - * @param String $directory Template Directory - */ - public function setDirectory($directory); +interface TemplateEngine +{ + /** + * Set the directory of the current template. + * + * @param string $directory Template Directory + */ + public function setDirectory($directory); - /** - * Handle and retrieve a template file - * @param String $file Template File - * @param Array $assigned_variables All the variables used in this view - * @return String Output of the template - */ - public function get($file, $assigned_variables); + /** + * Handle and retrieve a template file. + * + * @param string $file Template File + * @param array $assigned_variables All the variables used in this view + * + * @return string Output of the template + */ + public function get($file, $assigned_variables); - /** - * Retrieve the file extensions that this template engine uses - * @return Array All used extensions. eg: array('php') - */ - public function getFileExtensions(); + /** + * Retrieve the file extensions that this template engine uses. + * + * @return array All used extensions. eg: array('php') + */ + public function getFileExtensions(); - /** - * Reset the template engine to its default state, so it can be used again clean. - */ - public function reset(); + /** + * Reset the template engine to its default state, so it can be used again clean. + */ + public function reset(); } /** - * Simple Template Engine that allows for PHP templates - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Simple Template Engine that allows for PHP templates. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class PHPEngine implements TemplateEngine { +class PHPEngine implements TemplateEngine +{ + /** + * The currently used directory by the template. + * + * @var string + */ + protected $directory; - /** - * The currently used directory by the template - * @var String - */ - protected $directory; + /** + * All the currently assigned variables. + * + * @var array + */ + protected $assigned_variables = array(); - /** - * All the currently assigned variables - * @var array - */ - protected $assigned_variables = array(); + public function setDirectory($directory) + { + $this->directory = $directory; + } - public function setDirectory($directory) { - $this->directory = $directory; - } + public function get($file, $assigned_variables) + { + // First set all the variables + $this->assigned_variables = $assigned_variables; + $vars = $this->assigned_variables; + $directory = $this->directory; - public function get($file, $assigned_variables) { - // First set all the variables - $this->assigned_variables = $assigned_variables; - $vars = $this->assigned_variables; - $directory = $this->directory; + // Then run the file + if (!is_null($file)) { + ob_start(); + include $file; - // Then run the file - if (!is_null($file)) { - ob_start(); - require($file); - return ob_get_clean(); - } - } + return ob_get_clean(); + } + } - public function getFileExtensions() { - return array('php'); - } + public function getFileExtensions() + { + return array('php'); + } - public function reset() { - $this->directory = null; - $this->assigned_variables = array(); - } + public function reset() + { + $this->directory = null; + $this->assigned_variables = array(); + } } /** - * Wrapper for the Smarty Template Engine - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Wrapper for the Smarty Template Engine. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class SmartyEngine implements TemplateEngine { +class SmartyEngine implements TemplateEngine +{ + /** + * The currently used directory by the template. + * + * @var string + */ + protected $directory; - /** - * The currently used directory by the template - * @var String - */ - protected $directory; + /** + * All the currently assigned variables. + * + * @var array + */ + protected $assigned_variables = array(); - /** - * All the currently assigned variables - * @var array - */ - protected $assigned_variables = array(); + /** + * Instance of the Smarty Template Engine. + * + * @var \Smarty + */ + protected $smartyInstance; - /** - * Instance of the Smarty Template Engine - * @var \Smarty - */ - protected $smartyInstance; + public function setDirectory($directory) + { + $this->directory = $directory; + } - public function setDirectory($directory) { - $this->directory = $directory; - } + public function get($file, $assigned_variables) + { + // First set all the variables + $this->assigned_variables = $assigned_variables; - public function get($file, $assigned_variables) { - // First set all the variables - $this->assigned_variables = $assigned_variables; + // Load Smarty + $this->loadSmarty(); - // Load Smarty - $this->loadSmarty(); + // Set the directory + $this->smartyInstance->setTemplateDir($this->directory); - // Set the directory - $this->smartyInstance->setTemplateDir($this->directory); + // Then assign all variables + foreach ($this->assigned_variables as $key => $value) { + $this->smartyInstance->assign($key, $value); + } - // Then assign all variables - foreach ($this->assigned_variables as $key => $value) { - $this->smartyInstance->assign($key, $value); - } + // And finally, load the template + return $this->smartyInstance->fetch($file); + } - // And finally, load the template - return $this->smartyInstance->fetch($file); - } + /** + * Loads a Smarty instance if it is not already loaded. + */ + private function loadSmarty() + { + if (is_null($this->smartyInstance)) { + $this->smartyInstance = new Smarty(); - /** - * Loads a Smarty instance if it is not already loaded - */ - private function loadSmarty() { - if (is_null($this->smartyInstance)) { - $this->smartyInstance = new Smarty(); + // Then prepare all variables + $this->smartyInstance->setCompileDir('Core/Cache/Compile'); + $this->smartyInstance->setCacheDir('Core/Cache/'); + } + } - // Then prepare all variables - $this->smartyInstance->setCompileDir("Core/Cache/Compile"); - $this->smartyInstance->setCacheDir("Core/Cache/"); - } - } + public function getFileExtensions() + { + return array('tpl'); + } - public function getFileExtensions() { - return array('tpl'); - } + public function reset() + { + $this->smartyInstance = null; + $this->directory = null; + $this->assigned_variables = array(); + } - public function reset() { - $this->smartyInstance = null; - $this->directory = null; - $this->assigned_variables = array(); - } + /** + * Retrieve a value from Smarty. + * + * @param string $name Variable name + * + * @return mixed Variable Value + * + * @throws \FuzeWorks\LayoutException on error + */ + public function __get($name) + { + // First load Smarty + $this->loadSmarty(); - /** - * Retrieve a value from Smarty - * @param String $name Variable name - * @return Mixed Variable Value - * @throws \FuzeWorks\LayoutException on error - */ - public function __get($name) { - // First load Smarty - $this->loadSmarty(); + return $this->smartyInstance->$name; + } - return $this->smartyInstance->$name; - } + /** + * Set a variable in Smarty. + * + * @param string $name Variable Name + * @param mixed $value Variable Value + * + * @throws \FuzeWorks\LayoutException on error + */ + public function __set($name, $value) + { + // First load Smarty + $this->loadSmarty(); - /** - * Set a variable in Smarty - * @param String $name Variable Name - * @param Mixed $value Variable Value - * @throws \FuzeWorks\LayoutException on error - */ - public function __set($name, $value) { - // First load Smarty - $this->loadSmarty(); + $this->smartyInstance->$name = $value; + } - $this->smartyInstance->$name = $value; - } + /** + * Calls a function in Smarty. + * + * @param string $name Name of the function to be called + * @param Paramaters $params Parameters to be used + * + * @return mixed Function output + */ + public function __call($name, $params) + { + // First load Smarty + $this->loadSmarty(); - /** - * Calls a function in Smarty - * @param String $name Name of the function to be called - * @param Paramaters $params Parameters to be used - * @return Mixed Function output - */ - public function __call($name, $params) { - // First load Smarty - $this->loadSmarty(); - return call_user_func_array(array($this->smartyInstance, $name), $params); - } + return call_user_func_array(array($this->smartyInstance, $name), $params); + } } /** - * Template Engine that exports all assigned variables as JSON - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Template Engine that exports all assigned variables as JSON. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class JSONEngine implements TemplateEngine { +class JSONEngine implements TemplateEngine +{ + /** + * All the currently assigned variables. + * + * @var array + */ + protected $assigned_variables = array(); - /** - * All the currently assigned variables - * @var array - */ - protected $assigned_variables = array(); + /** + * Whether the JSON data should be parsed or left as is. + * + * @var bool true if to be parsed + */ + protected static $string_return = true; - /** - * Whether the JSON data should be parsed or left as is - * @var boolean true if to be parsed - */ - protected static $string_return = true; + /** + * Whether the JSON data should be parsed or left as is. + * + * @param true if to be parsed + */ + public static function returnAsString($boolean = true) + { + self::$string_return = $boolean; + } - /** - * Whether the JSON data should be parsed or left as is - * @param true if to be parsed - */ - public static function returnAsString($boolean = true) { - self::$string_return = $boolean; - } + public function setDirectory($directory) + { + return true; + } - public function setDirectory($directory) { - return true; - } + public function get($file, $assigned_variables) + { + // First set all the variables + $this->assigned_variables = $assigned_variables; - public function get($file, $assigned_variables) { - // First set all the variables - $this->assigned_variables = $assigned_variables; + // First set up the JSON array + $json = array(); - // First set up the JSON array - $json = array(); + // Look up if a file is provided + if (!is_null($file)) { + // Retrieve a file + $string = file_get_contents($file); + $json = json_decode($string, true); + } - // Look up if a file is provided - if (!is_null($file)) { - // Retrieve a file - $string = file_get_contents($file); - $json = json_decode($string, true); - } + // Then assign all variables + $json['data'] = $this->assigned_variables; - // Then assign all variables - $json['data'] = $this->assigned_variables; + // And return it + if (self::$string_return) { + return json_encode($json); + } - // And return it - if (self::$string_return) - return json_encode($json); + return $json; + } - return $json; - } + public function getFileExtensions() + { + return array('json'); + } - public function getFileExtensions() { - return array('json'); - } + public function reset() + { + $this->assigned_variables = array(); + $this->string_return = true; + } - public function reset() { - $this->assigned_variables = array(); - $this->string_return = true; - } - - public function test($param1, $param2, $param3) { - return array($param1, $param2, $param3); - } + public function test($param1, $param2, $param3) + { + return array($param1, $param2, $param3); + } } - - diff --git a/Core/System/class.logger.php b/Core/System/class.logger.php index d1f53fd..72cf133 100644 --- a/Core/System/class.logger.php +++ b/Core/System/class.logger.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Logger Class + * 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. - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Logger { +class Logger +{ + /** + * Log entries which display information entries. + * + * @var array + */ + public static $infoErrors = array(); - /** - * Log entries which display information entries - * @var array - */ - public static $infoErrors = array(); + /** + * Log entries which display critical error entries. + * + * @var array + */ + public static $criticalErrors = array(); - /** - * Log entries which display critical error entries - * @var array - */ - public static $criticalErrors = array(); + /** + * Log entries which display warning entries. + * + * @var array + */ + public static $warningErrors = array(); - /** - * Log entries which display warning entries - * @var array - */ - public static $warningErrors = array(); + /** + * All log entries, unsorted. + * + * @var array + */ + public static $Logs = array(); - /** - * All log entries, unsorted - * @var array - */ - public static $Logs = array(); + /** + * whether to output the log after FuzeWorks has run. + * + * @var bool + */ + private static $print_to_screen = false; - /** - * whether to output the log after FuzeWorks has run - * @var boolean - */ - private static $print_to_screen = false; + /** + * whether to output the log after FuzeWorks has run, regardless of conditions. + * + * @var bool + */ + public static $debug = false; - /** - * whether to output the log after FuzeWorks has run, regardless of conditions - * @var boolean - */ - public static $debug = false; + /** + * Initiates the Logger. + * + * Registers the error and exception handler, when required to do so by configuration + */ + public static function init() + { + // Register the error handler + if (Config::get('error')->error_reporting == true) { + set_error_handler(array('\FuzeWorks\Logger', 'errorHandler'), E_ALL); + set_Exception_handler(array('\FuzeWorks\Logger', 'exceptionHandler')); + error_reporting(false); + } + self::$debug = Config::get('error')->debug; + self::newLevel('Logger Initiated'); + } - /** - * Initiates the Logger. - * - * Registers the error and exception handler, when required to do so by configuration - */ - public static function init() { - // Register the error handler - if (Config::get('error')->error_reporting == true) { - set_error_handler(array('\FuzeWorks\Logger', "errorHandler"), E_ALL); - set_Exception_handler(array('\FuzeWorks\Logger', "exceptionHandler")); - error_reporting(false); - } - self::$debug = Config::get('error')->debug; - self::newLevel("Logger Initiated"); - } + /** + * Function to be run upon FuzeWorks shutdown. + * + * Logs a fatal error and outputs the log when configured or requested to do so + */ + public static function shutdown() + { + // Load last error if thrown + $errfile = 'Unknown file'; + $errstr = 'shutdown'; + $errno = E_CORE_ERROR; + $errline = 0; - /** - * Function to be run upon FuzeWorks shutdown. - * - * Logs a fatal error and outputs the log when configured or requested to do so - */ - public static function shutdown() { - // Load last error if thrown - $errfile = "Unknown file"; - $errstr = "shutdown"; - $errno = E_CORE_ERROR; - $errline = 0; + $error = error_get_last(); + if ($error !== null) { + $errno = $error['type']; + $errfile = $error['file']; + $errline = $error['line']; + $errstr = $error['message']; - $error = error_get_last(); - if ($error !== NULL) { - $errno = $error['type']; - $errfile = $error['file']; - $errline = $error['line']; - $errstr = $error['message']; + // Log it! + self::errorHandler($errno, $errstr, $errfile, $errline); + self::logInfo(self::backtrace()); + } - // Log it! - self::errorHandler($errno, $errstr, $errfile, $errline); - self::logInfo(self::backtrace()); - } + // And finally stop the Logging + self::stopLevel(); - // And finally stop the Logging - self::stopLevel(); + if (self::$debug == true || self::$print_to_screen) { + self::log('Parsing debug log'); + echo self::logToScreen(); + } + } - if (self::$debug == true || self::$print_to_screen) { - self::log("Parsing debug log"); - echo self::logToScreen(); - } - } + /** + * System that redirects the errors to the appropriate logging method. + * + * @param int $type Error-type, Pre defined PHP Constant + * @param string error. The error itself + * @param string File. The absolute path of the file + * @param int Line. The line on which the error occured. + * @param array context. Some of the error's relevant variables + */ + public static function errorHandler($type = E_USER_NOTICE, $error = 'Undefined Error', $errFile = null, $errLine = null, $context = null) + { + // Check type + $thisType = self::getType($type); + $LOG = array('type' => (!is_null($thisType) ? $thisType : 'ERROR'), + 'message' => (!is_null($error) ? $error : ''), + 'logFile' => (!is_null($errFile) ? $errFile : ''), + 'logLine' => (!is_null($errLine) ? $errLine : ''), + 'context' => (!is_null($context) ? $context : ''), + 'runtime' => round(self::getRelativeTime(), 4), ); + self::$Logs[] = $LOG; + } - /** - * System that redirects the errors to the appropriate logging method - * @access public - * @param int $type Error-type, Pre defined PHP Constant - * @param string error. The error itself - * @param string File. The absolute path of the file - * @param int Line. The line on which the error occured. - * @param array context. Some of the error's relevant variables - * @return void - */ - public static function errorHandler($type = E_USER_NOTICE, $error = "Undefined Error", $errFile = null, $errLine = null, $context = null) { - // Check type - $thisType = self::getType($type); - $LOG = array('type' => (!is_null($thisType) ? $thisType : "ERROR"), - 'message' => (!is_null($error) ? $error : ""), - 'logFile' => (!is_null($errFile) ? $errFile : ""), - 'logLine' => (!is_null($errLine) ? $errLine : ""), - 'context' => (!is_null($context) ? $context : ""), - 'runtime' => round(self::getRelativeTime(), 4)); - self::$Logs[] = $LOG; - } + /** + * Exception handler + * Will be triggered when an uncaught exception occures. This function shows the error-message, and shuts down the script. + * Please note that most of the user-defined exceptions will be caught in the router, and handled with the error-controller. + * + * @param Exception $exception The occured exception. + */ + public static function exceptionHandler($exception) + { + $message = $exception->getMessage(); + $code = $exception->getCode(); + $file = $exception->getFile(); + $line = $exception->getLine(); + $context = $exception->getTraceAsString(); - /** - * Exception handler - * Will be triggered when an uncaught exception occures. This function shows the error-message, and shuts down the script. - * Please note that most of the user-defined exceptions will be caught in the router, and handled with the error-controller. - * - * @access public - * @param Exception $exception The occured exception. - * @return void - */ - public static function exceptionHandler($exception) - { - $message = $exception->getMessage(); - $code = $exception->getCode(); - $file = $exception->getFile(); - $line = $exception->getLine(); - $context = $exception->getTraceAsString(); + self::logError('Exception thrown: '.$message.' | '.$code, null, $file, $line); + } - self::logError("Exception thrown: " . $message . " | " . $code, null, $file, $line); - } + /** + * Output the entire log to the screen. Used for debugging problems with your code. + * + * @return string Output of the log + */ + public static function logToScreen() + { + // Send a screenLogEvent, allows for new screen log designs + $event = Events::fireEvent('screenLogEvent'); + if ($event->isCancelled()) { + return false; + } - /** - * Output the entire log to the screen. Used for debugging problems with your code. - * @return String Output of the log - */ - public static function logToScreen() { - // Send a screenLogEvent, allows for new screen log designs - $event = Events::fireEvent('screenLogEvent'); - if ($event->isCancelled()) { - return false; - } - - // Otherwise just load it + // Otherwise just load it $string = '

FuzeWorks debug log

'; $layer = 0; - for($i = 0; $i < count(self::$Logs); $i++){ - - $log = self::$Logs[$i]; - if($log['type'] == 'LEVEL_START'){ - $layer++; - $color = 255-($layer*25); + for ($i = 0; $i < count(self::$Logs); ++$i) { + $log = self::$Logs[$i]; + if ($log['type'] == 'LEVEL_START') { + ++$layer; + $color = 255 - ($layer * 25); $string .= '
'; - $string .= '
'.$log['message'].''.(!empty($log['runtime']) ? "(".round($log['runtime']*1000, 4).'ms)' : "").'
'; - } elseif ($log['type'] == "LEVEL_STOP") { - $layer--; - $string .= "
"; - } elseif ($log['type'] == "ERROR") { - $string .= '
['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '['.$log['context'].']' : "").' '.$log["message"].' - '.(!empty($log['logFile']) ? $log['logFile'] : "")." : ".(!empty($log['logLine']) ? $log['logLine'] : "").'('.round($log['runtime']*1000, 4).' ms)
'; - } elseif ($log['type'] == "WARNING") { - $string .= '
['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '['.$log['context'].']' : "").' '.$log["message"].' - '.(!empty($log['logFile']) ? $log['logFile'] : "")." : ".(!empty($log['logLine']) ? $log['logLine'] : "").'('.round($log['runtime']*1000, 4).' ms)
'; - } elseif ($log['type'] == "INFO") { - $string .= '
'.(!empty($log['context']) ? '['.$log['context'].']' : "").' '.$log["message"].'('.round($log['runtime']*1000, 4).' ms)
'; + $string .= '
'.$log['message'].''.(!empty($log['runtime']) ? '('.round($log['runtime'] * 1000, 4).'ms)' : '').'
'; + } elseif ($log['type'] == 'LEVEL_STOP') { + --$layer; + $string .= ''; + } elseif ($log['type'] == 'ERROR') { + $string .= '
['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '['.$log['context'].']' : '').' '.$log['message'].' + '.(!empty($log['logFile']) ? $log['logFile'] : '').' : '.(!empty($log['logLine']) ? $log['logLine'] : '').'('.round($log['runtime'] * 1000, 4).' ms)
'; + } elseif ($log['type'] == 'WARNING') { + $string .= '
['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '['.$log['context'].']' : '').' '.$log['message'].' + '.(!empty($log['logFile']) ? $log['logFile'] : '').' : '.(!empty($log['logLine']) ? $log['logLine'] : '').'('.round($log['runtime'] * 1000, 4).' ms)
'; + } elseif ($log['type'] == 'INFO') { + $string .= '
'.(!empty($log['context']) ? '['.$log['context'].']' : '').' '.$log['message'].'('.round($log['runtime'] * 1000, 4).' ms)
'; } } return $string; - } + } - /** - * Backtrace a problem to the source using the trace of an Exception - * @return string HTML backtrace - */ - public static function backtrace() { - $e = new Exception(); - $trace = explode("\n", $e->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(); + /** + * Backtrace a problem to the source using the trace of an Exception. + * + * @return string HTML backtrace + */ + public static function backtrace() + { + $e = new Exception(); + $trace = explode("\n", $e->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 - } + for ($i = 0; $i < $length; ++$i) { + $result[] = ($i + 1).')'.substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering + } - return "BACKTRACE:
\t" . implode("
", $result)."
"; - } + return "BACKTRACE:
\t".implode('
', $result).'
'; + } - /* =========================================LOGGING METHODS==============================================================*/ + /* =========================================LOGGING METHODS==============================================================*/ - /** - * Create a information log entry - * @param String $msg The information to be logged - * @param String $mod The name of the module - * @param String $file The file where the log occured - * @param integer $line The line where the log occured - * @return void - */ - public static function log($msg, $mod = null, $file = 0, $line = 0) { - self::logInfo($msg, $mod, $file, $line); - } + /** + * Create a information log entry. + * + * @param string $msg The information to be logged + * @param string $mod The name of the module + * @param string $file The file where the log occured + * @param int $line The line where the log occured + */ + public static function log($msg, $mod = null, $file = 0, $line = 0) + { + self::logInfo($msg, $mod, $file, $line); + } - /** - * Create a information log entry - * @param String $msg The information to be logged - * @param String $mod The name of the module - * @param String $file The file where the log occured - * @param integer $line The line where the log occured - * @return void - */ - public static function logInfo($msg, $mod = null, $file = 0, $line = 0) { - $LOG = array('type' => 'INFO', - 'message' => (!is_null($msg) ? $msg : ""), - 'logFile' => (!is_null($file) ? $file : ""), - 'logLine' => (!is_null($line) ? $line : ""), - 'context' => (!is_null($mod) ? $mod : ""), - 'runtime' => round(self::getRelativeTime(), 4)); + /** + * Create a information log entry. + * + * @param string $msg The information to be logged + * @param string $mod The name of the module + * @param string $file The file where the log occured + * @param int $line The line where the log occured + */ + public static function logInfo($msg, $mod = null, $file = 0, $line = 0) + { + $LOG = array('type' => 'INFO', + 'message' => (!is_null($msg) ? $msg : ''), + 'logFile' => (!is_null($file) ? $file : ''), + 'logLine' => (!is_null($line) ? $line : ''), + 'context' => (!is_null($mod) ? $mod : ''), + 'runtime' => round(self::getRelativeTime(), 4), ); - self::$infoErrors[] = $LOG; - self::$Logs[] = $LOG; - } + self::$infoErrors[] = $LOG; + self::$Logs[] = $LOG; + } - /** - * Create a error log entry - * @param String $msg The information to be logged - * @param String $mod The name of the module - * @param String $file The file where the log occured - * @param integer $line The line where the log occured - * @return void - */ - public static function logError($msg, $mod = null, $file = 0, $line = 0) { - $LOG = array('type' => 'ERROR', - 'message' => (!is_null($msg) ? $msg : ""), - 'logFile' => (!is_null($file) ? $file : ""), - 'logLine' => (!is_null($line) ? $line : ""), - 'context' => (!is_null($mod) ? $mod : ""), - 'runtime' => round(self::getRelativeTime(), 4)); + /** + * Create a error log entry. + * + * @param string $msg The information to be logged + * @param string $mod The name of the module + * @param string $file The file where the log occured + * @param int $line The line where the log occured + */ + public static function logError($msg, $mod = null, $file = 0, $line = 0) + { + $LOG = array('type' => 'ERROR', + 'message' => (!is_null($msg) ? $msg : ''), + 'logFile' => (!is_null($file) ? $file : ''), + 'logLine' => (!is_null($line) ? $line : ''), + 'context' => (!is_null($mod) ? $mod : ''), + 'runtime' => round(self::getRelativeTime(), 4), ); - self::$criticalErrors[] = $LOG; - self::$Logs[] = $LOG; - } + self::$criticalErrors[] = $LOG; + self::$Logs[] = $LOG; + } - /** - * Create a warning log entry - * @param String $msg The information to be logged - * @param String $mod The name of the module - * @param String $file The file where the log occured - * @param integer $line The line where the log occured - * @return void - */ - public static function logWarning($msg, $mod = null, $file = 0, $line = 0) { - $LOG = array('type' => 'WARNING', - 'message' => (!is_null($msg) ? $msg : ""), - 'logFile' => (!is_null($file) ? $file : ""), - 'logLine' => (!is_null($line) ? $line : ""), - 'context' => (!is_null($mod) ? $mod : ""), - 'runtime' => round(self::getRelativeTime(), 4)); + /** + * Create a warning log entry. + * + * @param string $msg The information to be logged + * @param string $mod The name of the module + * @param string $file The file where the log occured + * @param int $line The line where the log occured + */ + public static function logWarning($msg, $mod = null, $file = 0, $line = 0) + { + $LOG = array('type' => 'WARNING', + 'message' => (!is_null($msg) ? $msg : ''), + 'logFile' => (!is_null($file) ? $file : ''), + 'logLine' => (!is_null($line) ? $line : ''), + 'context' => (!is_null($mod) ? $mod : ''), + 'runtime' => round(self::getRelativeTime(), 4), ); - self::$warningErrors[] = $LOG; - self::$Logs[] = $LOG; - } + self::$warningErrors[] = $LOG; + self::$Logs[] = $LOG; + } - /** - * Create a new Level log entry. Used to categorise logs - * @param String $msg The name of the new level - * @param String $mod The name of the module - * @param String $file The file where the log occured - * @param integer $line The line where the log occured - * @return void - */ - public static function newLevel($msg, $mod = null, $file = null, $line = null) { - $LOG = array('type' => 'LEVEL_START', - 'message' => (!is_null($msg) ? $msg : ""), - 'logFile' => (!is_null($file) ? $file : ""), - 'logLine' => (!is_null($line) ? $line : ""), - 'context' => (!is_null($mod) ? $mod : ""), - 'runtime' => round(self::getRelativeTime(), 4)); + /** + * Create a new Level log entry. Used to categorise logs. + * + * @param string $msg The name of the new level + * @param string $mod The name of the module + * @param string $file The file where the log occured + * @param int $line The line where the log occured + */ + public static function newLevel($msg, $mod = null, $file = null, $line = null) + { + $LOG = array('type' => 'LEVEL_START', + 'message' => (!is_null($msg) ? $msg : ''), + 'logFile' => (!is_null($file) ? $file : ''), + 'logLine' => (!is_null($line) ? $line : ''), + 'context' => (!is_null($mod) ? $mod : ''), + 'runtime' => round(self::getRelativeTime(), 4), ); - self::$Logs[] = $LOG; - } + self::$Logs[] = $LOG; + } - /** - * Create a stop Level log entry. Used to close log categories - * @param String $msg The name of the new level - * @param String $mod The name of the module - * @param String $file The file where the log occured - * @param integer $line The line where the log occured - * @return void - */ - public static function stopLevel($msg = null, $mod = null, $file = null, $line = null) { - $LOG = array('type' => 'LEVEL_STOP', - 'message' => (!is_null($msg) ? $msg : ""), - 'logFile' => (!is_null($file) ? $file : ""), - 'logLine' => (!is_null($line) ? $line : ""), - 'context' => (!is_null($mod) ? $mod : ""), - 'runtime' => round(self::getRelativeTime(), 4)); + /** + * Create a stop Level log entry. Used to close log categories. + * + * @param string $msg The name of the new level + * @param string $mod The name of the module + * @param string $file The file where the log occured + * @param int $line The line where the log occured + */ + public static function stopLevel($msg = null, $mod = null, $file = null, $line = null) + { + $LOG = array('type' => 'LEVEL_STOP', + 'message' => (!is_null($msg) ? $msg : ''), + 'logFile' => (!is_null($file) ? $file : ''), + 'logLine' => (!is_null($line) ? $line : ''), + 'context' => (!is_null($mod) ? $mod : ''), + 'runtime' => round(self::getRelativeTime(), 4), ); - self::$Logs[] = $LOG; - } + self::$Logs[] = $LOG; + } - /* =========================================OTHER METHODS==============================================================*/ + /* =========================================OTHER METHODS==============================================================*/ - /** - * Returns a string representation of an error - * Turns a PHP error-constant (or integer) into a string representation. - * - * @access public - * @param int $type PHP-constant errortype (e.g. E_NOTICE). - * @return string String representation - */ - public static function getType($type) { + /** + * Returns a string representation of an error + * Turns a PHP error-constant (or integer) into a string representation. + * + * @param int $type PHP-constant errortype (e.g. E_NOTICE). + * + * @return string String representation + */ + public static function getType($type) + { + switch ($type) { + case E_ERROR: + return 'ERROR'; + case E_WARNING: + return 'WARNING'; + case E_PARSE: + return 'ERROR'; + case E_NOTICE: + return 'WARNING'; + case E_CORE_ERROR: + return 'ERROR'; + case E_CORE_WARNING: + return 'WARNING'; + case E_COMPILE_ERROR: + return 'ERROR'; + case E_COMPILE_WARNING: + return 'WARNING'; + case E_USER_ERROR: + return 'ERROR'; + case E_USER_WARNING: + return 'WARNING'; + case E_USER_NOTICE: + return 'WARNING'; + case E_USER_DEPRECATED: + return 'WARNING'; + case E_STRICT: + return 'ERROR'; + case E_RECOVERABLE_ERROR: + return 'ERROR'; + case E_DEPRECATED: + return 'WARNING'; + } - switch ($type) - { - - case E_ERROR: - return "ERROR"; - case E_WARNING: - return "WARNING"; - case E_PARSE: - return "ERROR"; - case E_NOTICE: - return "WARNING"; - case E_CORE_ERROR: - return "ERROR"; - case E_CORE_WARNING: - return "WARNING"; - case E_COMPILE_ERROR: - return "ERROR"; - case E_COMPILE_WARNING: - return "WARNING"; - case E_USER_ERROR: - return "ERROR"; - case E_USER_WARNING: - return "WARNING"; - case E_USER_NOTICE: - return "WARNING"; - case E_USER_DEPRECATED: - return "WARNING"; - case E_STRICT: - return "ERROR"; - case E_RECOVERABLE_ERROR: - return "ERROR"; - case E_DEPRECATED: - return "WARNING"; - } - - return $type = 'Unknown error: '.$type; - } - - /** - * Calls an HTTP error, sends it as a header, and loads a template if required to do so. - * @param integer $errno HTTP error code - * @param boolean $view true to view error on website - */ - public static function http_error($errno = 500, $view = true){ + return $type = 'Unknown error: '.$type; + } + /** + * Calls an HTTP error, sends it as a header, and loads a template if required to do so. + * + * @param int $errno HTTP error code + * @param bool $view true to view error on website + */ + public static function http_error($errno = 500, $view = true) + { $http_codes = array( 400 => 'Bad Request', @@ -432,58 +447,59 @@ class Logger { 506 => 'Variant Also Negotiates', 509 => 'Bandwidth Limit Exceeded', 510 => 'Not Extended', - 511 => 'Network Authentication Required' + 511 => 'Network Authentication Required', ); self::logError('HTTP-error '.$errno.' called'); self::log('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno]); header('HTTP/1.1 '.$errno.' '.$http_codes[$errno]); - // Do we want the error-view with it? - if($view == false) - return; + // Do we want the error-view with it? + if ($view == false) { + return; + } - // Load the view + // Load the view $view = 'errors/'.$errno; self::log('Loading view '.$view); // Try and load the view, if impossible, load HTTP code instead. - try{ + try { Layout::view($view); - } catch(LayoutException $exception){ + } catch (LayoutException $exception) { // No error page could be found, just echo the result - echo "

$errno

".$http_codes[$errno]."

"; + echo "

$errno

".$http_codes[$errno].'

'; } } - /** - * Enable error to screen logging - * @access public - */ - public static function enable() { - self::$print_to_screen = true; - } + /** + * Enable error to screen logging. + */ + public static function enable() + { + self::$print_to_screen = true; + } - /** - * Disable error to screen logging - * @access public - */ - public static function disable() { - self::$print_to_screen = false; - } + /** + * Disable error to screen logging. + */ + public static function disable() + { + self::$print_to_screen = false; + } - /** - * Get the relative time since the framework started. - * - * Used for debugging timings in FuzeWorks - * @return int Time passed since FuzeWorks init - */ - private static function getRelativeTime() { - $startTime = STARTTIME; - $time = microtime(true) - $startTime; - return $time; - } + /** + * Get the relative time since the framework started. + * + * Used for debugging timings in FuzeWorks + * + * @return int Time passed since FuzeWorks init + */ + private static function getRelativeTime() + { + $startTime = STARTTIME; + $time = microtime(true) - $startTime; + + return $time; + } } - - -?> \ No newline at end of file diff --git a/Core/System/class.models.php b/Core/System/class.models.php index c39b76a..8dec952 100644 --- a/Core/System/class.models.php +++ b/Core/System/class.models.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; /** - * Models Class + * 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. - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Models { - +class Models +{ /** - * Array of all the loaded models + * Array of all the loaded models. + * * @var array */ private static $models_array = array(); /** - * Array of all the existing model types (classes) + * Array of all the existing model types (classes). + * * @var array */ private static $model_types = array(); /** * Load a model. - * @param String $name Name of the model - * @param String $directory Optional directory of the model - * @return Object The Model object. + * + * @param string $name Name of the model + * @param string $directory Optional directory of the model + * + * @return object The Model object. */ - public static function loadModel($name, $directory = null){ + public static function loadModel($name, $directory = null) + { // Model load event $event = Events::fireEvent('modelLoadEvent', $name, $directory); - $directory = ($event->directory === null ? "Application/Models" : $event->directory); - $name = ($event->model === null ? $name : $event->model); + $directory = ($event->directory === null ? 'Application/Models' : $event->directory); + $name = ($event->model === null ? $name : $event->model); $file = $directory.'/model.'.$name.'.php'; if (isset(self::$model_types[$name])) { Logger::log('Loading Model: '.get_class(self::$model_types[$name]), get_class(self::$model_types[$name])); self::$models_array[$name] = self::$model_types[$name]; - } elseif (file_exists($file)){ - require_once($file); - $model = "\Application\Model\\" . ucfirst($name); + } elseif (file_exists($file)) { + include_once $file; + $model = "\Application\Model\\".ucfirst($name); Logger::log('Loading Model: '.$model, $model); + return self::$models_array[$name] = new $model(); - } else{ + } else { throw new ModelException("The requested model: \''.$name.'\' could not be found", 1); } } /** - * Retrieve a model - * @param String $name Name of the model - * @return Object The Model object + * Retrieve a model. + * + * @param string $name Name of the model + * + * @return object The Model object */ - public static function get($name){ + public static function get($name) + { // Get the name $name = strtolower($name); // Check if it already exists - if (isset(self::$models_array[$name])) { + if (isset(self::$models_array[$name])) { // Return if it does - return self::$models_array[$name]; - } else { + return self::$models_array[$name]; + } else { // If not, load and return afterwards - return self::loadModel($name); - } + return self::loadModel($name); + } } } - -?> \ No newline at end of file diff --git a/Core/System/class.modules.php b/Core/System/class.modules.php index 9c43937..e566244 100644 --- a/Core/System/class.modules.php +++ b/Core/System/class.modules.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; -use \stdClass; + +use stdClass; /** - * Modules Class - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Modules Class. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Modules { - +class Modules +{ /** * A register of all the existing module headers. * * The module headers contain information required to loading the module - * @var Array + * + * @var array */ private static $register; /** - * A register which holds all the module advertisements by key + * A register which holds all the module advertisements by key. + * * @var array */ private static $advertiseRegister = array(); /** - * An array of all the loaded modules + * An array of all the loaded modules. + * * @var array */ public static $modules = array(); /** - * An array with the names of all modules that are loaded, and should not be loaded again - * @access private - * @var Array of module names + * An array with the names of all modules that are loaded, and should not be loaded again. + * + * @var array of module names */ private static $loaded_modules = array(); /** - * An array which holds the routes to module to load them quickly - * @access private + * An array which holds the routes to module to load them quickly. + * * @var array */ private static $module_routes = array(); /** * Retrieves a module and returns it. - * If a module is already loaded, it returns a reference to the loaded version - * @param String $name Name of the module + * If a module is already loaded, it returns a reference to the loaded version. + * + * @param string $name Name of the module + * * @return \FuzeWorks\Module Module The module + * * @throws \FuzeWorks\ModuleException */ - public static function get($name) { + public static function get($name) + { // Where the modules are - $path = "Modules/"; + $path = 'Modules/'; // Check if the requested module is registered if (isset(self::$register[$name])) { @@ -91,37 +101,40 @@ class Modules { $cfg = (object) self::$register[$name]; // Check if the module is disabled - if (isset($cfg->meta)) + if (isset($cfg->meta)) { throw new ModuleException("Could not load module. Module '".$name."' is not enabled", 1); + } // Check if the module is already loaded. If so, only return a reference, if not, load the module if (in_array(strtolower($name), self::$loaded_modules)) { // return the link $c = self::$modules[strtolower($cfg->module_name)]; + return $c; } else { // Load the module - $file = $cfg->directory ."/". $cfg->module_file; + $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++) { + for ($i = 0; $i < count($deps); ++$i) { self::get($deps[$i]); } // Check if the file exists if (file_exists($file)) { // And load it - require_once($file); + include_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 = "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 : ''); Logger::log($msg); } else { // Throw Exception if the file does not exist throw new ModuleException("Could not load module. Module '".$name."' class file was not found.", 1); + return false; } @@ -129,6 +142,7 @@ class Modules { if (isset($cfg->abstract)) { if ($cfg->abstract) { $CLASS = new stdClass(); + return self::$modules[strtolower($cfg->module_name)] = &$CLASS; } } @@ -142,11 +156,13 @@ class Modules { $CLASS::setModulePath($cfg->directory); } - if (method_exists($CLASS, 'setModuleLinkName')) + if (method_exists($CLASS, 'setModuleLinkName')) { $CLASS::setModuleLinkName(strtolower($cfg->module_name)); + } - if (method_exists($CLASS, 'setModuleName')) + if (method_exists($CLASS, 'setModuleName')) { $CLASS::setModuleName($name); + } // Send all advertisements if (isset($cfg->listenFor)) { @@ -165,8 +181,8 @@ class Modules { // Send the moduleConfig if possible if (method_exists($CLASS, 'setModuleConfig')) { // Append the config file to the module CFG (accessable through $this->cfg) - if (file_exists($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php")) { - $data = (object) include($cfg->directory . "/" . "config.".strtolower($cfg->module_name).".php"); + if (file_exists($cfg->directory.'/'.'config.'.strtolower($cfg->module_name).'.php')) { + $data = (object) include $cfg->directory.'/'.'config.'.strtolower($cfg->module_name).'.php'; foreach ($data as $key => $value) { $cfg->$key = $value; } @@ -176,8 +192,9 @@ class Modules { } // And finally check if it can be loaded - if (!method_exists($CLASS, 'onLoad')) + if (!method_exists($CLASS, 'onLoad')) { throw new ModuleException("Could not load module. Module '".$name."' does not have an onLoad() method", 1); + } // Prepare onLoad call $args = func_get_args(); @@ -201,14 +218,16 @@ class Modules { } /** - * Set the value of a module config or moduleInfo.php - * @param String $file File to edit - * @param String $key Key to edit - * @param Mixed $value Value to set + * Set the value of a module config or moduleInfo.php. + * + * @param string $file File to edit + * @param string $key Key to edit + * @param mixed $value Value to set */ - private static function setModuleValue($file, $key, $value) { + private static function setModuleValue($file, $key, $value) + { if (file_exists($file) && is_writable($file)) { - $cfg = require($file); + $cfg = include $file; $cfg[$key] = $value; $config = var_export($cfg, true); file_put_contents($file, "directory = $directory; // Define the module name - $name = ""; - $name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : ""); + $name = ''; + $name .= (!empty($cfg->author) ? strtolower($cfg->author).'/' : ''); $name .= strtolower($cfg->module_name); Logger::log("Adding module: '".$name."'"); if (isset(self::$register[$name])) { Logger::logError("Module '".$name."' can not be added. Module is already loaded"); + return false; } @@ -251,7 +273,7 @@ class Modules { $cfg2->module_name = $cfg->module_name; $cfg2->directory = $cfg->directory; $cfg2->meta = $cfg; - self::$register[$name] = (array)$cfg2; + self::$register[$name] = (array) $cfg2; Logger::log("[OFF] '".$name."'"); } } else { @@ -265,14 +287,15 @@ class Modules { } /** - * Enables a module when it is disabled + * Enables a module when it is disabled. + * + * @param string Module name + * @param bool true for permanent enable * - * @access public - * @param String Module name - * @param boolean true for permanent enable * @throws FuzeWorks\ModuleException */ - public static function enableModule($name, $permanent = true) { + public static function enableModule($name, $permanent = true) + { if (isset(self::$register[$name])) { // Change the register $info = (object) self::$register[$name]; @@ -281,6 +304,7 @@ class Modules { if (isset($info->enabled)) { if ($info->enabled) { Logger::logWarning("Could not enable module '".$name."'. Module is already enabled."); + return false; } } @@ -288,13 +312,13 @@ class Modules { // Otherwise move data from meta to the module config $info = $info->meta; $info->enabled = true; - self::$register[$name] = (array)$info; + self::$register[$name] = (array) $info; Logger::log("Enabled module '".$name."'"); // Enable it permanently if so desired if ($permanent) { - $file = $info->directory . "/moduleInfo.php"; + $file = $info->directory.'/moduleInfo.php'; self::setModuleValue($file, 'enabled', true); } @@ -306,20 +330,22 @@ class Modules { } /** - * Disableds a module when it is enabled + * Disableds a module when it is enabled. + * + * @param string Module name + * @param bool true for permanent disable * - * @access public - * @param String Module name - * @param boolean true for permanent disable * @throws FuzeWorks\ModuleException */ - public static function disableModule($name, $permanent = true) { + public static function disableModule($name, $permanent = true) + { if (isset(self::$register[$name])) { $info = (object) self::$register[$name]; // Do nothing if it is already disabled if (isset($info->meta)) { Logger::logWarning("Could not disable module '".$name."'. Module is already disabled."); + return false; } @@ -328,10 +354,10 @@ class Modules { $disabled->directory = $info->directory; $disabled->module_name = $info->module_name; - self::$register[$name] = (array)$disabled; + self::$register[$name] = (array) $disabled; Logger::log("Disabled module '".$name."'"); if ($permanent) { - $file = $info->directory . "/moduleInfo.php"; + $file = $info->directory.'/moduleInfo.php'; self::setModuleValue($file, 'enabled', false); } @@ -343,20 +369,19 @@ class Modules { } else { throw new ModuleException("Could not disable module '".$name."'. Module does not exist.", 1); } - } /** * Create a register with all the module headers from all the existing modules. * * Used to correctly load all modules - * @return void */ - public static function buildRegister() { - Logger::newLevel("Loading Module Headers", 'Core'); + public static function buildRegister() + { + Logger::newLevel('Loading Module Headers', 'Core'); // Get all the module directories - $dir = "Modules/"; + $dir = 'Modules/'; $mod_dirs = array(); $mod_dirs = array_values(array_diff(scandir($dir), array('..', '.'))); @@ -365,19 +390,19 @@ class Modules { $event_register = array(); // Cycle through all module directories - for ($i=0; $i < count($mod_dirs); $i++) { - $mod_dir = $dir . $mod_dirs[$i] . "/"; + 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")) { + if (file_exists($mod_dir.'/moduleInfo.php')) { // Load the configuration file - $cfg = (object) require($mod_dir . "/moduleInfo.php"); + $cfg = (object) include $mod_dir.'/moduleInfo.php'; // Set enabled for now $enabled = true; // Define the module name - $name = ""; - $name .= (!empty($cfg->author) ? strtolower($cfg->author)."/" : ""); + $name = ''; + $name .= (!empty($cfg->author) ? strtolower($cfg->author).'/' : ''); $name .= strtolower($cfg->module_name); // Get the module directory @@ -405,10 +430,11 @@ class Modules { $register[$name] = (array) $cfg; // Log the name for enabled and disabled - if (!$enabled) + if (!$enabled) { Logger::newLevel("[OFF] '".$name."'"); - else + } else { Logger::newLevel("[ON] '".$name."'"); + } // And possibly some aliases if (isset($cfg->aliases)) { @@ -441,10 +467,11 @@ class Modules { // Get the events and add them foreach ($cfg->events as $event) { // First check if the event already exists, if so, append it - if (isset($event_register[$event])) + if (isset($event_register[$event])) { $event_register[$event][] = $name; - else + } else { $event_register[$event] = array($name); + } // Log the event Logger::Log('Event added: \''.$event.'\''); @@ -456,7 +483,7 @@ class Modules { // Cycle through advertisements foreach ($cfg->advertise as $advertiseName => $advertiseData) { // Log advertisement - Logger::log('Advertisement added: \'' .$advertiseName. '\''); + Logger::log('Advertisement added: \''.$advertiseName.'\''); // Add to advertiseRegister self::$advertiseRegister[$advertiseName][$name] = $advertiseData; @@ -464,7 +491,6 @@ class Modules { } Logger::stopLevel(); - } else { // If no details are specified, create a basic mock module $name = $mod_dirs[$i]; @@ -472,14 +498,14 @@ class Modules { // Build a default mock module config $mock = new stdClass(); $mock->module_class = ucfirst($name); - $mock->module_file = 'class.'.strtolower($name).".php"; + $mock->module_file = 'class.'.strtolower($name).'.php'; $mock->module_name = $name; $mock->dependencies = array(); $mock->versions = array(); $mock->directory = $mod_dir; // Apply it - $register[$name] = (array)$mock; + $register[$name] = (array) $mock; Logger::newLevel("[ON] '".$name."'"); Logger::stopLevel(); } @@ -489,19 +515,18 @@ class Modules { self::$register = $register; Events::$register = $event_register; Logger::stopLevel(); - } - /** - * The Module Callable + /** + * The Module Callable. * * When a module listens for a specific routing path, this callable get's called. * After this the module can handle the request with the route() function in the module's root directory - * @access public - * @param array Regex matches - * @return void + * + * @param array Regex matches */ - public static function moduleCallable($matches = array()){ + public static function moduleCallable($matches = array()) + { // First detect what module is attached to this route Logger::newLevel('Module callable called!'); @@ -517,13 +542,11 @@ class Modules { unset($matches['route']); $mod->route($matches); } else { - Logger::logError("Route did not match known module. Fatal error"); + Logger::logError('Route did not match known module. Fatal error'); + return Logger::http_error(500); } Logger::stopLevel(); } - } - -?> \ No newline at end of file diff --git a/Core/System/class.router.php b/Core/System/class.router.php index 9457ab5..bec7f04 100644 --- a/Core/System/class.router.php +++ b/Core/System/class.router.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace FuzeWorks; -use \Application\Init; + +use Application\Init; /** - * Class Router + * Class Router. * * This class handles the framework's routing. The router determines which system should be loaded and called. * The overall structure of the routing is as follows: @@ -75,42 +78,39 @@ use \Application\Init; * @see Router::setPath * @see Router::route * - * @package net.techfuze.fuzeworks.core - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Router { - +class Router +{ /** * @var null|string The provided path */ - private static $path = null; + private static $path = null; /** * @var array Routes */ - private static $routes = array(); + private static $routes = array(); /** * @var null|mixed The callable */ - private static $callable = null; + private static $callable = null; /** * @var null|array The extracted matches from the regex */ - private static $matches = null; + private static $matches = null; /** - * The constructor adds the default route to the routing table + * The constructor adds the default route to the routing table. */ - public static function init(){ - - foreach(Config::get('routes') as $route => $callable){ - - if(is_int($route)) { - - $route = $callable; + public static function init() + { + foreach (Config::get('routes') as $route => $callable) { + if (is_int($route)) { + $route = $callable; $callable = array('\FuzeWorks\Router', 'defaultCallable'); } @@ -119,56 +119,60 @@ class Router { } /** - * Returns the current routing path + * Returns the current routing path. * * @return bool|string */ - public static function getPath(){ - + public static function getPath() + { return self::$path; } /** - * Returns an array with all the routes + * Returns an array with all the routes. + * * @return array */ - public static function getRoutes(){ - + public static function getRoutes() + { return self::$routes; } /** - * Returns the currently loaded callable + * Returns the currently loaded callable. + * * @return null|callable */ - public static function getCallable(){ - + public static function getCallable() + { return self::$callable; } /** - * Returns all the matches with the RegEx route + * Returns all the matches with the RegEx route. + * * @return null|array */ - public static function getMatches() { - + public static function getMatches() + { return self::$matches; } /** - * Set the current routing path + * Set the current routing path. * * @param string $path The routing path (e.g. a/b/c/d/e) + * * @return bool|string */ - public static function setPath($path){ + public static function setPath($path) + { // Fire the event to notify our modules $event = Events::fireEvent('routerSetPathEvent', $path); // The event has been cancelled - if($event->isCancelled()){ - + if ($event->isCancelled()) { return false; } @@ -176,18 +180,20 @@ class Router { $path = preg_replace('@[/]+@', '/', $event->path); // Remove first slash - if(substr($path, 0, 1) == '/') + if (substr($path, 0, 1) == '/') { $path = substr($path, 1); + } // Remove trailing slash - if(substr($path, -1, 1) == '/') - $path = substr($path, 0, strlen($path)-1); + if (substr($path, -1, 1) == '/') { + $path = substr($path, 0, strlen($path) - 1); + } return self::$path = $path; } /** - * Add a route + * Add a route. * * The path will be checked before custom routes before the default route(/controller/function/param1/param2/etc) * When the given RegEx matches the current routing-path, the callable will be called. @@ -227,27 +233,28 @@ class Router { * You do not *have* to use named groups, but when you don't the arguments will be left NULL; and you will need to * extract the information from the routing-path yourself. * - * @param string $route This is a RegEx of the route, Every capture group will be a parameter + * @param string $route This is a RegEx of the route, Every capture group will be a parameter * @param callable $callable The callable to execute - * @param bool $prepend Whether or not to insert at the beginning of the routing table + * @param bool $prepend Whether or not to insert at the beginning of the routing table */ - public static function addRoute($route, $callable, $prepend = true){ - - if($prepend) + public static function addRoute($route, $callable, $prepend = true) + { + if ($prepend) { self::$routes = array($route => $callable) + self::$routes; - else + } else { self::$routes[$route] = $callable; + } Logger::log('Route added at '.($prepend ? 'top' : 'bottom').': "'.$route.'"'); } /** - * Removes a route from the array based on the given route + * Removes a route from the array based on the given route. * * @param $route string The route to remove */ - public static function removeRoute($route){ - + public static function removeRoute($route) + { unset(self::$routes[$route]); Logger::log('Route removed: '.$route); @@ -258,7 +265,7 @@ class Router { * * Determines what callable should be loaded and what data matches the route regex. * - * @param boolean $loadCallable Immediate load the callable when it's route matches + * @param bool $loadCallable Immediate load the callable when it's route matches */ public static function route($loadCallable = true) { @@ -266,8 +273,7 @@ class Router { $event = Events::fireEvent('routerRouteEvent', self::$routes, $loadCallable, self::$path); // The event has been cancelled - if($event->isCancelled()){ - + if ($event->isCancelled()) { return; } @@ -277,25 +283,25 @@ class Router { //Check the custom routes foreach ($routes as $r => $c) { - //A custom route is found - if(preg_match($r, $event->path, $matches)) { + if (preg_match($r, $event->path, $matches)) { Logger::log('Route matched: '.$r); // Add the matches to the current class self::$matches = $matches; - self::$callable = $c; - if(!$loadCallable || !self::loadCallable($matches, $r)) + self::$callable = $c; + if (!$loadCallable || !self::loadCallable($matches, $r)) { break; + } } } // Check if we found a callable anyway - if(self::$callable === null){ - + if (self::$callable === null) { Logger::log('No routes found for given path: "'.$event->path.'"', E_WARNING); Logger::http_error(404); + return; } } @@ -307,84 +313,88 @@ class Router { * * Then the arguments get prepared and finally the callable is called. * - * @param array Preg matches with the routing path - * @param string The route that matched - * @return boolean Whether or not the callable was satisfied + * @param array Preg matches with the routing path + * @param string The route that matched + * + * @return bool Whether or not the callable was satisfied */ - public static function loadCallable($matches = array(), $route){ - + public static function loadCallable($matches = array(), $route) + { Logger::newLevel('Loading callable'); // Fire the event to notify our modules $event = Events::fireEvent('routerLoadCallableEvent', self::$callable, $matches, $route); // The event has been cancelled - if($event->isCancelled()) + if ($event->isCancelled()) { return false; + } // Prepare the arguments and add the route $args = $event->matches; $args['route'] = $event->route; - if(!is_callable($event->callable)) - if(isset(self::$callable['controller'])) { + if (!is_callable($event->callable)) { + if (isset(self::$callable['controller'])) { + // Reset the arguments and fetch from custom callable + $args = array(); + $args['controller'] = isset(self::$callable['controller']) ? self::$callable['controller'] : (isset($matches['controller']) ? $matches['controller'] : null); + $args['function'] = isset(self::$callable['function']) ? self::$callable['function'] : (isset($matches['function']) ? $matches['function'] : null); + $args['parameters'] = isset(self::$callable['parameters']) ? self::$callable['parameters'] : (isset($matches['parameters']) ? explode('/', $matches['parameters']) : null); - // Reset the arguments and fetch from custom callable - $args = array(); - $args['controller'] = isset(self::$callable['controller']) ? self::$callable['controller'] : (isset($matches['controller']) ? $matches['controller'] : null); - $args['function'] = isset(self::$callable['function']) ? self::$callable['function'] : (isset($matches['function']) ? $matches['function'] : null); - $args['parameters'] = isset(self::$callable['parameters']) ? self::$callable['parameters'] : (isset($matches['parameters']) ? explode('/', $matches['parameters']) : null); + self::$callable = array('\FuzeWorks\Router', 'defaultCallable'); + } else { + Logger::log('The given callable is not callable!', E_ERROR); + Logger::http_error(500); + Logger::stopLevel(); - self::$callable = array('\FuzeWorks\Router', 'defaultCallable'); - }else{ - - Logger::log('The given callable is not callable!', E_ERROR); - Logger::http_error(500); - Logger::stopLevel(); - return true; + return true; + } } // And log the input to the logger Logger::newLevel('Calling callable'); foreach ($args as $key => $value) { - Logger::log($key.": ".var_export($value,true).""); + Logger::log($key.': '.var_export($value, true).''); } Logger::stopLevel(); $skip = call_user_func_array(self::$callable, array($args)) === false; - if($skip) + if ($skip) { Logger::log('Callable not satisfied, skipping to next callable'); + } Logger::stopLevel(); + return $skip; } /** - * The default callable + * The default callable. * * This callable will do the 'old skool' routing. It will load the controllers from the controller-directory * in the application-directory. */ - public static function defaultCallable($arguments = array()){ - + public static function defaultCallable($arguments = array()) + { Logger::log('Default callable called!'); $controller = empty($arguments['controller']) ? Config::get('main')->default_controller : $arguments['controller']; - $function = empty($arguments['function']) ? Config::get('main')->default_function : $arguments['function']; + $function = empty($arguments['function']) ? Config::get('main')->default_function : $arguments['function']; $parameters = empty($arguments['parameters']) ? null : $arguments['parameters']; // Construct file paths and classes - $class = '\Application\Controller\\'.ucfirst($controller); - $file = 'Application/Controller/controller.'.$controller.'.php'; + $class = '\Application\Controller\\'.ucfirst($controller); + $file = 'Application/Controller/controller.'.$controller.'.php'; Logger::log('Loading controller '.$class.' from file: '.$file); // Check if the file exists - if(file_exists($file)){ - - if(!class_exists($class)) - require $file; + if (file_exists($file)) { + if (!class_exists($class)) { + include $file; + } // Get the path the controller should know about $path = substr(self::getPath(), ($pos = strpos(self::getPath(), '/')) !== false ? $pos + 1 : 0); @@ -398,22 +408,18 @@ class Router { } // Check if method exists or if there is a caller function - if(method_exists(self::$callable, $function) || method_exists(self::$callable, '__call')){ - + if (method_exists(self::$callable, $function) || method_exists(self::$callable, '__call')) { // Execute the function on the controller echo self::$callable->{$function}($parameters); - }else{ - + } else { // Function could not be found Logger::log('Could not find function '.$function.' on controller '.$class); Logger::http_error(404); } - }else{ - + } else { // Controller could not be found Logger::log('Could not find controller '.$class); Logger::http_error(404); } } } -?> \ No newline at end of file diff --git a/Modules/admin/class.main.php b/Modules/admin/class.main.php index fb7fad9..b74de04 100644 --- a/Modules/admin/class.main.php +++ b/Modules/admin/class.main.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -use \FuzeWorks\Module; + +use FuzeWorks\Module; /** - * Admin Module + * Admin Module. * * Admin panel module controller - * @package net.techfuze.fuzeworks.admin - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class Main { - use Module; +class Main +{ + use Module; - /** - * Loads the module and registers the events - * - * @access public - */ - public function onLoad() { - require_once(self::getModulePath() . "/classes/class.layout_manager.php"); - require_once(self::getModulePath() . "/classes/class.admin_exception.php"); - require_once(self::getModulePath() . "/classes/class.theme_manager.php"); - require_once(self::getModulePath() . "/classes/class.advertise_fetcher.php"); - require_once(self::getModulePath() . "/classes/class.page_loader.php"); - require_once(self::getModulePath() . "/classes/class.page_data.php"); - require_once(self::getModulePath() . "/classes/class.page.php"); - require_once(self::getModulePath() . "/classes/class.page_list.php"); - require_once(self::getModulePath() . "/classes/class.page_router_interface.php"); - require_once(self::getModulePath() . "/classes/class.page_interface.php"); - require_once(self::getModulePath() . "/classes/class.admin_router.php"); - } + /** + * Loads the module and registers the events. + */ + public function onLoad() + { + include_once self::getModulePath().'/classes/class.layout_manager.php'; + include_once self::getModulePath().'/classes/class.admin_exception.php'; + include_once self::getModulePath().'/classes/class.theme_manager.php'; + include_once self::getModulePath().'/classes/class.advertise_fetcher.php'; + include_once self::getModulePath().'/classes/class.page_loader.php'; + include_once self::getModulePath().'/classes/class.page_data.php'; + include_once self::getModulePath().'/classes/class.page.php'; + include_once self::getModulePath().'/classes/class.page_list.php'; + include_once self::getModulePath().'/classes/class.page_router_interface.php'; + include_once self::getModulePath().'/classes/class.page_interface.php'; + include_once self::getModulePath().'/classes/class.admin_router.php'; + } - /** - * Gets called when the path matches the regex of this module. - * @access public - * @param array Regex matches - * @return void - */ - public function route($matches = array()) { - // First create a pageList based on the advertisements - $advertisements = self::getAdvertisements('admin'); - if (!is_array($advertisements)) - throw new AdminException("Could not load advertised modules. Malformed object retrieved", 1); + /** + * Gets called when the path matches the regex of this module. + * + * @param array Regex matches + */ + public function route($matches = array()) + { + // First create a pageList based on the advertisements + $advertisements = self::getAdvertisements('admin'); + if (!is_array($advertisements)) { + throw new AdminException('Could not load advertised modules. Malformed object retrieved', 1); + } - $pageList = AdvertiseFetcher::getPageList($advertisements); + $pageList = AdvertiseFetcher::getPageList($advertisements); - // After that, load the authenticator and check if user is logged in - // @TODO IMPLEMENT + // After that, load the authenticator and check if user is logged in + // @TODO IMPLEMENT - // After that, load the theme that is set - LayoutManager::setPageList($pageList); - LayoutManager::setMatches($matches); - $html = LayoutManager::loadPanel(); + // After that, load the theme that is set + LayoutManager::setPageList($pageList); + LayoutManager::setMatches($matches); + $html = LayoutManager::loadPanel(); - // And print it - echo $html; - } - - public function getAdminRouter() { - return new AdminRouter(); - } + // And print it + echo $html; + } + public function getAdminRouter() + { + return new AdminRouter(); + } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.admin_exception.php b/Modules/admin/classes/class.admin_exception.php index 778ad79..bd97d75 100644 --- a/Modules/admin/classes/class.admin_exception.php +++ b/Modules/admin/classes/class.admin_exception.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; /** - * Class Exception - * @package net.techfuze.fuzeworks.admin - * @author Abel Hoogeveen - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) + * Class Exception. + * + * @author Abel Hoogeveen + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ -class AdminException extends \Exception{} - -?> \ No newline at end of file +class AdminException extends \Exception +{ +} diff --git a/Modules/admin/classes/class.admin_router.php b/Modules/admin/classes/class.admin_router.php index e1e8639..621cfe4 100644 --- a/Modules/admin/classes/class.admin_router.php +++ b/Modules/admin/classes/class.admin_router.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -class AdminRouter implements PageRouterInterface { +class AdminRouter implements PageRouterInterface +{ + private $pageObject; - private $pageObject; + public function route() + { + //echo $pagePath; + } - public function route() { - //echo $pagePath; - } - - /** - * Import the page object from the Admin Module - * @param Page $pageObject Page object - * @return void - */ - public function importPage($pageObject) { - $this->pageObject = $pageObject; - } - - public function getPage() { - return $this->pageObject; - } + /** + * Import the page object from the Admin Module. + * + * @param Page $pageObject Page object + */ + public function importPage($pageObject) + { + $this->pageObject = $pageObject; + } + public function getPage() + { + return $this->pageObject; + } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.advertise_fetcher.php b/Modules/admin/classes/class.advertise_fetcher.php index ff30a0a..fd72a1d 100644 --- a/Modules/admin/classes/class.advertise_fetcher.php +++ b/Modules/admin/classes/class.advertise_fetcher.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -use \FuzeWorks\Logger; -class AdvertiseFetcher { +use FuzeWorks\Logger; - /** - * Create a pageList using the advertisements from the admin module - * @param array $advertisements The advertisement repository - * @throws AdminException On fatal and/or missing data - * @return PageList An object oriented page list with details - * @todo Implement Unit Test - */ - public static function getPageList($advertisements) { - // Prepare a pageList - Logger::newLevel('Generating PageList'); - $pageList = new PageList(); +class AdvertiseFetcher +{ + /** + * Create a pageList using the advertisements from the admin module. + * + * @param array $advertisements The advertisement repository + * + * @throws AdminException On fatal and/or missing data + * + * @return PageList An object oriented page list with details + * + * @todo Implement Unit Test + */ + public static function getPageList($advertisements) + { + // Prepare a pageList + Logger::newLevel('Generating PageList'); + $pageList = new PageList(); - // First get the modules - foreach ($advertisements as $module => $data) { - // Apple regular data - $identifier = (isset($data['identifier']) ? $data['identifier'] : null); - $pages = (isset($data['pages']) ? $data['pages'] : null); + // First get the modules + foreach ($advertisements as $module => $data) { + // Apple regular data + $identifier = (isset($data['identifier']) ? $data['identifier'] : null); + $pages = (isset($data['pages']) ? $data['pages'] : null); - // Check if everything is set, if not shout out in terror - if (is_null($identifier) || is_null($pages)) - throw new AdminException("Incomplete data for module '".$module."'", 1); + // Check if everything is set, if not shout out in terror + if (is_null($identifier) || is_null($pages)) { + throw new AdminException("Incomplete data for module '".$module."'", 1); + } - // And then the pages - foreach ($pages as $pageData) { - // Create page variable and add module and identifier - $page = new PageData(); - $page->setModule($module); - $page->setIdentifier($identifier); + // And then the pages + foreach ($pages as $pageData) { + // Create page variable and add module and identifier + $page = new PageData(); + $page->setModule($module); + $page->setIdentifier($identifier); - // First the required data for every page - $page_path = (isset($pageData['page_path']) ? $pageData['page_path'] : null); - $name = (isset($pageData['name']) ? $pageData['name'] : null); + // First the required data for every page + $page_path = (isset($pageData['page_path']) ? $pageData['page_path'] : null); + $name = (isset($pageData['name']) ? $pageData['name'] : null); - // And throw errors if non-existent - if (is_null($page_path) || is_null($name)) - throw new AdminException("Incomplete data for module '".$module."'", 1); + // And throw errors if non-existent + if (is_null($page_path) || is_null($name)) { + throw new AdminException("Incomplete data for module '".$module."'", 1); + } - // And set those values - $page->setPagePath($page_path); - $page->setName($name); - $unique_identifier = $identifier . "/" . $page_path; - Logger::log("Adding page '".$name."' on '".$unique_identifier."'"); + // And set those values + $page->setPagePath($page_path); + $page->setName($name); + $unique_identifier = $identifier.'/'.$page_path; + Logger::log("Adding page '".$name."' on '".$unique_identifier."'"); + // And at last for the optional values + $page->setIcon((isset($pageData['icon']) ? $pageData['icon'] : '')); + $page->setPermissionGroups((isset($pageData['permissionGroups']) ? $pageData['permissionGroups'] : array())); + $page->setPriority((isset($pageData['priority']) ? $pageData['priority'] : 1)); + // And finally add the page + $pageList->addPage($page, $unique_identifier); + } + } - // And at last for the optional values - $page->setIcon( (isset($pageData['icon']) ? $pageData['icon'] : '') ); - $page->setPermissionGroups( (isset($pageData['permissionGroups']) ? $pageData['permissionGroups'] : array()) ); - $page->setPriority( (isset($pageData['priority']) ? $pageData['priority'] : 1) ); + // And finally return the pageList\ + Logger::stopLevel(); - // And finally add the page - $pageList->addPage($page, $unique_identifier); - } - } - - // And finally return the pageList\ - Logger::stopLevel(); - return $pageList; - } + return $pageList; + } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.layout_manager.php b/Modules/admin/classes/class.layout_manager.php index 44f70ea..715ec33 100644 --- a/Modules/admin/classes/class.layout_manager.php +++ b/Modules/admin/classes/class.layout_manager.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -use \FuzeWorks\Layout; -use \FuzeWorks\Config; -class LayoutManager { +use FuzeWorks\Layout; +use FuzeWorks\Config; - private static $pageList; - private static $matches; +class LayoutManager +{ + private static $pageList; + private static $matches; - /** - * Load the panel of this admin interface - * @throws AdminException - * @return string HTML - */ - public static function loadPanel() { - // First check if the pageList is set and valid - if (is_null(self::$pageList)) - throw new AdminException("Can not load panel. PageList is not set", 1); + /** + * Load the panel of this admin interface. + * + * @throws AdminException + * + * @return string HTML + */ + public static function loadPanel() + { + // First check if the pageList is set and valid + if (is_null(self::$pageList)) { + throw new AdminException('Can not load panel. PageList is not set', 1); + } - // Load the theme - ThemeManager::loadTheme(); + // Load the theme + ThemeManager::loadTheme(); - // Set the PageLoader variables - PageLoader::setPageList(self::$pageList); + // Set the PageLoader variables + PageLoader::setPageList(self::$pageList); - // Get the page we are trying to load - PageLoader::loadPage(self::$matches); - $html = PageLoader::getHtml(); - $activePage = PageLoader::getActivePage(); + // Get the page we are trying to load + PageLoader::loadPage(self::$matches); + $html = PageLoader::getHtml(); + $activePage = PageLoader::getActivePage(); - // And add the pageList - Layout::assign('pageList', self::$pageList); - Layout::assign('activePage', $activePage); - Layout::assign('pageHTML', $html); + // And add the pageList + Layout::assign('pageList', self::$pageList); + Layout::assign('activePage', $activePage); + Layout::assign('pageHTML', $html); - // And add more basic variables - foreach (self::getVariables() as $key => $value) { - Layout::assign($key, $value); - } + // And add more basic variables + foreach (self::getVariables() as $key => $value) { + Layout::assign($key, $value); + } - // And load the file - return Layout::get('panel'); - } + // And load the file + return Layout::get('panel'); + } - public static function loadPanelAPI() { + public static function loadPanelAPI() + { + } - } + public static function loadLogin() + { + } - public static function loadLogin() { + public static function loadLoginAPI() + { + } - } + /** + * Set the pageList. + * + * @param PageList $pageList PageList + */ + public static function setPageList($pageList) + { + self::$pageList = $pageList; + } - public static function loadLoginAPI() { + public static function setMatches($matches) + { + self::$matches = $matches; + } - } - - /** - * Set the pageList - * @param PageList $pageList PageList - */ - public static function setPageList($pageList) { - self::$pageList = $pageList; - } - - public static function setMatches($matches) { - self::$matches = $matches; - } - - /** - * Get all the basic variables required for every template - * @return array with settings - */ - private static function getVariables() { - $vars = array(); - $vars['adminURL'] = Config::get('main')->SITE_URL . "admin/"; - return $vars; - } + /** + * Get all the basic variables required for every template. + * + * @return array with settings + */ + private static function getVariables() + { + $vars = array(); + $vars['adminURL'] = Config::get('main')->SITE_URL.'admin/'; + return $vars; + } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.page.php b/Modules/admin/classes/class.page.php index 1015400..c548abe 100644 --- a/Modules/admin/classes/class.page.php +++ b/Modules/admin/classes/class.page.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -class Page { - - private $pagePath; - private $subPath = array(); - private $html; - private $title; - private $breadcrumbs = array(); +class Page +{ + private $pagePath; + private $subPath = array(); + private $html; + private $title; + private $breadcrumbs = array(); /** * Gets the value of pagePath. @@ -158,5 +160,3 @@ class Page { return $this; } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.page_data.php b/Modules/admin/classes/class.page_data.php index 31ab932..31b6f08 100644 --- a/Modules/admin/classes/class.page_data.php +++ b/Modules/admin/classes/class.page_data.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -class PageData { - - public $module; - public $identifier; - public $page_path; - public $icon; - public $permissionGroups = array(); - public $name; - public $priority; +class PageData +{ + public $module; + public $identifier; + public $page_path; + public $icon; + public $permissionGroups = array(); + public $name; + public $priority; /** * Gets the value of module. @@ -208,5 +210,3 @@ class PageData { return $this; } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.page_list.php b/Modules/admin/classes/class.page_list.php index eaf995f..2e719cc 100644 --- a/Modules/admin/classes/class.page_list.php +++ b/Modules/admin/classes/class.page_list.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -class PageList { - - public $pages = array(); +class PageList +{ + public $pages = array(); /** * Gets the value of pages. @@ -45,23 +47,24 @@ class PageList { } /** - * Retrieve a page - * @param string $unique_identifier Unique name for the page - * @return PageData PageData Object + * Retrieve a page. + * + * @param string $unique_identifier Unique name for the page + * + * @return PageData PageData Object */ - public function getPage($unique_identifier) { + public function getPage($unique_identifier) + { return $this->pages[$unique_identifier]; } /** - * Add a page to the array - * @param PageData $page PageData Object + * Add a page to the array. * - * @return void + * @param PageData $page PageData Object */ - public function addPage($page, $unique_identifier) { - $this->pages[$unique_identifier] = $page; + public function addPage($page, $unique_identifier) + { + $this->pages[$unique_identifier] = $page; } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.page_loader.php b/Modules/admin/classes/class.page_loader.php index aadec1e..7b6aafa 100644 --- a/Modules/admin/classes/class.page_loader.php +++ b/Modules/admin/classes/class.page_loader.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -use \FuzeWorks\Logger; -use \FuzeWorks\Layout; -use \FuzeWorks\Modules; -class PageLoader { +use FuzeWorks\Logger; +use FuzeWorks\Layout; +use FuzeWorks\Modules; - private static $pageList; - private static $activePage; - private static $html; - private static $breadcrumbs = array(); - private static $title; +class PageLoader +{ + private static $pageList; + private static $activePage; + private static $html; + private static $breadcrumbs = array(); + private static $title; - /** - * Set the pageList - * @param PageList $pageList PageList - */ - public static function setPageList($pageList) { - self::$pageList = $pageList; - } + /** + * Set the pageList. + * + * @param PageList $pageList PageList + */ + public static function setPageList($pageList) + { + self::$pageList = $pageList; + } - public static function loadPage($matches) { - // First check if any data is given at all - Logger::newLevel("Retrieving page from module"); - if (!isset($matches['identifier']) && !isset($matches['page'])) { - // If nothing is provided, load the dashboard - Logger::log("No input retrieved. Loading dashboard"); - return self::dashboard(); - } elseif (!isset($matches['identifier']) || !isset($matches['page'])) { - // If incomplete data is provided, load a 404 - Logger::log("Invalid input retrieved. Loading 404 not found page"); - return self::error404(); - } + public static function loadPage($matches) + { + // First check if any data is given at all + Logger::newLevel('Retrieving page from module'); + if (!isset($matches['identifier']) && !isset($matches['page'])) { + // If nothing is provided, load the dashboard + Logger::log('No input retrieved. Loading dashboard'); - // If enough data is provided, try and load a page - Logger::log("Input received. Attempting to find page"); - $unique_identifier = $matches['identifier'] . '/' . $matches['page']; - if (isset(self::$pageList->pages[$unique_identifier])) { - // Page found, start loading process - $page = self::$pageList->getPage($unique_identifier); + return self::dashboard(); + } elseif (!isset($matches['identifier']) || !isset($matches['page'])) { + // If incomplete data is provided, load a 404 + Logger::log('Invalid input retrieved. Loading 404 not found page'); - // Load the designated module - $module = Modules::get($page->getModule()); + return self::error404(); + } - // Check if it implements the PageRouterInterface - if (method_exists($module, 'getAdminRouter')) { - $router = $module->getAdminRouter(); + // If enough data is provided, try and load a page + Logger::log('Input received. Attempting to find page'); + $unique_identifier = $matches['identifier'].'/'.$matches['page']; + if (isset(self::$pageList->pages[$unique_identifier])) { + // Page found, start loading process + $page = self::$pageList->getPage($unique_identifier); - // Then check if the router is valid, if not, return 500 - if (!$router instanceof PageRouterInterface) { - Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($router)." does not implement \Module\Admin\PageRouterInterface"); - return self::error500(); - } + // Load the designated module + $module = Modules::get($page->getModule()); - // Route the request into the module - Logger::log("Input valid and module loaded. Attempting to route request"); + // Check if it implements the PageRouterInterface + if (method_exists($module, 'getAdminRouter')) { + $router = $module->getAdminRouter(); - // Generating page object - $pageObject = new Page(); - $pageObject->setPagePath($matches['page']); - $pageObject->setSubPath( (isset($matches['subdata']) ? $matches['subdata'] : null) ); + // Then check if the router is valid, if not, return 500 + if (!$router instanceof PageRouterInterface) { + Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($router)." does not implement \Module\Admin\PageRouterInterface"); - // And send it - $router->importPage($pageObject); - $router->route(); + return self::error500(); + } - // And retrieve it - $pageObject = $router->getPage(); + // Route the request into the module + Logger::log('Input valid and module loaded. Attempting to route request'); - // And retrieve some data - self::$html = $pageObject->getHtml(); - // $html = $pageObject->getHtml(); + // Generating page object + $pageObject = new Page(); + $pageObject->setPagePath($matches['page']); + $pageObject->setSubPath((isset($matches['subdata']) ? $matches['subdata'] : null)); - Logger::stopLevel(); - return ''; - } else { - // Error, router does not exist - Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($module)." does not implement method getAdminRouter()"); - Logger::stopLevel(); - return self::error500(); - } - } + // And send it + $router->importPage($pageObject); + $router->route(); - Logger::log("Matching page was not found. Loading 404 not found page"); - Logger::stopLevel(); - return self::error404(); + // And retrieve it + $pageObject = $router->getPage(); + // And retrieve some data + self::$html = $pageObject->getHtml(); + // $html = $pageObject->getHtml(); - } + Logger::stopLevel(); - public static function getHtml() { - return self::$html; - } + return ''; + } else { + // Error, router does not exist + Logger::logError("Could not load '".$unique_identifier."' on module '".$page->getModule()."'. ".get_class($module).' does not implement method getAdminRouter()'); + Logger::stopLevel(); - public static function getActivePage() { - return 'fuzeadmin/testPage'; - } + return self::error500(); + } + } - public static function dashboard() { + Logger::log('Matching page was not found. Loading 404 not found page'); + Logger::stopLevel(); - } + return self::error404(); + } - public static function error404() { - Logger::http_error(404, false); - return Layout::get('404'); - } + public static function getHtml() + { + return self::$html; + } - public static function error500() { - Logger::http_error(500, false); - return Layout::get('500'); - } + public static function getActivePage() + { + return 'fuzeadmin/testPage'; + } + + public static function dashboard() + { + } + + public static function error404() + { + Logger::http_error(404, false); + + return Layout::get('404'); + } + + public static function error500() + { + Logger::http_error(500, false); + + return Layout::get('500'); + } } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.page_router_interface.php b/Modules/admin/classes/class.page_router_interface.php index 2bf911c..9813ba4 100644 --- a/Modules/admin/classes/class.page_router_interface.php +++ b/Modules/admin/classes/class.page_router_interface.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -interface PageRouterInterface { - - public function importPage($pageObject); - public function getPage(); - +interface PageRouterInterface +{ + public function importPage($pageObject); + public function getPage(); } - -?> \ No newline at end of file diff --git a/Modules/admin/classes/class.theme_manager.php b/Modules/admin/classes/class.theme_manager.php index 659932a..b174553 100644 --- a/Modules/admin/classes/class.theme_manager.php +++ b/Modules/admin/classes/class.theme_manager.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ namespace Module\Admin; -use \FuzeWorks\Layout; -use \FuzeWorks\Logger; -class ThemeManager { +use FuzeWorks\Layout; - private static $themeDir = 'views/adminlte2.1/'; +class ThemeManager +{ + private static $themeDir = 'views/adminlte2.1/'; - public static function loadTheme($theme = null) { - self::$themeDir = Main::getModulePath() . 'themes/adminlte2.1/'; - Layout::setDirectory(self::$themeDir); - } - - public static function getDirectory() { - // First check if the theme is actually loaded - if (empty(self::$themeDir)) - throw new AdminException("Could not load panel. Theme not loaded", 1); - // And then return the theme Directory - return self::$themeDir; - } + public static function loadTheme($theme = null) + { + self::$themeDir = Main::getModulePath().'themes/adminlte2.1/'; + Layout::setDirectory(self::$themeDir); + } + public static function getDirectory() + { + // First check if the theme is actually loaded + if (empty(self::$themeDir)) { + throw new AdminException('Could not load panel. Theme not loaded', 1); + } + // And then return the theme Directory + return self::$themeDir; + } } - -?> \ No newline at end of file diff --git a/Modules/admin/moduleInfo.php b/Modules/admin/moduleInfo.php index 2ebe8f8..abddf53 100644 --- a/Modules/admin/moduleInfo.php +++ b/Modules/admin/moduleInfo.php @@ -1,6 +1,6 @@ . * - * @author TechFuze - * @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net) - * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) - * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License - * @link http://fuzeworks.techfuze.net - * @since Version 0.0.1 - * @version Version 0.0.1 + * @author TechFuze + * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) + * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) + * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License + * + * @link http://fuzeworks.techfuze.net + * @since Version 0.0.1 + * + * @version Version 0.0.1 */ return array( - 'module_class' => 'Module\Admin\Main', - 'module_file' => 'class.main.php', - 'module_name' => 'Admin', - 'abstract' => false, - 'aliases' => array(), - 'dependencies' => array(), - 'events' => array(), - 'routes' => array('/^admin(|\/(?P.*?)(|\/(?.*?)(|\/(?P.*?))))$/'), - 'advertise' => array('admin' => array( 'identifier' => 'fuzeadmin', 'pages' => array( array( 'name' => 'TEST', 'page_path' => 'testPage', 'icon' => 'fa-plane')) )), - 'listenFor' => array('admin'), - 'name' => 'FuzeWorks Admin Panel', - 'description' => 'Control Panel for FuzeWorks Modules and FrameWork', - 'author' => 'core', - 'version' => '1.0.0', - 'website' => 'http://fuzeworks.techfuze.net/', - 'date_created' => '13-01-2016', - 'date_updated' => '17-01-2016', - 'enabled' => true + 'module_class' => 'Module\Admin\Main', + 'module_file' => 'class.main.php', + 'module_name' => 'Admin', + 'abstract' => false, + 'aliases' => array(), + 'dependencies' => array(), + 'events' => array(), + 'routes' => array('/^admin(|\/(?P.*?)(|\/(?.*?)(|\/(?P.*?))))$/'), + 'advertise' => array('admin' => array('identifier' => 'fuzeadmin', 'pages' => array(array('name' => 'TEST', 'page_path' => 'testPage', 'icon' => 'fa-plane')))), + 'listenFor' => array('admin'), + 'name' => 'FuzeWorks Admin Panel', + 'description' => 'Control Panel for FuzeWorks Modules and FrameWork', + 'author' => 'core', + 'version' => '1.0.0', + 'website' => 'http://fuzeworks.techfuze.net/', + 'date_created' => '13-01-2016', + 'date_updated' => '17-01-2016', + 'enabled' => true, ); diff --git a/Modules/admin/themes/adminlte2.1/view.panel.php b/Modules/admin/themes/adminlte2.1/view.panel.php index 6f8c317..107ff29 100644 --- a/Modules/admin/themes/adminlte2.1/view.panel.php +++ b/Modules/admin/themes/adminlte2.1/view.panel.php @@ -7,18 +7,18 @@ - + - + - + @@ -131,7 +131,7 @@ @@ -153,7 +153,7 @@
- +
@@ -236,14 +236,14 @@ - + - + - + - +