aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-07-21 18:00:32 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-07-21 18:00:32 +0200
commit8d7ac978f9af4819fc788e7e0a514dc7ca9886d9 (patch)
treefcc7e399a5f628a904518b7b522b17cef67a76e1 /app/Controllers
parenta4dac0f791ae6d34b64cee5a3fae1815f6f70a2b (diff)
parent73bbdaa015ec8596603fa88bd2cb03f85548e05e (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'app/Controllers')
-rwxr-xr-xapp/Controllers/configureController.php290
-rwxr-xr-xapp/Controllers/entryController.php12
-rwxr-xr-xapp/Controllers/feedController.php106
-rw-r--r--app/Controllers/importExportController.php5
-rwxr-xr-xapp/Controllers/indexController.php42
-rwxr-xr-xapp/Controllers/javascriptController.php4
-rw-r--r--app/Controllers/statsController.php67
-rw-r--r--app/Controllers/usersController.php14
8 files changed, 341 insertions, 199 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index a117e0f9c..79f40b30b 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -1,81 +1,81 @@
<?php
class FreshRSS_configure_Controller extends Minz_ActionController {
- public function firstAction () {
+ public function firstAction() {
if (!$this->view->loginOk) {
- Minz_Error::error (
+ Minz_Error::error(
403,
- array ('error' => array (Minz_Translate::t ('access_denied')))
+ array('error' => array(Minz_Translate::t('access_denied')))
);
}
- $catDAO = new FreshRSS_CategoryDAO ();
- $catDAO->checkDefault ();
+ $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO->checkDefault();
}
- public function categorizeAction () {
- $feedDAO = new FreshRSS_FeedDAO ();
- $catDAO = new FreshRSS_CategoryDAO ();
- $defaultCategory = $catDAO->getDefault ();
- $defaultId = $defaultCategory->id ();
+ public function categorizeAction() {
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $catDAO = new FreshRSS_CategoryDAO();
+ $defaultCategory = $catDAO->getDefault();
+ $defaultId = $defaultCategory->id();
- if (Minz_Request::isPost ()) {
- $cats = Minz_Request::param ('categories', array ());
- $ids = Minz_Request::param ('ids', array ());
- $newCat = trim (Minz_Request::param ('new_category', ''));
+ if (Minz_Request::isPost()) {
+ $cats = Minz_Request::param('categories', array());
+ $ids = Minz_Request::param('ids', array());
+ $newCat = trim(Minz_Request::param('new_category', ''));
foreach ($cats as $key => $name) {
- if (strlen ($name) > 0) {
- $cat = new FreshRSS_Category ($name);
- $values = array (
- 'name' => $cat->name (),
+ if (strlen($name) > 0) {
+ $cat = new FreshRSS_Category($name);
+ $values = array(
+ 'name' => $cat->name(),
);
- $catDAO->updateCategory ($ids[$key], $values);
+ $catDAO->updateCategory($ids[$key], $values);
} elseif ($ids[$key] != $defaultId) {
- $feedDAO->changeCategory ($ids[$key], $defaultId);
- $catDAO->deleteCategory ($ids[$key]);
+ $feedDAO->changeCategory($ids[$key], $defaultId);
+ $catDAO->deleteCategory($ids[$key]);
}
}
if ($newCat != '') {
- $cat = new FreshRSS_Category ($newCat);
- $values = array (
- 'id' => $cat->id (),
- 'name' => $cat->name (),
+ $cat = new FreshRSS_Category($newCat);
+ $values = array(
+ 'id' => $cat->id(),
+ 'name' => $cat->name(),
);
- if ($catDAO->searchByName ($newCat) == null) {
- $catDAO->addCategory ($values);
+ if ($catDAO->searchByName($newCat) == null) {
+ $catDAO->addCategory($values);
}
}
invalidateHttpCache();
- $notif = array (
+ $notif = array(
'type' => 'good',
- 'content' => Minz_Translate::t ('categories_updated')
+ 'content' => Minz_Translate::t('categories_updated')
);
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('notification', $notif);
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'categorize'), true);
}
- $this->view->categories = $catDAO->listCategories (false);
- $this->view->defaultCategory = $catDAO->getDefault ();
- $this->view->feeds = $feedDAO->listFeeds ();
+ $this->view->categories = $catDAO->listCategories(false);
+ $this->view->defaultCategory = $catDAO->getDefault();
+ $this->view->feeds = $feedDAO->listFeeds();
- Minz_View::prependTitle (Minz_Translate::t ('categories_management') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('categories_management') . ' · ');
}
- public function feedAction () {
- $catDAO = new FreshRSS_CategoryDAO ();
- $this->view->categories = $catDAO->listCategories (false);
+ public function feedAction() {
+ $catDAO = new FreshRSS_CategoryDAO();
+ $this->view->categories = $catDAO->listCategories(false);
- $feedDAO = new FreshRSS_FeedDAO ();
- $this->view->feeds = $feedDAO->listFeeds ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $this->view->feeds = $feedDAO->listFeeds();
- $id = Minz_Request::param ('id');
- if ($id == false && !empty ($this->view->feeds)) {
- $id = current ($this->view->feeds)->id ();
+ $id = Minz_Request::param('id');
+ if ($id == false && !empty($this->view->feeds)) {
+ $id = current($this->view->feeds)->id();
}
$this->view->flux = false;
@@ -83,14 +83,14 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$this->view->flux = $this->view->feeds[$id];
if (!$this->view->flux) {
- Minz_Error::error (
+ Minz_Error::error(
404,
- array ('error' => array (Minz_Translate::t ('page_not_found')))
+ array('error' => array(Minz_Translate::t('page_not_found')))
);
} else {
- if (Minz_Request::isPost () && $this->view->flux) {
- $user = Minz_Request::param ('http_user', '');
- $pass = Minz_Request::param ('http_pass', '');
+ if (Minz_Request::isPost() && $this->view->flux) {
+ $user = Minz_Request::param('http_user', '');
+ $pass = Minz_Request::param('http_pass', '');
$httpAuth = '';
if ($user != '' || $pass != '') {
@@ -99,45 +99,46 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$cat = intval(Minz_Request::param('category', 0));
- $values = array (
- 'name' => Minz_Request::param ('name', ''),
+ $values = array(
+ 'name' => Minz_Request::param('name', ''),
'description' => sanitizeHTML(Minz_Request::param('description', '', true)),
'website' => Minz_Request::param('website', ''),
'url' => Minz_Request::param('url', ''),
'category' => $cat,
- 'pathEntries' => Minz_Request::param ('path_entries', ''),
- 'priority' => intval(Minz_Request::param ('priority', 0)),
+ 'pathEntries' => Minz_Request::param('path_entries', ''),
+ 'priority' => intval(Minz_Request::param('priority', 0)),
'httpAuth' => $httpAuth,
- 'keep_history' => intval(Minz_Request::param ('keep_history', -2)),
+ 'keep_history' => intval(Minz_Request::param('keep_history', -2)),
+ 'ttl' => intval(Minz_Request::param('ttl', -2)),
);
- if ($feedDAO->updateFeed ($id, $values)) {
- $this->view->flux->_category ($cat);
+ if ($feedDAO->updateFeed($id, $values)) {
+ $this->view->flux->_category($cat);
$this->view->flux->faviconPrepare();
- $notif = array (
+ $notif = array(
'type' => 'good',
- 'content' => Minz_Translate::t ('feed_updated')
+ 'content' => Minz_Translate::t('feed_updated')
);
} else {
- $notif = array (
+ $notif = array(
'type' => 'bad',
- 'content' => Minz_Translate::t ('error_occurred_update')
+ 'content' => Minz_Translate::t('error_occurred_update')
);
}
invalidateHttpCache();
- Minz_Session::_param ('notification', $notif);
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true);
+ Minz_Session::_param('notification', $notif);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'feed', 'params' => array('id' => $id)), true);
}
- Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' — ' . $this->view->flux->name () . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('rss_feed_management') . ' — ' . $this->view->flux->name() . ' · ');
}
} else {
- Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('rss_feed_management') . ' · ');
}
}
- public function displayAction () {
+ public function displayAction() {
if (Minz_Request::isPost()) {
$this->view->conf->_language(Minz_Request::param('language', 'en'));
$themeId = Minz_Request::param('theme', '');
@@ -158,36 +159,37 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$this->view->conf->_bottomline_link(Minz_Request::param('bottomline_link', false));
$this->view->conf->save();
- Minz_Session::_param ('language', $this->view->conf->language);
- Minz_Translate::reset ();
+ Minz_Session::_param('language', $this->view->conf->language);
+ Minz_Translate::reset();
invalidateHttpCache();
- $notif = array (
+ $notif = array(
'type' => 'good',
- 'content' => Minz_Translate::t ('configuration_updated')
+ 'content' => Minz_Translate::t('configuration_updated')
);
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('notification', $notif);
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'display'), true);
}
$this->view->themes = FreshRSS_Themes::get();
- Minz_View::prependTitle (Minz_Translate::t ('display_configuration') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('display_configuration') . ' · ');
}
- public function readingAction () {
+ public function readingAction() {
if (Minz_Request::isPost()) {
$this->view->conf->_posts_per_page(Minz_Request::param('posts_per_page', 10));
$this->view->conf->_view_mode(Minz_Request::param('view_mode', 'normal'));
- $this->view->conf->_default_view (Minz_Request::param('default_view', 'a'));
+ $this->view->conf->_default_view((int)Minz_Request::param('default_view', FreshRSS_Entry::STATE_ALL));
$this->view->conf->_auto_load_more(Minz_Request::param('auto_load_more', false));
$this->view->conf->_display_posts(Minz_Request::param('display_posts', false));
$this->view->conf->_onread_jump_next(Minz_Request::param('onread_jump_next', false));
- $this->view->conf->_lazyload (Minz_Request::param('lazyload', false));
- $this->view->conf->_sticky_post (Minz_Request::param('sticky_post', false));
+ $this->view->conf->_lazyload(Minz_Request::param('lazyload', false));
+ $this->view->conf->_sticky_post(Minz_Request::param('sticky_post', false));
+ $this->view->conf->_reading_confirm(Minz_Request::param('reading_confirm', false));
$this->view->conf->_sort_order(Minz_Request::param('sort_order', 'DESC'));
- $this->view->conf->_mark_when (array(
+ $this->view->conf->_mark_when(array(
'article' => Minz_Request::param('mark_open_article', false),
'site' => Minz_Request::param('mark_open_site', false),
'scroll' => Minz_Request::param('mark_scroll', false),
@@ -195,43 +197,43 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
));
$this->view->conf->save();
- Minz_Session::_param ('language', $this->view->conf->language);
- Minz_Translate::reset ();
+ Minz_Session::_param('language', $this->view->conf->language);
+ Minz_Translate::reset();
invalidateHttpCache();
- $notif = array (
+ $notif = array(
'type' => 'good',
- 'content' => Minz_Translate::t ('configuration_updated')
+ 'content' => Minz_Translate::t('configuration_updated')
);
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('notification', $notif);
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'reading'), true);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'reading'), true);
}
- Minz_View::prependTitle (Minz_Translate::t ('reading_configuration') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('reading_configuration') . ' · ');
}
- public function sharingAction () {
- if (Minz_Request::isPost ()) {
+ public function sharingAction() {
+ if (Minz_Request::isPost()) {
$params = Minz_Request::params();
- $this->view->conf->_sharing ($params['share']);
+ $this->view->conf->_sharing($params['share']);
$this->view->conf->save();
invalidateHttpCache();
- $notif = array (
+ $notif = array(
'type' => 'good',
- 'content' => Minz_Translate::t ('configuration_updated')
+ 'content' => Minz_Translate::t('configuration_updated')
);
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('notification', $notif);
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'sharing'), true);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'sharing'), true);
}
- Minz_View::prependTitle (Minz_Translate::t ('sharing') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('sharing') . ' · ');
}
- public function shortcutAction () {
- $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
+ public function shortcutAction() {
+ $list_keys = array('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
'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',
@@ -240,9 +242,9 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
'f10', 'f11', 'f12');
$this->view->list_keys = $list_keys;
- if (Minz_Request::isPost ()) {
- $shortcuts = Minz_Request::param ('shortcuts');
- $shortcuts_ok = array ();
+ if (Minz_Request::isPost()) {
+ $shortcuts = Minz_Request::param('shortcuts');
+ $shortcuts_ok = array();
foreach ($shortcuts as $key => $value) {
if (in_array($value, $list_keys)) {
@@ -250,33 +252,35 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
}
}
- $this->view->conf->_shortcuts ($shortcuts_ok);
+ $this->view->conf->_shortcuts($shortcuts_ok);
$this->view->conf->save();
invalidateHttpCache();
- $notif = array (
+ $notif = array(
'type' => 'good',
- 'content' => Minz_Translate::t ('shortcuts_updated')
+ 'content' => Minz_Translate::t('shortcuts_updated')
);
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('notification', $notif);
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'shortcut'), true);
}
- Minz_View::prependTitle (Minz_Translate::t ('shortcuts') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('shortcuts') . ' · ');
}
public function usersAction() {
- Minz_View::prependTitle(Minz_Translate::t ('users') . ' · ');
+ Minz_View::prependTitle(Minz_Translate::t('users') . ' · ');
}
- public function archivingAction () {
+ public function archivingAction() {
if (Minz_Request::isPost()) {
$old = Minz_Request::param('old_entries', 3);
$keepHistoryDefault = Minz_Request::param('keep_history_default', 0);
+ $ttlDefault = Minz_Request::param('ttl_default', -2);
$this->view->conf->_old_entries($old);
$this->view->conf->_keep_history_default($keepHistoryDefault);
+ $this->view->conf->_ttl_default($ttlDefault);
$this->view->conf->save();
invalidateHttpCache();
@@ -291,7 +295,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' · ');
- $entryDAO = new FreshRSS_EntryDAO();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$this->view->nb_total = $entryDAO->count();
$this->view->size_user = $entryDAO->size();
@@ -299,4 +303,80 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$this->view->size_total = $entryDAO->size(true);
}
}
+
+ public function queriesAction() {
+ if (Minz_Request::isPost()) {
+ $queries = Minz_Request::param('queries', array());
+
+ foreach ($queries as $key => $query) {
+ if (!$query['name']) {
+ $query['name'] = Minz_Translate::t('query_number', $key + 1);
+ }
+ }
+ $this->view->conf->_queries($queries);
+ $this->view->conf->save();
+
+ $notif = array(
+ 'type' => 'good',
+ 'content' => Minz_Translate::t('configuration_updated')
+ );
+ Minz_Session::_param('notification', $notif);
+
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'queries'), true);
+ } else {
+ $this->view->query_get = array();
+ foreach ($this->view->conf->queries as $key => $query) {
+ if (!isset($query['get'])) {
+ continue;
+ }
+
+ switch ($query['get'][0]) {
+ case 'c':
+ $dao = new FreshRSS_CategoryDAO();
+ $category = $dao->searchById(substr($query['get'], 2));
+ $this->view->query_get[$key] = array(
+ 'type' => 'category',
+ 'name' => $category->name(),
+ );
+ break;
+ case 'f':
+ $dao = FreshRSS_Factory::createFeedDao();
+ $feed = $dao->searchById(substr($query['get'], 2));
+ $this->view->query_get[$key] = array(
+ 'type' => 'feed',
+ 'name' => $feed->name(),
+ );
+ break;
+ case 's':
+ $this->view->query_get[$key] = array(
+ 'type' => 'favorite',
+ 'name' => 'favorite',
+ );
+ break;
+ case 'a':
+ $this->view->query_get[$key] = array(
+ 'type' => 'all',
+ 'name' => 'all',
+ );
+ break;
+ }
+ }
+ }
+
+ Minz_View::prependTitle(Minz_Translate::t('queries') . ' · ');
+ }
+
+ public function addQueryAction() {
+ $queries = $this->view->conf->queries;
+ $query = Minz_Request::params();
+ $query['name'] = Minz_Translate::t('query_number', count($queries) + 1);
+ unset($query['output']);
+ unset($query['token']);
+ $queries[] = $query;
+ $this->view->conf->_queries($queries);
+ $this->view->conf->save();
+
+ // Minz_Request::forward(array('params' => $query), true);
+ Minz_Request::forward(array('c' => 'configure', 'a' => 'queries'), true);
+ }
}
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index bbcb990f5..ac43587ea 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -43,7 +43,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$nextGet = Minz_Request::param ('nextGet', $get);
$idMax = Minz_Request::param ('idMax', 0);
- $entryDAO = new FreshRSS_EntryDAO ();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
if ($id == false) {
if (!$get) {
$entryDAO->markReadEntries ($idMax);
@@ -85,7 +85,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$id = Minz_Request::param ('id');
if ($id) {
- $entryDAO = new FreshRSS_EntryDAO ();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$entryDAO->markFavorite ($id, (bool)(Minz_Request::param ('is_favorite', true)));
}
}
@@ -97,10 +97,10 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
// La table des entrées a tendance à grossir énormément
// Cette action permet d'optimiser cette table permettant de grapiller un peu de place
// Cette fonctionnalité n'est à appeler qu'occasionnellement
- $entryDAO = new FreshRSS_EntryDAO();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$entryDAO->optimizeTable();
- $feedDAO = new FreshRSS_FeedDAO();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$feedDAO->updateCachedValues();
invalidateHttpCache();
@@ -124,8 +124,8 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$nb_month_old = max($this->view->conf->old_entries, 1);
$date_min = time() - (3600 * 24 * 30 * $nb_month_old);
- $feedDAO = new FreshRSS_FeedDAO();
- $feeds = $feedDAO->listFeedsOrderUpdate();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $feeds = $feedDAO->listFeeds();
$nbTotal = 0;
invalidateHttpCache();
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index fce008399..3326b2059 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -31,7 +31,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
), true);
}
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$this->catDAO = new FreshRSS_CategoryDAO ();
$this->catDAO->checkDefault ();
@@ -102,25 +102,30 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$is_read = $this->view->conf->mark_when['reception'] ? 1 : 0;
- $entryDAO = new FreshRSS_EntryDAO ();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order
// on calcule la date des articles les plus anciens qu'on accepte
$nb_month_old = $this->view->conf->old_entries;
$date_min = time () - (3600 * 24 * 30 * $nb_month_old);
+ //MySQL: http://docs.oracle.com/cd/E17952_01/refman-5.5-en/optimizing-innodb-transaction-management.html
+ //SQLite: http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite
+ $preparedStatement = $entryDAO->addEntryPrepare();
$transactionStarted = true;
- $feedDAO->beginTransaction ();
+ $feedDAO->beginTransaction();
// on ajoute les articles en masse sans vérification
foreach ($entries as $entry) {
- $values = $entry->toArray ();
- $values['id_feed'] = $feed->id ();
- $values['id'] = min(time(), $entry->date (true)) . uSecString();
+ $values = $entry->toArray();
+ $values['id_feed'] = $feed->id();
+ $values['id'] = min(time(), $entry->date(true)) . uSecString();
$values['is_read'] = $is_read;
- $entryDAO->addEntry ($values);
+ $entryDAO->addEntry($values, $preparedStatement);
+ }
+ $feedDAO->updateLastUpdate($feed->id());
+ if ($transactionStarted) {
+ $feedDAO->commit();
}
- $feedDAO->updateLastUpdate ($feed->id ());
- $feedDAO->commit ();
$transactionStarted = false;
// ok, ajout terminé
@@ -162,45 +167,46 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true);
- }
-
- // GET request so we must ask confirmation to user
- Minz_View::prependTitle(Minz_Translate::t('add_rss_feed') . ' · ');
- $this->view->categories = $this->catDAO->listCategories();
- $this->view->feed = new FreshRSS_Feed($url);
- try {
- // We try to get some more information about the feed
- $this->view->feed->load(true);
- $this->view->load_ok = true;
- } catch (Exception $e) {
- $this->view->load_ok = false;
- }
+ } else {
- $feed = $feedDAO->searchByUrl($this->view->feed->url());
- if ($feed) {
- // Already subscribe so we redirect to the feed configuration page
- $notif = array(
- 'type' => 'bad',
- 'content' => Minz_Translate::t(
- 'already_subscribed', $feed->name()
- )
- );
- Minz_Session::_param('notification', $notif);
+ // GET request so we must ask confirmation to user
+ Minz_View::prependTitle(Minz_Translate::t('add_rss_feed') . ' · ');
+ $this->view->categories = $this->catDAO->listCategories();
+ $this->view->feed = new FreshRSS_Feed($url);
+ try {
+ // We try to get some more information about the feed
+ $this->view->feed->load(true);
+ $this->view->load_ok = true;
+ } catch (Exception $e) {
+ $this->view->load_ok = false;
+ }
- Minz_Request::forward(array(
- 'c' => 'configure',
- 'a' => 'feed',
- 'params' => array(
- 'id' => $feed->id()
- )
- ), true);
+ $feed = $feedDAO->searchByUrl($this->view->feed->url());
+ if ($feed) {
+ // Already subscribe so we redirect to the feed configuration page
+ $notif = array(
+ 'type' => 'bad',
+ 'content' => Minz_Translate::t(
+ 'already_subscribed', $feed->name()
+ )
+ );
+ Minz_Session::_param('notification', $notif);
+
+ Minz_Request::forward(array(
+ 'c' => 'configure',
+ 'a' => 'feed',
+ 'params' => array(
+ 'id' => $feed->id()
+ )
+ ), true);
+ }
}
}
public function truncateAction () {
if (Minz_Request::isPost ()) {
$id = Minz_Request::param ('id');
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$n = $feedDAO->truncate($id);
$notif = array(
'type' => $n === false ? 'bad' : 'good',
@@ -215,8 +221,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
public function actualizeAction () {
@set_time_limit(300);
- $feedDAO = new FreshRSS_FeedDAO ();
- $entryDAO = new FreshRSS_EntryDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
Minz_Session::_param('actualize_feeds', false);
$id = Minz_Request::param ('id');
@@ -232,7 +238,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feeds = array ($feed);
}
} else {
- $feeds = $feedDAO->listFeedsOrderUpdate ();
+ $feeds = $feedDAO->listFeedsOrderUpdate($this->view->conf->ttl_default);
}
// on calcule la date des articles les plus anciens qu'on accepte
@@ -264,22 +270,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feedHistory = $this->view->conf->keep_history_default;
}
+ $preparedStatement = $entryDAO->addEntryPrepare();
$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
foreach ($entries as $entry) {
- $eDate = $entry->date (true);
- if ((!isset ($existingGuids[$entry->guid ()])) &&
+ $eDate = $entry->date(true);
+ if ((!isset($existingGuids[$entry->guid()])) &&
(($feedHistory != 0) || ($eDate >= $date_min))) {
- $values = $entry->toArray ();
+ $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);
+ $entryDAO->addEntry($values, $preparedStatement);
}
}
}
@@ -300,7 +307,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feedDAO->commit();
}
$flux_update++;
- if ($feed->url() !== $url) { //URL has changed (auto-discovery)
+ if (($feed->url() !== $url)) { //HTTP 301 Moved Permanently
+ Minz_Log::record('Feed ' . $url . ' moved permanently to ' . $feed->url(), Minz_Log::NOTICE);
$feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));
}
} catch (FreshRSS_Feed_Exception $e) {
@@ -373,7 +381,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$type = Minz_Request::param ('type', 'feed');
$id = Minz_Request::param ('id');
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
if ($type == 'category') {
if ($feedDAO->deleteFeedByCategory ($id)) {
$notif = array (
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index 3cd791781..ba172cc6d 100644
--- a/app/Controllers/importExportController.php
+++ b/app/Controllers/importExportController.php
@@ -12,8 +12,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
require_once(LIB_PATH . '/lib_opml.php');
$this->catDAO = new FreshRSS_CategoryDAO();
- $this->entryDAO = new FreshRSS_EntryDAO();
- $this->feedDAO = new FreshRSS_FeedDAO();
+ $this->entryDAO = FreshRSS_Factory::createEntryDao();
+ $this->feedDAO = FreshRSS_Factory::createFeedDao();
}
public function indexAction() {
@@ -266,6 +266,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
);
$entry->_tags($tags);
+ //FIME: Use entryDAO->addEntryPrepare(). Do not call entryDAO->listLastGuidsByFeed() for each entry. Consider using a transaction.
$id = $this->entryDAO->addEntryObject(
$entry, $this->view->conf, $feed->keepHistory()
);
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index c843748c3..9a46bde6c 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -45,7 +45,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
$catDAO = new FreshRSS_CategoryDAO();
- $entryDAO = new FreshRSS_EntryDAO();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$this->view->cat_aside = $catDAO->listCategories ();
$this->view->nb_favorites = $entryDAO->countUnreadReadFavorites ();
@@ -70,11 +70,11 @@ class FreshRSS_index_Controller extends Minz_ActionController {
// mise à jour des titres
$this->view->rss_title = $this->view->currentName . ' | ' . Minz_View::title();
if ($this->view->nb_not_read > 0) {
- Minz_View::appendTitle (' (' . formatNumber($this->view->nb_not_read) . ')');
+ Minz_View::prependTitle('(' . formatNumber($this->view->nb_not_read) . ') ');
}
- Minz_View::prependTitle (
+ Minz_View::prependTitle(
+ ($this->nb_not_read_cat > 0 ? '(' . formatNumber($this->nb_not_read_cat) . ') ' : '') .
$this->view->currentName .
- ($this->nb_not_read_cat > 0 ? ' (' . formatNumber($this->nb_not_read_cat) . ')' : '') .
' · '
);
@@ -82,9 +82,6 @@ class FreshRSS_index_Controller extends Minz_ActionController {
$this->view->state = $state = Minz_Request::param ('state', $this->view->conf->default_view);
$state_param = Minz_Request::param ('state', null);
$filter = Minz_Request::param ('search', '');
- if (!empty($filter)) {
- $state = FreshRSS_Entry::STATE_ALL; //Search always in read and unread articles
- }
$this->view->order = $order = Minz_Request::param ('order', $this->view->conf->sort_order);
$nb = Minz_Request::param ('nb', $this->view->conf->posts_per_page);
$first = Minz_Request::param ('next', '');
@@ -127,8 +124,14 @@ class FreshRSS_index_Controller extends Minz_ActionController {
// Si on a récupéré aucun article "non lus"
// on essaye de récupérer tous les articles
- if ($state === FreshRSS_Entry::STATE_NOT_READ && empty($entries) && ($state_param === null)) {
- Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
+ if ($state === FreshRSS_Entry::STATE_NOT_READ && empty($entries) && ($state_param === null) && ($filter == '')) {
+ Minz_Log::record('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ try {
+ $feedDAO->updateCachedValues();
+ } catch (Exception $ex) {
+ Minz_Log::record('Failed to automatically correct nbNotRead! ' + $ex->getMessage(), Minz_Log::NOTICE);
+ }
$this->view->state = FreshRSS_Entry::STATE_ALL;
$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb, $first, $filter, $date_min, true, $keepHistoryDefault);
}
@@ -184,7 +187,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
case 'f':
$feed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId);
if (empty($feed)) {
- $feedDAO = new FreshRSS_FeedDAO();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
$feed = $feedDAO->searchById($getId);
}
if ($feed) {
@@ -201,25 +204,6 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
}
- public function statsAction () {
- if (!$this->view->loginOk) {
- Minz_Error::error (
- 403,
- array ('error' => array (Minz_Translate::t ('access_denied')))
- );
- }
-
- Minz_View::prependTitle (Minz_Translate::t ('stats') . ' · ');
-
- $statsDAO = new FreshRSS_StatsDAO ();
- Minz_View::appendScript (Minz_Url::display ('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
- $this->view->repartition = $statsDAO->calculateEntryRepartition();
- $this->view->count = ($statsDAO->calculateEntryCount());
- $this->view->feedByCategory = $statsDAO->calculateFeedByCategory();
- $this->view->entryByCategory = $statsDAO->calculateEntryByCategory();
- $this->view->topFeed = $statsDAO->calculateTopFeed();
- }
-
public function aboutAction () {
Minz_View::prependTitle (Minz_Translate::t ('about') . ' · ');
}
diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php
index 3d741e298..67148350f 100755
--- a/app/Controllers/javascriptController.php
+++ b/app/Controllers/javascriptController.php
@@ -7,8 +7,8 @@ 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->listFeedsOrderUpdate();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $this->view->feeds = $feedDAO->listFeedsOrderUpdate($this->view->conf->ttl_default);
}
public function nbUnreadsPerFeedAction() {
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php
new file mode 100644
index 000000000..9009468bc
--- /dev/null
+++ b/app/Controllers/statsController.php
@@ -0,0 +1,67 @@
+<?php
+
+class FreshRSS_stats_Controller extends Minz_ActionController {
+
+ public function indexAction() {
+ $statsDAO = FreshRSS_Factory::createStatsDAO();
+ Minz_View::appendScript (Minz_Url::display ('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
+ $this->view->repartition = $statsDAO->calculateEntryRepartition();
+ $this->view->count = ($statsDAO->calculateEntryCount());
+ $this->view->feedByCategory = $statsDAO->calculateFeedByCategory();
+ $this->view->entryByCategory = $statsDAO->calculateEntryByCategory();
+ $this->view->topFeed = $statsDAO->calculateTopFeed();
+ }
+
+ public function idleAction() {
+ $statsDAO = FreshRSS_Factory::createStatsDAO();
+ $feeds = $statsDAO->calculateFeedLastDate();
+ $idleFeeds = array();
+ $now = new \DateTime();
+ $feedDate = clone $now;
+ $lastWeek = clone $now;
+ $lastWeek->modify('-1 week');
+ $lastMonth = clone $now;
+ $lastMonth->modify('-1 month');
+ $last3Month = clone $now;
+ $last3Month->modify('-3 month');
+ $last6Month = clone $now;
+ $last6Month->modify('-6 month');
+ $lastYear = clone $now;
+ $lastYear->modify('-1 year');
+
+ foreach ($feeds as $feed) {
+ $feedDate->setTimestamp($feed['last_date']);
+ if ($feedDate >= $lastWeek) {
+ continue;
+ }
+ if ($feedDate < $lastWeek) {
+ $idleFeeds['last_week'][] = $feed['name'];
+ }
+ if ($feedDate < $lastMonth) {
+ $idleFeeds['last_month'][] = $feed['name'];
+ }
+ if ($feedDate < $last3Month) {
+ $idleFeeds['last_3_month'][] = $feed['name'];
+ }
+ if ($feedDate < $last6Month) {
+ $idleFeeds['last_6_month'][] = $feed['name'];
+ }
+ if ($feedDate < $lastYear) {
+ $idleFeeds['last_year'][] = $feed['name'];
+ }
+ }
+
+ $this->view->idleFeeds = array_reverse($idleFeeds);
+ }
+
+ public function firstAction() {
+ if (!$this->view->loginOk) {
+ Minz_Error::error(
+ 403, array('error' => array(Minz_Translate::t('access_denied')))
+ );
+ }
+
+ Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');
+ }
+
+}
diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php
index fa967cedc..35fa3675f 100644
--- a/app/Controllers/usersController.php
+++ b/app/Controllers/usersController.php
@@ -17,7 +17,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
if (Minz_Request::isPost()) {
$ok = true;
- $passwordPlain = Minz_Request::param('passwordPlain', false);
+ $passwordPlain = Minz_Request::param('passwordPlain', '', true);
if ($passwordPlain != '') {
Minz_Request::_param('passwordPlain'); //Discard plain-text password ASAP
$_POST['passwordPlain'] = '';
@@ -32,7 +32,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
}
Minz_Session::_param('passwordHash', $this->view->conf->passwordHash);
- $passwordPlain = Minz_Request::param('apiPasswordPlain', false);
+ $passwordPlain = Minz_Request::param('apiPasswordPlain', '', true);
if ($passwordPlain != '') {
if (!function_exists('password_hash')) {
include_once(LIB_PATH . '/password_compat.php');
@@ -45,7 +45,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
}
if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
- $this->view->conf->_mail_login(Minz_Request::param('mail_login', false));
+ $this->view->conf->_mail_login(Minz_Request::param('mail_login', '', true));
}
$email = $this->view->conf->mail_login;
Minz_Session::_param('mail', $email);
@@ -99,7 +99,8 @@ class FreshRSS_users_Controller extends Minz_ActionController {
public function createAction() {
if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
- require_once(APP_PATH . '/sql.php');
+ $db = Minz_Configuration::dataBase();
+ require_once(APP_PATH . '/SQL/sql.' . $db['type'] . '.php');
$new_user_language = Minz_Request::param('new_user_language', $this->view->conf->language);
if (!in_array($new_user_language, $this->view->conf->availableLanguages())) {
@@ -119,7 +120,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
}
if ($ok) {
- $passwordPlain = Minz_Request::param('new_user_passwordPlain', false);
+ $passwordPlain = Minz_Request::param('new_user_passwordPlain', '', true);
$passwordHash = '';
if ($passwordPlain != '') {
Minz_Request::_param('new_user_passwordPlain'); //Discard plain-text password ASAP
@@ -170,7 +171,8 @@ class FreshRSS_users_Controller extends Minz_ActionController {
public function deleteAction() {
if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
- require_once(APP_PATH . '/sql.php');
+ $db = Minz_Configuration::dataBase();
+ require_once(APP_PATH . '/SQL/sql.' . $db['type'] . '.php');
$username = Minz_Request::param('username');
$ok = ctype_alnum($username);