diff options
Diffstat (limited to 'lib/minz')
| -rwxr-xr-x | lib/minz/ActionController.php | 42 | ||||
| -rwxr-xr-x | lib/minz/Configuration.php | 250 | ||||
| -rw-r--r-- | lib/minz/Dispatcher.php | 152 | ||||
| -rwxr-xr-x | lib/minz/Error.php | 94 | ||||
| -rwxr-xr-x | lib/minz/FrontController.php | 127 | ||||
| -rwxr-xr-x | lib/minz/Helper.php | 22 | ||||
| -rw-r--r-- | lib/minz/Minz_Cache.php | 116 | ||||
| -rw-r--r-- | lib/minz/Minz_Log.php | 89 | ||||
| -rwxr-xr-x | lib/minz/Model.php | 12 | ||||
| -rwxr-xr-x | lib/minz/Paginator.php | 196 | ||||
| -rw-r--r-- | lib/minz/Request.php | 196 | ||||
| -rw-r--r-- | lib/minz/Response.php | 60 | ||||
| -rwxr-xr-x | lib/minz/Router.php | 209 | ||||
| -rwxr-xr-x | lib/minz/Session.php | 78 | ||||
| -rw-r--r-- | lib/minz/Translate.php | 71 | ||||
| -rwxr-xr-x | lib/minz/Url.php | 129 | ||||
| -rwxr-xr-x | lib/minz/View.php | 240 | ||||
| -rwxr-xr-x | lib/minz/dao/Model_array.php | 122 | ||||
| -rwxr-xr-x | lib/minz/dao/Model_pdo.php | 92 | ||||
| -rwxr-xr-x | lib/minz/dao/Model_txt.php | 84 | ||||
| -rw-r--r-- | lib/minz/exceptions/MinzException.php | 94 |
21 files changed, 0 insertions, 2475 deletions
diff --git a/lib/minz/ActionController.php b/lib/minz/ActionController.php deleted file mode 100755 index ab9389dbd..000000000 --- a/lib/minz/ActionController.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe ActionController représente le contrôleur de l'application - */ -class ActionController { - protected $router; - protected $view; - - /** - * Constructeur - * @param $controller nom du controller - * @param $action nom de l'action à lancer - */ - public function __construct ($router) { - $this->router = $router; - $this->view = new View (); - $this->view->attributeParams (); - } - - /** - * Getteur - */ - public function view () { - return $this->view; - } - - /** - * Méthodes à redéfinir (ou non) par héritage - * firstAction est la première méthode exécutée par le Dispatcher - * lastAction est la dernière - */ - public function init () { } - public function firstAction () { } - public function lastAction () { } -} - - diff --git a/lib/minz/Configuration.php b/lib/minz/Configuration.php deleted file mode 100755 index b296ec378..000000000 --- a/lib/minz/Configuration.php +++ /dev/null @@ -1,250 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Configuration permet de gérer la configuration de l'application - */ -class Configuration { - const CONF_PATH_NAME = '/configuration/application.ini'; - - /** - * VERSION est la version actuelle de MINZ - */ - const VERSION = '1.3.1.freshrss'; // version spéciale FreshRSS - - /** - * valeurs possibles pour l'"environment" - * SILENT rend l'application muette (pas de log) - * PRODUCTION est recommandée pour une appli en production - * (log les erreurs critiques) - * DEVELOPMENT log toutes les erreurs - */ - const SILENT = 0; - const PRODUCTION = 1; - const DEVELOPMENT = 2; - - /** - * définition des variables de configuration - * $sel_application une chaîne de caractères aléatoires (obligatoire) - * $environment gère le niveau d'affichage pour log et erreurs - * $use_url_rewriting indique si on utilise l'url_rewriting - * $base_url le chemin de base pour accéder à l'application - * $title le nom de l'application - * $language la langue par défaut de l'application - * $cacheEnabled permet de savoir si le cache doit être activé - * $delayCache la limite de cache - * $db paramètres pour la base de données (tableau) - * - host le serveur de la base - * - user nom d'utilisateur - * - password mot de passe de l'utilisateur - * - base le nom de la base de données - */ - private static $sel_application = ''; - private static $environment = Configuration::PRODUCTION; - private static $base_url = ''; - private static $use_url_rewriting = false; - private static $title = ''; - private static $language = 'en'; - private static $cache_enabled = false; - private static $delay_cache = 3600; - - private static $db = array ( - 'host' => false, - 'user' => false, - 'password' => false, - 'base' => false - ); - - /* - * Getteurs - */ - public static function selApplication () { - return self::$sel_application; - } - public static function environment () { - return self::$environment; - } - public static function baseUrl () { - return self::$base_url; - } - public static function useUrlRewriting () { - return self::$use_url_rewriting; - } - public static function title () { - return self::$title; - } - public static function language () { - return self::$language; - } - public static function cacheEnabled () { - return self::$cache_enabled; - } - public static function delayCache () { - return self::$delay_cache; - } - public static function dataBase () { - return self::$db; - } - - /** - * Initialise les variables de configuration - * @exception FileNotExistException si le CONF_PATH_NAME n'existe pas - * @exception BadConfigurationException si CONF_PATH_NAME mal formaté - */ - public static function init () { - try { - self::parseFile (); - self::setReporting (); - } catch (FileNotExistException $e) { - throw $e; - } catch (BadConfigurationException $e) { - throw $e; - } - } - - /** - * Parse un fichier de configuration de type ".ini" - * @exception FileNotExistException si le CONF_PATH_NAME n'existe pas - * @exception BadConfigurationException si CONF_PATH_NAME mal formaté - */ - private static function parseFile () { - if (!file_exists (APP_PATH . self::CONF_PATH_NAME)) { - throw new FileNotExistException ( - APP_PATH . self::CONF_PATH_NAME, - MinzException::ERROR - ); - } - - $ini_array = parse_ini_file ( - APP_PATH . self::CONF_PATH_NAME, - true - ); - - if (!$ini_array) { - throw new PermissionDeniedException ( - APP_PATH . self::CONF_PATH_NAME, - MinzException::ERROR - ); - } - - // [general] est obligatoire - if (!isset ($ini_array['general'])) { - throw new BadConfigurationException ( - '[general]', - MinzException::ERROR - ); - } - $general = $ini_array['general']; - - - // sel_application est obligatoire - if (!isset ($general['sel_application'])) { - throw new BadConfigurationException ( - 'sel_application', - MinzException::ERROR - ); - } - self::$sel_application = $general['sel_application']; - - if (isset ($general['environment'])) { - switch ($general['environment']) { - case 'silent': - self::$environment = Configuration::SILENT; - break; - case 'development': - self::$environment = Configuration::DEVELOPMENT; - break; - case 'production': - self::$environment = Configuration::PRODUCTION; - break; - default: - throw new BadConfigurationException ( - 'environment', - MinzException::ERROR - ); - } - - } - if (isset ($general['base_url'])) { - self::$base_url = $general['base_url']; - } - if (isset ($general['use_url_rewriting'])) { - self::$use_url_rewriting = $general['use_url_rewriting']; - } - - if (isset ($general['title'])) { - self::$title = $general['title']; - } - if (isset ($general['language'])) { - self::$language = $general['language']; - } - if (isset ($general['cache_enabled'])) { - self::$cache_enabled = $general['cache_enabled']; - if (CACHE_PATH === false && self::$cache_enabled) { - throw new FileNotExistException ( - 'CACHE_PATH', - MinzException::ERROR - ); - } - } - if (isset ($general['delay_cache'])) { - self::$delay_cache = $general['delay_cache']; - } - - // Base de données - $db = false; - if (isset ($ini_array['db'])) { - $db = $ini_array['db']; - } - if ($db) { - if (!isset ($db['host'])) { - throw new BadConfigurationException ( - 'host', - MinzException::ERROR - ); - } - if (!isset ($db['user'])) { - throw new BadConfigurationException ( - 'user', - MinzException::ERROR - ); - } - if (!isset ($db['password'])) { - throw new BadConfigurationException ( - 'password', - MinzException::ERROR - ); - } - if (!isset ($db['base'])) { - throw new BadConfigurationException ( - 'base', - MinzException::ERROR - ); - } - - self::$db['type'] = isset ($db['type']) ? $db['type'] : 'mysql'; - self::$db['host'] = $db['host']; - self::$db['user'] = $db['user']; - self::$db['password'] = $db['password']; - self::$db['base'] = $db['base']; - self::$db['prefix'] = isset ($db['prefix']) ? $db['prefix'] : ''; - } - } - - private static function setReporting () { - if (self::environment () == self::DEVELOPMENT) { - error_reporting (E_ALL); - ini_set ('display_errors','On'); - ini_set('log_errors', 'On'); - } elseif (self::environment () == self::PRODUCTION) { - error_reporting(E_ALL); - ini_set('display_errors','Off'); - ini_set('log_errors', 'On'); - } else { - error_reporting(0); - } - } -} diff --git a/lib/minz/Dispatcher.php b/lib/minz/Dispatcher.php deleted file mode 100644 index 0cfdd8e75..000000000 --- a/lib/minz/Dispatcher.php +++ /dev/null @@ -1,152 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * Le Dispatcher s'occupe d'initialiser le Controller et d'executer l'action - * déterminée dans la Request - * C'est un singleton - */ -class Dispatcher { - const CONTROLLERS_PATH_NAME = '/controllers'; - - /* singleton */ - private static $instance = null; - - private $router; - private $controller; - - /** - * Récupère l'instance du Dispatcher - */ - public static function getInstance ($router) { - if (is_null (self::$instance)) { - self::$instance = new Dispatcher ($router); - } - return self::$instance; - } - - /** - * Constructeur - */ - private function __construct ($router) { - $this->router = $router; - } - - /** - * Lance le controller indiqué dans Request - * Remplit le body de Response à partir de la Vue - * @exception MinzException - */ - public function run () { - $cache = new Minz_Cache(); - // Le ob_start est dupliqué : sans ça il y a un bug sous Firefox - // ici on l'appelle avec 'ob_gzhandler', après sans. - // Vraisemblablement la compression fonctionne mais c'est sale - // J'ignore les effets de bord :( - ob_start ('ob_gzhandler'); - - if (Minz_Cache::isEnabled () && !$cache->expired ()) { - ob_start (); - $cache->render (); - $text = ob_get_clean(); - } else { - while (Request::$reseted) { - Request::$reseted = false; - - try { - $this->createController ( - Request::controllerName () - . 'Controller' - ); - - $this->controller->init (); - $this->controller->firstAction (); - $this->launchAction ( - Request::actionName () - . 'Action' - ); - $this->controller->lastAction (); - - if (!Request::$reseted) { - ob_start (); - $this->controller->view ()->build (); - $text = ob_get_clean(); - } - } catch (MinzException $e) { - throw $e; - } - } - - if (Minz_Cache::isEnabled ()) { - $cache->cache ($text); - } - } - - Response::setBody ($text); - } - - /** - * Instancie le Controller - * @param $controller_name le nom du controller à instancier - * @exception FileNotExistException le fichier correspondant au - * > controller n'existe pas - * @exception ControllerNotExistException le controller n'existe pas - * @exception ControllerNotActionControllerException controller n'est - * > pas une instance de ActionController - */ - private function createController ($controller_name) { - $filename = APP_PATH . self::CONTROLLERS_PATH_NAME . '/' - . $controller_name . '.php'; - - if (!file_exists ($filename)) { - throw new FileNotExistException ( - $filename, - MinzException::ERROR - ); - } - require_once ($filename); - - if (!class_exists ($controller_name)) { - throw new ControllerNotExistException ( - $controller_name, - MinzException::ERROR - ); - } - $this->controller = new $controller_name ($this->router); - - if (! ($this->controller instanceof ActionController)) { - throw new ControllerNotActionControllerException ( - $controller_name, - MinzException::ERROR - ); - } - } - - /** - * Lance l'action sur le controller du dispatcher - * @param $action_name le nom de l'action - * @exception ActionException si on ne peut pas exécuter l'action sur - * > le controller - */ - private function launchAction ($action_name) { - if (!Request::$reseted) { - if (!is_callable (array ( - $this->controller, - $action_name - ))) { - throw new ActionException ( - get_class ($this->controller), - $action_name, - MinzException::ERROR - ); - } - call_user_func (array ( - $this->controller, - $action_name - )); - } - } -} diff --git a/lib/minz/Error.php b/lib/minz/Error.php deleted file mode 100755 index 0e8c2f60b..000000000 --- a/lib/minz/Error.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Error permet de lancer des erreurs HTTP - */ -class Error { - public function __construct () { } - - /** - * Permet de lancer une erreur - * @param $code le type de l'erreur, par défaut 404 (page not found) - * @param $logs logs d'erreurs découpés de la forme - * > $logs['error'] - * > $logs['warning'] - * > $logs['notice'] - * @param $redirect indique s'il faut forcer la redirection (les logs ne seront pas transmis) - */ - public static function error ($code = 404, $logs = array (), $redirect = false) { - $logs = self::processLogs ($logs); - $error_filename = APP_PATH . '/controllers/errorController.php'; - - if (file_exists ($error_filename)) { - $params = array ( - 'code' => $code, - 'logs' => $logs - ); - - Response::setHeader ($code); - if ($redirect) { - Request::forward (array ( - 'c' => 'error' - ), true); - } else { - Request::forward (array ( - 'c' => 'error', - 'params' => $params - ), false); - } - } else { - $text = '<h1>An error occured</h1>'."\n"; - - if (!empty ($logs)) { - $text .= '<ul>'."\n"; - foreach ($logs as $log) { - $text .= '<li>' . $log . '</li>'."\n"; - } - $text .= '</ul>'."\n"; - } - - Response::setHeader ($code); - Response::setBody ($text); - Response::send (); - exit (); - } - } - - /** - * Permet de retourner les logs de façon à n'avoir que - * ceux que l'on veut réellement - * @param $logs les logs rangés par catégories (error, warning, notice) - * @return la liste des logs, sans catégorie, - * > en fonction de l'environment - */ - private static function processLogs ($logs) { - $env = Configuration::environment (); - $logs_ok = array (); - $error = array (); - $warning = array (); - $notice = array (); - - if (isset ($logs['error'])) { - $error = $logs['error']; - } - if (isset ($logs['warning'])) { - $warning = $logs['warning']; - } - if (isset ($logs['notice'])) { - $notice = $logs['notice']; - } - - if ($env == Configuration::PRODUCTION) { - $logs_ok = $error; - } - if ($env == Configuration::DEVELOPMENT) { - $logs_ok = array_merge ($error, $warning, $notice); - } - - return $logs_ok; - } -} diff --git a/lib/minz/FrontController.php b/lib/minz/FrontController.php deleted file mode 100755 index d48d43d04..000000000 --- a/lib/minz/FrontController.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php -# ***** BEGIN LICENSE BLOCK ***** -# MINZ - a free PHP Framework like Zend Framework -# Copyright (C) 2011 Marien Fressinaud -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# ***** END LICENSE BLOCK ***** - -/** - * La classe FrontController est le noyau du framework, elle lance l'application - * Elle est appelée en général dans le fichier index.php à la racine du serveur - */ -class FrontController { - protected $dispatcher; - protected $router; - - /** - * Constructeur - * Initialise le router et le dispatcher - */ - public function __construct () { - $this->loadLib (); - - if (LOG_PATH === false) { - $this->killApp ('Path doesn\'t exist : LOG_PATH'); - } - - try { - Configuration::init (); - - Request::init (); - - $this->router = new Router (); - $this->router->init (); - } catch (RouteNotFoundException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - Error::error ( - 404, - array ('error' => array ($e->getMessage ())) - ); - } catch (MinzException $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $this->killApp ($e->getMessage ()); - } - - $this->dispatcher = Dispatcher::getInstance ($this->router); - } - - /** - * Inclue les fichiers de la librairie - */ - private function loadLib () { - require ('ActionController.php'); - require ('Minz_Cache.php'); - require ('Configuration.php'); - require ('Dispatcher.php'); - require ('Error.php'); - require ('Helper.php'); - require ('Minz_Log.php'); - require ('Model.php'); - require ('Paginator.php'); - require ('Request.php'); - require ('Response.php'); - require ('Router.php'); - require ('Session.php'); - require ('Translate.php'); - require ('Url.php'); - require ('View.php'); - - require ('dao/Model_pdo.php'); - require ('dao/Model_txt.php'); - require ('dao/Model_array.php'); - - require ('exceptions/MinzException.php'); - } - - /** - * Démarre l'application (lance le dispatcher et renvoie la réponse - */ - public function run () { - try { - $this->dispatcher->run (); - Response::send (); - } catch (MinzException $e) { - try { - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - } catch (PermissionDeniedException $e) { - $this->killApp ($e->getMessage ()); - } - - if ($e instanceof FileNotExistException || - $e instanceof ControllerNotExistException || - $e instanceof ControllerNotActionControllerException || - $e instanceof ActionException) { - Error::error ( - 404, - array ('error' => array ($e->getMessage ())), - true - ); - } else { - $this->killApp (); - } - } - } - - /** - * Permet d'arrêter le programme en urgence - */ - private function killApp ($txt = '') { - if ($txt == '') { - $txt = 'See logs files'; - } - exit ('### Application problem ###<br />'."\n".$txt); - } -} diff --git a/lib/minz/Helper.php b/lib/minz/Helper.php deleted file mode 100755 index 4f64ba218..000000000 --- a/lib/minz/Helper.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Helper représente une aide pour des tâches récurrentes - */ -class Helper { - /** - * Annule les effets des magic_quotes pour une variable donnée - * @param $var variable à traiter (tableau ou simple variable) - */ - public static function stripslashes_r ($var) { - if (is_array ($var)){ - return array_map (array ('Helper', 'stripslashes_r'), $var); - } else { - return stripslashes($var); - } - } -} diff --git a/lib/minz/Minz_Cache.php b/lib/minz/Minz_Cache.php deleted file mode 100644 index 6848e3350..000000000 --- a/lib/minz/Minz_Cache.php +++ /dev/null @@ -1,116 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Cache permet de gérer facilement les pages en cache - */ -class Minz_Cache { - /** - * $expire timestamp auquel expire le cache de $url - */ - private $expire = 0; - - /** - * $file est le nom du fichier de cache - */ - private $file = ''; - - /** - * $enabled permet de déterminer si le cache est activé - */ - private static $enabled = true; - - /** - * Constructeur - */ - public function __construct () { - $this->_fileName (); - $this->_expire (); - } - - /** - * Setteurs - */ - public function _fileName () { - $file = md5 (Request::getURI ()); - - $this->file = CACHE_PATH . '/'.$file; - } - - public function _expire () { - if ($this->exist ()) { - $this->expire = filemtime ($this->file) - + Configuration::delayCache (); - } - } - - /** - * Permet de savoir si le cache est activé - * @return true si activé, false sinon - */ - public static function isEnabled () { - return Configuration::cacheEnabled () && self::$enabled; - } - - /** - * Active / désactive le cache - */ - public static function switchOn () { - self::$enabled = true; - } - public static function switchOff () { - self::$enabled = false; - } - - /** - * Détermine si le cache de $url a expiré ou non - * @return true si il a expiré, false sinon - */ - public function expired () { - return time () > $this->expire; - } - - /** - * Affiche le contenu du cache - * @print le code html du cache - */ - public function render () { - if ($this->exist ()) { - include ($this->file); - } - } - - /** - * Enregistre $html en cache - * @param $html le html à mettre en cache - */ - public function cache ($html) { - file_put_contents ($this->file, $html); - } - - /** - * Permet de savoir si le cache existe - * @return true si il existe, false sinon - */ - public function exist () { - return file_exists ($this->file); - } - - /** - * Nettoie le cache en supprimant tous les fichiers - */ - public static function clean () { - $files = opendir (CACHE_PATH); - - while ($fic = readdir ($files)) { - if ($fic != '.' && $fic != '..') { - unlink (CACHE_PATH.'/'.$fic); - } - } - - closedir ($files); - } -} diff --git a/lib/minz/Minz_Log.php b/lib/minz/Minz_Log.php deleted file mode 100644 index 153870435..000000000 --- a/lib/minz/Minz_Log.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Log permet de logger des erreurs - */ -class Minz_Log { - /** - * Les différents niveau de log - * ERROR erreurs bloquantes de l'application - * WARNING erreurs pouvant géner le bon fonctionnement, mais non bloquantes - * NOTICE messages d'informations, affichés pour le déboggage - */ - const ERROR = 0; - const WARNING = 10; - const NOTICE = 20; - - /** - * Enregistre un message dans un fichier de log spécifique - * Message non loggué si - * - environment = SILENT - * - level = WARNING et environment = PRODUCTION - * - level = NOTICE et environment = PRODUCTION - * @param $information message d'erreur / information à enregistrer - * @param $level niveau d'erreur - * @param $file_name fichier de log, par défaut LOG_PATH/application.log - */ - public static function record ($information, $level, $file_name = null) { - $env = Configuration::environment (); - - if (! ($env == Configuration::SILENT - || ($env == Configuration::PRODUCTION - && ($level == Minz_Log::WARNING || $level == Minz_Log::NOTICE)))) { - if (is_null ($file_name)) { - $file_name = LOG_PATH . '/application.log'; - } - - switch ($level) { - case Minz_Log::ERROR : - $level_label = 'error'; - break; - case Minz_Log::WARNING : - $level_label = 'warning'; - break; - case Minz_Log::NOTICE : - $level_label = 'notice'; - break; - default : - $level_label = 'unknown'; - } - - if ($env == Configuration::PRODUCTION) { - $file = @fopen ($file_name, 'a'); - } else { - $file = fopen ($file_name, 'a'); - } - - if ($file !== false) { - $log = '[' . date('r') . ']'; - $log .= ' [' . $level_label . ']'; - $log .= ' --- ' . $information . "\n"; - fwrite ($file, $log); - fclose ($file); - } else { - throw new PermissionDeniedException ( - $file_name, - MinzException::ERROR - ); - } - } - } - - /** - * Automatise le log des variables globales $_GET et $_POST - * Fait appel à la fonction record(...) - * Ne fonctionne qu'en environnement "development" - * @param $file_name fichier de log, par défaut LOG_PATH/application.log - */ - public static function recordRequest($file_name = null) { - $msg_get = str_replace("\n", '', '$_GET content : ' . print_r($_GET, true)); - $msg_post = str_replace("\n", '', '$_POST content : ' . print_r($_POST, true)); - - self::record($msg_get, Minz_Log::NOTICE, $file_name); - self::record($msg_post, Minz_Log::NOTICE, $file_name); - } -} diff --git a/lib/minz/Model.php b/lib/minz/Model.php deleted file mode 100755 index 37fc19ed1..000000000 --- a/lib/minz/Model.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Model représente un modèle de l'application (représentation MVC) - */ -class Model { - -} diff --git a/lib/minz/Paginator.php b/lib/minz/Paginator.php deleted file mode 100755 index 1a8376e75..000000000 --- a/lib/minz/Paginator.php +++ /dev/null @@ -1,196 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Paginator permet de gérer la pagination de l'application facilement - */ -class Paginator { - /** - * $items tableau des éléments à afficher/gérer - */ - private $items = array (); - - /** - * $nbItemsPerPage le nombre d'éléments par page - */ - private $nbItemsPerPage = 10; - - /** - * $currentPage page actuelle à gérer - */ - private $currentPage = 1; - - /** - * $nbPage le nombre de pages de pagination - */ - private $nbPage = 1; - - /** - * $nbItems le nombre d'éléments - */ - private $nbItems = 0; - - /** - * Constructeur - * @param $items les éléments à gérer - */ - public function __construct ($items) { - $this->_items ($items); - $this->_nbItems (count ($this->items (true))); - $this->_nbItemsPerPage ($this->nbItemsPerPage); - $this->_currentPage ($this->currentPage); - } - - /** - * Permet d'afficher la pagination - * @param $view nom du fichier de vue situé dans /app/views/helpers/ - * @param $getteur variable de type $_GET[] permettant de retrouver la page - */ - public function render ($view, $getteur) { - $view = APP_PATH . '/views/helpers/'.$view; - - if (file_exists ($view)) { - include ($view); - } - } - - /** - * Permet de retrouver la page d'un élément donné - * @param $item l'élément à retrouver - * @return la page à laquelle se trouve l'élément (false si non trouvé) - */ - public function pageByItem ($item) { - $page = false; - $i = 0; - - do { - if ($item == $this->items[$i]) { - $page = ceil (($i + 1) / $this->nbItemsPerPage); - } - - $i++; - } while (!$page && $i < $this->nbItems ()); - - return $page; - } - - /** - * Permet de retrouver la position d'un élément donné (à partir de 0) - * @param $item l'élément à retrouver - * @return la position à laquelle se trouve l'élément (false si non trouvé) - */ - public function positionByItem ($item) { - $find = false; - $i = 0; - - do { - if ($item == $this->items[$i]) { - $find = true; - } else { - $i++; - } - } while (!$find && $i < $this->nbItems ()); - - return $i; - } - - /** - * Permet de récupérer un item par sa position - * @param $pos la position de l'élément - * @return l'item situé à $pos (dernier item si $pos<0, 1er si $pos>=count($items)) - */ - public function itemByPosition ($pos) { - if ($pos < 0) { - $pos = $this->nbItems () - 1; - } - if ($pos >= count($this->items)) { - $pos = 0; - } - - return $this->items[$pos]; - } - - /** - * GETTEURS - */ - /** - * @param $all si à true, retourne tous les éléments sans prendre en compte la pagination - */ - public function items ($all = false) { - $array = array (); - $nbItems = $this->nbItems (); - - if ($nbItems <= $this->nbItemsPerPage || $all) { - $array = $this->items; - } else { - $begin = ($this->currentPage - 1) * $this->nbItemsPerPage; - $counter = 0; - $i = 0; - - foreach ($this->items as $key => $item) { - if ($i >= $begin) { - $array[$key] = $item; - $counter++; - } - if ($counter >= $this->nbItemsPerPage) { - break; - } - $i++; - } - } - - return $array; - } - public function nbItemsPerPage () { - return $this->nbItemsPerPage; - } - public function currentPage () { - return $this->currentPage; - } - public function nbPage () { - return $this->nbPage; - } - public function nbItems () { - return $this->nbItems; - } - - /** - * SETTEURS - */ - public function _items ($items) { - if (is_array ($items)) { - $this->items = $items; - } - - $this->_nbPage (); - } - public function _nbItemsPerPage ($nbItemsPerPage) { - if ($nbItemsPerPage > $this->nbItems ()) { - $nbItemsPerPage = $this->nbItems (); - } - if ($nbItemsPerPage < 0) { - $nbItemsPerPage = 0; - } - - $this->nbItemsPerPage = $nbItemsPerPage; - $this->_nbPage (); - } - public function _currentPage ($page) { - if($page < 1 || ($page > $this->nbPage && $this->nbPage > 0)) { - throw new CurrentPagePaginationException ($page); - } - - $this->currentPage = $page; - } - private function _nbPage () { - if ($this->nbItemsPerPage > 0) { - $this->nbPage = ceil ($this->nbItems () / $this->nbItemsPerPage); - } - } - public function _nbItems ($value) { - $this->nbItems = $value; - } -} diff --git a/lib/minz/Request.php b/lib/minz/Request.php deleted file mode 100644 index ffddbe6ad..000000000 --- a/lib/minz/Request.php +++ /dev/null @@ -1,196 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * Request représente la requête http - */ -class Request { - private static $controller_name = ''; - private static $action_name = ''; - private static $params = array (); - - private static $default_controller_name = 'index'; - private static $default_action_name = 'index'; - - public static $reseted = true; - - /** - * Getteurs - */ - public static function controllerName () { - return self::$controller_name; - } - public static function actionName () { - return self::$action_name; - } - public static function params () { - return self::$params; - } - public static function param ($key, $default = false, $specialchars = false) { - if (isset (self::$params[$key])) { - $p = self::$params[$key]; - if(is_object($p) || $specialchars) { - return $p; - } elseif(is_array($p)) { - return array_map('htmlspecialchars', $p); //TODO: Should use explicit UTF-8 - } else { - return htmlspecialchars($p, ENT_NOQUOTES, 'UTF-8'); - } - } else { - return $default; - } - } - public static function defaultControllerName () { - return self::$default_controller_name; - } - public static function defaultActionName () { - return self::$default_action_name; - } - - /** - * Setteurs - */ - public static function _controllerName ($controller_name) { - self::$controller_name = $controller_name; - } - public static function _actionName ($action_name) { - self::$action_name = $action_name; - } - public static function _params ($params) { - if (!is_array($params)) { - $params = array ($params); - } - - self::$params = $params; - } - public static function _param ($key, $value = false) { - if ($value === false) { - unset (self::$params[$key]); - } else { - self::$params[$key] = $value; - } - } - - /** - * Initialise la Request - */ - public static function init () { - self::magicQuotesOff (); - } - - /** - * Retourn le nom de domaine du site - */ - public static function getDomainName () { - return $_SERVER['HTTP_HOST']; - } - - /** - * Détermine la base de l'url - * @return la base de l'url - */ - public static function getBaseUrl () { - return Configuration::baseUrl (); - } - - /** - * Récupère l'URI de la requête - * @return l'URI - */ - public static function getURI () { - if (isset ($_SERVER['REQUEST_URI'])) { - $base_url = self::getBaseUrl (); - $uri = $_SERVER['REQUEST_URI']; - - $len_base_url = strlen ($base_url); - $real_uri = substr ($uri, $len_base_url); - } else { - $real_uri = ''; - } - - return $real_uri; - } - - /** - * Relance une requête - * @param $url l'url vers laquelle est relancée la requête - * @param $redirect si vrai, force la redirection http - * > sinon, le dispatcher recharge en interne - */ - public static function forward ($url = array (), $redirect = false) { - $url = Url::checkUrl ($url); - - if ($redirect) { - header ('Location: ' . Url::display ($url, 'php')); - exit (); - } else { - self::$reseted = true; - - self::_controllerName ($url['c']); - self::_actionName ($url['a']); - self::_params (array_merge ( - self::$params, - $url['params'] - )); - } - } - - /** - * Permet de récupérer une variable de type $_GET - * @param $param nom de la variable - * @param $default valeur par défaut à attribuer à la variable - * @return $_GET[$param] - * $_GET si $param = false - * $default si $_GET[$param] n'existe pas - */ - public static function fetchGET ($param = false, $default = false) { - if ($param === false) { - return $_GET; - } elseif (isset ($_GET[$param])) { - return $_GET[$param]; - } else { - return $default; - } - } - - /** - * Permet de récupérer une variable de type $_POST - * @param $param nom de la variable - * @param $default valeur par défaut à attribuer à la variable - * @return $_POST[$param] - * $_POST si $param = false - * $default si $_POST[$param] n'existe pas - */ - public static function fetchPOST ($param = false, $default = false) { - if ($param === false) { - return $_POST; - } elseif (isset ($_POST[$param])) { - return $_POST[$param]; - } else { - return $default; - } - } - - /** - * Méthode désactivant les magic_quotes pour les variables - * $_GET - * $_POST - * $_COOKIE - */ - private static function magicQuotesOff () { - if (get_magic_quotes_gpc ()) { - $_GET = Helper::stripslashes_r ($_GET); - $_POST = Helper::stripslashes_r ($_POST); - $_COOKIE = Helper::stripslashes_r ($_COOKIE); - } - } - - public static function isPost () { - return !empty ($_POST) || !empty ($_FILES); - } -} - - diff --git a/lib/minz/Response.php b/lib/minz/Response.php deleted file mode 100644 index fcf53c5b1..000000000 --- a/lib/minz/Response.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * Response représente la requête http renvoyée à l'utilisateur - */ -class Response { - private static $header = 'HTTP/1.0 200 OK'; - private static $body = ''; - - /** - * Mets à jour le body de la Response - * @param $text le texte à incorporer dans le body - */ - public static function setBody ($text) { - self::$body = $text; - } - - /** - * Mets à jour le header de la Response - * @param $code le code HTTP, valeurs possibles - * - 200 (OK) - * - 403 (Forbidden) - * - 404 (Forbidden) - * - 500 (Forbidden) -> par défaut si $code erroné - * - 503 (Forbidden) - */ - public static function setHeader ($code) { - switch ($code) { - case 200 : - self::$header = 'HTTP/1.0 200 OK'; - break; - case 403 : - self::$header = 'HTTP/1.0 403 Forbidden'; - break; - case 404 : - self::$header = 'HTTP/1.0 404 Not Found'; - break; - case 500 : - self::$header = 'HTTP/1.0 500 Internal Server Error'; - break; - case 503 : - self::$header = 'HTTP/1.0 503 Service Unavailable'; - break; - default : - self::$header = 'HTTP/1.0 500 Internal Server Error'; - } - } - - /** - * Envoie la Response à l'utilisateur - */ - public static function send () { - header (self::$header); - echo self::$body; - } -} diff --git a/lib/minz/Router.php b/lib/minz/Router.php deleted file mode 100755 index c5d6f5baa..000000000 --- a/lib/minz/Router.php +++ /dev/null @@ -1,209 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Router gère le routage de l'application - * Les routes sont définies dans APP_PATH.'/configuration/routes.php' - */ -class Router { - const ROUTES_PATH_NAME = '/configuration/routes.php'; - - private $routes = array (); - - /** - * Constructeur - * @exception FileNotExistException si ROUTES_PATH_NAME n'existe pas - * et que l'on utilise l'url rewriting - */ - public function __construct () { - if (Configuration::useUrlRewriting ()) { - if (file_exists (APP_PATH . self::ROUTES_PATH_NAME)) { - $routes = include ( - APP_PATH . self::ROUTES_PATH_NAME - ); - - if (!is_array ($routes)) { - $routes = array (); - } - - $this->routes = array_map ( - array ('Url', 'checkUrl'), - $routes - ); - } else { - throw new FileNotExistException ( - self::ROUTES_PATH_NAME, - MinzException::ERROR - ); - } - } - } - - /** - * Initialise le Router en déterminant le couple Controller / Action - * Mets à jour la Request - * @exception RouteNotFoundException si l'uri n'est pas présente dans - * > la table de routage - */ - public function init () { - $url = array (); - - if (Configuration::useUrlRewriting ()) { - try { - $url = $this->buildWithRewriting (); - } catch (RouteNotFoundException $e) { - throw $e; - } - } else { - $url = $this->buildWithoutRewriting (); - } - - $url['params'] = array_merge ( - $url['params'], - Request::fetchPOST () - ); - - Request::forward ($url); - } - - /** - * Retourne un tableau représentant l'url passée par la barre d'adresses - * Ne se base PAS sur la table de routage - * @return tableau représentant l'url - */ - public function buildWithoutRewriting () { - $url = array (); - - $url['c'] = Request::fetchGET ( - 'c', - Request::defaultControllerName () - ); - $url['a'] = Request::fetchGET ( - 'a', - Request::defaultActionName () - ); - $url['params'] = Request::fetchGET (); - - // post-traitement - unset ($url['params']['c']); - unset ($url['params']['a']); - - return $url; - } - - /** - * Retourne un tableau représentant l'url passée par la barre d'adresses - * Se base sur la table de routage - * @return tableau représentant l'url - * @exception RouteNotFoundException si l'uri n'est pas présente dans - * > la table de routage - */ - public function buildWithRewriting () { - $url = array (); - $uri = Request::getURI (); - $find = false; - - foreach ($this->routes as $route) { - $regex = '*^' . $route['route'] . '$*'; - if (preg_match ($regex, $uri, $matches)) { - $url['c'] = $route['controller']; - $url['a'] = $route['action']; - $url['params'] = $this->getParams ( - $route['params'], - $matches - ); - $find = true; - break; - } - } - - if (!$find && $uri != '/') { - throw new RouteNotFoundException ( - $uri, - MinzException::ERROR - ); - } - - // post-traitement - $url = Url::checkUrl ($url); - - return $url; - } - - /** - * Retourne l'uri d'une url en se basant sur la table de routage - * @param l'url sous forme de tableau - * @return l'uri formatée (string) selon une route trouvée - */ - public function printUriRewrited ($url) { - $route = $this->searchRoute ($url); - - if ($route !== false) { - return $this->replaceParams ($route, $url['params']); - } - - return ''; - } - - /** - * Recherche la route correspondante à une url - * @param l'url sous forme de tableau - * @return la route telle que spécifiée dans la table de routage, - * false si pas trouvée - */ - public function searchRoute ($url) { - foreach ($this->routes as $route) { - if ($route['controller'] == $url['c'] - && $route['action'] == $url['a']) { - // calcule la différence des tableaux de params - $params = array_flip ($route['params']); - $difference_params = array_diff_key ( - $params, - $url['params'] - ); - - // vérifie que pas de différence - // et le cas où $params est vide et pas $url['params'] - if (empty ($difference_params) - && (!empty ($params) || empty ($url['params']))) { - return $route; - } - } - } - - return false; - } - - /** - * Récupère un tableau dont - * - les clés sont définies dans $params_route - * - les valeurs sont situées dans $matches - * Le tableau $matches est décalé de +1 par rapport à $params_route - */ - private function getParams($params_route, $matches) { - $params = array (); - - for ($i = 0; $i < count ($params_route); $i++) { - $param = $params_route[$i]; - $params[$param] = $matches[$i + 1]; - } - - return $params; - } - - /** - * Remplace les éléments de la route par les valeurs contenues dans $params - */ - private function replaceParams ($route, $params_replace) { - $uri = $route['route']; - $params = array(); - foreach($route['params'] as $param) { - $uri = preg_replace('#\((.+)\)#U', $params_replace[$param], $uri, 1); - } - - return stripslashes($uri); - } -} diff --git a/lib/minz/Session.php b/lib/minz/Session.php deleted file mode 100755 index f9c9c6754..000000000 --- a/lib/minz/Session.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -/** - * La classe Session gère la session utilisateur - * C'est un singleton - */ -class Session { - /** - * $session stocke les variables de session - */ - private static $session = array (); - - /** - * Initialise la session - */ - public static function init () { - // démarre la session - session_name (md5 (Configuration::selApplication ())); - session_start (); - - if (isset ($_SESSION)) { - self::$session = $_SESSION; - } - } - - - /** - * Permet de récupérer une variable de session - * @param $p le paramètre à récupérer - * @return la valeur de la variable de session, false si n'existe pas - */ - public static function param ($p, $default = false) { - if (isset (self::$session[$p])) { - $return = self::$session[$p]; - } else { - $return = $default; - } - - return $return; - } - - - /** - * Permet de créer ou mettre à jour une variable de session - * @param $p le paramètre à créer ou modifier - * @param $v la valeur à attribuer, false pour supprimer - */ - public static function _param ($p, $v = false) { - if ($v === false) { - unset ($_SESSION[$p]); - unset (self::$session[$p]); - } else { - $_SESSION[$p] = $v; - self::$session[$p] = $v; - - if($p == 'language') { - // reset pour remettre à jour le fichier de langue à utiliser - Translate::reset (); - } - } - } - - - /** - * Permet d'effacer une session - * @param $force si à false, n'efface pas le paramètre de langue - */ - public static function unset_session ($force = false) { - $language = self::param ('language'); - - session_unset (); - self::$session = array (); - - if (!$force) { - self::_param ('language', $language); - } - } -} diff --git a/lib/minz/Translate.php b/lib/minz/Translate.php deleted file mode 100644 index e8cbe4852..000000000 --- a/lib/minz/Translate.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> - */ - -/** - * La classe Translate se charge de la traduction - * Utilise les fichiers du répertoire /app/i18n/ - */ -class Translate { - /** - * $language est la langue à afficher - */ - private static $language; - - /** - * $translates est le tableau de correspondance - * $key => $traduction - */ - private static $translates = array (); - - /** - * Inclus le fichier de langue qui va bien - * l'enregistre dans $translates - */ - public static function init () { - $l = Configuration::language (); - self::$language = Session::param ('language', $l); - - $l_path = APP_PATH . '/i18n/' . self::$language . '.php'; - - if (file_exists ($l_path)) { - self::$translates = include ($l_path); - } - } - - /** - * Alias de init - */ - public static function reset () { - self::init (); - } - - /** - * Traduit une clé en sa valeur du tableau $translates - * @param $key la clé à traduire - * @return la valeur correspondante à la clé - * > si non présente dans le tableau, on retourne la clé elle-même - */ - public static function t ($key) { - $translate = $key; - - if (isset (self::$translates[$key])) { - $translate = self::$translates[$key]; - } - - $args = func_get_args (); - unset($args[0]); - - return vsprintf ($translate, $args); - } - - /** - * Retourne la langue utilisée actuellement - * @return la langue - */ - public static function language () { - return self::$language; - } -} diff --git a/lib/minz/Url.php b/lib/minz/Url.php deleted file mode 100755 index ce051ebd9..000000000 --- a/lib/minz/Url.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php - -/** - * La classe Url permet de gérer les URL à travers MINZ - */ -class Url { - /** - * Affiche une Url formatée selon que l'on utilise l'url_rewriting ou non - * si oui, on cherche dans la table de routage la correspondance pour formater - * @param $url l'url à formater définie comme un tableau : - * $url['c'] = controller - * $url['a'] = action - * $url['params'] = tableau des paramètres supplémentaires - * $url['protocol'] = protocole à utiliser (http par défaut) - * ou comme une chaîne de caractère - * @param $encodage pour indiquer comment encoder les & (& ou & pour html) - * @return l'url formatée - */ - public static function display ($url = array (), $encodage = 'html', $absolute = false) { - $url = self::checkUrl ($url); - - $url_string = ''; - - if ($absolute) { - if (is_array ($url) && isset ($url['protocol'])) { - $protocol = $url['protocol']; - } elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { - $protocol = 'https:'; - } else { - $protocol = 'http:'; - } - $url_string = $protocol . '//' . Request::getDomainName () . Request::getBaseUrl (); - } - else { - $url_string = '.'; - } - - if (is_array ($url)) { - $router = new Router (); - - if (Configuration::useUrlRewriting ()) { - $url_string .= $router->printUriRewrited ($url); - } else { - $url_string .= self::printUri ($url, $encodage); - } - } else { - $url_string .= $url; - } - - return $url_string; - } - - /** - * Construit l'URI d'une URL sans url rewriting - * @param l'url sous forme de tableau - * @param $encodage pour indiquer comment encoder les & (& ou & pour html) - * @return l'uri sous la forme ?key=value&key2=value2 - */ - private static function printUri ($url, $encodage) { - $uri = ''; - $separator = '/?'; - - if($encodage == 'html') { - $and = '&'; - } else { - $and = '&'; - } - - if (isset ($url['c']) - && $url['c'] != Request::defaultControllerName ()) { - $uri .= $separator . 'c=' . $url['c']; - $separator = $and; - } - - if (isset ($url['a']) - && $url['a'] != Request::defaultActionName ()) { - $uri .= $separator . 'a=' . $url['a']; - $separator = $and; - } - - if (isset ($url['params'])) { - foreach ($url['params'] as $key => $param) { - $uri .= $separator . $key . '=' . $param; - $separator = $and; - } - } - - return $uri; - } - - /** - * Vérifie que les éléments du tableau représentant une url soit ok - * @param l'url sous forme de tableau (sinon renverra directement $url) - * @return l'url vérifié - */ - public static function checkUrl ($url) { - $url_checked = $url; - - if (is_array ($url)) { - if (!isset ($url['c'])) { - $url_checked['c'] = Request::defaultControllerName (); - } - if (!isset ($url['a'])) { - $url_checked['a'] = Request::defaultActionName (); - } - if (!isset ($url['params'])) { - $url_checked['params'] = array (); - } - } - - return $url_checked; - } -} - -function _url ($controller, $action) { - $nb_args = func_num_args (); - - if($nb_args < 2 || $nb_args % 2 != 0) { - return false; - } - - $args = func_get_args (); - $params = array (); - for($i = 2; $i < $nb_args; $i = $i + 2) { - $params[$args[$i]] = $args[$i + 1]; - } - - return Url::display (array ('c' => $controller, 'a' => $action, 'params' => $params)); -} diff --git a/lib/minz/View.php b/lib/minz/View.php deleted file mode 100755 index fd92762b3..000000000 --- a/lib/minz/View.php +++ /dev/null @@ -1,240 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe View représente la vue de l'application - */ -class View { - const VIEWS_PATH_NAME = '/views'; - const LAYOUT_PATH_NAME = '/layout'; - const LAYOUT_FILENAME = '/layout.phtml'; - - private $view_filename = ''; - private $use_layout = false; - - private static $title = ''; - private static $styles = array (); - private static $scripts = array (); - - private static $params = array (); - - /** - * Constructeur - * Détermine si on utilise un layout ou non - */ - public function __construct () { - $this->view_filename = APP_PATH - . self::VIEWS_PATH_NAME . '/' - . Request::controllerName () . '/' - . Request::actionName () . '.phtml'; - - if (file_exists (APP_PATH - . self::LAYOUT_PATH_NAME - . self::LAYOUT_FILENAME)) { - $this->use_layout = true; - } - - self::$title = Configuration::title (); - } - - /** - * Construit la vue - */ - public function build () { - if ($this->use_layout) { - $this->buildLayout (); - } else { - $this->render (); - } - } - - /** - * Construit le layout - */ - public function buildLayout () { - include ( - APP_PATH - . self::LAYOUT_PATH_NAME - . self::LAYOUT_FILENAME - ); - } - - /** - * Affiche la Vue en elle-même - */ - public function render () { - if (file_exists ($this->view_filename)) { - include ($this->view_filename); - } else { - Minz_Log::record ('File doesn\'t exist : `' - . $this->view_filename . '`', - Minz_Log::NOTICE); - } - } - - /** - * Ajoute un élément du layout - * @param $part l'élément partial à ajouter - */ - public function partial ($part) { - $fic_partial = APP_PATH - . self::LAYOUT_PATH_NAME . '/' - . $part . '.phtml'; - - if (file_exists ($fic_partial)) { - include ($fic_partial); - } else { - Minz_Log::record ('File doesn\'t exist : `' - . $fic_partial . '`', - Minz_Log::WARNING); - } - } - - /** - * Affiche un élément graphique situé dans APP./views/helpers/ - * @param $helper l'élément à afficher - */ - public function renderHelper ($helper) { - $fic_helper = APP_PATH - . '/views/helpers/' - . $helper . '.phtml'; - - if (file_exists ($fic_helper)) { - include ($fic_helper); - } else { - Minz_Log::record ('File doesn\'t exist : `' - . $fic_helper . '`', - Minz_Log::WARNING); - } - } - - /** - * Permet de choisir si on souhaite utiliser le layout - * @param $use true si on souhaite utiliser le layout, false sinon - */ - public function _useLayout ($use) { - $this->use_layout = $use; - } - - /** - * Gestion du titre - */ - public static function title () { - return self::$title; - } - public static function headTitle () { - return '<title>' . self::$title . '</title>' . "\n"; - } - public static function _title ($title) { - self::$title = $title; - } - public static function prependTitle ($title) { - self::$title = $title . self::$title; - } - public static function appendTitle ($title) { - self::$title = self::$title . $title; - } - - /** - * Gestion des feuilles de style - */ - public static function headStyle () { - $styles = ''; - - foreach(self::$styles as $style) { - $cond = $style['cond']; - if ($cond) { - $styles .= '<!--[if ' . $cond . ']>'; - } - - $styles .= '<link rel="stylesheet" media="' . $style['media'] - . '" href="' . $style['url'] . '" />'; - - if ($cond) { - $styles .= '<![endif]-->'; - } - - $styles .= "\n"; - } - - return $styles; - } - public static function prependStyle ($url, $media = 'all', $cond = false) { - array_unshift (self::$styles, array ( - 'url' => $url, - 'media' => $media, - 'cond' => $cond - )); - } - public static function appendStyle ($url, $media = 'all', $cond = false) { - self::$styles[] = array ( - 'url' => $url, - 'media' => $media, - 'cond' => $cond - ); - } - - /** - * Gestion des scripts JS - */ - public static function headScript () { - $scripts = ''; - - foreach (self::$scripts as $script) { - $cond = $script['cond']; - if ($cond) { - $scripts .= '<!--[if ' . $cond . ']>'; - } - - $scripts .= '<script src="' . $script['url'] . '"'; - if ($script['defer']) { - $scripts .= ' defer="defer"'; - } - if ($script['async']) { - $scripts .= ' async="async"'; - } - $scripts .= '></script>'; - - if ($cond) { - $scripts .= '<![endif]-->'; - } - - $scripts .= "\n"; - } - - return $scripts; - } - public static function prependScript ($url, $cond = false, $defer = true, $async = true) { - array_unshift(self::$scripts, array ( - 'url' => $url, - 'cond' => $cond, - 'defer' => $defer, - 'async' => $async, - )); - } - public static function appendScript ($url, $cond = false, $defer = true, $async = true) { - self::$scripts[] = array ( - 'url' => $url, - 'cond' => $cond, - 'defer' => $defer, - 'async' => $async, - ); - } - - /** - * Gestion des paramètres ajoutés à la vue - */ - public static function _param ($key, $value) { - self::$params[$key] = $value; - } - public function attributeParams () { - foreach (View::$params as $key => $value) { - $this->$key = $value; - } - } -} - - diff --git a/lib/minz/dao/Model_array.php b/lib/minz/dao/Model_array.php deleted file mode 100755 index 0b9ccf071..000000000 --- a/lib/minz/dao/Model_array.php +++ /dev/null @@ -1,122 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Model_array représente le modèle interragissant avec les fichiers de type texte gérant des tableaux php - */ -class Model_array extends Model_txt { - /** - * $array Le tableau php contenu dans le fichier $nameFile - */ - protected $array = array (); - - /** - * Ouvre le fichier indiqué, charge le tableau dans $array et le $nameFile - * @param $nameFile le nom du fichier à ouvrir contenant un tableau - * Remarque : $array sera obligatoirement un tableau - */ - public function __construct ($nameFile) { - parent::__construct ($nameFile); - - if (!$this->getLock ('read')) { - throw new PermissionDeniedException ($this->filename); - } else { - $this->array = include ($this->filename); - $this->releaseLock (); - - if (!is_array ($this->array)) { - $this->array = array (); - } - - $this->array = $this->decodeArray ($this->array); - } - } - - /** - * Écrit un tableau dans le fichier $nameFile - * @param $array le tableau php à enregistrer - **/ - public function writeFile ($array) { - if (!$this->getLock ('write')) { - throw new PermissionDeniedException ($this->namefile); - } else { - $this->erase (); - - $this->writeLine ('<?php'); - $this->writeLine ('return ', false); - $this->writeArray ($array); - $this->writeLine (';'); - - $this->releaseLock (); - } - } - - private function writeArray ($array, $profondeur = 0) { - $tab = ''; - for ($i = 0; $i < $profondeur; $i++) { - $tab .= "\t"; - } - $this->writeLine ('array ('); - - foreach ($array as $key => $value) { - if (is_int ($key)) { - $this->writeLine ($tab . "\t" . $key . ' => ', false); - } else { - $this->writeLine ($tab . "\t" . '\'' . $key . '\'' . ' => ', false); - } - - if (is_array ($value)) { - $this->writeArray ($value, $profondeur + 1); - $this->writeLine (','); - } else { - if (is_numeric ($value)) { - $this->writeLine ($value . ','); - } else { - $this->writeLine ('\'' . addslashes ($value) . '\','); - } - } - } - - $this->writeLine ($tab . ')', false); - } - - private function decodeArray ($array) { - $new_array = array (); - - foreach ($array as $key => $value) { - if (is_array ($value)) { - $new_array[$key] = $this->decodeArray ($value); - } else { - $new_array[$key] = stripslashes ($value); - } - } - - return $new_array; - } - - private function getLock ($type) { - if ($type == 'write') { - $lock = LOCK_EX; - } else { - $lock = LOCK_SH; - } - - $count = 1; - while (!flock ($this->file, $lock) && $count <= 50) { - $count++; - } - - if ($count >= 50) { - return false; - } else { - return true; - } - } - - private function releaseLock () { - flock ($this->file, LOCK_UN); - } -} diff --git a/lib/minz/dao/Model_pdo.php b/lib/minz/dao/Model_pdo.php deleted file mode 100755 index a91a4fa00..000000000 --- a/lib/minz/dao/Model_pdo.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Model_sql représente le modèle interragissant avec les bases de données - * Seul la connexion MySQL est prise en charge pour le moment - */ -class Model_pdo { - - /** - * Partage la connexion à la base de données entre toutes les instances. - */ - public static $useSharedBd = true; - private static $sharedBd = null; - private static $sharedPrefix; - - /** - * $bd variable représentant la base de données - */ - protected $bd; - - protected $prefix; - - /** - * Créé la connexion à la base de données à l'aide des variables - * HOST, BASE, USER et PASS définies dans le fichier de configuration - */ - public function __construct () { - if (self::$useSharedBd && self::$sharedBd != null) { - $this->bd = self::$sharedBd; - $this->prefix = self::$sharedPrefix; - return; - } - - $db = Configuration::dataBase (); - $driver_options = null; - - try { - $type = $db['type']; - if($type == 'mysql') { - $string = $type - . ':host=' . $db['host'] - . ';dbname=' . $db['base'] - . ';charset=utf8'; - $driver_options = array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' - ); - } elseif($type == 'sqlite') { - $string = $type - . ':/' . PUBLIC_PATH - . '/data/' . $db['base'] . '.sqlite'; //TODO: DEBUG UTF-8 http://www.siteduzero.com/forum/sujet/sqlite-connexion-utf-8-18797 - } - - $this->bd = new FreshPDO ( - $string, - $db['user'], - $db['password'], - $driver_options - ); - self::$sharedBd = $this->bd; - - $this->prefix = $db['prefix']; - self::$sharedPrefix = $this->prefix; - } catch (Exception $e) { - throw new PDOConnectionException ( - $string, - $db['user'], MinzException::WARNING - ); - } - } -} - -class FreshPDO extends PDO { - private static function check($statement) { - if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { - touch(PUBLIC_PATH . '/data/touch.txt'); - } - } - - public function prepare ($statement, $driver_options = array()) { - FreshPDO::check($statement); - return parent::prepare($statement, $driver_options); - } - - public function exec ($statement) { - FreshPDO::check($statement); - return parent::exec($statement); - } -} diff --git a/lib/minz/dao/Model_txt.php b/lib/minz/dao/Model_txt.php deleted file mode 100755 index aed653068..000000000 --- a/lib/minz/dao/Model_txt.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php -/** - * MINZ - Copyright 2011 Marien Fressinaud - * Sous licence AGPL3 <http://www.gnu.org/licenses/> -*/ - -/** - * La classe Model_txt représente le modèle interragissant avec les fichiers de type texte - */ -class Model_txt { - /** - * $file représente le fichier à ouvrir - */ - protected $file; - - /** - * $filename est le nom du fichier - */ - protected $filename; - - /** - * Ouvre un fichier dans $file - * @param $nameFile nom du fichier à ouvrir - * @param $mode mode d'ouverture du fichier ('a+' par défaut) - * @exception FileNotExistException si le fichier n'existe pas - * > ou ne peux pas être ouvert - */ - public function __construct ($nameFile, $mode = 'a+') { - $this->filename = $nameFile; - if (!file_exists($this->filename)) { - throw new FileNotExistException ( - $this->filename, - MinzException::WARNING - ); - } - - $this->file = @fopen ($this->filename, $mode); - - if (!$this->file) { - throw new PermissionDeniedException ( - $this->filename, - MinzException::WARNING - ); - } - } - - /** - * Lit une ligne de $file - * @return une ligne du fichier - */ - public function readLine () { - return fgets ($this->file); - } - - /** - * Écrit une ligne dans $file - * @param $line la ligne à écrire - */ - public function writeLine ($line, $newLine = true) { - $char = ''; - if ($newLine) { - $char = "\n"; - } - - fwrite ($this->file, $line . $char); - } - - /** - * Efface le fichier $file - * @return true en cas de succès, false sinon - */ - public function erase () { - return ftruncate ($this->file, 0); - } - - /** - * Ferme $file - */ - public function __destruct () { - if (isset ($this->file)) { - fclose ($this->file); - } - } -} diff --git a/lib/minz/exceptions/MinzException.php b/lib/minz/exceptions/MinzException.php deleted file mode 100644 index 4568c4da8..000000000 --- a/lib/minz/exceptions/MinzException.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php - -class MinzException extends Exception { - const ERROR = 0; - const WARNING = 10; - const NOTICE = 20; - - public function __construct ($message, $code = self::ERROR) { - if ($code != MinzException::ERROR - && $code != MinzException::WARNING - && $code != MinzException::NOTICE) { - $code = MinzException::ERROR; - } - - parent::__construct ($message, $code); - } -} - -class PermissionDeniedException extends MinzException { - public function __construct ($file_name, $code = self::ERROR) { - $message = 'Permission is denied for `' . $file_name.'`'; - - parent::__construct ($message, $code); - } -} -class FileNotExistException extends MinzException { - public function __construct ($file_name, $code = self::ERROR) { - $message = 'File doesn\'t exist : `' . $file_name.'`'; - - parent::__construct ($message, $code); - } -} -class BadConfigurationException extends MinzException { - public function __construct ($part_missing, $code = self::ERROR) { - $message = '`' . $part_missing - . '` in the configuration file is missing or is misconfigured'; - - parent::__construct ($message, $code); - } -} -class ControllerNotExistException extends MinzException { - public function __construct ($controller_name, $code = self::ERROR) { - $message = 'Controller `' . $controller_name - . '` doesn\'t exist'; - - parent::__construct ($message, $code); - } -} -class ControllerNotActionControllerException extends MinzException { - public function __construct ($controller_name, $code = self::ERROR) { - $message = 'Controller `' . $controller_name - . '` isn\'t instance of ActionController'; - - parent::__construct ($message, $code); - } -} -class ActionException extends MinzException { - public function __construct ($controller_name, $action_name, $code = self::ERROR) { - $message = '`' . $action_name . '` cannot be invoked on `' - . $controller_name . '`'; - - parent::__construct ($message, $code); - } -} -class RouteNotFoundException extends MinzException { - private $route; - - public function __construct ($route, $code = self::ERROR) { - $this->route = $route; - - $message = 'Route `' . $route . '` not found'; - - parent::__construct ($message, $code); - } - - public function route () { - return $this->route; - } -} -class PDOConnectionException extends MinzException { - public function __construct ($string_connection, $user, $code = self::ERROR) { - $message = 'Access to database is denied for `' . $user . '`' - . ' (`' . $string_connection . '`)'; - - parent::__construct ($message, $code); - } -} -class CurrentPagePaginationException extends MinzException { - public function __construct ($page) { - $message = 'Page number `' . $page . '` doesn\'t exist'; - - parent::__construct ($message, self::ERROR); - } -} |
