aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Minz')
-rw-r--r--lib/Minz/ActionController.php6
-rw-r--r--lib/Minz/ActionException.php2
-rw-r--r--lib/Minz/Configuration.php32
-rw-r--r--lib/Minz/ControllerNotActionControllerException.php2
-rw-r--r--lib/Minz/ControllerNotExistException.php2
-rw-r--r--lib/Minz/CurrentPagePaginationException.php2
-rw-r--r--lib/Minz/Dispatcher.php2
-rw-r--r--lib/Minz/Extension.php2
-rw-r--r--lib/Minz/ExtensionManager.php36
-rw-r--r--lib/Minz/FileNotExistException.php2
-rw-r--r--lib/Minz/FrontController.php6
-rw-r--r--lib/Minz/Helper.php4
-rw-r--r--lib/Minz/Log.php39
-rw-r--r--lib/Minz/Model.php2
-rw-r--r--lib/Minz/ModelArray.php3
-rw-r--r--lib/Minz/ModelPdo.php124
-rw-r--r--lib/Minz/PDOConnectionException.php2
-rw-r--r--lib/Minz/Paginator.php8
-rw-r--r--lib/Minz/Request.php72
-rw-r--r--lib/Minz/Session.php17
-rw-r--r--lib/Minz/Translate.php4
-rw-r--r--lib/Minz/Url.php25
-rw-r--r--lib/Minz/View.php3
23 files changed, 245 insertions, 152 deletions
diff --git a/lib/Minz/ActionController.php b/lib/Minz/ActionController.php
index b47c54554..232a4ef9b 100644
--- a/lib/Minz/ActionController.php
+++ b/lib/Minz/ActionController.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* MINZ - Copyright 2011 Marien Fressinaud
* Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/
@@ -24,7 +24,7 @@ class Minz_ActionController {
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
@@ -34,5 +34,3 @@ class Minz_ActionController {
public function firstAction () { }
public function lastAction () { }
}
-
-
diff --git a/lib/Minz/ActionException.php b/lib/Minz/ActionException.php
index c566a076f..f1f70c1bc 100644
--- a/lib/Minz/ActionException.php
+++ b/lib/Minz/ActionException.php
@@ -3,7 +3,7 @@ class Minz_ActionException extends Minz_Exception {
public function __construct ($controller_name, $action_name, $code = self::ERROR) {
$message = '`' . $action_name . '` cannot be invoked on `'
. $controller_name . '`';
-
+
parent::__construct ($message, $code);
}
}
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index ab5bb4fc2..5470dc85f 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -39,7 +39,7 @@ class Minz_Configuration {
throw new Minz_FileNotExistException($filename);
}
- $data = @include($filename);
+ $data = include($filename);
if (is_array($data)) {
return $data;
} else {
@@ -85,11 +85,6 @@ class Minz_Configuration {
private $data = array();
/**
- * The default values, an empty array by default.
- */
- private $data_default = array();
-
- /**
* An object which help to set good values in configuration.
*/
private $configuration_setter = null;
@@ -109,7 +104,7 @@ class Minz_Configuration {
/**
* Create a new Minz_Configuration object.
- *
+ *
* @param $namespace the name of the current configuration.
* @param $config_filename the file containing configuration values.
* @param $default_filename the file containing default values, null by default.
@@ -119,21 +114,22 @@ class Minz_Configuration {
$configuration_setter = null) {
$this->namespace = $namespace;
$this->config_filename = $config_filename;
+ $this->default_filename = $default_filename;
+ $this->_configurationSetter($configuration_setter);
+
+ if (!is_null($this->default_filename)) {
+ $this->data = self::load($this->default_filename);
+ }
try {
- $this->data = self::load($this->config_filename);
+ $this->data = array_replace_recursive(
+ $this->data, self::load($this->config_filename)
+ );
} catch (Minz_FileNotExistException $e) {
- if (is_null($default_filename)) {
+ if (is_null($this->default_filename)) {
throw $e;
}
}
-
- $this->default_filename = $default_filename;
- if (!is_null($this->default_filename)) {
- $this->data_default = self::load($this->default_filename);
- }
-
- $this->_configurationSetter($configuration_setter);
}
/**
@@ -149,7 +145,7 @@ class Minz_Configuration {
/**
* Return the value of the given param.
- *
+ *
* @param $key the name of the param.
* @param $default default value to return if key does not exist.
* @return the value corresponding to the key.
@@ -160,8 +156,6 @@ class Minz_Configuration {
return $this->data[$key];
} elseif (!is_null($default)) {
return $default;
- } elseif (isset($this->data_default[$key])) {
- return $this->data_default[$key];
} else {
Minz_Log::warning($key . ' does not exist in configuration');
return null;
diff --git a/lib/Minz/ControllerNotActionControllerException.php b/lib/Minz/ControllerNotActionControllerException.php
index 535a1377e..1a8e0729c 100644
--- a/lib/Minz/ControllerNotActionControllerException.php
+++ b/lib/Minz/ControllerNotActionControllerException.php
@@ -3,7 +3,7 @@ class Minz_ControllerNotActionControllerException extends Minz_Exception {
public function __construct ($controller_name, $code = self::ERROR) {
$message = 'Controller `' . $controller_name
. '` isn\'t instance of ActionController';
-
+
parent::__construct ($message, $code);
}
}
diff --git a/lib/Minz/ControllerNotExistException.php b/lib/Minz/ControllerNotExistException.php
index 523867d11..24a09a635 100644
--- a/lib/Minz/ControllerNotExistException.php
+++ b/lib/Minz/ControllerNotExistException.php
@@ -3,7 +3,7 @@ class Minz_ControllerNotExistException extends Minz_Exception {
public function __construct ($controller_name, $code = self::ERROR) {
$message = 'Controller `' . $controller_name
. '` doesn\'t exist';
-
+
parent::__construct ($message, $code);
}
}
diff --git a/lib/Minz/CurrentPagePaginationException.php b/lib/Minz/CurrentPagePaginationException.php
index 74214d879..3e3d9d1b4 100644
--- a/lib/Minz/CurrentPagePaginationException.php
+++ b/lib/Minz/CurrentPagePaginationException.php
@@ -2,7 +2,7 @@
class Minz_CurrentPagePaginationException extends Minz_Exception {
public function __construct ($page) {
$message = 'Page number `' . $page . '` doesn\'t exist';
-
+
parent::__construct ($message, self::ERROR);
}
}
diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php
index 125ce5757..bdb1c76f6 100644
--- a/lib/Minz/Dispatcher.php
+++ b/lib/Minz/Dispatcher.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* MINZ - Copyright 2011 Marien Fressinaud
* Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php
index d7ee8fe81..78b8a2725 100644
--- a/lib/Minz/Extension.php
+++ b/lib/Minz/Extension.php
@@ -168,7 +168,7 @@ class Minz_Extension {
$url = '/ext.php?f=' . $file_name_url .
'&amp;t=' . $type .
'&amp;' . $mtime;
- return Minz_Url::display($url);
+ return Minz_Url::display($url, 'php');
}
/**
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index c5c68a8d4..02a99701f 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -94,8 +94,8 @@ class Minz_ExtensionManager {
* If the extension class name is `TestExtension`, entry point will be `Test`.
* `entry_point` must be composed of alphanumeric characters.
*
- * @param $meta is an array of values.
- * @return true if the array is valid, false else.
+ * @param array $meta is an array of values.
+ * @return bool true if the array is valid, false else.
*/
public static function isValidMetadata($meta) {
$valid_chars = array('_');
@@ -107,8 +107,8 @@ class Minz_ExtensionManager {
/**
* Load the extension source code based on info metadata.
*
- * @param $info an array containing information about extension.
- * @return an extension inheriting from Minz_Extension.
+ * @param array $info an array containing information about extension.
+ * @return Minz_Extension|null an extension inheriting from Minz_Extension.
*/
public static function load($info) {
$entry_point_filename = $info['path'] . '/' . self::$ext_entry_point;
@@ -127,9 +127,9 @@ class Minz_ExtensionManager {
$extension = null;
try {
$extension = new $ext_class_name($info);
- } catch (Minz_ExtensionException $e) {
+ } catch (Exception $e) {
// We cannot load the extension? Invalid!
- Minz_Log::warning('In `' . $metadata_filename . '`: ' . $e->getMessage());
+ Minz_Log::warning('Invalid extension `' . $ext_class_name . '`: ' . $e->getMessage());
return null;
}
@@ -149,7 +149,7 @@ class Minz_ExtensionManager {
* If the extension is present in $ext_auto_enabled and if its type is "system",
* it will be enabled in the same time.
*
- * @param $ext a valid extension.
+ * @param Minz_Extension $ext a valid extension.
*/
public static function register($ext) {
$name = $ext->getName();
@@ -168,7 +168,7 @@ class Minz_ExtensionManager {
*
* The extension init() method will be called.
*
- * @param $ext_name is the name of a valid extension present in $ext_list.
+ * @param Minz_Extension $ext_name is the name of a valid extension present in $ext_list.
*/
public static function enable($ext_name) {
if (isset(self::$ext_list[$ext_name])) {
@@ -182,7 +182,7 @@ class Minz_ExtensionManager {
/**
* Enable a list of extensions.
*
- * @param $ext_list the names of extensions we want to load.
+ * @param string[] $ext_list the names of extensions we want to load.
*/
public static function enableByList($ext_list) {
foreach ($ext_list as $ext_name) {
@@ -193,8 +193,8 @@ class Minz_ExtensionManager {
/**
* Return a list of extensions.
*
- * @param $only_enabled if true returns only the enabled extensions (false by default).
- * @return an array of extensions.
+ * @param bool $only_enabled if true returns only the enabled extensions (false by default).
+ * @return Minz_Extension[] an array of extensions.
*/
public static function listExtensions($only_enabled = false) {
if ($only_enabled) {
@@ -207,8 +207,8 @@ class Minz_ExtensionManager {
/**
* Return an extension by its name.
*
- * @param $ext_name the name of the extension.
- * @return the corresponding extension or null if it doesn't exist.
+ * @param string $ext_name the name of the extension.
+ * @return Minz_Extension|null the corresponding extension or null if it doesn't exist.
*/
public static function findExtension($ext_name) {
if (!isset(self::$ext_list[$ext_name])) {
@@ -224,9 +224,9 @@ class Minz_ExtensionManager {
* The hook name must be a valid one. For the valid list, see self::$hook_list
* array keys.
*
- * @param $hook_name the hook name (must exist).
- * @param $hook_function the function name to call (must be callable).
- * @param $ext the extension which register the hook.
+ * @param string $hook_name the hook name (must exist).
+ * @param callable $hook_function the function name to call (must be callable).
+ * @param Minz_Extension $ext the extension which register the hook.
*/
public static function addHook($hook_name, $hook_function, $ext) {
if (isset(self::$hook_list[$hook_name]) && is_callable($hook_function)) {
@@ -241,8 +241,8 @@ class Minz_ExtensionManager {
* The hook name must be a valid one. For the valid list, see self::$hook_list
* array keys.
*
- * @param $hook_name the hook to call.
- * @param additionnal parameters (for signature, please see self::$hook_list).
+ * @param string $hook_name the hook to call.
+ * @param additional parameters (for signature, please see self::$hook_list).
* @return the final result of the called hook.
*/
public static function callHook($hook_name) {
diff --git a/lib/Minz/FileNotExistException.php b/lib/Minz/FileNotExistException.php
index f8dfbdf66..f97f161af 100644
--- a/lib/Minz/FileNotExistException.php
+++ b/lib/Minz/FileNotExistException.php
@@ -2,7 +2,7 @@
class Minz_FileNotExistException extends Minz_Exception {
public function __construct ($file_name, $code = self::ERROR) {
$message = 'File not found: `' . $file_name.'`';
-
+
parent::__construct ($message, $code);
}
}
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index f9eff3db6..066278b7c 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -33,7 +33,7 @@ class Minz_FrontController {
try {
Minz_Configuration::register('system',
DATA_PATH . '/config.php',
- DATA_PATH . '/config.default.php');
+ FRESHRSS_PATH . '/config.default.php');
$this->setReporting();
Minz_Request::init();
@@ -119,12 +119,12 @@ class Minz_FrontController {
switch($conf->environment) {
case 'production':
error_reporting(E_ALL);
- ini_set('display_errors','Off');
+ ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');
break;
case 'development':
error_reporting(E_ALL);
- ini_set('display_errors','On');
+ ini_set('display_errors', 'On');
ini_set('log_errors', 'On');
break;
case 'silent':
diff --git a/lib/Minz/Helper.php b/lib/Minz/Helper.php
index f4a547c4e..c328d9e6b 100644
--- a/lib/Minz/Helper.php
+++ b/lib/Minz/Helper.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* MINZ - Copyright 2011 Marien Fressinaud
* Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/
@@ -13,7 +13,7 @@ class Minz_Helper {
* @param $var variable à traiter (tableau ou simple variable)
*/
public static function stripslashes_r($var) {
- if (is_array($var)){
+ if (is_array($var)) {
return array_map(array('Minz_Helper', 'stripslashes_r'), $var);
} else {
return stripslashes($var);
diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php
index 2a9e10993..5e7831cdb 100644
--- a/lib/Minz/Log.php
+++ b/lib/Minz/Log.php
@@ -29,6 +29,7 @@ class Minz_Log {
* @param $information message d'erreur / information à enregistrer
* @param $level niveau d'erreur
* @param $file_name fichier de log
+ * @throws Minz_PermissionDeniedException
*/
public static function record ($information, $level, $file_name = null) {
try {
@@ -42,7 +43,11 @@ class Minz_Log {
|| ($env === 'production'
&& ($level >= Minz_Log::NOTICE)))) {
if ($file_name === null) {
- $file_name = join_path(USERS_PATH, Minz_Session::param('currentUser', '_'), 'log.txt');
+ $username = Minz_Session::param('currentUser', '');
+ if ($username == '') {
+ $username = '_';
+ }
+ $file_name = join_path(USERS_PATH, $username, 'log.txt');
}
switch ($level) {
@@ -66,6 +71,8 @@ class Minz_Log {
. ' [' . $level_label . ']'
. ' --- ' . $information . "\n";
+ self::ensureMaxLogSize($file_name);
+
if (file_put_contents($file_name, $log, FILE_APPEND | LOCK_EX) === false) {
throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR);
}
@@ -73,6 +80,36 @@ class Minz_Log {
}
/**
+ * Make sure we do not waste a huge amount of disk space with old log messages.
+ *
+ * This method can be called multiple times for one script execution, but its result will not change unless
+ * you call clearstatcache() in between. We won't due do that for performance reasons.
+ *
+ * @param $file_name
+ * @throws Minz_PermissionDeniedException
+ */
+ protected static function ensureMaxLogSize($file_name) {
+ $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576;
+ if ($maxSize > 0 && @filesize($file_name) > $maxSize) {
+ $fp = fopen($file_name, 'c+');
+ if ($fp && flock($fp, LOCK_EX)) {
+ fseek($fp, -intval($maxSize / 2), SEEK_END);
+ $content = fread($fp, $maxSize);
+ rewind($fp);
+ ftruncate($fp, 0);
+ fwrite($fp, $content ? $content : '');
+ fflush($fp);
+ flock($fp, LOCK_UN);
+ } else {
+ throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR);
+ }
+ if ($fp) {
+ fclose($fp);
+ }
+ }
+ }
+
+ /**
* Automatise le log des variables globales $_GET et $_POST
* Fait appel à la fonction record(...)
* Ne fonctionne qu'en environnement "development"
diff --git a/lib/Minz/Model.php b/lib/Minz/Model.php
index adbaba942..1310888cf 100644
--- a/lib/Minz/Model.php
+++ b/lib/Minz/Model.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* MINZ - Copyright 2011 Marien Fressinaud
* Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/
diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php
index ff23dbc83..1ac2b313d 100644
--- a/lib/Minz/ModelArray.php
+++ b/lib/Minz/ModelArray.php
@@ -25,8 +25,7 @@ class Minz_ModelArray {
protected function loadArray() {
if (!file_exists($this->filename)) {
throw new Minz_FileNotExistException($this->filename, Minz_Exception::WARNING);
- }
- elseif (($handle = $this->getLock()) === false) {
+ } elseif (($handle = $this->getLock()) === false) {
throw new Minz_PermissionDeniedException($this->filename);
} else {
$data = include($this->filename);
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index ac7a1bed7..d769e0ff4 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -16,7 +16,6 @@ class Minz_ModelPdo {
public static $useSharedBd = true;
private static $sharedBd = null;
private static $sharedPrefix;
- private static $has_transaction = false;
private static $sharedCurrentUser;
protected static $sharedDbType;
@@ -37,57 +36,61 @@ class Minz_ModelPdo {
* HOST, BASE, USER et PASS définies dans le fichier de configuration
*/
public function __construct($currentUser = null) {
- if (self::$useSharedBd && self::$sharedBd != null && $currentUser === null) {
+ if ($currentUser === null) {
+ $currentUser = Minz_Session::param('currentUser');
+ }
+ if (self::$useSharedBd && self::$sharedBd != null &&
+ ($currentUser == null || $currentUser === self::$sharedCurrentUser)) {
$this->bd = self::$sharedBd;
$this->prefix = self::$sharedPrefix;
$this->current_user = self::$sharedCurrentUser;
return;
}
+ $this->current_user = $currentUser;
+ self::$sharedCurrentUser = $currentUser;
$conf = Minz_Configuration::get('system');
$db = $conf->db;
- if ($currentUser === null) {
- $currentUser = Minz_Session::param('currentUser', '_');
- }
- $this->current_user = $currentUser;
- self::$sharedCurrentUser = $currentUser;
+ $driver_options = isset($conf->db['pdo_options']) && is_array($conf->db['pdo_options']) ? $conf->db['pdo_options'] : array();
+ $dbServer = parse_url('db://' . $db['host']);
try {
- $type = $db['type'];
- if ($type === 'mysql') {
- $string = 'mysql:host=' . $db['host']
- . ';dbname=' . $db['base']
- . ';charset=utf8';
- $driver_options = array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
- );
- $this->prefix = $db['prefix'] . $currentUser . '_';
- } elseif ($type === 'sqlite') {
- $string = 'sqlite:' . join_path(DATA_PATH, 'users', $currentUser, 'db.sqlite');
- $driver_options = array(
- //PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- );
- $this->prefix = '';
- } else {
- throw new Minz_PDOConnectionException(
- 'Invalid database type!',
- $db['user'], Minz_Exception::ERROR
- );
- }
- self::$sharedDbType = $type;
- self::$sharedPrefix = $this->prefix;
-
- $this->bd = new MinzPDO(
- $string,
- $db['user'],
- $db['password'],
- $driver_options
- );
- if ($type === 'sqlite') {
- $this->bd->exec('PRAGMA foreign_keys = ON;');
+ switch ($db['type']) {
+ case 'mysql':
+ $string = 'mysql:host=' . $dbServer['host'] . ';dbname=' . $db['base'] . ';charset=utf8mb4';
+ if (!empty($dbServer['port'])) {
+ $string .= ';port=' . $dbServer['port'];
+ }
+ $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8mb4';
+ $this->prefix = $db['prefix'] . $currentUser . '_';
+ $this->bd = new MinzPDOMySql($string, $db['user'], $db['password'], $driver_options);
+ break;
+ case 'sqlite':
+ $string = 'sqlite:' . join_path(DATA_PATH, 'users', $currentUser, 'db.sqlite');
+ $this->prefix = '';
+ $this->bd = new MinzPDOMSQLite($string, $db['user'], $db['password'], $driver_options);
+ $this->bd->exec('PRAGMA foreign_keys = ON;');
+ break;
+ case 'pgsql':
+ $string = 'pgsql:host=' . $dbServer['host'] . ';dbname=' . $db['base'];
+ if (!empty($dbServer['port'])) {
+ $string .= ';port=' . $dbServer['port'];
+ }
+ $this->prefix = $db['prefix'] . $currentUser . '_';
+ $this->bd = new MinzPDOPGSQL($string, $db['user'], $db['password'], $driver_options);
+ $this->bd->exec("SET NAMES 'UTF8';");
+ break;
+ default:
+ throw new Minz_PDOConnectionException(
+ 'Invalid database type!',
+ $db['user'], Minz_Exception::ERROR
+ );
+ break;
}
self::$sharedBd = $this->bd;
+ self::$sharedDbType = $db['type'];
+ self::$sharedPrefix = $this->prefix;
} catch (Exception $e) {
throw new Minz_PDOConnectionException(
$string,
@@ -98,24 +101,27 @@ class Minz_ModelPdo {
public function beginTransaction() {
$this->bd->beginTransaction();
- self::$has_transaction = true;
}
- public function hasTransaction() {
- return self::$has_transaction;
+ public function inTransaction() {
+ return $this->bd->inTransaction(); //requires PHP >= 5.3.3
}
public function commit() {
$this->bd->commit();
- self::$has_transaction = false;
}
public function rollBack() {
$this->bd->rollBack();
- self::$has_transaction = false;
}
public static function clean() {
self::$sharedBd = null;
self::$sharedPrefix = '';
}
+
+ public function disableBuffering() {
+ if ((self::$sharedDbType === 'mysql') && defined('PDO::MYSQL_ATTR_USE_BUFFERED_QUERY')) {
+ $this->bd->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
+ }
+ }
}
class MinzPDO extends PDO {
@@ -125,13 +131,43 @@ class MinzPDO extends PDO {
}
}
+ protected function compatibility($statement) {
+ return $statement;
+ }
+
public function prepare($statement, $driver_options = array()) {
MinzPDO::check($statement);
+ $statement = $this->compatibility($statement);
return parent::prepare($statement, $driver_options);
}
public function exec($statement) {
MinzPDO::check($statement);
+ $statement = $this->compatibility($statement);
return parent::exec($statement);
}
+
+ public function query($statement) {
+ MinzPDO::check($statement);
+ $statement = $this->compatibility($statement);
+ return parent::query($statement);
+ }
+}
+
+class MinzPDOMySql extends MinzPDO {
+ public function lastInsertId($name = null) {
+ return parent::lastInsertId(); //We discard the name, only used by PostgreSQL
+ }
+}
+
+class MinzPDOMSQLite extends MinzPDO {
+ public function lastInsertId($name = null) {
+ return parent::lastInsertId(); //We discard the name, only used by PostgreSQL
+ }
+}
+
+class MinzPDOPGSQL extends MinzPDO {
+ protected function compatibility($statement) {
+ return str_replace(array('`', ' LIKE '), array('"', ' ILIKE '), $statement);
+ }
}
diff --git a/lib/Minz/PDOConnectionException.php b/lib/Minz/PDOConnectionException.php
index faf2e0fe9..064748708 100644
--- a/lib/Minz/PDOConnectionException.php
+++ b/lib/Minz/PDOConnectionException.php
@@ -3,7 +3,7 @@ class Minz_PDOConnectionException extends Minz_Exception {
public function __construct ($string_connection, $user, $code = self::ERROR) {
$message = 'Access to database is denied for `' . $user . '`'
. ' (`' . $string_connection . '`)';
-
+
parent::__construct ($message, $code);
}
}
diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php
index 5858e76a5..795085a30 100644
--- a/lib/Minz/Paginator.php
+++ b/lib/Minz/Paginator.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* MINZ - Copyright 2011 Marien Fressinaud
* Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/
@@ -51,7 +51,7 @@ class Minz_Paginator {
*/
public function render ($view, $getteur) {
$view = APP_PATH . '/views/helpers/'.$view;
-
+
if (file_exists ($view)) {
include ($view);
}
@@ -129,7 +129,7 @@ class Minz_Paginator {
$begin = ($this->currentPage - 1) * $this->nbItemsPerPage;
$counter = 0;
$i = 0;
-
+
foreach ($this->items as $key => $item) {
if ($i >= $begin) {
$array[$key] = $item;
@@ -164,7 +164,7 @@ class Minz_Paginator {
if (is_array ($items)) {
$this->items = $items;
}
-
+
$this->_nbPage ();
}
public function _nbItemsPerPage ($nbItemsPerPage) {
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 6db2e9c7a..f80b707d6 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -85,44 +85,64 @@ class Minz_Request {
}
/**
- * Retourn le nom de domaine du site
+ * Return true if the request is over HTTPS, false otherwise (HTTP)
*/
- public static function getDomainName() {
- return $_SERVER['HTTP_HOST'];
+ public static function isHttps() {
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
+ return strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https';
+ } else {
+ return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
+ }
}
/**
- * Détermine la base de l'url
- * @return la base de l'url
+ * Try to guess the base URL from $_SERVER information
+ *
+ * @return the base url (e.g. http://example.com/)
*/
- public static function getBaseUrl() {
- $conf = Minz_Configuration::get('system');
- $defaultBaseUrl = $conf->base_url;
- if (!empty($defaultBaseUrl)) {
- return $defaultBaseUrl;
- } elseif (isset($_SERVER['REQUEST_URI'])) {
- return dirname($_SERVER['REQUEST_URI']) . '/';
+ public static function guessBaseUrl() {
+ $url = 'http';
+
+ $https = self::isHttps();
+
+ if (!empty($_SERVER['HTTP_HOST'])) {
+ $host = $_SERVER['HTTP_HOST'];
+ } elseif (!empty($_SERVER['SERVER_NAME'])) {
+ $host = $_SERVER['SERVER_NAME'];
} else {
- return '/';
+ $host = 'localhost';
}
- }
- /**
- * 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'];
+ if (!empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
+ $port = intval($_SERVER['HTTP_X_FORWARDED_PORT']);
+ } elseif (!empty($_SERVER['SERVER_PORT'])) {
+ $port = intval($_SERVER['SERVER_PORT']);
+ } else {
+ $port = $https ? 443 : 80;
+ }
- $len_base_url = strlen($base_url);
- $real_uri = substr($uri, $len_base_url);
+ if ($https) {
+ $url .= 's://' . $host . ($port == 443 ? '' : ':' . $port);
} else {
- $real_uri = '';
+ $url .= '://' . $host . ($port == 80 ? '' : ':' . $port);
}
+ if (isset($_SERVER['REQUEST_URI'])) {
+ $path = $_SERVER['REQUEST_URI'];
+ $url .= substr($path, -1) === '/' ? substr($path, 0, -1) : dirname($path);
+ }
+
+ return filter_var($url, FILTER_SANITIZE_URL);
+ }
- return $real_uri;
+ /**
+ * Return the base_url from configuration and add a suffix if given.
+ *
+ * @return the base_url with a suffix.
+ */
+ public static function getBaseUrl() {
+ $conf = Minz_Configuration::get('system');
+ $url = rtrim($conf->base_url, '/\\');
+ return filter_var($url, FILTER_SANITIZE_URL);
}
/**
diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php
index 058685ada..c94f2b646 100644
--- a/lib/Minz/Session.php
+++ b/lib/Minz/Session.php
@@ -59,16 +59,21 @@ class Minz_Session {
}
}
+ public static function getCookieDir() {
+ // Get the script_name (e.g. /p/i/index.php) and keep only the path.
+ $cookie_dir = empty($_SERVER['REQUEST_URI']) ? '/' : $_SERVER['REQUEST_URI'];
+ if (substr($cookie_dir, -1) !== '/') {
+ $cookie_dir = dirname($cookie_dir) . '/';
+ }
+ return $cookie_dir;
+ }
/**
* Spécifie la durée de vie des cookies
* @param $l la durée de vie
*/
public static function keepCookie($l) {
- // Get the script_name (e.g. /p/i/index.php) and keep only the path.
- $cookie_dir = empty($_SERVER['SCRIPT_NAME']) ? '' : $_SERVER['SCRIPT_NAME'];
- $cookie_dir = dirname($cookie_dir);
- session_set_cookie_params($l, $cookie_dir, '', false, true);
+ session_set_cookie_params($l, self::getCookieDir(), '', Minz_Request::isHttps(), true);
}
@@ -81,11 +86,11 @@ class Minz_Session {
}
public static function deleteLongTermCookie($name) {
- setcookie($name, '', 1, '', '', false, true);
+ setcookie($name, '', 1, '', '', Minz_Request::isHttps(), true);
}
public static function setLongTermCookie($name, $value, $expire) {
- setcookie($name, $value, $expire, '', '', false, true);
+ setcookie($name, $value, $expire, '', '', Minz_Request::isHttps(), true);
}
public static function getLongTermCookie($name) {
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index baddcb424..d9cd59f7e 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -1,5 +1,5 @@
<?php
-/**
+/**
* MINZ - Copyright 2011 Marien Fressinaud
* Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/
@@ -153,7 +153,7 @@ class Minz_Translate {
* @param additional parameters for variable keys.
* @return the value corresponding to the key.
* If no value is found, return the key itself.
- */
+ */
public static function t($key) {
$group = explode('.', $key);
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index af555a277..99c0443c1 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -10,7 +10,6 @@ class Minz_Url {
* $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 &amp; pour html)
* @return l'url formatée
@@ -19,26 +18,30 @@ class Minz_Url {
$isArray = is_array($url);
if ($isArray) {
- $url = self::checkUrl ($url);
+ $url = self::checkUrl($url);
}
$url_string = '';
if ($absolute) {
- if ($isArray && isset ($url['protocol'])) {
- $protocol = $url['protocol'];
- } elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
- $protocol = 'https:';
- } else {
- $protocol = 'http:';
+ $url_string = Minz_Request::getBaseUrl();
+ if ($url_string == '') {
+ $url_string = Minz_Request::guessBaseUrl();
+ }
+ if ($isArray) {
+ $url_string .= PUBLIC_TO_INDEX_PATH;
+ }
+ if ($absolute === 'root') {
+ $url_string = parse_url($url_string, PHP_URL_PATH);
}
- $url_string = $protocol . '//' . Minz_Request::getDomainName () . Minz_Request::getBaseUrl ();
} else {
$url_string = $isArray ? '.' : PUBLIC_RELATIVE;
}
if ($isArray) {
- $url_string .= self::printUri ($url, $encodage);
+ $url_string .= self::printUri($url, $encodage);
+ } elseif ($encodage === 'html') {
+ $url_string = Minz_Helper::htmlspecialchars_utf8($url_string . $url);
} else {
$url_string .= $url;
}
@@ -75,6 +78,8 @@ class Minz_Url {
}
if (isset($url['params'])) {
+ unset($url['params']['c']);
+ unset($url['params']['a']);
foreach ($url['params'] as $key => $param) {
$uri .= $separator . urlencode($key) . '=' . urlencode($param);
$separator = $and;
diff --git a/lib/Minz/View.php b/lib/Minz/View.php
index ff5cce4a5..d6bf6ea2c 100644
--- a/lib/Minz/View.php
+++ b/lib/Minz/View.php
@@ -91,6 +91,7 @@ class Minz_View {
* Construit le layout
*/
public function buildLayout () {
+ header('Content-Type: text/html; charset=UTF-8');
$this->includeFile(self::LAYOUT_PATH_NAME . self::LAYOUT_FILENAME);
}
@@ -261,5 +262,3 @@ class Minz_View {
}
}
}
-
-