diff options
| author | 2019-12-18 09:26:17 +0100 | |
|---|---|---|
| committer | 2019-12-18 09:26:17 +0100 | |
| commit | 2b1f8e67f76672a5b1b0a1b0403d81dbee364c58 (patch) | |
| tree | ab3142289e260111c686e740b9f4214453a0a84c /lib | |
| parent | 90c7292326538522a5df97b3f0a847b8a28f759f (diff) | |
| parent | 82851d2039f619f1b2558e06b04a9e47fceeea54 (diff) | |
Merge branch 'dev'
This is the end of the `dev` branch. Good bye old friend!
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 8 | ||||
| -rw-r--r-- | lib/Minz/Helper.php | 11 | ||||
| -rw-r--r-- | lib/Minz/Request.php | 195 | ||||
| -rw-r--r-- | lib/SimplePie/SimplePie.php | 4 | ||||
| -rw-r--r-- | lib/SimplePie/SimplePie/Locator.php | 2 | ||||
| -rw-r--r-- | lib/SimplePie/SimplePie/Parse/Date.php | 39 |
6 files changed, 174 insertions, 85 deletions
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 2240b7642..e6b8dafb0 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -15,6 +15,10 @@ class Minz_ExtensionManager { // List of available hooks. Please keep this list sorted. private static $hook_list = array( + 'check_url_before_add' => array( // function($url) -> Url | null + 'list' => array(), + 'signature' => 'OneToOne', + ), 'entry_before_display' => array( // function($entry) -> Entry | null 'list' => array(), 'signature' => 'OneToOne', @@ -23,6 +27,10 @@ class Minz_ExtensionManager { 'list' => array(), 'signature' => 'OneToOne', ), + 'feed_before_actualize' => array( // function($feed) -> Feed | null + 'list' => array(), + 'signature' => 'OneToOne', + ), 'feed_before_insert' => array( // function($feed) -> Feed | null 'list' => array(), 'signature' => 'OneToOne', diff --git a/lib/Minz/Helper.php b/lib/Minz/Helper.php index c328d9e6b..5fddbf91c 100644 --- a/lib/Minz/Helper.php +++ b/lib/Minz/Helper.php @@ -8,17 +8,6 @@ * La classe Helper représente une aide pour des tâches récurrentes */ class Minz_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('Minz_Helper', 'stripslashes_r'), $var); - } else { - return stripslashes($var); - } - } /** * Wrapper for htmlspecialchars. diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 9235f873a..ef641a0e9 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -11,6 +11,7 @@ class Minz_Request { private static $controller_name = ''; private static $action_name = ''; private static $params = array(); + private static $headers = array(); private static $default_controller_name = 'index'; private static $default_action_name = 'index'; @@ -100,7 +101,7 @@ class Minz_Request { * Initialise la Request */ public static function init() { - self::magicQuotesOff(); + static::$headers = $_SERVER; self::initJSON(); } @@ -113,13 +114,15 @@ class Minz_Request { /** * Return true if the request is over HTTPS, false otherwise (HTTP) + * + * @return boolean */ 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'; + $header = static::getHeader('HTTP_X_FORWARDED_PROTO'); + if (null !== $header) { + return 'https' === strtolower($header); } + return 'on' === static::getHeader('HTTPS'); } /** @@ -128,45 +131,89 @@ class Minz_Request { * @return the base url (e.g. http://example.com/) */ public static function guessBaseUrl() { - $url = 'http'; + $protocol = static::extractProtocol(); + $host = static::extractHost(); + $port = static::extractPortForUrl(); + $prefix = static::extractPrefix(); + $path = static::extractPath(); - $https = self::isHttps(); + return filter_var("{$protocol}://{$host}{$port}{$prefix}{$path}", FILTER_SANITIZE_URL); + } - if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { - $host = parse_url('http://' . $_SERVER['HTTP_X_FORWARDED_HOST'], PHP_URL_HOST); - } elseif (!empty($_SERVER['HTTP_HOST'])) { - //Might contain a port number, and mind IPv6 addresses - $host = parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST); - } elseif (!empty($_SERVER['SERVER_NAME'])) { - $host = $_SERVER['SERVER_NAME']; - } else { - $host = 'localhost'; + /** + * @return string + */ + private static function extractProtocol() { + if (static::isHttps()) { + return 'https'; } + return 'http'; + } - if (!empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { - $port = intval($_SERVER['HTTP_X_FORWARDED_PORT']); - } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { - $port = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https' ? 443 : 80; - } elseif (!empty($_SERVER['SERVER_PORT'])) { - $port = intval($_SERVER['SERVER_PORT']); - } else { - $port = $https ? 443 : 80; + /** + * @return string + */ + private static function extractHost() { + if (null !== $host = static::getHeader('HTTP_X_FORWARDED_HOST')) { + return parse_url("http://{$host}", PHP_URL_HOST); } + if (null !== $host = static::getHeader('HTTP_HOST')) { + // Might contain a port number, and mind IPv6 addresses + return parse_url("http://{$host}", PHP_URL_HOST); + } + if (null !== $host = static::getHeader('SERVER_NAME')) { + return $host; + } + return 'localhost'; + } - if ($https) { - $url .= 's://' . $host . ($port == 443 ? '' : ':' . $port); - } else { - $url .= '://' . $host . ($port == 80 ? '' : ':' . $port); + /** + * @return integer + */ + private static function extractPort() { + if (null !== $port = static::getHeader('HTTP_X_FORWARDED_PORT')) { + return intval($port); } - if (!empty($_SERVER['HTTP_X_FORWARDED_PREFIX'])) { - $url .= rtrim($_SERVER['HTTP_X_FORWARDED_PREFIX'], '/ '); + if (null !== $proto = static::getHeader('HTTP_X_FORWARDED_PROTO')) { + return 'https' === strtolower($proto) ? 443 : 80; } - if (isset($_SERVER['REQUEST_URI'])) { - $path = $_SERVER['REQUEST_URI']; - $url .= substr($path, -1) === '/' ? substr($path, 0, -1) : dirname($path); + if (null !== $port = static::getHeader('SERVER_PORT')) { + return intval($port); } + return static::isHttps() ? 443 : 80; + } - return filter_var($url, FILTER_SANITIZE_URL); + /** + * @return string + */ + private static function extractPortForUrl() { + if (static::isHttps() && 443 !== $port = static::extractPort()) { + return ":{$port}"; + } + if (!static::isHttps() && 80 !== $port = static::extractPort()) { + return ":{$port}"; + } + return ''; + } + + /** + * @return string + */ + private static function extractPrefix() { + if (null !== $prefix = static::getHeader('HTTP_X_FORWARDED_PREFIX')) { + return rtrim($prefix, '/ '); + } + return ''; + } + + /** + * @return string + */ + private static function extractPath() { + if (null !== $path = static::getHeader('REQUEST_URI')) { + return '/' === substr($path, -1) ? substr($path, 0, -1) : dirname($path); + } + return ''; } /** @@ -242,40 +289,44 @@ class Minz_Request { * $default si $_GET[$param] n'existe pas */ public static function fetchGET($param = false, $default = false) { - if ($param === false) { + if (false === $param) { return $_GET; - } elseif (isset($_GET[$param])) { + } + if (isset($_GET[$param])) { return $_GET[$param]; - } else { - return $default; } + return $default; } /** * Allows receiving POST data as application/json */ private static function initJSON() { - $contentType = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''; - if ($contentType == '') { //PHP < 5.3.16 - $contentType = isset($_SERVER['HTTP_CONTENT_TYPE']) ? $_SERVER['HTTP_CONTENT_TYPE'] : ''; + if ('application/json' !== static::extractContentType()) { + return; + } + if ('' === $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576)) { + return; } - $contentType = strtolower(trim($contentType)); - if ($contentType === 'application/json') { - $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576); - if ($ORIGINAL_INPUT != '') { - $json = json_decode($ORIGINAL_INPUT, true); - if ($json != null) { - foreach ($json as $k => $v) { - if (!isset($_POST[$k])) { - $_POST[$k] = $v; - } - } - } + if (null === $json = json_decode($ORIGINAL_INPUT, true)) { + return; + } + + foreach ($json as $k => $v) { + if (!isset($_POST[$k])) { + $_POST[$k] = $v; } } } /** + * @return string + */ + private static function extractContentType() { + return strtolower(trim(static::getHeader('CONTENT_TYPE'))); + } + + /** * 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 @@ -284,31 +335,39 @@ class Minz_Request { * $default si $_POST[$param] n'existe pas */ public static function fetchPOST($param = false, $default = false) { - if ($param === false) { + if (false === $param) { return $_POST; - } elseif (isset($_POST[$param])) { + } + if (isset($_POST[$param])) { return $_POST[$param]; - } else { - return $default; } + return $default; } /** - * Méthode désactivant les magic_quotes pour les variables - * $_GET - * $_POST - * $_COOKIE + * @return mixed */ - private static function magicQuotesOff() { - if (get_magic_quotes_gpc()) { - $_GET = Minz_Helper::stripslashes_r($_GET); - $_POST = Minz_Helper::stripslashes_r($_POST); - $_COOKIE = Minz_Helper::stripslashes_r($_COOKIE); + public static function getHeader($header, $default = null) { + if (isset(static::$headers[$header])) { + return static::$headers[$header]; } + return $default; } + /** + * @return boolean + */ public static function isPost() { - return isset($_SERVER['REQUEST_METHOD']) && - $_SERVER['REQUEST_METHOD'] === 'POST'; + return 'POST' === static::getHeader('REQUEST_METHOD'); + } + + /** + * @return array + */ + public static function getPreferredLanguage() { + if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', static::getHeader('HTTP_ACCEPT_LANGUAGE'), $matches)) { + return $matches['lang']; + } + return array('en'); } } diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php index d684c1a2c..87626f369 100644 --- a/lib/SimplePie/SimplePie.php +++ b/lib/SimplePie/SimplePie.php @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package SimplePie - * @version 1.5.2 + * @version 1.5.3 * @copyright 2004-2017 Ryan Parman, Geoffrey Sneddon, Ryan McCue * @author Ryan Parman * @author Geoffrey Sneddon @@ -50,7 +50,7 @@ define('SIMPLEPIE_NAME', 'SimplePie'); /** * SimplePie Version */ -define('SIMPLEPIE_VERSION', '1.5.2'); +define('SIMPLEPIE_VERSION', '1.5.3'); /** * SimplePie Build diff --git a/lib/SimplePie/SimplePie/Locator.php b/lib/SimplePie/SimplePie/Locator.php index 3876a2da6..12bc15e15 100644 --- a/lib/SimplePie/SimplePie/Locator.php +++ b/lib/SimplePie/SimplePie/Locator.php @@ -402,7 +402,7 @@ class SimplePie_Locator { break; } - if (preg_match('/(rss|rdf|atom|xml)/i', $value)) + if (preg_match('/(feed|rss|rdf|atom|xml)/i', $value)) { $this->checked_feeds++; $headers = array( diff --git a/lib/SimplePie/SimplePie/Parse/Date.php b/lib/SimplePie/SimplePie/Parse/Date.php index b29274c64..18e60e281 100644 --- a/lib/SimplePie/SimplePie/Parse/Date.php +++ b/lib/SimplePie/SimplePie/Parse/Date.php @@ -145,6 +145,14 @@ class SimplePie_Parse_Date 'Παρ' => 5, 'Σαβ' => 6, 'Κυρ' => 7, + // Russian + 'Пн.' => 1, + 'Вт.' => 2, + 'Ср.' => 3, + 'Чт.' => 4, + 'Пт.' => 5, + 'Сб.' => 6, + 'Вс.' => 7, ); /** @@ -290,6 +298,31 @@ class SimplePie_Parse_Date 'Οκτ' => 10, 'Νοέ' => 11, 'Δεκ' => 12, + // Russian + 'Янв' => 1, + 'января' => 1, + 'Фев' => 2, + 'февраля' => 2, + 'Мар' => 3, + 'марта' => 3, + 'Апр' => 4, + 'апреля' => 4, + 'Май' => 5, + 'мая' => 5, + 'Июн' => 6, + 'июня' => 6, + 'Июл' => 7, + 'июля' => 7, + 'Авг' => 8, + 'августа' => 8, + 'Сен' => 9, + 'сентября' => 9, + 'Окт' => 10, + 'октября' => 10, + 'Ноя' => 11, + 'ноября' => 11, + 'Дек' => 12, + 'декабря' => 12, ); /** @@ -541,8 +574,8 @@ class SimplePie_Parse_Date */ public function __construct() { - $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')'; - $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')'; + $this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')'; + $this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')'; static $cache; if (!isset($cache[get_class($this)])) @@ -690,7 +723,7 @@ class SimplePie_Parse_Date } // Convert the number of seconds to an integer, taking decimals into account - $second = round((int)$match[6] + (int)$match[7] / pow(10, strlen($match[7]))); + $second = round((int)$match[6] + (int)$match[7] / (10 ** strlen($match[7]))); return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; } |
