Merge branch 'Dev' into 'master'

Miscellaneous changes and fixes

See 9d665e2a for more details about the contents of this MR



See merge request !40
This commit is contained in:
Abel Hoogeveen 2015-10-12 15:42:06 +02:00
commit 69c233f6b3
51 changed files with 1693 additions and 2549 deletions

View File

@ -1,4 +1,4 @@
<?php return array (
'enable_composer' => true
'enable_composer' => true,
'composer_autoloader' => ''
) ;

View File

@ -1,11 +1,56 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace Controller;
use \FuzeWorks\Controller;
namespace Application\Controller;
use \FuzeWorks\ControllerAbstract;
use \FuzeWorks\Layout;
class Standard extends Controller {
/**
* The default controller of FuzeWorks.
*
* 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, 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');
}

View File

@ -1,8 +1,44 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace Model;
namespace Application\Model;
use \FuzeWorks\Model;
/**
* 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Example extends Model{
public function __construct(&$core){

View File

@ -28,27 +28,25 @@
* @version Version 0.0.1
*/
namespace FuzeWorks;
namespace Application\Model;
use \FuzeWorks\Model;
/**
* Interpret Class.
* SQLTable model
*
* This Model is able to automatically select a SQL database as its source.
* @package net.techfuze.fuzeworks.core
* 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Interpret extends Model {
class Sqltable extends Model{
public function __construct(){
$this->setType('techfuze/databaseutils', 'Model');
$this->table = '';
$this->setType('core/databaseutils', 'Model');
$this->fields = '*';
$this->table = 'table';
}
public function table($name) {
$this->table = $name;
}
}
?>
}

View File

@ -1,13 +0,0 @@
<?php
namespace Model;
use \FuzeWorks\Model;
class Table extends Model{
public function __construct(){
$this->setType('core/databaseutils', 'Model');
$this->fields = '*';
$this->table = 'table';
}
}

View File

@ -1,3 +1,34 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
?>
<html>
<head>
<title>Page not found</title>

View File

@ -1,3 +1,34 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
?>
<html>
<head>
<title>FuzeWorks - Home</title>

View File

@ -1,22 +0,0 @@
<?php
use \FuzeWorks\Event;
class ControllerLoadEvent extends Event {
public $route;
public $controllerName;
public $function;
public $parameters;
public $directory;
public function init($route, $controllerName, $function, $parameters, $directory) {
$this->route = $route;
$this->controllerName = $controllerName;
$this->function = $function;
$this->parameters = $parameters;
$this->directory = $directory;
}
}
?>

View File

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

View File

@ -28,22 +28,50 @@
* @version Version 0.0.1
*/
return array(
namespace FuzeWorks\Event;
use \FuzeWorks\Event;
'module_class' => '\Module\Users\Users',
'module_file' => 'class.users.php',
'module_name' => 'users',
/**
* 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class LayoutLoadViewEvent extends Event {
'dependencies' => array('core/database'),
'aliases' => array(),
'events' => array(),
/**
* The directory of the view to be loaded
* @var string
*/
public $directory;
'name' => 'Users',
'description' => 'Lightweight user and permissions system',
'author' => 'core',
'version' => '1.0.0.0',
'website' => 'http://fuzeworks.techfuze.net/',
/**
* The file of the view to be loaded
* @var string
*/
public $file;
'date_created' => '23-02-2015',
'date_updated' => '29-08-2015',
);
/**
* The engine the file will be loaded with
* @var object
*/
public $engine;
/**
* The assigned variables to the template
* @var array
*/
public $assigned_variables;
public function init($file, $directory, $engine, $assigned_variables){
$this->file = $file;
$this->directory = $directory;
$this->engine = $engine;
$this->assigned_variables = $assigned_variables;
}
}
?>

View File

