diff options
| author | 2017-12-17 20:28:04 +0100 | |
|---|---|---|
| committer | 2017-12-17 20:28:04 +0100 | |
| commit | 60f56539c3f30fd3f7ba4f2a3570f7029ac93e5f (patch) | |
| tree | 1e78bfac7042dceb63898e2215db8fb0c1d7745d /lib | |
| parent | ceda55c75b158fc1cf4813fe0f258527754b9289 (diff) | |
| parent | 0b1516af91792f86868689392f72ad4b6e32cdcf (diff) | |
Merge pull request #1720 from FreshRSS/dev
FreshRSS 1.9.0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/Dispatcher.php | 3 | ||||
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 36 | ||||
| -rw-r--r-- | lib/Minz/Log.php | 34 | ||||
| -rw-r--r-- | lib/favicons.php | 10 | ||||
| -rw-r--r-- | lib/lib_rss.php | 16 |
5 files changed, 70 insertions, 29 deletions
diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index bdb1c76f6..f05b285b5 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -10,7 +10,6 @@ * C'est un singleton */ class Minz_Dispatcher { - const CONTROLLERS_PATH_NAME = '/Controllers'; /* singleton */ private static $instance = null; @@ -149,7 +148,7 @@ class Minz_Dispatcher { */ private static function loadController($base_name) { $base_path = self::$registrations[$base_name]; - $controller_filename = $base_path . '/controllers/' . $base_name . 'Controller.php'; + $controller_filename = $base_path . '/Controllers/' . $base_name . 'Controller.php'; include_once $controller_filename; } 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/Log.php b/lib/Minz/Log.php index 9559a0bd4..a8dbf8350 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 { @@ -70,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); } @@ -77,6 +80,37 @@ 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 : ''); + fwrite($fp, sprintf("[%s] [notice] --- Log rotate.\n", date('r'))); + 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/favicons.php b/lib/favicons.php index a7ed966a1..fe2e65f1f 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -24,19 +24,21 @@ function isImgMime($content) { function downloadHttp(&$url, $curlOptions = array()) { syslog(LOG_INFO, 'FreshRSS Favicon GET ' . $url); if (substr($url, 0, 2) === '//') { - $url = 'https:' . $favicon; + $url = 'https:' . $url; } if ($url == '' || filter_var($url, FILTER_VALIDATE_URL) === false) { return ''; } $ch = curl_init($url); curl_setopt_array($ch, array( - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, - CURLOPT_USERAGENT => 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')', + CURLOPT_USERAGENT => FRESHRSS_USERAGENT, + CURLOPT_MAXREDIRS => 10, )); + if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') { + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646 + } if (defined('CURLOPT_ENCODING')) { curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings } diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 09048700d..e9c4da049 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -4,7 +4,7 @@ if (version_compare(PHP_VERSION, '5.3.8', '<')) { } if (!function_exists('json_decode')) { - require_once('JSON.php'); + require_once(__DIR__ . '/JSON.php'); function json_decode($var, $assoc = false) { $JSON = new Services_JSON($assoc ? SERVICES_JSON_LOOSE_TYPE : 0); return $JSON->decode($var); @@ -12,7 +12,7 @@ if (!function_exists('json_decode')) { } if (!function_exists('json_encode')) { - require_once('JSON.php'); + require_once(__DIR__ . '/JSON.php'); function json_encode($var) { $JSON = new Services_JSON(); return $JSON->encodeUnsafe($var); @@ -62,7 +62,12 @@ function idn_to_puny($url) { $parts = parse_url($url); if (!empty($parts['host'])) { $idn = $parts['host']; - $puny = idn_to_ascii($idn); + // INTL_IDNA_VARIANT_UTS46 is defined starting in PHP 5.4 + if (defined('INTL_IDNA_VARIANT_UTS46')) { + $puny = idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46); + } else { + $puny = idn_to_ascii($idn); + } $pos = strpos($url, $idn); if ($pos !== false) { return substr_replace($url, $puny, $pos, strlen($idn)); @@ -174,7 +179,7 @@ function customSimplePie() { $system_conf = Minz_Configuration::get('system'); $limits = $system_conf->limits; $simplePie = new SimplePie(); - $simplePie->set_useragent('FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION); + $simplePie->set_useragent(FRESHRSS_USERAGENT); $simplePie->set_syslog($system_conf->simplepie_syslog_enabled); $simplePie->set_cache_location(CACHE_PATH); $simplePie->set_cache_duration($limits['cache_duration']); @@ -397,12 +402,13 @@ function is_referer_from_same_domain() { */ function check_install_php() { $pdo_mysql = extension_loaded('pdo_mysql'); + $pdo_pgsql = extension_loaded('pdo_pgsql'); $pdo_sqlite = extension_loaded('pdo_sqlite'); return array( 'php' => version_compare(PHP_VERSION, '5.3.8') >= 0, 'minz' => file_exists(LIB_PATH . '/Minz'), 'curl' => extension_loaded('curl'), - 'pdo' => $pdo_mysql || $pdo_sqlite, + 'pdo' => $pdo_mysql || $pdo_sqlite || $pdo_pgsql, 'pcre' => extension_loaded('pcre'), 'ctype' => extension_loaded('ctype'), 'fileinfo' => extension_loaded('fileinfo'), |
