aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2016-07-23 17:11:38 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2016-07-23 17:11:38 +0200
commit3f705cf03ccd919e0930bc3e95b98daff9f0560a (patch)
treee12c530198e3d5ee7032d5aaa381e7ecc8781cdf /lib/Minz
parentca6ca218dca17c3806191f72fa2b3fe02acc1692 (diff)
parent43f3be7098a908321c29a14a1fbe542389479155 (diff)
Merge branch 'dev'
Diffstat (limited to 'lib/Minz')
-rw-r--r--lib/Minz/Request.php22
-rw-r--r--lib/Minz/Session.php19
-rw-r--r--lib/Minz/Url.php10
3 files changed, 33 insertions, 18 deletions
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index effb9943c..f80b707d6 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -85,6 +85,17 @@ class Minz_Request {
}
/**
+ * Return true if the request is over HTTPS, false otherwise (HTTP)
+ */
+ 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';
+ }
+ }
+
+ /**
* Try to guess the base URL from $_SERVER information
*
* @return the base url (e.g. http://example.com/)
@@ -92,11 +103,7 @@ class Minz_Request {
public static function guessBaseUrl() {
$url = 'http';
- if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
- $https = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https';
- } else {
- $https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
- }
+ $https = self::isHttps();
if (!empty($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
@@ -130,12 +137,11 @@ class Minz_Request {
/**
* Return the base_url from configuration and add a suffix if given.
*
- * @param $base_url_suffix a string to add at base_url (default: empty string)
* @return the base_url with a suffix.
*/
- public static function getBaseUrl($base_url_suffix = '') {
+ public static function getBaseUrl() {
$conf = Minz_Configuration::get('system');
- $url = rtrim($conf->base_url, '/\\') . $base_url_suffix;
+ $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 057e7746a..c94f2b646 100644
--- a/lib/Minz/Session.php
+++ b/lib/Minz/Session.php
@@ -59,18 +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['REQUEST_URI']) ? '/' : $_SERVER['REQUEST_URI'];
- if (substr($cookie_dir, -1) !== '/') {
- $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);
}
@@ -83,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/Url.php b/lib/Minz/Url.php
index 4279b045b..c7c67123e 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -24,10 +24,16 @@ class Minz_Url {
$url_string = '';
if ($absolute) {
- $url_string = Minz_Request::getBaseUrl(PUBLIC_TO_INDEX_PATH);
- if ($url_string === PUBLIC_TO_INDEX_PATH) {
+ $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);
+ }
} else {
$url_string = $isArray ? '.' : PUBLIC_RELATIVE;
}