aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-31 16:57:11 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-31 16:57:11 +0100
commit54479a5027d83b5dc8deee5e2795c9d89c732ba0 (patch)
tree7ae55930f3ab6d5e2a548784e4d7561809f7c68c /lib
parentcff8636e770b2072a41928cd918b37654c0dafbb (diff)
parent724e13f0a6419b046b33da71e66058e279551edd (diff)
Merge branch 'dev' into beta
Conflicts: CHANGELOG README.fr.md README.md app/Controllers/feedController.php app/Controllers/indexController.php app/i18n/en.php app/i18n/fr.php app/views/helpers/view/normal_view.phtml app/views/stats/index.phtml app/views/stats/repartition.phtml constants.php p/scripts/main.js
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Configuration.php50
-rw-r--r--lib/Minz/FrontController.php4
-rw-r--r--lib/Minz/ModelPdo.php12
-rw-r--r--lib/Minz/Request.php7
-rw-r--r--lib/Minz/View.php12
-rw-r--r--lib/SimplePie/SimplePie.php24
-rw-r--r--lib/SimplePie/SimplePie/Cache/File.php12
-rw-r--r--lib/SimplePie/SimplePie/Parse/Date.php1
-rw-r--r--lib/lib_opml.php2
-rw-r--r--lib/lib_rss.php92
10 files changed, 177 insertions, 39 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 4e9da58b4..6cbc9fc0b 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -60,6 +60,15 @@ class Minz_Configuration {
'prefix' => '',
);
+ const MAX_SMALL_INT = 16384;
+ private static $limits = array(
+ 'cache_duration' => 800, //SimplePie cache duration in seconds
+ 'timeout' => 10, //SimplePie timeout in seconds
+ 'max_inactivity' => PHP_INT_MAX, //Time in seconds after which a user who has not used the account is considered inactive (no auto-refresh of feeds).
+ 'max_feeds' => Minz_Configuration::MAX_SMALL_INT,
+ 'max_categories' => Minz_Configuration::MAX_SMALL_INT,
+ );
+
/*
* Getteurs
*/
@@ -97,12 +106,12 @@ class Minz_Configuration {
public static function dataBase () {
return self::$db;
}
+ public static function limits() {
+ return self::$limits;
+ }
public static function defaultUser () {
return self::$default_user;
}
- public static function isAdmin($currentUser) {
- return $currentUser === self::$default_user;
- }
public static function allowAnonymous() {
return self::$allow_anonymous;
}
@@ -181,6 +190,7 @@ class Minz_Configuration {
'api_enabled' => self::$api_enabled,
'unsafe_autologin_enabled' => self::$unsafe_autologin_enabled,
),
+ 'limits' => self::$limits,
'db' => self::$db,
);
@rename(DATA_PATH . self::CONF_PATH_NAME, DATA_PATH . self::CONF_PATH_NAME . '.bak.php');
@@ -294,6 +304,40 @@ class Minz_Configuration {
);
}
+ if (isset($ini_array['limits'])) {
+ $limits = $ini_array['limits'];
+ if (isset($limits['cache_duration'])) {
+ $v = intval($limits['cache_duration']);
+ if ($v > 0) {
+ self::$limits['cache_duration'] = $v;
+ }
+ }
+ if (isset($limits['timeout'])) {
+ $v = intval($limits['timeout']);
+ if ($v > 0) {
+ self::$limits['timeout'] = $v;
+ }
+ }
+ if (isset($limits['max_inactivity'])) {
+ $v = intval($limits['max_inactivity']);
+ if ($v > 0) {
+ self::$limits['max_inactivity'] = $v;
+ }
+ }
+ if (isset($limits['max_feeds'])) {
+ $v = intval($limits['max_feeds']);
+ if ($v > 0 && $v < Minz_Configuration::MAX_SMALL_INT) {
+ self::$limits['max_feeds'] = $v;
+ }
+ }
+ if (isset($limits['max_categories'])) {
+ $v = intval($limits['max_categories']);
+ if ($v > 0 && $v < Minz_Configuration::MAX_SMALL_INT) {
+ self::$limits['max_categories'] = $v;
+ }
+ }
+ }
+
// Base de données
if (isset ($ini_array['db'])) {
$db = $ini_array['db'];
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index f13882801..e95c56bf3 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -46,7 +46,7 @@ class Minz_FrontController {
);
Minz_Request::forward ($url);
} catch (Minz_Exception $e) {
- Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
+ Minz_Log::error($e->getMessage());
$this->killApp ($e->getMessage ());
}
@@ -85,7 +85,7 @@ class Minz_FrontController {
$this->dispatcher->run();
} catch (Minz_Exception $e) {
try {
- Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
+ Minz_Log::error($e->getMessage());
} catch (Minz_PermissionDeniedException $e) {
$this->killApp ($e->getMessage ());
}
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index b4bfca746..6198cd85c 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -16,6 +16,8 @@ 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;
/**
@@ -23,6 +25,7 @@ class Minz_ModelPdo {
*/
protected $bd;
+ protected $current_user;
protected $prefix;
public function dbType() {
@@ -37,6 +40,7 @@ class Minz_ModelPdo {
if (self::$useSharedBd && self::$sharedBd != null && $currentUser === null) {
$this->bd = self::$sharedBd;
$this->prefix = self::$sharedPrefix;
+ $this->current_user = self::$sharedCurrentUser;
return;
}
@@ -45,6 +49,8 @@ class Minz_ModelPdo {
if ($currentUser === null) {
$currentUser = Minz_Session::param('currentUser', '_');
}
+ $this->current_user = $currentUser;
+ self::$sharedCurrentUser = $currentUser;
try {
$type = $db['type'];
@@ -91,12 +97,18 @@ class Minz_ModelPdo {
public function beginTransaction() {
$this->bd->beginTransaction();
+ self::$has_transaction = true;
+ }
+ public function hasTransaction() {
+ return self::$has_transaction;
}
public function commit() {
$this->bd->commit();
+ self::$has_transaction = false;
}
public function rollBack() {
$this->bd->rollBack();
+ self::$has_transaction = false;
}
public static function clean() {
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index f7a24c026..4b97a3caf 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -45,6 +45,13 @@ class Minz_Request {
public static function defaultActionName() {
return self::$default_action_name;
}
+ public static function currentRequest() {
+ return array(
+ 'c' => self::$controller_name,
+ 'a' => self::$action_name,
+ 'params' => self::$params,
+ );
+ }
/**
* Setteurs
diff --git a/lib/Minz/View.php b/lib/Minz/View.php
index a0dec1824..b40448491 100644
--- a/lib/Minz/View.php
+++ b/lib/Minz/View.php
@@ -71,9 +71,7 @@ class Minz_View {
*/
public function render () {
if ((include($this->view_filename)) === false) {
- Minz_Log::record ('File not found: `'
- . $this->view_filename . '`',
- Minz_Log::NOTICE);
+ Minz_Log::notice('File not found: `' . $this->view_filename . '`');
}
}
@@ -87,9 +85,7 @@ class Minz_View {
. $part . '.phtml';
if ((include($fic_partial)) === false) {
- Minz_Log::record ('File not found: `'
- . $fic_partial . '`',
- Minz_Log::WARNING);
+ Minz_Log::warning('File not found: `' . $fic_partial . '`');
}
}
@@ -103,9 +99,7 @@ class Minz_View {
. $helper . '.phtml';
if ((include($fic_helper)) === false) {;
- Minz_Log::record ('File not found: `'
- . $fic_helper . '`',
- Minz_Log::WARNING);
+ Minz_Log::warning('File not found: `' . $fic_helper . '`');
}
}
diff --git a/lib/SimplePie/SimplePie.php b/lib/SimplePie/SimplePie.php
index 06c100f59..84001dd9a 100644
--- a/lib/SimplePie/SimplePie.php
+++ b/lib/SimplePie/SimplePie.php
@@ -1455,7 +1455,11 @@ class SimplePie
{
// Load the Cache
$this->data = $cache->load();
- if (!empty($this->data))
+ if ($cache->mtime() + $this->cache_duration > time()) { //FreshRSS
+ $this->raw_data = false;
+ return true; // If the cache is still valid, just return true
+ }
+ elseif (!empty($this->data))
{
// If the cache is for an outdated build of SimplePie
if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
@@ -1487,7 +1491,7 @@ class SimplePie
}
}
// Check if the cache has been updated
- elseif ($cache->mtime() + $this->cache_duration < time())
+ else //if ($cache->mtime() + $this->cache_duration < time()) //FreshRSS removed
{
// If we have last-modified and/or etag set
//if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) //FreshRSS removed
@@ -1516,6 +1520,7 @@ class SimplePie
}
else
{
+ $cache->touch(); //FreshRSS
$this->error = $file->error; //FreshRSS
return !empty($this->data); //FreshRSS
//unset($file); //FreshRSS removed
@@ -1533,17 +1538,18 @@ class SimplePie
}
}
}
- // If the cache is still valid, just return true
- else
- {
- $this->raw_data = false;
- return true;
- }
+ //// If the cache is still valid, just return true
+ //else //FreshRSS removed
+ //{
+ // $this->raw_data = false;
+ // return true;
+ //}
}
// If the cache is empty, delete it
else
{
- $cache->unlink();
+ //$cache->unlink(); //FreshRSS removed
+ $cache->touch(); //FreshRSS
$this->data = array();
}
}
diff --git a/lib/SimplePie/SimplePie/Cache/File.php b/lib/SimplePie/SimplePie/Cache/File.php
index 3b163545b..cb4b528c4 100644
--- a/lib/SimplePie/SimplePie/Cache/File.php
+++ b/lib/SimplePie/SimplePie/Cache/File.php
@@ -136,11 +136,11 @@ class SimplePie_Cache_File implements SimplePie_Cache_Base
*/
public function mtime()
{
- if (file_exists($this->name))
+ //if (file_exists($this->name)) //FreshRSS removed
{
- return filemtime($this->name);
+ return @filemtime($this->name); //FreshRSS
}
- return false;
+ //return false; //FreshRSS removed
}
/**
@@ -150,11 +150,11 @@ class SimplePie_Cache_File implements SimplePie_Cache_Base
*/
public function touch()
{
- if (file_exists($this->name))
+ //if (file_exists($this->name)) //FreshRSS removed
{
- return touch($this->name);
+ return @touch($this->name); //FreshRSS
}
- return false;
+ //return false; //FreshRSS removed
}
/**
diff --git a/lib/SimplePie/SimplePie/Parse/Date.php b/lib/SimplePie/SimplePie/Parse/Date.php
index ef800f125..ba7c0703e 100644
--- a/lib/SimplePie/SimplePie/Parse/Date.php
+++ b/lib/SimplePie/SimplePie/Parse/Date.php
@@ -331,6 +331,7 @@ class SimplePie_Parse_Date
'CCT' => 23400,
'CDT' => -18000,
'CEDT' => 7200,
+ 'CEST' => 7200, //FreshRSS
'CET' => 3600,
'CGST' => -7200,
'CGT' => -10800,
diff --git a/lib/lib_opml.php b/lib/lib_opml.php
index 16a9921ea..f320335bb 100644
--- a/lib/lib_opml.php
+++ b/lib/lib_opml.php
@@ -101,6 +101,7 @@ function libopml_parse_string($xml) {
// First, we get all "head" elements. Head is required but its sub-elements
// are optional.
+ // TODO: test head exists!
foreach ($opml->head->children() as $key => $value) {
if (in_array($key, unserialize(HEAD_ELEMENTS), true)) {
$array['head'][$key] = (string)$value;
@@ -114,6 +115,7 @@ function libopml_parse_string($xml) {
// Then, we get body oulines. Body must contain at least one outline
// element.
$at_least_one_outline = false;
+ // TODO: test body exists!
foreach ($opml->body->children() as $key => $value) {
if ($key === 'outline') {
$at_least_one_outline = true;
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 31c9cdbc1..e7ca95aba 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -56,12 +56,14 @@ function checkUrl($url) {
}
}
-function formatNumber($n, $precision = 0) {
- return str_replace(' ', ' ', //Espace insécable //TODO: remplacer par une espace _fine_ insécable
- number_format($n, $precision, '.', ' ')); //number_format does not seem to be Unicode-compatible
+function format_number($n, $precision = 0) {
+ // number_format does not seem to be Unicode-compatible
+ return str_replace(' ', ' ', //Espace fine insécable
+ number_format($n, $precision, '.', ' ')
+ );
}
-function formatBytes($bytes, $precision = 2, $system = 'IEC') {
+function format_bytes($bytes, $precision = 2, $system = 'IEC') {
if ($system === 'IEC') {
$base = 1024;
$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
@@ -73,15 +75,15 @@ function formatBytes($bytes, $precision = 2, $system = 'IEC') {
$pow = $bytes === 0 ? 0 : floor(log($bytes) / log($base));
$pow = min($pow, count($units) - 1);
$bytes /= pow($base, $pow);
- return formatNumber($bytes, $precision) . ' ' . $units[$pow];
+ return format_number($bytes, $precision) . ' ' . $units[$pow];
}
function timestamptodate ($t, $hour = true) {
- $month = Minz_Translate::t (date('M', $t));
+ $month = _t(date('M', $t));
if ($hour) {
- $date = Minz_Translate::t ('format_date_hour', $month);
+ $date = _t('format_date_hour', $month);
} else {
- $date = Minz_Translate::t ('format_date', $month);
+ $date = _t('format_date', $month);
}
return @date ($date, $t);
@@ -106,10 +108,12 @@ function html_only_entity_decode($text) {
}
function customSimplePie() {
+ $limits = Minz_Configuration::limits();
$simplePie = new SimplePie();
- $simplePie->set_useragent(Minz_Translate::t('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
+ $simplePie->set_useragent(_t('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
$simplePie->set_cache_location(CACHE_PATH);
- $simplePie->set_cache_duration(800);
+ $simplePie->set_cache_duration($limits['cache_duration']);
+ $simplePie->set_timeout($limits['timeout']);
$simplePie->strip_htmltags(array(
'base', 'blink', 'body', 'doctype', 'embed',
'font', 'form', 'frame', 'frameset', 'html',
@@ -244,3 +248,71 @@ function is_referer_from_same_domain() {
}
return (isset($host['port']) ? $host['port'] : 0) === (isset($referer['port']) ? $referer['port'] : 0);
}
+
+
+/**
+ * Check PHP and its extensions are well-installed.
+ *
+ * @return array of tested values.
+ */
+function check_install_php() {
+ $pdo_mysql = extension_loaded('pdo_mysql');
+ $pdo_sqlite = extension_loaded('pdo_sqlite');
+ return array(
+ 'php' => version_compare(PHP_VERSION, '5.2.1') >= 0,
+ 'minz' => file_exists(LIB_PATH . '/Minz'),
+ 'curl' => extension_loaded('curl'),
+ 'pdo' => $pdo_mysql || $pdo_sqlite,
+ 'pcre' => extension_loaded('pcre'),
+ 'ctype' => extension_loaded('ctype'),
+ 'dom' => class_exists('DOMDocument'),
+ 'json' => extension_loaded('json'),
+ 'zip' => extension_loaded('zip'),
+ );
+}
+
+
+/**
+ * Check different data files and directories exist.
+ *
+ * @return array of tested values.
+ */
+function check_install_files() {
+ return array(
+ 'data' => DATA_PATH && is_writable(DATA_PATH),
+ 'cache' => CACHE_PATH && is_writable(CACHE_PATH),
+ 'logs' => LOG_PATH && is_writable(LOG_PATH),
+ 'favicons' => is_writable(DATA_PATH . '/favicons'),
+ 'persona' => is_writable(DATA_PATH . '/persona'),
+ 'tokens' => is_writable(DATA_PATH . '/tokens'),
+ );
+}
+
+
+/**
+ * Check database is well-installed.
+ *
+ * @return array of tested values.
+ */
+function check_install_database() {
+ $status = array(
+ 'connection' => true,
+ 'tables' => false,
+ 'categories' => false,
+ 'feeds' => false,
+ 'entries' => false,
+ );
+
+ try {
+ $dbDAO = FreshRSS_Factory::createDatabaseDAO();
+
+ $status['tables'] = $dbDAO->tablesAreCorrect();
+ $status['categories'] = $dbDAO->categoryIsCorrect();
+ $status['feeds'] = $dbDAO->feedIsCorrect();
+ $status['entries'] = $dbDAO->entryIsCorrect();
+ } catch(Minz_PDOConnectionException $e) {
+ $status['connection'] = false;
+ }
+
+ return $status;
+}