aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-12-26 16:33:47 +0100
committerGravatar GitHub <noreply@github.com> 2016-12-26 16:33:47 +0100
commit5f637bd816b7323885bfe1751a1724ee59a822f6 (patch)
tree67028e45792c575c25c92616633f64cc7a4a13eb /app/Models
parentc3d2496bb3ce665faf4a0f24a4aa2ab300ab56d3 (diff)
parent109f63be2620cf108efdfebd43f491e2720c824a (diff)
Merge pull request #1399 from FreshRSS/dev1.6.2
Release 1.6.2
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Auth.php15
-rw-r--r--app/Models/EntryDAO.php47
-rw-r--r--app/Models/Factory.php1
-rw-r--r--app/Models/UserDAO.php5
4 files changed, 45 insertions, 23 deletions
diff --git a/app/Models/Auth.php b/app/Models/Auth.php
index b93942e19..b3255cfbd 100644
--- a/app/Models/Auth.php
+++ b/app/Models/Auth.php
@@ -25,7 +25,7 @@ class FreshRSS_Auth {
self::giveAccess();
} elseif (self::accessControl()) {
self::giveAccess();
- FreshRSS_UserDAO::touch($current_user);
+ FreshRSS_UserDAO::touch();
} else {
// Be sure all accesses are removed!
self::removeAccess();
@@ -219,8 +219,8 @@ class FreshRSS_FormAuth {
}
public static function makeCookie($username, $password_hash) {
+ $conf = Minz_Configuration::get('system');
do {
- $conf = Minz_Configuration::get('system');
$token = sha1($conf->salt . $username . uniqid(mt_rand(), true));
$token_file = DATA_PATH . '/tokens/' . $token . '.txt';
} while (file_exists($token_file));
@@ -229,15 +229,17 @@ class FreshRSS_FormAuth {
return false;
}
- $expire = time() + 2629744; //1 month //TODO: Use a configuration instead
+ $limits = $conf->limits;
+ $cookie_duration = empty($limits['cookie_duration']) ? 2629744 : $limits['cookie_duration'];
+ $expire = time() + $cookie_duration;
Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire);
return $token;
}
public static function deleteCookie() {
$token = Minz_Session::getLongTermCookie('FreshRSS_login');
- Minz_Session::deleteLongTermCookie('FreshRSS_login');
if (ctype_alnum($token)) {
+ Minz_Session::deleteLongTermCookie('FreshRSS_login');
@unlink(DATA_PATH . '/tokens/' . $token . '.txt');
}
@@ -247,7 +249,10 @@ class FreshRSS_FormAuth {
}
public static function purgeTokens() {
- $oldest = time() - 2629744; // 1 month // TODO: Use a configuration instead
+ $conf = Minz_Configuration::get('system');
+ $limits = $conf->limits;
+ $cookie_duration = empty($limits['cookie_duration']) ? 2629744 : $limits['cookie_duration'];
+ $oldest = time() - $cookie_duration;
foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $file_info) {
// $extension = $file_info->getExtension(); doesn't work in PHP < 5.3.7
$extension = pathinfo($file_info->getFilename(), PATHINFO_EXTENSION);
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 58f2c1a79..397471baa 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -241,6 +241,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
if (count($ids) < 1) {
return 0;
}
+ FreshRSS_UserDAO::touch();
$sql = 'UPDATE `' . $this->prefix . 'entry` '
. 'SET is_favorite=? '
. 'WHERE id IN (' . str_repeat('?,', count($ids) - 1). '?)';
@@ -315,6 +316,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @return integer affected rows
*/
public function markRead($ids, $is_read = true) {
+ FreshRSS_UserDAO::touch();
if (is_array($ids)) { //Many IDs at once (used by API)
if (count($ids) < 6) { //Speed heuristics
$affected = 0;
@@ -379,6 +381,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @return integer affected rows
*/
public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filter = null, $state = 0) {
+ FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadEntries(0) is deprecated!');
@@ -421,6 +424,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @return integer affected rows
*/
public function markReadCat($id, $idMax = 0, $filter = null, $state = 0) {
+ FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadCat(0) is deprecated!');
@@ -458,6 +462,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @return integer affected rows
*/
public function markReadFeed($id_feed, $idMax = 0, $filter = null, $state = 0) {
+ FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadFeed(0) is deprecated!');
@@ -513,7 +518,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$stm->execute($values);
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
- $entries = self::daoToEntry($res);
+ $entries = self::daoToEntries($res);
return isset($entries[0]) ? $entries[0] : null;
}
@@ -528,7 +533,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$stm->execute($values);
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
- $entries = self::daoToEntry($res);
+ $entries = self::daoToEntries($res);
return isset($entries[0]) ? $entries[0] : null;
}
@@ -661,7 +666,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
. ($limit > 0 ? ' LIMIT ' . $limit : '')); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
}
- public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
+ public function listWhereRaw($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
$sql = 'SELECT e0.id, e0.guid, e0.title, e0.author, '
@@ -675,8 +680,12 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$stm = $this->bd->prepare($sql);
$stm->execute($values);
+ return $stm;
+ }
- return self::daoToEntry($stm->fetchAll(PDO::FETCH_ASSOC));
+ public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
+ $stm = $this->listWhereRaw($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
+ return self::daoToEntries($stm->fetchAll(PDO::FETCH_ASSOC));
}
public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) { //For API
@@ -805,15 +814,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return $res[0];
}
- public static function daoToEntry($listDAO) {
- $list = array();
-
- if (!is_array($listDAO)) {
- $listDAO = array($listDAO);
- }
-
- foreach ($listDAO as $key => $dao) {
- $entry = new FreshRSS_Entry(
+ public static function daoToEntry($dao) {
+ $entry = new FreshRSS_Entry(
$dao['id_feed'],
$dao['guid'],
$dao['title'],
@@ -825,10 +827,21 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$dao['is_favorite'],
$dao['tags']
);
- if (isset($dao['id'])) {
- $entry->_id($dao['id']);
- }
- $list[] = $entry;
+ if (isset($dao['id'])) {
+ $entry->_id($dao['id']);
+ }
+ return $entry;
+ }
+
+ private static function daoToEntries($listDAO) {
+ $list = array();
+
+ if (!is_array($listDAO)) {
+ $listDAO = array($listDAO);
+ }
+
+ foreach ($listDAO as $key => $dao) {
+ $list[] = self::daoToEntry($dao);
}
unset($listDAO);
diff --git a/app/Models/Factory.php b/app/Models/Factory.php
index 764987c46..6502c38b7 100644
--- a/app/Models/Factory.php
+++ b/app/Models/Factory.php
@@ -6,6 +6,7 @@ class FreshRSS_Factory {
$conf = Minz_Configuration::get('system');
switch ($conf->db['type']) {
case 'sqlite':
+ case 'pgsql':
return new FreshRSS_FeedDAOSQLite($username);
default:
return new FreshRSS_FeedDAO($username);
diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php
index a95ee6bc4..32bc6de2f 100644
--- a/app/Models/UserDAO.php
+++ b/app/Models/UserDAO.php
@@ -84,7 +84,10 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {
return is_dir(join_path(DATA_PATH , 'users', $username));
}
- public static function touch($username) {
+ public static function touch($username = '') {
+ if (($username == '') || (!ctype_alnum($username))) {
+ $username = Minz_Session::param('currentUser', '_');
+ }
return touch(join_path(DATA_PATH , 'users', $username, 'config.php'));
}