aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-06-03 13:35:38 +0200
committerGravatar GitHub <noreply@github.com> 2018-06-03 13:35:38 +0200
commitc0122003fe3031926546012b86a38b5187082613 (patch)
tree5502841327e7775f280fbd12732b4e8b8b7be6ff /app/Controllers
parent029f4107123f6c318584bf9a43da7118c318657f (diff)
parentbe778c6bc2d8075e5a923153183b47507a2a71e3 (diff)
Merge pull request #1902 from FreshRSS/dev1.11.0
FreshRSS 1.11.0
Diffstat (limited to 'app/Controllers')
-rwxr-xr-xapp/Controllers/entryController.php2
-rwxr-xr-xapp/Controllers/feedController.php19
-rw-r--r--app/Controllers/importExportController.php21
-rwxr-xr-xapp/Controllers/indexController.php2
-rw-r--r--app/Controllers/subscriptionController.php24
-rw-r--r--app/Controllers/userController.php47
6 files changed, 73 insertions, 42 deletions
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index 28f0cb745..73e181b07 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -40,7 +40,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$get = Minz_Request::param('get');
$next_get = Minz_Request::param('nextGet', $get);
$id_max = Minz_Request::param('idMax', 0);
- FreshRSS_Context::$search = new FreshRSS_Search(Minz_Request::param('search', ''));
+ FreshRSS_Context::$search = new FreshRSS_BooleanSearch(Minz_Request::param('search', ''));
FreshRSS_Context::$state = Minz_Request::param('state', 0);
if (FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_FAVORITE)) {
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index af732951f..ca85e7cb8 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -84,6 +84,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
'description' => $feed->description(),
'lastUpdate' => time(),
'httpAuth' => $feed->httpAuth(),
+ 'attributes' => array(),
);
$id = $feedDAO->addFeed($values);
@@ -271,7 +272,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$updated_feeds = 0;
$nb_new_articles = 0;
- $is_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
foreach ($feeds as $feed) {
$url = $feed->url(); //For detection of HTTP 301
@@ -284,10 +284,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
$mtime = 0;
- $ttl = $feed->ttl();
- if ($ttl < FreshRSS_Feed::TTL_DEFAULT) {
+ if ($feed->mute()) {
continue; //Feed refresh is disabled
}
+ $ttl = $feed->ttl();
if ((!$simplePiePush) && (!$feed_id) &&
($feed->lastUpdate() + 10 >= time() - ($ttl == FreshRSS_Feed::TTL_DEFAULT ? FreshRSS_Context::$user_conf->ttl_default : $ttl))) {
//Too early to refresh from source, but check whether the feed was updated by another user
@@ -353,8 +353,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
} else { //This entry already exists but has been updated
//Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->id() .
//', old hash ' . $existingHash . ', new hash ' . $entry->hash());
- //TODO: Make an updated/is_read policy by feed, in addition to the global one.
- $needFeedCacheRefresh = FreshRSS_Context::$user_conf->mark_updated_article_unread;
+ $mark_updated_article_unread = $feed->attributes('mark_updated_article_unread') !== null ? (
+ $feed->attributes('mark_updated_article_unread')
+ ) : FreshRSS_Context::$user_conf->mark_updated_article_unread;
+ $needFeedCacheRefresh = $mark_updated_article_unread;
$entry->_isRead(FreshRSS_Context::$user_conf->mark_updated_article_unread ? false : null); //Change is_read according to policy.
if (!$entryDAO->inTransaction()) {
$entryDAO->beginTransaction();
@@ -365,15 +367,18 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
// This entry should not be added considering configuration and date.
$oldGuids[] = $entry->guid();
} else {
+ $read_upon_reception = $feed->attributes('read_upon_reception') !== null ? (
+ $feed->attributes('read_upon_reception')
+ ) : FreshRSS_Context::$user_conf->mark_when['reception'];
if ($isNewFeed) {
$id = min(time(), $entry_date) . uSecString();
- $entry->_isRead($is_read);
+ $entry->_isRead($read_upon_reception);
} elseif ($entry_date < $date_min) {
$id = min(time(), $entry_date) . uSecString();
$entry->_isRead(true); //Old article that was not in database. Probably an error, so mark as read
} else {
$id = uTimeString();
- $entry->_isRead($is_read);
+ $entry->_isRead($read_upon_reception);
}
$entry->_id($id);
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index a76dd9a2b..0fb5ba651 100644
--- a/app/Controllers/importExportController.php
+++ b/app/Controllers/importExportController.php
@@ -390,6 +390,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
$article_to_feed = array();
$nb_feeds = count($this->feedDAO->listFeeds());
+ $newFeedGuids = array();
$limits = FreshRSS_Context::$system_conf->limits;
// First, we check feeds of articles are in DB (and add them if needed).
@@ -417,21 +418,25 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
if ($feed != null) {
$article_to_feed[$item['id']] = $feed->id();
+ if (!isset($newFeedGuids['f_' . $feed->id()])) {
+ $newFeedGuids['f_' . $feed->id()] = array();
+ }
+ $newFeedGuids['f_' . $feed->id()][] = safe_ascii($item['id']);
}
}
- $newGuids = array();
- foreach ($article_object['items'] as $item) {
- $newGuids[] = safe_ascii($item['id']);
+ // For each feed, check existing GUIDs already in database.
+ $existingHashForGuids = array();
+ foreach ($newFeedGuids as $feedId => $newGuids) {
+ $existingHashForGuids[$feedId] = $this->entryDAO->listHashForFeedGuids(substr($feedId, 2), $newGuids);
}
- // For this feed, check existing GUIDs already in database.
- $existingHashForGuids = $this->entryDAO->listHashForFeedGuids($feed->id(), $newGuids);
- $newGuids = array();
+ unset($newFeedGuids);
// Then, articles are imported.
+ $newGuids = array();
$this->entryDAO->beginTransaction();
foreach ($article_object['items'] as $item) {
- if (!isset($article_to_feed[$item['id']])) {
+ if (empty($article_to_feed[$item['id']])) {
// Related feed does not exist for this entry, do nothing.
continue;
}
@@ -468,7 +473,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
$values = $entry->toArray();
$ok = false;
- if (isset($existingHashForGuids[$entry->guid()])) {
+ if (isset($existingHashForGuids['f_' . $feed_id][$entry->guid()])) {
$ok = $this->entryDAO->updateEntry($values);
} else {
$ok = $this->entryDAO->addEntry($values);
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index e3dbd4664..8567b4657 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -182,7 +182,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ;
}
- FreshRSS_Context::$search = new FreshRSS_Search(Minz_Request::param('search', ''));
+ FreshRSS_Context::$search = new FreshRSS_BooleanSearch(Minz_Request::param('search', ''));
FreshRSS_Context::$order = Minz_Request::param(
'order', FreshRSS_Context::$user_conf->sort_order
);
diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php
index 37efd3b57..701a588e0 100644
--- a/app/Controllers/subscriptionController.php
+++ b/app/Controllers/subscriptionController.php
@@ -15,7 +15,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
}
$catDAO = new FreshRSS_CategoryDAO();
- $feedDAO = new FreshRSS_FeedDAO();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$catDAO->checkDefault();
$feedDAO->updateTTL();
@@ -74,9 +74,10 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
return;
}
- $this->view->feed = $this->view->feeds[$id];
+ $feed = $this->view->feeds[$id];
+ $this->view->feed = $feed;
- Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $this->view->feed->name() . ' · ');
+ Minz_View::prependTitle(_t('sub.title.feed_management') . ' · ' . $feed->name() . ' · ');
if (Minz_Request::isPost()) {
$user = trim(Minz_Request::param('http_user_feed' . $id, ''));
@@ -95,6 +96,18 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
$ttl = FreshRSS_Context::$user_conf->ttl_default;
}
+ $feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread'));
+ $feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception'));
+
+ if (FreshRSS_Auth::hasAccess('admin')) {
+ $feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));
+ $timeout = intval(Minz_Request::param('timeout', 0));
+ $feed->_attributes('timeout', $timeout > 0 ? $timeout : null);
+ } else {
+ $feed->_attributes('ssl_verify', null);
+ $feed->_attributes('timeout', null);
+ }
+
$values = array(
'name' => Minz_Request::param('name', ''),
'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
@@ -106,14 +119,15 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
'httpAuth' => $httpAuth,
'keep_history' => intval(Minz_Request::param('keep_history', FreshRSS_Feed::KEEP_HISTORY_DEFAULT)),
'ttl' => $ttl * ($mute ? -1 : 1),
+ 'attributes' => $feed->attributes()
);
invalidateHttpCache();
$url_redirect = array('c' => 'subscription', 'params' => array('id' => $id));
if ($feedDAO->updateFeed($id, $values) !== false) {
- $this->view->feed->_category($cat);
- $this->view->feed->faviconPrepare();
+ $feed->_category($cat);
+ $feed->faviconPrepare();
Minz_Request::good(_t('feedback.sub.feed.updated'), $url_redirect);
} else {
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 2dad6a3f0..47f0ecc62 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -44,8 +44,20 @@ class FreshRSS_user_Controller extends Minz_ActionController {
return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1;
}
+ public static function deleteFeverKey($username) {
+ $userConfig = get_user_configuration($username);
+ if ($userConfig !== null && ctype_xdigit($userConfig->feverKey)) {
+ return @unlink(DATA_PATH . '/fever/.key-' . sha1(FreshRSS_Context::$system_conf->salt) . '-' . $userConfig->feverKey . '.txt');
+ }
+ return false;
+ }
+
public static function updateUser($user, $passwordPlain, $apiPasswordPlain, $userConfigUpdated = array()) {
$userConfig = get_user_configuration($user);
+ if ($userConfig === null) {
+ return false;
+ }
+
if ($passwordPlain != '') {
$passwordHash = self::hashPassword($passwordPlain);
$userConfig->passwordHash = $passwordHash;
@@ -54,6 +66,16 @@ class FreshRSS_user_Controller extends Minz_ActionController {
if ($apiPasswordPlain != '') {
$apiPasswordHash = self::hashPassword($apiPasswordPlain);
$userConfig->apiPasswordHash = $apiPasswordHash;
+
+ @mkdir(DATA_PATH . '/fever/', 0770, true);
+ self::deleteFeverKey($user);
+ $userConfig->feverKey = strtolower(md5($user . ':' . $apiPasswordPlain));
+ $ok = file_put_contents(DATA_PATH . '/fever/.key-' . sha1(FreshRSS_Context::$system_conf->salt) . '-' . $userConfig->feverKey . '.txt', $user) !== false;
+
+ if (!$ok) {
+ Minz_Log::warning('Could not save API credentials for fever API', ADMIN_LOG);
+ return $ok;
+ }
}
if (is_array($userConfigUpdated)) {
@@ -78,8 +100,8 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$username = Minz_Request::param('username');
$ok = self::updateUser($username, $passwordPlain, $apiPasswordPlain, array(
- 'token' => Minz_Request::param('token', null),
- ));
+ 'token' => Minz_Request::param('token', null),
+ ));
if ($ok) {
Minz_Request::good(_t('feedback.user.updated', $username),
@@ -169,29 +191,15 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$ok &= !file_exists($configPath);
}
if ($ok) {
- $passwordHash = '';
- if ($passwordPlain != '') {
- $passwordHash = self::hashPassword($passwordPlain);
- $ok &= ($passwordHash != '');
- }
-
- $apiPasswordHash = '';
- if ($apiPasswordPlain != '') {
- $apiPasswordHash = self::hashPassword($apiPasswordPlain);
- $ok &= ($apiPasswordHash != '');
- }
- }
- if ($ok) {
if (!is_dir($homeDir)) {
mkdir($homeDir);
}
- $userConfig['passwordHash'] = $passwordHash;
- $userConfig['apiPasswordHash'] = $apiPasswordHash;
$ok &= (file_put_contents($configPath, "<?php\n return " . var_export($userConfig, true) . ';') !== false);
}
if ($ok) {
$userDAO = new FreshRSS_UserDAO();
$ok &= $userDAO->createUser($new_user_name, $userConfig['language'], $insertDefaultFeeds);
+ $ok &= self::updateUser($new_user_name, $passwordPlain, $apiPasswordPlain);
}
return $ok;
}
@@ -246,10 +254,9 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$ok &= (strcasecmp($username, $default_user) !== 0); //It is forbidden to delete the default user
}
$user_data = join_path(DATA_PATH, 'users', $username);
+ $ok &= is_dir($user_data);
if ($ok) {
- $ok &= is_dir($user_data);
- }
- if ($ok) {
+ self::deleteFeverKey($username);
$userDAO = new FreshRSS_UserDAO();
$ok &= $userDAO->deleteUser($username);
$ok &= recursive_unlink($user_data);