@ -1,11 +1,58 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class ModelLoadEvent extends Event {
public $directory;
public $model;
/**
* The directory the model gets loaded from
* @var string|null
*/
public $directory = null;
/**
* The name of the model to be loaded
* @var string|null
*/
public $model = null;
public function init($model, $directory){
$this->model = $model;

View File

@ -1,5 +1,34 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace FuzeWorks\Event;
use \FuzeWorks\Event;
/**
@ -7,7 +36,9 @@ use \FuzeWorks\Event;
*
* Called when a callable is about to be loaded
*
* @package net.techfuze.fuzeworks.events
* @package net.techfuze.fuzeworks.core.event
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class routerLoadCallableEvent extends Event{
@ -17,25 +48,20 @@ class routerLoadCallableEvent extends Event{
public $callable;
/**
* @var null|string The controller-part of the route
* @var array The matches with the routing path
*/
public $controller = null;
public $matches = array();
/**
* @var null|string The function-part of the route
* The route which was matched
* @var null|string
*/
public $function = null;
public $route = null;
/**
* @var null|string The parameter-part of the route
*/
public $parameters = null;
public function init($callable, $matches, $route){
public function init($callable, $controller, $function, $parameters){
$this->callable = $callable;
$this->controller = $controller;
$this->function = $function;
$this->parameters = $parameters;
$this->callable = $callable;
$this->matches = $matches;
$this->route = $route;
}
}

View File

@ -1,13 +1,46 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace FuzeWorks\Event;
use \FuzeWorks\Event;
/**
* Class routerRouteEvent
*
* Fired after the router has extracted the path
* Fired after the router has extracted the path, and is about to find out what route matches the path.
*
* @package net.techfuze.fuzeworks.events
* This Event is usefull for adding routes.
*
* @package net.techfuze.fuzeworks.core.event
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class routerRouteEvent extends Event{
@ -21,9 +54,16 @@ class routerRouteEvent extends Event{
*/
public $loadCallable;
public function init($routes, $loadCallable){
/**
* The current path input to FuzeWorks
* @var null|string
*/
public $path;
public function init($routes, $loadCallable, $path){
$this->routes = $routes;
$this->loadCallable = $loadCallable;
$this->path = $path;
}
}

View File

@ -1,5 +1,34 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace FuzeWorks\Event;
use \FuzeWorks\Event;
/**
@ -7,11 +36,14 @@ use \FuzeWorks\Event;
*
* Fired when the router's path is changing
*
* @package net.techfuze.fuzeworks.events
* @package net.techfuze.fuzeworks.core.event
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class routerSetPathEvent extends Event{
/**
* The path to be set to the router
* @var string The new path
*/
public $path;

View File

@ -31,11 +31,11 @@
namespace FuzeWorks;
/**
* Abstract class Controller
* 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
abstract class Controller {}
abstract class ControllerAbstract {}

View File

@ -61,12 +61,14 @@ 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 <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class NotifierEvent extends Event {}
class NotifierEvent extends \FuzeWorks\Event {}
?>

View File

@ -29,8 +29,9 @@
*/
namespace FuzeWorks;
use \Iterator;
use \PDOException;
use \FuzeWorks\ORM\ConfigFileORM;
use \FuzeWorks\ORM\ConfigDatabaseORM;
/**
@ -51,13 +52,6 @@ class Config {
*/
public static $dbActive = false;
/**
* Class Constructor
* @access public
* @param FuzeWorks Core Reference
*/
public static function init() {}
/**
* All loaded Config files
* @var Array of ConfigORM
@ -70,7 +64,7 @@ class Config {
* @param String config file name
* @param String directory, default is Application/Config
* @throws \Exception on file not found
* @return StdObject of config
* @return \FuzeWorks\ORM\ConfigORM of config
*/
public static function loadConfigFile($name, $directory = null) {
$dir = (isset($directory) ? $directory : "Application/Config/");
@ -111,13 +105,16 @@ class Config {
* Magic config getter
* @access public
* @param String config file name
* @return StdObject of config
* @return \FuzeWorks\ORM\ConfigORM of config
*/
public static function get($name) {
return self::loadConfigFile($name);
}
}
namespace FuzeWorks\ORM;
use \Iterator;
/**
* Abstract ConfigORM class.
*

View File

@ -71,17 +71,23 @@ class Core {
// Load core functionality
self::loadStartupFiles();
Logger::init();
// Load the config file of the FuzeWorks core
$config = Config::get('core');
Modules::buildRegister();
Events::buildEventRegister();
// Load the logger
Logger::init();
// And initialize the router paths
Router::init();
// Build all the registers for correct operation
Modules::buildRegister();
Events::buildEventRegister();
// Load Composer
if (Config::get('core')->enable_composer) {
self::loadComposer();
if ($config->enable_composer) {
$file = ($config->composer_autoloader != '' ? $config->composer_autoloader : 'vendor/autoload.php');
self::loadComposer($file);
}
$event = Events::fireEvent('coreStartEvent');
@ -90,7 +96,10 @@ class Core {
}
}
public static function loadStartupFiles($config = array()) {
/**
* Load all the files of the FuzeWorks Framework.
*/
private static function loadStartupFiles() {
if (self::$loaded)
return;
@ -106,7 +115,7 @@ class Core {
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.controller.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");
@ -123,6 +132,11 @@ class Core {
self::$loaded = true;
}
/**
* Stop FuzeWorks and run all shutdown functions.
*
* Afterwards run the Logger shutdown function in order to possibly display the log
*/
public static function shutdown() {
Events::fireEvent('coreShutdownEvent');
Logger::shutdown();
@ -132,11 +146,16 @@ class Core {
* 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;
}

View File

@ -110,7 +110,13 @@ class Events {
}
}
## EVENTS
/**
* 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
*/
public static function fireEvent($input) {
if (is_string($input)) {
// If the input is a string
@ -121,12 +127,13 @@ class Events {
$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\NotifierEvent';
$eventClass = '\FuzeWorks\Event\NotifierEvent';
}else{
// No notify-event: we tried all we could
throw new Exception("Event ".$eventName." could not be found!");
@ -178,11 +185,12 @@ class Events {
Logger::newLevel('Found listeners with priority ' . EventPriority::getPriority($priority));
//Fire the event to each listener
foreach ($listeners as $callback) {
if(!is_string($callback[0]))
Logger::log('Firing ' . get_class($callback[0]) . '->' . $callback[1]);
if (is_callable($callback)) {
Logger::newLevel('Firing function');
} elseif(!is_string($callback[0]))
Logger::newLevel('Firing ' . get_class($callback[0]) . '->' . $callback[1]);
else
Logger::log('Firing ' . join('->', $callback));
Logger::newLevel('');
Logger::newLevel('Firing ' . join('->', $callback));
try {
call_user_func($callback, $event);
} catch (ModuleException $e) {
@ -200,7 +208,12 @@ class Events {
return $event;
}
// Event Preparation:
/**
* Build a register which says which module listens for what event.
*
* This way not all modules have to be loaded in order to listen to all events.
* @return boolean true on success
*/
public static function buildEventRegister() {
$event_register = array();

View File

@ -30,6 +30,10 @@
namespace FuzeWorks;
use \Smarty;
use \FuzeWorks\TemplateEngine\JSONEngine;
use \FuzeWorks\TemplateEngine\PHPEngine;
use \FuzeWorks\TemplateEngine\SmartyEngine;
use \FuzeWorks\TemplateEngine\TemplateEngine;
/**
* Layout and Template Manager for FuzeWorks.
@ -71,13 +75,14 @@ class Layout {
/**
* Retrieve a template file using a string and a directory and immediatly echo it.
* What template files get loaded depend on the template engine that is used.
* PHP for example used .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php files.
*
* 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 an LayoutException when multiple compatible files are found.
* 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 true on success
* @return Boolean true on success
* @throws LayoutException On error
*/
public static function view($file, $directory = 'Application/Views') {
@ -88,10 +93,11 @@ class Layout {
/**
* Retrieve a template file using a string and a directory.
* What template files get loaded depend on the template engine that is used.
* PHP for example used .php files. Providing this function with 'home/dashboard' will load the home/view.dashboard.php files.
*
* 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 an LayoutException when multiple compatible files are found.
* 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
@ -126,10 +132,23 @@ class Layout {
self::$current_engine->setDirectory($directory);
// And run an Event to see what other parts have to say about it
$event = Events::fireEvent('layoutLoadViewEvent', $file, $directory, self::$current_engine, self::$assigned_variables);
// The event has been cancelled
if($event->isCancelled()){
return false;
}
// And refetch the data from the event
self::$current_engine = $event->engine;
self::$assigned_variables = $event->assigned_variables;
Logger::stopLevel();
// And finally run it
return self::$current_engine->get($file, self::$assigned_variables);
return self::$current_engine->get($event->file, self::$assigned_variables);
}
/**
@ -156,6 +175,7 @@ class Layout {
/**
* Converts a view string to a file using the directory and the used extensions.
*
* It will detect wether 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
@ -353,6 +373,9 @@ class Layout {
}
}
namespace FuzeWorks\TemplateEngine;
use \FuzeWorks\LayoutException;
/**
* Interface that all Template Engines must follow
* @package net.techfuze.fuzeworks.core
@ -559,6 +582,20 @@ class JSONEngine implements TemplateEngine {
*/
protected $assigned_variables = array();
/**
* 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;
}
public function setDirectory($directory) {
return true;
}
@ -581,7 +618,10 @@ class JSONEngine implements TemplateEngine {
$json['data'] = $this->assigned_variables;
// And return it
return json_encode($json);
if (self::$string_return)
return json_encode($json);
return $json;
}
public function getFileExtensions() {
@ -590,6 +630,7 @@ class JSONEngine implements TemplateEngine {
public function reset() {
$this->assigned_variables = array();
$this->string_return = true;
}
public function test($param1, $param2, $param3) {

View File

@ -41,13 +41,47 @@ namespace FuzeWorks;
*/
class Logger {
/**
* 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 warning entries
* @var array
*/
public static $warningErrors = array();
/**
* All log entries, unsorted
* @var array
*/
public static $Logs = array();
/**
* Wether to output the log after FuzeWorks has run
* @var boolean
*/
private static $print_to_screen = false;
/**
* Wether 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) {
@ -59,6 +93,11 @@ class Logger {
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";
@ -79,8 +118,8 @@ class Logger {
}
if (self::$debug == true || self::$print_to_screen) {
self::log("Parsing debug log", "Logger");
self::logToScreen();
self::log("Parsing debug log");
echo self::logToScreen();
}
}
@ -126,6 +165,10 @@ class Logger {
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');
@ -134,7 +177,7 @@ class Logger {
}
// Otherwise just load it
echo '<h3>FuzeWorks debug log</h3>';
$string = '<h3>FuzeWorks debug log</h3>';
$layer = 0;
for($i = 0; $i < count(self::$Logs); $i++){
@ -142,23 +185,29 @@ class Logger {
if($log['type'] == 'LEVEL_START'){
$layer++;
$color = 255-($layer*25);
echo '<div style="background: rgb(188 , 232 ,'.$color.');border: 1px black solid;margin: 5px 0;padding: 5px 20px;">';
echo '<div style="font-weight: bold; font-size: 11pt;">'.$log['message'].'<span style="float: right">'.(!empty($log['runtime']) ? "(".round($log['runtime']*1000, 4).'ms)' : "").'</span></div>';
$string .= '<div style="background: rgb(188 , 232 ,'.$color.');border: 1px black solid;margin: 5px 0;padding: 5px 20px;">';
$string .= '<div style="font-weight: bold; font-size: 11pt;">'.$log['message'].'<span style="float: right">'.(!empty($log['runtime']) ? "(".round($log['runtime']*1000, 4).'ms)' : "").'</span></div>';
} elseif ($log['type'] == "LEVEL_STOP") {
$layer--;
echo "</div>";
$string .= "</div>";
} elseif ($log['type'] == "ERROR") {
echo '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt; background-color:#f56954;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt; background-color:#f56954;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'
<span style="float: right">'.(!empty($log['logFile']) ? $log['logFile'] : "")." : ".(!empty($log['logLine']) ? $log['logLine'] : "").'('.round($log['runtime']*1000, 4).' ms)</span></div>';
} elseif ($log['type'] == "WARNING") {
echo '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt; background-color:#f39c12;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt; background-color:#f39c12;">['.$log['type'].']'.(!empty($log['context']) && is_string($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'
<span style="float: right">'.(!empty($log['logFile']) ? $log['logFile'] : "")." : ".(!empty($log['logLine']) ? $log['logLine'] : "").'('.round($log['runtime']*1000, 4).' ms)</span></div>';
} elseif ($log['type'] == "INFO") {
echo '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt;">'.(!empty($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'<span style="float: right">('.round($log['runtime']*1000, 4).' ms)</span></div>';
$string .= '<div style="'.($layer == 0 ? 'padding-left: 21px;' : "").'font-size: 11pt;">'.(!empty($log['context']) ? '<u>['.$log['context'].']</u>' : "").' '.$log["message"].'<span style="float: right">('.round($log['runtime']*1000, 4).' ms)</span></div>';
}
}
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());
@ -179,11 +228,26 @@ class Logger {
/* =========================================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 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 : ""),
@ -196,6 +260,14 @@ class Logger {
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 : ""),
@ -208,6 +280,14 @@ class Logger {
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 : ""),
@ -220,6 +300,14 @@ class Logger {
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 : ""),
@ -231,6 +319,14 @@ class Logger {
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 : ""),
@ -292,6 +388,11 @@ class Logger {
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){
$http_codes = array(
@ -331,22 +432,22 @@ class Logger {
511 => 'Network Authentication Required'
);
self::logError('HTTP-error '.$errno.' called', 'Logger');
self::log('Sending header HTTP/1.1 '.$errno.' '.$http_codes[$errno], 'Logger', __FILE__, __LINE__);
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;
// Load the view
$view = 'errors/'.$errno;
self::log('Loading view '.$view);
// Try and load the view, if impossible, load HTTP code instead.
try{
Layout::view($view);
}catch(LayoutException $exception){
} catch(LayoutException $exception){
// No error page could be found, just echo the result
echo "<h1>$errno</h1><h3>".$http_codes[$errno]."</h3>";
}
@ -368,6 +469,12 @@ class Logger {
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;

View File

@ -41,10 +41,24 @@ namespace FuzeWorks;
*/
class Models {
/**
* Array of all the loaded models
* @var array
*/
private static $models_array = array();
private static $model_types = array();
private static $models_loaded = false;
/**
* 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.
*/
public static function loadModel($name, $directory = null){
// Model load event
$event = Events::fireEvent('modelLoadEvent', $name, $directory);
@ -57,25 +71,30 @@ class Models {
self::$models_array[$name] = self::$model_types[$name];
} elseif (file_exists($file)){
require_once($file);
$model = "\Model\\" . ucfirst($name);
$model = "\Application\Model\\" . ucfirst($name);
Logger::log('Loading Model: '.$model, $model);
self::$models_array[$name] = new $model();
return self::$models_array[$name] = new $model();
} else{
Logger::logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'Models');
require_once("Core/System/Models/model.interpret.php");
Logger::log('Loading Model: interprated databasemodel', 'Models');
$model = new Interpret();
$model->table($name);
self::$models_array[$name] = $model;
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
*/
public static function get($name){
if (isset(self::$models_array[strtolower($name)])) {
return self::$models_array[strtolower($name)];
// Get the name
$name = strtolower($name);
// Check if it already exists
if (isset(self::$models_array[$name])) {
// Return if it does
return self::$models_array[$name];
} else {
self::loadModel(strtolower($name));
return self::$models_array[strtolower($name)];
// If not, load and return afterwards
return self::loadModel($name);
}
}
}

View File

@ -39,22 +39,40 @@ use \stdClass;
*/
class Modules {
/**
* A register of all the existing module headers.
*
* The module headers contain information required to loading the module
* @var Array
*/
public static $register;
/**
* An array of all the loaded modules
* @var array
*/
public static $modules = array();
/**
* An array which modules are loaded, and should not be loaded again
* An array with the names of all modules that are loaded, and should not be loaded again
* @access private
* @var Array of module names
*/
private static $loaded_modules = array();
/**
* An array which holds the routes to module to load them quickly
* @access private
* @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
* @return \FuzeWorks\Module Module The module
* @throws FuzeWorks\ModuleException
* @throws \FuzeWorks\ModuleException
*/
public static function get($name) {
// Where the modules are
@ -75,8 +93,6 @@ class Modules {
// Check if the module is already loaded. If so, only return a reference, if not, load the module
if (in_array($name, self::$loaded_modules)) {
// return the link
$msg = "Module '".ucfirst((isset($cfg->name) ? $cfg->name : $cfg->module_name)) . "' is already loaded";
Logger::log($msg);
$c = self::$modules[strtolower($cfg->module_name)];
return $c;
} else {
@ -154,6 +170,12 @@ 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
*/
private static function setModuleValue($file, $key, $value) {
if (file_exists($file) && is_writable($file)) {
$cfg = require($file);
@ -164,6 +186,9 @@ class Modules {
}
/**
* Add a module using a moduleInfo.php file
*
* @param String Path to moduleInfo.php file
* @throws FuzeWorks\ModuleException
*/
public static function addModule($moduleInfo_file) {
@ -210,6 +235,11 @@ class Modules {
}
/**
* Enables a module when it is disabled
*
* @access public
* @param String Module name
* @param boolean true for permanent enable
* @throws FuzeWorks\ModuleException
*/
public static function enableModule($name, $permanent = true) {
@ -246,6 +276,11 @@ class Modules {
}
/**
* Disableds a module when it is enabled
*
* @access public
* @param String Module name
* @param boolean true for permanent disable
* @throws FuzeWorks\ModuleException
*/
public static function disableModule($name, $permanent = true) {
@ -281,6 +316,12 @@ class Modules {
}
/**
* 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');
@ -306,31 +347,18 @@ class Modules {
// Get the module directory
$cfg->directory = $mod_dir;
// Check wether the module is enabled or no
// Check wether the module is disabled
if (isset($cfg->enabled)) {
if ($cfg->enabled) {
// Copy all the data into the register and enable
$register[$name] = (array) $cfg;
Logger::log("[ON] '".$name."'");
// Add all module aliases if available
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg;
unset($register[$alias]['events']);
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
}
} else {
// If not, copy all the basic data so that it can be enabled in the future
if (!$cfg->enabled) {
// If disabled, a holder will be placed so it might be enabled in the future
$cfg2 = new StdClass();
$cfg2->module_name = $cfg->module_name;
$cfg2->directory = $cfg->directory;
$cfg2->meta = $cfg;
$register[$name] = (array)$cfg2;
Logger::log("[OFF] '".$name."'");
Logger::newLevel("[OFF] '".$name."'");
// Add all module aliases if available
// And possibly some aliases
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg2;
@ -338,21 +366,39 @@ class Modules {
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
}
}
} else {
// Copy all the data into the register and enable
$register[$name] = (array) $cfg;
Logger::log("[ON] '".$name."'");
// Add all module aliases if available
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg;
unset($register[$alias]['events']);
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
Logger::stopLevel();
// And to the next one
continue;
}
}
// Copy all the data into the register and enable
$register[$name] = (array) $cfg;
Logger::newLevel("[ON] '".$name."'");
// Add all module aliases if available
if (isset($cfg->aliases)) {
foreach ($cfg->aliases as $alias) {
$register[$alias] = (array) $cfg;
unset($register[$alias]['events']);
Logger::log("&nbsp;&nbsp;&nbsp;'".$alias."' (alias of '".$name."')");
}
}
// If routes are present, add them to the router
if (isset($cfg->routes)) {
foreach ($cfg->routes as $route) {
// Create the route and callable and parse them
$callable = array('\FuzeWorks\Modules', 'moduleCallable');
Router::addRoute($route, $callable, true);
self::$module_routes[$route] = $name;
}
}
Logger::stopLevel();
} else {
// If no details are specified, create a basic module
$name = $mod_dirs[$i];
@ -368,7 +414,8 @@ class Modules {
// Apply it
$register[$name] = (array)$cfg;
Logger::log("[ON] '".$name."'");
Logger::newLevel("[ON] '".$name."'");
Logger::stopLevel();
}
}
@ -377,6 +424,38 @@ class Modules {
}
/**
* 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
*/
public static function moduleCallable($matches = array()){
// First detect what module is attached to this route
Logger::newLevel('Module callable called!');
// Get the route
$route = !empty($matches['route']) ? $matches['route'] : null;
// See if the route exists
if (isset(self::$module_routes[$route])) {
Logger::log("Module '".self::$module_routes[$route]."' matched given route");
// Load the module
$mod = self::get(self::$module_routes[$route]);
unset($matches['route']);
$mod->route($matches);
} else {
Logger::logError("Route did not match known module. Fatal error");
return Logger::http_error(500);
}
Logger::stopLevel();
}
}
?>

View File

@ -34,25 +34,32 @@ use \Application\Init;
/**
* Class Router
*
* This class handles the framework's routing. The router determines which controller should be called.
* 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:
*
* The routes-array will hold a list of RegEx-strings. When the route-method is called, the framework will try
* to match the current path against all the RegEx's. When a RegEx matches, the linked callable will be called.
*
* The default route works as follows:
* Every module can register routes and add their own callables. By default, two callables are used:
* The defaultCallable and the moduleCallable.
*
* The defaultCallable is a traditional MVC controller loader. Loading an URL using a default route works as follows:
*
* Let's say the visitor requests /A/B/C
*
* A would be the 'controller' (default: home)
* A would be the 'controller' (default: standard)
* B would be the function to be called in the 'controller' (default: index)
* C would be the first parameter
*
* All controllers are to be placed in the /Application/controller-directory.
*
* This is the default behaviour by adding routes to the config.routes.php. It is also possible to load Modules using routes.
* To load a Module using a route, add the route to the moduleInfo.php in a routes array.
* When this route is matched, a moduleCallable gets loaded which loads the module and loads either a controller file, or a routing function.
*
* But because of this RegEx-table, modules can easily listen on completely different paths. You can, for example, make
* a module that only triggers when /admin/<controller>/<function>/.. is accessed. Or even complexer structure are
* available, e.g: /webshop/product-<controller>/view/<function>.
* a module that only triggers when /admin/<page>/<component>/.. is accessed. Or even complexer structure are
* available, e.g: /webshop/product-<id>/view/<detailID>.
*
* BE AWARE:
*
@ -72,7 +79,7 @@ use \Application\Init;
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Router{
class Router {
/**
* @var null|string The provided path
@ -90,19 +97,9 @@ class Router{
private static $callable = null;
/**
* @var null|string The extracted controller's name
* @var null|array The extracted matches from the regex
*/
private static $controller = null;
/**
* @var null|string The extracted controller's function name
*/
private static $function = null;
/**
* @var array The extracted parameters
*/
private static $parameters = array();
private static $matches = null;
/**
* The constructor adds the default route to the routing table
@ -150,50 +147,12 @@ class Router{
}
/**
* Returns the active controller's name
*
* @return null|string
* Returns all the matches with the RegEx route
* @return null|array
*/
public static function getController() {
public static function getMatches() {
return self::$controller;
}
/**
* Returns the name of the active controller's function
*
* @return null|string The name of the function
*/
public static function getFunction() {
return self::$function;
}
/**
* Returns the routing parameters
*
* @return array
*/
public static function getParameters(){
return self::$parameters;
}
/**
* Returns the routing parameter at given index
*
* @param int $index
* @return array
*/
public static function getParameter($index = 0){
$parameters = self::$parameters;
$index = ($index >= 0 ? $index : count($parameters)+$index);
if(isset($parameters[$index]))
return $parameters[$index];
return null;
return self::$matches;
}
/**
@ -214,7 +173,7 @@ class Router{
}
// Remove double slashes
$path = preg_replace('@[/]+@', '/', $path);
$path = preg_replace('@[/]+@', '/', $event->path);
// Remove first slash
if(substr($path, 0, 1) == '/')
@ -227,43 +186,17 @@ class Router{
return self::$path = $path;
}
/**
* Set the controller name
*
* Until we decide what to do with name giving of controllers/functions,
* this function stays here.
*
* @param string $controller the name of the controller
*/
public static function setController($controller){
self::$controller = $controller;
}
/**
* Set the function name
*
* Until we decide what to do with name giving of controllers/functions,
* this function stays here.
*
* @param string $function the name of the controller
*/
public static function setFunction($function){
self::$function = $function;
}
/**
* 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.
*
*
* The callable will be called with three arguments:
*
* Callable($controller, $function, $parameters)
*
* These three variables will be extracted from the named groups of your RegEx. When one or more named groups are
*
* Callable($regex_matches = array())
*
* The variables in the array will be the named groups of your RegEx. When one or more named groups are
* not matched, they will be set to NULL. The default RegEx is:
*
* /^(?P<controller>.*?)(|\/(?P<function>.*?)(|\/(?P<parameters>.*?)))$/
@ -321,15 +254,17 @@ class Router{
}
/**
* Extracts the routing path to controller, function and parameters
* Extracts the routing path from the URL using the routing table.
*
* @TODO: $loadCallable might not be needed anymore
* Determines what callable should be loaded and what data matches the route regex.
*
* @todo: Add path to routerRouteEvent
* @param boolean $loadCallable Immediate load the callable when it's route matches
*/
public static function route($loadCallable = true)
{
// Fire the event to notify our modules
$event = Events::fireEvent('routerRouteEvent', self::$routes, $loadCallable);
$event = Events::fireEvent('routerRouteEvent', self::$routes, $loadCallable, self::$path);
// The event has been cancelled
if($event->isCancelled()){
@ -338,23 +273,21 @@ class Router{
}
// Assign everything to the object to make it accessible, but let modules check it first
//self::$routes = $event->routes;
//$loadCallable = $event->loadCallable;
$routes = $event->routes;
$loadCallable = $event->loadCallable;
//Check the custom routes
foreach (self::$routes as $r => $c) {
foreach ($routes as $r => $c) {
//A custom route is found
if(preg_match($r, self::$path, $matches)) {
self::$controller = !empty($matches['controller']) ? $matches['controller'] : null;
self::$function = !empty($matches['function']) ? $matches['function'] : null;
self::$parameters = !empty($matches['parameters']) ? explode('/', $matches['parameters']) : null;
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())
if(!$loadCallable || !self::loadCallable($matches, $r))
break;
}
}
@ -362,34 +295,47 @@ class Router{
// Check if we found a callable anyway
if(self::$callable === null){
Logger::log('No routes found for given path: "'.self::$path.'"', E_WARNING);
Logger::log('No routes found for given path: "'.$event->path.'"', E_WARNING);
Logger::http_error(404);
return;
}
}
/**
* Load and execute the callable
* Load the callable to which the route matched.
*
* First it checks if it is possible to call the callable. If not, the default callable gets selected and a controller, function and parameters get selected.
*
* 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
* @todo add route to routerLoadCallableEvent
*/
public static function loadCallable(){
public static function loadCallable($matches = array(), $route){
Logger::newLevel('Loading callable');
// Fire the event to notify our modules
$event = Events::fireEvent('routerLoadCallableEvent', self::$callable, self::$controller, self::$function, self::$parameters);
$event = Events::fireEvent('routerLoadCallableEvent', self::$callable, $matches, $route);
// The event has been cancelled
if($event->isCancelled())
return false;
if(!is_callable(self::$callable))
// Prepare the arguments and add the route
$args = $event->matches;
$args['route'] = $event->route;
if(!is_callable($event->callable))
if(isset(self::$callable['controller'])) {
self::$controller = isset(self::$callable['controller']) ? self::$callable['controller'] : self::$controller;
self::$function = isset(self::$callable['function']) ? self::$callable['function'] : self::$function;
self::$parameters = isset(self::$callable['parameters']) ? self::$callable['parameters'] : self::$parameters;
// 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{
@ -400,19 +346,14 @@ class Router{
return true;
}
$args = array(
self::$controller,
self::$function,
self::$parameters,
);
// And log the input to the logger
Logger::newLevel('Calling callable');
Logger::log('Controller: '. ($args[0] === null ? 'null' : $args[0]));
Logger::log('Function: '. ($args[1] === null ? 'null' : $args[1]));
Logger::log('Parameters: '. (empty($args[2]) ? '[]' : implode(', ',$args[2])));
foreach ($args as $key => $value) {
Logger::log($key.": ".var_export($value,true)."");
}
Logger::stopLevel();
$skip = call_user_func_array(self::$callable, $args) === false;
$skip = call_user_func_array(self::$callable, array($args)) === false;
if($skip)
Logger::log('Callable not satisfied, skipping to next callable');
@ -427,16 +368,17 @@ class Router{
* 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(){
public static function defaultCallable($arguments = array()){
Logger::log('Default callable called!');
self::$controller = self::$controller === null ? Config::get('main')->default_controller : self::$controller;
self::$function = self::$function === null ? Config::get('main')->default_function : self::$function;
$controller = empty($arguments['controller']) ? Config::get('main')->default_controller : $arguments['controller'];
$function = empty($arguments['function']) ? Config::get('main')->default_function : $arguments['function'];
$parameters = empty($arguments['parameters']) ? null : $arguments['parameters'];
// Construct file paths and classes
$class = '\Controller\\'.ucfirst(self::$controller);
$file = 'Application/Controller/controller.'.self::$controller.'.php';
$class = '\Application\Controller\\'.ucfirst($controller);
$file = 'Application/Controller/controller.'.$controller.'.php';
Logger::log('Loading controller '.$class.' from file: '.$file);
@ -446,17 +388,26 @@ class Router{
if(!class_exists($class))
require $file;
self::$callable = new $class();
// Get the path the controller should know about
$path = substr(self::getPath(), ($pos = strpos(self::getPath(), '/')) !== false ? $pos + 1 : 0);
// And create the controller
self::$callable = new $class($path);
// If the controller does not want a function to be loaded, provide a halt parameter.
if (isset(self::$callable->halt)) {
return;
}
// Check if method exists or if there is a caller function
if(method_exists(self::$callable, self::$function) || method_exists(self::$callable, '__call')){
if(method_exists(self::$callable, $function) || method_exists(self::$callable, '__call')){
// Execute the function on the controller
self::$callable->{self::$function}(self::$parameters);
echo self::$callable->{$function}($parameters);
}else{
// Function could not be found
Logger::log('Could not find function '.self::$function.' on controller '.$class);
Logger::log('Could not find function '.$function.' on controller '.$class);
Logger::http_error(404);
}
}else{

111
Database.sql Normal file
View File

@ -0,0 +1,111 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
CREATE TABLE IF NOT EXISTS `hi_config` (
`id` int(11) NOT NULL,
`file` varchar(32) NOT NULL,
`key` text NOT NULL,
`value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `hi_log` (
`id` int(11) NOT NULL,
`type` varchar(8) NOT NULL,
`message` varchar(255) NOT NULL,
`logFile` varchar(255) NOT NULL,
`logLine` int(11) NOT NULL,
`context` text NOT NULL,
`runtime` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `hi_user_data` (
`data_id` int(11) NOT NULL,
`data_user_id` int(11) NOT NULL,
`data_key` varchar(255) NOT NULL,
`data_value` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `hi_user_emails` (
`email_id` int(11) NOT NULL,
`email_user_id` int(11) NOT NULL,
`email_text` varchar(64) NOT NULL,
`email_primary` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `hi_user_permissions` (
`permission_id` int(11) NOT NULL,
`permission_tag_id` int(11) NOT NULL,
`permission_user_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `hi_user_sessions` (
`session_id` int(11) NOT NULL,
`session_hash` varchar(255) NOT NULL,
`session_user_id` int(11) NOT NULL,
`session_info` text NOT NULL,
`session_ip` varchar(64) NOT NULL,
`session_start` datetime NOT NULL,
`session_end` datetime NOT NULL,
`session_active` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `hi_user_tags` (
`tag_id` int(11) NOT NULL,
`tag_name` varchar(64) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
INSERT INTO `hi_user_tags` (`tag_id`, `tag_name`) VALUES
(1, 'ACTIVE'),
(2, 'BLOCKED'),
(3, 'ADMIN');
CREATE TABLE IF NOT EXISTS `hi_user_users` (
`user_id` int(11) NOT NULL,
`user_username` varchar(32) NOT NULL,
`user_password` varchar(255) NOT NULL,
`user_email` varchar(255) NOT NULL COMMENT 'Primary Email of the user',
`user_verify_code` varchar(16) NOT NULL COMMENT 'Verification code used in email to verify user email'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `hi_config`
ADD PRIMARY KEY (`id`);
ALTER TABLE `hi_log`
ADD PRIMARY KEY (`id`);
ALTER TABLE `hi_user_data`
ADD PRIMARY KEY (`data_id`);
ALTER TABLE `hi_user_emails`
ADD PRIMARY KEY (`email_id`);
ALTER TABLE `hi_user_permissions`
ADD PRIMARY KEY (`permission_id`);
ALTER TABLE `hi_user_sessions`
ADD PRIMARY KEY (`session_id`);
ALTER TABLE `hi_user_tags`
ADD PRIMARY KEY (`tag_id`);
ALTER TABLE `hi_user_users`
ADD PRIMARY KEY (`user_id`);
ALTER TABLE `hi_config`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `hi_log`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `hi_user_data`
MODIFY `data_id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `hi_user_emails`
MODIFY `email_id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `hi_user_permissions`
MODIFY `permission_id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `hi_user_sessions`
MODIFY `session_id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `hi_user_tags`
MODIFY `tag_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4;
ALTER TABLE `hi_user_users`
MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT;

View File

@ -1,10 +1,51 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace Module\Api;
use \FuzeWorks\Module;
/**
* Loading class for multiple API types
*
* Currently loads a REST API class which controllers can extend so they provide a standardized API
* @package net.techfuze.fuzeworks.core
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class Main extends Module {
/**
* Gets loaded upon module initialization
*
* Loads all the API types
*/
public function onLoad() {
require_once($this->getModulePath() . "/class.rest.php");
}

View File

@ -1,50 +1,96 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace Module\Api;
use \FuzeWorks\Module;
use \FuzeWorks\Layout;
class RestApi extends Module {
public function onLoad() {}
/**
* RestAPI class for creating API's out of modules or contrllers
*
* Extend a Controller with this class, and be sure to return the data from methods of your controller.
* This data will be parsed by this class and returned as valid JSON data.
* The necessity of API keys can be configured in the controller by settings $this->requireApiKey = false;
* @package net.techfuze.fuzeworks.core
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
abstract class RestAPI
{
/**
* Property: method
* The HTTP method this request was made in, either GET, POST, PUT or DELETE
*/
public $method = '';
protected $method = '';
/**
* Property: endpoint
* The Model requested in the URI. eg: /files
*/
public $endpoint = '';
protected $endpoint = '';
/**
* Property: verb
* An optional additional descriptor about the endpoint, used for things that can
* not be handled by the basic methods. eg: /files/process
*/
public $verb = '';
protected $verb = '';
/**
* Property: args
* Any additional URI components after the endpoint and verb have been removed, in our
* case, an integer ID for the resource. eg: /<endpoint>/<verb>/<arg0>/<arg1>
* or /<endpoint>/<arg0>
*/
public $args = Array();
protected $args = Array();
/**
* Property: file
* Stores the input of the PUT request
*/
public $file = Null;
protected $file = Null;
/**
* Whether API authentication is needed before interacting with the API
*/
protected $requireApiKey = true;
/**
* Request
* Constructor: __construct
* Allow for CORS, assemble and pre-process the data
*/
public function request($request) {
public function __construct($request) {
header("Access-Control-Allow-Orgin: *");
header("Access-Control-Allow-Methods: *");
header("Content-Type: application/json");
// Return layout data as string
Layout::setEngine('JSON');
Layout::returnAsString(false);
$this->args = explode('/', rtrim($request, '/'));
$this->endpoint = array_shift($this->args);
if (array_key_exists(0, $this->args) && !is_numeric($this->args[0])) {
@ -78,10 +124,21 @@ class RestApi extends Module {
$this->_response('Invalid Method', 405);
break;
}
// And afterwards process the data
echo $this->processAPI();
// Halter for when the RestApi is used by a controller
$this->halt = true;
Layout::reset();
}
/**
* Process an API request when retrieving
* @return String JSON encoded response
*/
public function processAPI() {
if ((int)method_exists($this, $this->endpoint) > 0) {
if (method_exists($this, $this->endpoint)) {
return $this->_response($this->{$this->endpoint}($this->args));
}
return $this->_response("No Endpoint: $this->endpoint", 404);
@ -113,5 +170,4 @@ class RestApi extends Module {
);
return ($status[$code])?$status[$code]:$status[500];
}
}

View File

@ -1,4 +1,33 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
return array(
'module_class' => 'Module\Api\Main',
@ -18,7 +47,7 @@ return array(
'website' => 'http://fuzeworks.techfuze.net/',
'date_created' => '03-05-2015',
'date_updated' => '03-05-2015',
'date_updated' => '06-09-2015',
'enabled' => true,
);

View File

@ -31,6 +31,7 @@
namespace Module\DatabaseUtils;
use \FuzeWorks\Module;
use \FuzeWorks\Modules;
use \FuzeWorks\Bus;
use \FuzeWorks\ModelServer;
use \FuzeWorks\DatabaseException;
@ -182,6 +183,23 @@ class Model {
return $queryBuilder;
}
/**
* The default table will be set to $this->table
* @see Query::replace
* @param $array Array with values
* @return Query
* @throws Exception
*/
public function replace($array){
$queryBuilder = new Query();
$queryBuilder->setTable($this->table);
call_user_func_array(array($queryBuilder, 'replace'), func_get_args());
return $queryBuilder;
}
/**
* Return latest insert id
*
@ -192,6 +210,6 @@ class Model {
}
public function __call($name, $params) {
return call_user_func_array(array($this->mods->database, $name), $params);
return call_user_func_array(array(Modules::get('core/database'), $name), $params);
}
}

View File

@ -779,7 +779,7 @@ class Query extends Module {
try{
$this->sth = Modules::get('core/database')->getConnection()->prepare($this->getSql());
$this->sth = Modules::get('core/database')->prepare($this->getSql());
if(count($this->getBinds()) === 0){
$this->sth->execute();
@ -832,7 +832,7 @@ class Query extends Module {
*/
public function getLastInsertId(){
return Modules::get('core/database')->getConnection()->lastInsertId();
return Modules::get('core/database')->lastInsertId();
}

View File

@ -99,6 +99,17 @@ class Main extends Module {
return $result;
}
/**
* Gets called when the path matches the regex of this module.
* @access public
* @param array Regex matches
* @return void
*/
public function route($matches = array()) {
// Just print the inputted data:
echo "<h3>Input data: ".$matches['data']."</h3>";
}
}
class ExampleEvent extends Event {

View File

@ -51,6 +51,11 @@ return array(
// Events that this module listens for. When the exampleEvent is fired, this module will be loaded so the module can handle the event
'events' => array('exampleEvent'),
// Routes that this module listens on. If the URL /example/ gets called, this module will be loaded
// Everything after /example/ will be sent to the route() function in the matches array under the 'data' key
// A route must ALWAYS have the module capturing group. Otherwise it will fail
'routes' => array('/^example(|\/(?P<data>.*?))$/'),
// The name of the module as it will be logged. This does not affect usage of the module in any way
'name' => 'FuzeWorks Example Module',

View File

@ -76,13 +76,14 @@ use \PHPMailer;
if ($cfg->sendmail_enabled && !$cfg->smtp_enabled) {
$this->mailers[$name]->isSendmail();
} elseif (!$cfg->sendmail_enabled && $cfg->smtp_enabled) {
// Set up all the SMTP details
$this->mailers[$name]->isSMTP();
$this->mailers[$name]->SMTPDebug = $cfg->smtp_debug_level;
$this->mailers[$name]->Debugoutput = 'html';
$this->mailers[$name]->Host = $cfg->smtp_host;
$this->mailers[$name]->Port = $cfg->smtp_port;
// Authentication
// SMTP Authentication
if ($cfg->smtp_auth) {
$this->mailers[$name]->SMTPAuth = true;
$this->mailers[$name]->Username = $cfg->smtp_username;

View File

@ -1,13 +0,0 @@
<?php
namespace Controller;
use \FuzeWorks\Controller;
class Standard extends Controller {
public function index($path = null) {
}
}
?>

View File

@ -1,321 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Verify Email Adress</title>
<style type="text/css">
@media screen and (max-width: 600px) {
table[class="container"] {
width: 95% !important;
}
}
#outlook a {padding:0;}
body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
.ExternalClass {width:100%;}
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}
#backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}
img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;}
a img {border:none;}
.image_fix {display:block;}
p {margin: 1em 0;}
h1, h2, h3, h4, h5, h6 {color: black !important;}
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}
h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
color: red !important;
}
h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
color: purple !important;
}
table td {border-collapse: collapse;}
table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }
a {color: #000;}
@media only screen and (max-device-width: 480px) {
a[href^="tel"], a[href^="sms"] {
text-decoration: none;
color: black; /* or whatever your want */
pointer-events: none;
cursor: default;
}
.mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {
text-decoration: default;
color: orange !important; /* or whatever your want */
pointer-events: auto;
cursor: default;
}
}
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
a[href^="tel"], a[href^="sms"] {
text-decoration: none;
color: blue; /* or whatever your want */
pointer-events: none;
cursor: default;
}
.mobile_link a[href^="tel"], .mobile_link a[href^="sms"] {
text-decoration: default;
color: orange !important;
pointer-events: auto;
cursor: default;
}
}
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
/* Put your iPhone 4g styles in here */
}
@media only screen and (-webkit-device-pixel-ratio:.75){
/* Put CSS for low density (ldpi) Android layouts in here */
}
@media only screen and (-webkit-device-pixel-ratio:1){
/* Put CSS for medium density (mdpi) Android layouts in here */
}
@media only screen and (-webkit-device-pixel-ratio:1.5){
/* Put CSS for high density (hdpi) Android layouts in here */
}
/* end Android targeting */
h2{
color:#181818;
font-family:Helvetica, Arial, sans-serif;
font-size:22px;
line-height: 22px;
font-weight: normal;
}
a.link1{
}
a.link2{
color:#fff;
text-decoration:none;
font-family:Helvetica, Arial, sans-serif;
font-size:16px;
color:#fff;border-radius:4px;
}
p{
color:#555;
font-family:Helvetica, Arial, sans-serif;
font-size:16px;
line-height:160%;
}
</style>
<script type="colorScheme" class="swatch active">
{
"name":"Default",
"bgBody":"ffffff",
"link":"fff",
"color":"555555",
"bgItem":"ffffff",
"title":"181818"
}
</script>
</head>
<body>
<!-- Wrapper/Container Table: Use a wrapper table to control the width and the background color consistently of your email. Use this approach instead of setting attributes on the body tag. -->
<table cellpadding="0" width="100%" cellspacing="0" border="0" id="backgroundTable" class='bgBody'>
<tr>
<td>
<table cellpadding="0" width="620" class="container" align="center" cellspacing="0" border="0">
<tr>
<td>
<!-- Tables are the most common way to format your email consistently. Set your table widths inside cells and in most cases reset cellpadding, cellspacing, and border to zero. Use nested tables as a way to space effectively in your message. -->
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" class="container">
<tr>
<td class='movableContentContainer bgItem'>
<div class='movableContent'>
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" class="container">
<tr height="40">
<td width="200">&nbsp;</td>
<td width="200">&nbsp;</td>
<td width="200">&nbsp;</td>
</tr>
<tr>
<td width="200" valign="top">&nbsp;</td>
<td width="200" valign="top" align="center">
<div class="contentEditableContainer contentImageEditable">
<div class="contentEditable" align='center' >
<img src="<?php echo($vars["siteLogo"]); ?>" width="155" height="155" alt='Logo' data-default="placeholder" />
</div>
</div>
</td>
<td width="200" valign="top">&nbsp;</td>
</tr>
<tr height="25">
<td width="200">&nbsp;</td>
<td width="200">&nbsp;</td>
<td width="200">&nbsp;</td>
</tr>
</table>
</div>
<div class='movableContent'>
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" class="container">
<?php if (isset($vars['verifyURL'])) { ?>
<tr>
<td width="100%" colspan="3" align="center" style="padding-bottom:10px;padding-top:25px;">
<div class="contentEditableContainer contentTextEditable">
<div class="contentEditable" align='center' >
<h2 >Welcome to <?php echo($vars['serverName']); ?></h2>
</div>
</div>
</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="400" align="center">
<div class="contentEditableContainer contentTextEditable">
<div class="contentEditable" align='left' >
<p >Hello <?php echo($vars['username']); ?>,
<br/>
<br/>
<b>Your account has not yet been verified.</b> Click on the link below to verify your mail adress to grant acess to <?php echo($vars['serverName']); ?>.
<br/><br/>If this account has been created without your knowlegde, please let us know on <a href='<?php echo($vars['siteURL'] ); ?>'>Our Website</a>
</p>
</div>
</div>
</td>
<td width="100">&nbsp;</td>
</tr>
<?php } else { ?>
<tr>
<td width="100%" colspan="3" align="center" style="padding-bottom:10px;padding-top:25px;">
<div class="contentEditableContainer contentTextEditable">
<div class="contentEditable" align='center' >
<h2 >Welcome to <?php echo($vars['serverName']); ?></h2>
</div>
</div>
</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="400" align="center">
<div class="contentEditableContainer contentTextEditable">
<div class="contentEditable" align='left' >
<p >Hello <?php echo($vars['username']); ?>,
<br/>
<br/>
Your account on <?php echo($vars['serverName']); ?> has been successfully created. You can now start using the website.<br/><br/>
If this account has been created without your knowlegde, please let us know on <a href='<?php echo($vars['siteURL'] ); ?>'>Our Website</a>
</p>
</div>
</div>
</td>
<td width="100">&nbsp;</td>
</tr>
<?php } ?>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" class="container">
<tr>
<td width="200">&nbsp;</td>
<td width="200" align="center" style="padding-top:25px;">
<?php if (isset($vars['verifyURL'])) { ?>
<table cellpadding="0" cellspacing="0" border="0" align="center" width="200" height="50">
<tr>
<td bgcolor="#ED006F" align="center" style="border-radius:4px;" width="200" height="50">
<div class="contentEditableContainer contentTextEditable">
<div class="contentEditable" align='center' >
<a target='_blank' href="<?php echo($vars['verifyURL']); ?>" class='link2'>Verify Email Adress</a>
</div>
</div>
</td>
</tr>
</table>
<?php } ?>
</td>
<td width="200">&nbsp;</td>
</tr>
</table>
</div>
<div class='movableContent'>
<table cellpadding="0" cellspacing="0" border="0" align="center" width="600" class="container">
<tr>
<td width="100%" colspan="2" style="padding-top:65px;">
<hr style="height:1px;border:none;color:#333;background-color:#ddd;" />
</td>
</tr>
<tr>
<td width="60%" height="70" valign="middle" style="padding-bottom:20px;">
<div class="contentEditableContainer contentTextEditable">
<div class="contentEditable" align='left' >
<span style="font-size:13px;color:#181818;font-family:Helvetica, Arial, sans-serif;line-height:200%;">Sent to <?php echo($vars['email']) . (!empty($vars['contact']['contact_name']) ? " by " . $vars['contact']['contact_name'] : "") ?></span>
<br/>
<span style="font-size:11px;color:#555;font-family:Helvetica, Arial, sans-serif;line-height:200%;"><?php echo( (!empty($vars['contact']['contact_adress']) ? $vars['contact']['contact_adress'] : " ") . (!empty($vars['contact']['contact_adress']) || !empty($vars['contact']['contact_phone']) ? " | " : "") . (!empty($vars['contact']['contact_phone']) ? "<a href='tel:".$vars['contact']['contact_phone']."'>".$vars['contact']['contact_phone']."</a>" : "") ); ?></span>
<br/>
<span style="font-size:13px;color:#181818;font-family:Helvetica, Arial, sans-serif;line-height:200%;">
</span>
<br/>
<span style="font-size:13px;color:#181818;font-family:Helvetica, Arial, sans-serif;line-height:200%;">
</div>
</div>
</td>
<td width="40%" height="70" align="right" valign="top" align='right' style="padding-bottom:20px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align='right'>
<tr>
<!-- SOCIAL EXAMPLES HERE
<td width='57%'></td>
<td valign="top" width='34'>
<div class="contentEditableContainer contentFacebookEditable" style='display:inline;'>
<div class="contentEditable" >
<img src="facebook.png" data-default="placeholder" data-max-width='30' data-customIcon="true" width='30' height='30' alt='facebook' style='margin-right:40x;'>
</div>
</div>
</td>
<td valign="top" width='34'>
<div class="contentEditableContainer contentTwitterEditable" style='display:inline;'>
<div class="contentEditable" >
<img src="twitter.png" data-default="placeholder" data-max-width='30' data-customIcon="true" width='30' height='30' alt='twitter' style='margin-right:40x;'>
</div>
</div>
</td>
<td valign="top" width='34'>
<div class="contentEditableContainer contentImageEditable" style='display:inline;'>
<div class="contentEditable" >
<a target='_blank' href="#" data-default="placeholder" style="text-decoration:none;">
<img src="pinterest.png" width="30" height="30" data-max-width="30" alt='pinterest' style='margin-right:40x;' />
</a>
</div>
</div>
</td>-->
</tr>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td></tr></table>
</td>
</tr>
</table>
<!-- End of wrapper table -->
</body>
</html>

View File

@ -1,636 +0,0 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
namespace Module\Users;
use \FuzeWorks\Event;
/**
* An Event that gets fired when an email is about to be sent to the user upon registration
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionRegisterMailEvent extends Event {
/**
* User Data Table of the user to send the mail to
* @var Array UDT
*/
public $udt;
/**
* HTML of the final mail
* @var HTML
*/
public $html;
/**
* Identifier for the verification of a user
* @var String Code
*/
public $verifyCode;
/**
* URL to send the verification to
* @var String URL
*/
public $verifyURL;
/**
* Wether to use custom HTML or not
* @var Boolean true of using custom HTML
*/
public $customHtml = false;
/**
* Wether to use custom HTML or not. Can be set here
* @access public
* @param True if using custom HTML or false if not
* @return true on success
* @throws ServiceException on Fatal error
*/
public function useCustomHtml($bool) {
if (is_bool($bool)) {
$this->customHtml = $bool;
return true;
}
throw new ServiceException("Could not set customHtml. Input is not a Boolean", 1);
}
/**
* Intializes the event and it's variables
* @access public
* @param Array UDT of user to send mail to
* @param String VerificationCode
* @param String VerificationURL
*/
public function init($udt, $verifyCode, $verifyURL) {
$this->udt = $udt;
$this->verifyCode = $verifyCode;
$this->verifyURL = $verifyURL;
}
}
/**
* Event that is fired when a user tries to log in.
* Event should be cancelled if you want to deny a user to log in.
* If you want to use your own authenticator service, please provide a User Data Table so the authenticator can be successfully identified.
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionLoginEvent extends Event {
/**
* The username of the user.
* Available if the user has been successfully verified by the sessions module
* @var String Username
*/
public $username;
/**
* Identifier used when logging in. Usefull for if another module wants to log users in
* @var String Identifier
*/
public $identifier;
/**
* The password used to identify a user
* @var String password
*/
public $password;
/**
* The email of the user.
* Available if the user has been successfully verified by the sessions module
* @var String Email
*/
public $email;
/**
* User id of the user
* @var Int User Id
*/
public $user_id;
/**
* Wether the user has been successfully verified.
* Set to true (AND PROVIDE A UDT) to log a custom user in using another mechanism.
* @var boolean true if verified.
*/
public $verified = false;
/**
* Wether the user should be logged in for a very long time.
* @var boolean true if remember for long time.
*/
public $remember_me = false;
/**
* User Data Table for when the user is verified by the sessions module.
* @var Array User Data Table
*/
public $udt;
/**
* Initializes the event.
* @param String $identifier Can be an email or username
* @param String $password Password of the user
* @param boolean $remember_me Wether the user should be logged in for a long time
* @param String $username Username of a user (optional)
* @param String $email Email of a user (optional)
* @param Array $udt User Data Table of a user (optional)
*/
public function init($identifier, $password, $remember_me, $user_id, $username = null, $email = null, $udt = null) {
$this->identifier = $identifier;
$this->password = $password;
$this->remember_me = $remember_me;
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
$this->udt = $udt;
}
/**
* Set the verification of this user
* @param boolean $verified True if verified.
*/
public function setVerified($verified = false) {
$this->verified = $verified;
}
/**
* Sets the UserId of a user
* @param Int $user_id Id of the user
*/
public function setUserId($user_id) {
$this->user_id = $user_id;
}
/**
* Sets the username when a user is successfully verified
* @param String $username Username of the user
*/
public function setUsername($username) {
$this->username = $username;
}
/**
* Sets the email when a user is successfully verified
* @param String $email Email of the user
*/
public function setEmail($email) {
$this->email = $email;
}
/**
* Sets the User Data Table when a user is successfully verified
* @param Array $udt User Data Table
*/
public function setUdt($udt) {
$this->udt = $udt;
}
}
/**
* Event gets fired when a user tries to log out
* Cancel the event to deny a logout.
* The Event only provides information. Changing variables will not log someone else out.
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionLogoutEvent extends Event {
/**
* User ID of a user
* @var Int User ID
*/
public $user_id;
/**
* Username of a user
* @var String username
*/
public $username;
/**
* Email of a user
* @var String Email
*/
public $email;
/**
* Initializes the event
* @param String $user_id User ID of a user
* @param String $username Username of a user
* @param String $email Email of a user
*/
public function init($user_id, $username, $email) {
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
}
}
/**
* Event that gets fired when a new user get's created.
* Cancel the event to deny user creation.
* The Event only provides information. Changing variables will not register with new data.
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionUserCreateEvent extends Event {
/**
* Username of a user
* @var String Username
*/
public $username;
/**
* Email of a user
* @var String Email
*/
public $email;
/**
* User ID of a user
* @var Int UserId
*/
public $user_id;
/**
* Initializes the event
* @param Int $user_id User ID of a user
* @param String $username Username of a user
* @param String $email Email of a user
*/
public function init($user_id, $username, $email) {
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
}
}
/**
* Event that gets fired when a user is modified.
* Cancel the event to deny the change.
* Change variables to change what gets changed.
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionUserModifyEvent extends Event {
/**
* User ID of a user
* @var Int User ID
*/
public $user_id;
/**
* The key that get's changed
* @var String name of key
*/
public $key;
/**
* The original value that is getting changed.
* @var Mixed Value
*/
public $from;
/**
* The value it is getting changed into
* @var Mixed value
*/
public $value;
/**
* Initializes the Event
* @param Int $user_id User ID of a user
* @param String $key The key that get's changed
* @param Mixed $value The original value that is getting changed.
* @param Mixed $from The value it is getting changed into
*/
public function init($user_id, $key, $value, $from) {
$this->user_id = $user_id;
$this->key = $key;
$this->value = $value;
$this->from = $from;
}
}
/**
* Event that gets fired when a user is getting removed.
* Cancel the event to deny the user removal.
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionUserRemoveEvent extends Event {
/**
* User ID of the user
* @var Int User ID
*/
public $user_id;
/**
* Username of the user
* @var String username
*/
public $username;
/**
* Email of the user
* @var String email
*/
public $email;
/**
* Initializes the event
* @param Int $user_id User ID of the user
* @param String $username Username of the user
* @param String $email Email of the user
*/
public function init($user_id, $username, $email) {
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
}
}
/**
* Event that gets fired when a password is changed.
* Cancel the event to deny password change
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionChangePasswordEvent extends Event {
/**
* User ID of the user
* @var Int UserId
*/
public $user_id;
/**
* Username of the user
* @var String Username
*/
public $username;
/**
* Old Password of the user. (the one that it is being changed from).
* It will be null when the oldPassword is not required
* @var String|null Password
*/
public $oldPassword;
/**
* New Password of the user. (the one that it is being changed to)
* @var String password
*/
public $newPassword;
/**
* Initializes the Event
* @param Int $user_id User ID of the user
* @param String $username Username of the user
* @param String|null $oldPassword Old Password of the user. (the one that it is being changed from)
* @param String $newPassword New Password of the user. (the one that it is being changed to)
*/
public function init($user_id, $username, $oldPassword = null, $newPassword) {
$this->user_id = $user_id;
$this->username = $username;
$this->oldPassword = $oldPassword;
$this->newPassword = $newPassword;
}
}
/**
* Event that gets fired when a user is suspended
* Cancel event to deny user suspension
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionUserSuspendEvent extends Event {
/**
* User ID of the user
* @var Int User ID
*/
public $user_id;
/**
* Username of the user
* @var String username
*/
public $username;
/**
* Email of the user
* @var String email
*/
public $email;
/**
* Initializes the event
* @param Int $user_id User ID of the user
* @param String $username Username of the user
* @param String $email Email of the user
*/
public function init($user_id, $username, $email) {
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
}
}
/**
* Event that gets fired when a user is unsuspended
* Cancel event to deny user unsuspension
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionUserUnsuspendEvent extends Event {
/**
* User ID of the user
* @var Int User ID
*/
public $user_id;
/**
* Username of the user
* @var String username
*/
public $username;
/**
* Email of the user
* @var String email
*/
public $email;
/**
* Initializes the event
* @param Int $user_id User ID of the user
* @param String $username Username of the user
* @param String $email Email of the user
*/
public function init($user_id, $username, $email) {
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
}
}
/**
* Event that gets fired when a user is registering.
* Gets called before the SessionUserCreateEvent, so the userdata can still be changed.
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionRegisterEvent extends Event {
/**
* Username of the user
* @var String username
*/
public $username;
/**
* Email of the user
* @var String email
*/
public $email;
/**
* The password of the user
* @var String password
*/
public $password;
/**
* Initializes the Event
* @param String $username Username of the user
* @param String $email Email of the user
* @param String $password The password of the user
*/
public function init($username, $email, $password) {
$this->username = $username;
$this->email = $email;
$this->password = $password;
}
}
/**
* Event that gets fired when a session gets started.
* Cancel the event so that the user gets a guest session
* Change the UDT to change the session information
* @package net.techfuze.fuzeworks.sessions
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2015, Techfuze. (http://techfuze.net)
*/
class SessionStartEvent extends Event {
/**
* User ID of the user
* @var Int User ID
*/
public $user_id;
/**
* Username of the user
* @var String username
*/
public $username;
/**
* Email of the user
* @var String email
*/
public $email;
/**
* User Data Table of the user
* @var Array UDT
*/
public $udt;
/**
* Wether the session is from a guest.
* @var boolean true if a guest session
*/
public $guest_session = true;
/**
* Initializes the event
* @param Int $user_id User ID of the user
* @param String $username Username of the user
* @param String $email Email of the user
* @param Array $udt User Data Table of the user
* @param boolean $guest_session Wether the session is from a guest.
*/
public function init($user_id, $username, $email, $udt = null, $guest_session = true) {
$this->user_id = $user_id;
$this->username = $username;
$this->email = $email;
$this->udt = $udt;
$this->guest_session = $guest_session;
}
/**
* Set wether the session is a guest session
* @param boolean $bool Wether the session is from a guest
*/
public function setGuestSession($bool) {
$this->guest_session = $bool;
}
/**
* Set a new User Data Table.
* @param Array $udt UDT
*/
public function setUdt($udt) {
$this->udt = $udt;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +0,0 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
return array(
'cookie_name' => 'FuzeCookie',
// Should be filled in if you want email verification to work
'verify_controller' => '',
);

View File

@ -35,7 +35,6 @@ use \FuzeWorks\Router;
require_once( dirname(__FILE__) . "/Core/System/class.core.php");
// Load it
new Core();
Core::init();
Router::setPath( (isset($_GET['path']) ? $_GET['path'] : null) );

View File

@ -1,9 +0,0 @@
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /fw/index.php?path=$1 last;
}
}
location ~* (\.enc.cfg)$ {
return 404;
}

View File

@ -1,4 +1,33 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use FuzeWorks\Events;
/**

View File

@ -1,4 +1,32 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
// Load the abstract
use \FuzeWorks\Config;

View File

@ -1,4 +1,32 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
/**
* Class CoreTest

81
tests/core_modelTest.php Normal file
View File

@ -0,0 +1,81 @@
<?php
use \FuzeWorks\Core;
use \FuzeWorks\Models;
/**
* Class ModelTest
*
* Core model testing suite, will test basic model functionality
*
*/
class ModelTest extends CoreTestAbstract
{
/**
* Select
*/
public function testSelectSimple()
{
$query = Models::get('sqltable')->select();
$this->assertEquals('SELECT * FROM table', $query->getSql());
}
public function testSelectSimpleOneField(){
$query = Models::get('sqltable')->select('field1');
$this->assertEquals('SELECT field1 FROM table', $query->getSql());
}
public function testSelectSimpleTwoFields(){
$query = Models::get('sqltable')->select('field1', 'field2');
$this->assertEquals('SELECT field1, field2 FROM table', $query->getSql());
}
/**
* Delete
*/
public function testDeleteSimple(){
$query = Models::get('sqltable')->delete()->from('table');
$this->assertEquals('DELETE FROM table', $query->getSql());
}
/**
* Insert
*/
public function testInsertSimple(){
$query = Models::get('sqltable')->insert(array('field' => 'value'));
$this->assertEquals('INSERT INTO table (field) VALUES (?)', $query->getSql());
$this->assertEquals(array('value'), $query->getBinds());
}
public function testInsertMultiple(){
$query = Models::get('sqltable')->insert(array('field1' => 'value1', 'field2' => 'value2'), 'table');
$this->assertEquals('INSERT INTO table (field1,field2) VALUES (?,?)', $query->getSql());
$this->assertEquals(array('value1', 'value2'), $query->getBinds());
}
/**
* Replace
*/
public function testReplaceSimple(){
$query = Models::get('sqltable')->replace(array('field' => 'value'));
$this->assertEquals('REPLACE INTO table (field) VALUES (?)', $query->getSql());
$this->assertEquals(array('value'), $query->getBinds());
}
public function testReplaceMultiple(){
$query = Models::get('sqltable')->replace(array('field1' => 'value1', 'field2' => 'value2'), 'table');
$this->assertEquals('REPLACE INTO table (field1,field2) VALUES (?,?)', $query->getSql());
$this->assertEquals(array('value1', 'value2'), $query->getBinds());
}
}

View File

@ -1,4 +1,33 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use \FuzeWorks\Modules;
use \Module\DatabaseUtils\Query;

View File

@ -1,4 +1,33 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use \FuzeWorks\Core;
use \FuzeWorks\Router;
@ -42,19 +71,15 @@ class RouterTest extends CoreTestAbstract
// Assert
// Whole route
$this->assertEquals(array('a','b',array('c','d')), array(Router::getController(), Router::getFunction(), Router::getParameters()));
$this->assertEquals('a', Router::getController());
$this->assertEquals('d', Router::getParameter(-1));
$this->assertEquals(null, Router::getParameter(5));
$this->assertEquals(array('a','b','c/d'), array(Router::getMatches()['controller'], Router::getMatches()['function'], Router::getMatches()['parameters']));
$this->assertEquals('a', Router::getMatches()['controller']);
// Parameters
$this->assertEquals(array('c','d'), Router::getParameters());
$this->assertEquals('c', Router::getParameter(0));
$this->assertEquals('d', Router::getParameter(-1));
$this->assertEquals('c/d', Router::getMatches()['parameters']);
// Function and controller
$this->assertEquals('a', Router::getController());
$this->assertEquals('b', Router::getFunction());
$this->assertEquals('a', Router::getMatches()['controller']);
$this->assertEquals('b', Router::getMatches()['function']);
}
/**
@ -65,18 +90,18 @@ class RouterTest extends CoreTestAbstract
// Empty path
Router::setPath(null);
Router::route(false);
$this->assertEquals(null, Router::getController());
$this->assertEquals(null, Router::getMatches()['controller']);
// Double slashes
Router::setPath('a///b');
Router::route(false);
$this->assertEquals(array('a','b'), array(Router::getController(), Router::getFunction()));
$this->assertEquals(array('a','b'), array(Router::getMatches()['controller'], Router::getMatches()['function']));
// Escaped path path
Router::setPath('/a\/b\/c/');
Router::route(false);
$this->assertEquals(array('a\\','b\\','c'), array(Router::getController(), Router::getFunction(), Router::getParameter(0)));
$this->assertNotEquals('a', Router::getController());
$this->assertEquals(array('a\\','b\\','c'), array(Router::getMatches()['controller'], Router::getMatches()['function'], Router::getMatches()['parameters']));
$this->assertNotEquals('a', Router::getMatches()['controller']);
}
public function testCustomRoute(){
@ -93,22 +118,22 @@ class RouterTest extends CoreTestAbstract
Router::setPath('b/controller_a/function_a');
Router::route(false);
$this->assertEquals('controller_a', Router::getController());
$this->assertEquals('function_a', Router::getFunction());
$this->assertEquals('controller_a', Router::getMatches()['controller']);
$this->assertEquals('function_a', Router::getMatches()['function']);
Router::setPath('e/function_b/c');
Router::route(false);
$this->assertEquals(null, Router::getController());
$this->assertEquals('function_b', Router::getFunction());
$this->assertEquals(null, Router::getMatches()['controller']);
$this->assertEquals('function_b', Router::getMatches()['function']);
Router::setPath('b/b');
Router::route(false);
$this->assertEquals(null, Router::getController());
$this->assertEquals(null, Router::getFunction());
$this->assertEquals(null, Router::getMatches()['controller']);
$this->assertEquals(null, Router::getMatches()['function']);
Router::setPath('a/b');
Router::route(false);
$this->assertEquals('a', Router::getController());
$this->assertEquals('b', Router::getFunction());
$this->assertEquals('a', Router::getMatches()['controller']);
$this->assertEquals('b', Router::getMatches()['function']);
}
}

View File

@ -1,4 +1,33 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use \FuzeWorks\Core;
use \FuzeWorks\Events;
use \FuzeWorks\EventPriority;

View File

@ -0,0 +1,120 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use \FuzeWorks\Events;
use \FuzeWorks\Router;
use \FuzeWorks\EventPriority;
/**
* Class RouterLoadCallableEventTest
*/
class RouterLoadCallableEventTest extends CoreTestAbstract{
/**
* Check if the event is fired when it should be
*/
public function test_basic(){
$mock = $this->getMock('MockEvent', array('mockMethod'));
$mock->expects($this->once())->method('mockMethod');
Router::setPath('/');
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
Events::addListener(array($mock, 'mockMethod'), 'routerLoadCallableEvent', EventPriority::NORMAL);
//Prevent ouputting HTML
ob_start();
Router::route();
ob_end_clean();
}
/**
* Intercept and change
*/
public function test_change(){
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
Events::addListener(array($this, 'listener_change'), 'routerLoadCallableEvent', EventPriority::NORMAL);
Router::setPath('x/y/z');
Router::route(true);
Events::$listeners = array();
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
Events::addListener(array($this, 'listener_change'), 'routerLoadCallableEvent', EventPriority::NORMAL);
Router::setPath('x/y/z');
Router::route(true);
$this->assertNotNull(Router::getCallable());
$this->assertInstanceOf('\Application\Controller\Standard', Router::getCallable());
}
// Change title from new to other
public function listener_change($event){
// This controller should not exist
$this->assertEquals('x', $event->matches['controller']);
$this->assertEquals('y', $event->matches['function']);
// It should exist now
$event->matches['controller'] = 'standard';
$event->matches['function'] = 'index';
return $event;
}
/**
* Cancel events
*/
public function test_cancel(){
ob_start();
// When the callable may execute, the callable will change to the controller
// (because '' will trigger the default callable)
Router::setPath('');
Events::addListener(array($this, 'listener_cancel'), 'routerLoadCallableEvent', EventPriority::NORMAL);
Router::route();
$this->assertTrue(is_callable(Router::getCallable()));
// When disabled, the default controller will be loaded and the callable will be overwritten
// Remove the listener
Events::$listeners = array();
Events::addListener(function($event){$event->setCancelled(true);}, 'layoutLoadViewEvent', EventPriority::HIGHEST);
Router::route();
$this->assertFalse(is_callable(Router::getCallable()));
ob_end_clean();
}
// Cancel all calls
public function listener_cancel($event){
$event->setCancelled(true);
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use \FuzeWorks\Events;
use \FuzeWorks\Router;
use \FuzeWorks\EventPriority;
/**
* Class RouterRouteEventTest
*/
class RouterRouteEventTest extends CoreTestAbstract{
/**
* Check if the event is fired when it should be
*/
public function test_basic(){
$mock = $this->getMock('MockEvent', array('mockMethod'));
$mock->expects($this->once())->method('mockMethod');
Events::addListener(array($mock, 'mockMethod'), 'routerRouteEvent', EventPriority::NORMAL);
Router::setPath('a/b/c');
Router::route(false);
}
/**
* Cancel events
*/
public function test_cancel(){
Router::setPath('x/y/z');
Events::addListener(array($this, 'listener_cancel'), 'routerRouteEvent', EventPriority::NORMAL);
Router::route(false);
$this->assertNotEquals('x', Router::getMatches()['controller']);
$this->assertNotEquals('y', Router::getMatches()['function']);
$this->assertNotEquals('z', Router::getMatches()['parameters']);
}
// Cancel all calls
public function listener_cancel($event){
$event->setCancelled(true);
}
}

View File

@ -0,0 +1,108 @@
<?php
/**
* FuzeWorks
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
use \FuzeWorks\Events;
use \FuzeWorks\Router;
use \FuzeWorks\EventPriority;
/**
* Class RouterSetPathEventTest
*/
class RouterSetPathEventTest extends CoreTestAbstract{
/**
* Check if the event is fired when it should be
*/
public function testRouterSetPathEvent(){
$mock = $this->getMock('MockEvent', array('mockMethod'));
$mock->expects($this->once())->method('mockMethod');
Events::addListener(array($mock, 'mockMethod'), 'routerSetPathEvent', EventPriority::NORMAL);
Router::setPath('a/b/c');
}
/**
* Intercept and change
*/
public function testRouterSetPathEvent_change(){
Events::addListener(array($this, 'listener_change'), 'routerSetPathEvent', EventPriority::NORMAL);
Router::setPath('a/b/c');
$this->assertEquals('x/y/z', Router::getPath());
}
// Change title from new to other
public function listener_change($event){
$this->assertEquals('a/b/c', $event->path);
$event->path = 'x/y/z';
}
/**
* Cancel events
*/
public function testLayoutFunctionCallEvent_cancel(){
Router::setPath('a/b/c');
Events::addListener(array($this, 'listener_cancel'), 'routerSetPathEvent', EventPriority::NORMAL);
Router::setPath('x/y/z');
$this->assertEquals('a/b/c', Router::getPath());
}
// Cancel all calls
public function listener_cancel($event){
$event->setCancelled(true);
}
/**
* Do not cancel events
*/
public function testLayoutFunctionCallEvent_dontcancel(){
Router::setPath('a/b/c');
Events::addListener(array($this, 'listener_dontcancel'), 'routerSetPathEvent', EventPriority::NORMAL);
Router::setPath('x/y/z');
$this->assertEquals('x/y/z', Router::getPath());
}
// Cancel all calls
public function listener_dontcancel($event){
$event->setCancelled(false);
}
}