aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-02-19 20:19:11 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-02-19 20:19:11 +0100
commit3aeea28ac7a1aa0bd07f23b1639c14985ff241ad (patch)
tree48e391d1aee6db4797cc46bd23ffb4dce311f46b /app/Controllers
parent165eb57459a152b3cc6aa3fd15ca990c3d908829 (diff)
parent04da549e2e52980ccc72689c32793222be76279d (diff)
Merge branch 'dev'
Diffstat (limited to 'app/Controllers')
-rwxr-xr-xapp/Controllers/configureController.php6
-rwxr-xr-xapp/Controllers/feedController.php90
-rwxr-xr-xapp/Controllers/indexController.php26
-rwxr-xr-xapp/Controllers/javascriptController.php2
-rw-r--r--app/Controllers/usersController.php7
5 files changed, 87 insertions, 44 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 645f9eabf..ad8bc546a 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -29,7 +29,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$cat = new FreshRSS_Category ($name);
$values = array (
'name' => $cat->name (),
- 'color' => $cat->color ()
);
$catDAO->updateCategory ($ids[$key], $values);
} elseif ($ids[$key] != $defaultId) {
@@ -43,7 +42,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$values = array (
'id' => $cat->id (),
'name' => $cat->name (),
- 'color' => $cat->color ()
);
if ($catDAO->searchByName ($newCat) == false) {
@@ -116,7 +114,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
if ($feedDAO->updateFeed ($id, $values)) {
$this->view->flux->_category ($cat);
-
+ $this->view->flux->faviconPrepare();
$notif = array (
'type' => 'good',
'content' => Minz_Translate::t ('feed_updated')
@@ -286,7 +284,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
public function shortcutAction () {
$list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
- 'escape', 'f', 'g', 'h', 'i', 'insert', 'j', 'k', 'l', 'left',
+ 'escape', 'f', 'g', 'h', 'home', 'i', 'insert', 'j', 'k', 'l', 'left',
'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right',
's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index c40b3c400..c718fcd5c 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -3,26 +3,31 @@
class FreshRSS_feed_Controller extends Minz_ActionController {
public function firstAction () {
if (!$this->view->loginOk) {
- $token = $this->view->conf->token; //TODO: check the token logic again, and if it is still needed
+ // Token is useful in the case that anonymous refresh is forbidden
+ // and CRON task cannot be used with php command so the user can
+ // set a CRON task to refresh his feeds by using token inside url
+ $token = $this->view->conf->token;
$token_param = Minz_Request::param ('token', '');
$token_is_ok = ($token != '' && $token == $token_param);
$action = Minz_Request::actionName ();
- if (!($token_is_ok && $action === 'actualize')) {
+ if (!(($token_is_ok || Minz_Configuration::allowAnonymousRefresh()) &&
+ $action === 'actualize')
+ ) {
Minz_Error::error (
403,
array ('error' => array (Minz_Translate::t ('access_denied')))
);
}
}
-
- $this->catDAO = new FreshRSS_CategoryDAO ();
- $this->catDAO->checkDefault ();
}
public function addAction () {
@set_time_limit(300);
if (Minz_Request::isPost ()) {
+ $this->catDAO = new FreshRSS_CategoryDAO ();
+ $this->catDAO->checkDefault ();
+
$url = Minz_Request::param ('url_rss');
$cat = Minz_Request::param ('category', false);
if ($cat === false) {
@@ -189,38 +194,51 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$flux_update = 0;
$is_read = $this->view->conf->mark_when['reception'] ? 1 : 0;
foreach ($feeds as $feed) {
+ if (!$feed->lock()) {
+ Minz_Log::record('Feed already being actualized: ' . $feed->url(), Minz_Log::NOTICE);
+ continue;
+ }
try {
$url = $feed->url();
+ $feedHistory = $feed->keepHistory();
+
$feed->load(false);
$entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order
+ $hasTransaction = false;
- //For this feed, check last n entry GUIDs already in database
- $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1);
- $useDeclaredDate = empty($existingGuids);
+ if (count($entries) > 0) {
+ //For this feed, check last n entry GUIDs already in database
+ $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1);
+ $useDeclaredDate = empty($existingGuids);
- $feedHistory = $feed->keepHistory();
- if ($feedHistory == -2) { //default
- $feedHistory = $this->view->conf->keep_history_default;
- }
+ if ($feedHistory == -2) { //default
+ $feedHistory = $this->view->conf->keep_history_default;
+ }
+
+ $hasTransaction = true;
+ $feedDAO->beginTransaction();
- // On ne vérifie pas strictement que l'article n'est pas déjà en BDD
- // La BDD refusera l'ajout car (id_feed, guid) doit être unique
- $feedDAO->beginTransaction ();
- foreach ($entries as $entry) {
- $eDate = $entry->date (true);
- if ((!isset ($existingGuids[$entry->guid ()])) &&
- (($feedHistory != 0) || ($eDate >= $date_min))) {
- $values = $entry->toArray ();
- //Use declared date at first import, otherwise use discovery date
- $values['id'] = ($useDeclaredDate || $eDate < $date_min) ?
- min(time(), $eDate) . uSecString() :
- uTimeString();
- $values['is_read'] = $is_read;
- $entryDAO->addEntry ($values);
+ // On ne vérifie pas strictement que l'article n'est pas déjà en BDD
+ // La BDD refusera l'ajout car (id_feed, guid) doit être unique
+ foreach ($entries as $entry) {
+ $eDate = $entry->date (true);
+ if ((!isset ($existingGuids[$entry->guid ()])) &&
+ (($feedHistory != 0) || ($eDate >= $date_min))) {
+ $values = $entry->toArray ();
+ //Use declared date at first import, otherwise use discovery date
+ $values['id'] = ($useDeclaredDate || $eDate < $date_min) ?
+ min(time(), $eDate) . uSecString() :
+ uTimeString();
+ $values['is_read'] = $is_read;
+ $entryDAO->addEntry ($values);
+ }
}
}
if (($feedHistory >= 0) && (rand(0, 30) === 1)) {
+ if (!$hasTransaction) {
+ $feedDAO->beginTransaction();
+ }
$nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10));
if ($nb > 0) {
Minz_Log::record ($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
@@ -228,18 +246,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
// on indique que le flux vient d'être mis à jour en BDD
- $feedDAO->updateLastUpdate ($feed->id ());
- $feedDAO->commit ();
+ $feedDAO->updateLastUpdate ($feed->id (), 0, $hasTransaction);
+ if ($hasTransaction) {
+ $feedDAO->commit();
+ }
$flux_update++;
if ($feed->url() !== $url) { //URL has changed (auto-discovery)
$feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));
}
- $feed->faviconPrepare();
} catch (FreshRSS_Feed_Exception $e) {
Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE);
$feedDAO->updateLastUpdate ($feed->id (), 1);
}
+ $feed->faviconPrepare();
+ $feed->unlock();
+ unset($feed);
+
// On arrête à 10 flux pour ne pas surcharger le serveur
// sauf si le paramètre $force est à vrai
$i++;
@@ -251,6 +274,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$url = array ();
if ($flux_update === 1) {
// on a mis un seul flux à jour
+ $feed = reset ($feeds);
$notif = array (
'type' => 'good',
'content' => Minz_Translate::t ('feed_actualized', $feed->name ())
@@ -264,8 +288,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
} else {
// aucun flux n'a été mis à jour, oups
$notif = array (
- 'type' => 'bad',
- 'content' => Minz_Translate::t ('no_feed_actualized')
+ 'type' => 'good',
+ 'content' => Minz_Translate::t ('no_feed_to_refresh')
);
}
@@ -298,6 +322,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
public function massiveImportAction () {
@set_time_limit(300);
+ $this->catDAO = new FreshRSS_CategoryDAO ();
+ $this->catDAO->checkDefault ();
+
$entryDAO = new FreshRSS_EntryDAO ();
$feedDAO = new FreshRSS_FeedDAO ();
@@ -416,7 +443,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$values = array (
'id' => $cat->id (),
'name' => $cat->name (),
- 'color' => $cat->color ()
);
$catDAO->addCategory ($values);
}
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 986a322a1..38f4c0e7c 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -5,18 +5,24 @@ class FreshRSS_index_Controller extends Minz_ActionController {
public function indexAction () {
$output = Minz_Request::param ('output');
- $token = '';
+ $token = $this->view->conf->token;
// check if user is logged in
- if (!$this->view->loginOk && !Minz_Configuration::allowAnonymous())
- {
- $token = $this->view->conf->token;
+ if (!$this->view->loginOk && !Minz_Configuration::allowAnonymous()) {
$token_param = Minz_Request::param ('token', '');
$token_is_ok = ($token != '' && $token === $token_param);
- if (!($output === 'rss' && $token_is_ok)) {
+ if ($output === 'rss' && !$token_is_ok) {
+ Minz_Error::error (
+ 403,
+ array ('error' => array (Minz_Translate::t ('access_denied')))
+ );
+ return;
+ } elseif ($output !== 'rss') {
+ // "hard" redirection is not required, just ask dispatcher to
+ // forward to the login form without 302 redirection
+ Minz_Request::forward(array('c' => 'index', 'a' => 'formLogin'));
return;
}
- $params['token'] = $token;
}
// construction of RSS url of this feed
@@ -25,6 +31,9 @@ class FreshRSS_index_Controller extends Minz_ActionController {
if (isset ($params['search'])) {
$params['search'] = urlencode ($params['search']);
}
+ if (!Minz_Configuration::allowAnonymous()) {
+ $params['token'] = $token;
+ }
$this->view->rss_url = array (
'c' => 'index',
'a' => 'index',
@@ -342,6 +351,11 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
$this->view->_useLayout(false);
Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
+ } elseif (!Minz_Configuration::canLogIn()) {
+ Minz_Error::error (
+ 403,
+ array ('error' => array (Minz_Translate::t ('access_denied')))
+ );
}
invalidateHttpCache();
}
diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php
index b879dcd6d..3d741e298 100755
--- a/app/Controllers/javascriptController.php
+++ b/app/Controllers/javascriptController.php
@@ -8,7 +8,7 @@ class FreshRSS_javascript_Controller extends Minz_ActionController {
public function actualizeAction () {
header('Content-Type: text/javascript; charset=UTF-8');
$feedDAO = new FreshRSS_FeedDAO ();
- $this->view->feeds = $feedDAO->listFeeds ();
+ $this->view->feeds = $feedDAO->listFeedsOrderUpdate();
}
public function nbUnreadsPerFeedAction() {
diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php
index 8314b75fc..bb4f34c5e 100644
--- a/app/Controllers/usersController.php
+++ b/app/Controllers/usersController.php
@@ -54,11 +54,16 @@ class FreshRSS_users_Controller extends Minz_ActionController {
$anon = Minz_Request::param('anon_access', false);
$anon = ((bool)$anon) && ($anon !== 'no');
+ $anon_refresh = Minz_Request::param('anon_refresh', false);
+ $anon_refresh = ((bool)$anon_refresh) && ($anon_refresh !== 'no');
$auth_type = Minz_Request::param('auth_type', 'none');
if ($anon != Minz_Configuration::allowAnonymous() ||
- $auth_type != Minz_Configuration::authType()) {
+ $auth_type != Minz_Configuration::authType() ||
+ $anon_refresh != Minz_Configuration::allowAnonymousRefresh()) {
+
Minz_Configuration::_authType($auth_type);
Minz_Configuration::_allowAnonymous($anon);
+ Minz_Configuration::_allowAnonymousRefresh($anon_refresh);
$ok &= Minz_Configuration::writeFile();
}
}