aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2015-05-23 02:23:38 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2015-05-23 02:23:38 +0200
commit27d2b88a19345dfc665dc086d3c2b2e4547e1b7f (patch)
treecbef13dbbfd07b580d12547c70d0440a5fc01e07
parent9b69ec4b3194a82f9c3b0d5ee513a2acdcea74eb (diff)
Minz getBaseUrl correction and RSS template bug
https://github.com/FreshRSS/FreshRSS/issues/848 Corrections in Minz (HTTP_HOST was not sanitized, getURI() was never used and not working anyway with absolute base_url) $this->url was not defined in rss.phtml
-rwxr-xr-xapp/Controllers/indexController.php1
-rw-r--r--constants.php3
-rw-r--r--lib/Minz/Request.php46
-rw-r--r--lib/Minz/Url.php10
4 files changed, 18 insertions, 42 deletions
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index c1aaca53f..baaf99065 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -137,6 +137,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
// No layout for RSS output.
+ $this->view->url = empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING'];
$this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();
$this->view->_useLayout(false);
header('Content-Type: application/rss+xml; charset=utf-8');
diff --git a/constants.php b/constants.php
index b20bf0710..d32fdfa9b 100644
--- a/constants.php
+++ b/constants.php
@@ -11,7 +11,8 @@ define('PHP_COMPRESSION', false);
define('FRESHRSS_PATH', dirname(__FILE__));
define('PUBLIC_PATH', FRESHRSS_PATH . '/p');
- define('INDEX_PATH', PUBLIC_PATH . '/i');
+ define('PUBLIC_TO_INDEX_PATH', '/i');
+ define('INDEX_PATH', PUBLIC_PATH . PUBLIC_TO_INDEX_PATH);
define('PUBLIC_RELATIVE', '..');
define('DATA_PATH', FRESHRSS_PATH . '/data');
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 6db2e9c7a..b9eda82a5 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -85,44 +85,26 @@ class Minz_Request {
}
/**
- * 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() {
+ public static function getBaseUrl($baseUrlSuffix = '') {
$conf = Minz_Configuration::get('system');
- $defaultBaseUrl = $conf->base_url;
- if (!empty($defaultBaseUrl)) {
- return $defaultBaseUrl;
- } elseif (isset($_SERVER['REQUEST_URI'])) {
- return dirname($_SERVER['REQUEST_URI']) . '/';
- } else {
- return '/';
- }
- }
-
- /**
- * 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);
+ $url = $conf->base_url;
+ if ($url == '' || !preg_match('%^https?://%i', $url)) {
+ $url = 'http';
+ $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
+ $port = empty($_SERVER['SERVER_PORT']) ? 80 : $_SERVER['SERVER_PORT'];
+ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
+ $url .= 's://' . $host . ($port == 443 ? '' : ':' . $port);
+ } else {
+ $url .= '://' . $host . ($port == 80 ? '' : ':' . $port);
+ }
+ $url .= isset($_SERVER['REQUEST_URI']) ? dirname($_SERVER['REQUEST_URI']) : '';
} else {
- $real_uri = '';
+ $url = rtrim($url, '/\\') . $baseUrlSuffix;
}
-
- return $real_uri;
+ return filter_var($url . '/', FILTER_SANITIZE_URL);
}
/**
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index af555a277..a47d8f1a6 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
@@ -25,14 +24,7 @@ class Minz_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 = $protocol . '//' . Minz_Request::getDomainName () . Minz_Request::getBaseUrl ();
+ $url_string = Minz_Request::getBaseUrl(PUBLIC_TO_INDEX_PATH);
} else {
$url_string = $isArray ? '.' : PUBLIC_RELATIVE;
}