aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-09-26 14:36:30 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-09-26 14:36:30 +0200
commit147a3d21bbe78ae66c7134ac0c355472a92e1159 (patch)
tree7f8ca64ccc0939c8c9aef145a8fd86cc2e52640b /app/Controllers
parent7e949d50320317b5c3b5a2da2bdaf324e794b2f7 (diff)
parentc14162221365077bcaeecde7127806190490dd58 (diff)
Merge branch 'dev'
Diffstat (limited to 'app/Controllers')
-rwxr-xr-xapp/Controllers/configureController.php588
-rwxr-xr-xapp/Controllers/entryController.php21
-rw-r--r--app/Controllers/errorController.php52
-rwxr-xr-xapp/Controllers/feedController.php217
-rw-r--r--app/Controllers/importExportController.php447
-rwxr-xr-xapp/Controllers/indexController.php215
-rwxr-xr-xapp/Controllers/javascriptController.php4
-rw-r--r--app/Controllers/statsController.php129
-rw-r--r--app/Controllers/updateController.php129
-rw-r--r--app/Controllers/usersController.php32
10 files changed, 1431 insertions, 403 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index ad8bc546a..231865bd7 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -1,82 +1,123 @@
<?php
+/**
+ * Controller to handle every configuration options.
+ */
class FreshRSS_configure_Controller extends Minz_ActionController {
- public function firstAction () {
+ /**
+ * This action is called before every other action in that class. It is
+ * the common boiler plate for every action. It is triggered by the
+ * underlying framework.
+ *
+ * @todo see if the category default configuration is needed here or if
+ * we can move it to the categorize action
+ */
+ 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(_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 ();
+ /**
+ * This action handles the category configuration page
+ *
+ * It displays the category configuration page.
+ * If this action is reached through a POST request, it loops through
+ * every category to check for modification then add a new category if
+ * needed then sends a notification to the user.
+ * If a category name is emptied, the category is deleted and all
+ * related feeds are moved to the default category. Related user queries
+ * are deleted too.
+ * If a category name is changed, it is updated.
+ */
+ 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]);
+
+ // Remove related queries.
+ $this->view->conf->remove_query_by_get('c_' . $ids[$key]);
+ $this->view->conf->save();
}
}
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) == false) {
- $catDAO->addCategory ($values);
+ if ($catDAO->searchByName($newCat) == null) {
+ $catDAO->addCategory($values);
}
}
invalidateHttpCache();
- $notif = array (
- 'type' => 'good',
- 'content' => Minz_Translate::t ('categories_updated')
- );
- Minz_Session::_param ('notification', $notif);
-
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
+ Minz_Request::good(_t('categories_updated'),
+ array('c' => 'configure', 'a' => 'categorize'));
}
- $this->view->categories = $catDAO->listCategories (false);
- $this->view->defaultCategory = $catDAO->getDefault ();
- $this->view->feeds = $feedDAO->listFeeds ();
- $this->view->flux = false;
+ $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(_t('categories_management') . ' · ');
}
- public function feedAction () {
- $catDAO = new FreshRSS_CategoryDAO ();
- $this->view->categories = $catDAO->listCategories (false);
-
- $feedDAO = new FreshRSS_FeedDAO ();
- $this->view->feeds = $feedDAO->listFeeds ();
-
- $id = Minz_Request::param ('id');
- if ($id == false && !empty ($this->view->feeds)) {
- $id = current ($this->view->feeds)->id ();
+ /**
+ * This action handles the feed configuration page.
+ *
+ * It displays the feed configuration page.
+ * If this action is reached through a POST request, it stores all new
+ * configuraiton values then sends a notification to the user.
+ *
+ * The options available on the page are:
+ * - name
+ * - description
+ * - website URL
+ * - feed URL
+ * - category id (default: default category id)
+ * - CSS path to article on website
+ * - display in main stream (default: 0)
+ * - HTTP authentication
+ * - number of article to retain (default: -2)
+ * - refresh frequency (default: -2)
+ * Default values are empty strings unless specified.
+ */
+ public function feedAction() {
+ $catDAO = new FreshRSS_CategoryDAO();
+ $this->view->categories = $catDAO->listCategories(false);
+
+ $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();
}
$this->view->flux = false;
@@ -84,14 +125,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(_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 != '') {
@@ -100,66 +141,74 @@ 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' => _t('feed_updated')
);
} else {
- $notif = array (
+ $notif = array(
'type' => 'bad',
- 'content' => Minz_Translate::t ('error_occurred_update')
+ 'content' => _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(_t('rss_feed_management') . ' — ' . $this->view->flux->name() . ' · ');
}
} else {
- Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' · ');
+ Minz_View::prependTitle(_t('rss_feed_management') . ' · ');
}
}
- public function displayAction () {
+ /**
+ * This action handles the display configuration page.
+ *
+ * It displays the display configuration page.
+ * If this action is reached through a POST request, it stores all new
+ * configuration values then sends a notification to the user.
+ *
+ * The options available on the page are:
+ * - language (default: en)
+ * - theme (default: Origin)
+ * - content width (default: thin)
+ * - display of read action in header
+ * - display of favorite action in header
+ * - display of date in header
+ * - display of open action in header
+ * - display of read action in footer
+ * - display of favorite action in footer
+ * - display of sharing action in footer
+ * - display of tags in footer
+ * - display of date in footer
+ * - display of open action in footer
+ * - html5 notification timeout (default: 0)
+ * Default values are false unless specified.
+ */
+ public function displayAction() {
if (Minz_Request::isPost()) {
$this->view->conf->_language(Minz_Request::param('language', 'en'));
- $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->_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->_sort_order(Minz_Request::param('sort_order', 'DESC'));
- $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),
- 'reception' => Minz_Request::param('mark_upon_reception', false),
- ));
- $themeId = Minz_Request::param('theme', '');
- if ($themeId == '') {
- $themeId = FreshRSS_Themes::defaultTheme;
- }
- $this->view->conf->_theme($themeId);
+ $this->view->conf->_theme(Minz_Request::param('theme', FreshRSS_Themes::$defaultTheme));
+ $this->view->conf->_content_width(Minz_Request::param('content_width', 'thin'));
$this->view->conf->_topline_read(Minz_Request::param('topline_read', false));
$this->view->conf->_topline_favorite(Minz_Request::param('topline_favorite', false));
$this->view->conf->_topline_date(Minz_Request::param('topline_date', false));
@@ -170,131 +219,127 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$this->view->conf->_bottomline_tags(Minz_Request::param('bottomline_tags', false));
$this->view->conf->_bottomline_date(Minz_Request::param('bottomline_date', false));
$this->view->conf->_bottomline_link(Minz_Request::param('bottomline_link', false));
+ $this->view->conf->_html5_notif_timeout(Minz_Request::param('html5_notif_timeout', 0));
$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 (
- 'type' => 'good',
- 'content' => Minz_Translate::t ('configuration_updated')
- );
- Minz_Session::_param ('notification', $notif);
-
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'display'), true);
+ Minz_Request::good(_t('configuration_updated'),
+ array('c' => 'configure', 'a' => 'display'));
}
$this->view->themes = FreshRSS_Themes::get();
- Minz_View::prependTitle (Minz_Translate::t ('reading_configuration') . ' · ');
+ Minz_View::prependTitle(_t('display_configuration') . ' · ');
}
- public function sharingAction () {
- if (Minz_Request::isPost ()) {
- $this->view->conf->_sharing (array(
- 'shaarli' => Minz_Request::param ('shaarli', false),
- 'wallabag' => Minz_Request::param ('wallabag', false),
- 'diaspora' => Minz_Request::param ('diaspora', false),
- 'twitter' => Minz_Request::param ('twitter', false),
- 'g+' => Minz_Request::param ('g+', false),
- 'facebook' => Minz_Request::param ('facebook', false),
- 'email' => Minz_Request::param ('email', false),
- 'print' => Minz_Request::param ('print', false),
+ /**
+ * This action handles the reading configuration page.
+ *
+ * It displays the reading configuration page.
+ * If this action is reached through a POST request, it stores all new
+ * configuration values then sends a notification to the user.
+ *
+ * The options available on the page are:
+ * - number of posts per page (default: 10)
+ * - view mode (default: normal)
+ * - default article view (default: all)
+ * - load automatically articles
+ * - display expanded articles
+ * - display expanded categories
+ * - hide categories and feeds without unread articles
+ * - jump on next category or feed when marked as read
+ * - image lazy loading
+ * - stick open articles to the top
+ * - display a confirmation when reading all articles
+ * - article order (default: DESC)
+ * - mark articles as read when:
+ * - displayed
+ * - opened on site
+ * - scrolled
+ * - received
+ * Default values are false unless specified.
+ */
+ 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((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->_display_categories(Minz_Request::param('display_categories', false));
+ $this->view->conf->_hide_read_feeds(Minz_Request::param('hide_read_feeds', 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->_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(
+ 'article' => Minz_Request::param('mark_open_article', false),
+ 'site' => Minz_Request::param('mark_open_site', false),
+ 'scroll' => Minz_Request::param('mark_scroll', false),
+ 'reception' => Minz_Request::param('mark_upon_reception', false),
));
$this->view->conf->save();
- invalidateHttpCache();
- $notif = array (
- 'type' => 'good',
- 'content' => Minz_Translate::t ('configuration_updated')
- );
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('language', $this->view->conf->language);
+ Minz_Translate::reset();
+ invalidateHttpCache();
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'sharing'), true);
+ Minz_Request::good(_t('configuration_updated'),
+ array('c' => 'configure', 'a' => 'reading'));
}
- Minz_View::prependTitle (Minz_Translate::t ('sharing') . ' · ');
+ Minz_View::prependTitle(_t('reading_configuration') . ' · ');
}
- public function importExportAction () {
- require_once(LIB_PATH . '/lib_opml.php');
- $catDAO = new FreshRSS_CategoryDAO ();
- $this->view->categories = $catDAO->listCategories ();
-
- $this->view->req = Minz_Request::param ('q');
-
- if ($this->view->req == 'export') {
- Minz_View::_title ('freshrss_feeds.opml');
-
- $this->view->_useLayout (false);
- header('Content-Type: application/xml; charset=utf-8');
- header('Content-disposition: attachment; filename=freshrss_feeds.opml');
-
- $feedDAO = new FreshRSS_FeedDAO ();
- $catDAO = new FreshRSS_CategoryDAO ();
-
- $list = array ();
- foreach ($catDAO->listCategories () as $key => $cat) {
- $list[$key]['name'] = $cat->name ();
- $list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
- }
-
- $this->view->categories = $list;
- } elseif ($this->view->req == 'import' && Minz_Request::isPost ()) {
- if ($_FILES['file']['error'] == 0) {
- invalidateHttpCache();
- // on parse le fichier OPML pour récupérer les catégories et les flux associés
- try {
- list ($categories, $feeds) = opml_import (
- file_get_contents ($_FILES['file']['tmp_name'])
- );
-
- // On redirige vers le controller feed qui va se charger d'insérer les flux en BDD
- // les flux sont mis au préalable dans des variables de Request
- Minz_Request::_param ('q', 'null');
- Minz_Request::_param ('categories', $categories);
- Minz_Request::_param ('feeds', $feeds);
- Minz_Request::forward (array ('c' => 'feed', 'a' => 'massiveImport'));
- } catch (FreshRSS_Opml_Exception $e) {
- Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
-
- $notif = array (
- 'type' => 'bad',
- 'content' => Minz_Translate::t ('bad_opml_file')
- );
- Minz_Session::_param ('notification', $notif);
+ /**
+ * This action handles the sharing configuration page.
+ *
+ * It displays the sharing configuration page.
+ * If this action is reached through a POST request, it stores all
+ * configuration values then sends a notification to the user.
+ */
+ public function sharingAction() {
+ if (Minz_Request::isPost()) {
+ $params = Minz_Request::params();
+ $this->view->conf->_sharing($params['share']);
+ $this->view->conf->save();
+ invalidateHttpCache();
- Minz_Request::forward (array (
- 'c' => 'configure',
- 'a' => 'importExport'
- ), true);
- }
- }
+ Minz_Request::good(_t('configuration_updated'),
+ array('c' => 'configure', 'a' => 'sharing'));
}
- $feedDAO = new FreshRSS_FeedDAO ();
- $this->view->feeds = $feedDAO->listFeeds ();
-
- // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste
- $this->view->flux = false;
-
- Minz_View::prependTitle (Minz_Translate::t ('import_export_opml') . ' · ');
+ Minz_View::prependTitle(_t('sharing') . ' · ');
}
- public function shortcutAction () {
- $list_keys = array ('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter',
+ /**
+ * This action handles the shortcut configuration page.
+ *
+ * It displays the shortcut configuration page.
+ * If this action is reached through a POST request, it stores all new
+ * configuration values then sends a notification to the user.
+ *
+ * The authorized values for shortcuts are letters (a to z), numbers (0
+ * to 9), function keys (f1 to f12), backspace, delete, down, end, enter,
+ * escape, home, insert, left, page down, page up, return, right, space,
+ * tab and up.
+ */
+ 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',
- 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
- '9', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
+ 'z', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
'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)) {
@@ -302,48 +347,56 @@ 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 (
- 'type' => 'good',
- 'content' => Minz_Translate::t ('shortcuts_updated')
- );
- Minz_Session::_param ('notification', $notif);
-
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true);
+ Minz_Request::good(_t('shortcuts_updated'),
+ array('c' => 'configure', 'a' => 'shortcut'));
}
- Minz_View::prependTitle (Minz_Translate::t ('shortcuts') . ' · ');
+ Minz_View::prependTitle(_t('shortcuts') . ' · ');
}
+ /**
+ * This action display the user configuration page
+ *
+ * @todo move that action in the user controller
+ */
public function usersAction() {
- Minz_View::prependTitle(Minz_Translate::t ('users') . ' · ');
+ Minz_View::prependTitle(_t('users') . ' · ');
}
- public function archivingAction () {
+ /**
+ * This action handles the archive configuration page.
+ *
+ * It displays the archive configuration page.
+ * If this action is reached through a POST request, it stores all new
+ * configuration values then sends a notification to the user.
+ *
+ * The options available on that page are:
+ * - duration to retain old article (default: 3)
+ * - number of article to retain per feed (default: 0)
+ * - refresh frequency (default: -2)
+ *
+ * @todo explain why the default value is -2 but this value does not
+ * exist in the drop-down list
+ */
+ public function archivingAction() {
if (Minz_Request::isPost()) {
- $old = Minz_Request::param('old_entries', 3);
- $keepHistoryDefault = Minz_Request::param('keep_history_default', 0);
-
- $this->view->conf->_old_entries($old);
- $this->view->conf->_keep_history_default($keepHistoryDefault);
+ $this->view->conf->_old_entries(Minz_Request::param('old_entries', 3));
+ $this->view->conf->_keep_history_default(Minz_Request::param('keep_history_default', 0));
+ $this->view->conf->_ttl_default(Minz_Request::param('ttl_default', -2));
$this->view->conf->save();
invalidateHttpCache();
- $notif = array(
- 'type' => 'good',
- 'content' => Minz_Translate::t('configuration_updated')
- );
- Minz_Session::_param('notification', $notif);
-
- Minz_Request::forward(array('c' => 'configure', 'a' => 'archiving'), true);
+ Minz_Request::good(_t('configuration_updated'),
+ array('c' => 'configure', 'a' => 'archiving'));
}
- Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' · ');
+ Minz_View::prependTitle(_t('archiving_configuration') . ' · ');
- $entryDAO = new FreshRSS_EntryDAO();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$this->view->nb_total = $entryDAO->count();
$this->view->size_user = $entryDAO->size();
@@ -351,4 +404,119 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$this->view->size_total = $entryDAO->size(true);
}
}
+
+ /**
+ * This action handles the user queries configuration page.
+ *
+ * If this action is reached through a POST request, it stores all new
+ * configuration values then sends a notification to the user then
+ * redirect to the same page.
+ * If this action is not reached through a POST request, it displays the
+ * configuration page and verifies that every user query is runable by
+ * checking if categories and feeds are still in use.
+ */
+ public function queriesAction() {
+ if (Minz_Request::isPost()) {
+ $queries = Minz_Request::param('queries', array());
+
+ foreach ($queries as $key => $query) {
+ if (!$query['name']) {
+ $query['name'] = _t('query_number', $key + 1);
+ }
+ }
+ $this->view->conf->_queries($queries);
+ $this->view->conf->save();
+
+ Minz_Request::good(_t('configuration_updated'),
+ array('c' => 'configure', 'a' => 'queries'));
+ } else {
+ $this->view->query_get = array();
+ $cat_dao = new FreshRSS_CategoryDAO();
+ $feed_dao = FreshRSS_Factory::createFeedDao();
+ foreach ($this->view->conf->queries as $key => $query) {
+ if (!isset($query['get'])) {
+ continue;
+ }
+
+ switch ($query['get'][0]) {
+ case 'c':
+ $category = $cat_dao->searchById(substr($query['get'], 2));
+
+ $deprecated = true;
+ $cat_name = '';
+ if ($category) {
+ $cat_name = $category->name();
+ $deprecated = false;
+ }
+
+ $this->view->query_get[$key] = array(
+ 'type' => 'category',
+ 'name' => $cat_name,
+ 'deprecated' => $deprecated,
+ );
+ break;
+ case 'f':
+ $feed = $feed_dao->searchById(substr($query['get'], 2));
+
+ $deprecated = true;
+ $feed_name = '';
+ if ($feed) {
+ $feed_name = $feed->name();
+ $deprecated = false;
+ }
+
+ $this->view->query_get[$key] = array(
+ 'type' => 'feed',
+ 'name' => $feed_name,
+ 'deprecated' => $deprecated,
+ );
+ break;
+ case 's':
+ $this->view->query_get[$key] = array(
+ 'type' => 'favorite',
+ 'name' => 'favorite',
+ 'deprecated' => false,
+ );
+ break;
+ case 'a':
+ $this->view->query_get[$key] = array(
+ 'type' => 'all',
+ 'name' => 'all',
+ 'deprecated' => false,
+ );
+ break;
+ }
+ }
+ }
+
+ Minz_View::prependTitle(_t('queries') . ' · ');
+ }
+
+ /**
+ * This action handles the creation of a user query.
+ *
+ * It gets the GET parameters and stores them in the configuration query
+ * storage. Before it is saved, the unwanted parameters are unset to keep
+ * lean data.
+ */
+ public function addQueryAction() {
+ $whitelist = array('get', 'order', 'name', 'search', 'state');
+ $queries = $this->view->conf->queries;
+ $query = Minz_Request::params();
+ $query['name'] = _t('query_number', count($queries) + 1);
+ foreach ($query as $key => $value) {
+ if (!in_array($key, $whitelist)) {
+ unset($query[$key]);
+ }
+ }
+ if (!empty($query['state']) && $query['state'] & FreshRSS_Entry::STATE_STRICT) {
+ $query['state'] -= FreshRSS_Entry::STATE_STRICT;
+ }
+ $queries[] = $query;
+ $this->view->conf->_queries($queries);
+ $this->view->conf->save();
+
+ Minz_Request::good(_t('query_created', $query['name']),
+ array('c' => 'configure', 'a' => 'queries'));
+ }
}
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index 1756c91e5..ab66d9198 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -43,8 +43,12 @@ 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 (!Minz_Request::isPost()) {
+ return;
+ }
+
if (!$get) {
$entryDAO->markReadEntries ($idMax);
} else {
@@ -85,7 +89,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,9 +101,12 @@ 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 = FreshRSS_Factory::createFeedDao();
+ $feedDAO->updateCachedValues();
+
invalidateHttpCache();
$notif = array (
@@ -121,8 +128,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();
@@ -137,11 +144,13 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
if ($nb > 0) {
$nbTotal += $nb;
Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
- $feedDAO->updateLastUpdate($feed->id());
+ //$feedDAO->updateLastUpdate($feed->id());
}
}
}
+ $feedDAO->updateCachedValues();
+
invalidateHttpCache();
$notif = array(
diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php
index dc9a2ee25..922650b3d 100644
--- a/app/Controllers/errorController.php
+++ b/app/Controllers/errorController.php
@@ -1,26 +1,38 @@
<?php
class FreshRSS_error_Controller extends Minz_ActionController {
- public function indexAction () {
- switch (Minz_Request::param ('code')) {
- case 403:
- $this->view->code = 'Error 403 - Forbidden';
- break;
- case 404:
- $this->view->code = 'Error 404 - Not found';
- break;
- case 500:
- $this->view->code = 'Error 500 - Internal Server Error';
- break;
- case 503:
- $this->view->code = 'Error 503 - Service Unavailable';
- break;
- default:
- $this->view->code = 'Error 404 - Not found';
+ public function indexAction() {
+ switch (Minz_Request::param('code')) {
+ case 403:
+ $this->view->code = 'Error 403 - Forbidden';
+ break;
+ case 404:
+ $this->view->code = 'Error 404 - Not found';
+ break;
+ case 500:
+ $this->view->code = 'Error 500 - Internal Server Error';
+ break;
+ case 503:
+ $this->view->code = 'Error 503 - Service Unavailable';
+ break;
+ default:
+ $this->view->code = 'Error 404 - Not found';
}
-
- $this->view->logs = Minz_Request::param ('logs');
-
- Minz_View::prependTitle ($this->view->code . ' · ');
+
+ $errors = Minz_Request::param('logs', array());
+ $this->view->errorMessage = trim(implode($errors));
+ if ($this->view->errorMessage == '') {
+ switch(Minz_Request::param('code')) {
+ case 403:
+ $this->view->errorMessage = Minz_Translate::t('forbidden_access');
+ break;
+ case 404:
+ default:
+ $this->view->errorMessage = Minz_Translate::t('page_not_found');
+ break;
+ }
+ }
+
+ Minz_View::prependTitle($this->view->code . ' · ');
}
}
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index c718fcd5c..c7cc25fbb 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -22,14 +22,32 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
public function addAction () {
- @set_time_limit(300);
+ $url = Minz_Request::param('url_rss', false);
+
+ if ($url === false) {
+ Minz_Request::forward(array(
+ 'c' => 'configure',
+ 'a' => 'feed'
+ ), true);
+ }
+
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $this->catDAO = new FreshRSS_CategoryDAO ();
+ $this->catDAO->checkDefault ();
+
+ if (Minz_Request::isPost()) {
+ @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 === 'nc') {
+ $new_cat = Minz_Request::param ('new_category');
+ if (empty($new_cat['name'])) {
+ $cat = false;
+ } else {
+ $cat = $this->catDAO->addCategory($new_cat);
+ }
+ }
if ($cat === false) {
$def_cat = $this->catDAO->getDefault ();
$cat = $def_cat->id ();
@@ -52,7 +70,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feed->load(true);
- $feedDAO = new FreshRSS_FeedDAO ();
$values = array (
'url' => $feed->url (),
'category' => $feed->category (),
@@ -85,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é
@@ -128,7 +150,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
$notif = array (
'type' => 'bad',
- 'content' => Minz_Translate::t ('internal_problem_feed')
+ 'content' => Minz_Translate::t ('internal_problem_feed', Minz_Url::display(array('a' => 'logs')))
);
Minz_Session::_param ('notification', $notif);
} catch (Minz_FileNotExistException $e) {
@@ -136,7 +158,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
$notif = array (
'type' => 'bad',
- 'content' => Minz_Translate::t ('internal_problem_feed')
+ 'content' => Minz_Translate::t ('internal_problem_feed', Minz_Url::display(array('a' => 'logs')))
);
Minz_Session::_param ('notification', $notif);
}
@@ -145,13 +167,46 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true);
+ } else {
+
+ // 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;
+ }
+
+ $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',
@@ -166,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');
@@ -183,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
@@ -215,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);
}
}
}
@@ -251,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) {
@@ -319,88 +376,23 @@ 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 ();
-
- $categories = Minz_Request::param ('categories', array (), true);
- $feeds = Minz_Request::param ('feeds', array (), true);
-
- // on ajoute les catégories en masse dans une fonction à part
- $this->addCategories ($categories);
-
- // 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);
-
- // la variable $error permet de savoir si une erreur est survenue
- // Le but est de ne pas arrêter l'import même en cas d'erreur
- // L'utilisateur sera mis au courant s'il y a eu des erreurs, mais
- // ne connaîtra pas les détails. Ceux-ci seront toutefois logguées
- $error = false;
- $i = 0;
- foreach ($feeds as $feed) {
- try {
- $values = array (
- 'id' => $feed->id (),
- 'url' => $feed->url (),
- 'category' => $feed->category (),
- 'name' => $feed->name (),
- 'website' => $feed->website (),
- 'description' => $feed->description (),
- 'lastUpdate' => 0,
- 'httpAuth' => $feed->httpAuth ()
- );
-
- // ajout du flux que s'il n'est pas déjà en BDD
- if (!$feedDAO->searchByUrl ($values['url'])) {
- $id = $feedDAO->addFeed ($values);
- if ($id) {
- $feed->_id ($id);
- $feed->faviconPrepare();
- } else {
- $error = true;
- }
- }
- } catch (FreshRSS_Feed_Exception $e) {
- $error = true;
- Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
- }
- }
-
- if ($error) {
- $res = Minz_Translate::t ('feeds_imported_with_errors');
- } else {
- $res = Minz_Translate::t ('feeds_imported');
- }
-
- $notif = array (
- 'type' => 'good',
- 'content' => $res
- );
- Minz_Session::_param ('notification', $notif);
- Minz_Session::_param ('actualize_feeds', true);
-
- // et on redirige vers la page d'accueil
- Minz_Request::forward (array (
- 'c' => 'index',
- 'a' => 'index'
- ), true);
- }
-
public function deleteAction () {
if (Minz_Request::isPost ()) {
$type = Minz_Request::param ('type', 'feed');
$id = Minz_Request::param ('id');
- $feedDAO = new FreshRSS_FeedDAO ();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
if ($type == 'category') {
+ // List feeds to remove then related user queries.
+ $feeds = $feedDAO->listByCategory($id);
+
if ($feedDAO->deleteFeedByCategory ($id)) {
+ // Remove related queries
+ foreach ($feeds as $feed) {
+ $this->view->conf->remove_query_by_get('f_' . $feed->id());
+ }
+ $this->view->conf->save();
+
$notif = array (
'type' => 'good',
'content' => Minz_Translate::t ('category_emptied')
@@ -414,6 +406,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
} else {
if ($feedDAO->deleteFeed ($id)) {
+ // Remove related queries
+ $this->view->conf->remove_query_by_get('f_' . $id);
+ $this->view->conf->save();
+
$notif = array (
'type' => 'good',
'content' => Minz_Translate::t ('feed_deleted')
@@ -429,22 +425,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
Minz_Session::_param ('notification', $notif);
- if ($type == 'category') {
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
+ $redirect_url = Minz_Request::param('r', false, true);
+ if ($redirect_url) {
+ Minz_Request::forward($redirect_url);
+ } elseif ($type == 'category') {
+ Minz_Request::forward(array ('c' => 'configure', 'a' => 'categorize'), true);
} else {
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed'), true);
- }
- }
- }
-
- private function addCategories ($categories) {
- foreach ($categories as $cat) {
- if (!$this->catDAO->searchByName ($cat->name ())) {
- $values = array (
- 'id' => $cat->id (),
- 'name' => $cat->name (),
- );
- $catDAO->addCategory ($values);
+ Minz_Request::forward(array ('c' => 'configure', 'a' => 'feed'), true);
}
}
}
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
new file mode 100644
index 000000000..f329766b8
--- /dev/null
+++ b/app/Controllers/importExportController.php
@@ -0,0 +1,447 @@
+<?php
+
+class FreshRSS_importExport_Controller extends Minz_ActionController {
+ public function firstAction() {
+ if (!$this->view->loginOk) {
+ Minz_Error::error(
+ 403,
+ array('error' => array(_t('access_denied')))
+ );
+ }
+
+ require_once(LIB_PATH . '/lib_opml.php');
+
+ $this->catDAO = new FreshRSS_CategoryDAO();
+ $this->entryDAO = FreshRSS_Factory::createEntryDao();
+ $this->feedDAO = FreshRSS_Factory::createFeedDao();
+ }
+
+ public function indexAction() {
+ $this->view->categories = $this->catDAO->listCategories();
+ $this->view->feeds = $this->feedDAO->listFeeds();
+
+ Minz_View::prependTitle(_t('import_export') . ' · ');
+ }
+
+ public function importAction() {
+ if (!Minz_Request::isPost()) {
+ Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
+ }
+
+ $file = $_FILES['file'];
+ $status_file = $file['error'];
+
+ if ($status_file !== 0) {
+ Minz_Log::error('File cannot be uploaded. Error code: ' . $status_file);
+ Minz_Request::bad(_t('file_cannot_be_uploaded'),
+ array('c' => 'importExport', 'a' => 'index'));
+ }
+
+ @set_time_limit(300);
+
+ $type_file = $this->guessFileType($file['name']);
+
+ $list_files = array(
+ 'opml' => array(),
+ 'json_starred' => array(),
+ 'json_feed' => array()
+ );
+
+ // We try to list all files according to their type
+ $list = array();
+ if ($type_file === 'zip' && extension_loaded('zip')) {
+ $zip = zip_open($file['tmp_name']);
+
+ if (!is_resource($zip)) {
+ // zip_open cannot open file: something is wrong
+ Minz_Log::error('Zip archive cannot be imported. Error code: ' . $zip);
+ Minz_Request::bad(_t('zip_error'),
+ array('c' => 'importExport', 'a' => 'index'));
+ }
+
+ while (($zipfile = zip_read($zip)) !== false) {
+ if (!is_resource($zipfile)) {
+ // zip_entry() can also return an error code!
+ Minz_Log::error('Zip file cannot be imported. Error code: ' . $zipfile);
+ } else {
+ $type_zipfile = $this->guessFileType(zip_entry_name($zipfile));
+ if ($type_file !== 'unknown') {
+ $list_files[$type_zipfile][] = zip_entry_read(
+ $zipfile,
+ zip_entry_filesize($zipfile)
+ );
+ }
+ }
+ }
+
+ zip_close($zip);
+ } elseif ($type_file === 'zip') {
+ // Zip extension is not loaded
+ Minz_Request::bad(_t('no_zip_extension'),
+ array('c' => 'importExport', 'a' => 'index'));
+ } elseif ($type_file !== 'unknown') {
+ $list_files[$type_file][] = file_get_contents($file['tmp_name']);
+ }
+
+ // Import file contents.
+ // OPML first(so categories and feeds are imported)
+ // Starred articles then so the "favourite" status is already set
+ // And finally all other files.
+ $error = false;
+ foreach ($list_files['opml'] as $opml_file) {
+ $error = $this->importOpml($opml_file);
+ }
+ foreach ($list_files['json_starred'] as $article_file) {
+ $error = $this->importArticles($article_file, true);
+ }
+ foreach ($list_files['json_feed'] as $article_file) {
+ $error = $this->importArticles($article_file);
+ }
+
+ // And finally, we get import status and redirect to the home page
+ Minz_Session::_param('actualize_feeds', true);
+ $content_notif = $error === true ? _t('feeds_imported_with_errors') :
+ _t('feeds_imported');
+ Minz_Request::good($content_notif);
+ }
+
+ private function guessFileType($filename) {
+ // A *very* basic guess file type function. Only based on filename
+ // That's could be improved but should be enough, at least for a first
+ // implementation.
+
+ if (substr_compare($filename, '.zip', -4) === 0) {
+ return 'zip';
+ } elseif (substr_compare($filename, '.opml', -5) === 0 ||
+ substr_compare($filename, '.xml', -4) === 0) {
+ return 'opml';
+ } elseif (substr_compare($filename, '.json', -5) === 0 &&
+ strpos($filename, 'starred') !== false) {
+ return 'json_starred';
+ } elseif (substr_compare($filename, '.json', -5) === 0) {
+ return 'json_feed';
+ } else {
+ return 'unknown';
+ }
+ }
+
+ private function importOpml($opml_file) {
+ $opml_array = array();
+ try {
+ $opml_array = libopml_parse_string($opml_file);
+ } catch (LibOPML_Exception $e) {
+ Minz_Log::warning($e->getMessage());
+ return true;
+ }
+
+ $this->catDAO->checkDefault();
+
+ return $this->addOpmlElements($opml_array['body']);
+ }
+
+ private function addOpmlElements($opml_elements, $parent_cat = null) {
+ $error = false;
+ foreach ($opml_elements as $elt) {
+ $res = false;
+ if (isset($elt['xmlUrl'])) {
+ $res = $this->addFeedOpml($elt, $parent_cat);
+ } else {
+ $res = $this->addCategoryOpml($elt, $parent_cat);
+ }
+
+ if (!$error && $res) {
+ // oops: there is at least one error!
+ $error = $res;
+ }
+ }
+
+ return $error;
+ }
+
+ private function addFeedOpml($feed_elt, $parent_cat) {
+ if (is_null($parent_cat)) {
+ // This feed has no parent category so we get the default one
+ $parent_cat = $this->catDAO->getDefault()->name();
+ }
+
+ $cat = $this->catDAO->searchByName($parent_cat);
+
+ if (!$cat) {
+ return true;
+ }
+
+ // We get different useful information
+ $url = Minz_Helper::htmlspecialchars_utf8($feed_elt['xmlUrl']);
+ $name = Minz_Helper::htmlspecialchars_utf8($feed_elt['text']);
+ $website = '';
+ if (isset($feed_elt['htmlUrl'])) {
+ $website = Minz_Helper::htmlspecialchars_utf8($feed_elt['htmlUrl']);
+ }
+ $description = '';
+ if (isset($feed_elt['description'])) {
+ $description = Minz_Helper::htmlspecialchars_utf8($feed_elt['description']);
+ }
+
+ $error = false;
+ try {
+ // Create a Feed object and add it in DB
+ $feed = new FreshRSS_Feed($url);
+ $feed->_category($cat->id());
+ $feed->_name($name);
+ $feed->_website($website);
+ $feed->_description($description);
+
+ // addFeedObject checks if feed is already in DB so nothing else to
+ // check here
+ $id = $this->feedDAO->addFeedObject($feed);
+ $error = ($id === false);
+ } catch (FreshRSS_Feed_Exception $e) {
+ Minz_Log::warning($e->getMessage());
+ $error = true;
+ }
+
+ return $error;
+ }
+
+ private function addCategoryOpml($cat_elt, $parent_cat) {
+ // Create a new Category object
+ $cat = new FreshRSS_Category(Minz_Helper::htmlspecialchars_utf8($cat_elt['text']));
+
+ $id = $this->catDAO->addCategoryObject($cat);
+ $error = ($id === false);
+
+ if (isset($cat_elt['@outlines'])) {
+ // Our cat_elt contains more categories or more feeds, so we
+ // add them recursively.
+ // Note: FreshRSS does not support yet category arborescence
+ $res = $this->addOpmlElements($cat_elt['@outlines'], $cat->name());
+ if (!$error && $res) {
+ $error = true;
+ }
+ }
+
+ return $error;
+ }
+
+ private function importArticles($article_file, $starred = false) {
+ $article_object = json_decode($article_file, true);
+ if (is_null($article_object)) {
+ Minz_Log::warning('Try to import a non-JSON file');
+ return true;
+ }
+
+ $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0;
+
+ $google_compliant = (
+ strpos($article_object['id'], 'com.google') !== false
+ );
+
+ $error = false;
+ $article_to_feed = array();
+
+ // First, we check feeds of articles are in DB (and add them if needed).
+ foreach ($article_object['items'] as $item) {
+ $feed = $this->addFeedArticles($item['origin'], $google_compliant);
+ if (is_null($feed)) {
+ $error = true;
+ } else {
+ $article_to_feed[$item['id']] = $feed->id();
+ }
+ }
+
+ // Then, articles are imported.
+ $prepared_statement = $this->entryDAO->addEntryPrepare();
+ $this->entryDAO->beginTransaction();
+ foreach ($article_object['items'] as $item) {
+ if (!isset($article_to_feed[$item['id']])) {
+ continue;
+ }
+
+ $feed_id = $article_to_feed[$item['id']];
+ $author = isset($item['author']) ? $item['author'] : '';
+ $key_content = ($google_compliant && !isset($item['content'])) ?
+ 'summary' : 'content';
+ $tags = $item['categories'];
+ if ($google_compliant) {
+ $tags = array_filter($tags, function($var) {
+ return strpos($var, '/state/com.google') === false;
+ });
+ }
+
+ $entry = new FreshRSS_Entry(
+ $feed_id, $item['id'], $item['title'], $author,
+ $item[$key_content]['content'], $item['alternate'][0]['href'],
+ $item['published'], $is_read, $starred
+ );
+ $entry->_id(min(time(), $entry->date(true)) . uSecString());
+ $entry->_tags($tags);
+
+ $values = $entry->toArray();
+ $id = $this->entryDAO->addEntry($values, $prepared_statement);
+
+ if (!$error && ($id === false)) {
+ $error = true;
+ }
+ }
+ $this->entryDAO->commit();
+
+ return $error;
+ }
+
+ private function addFeedArticles($origin, $google_compliant) {
+ $default_cat = $this->catDAO->getDefault();
+
+ $return = null;
+ $key = $google_compliant ? 'htmlUrl' : 'feedUrl';
+ $url = $origin[$key];
+ $name = $origin['title'];
+ $website = $origin['htmlUrl'];
+
+ try {
+ // Create a Feed object and add it in DB
+ $feed = new FreshRSS_Feed($url);
+ $feed->_category($default_cat->id());
+ $feed->_name($name);
+ $feed->_website($website);
+
+ // addFeedObject checks if feed is already in DB so nothing else to
+ // check here
+ $id = $this->feedDAO->addFeedObject($feed);
+
+ if ($id !== false) {
+ $feed->_id($id);
+ $return = $feed;
+ }
+ } catch (FreshRSS_Feed_Exception $e) {
+ Minz_Log::warning($e->getMessage());
+ }
+
+ return $return;
+ }
+
+ public function exportAction() {
+ if (!Minz_Request::isPost()) {
+ Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
+ }
+
+ $this->view->_useLayout(false);
+
+ $export_opml = Minz_Request::param('export_opml', false);
+ $export_starred = Minz_Request::param('export_starred', false);
+ $export_feeds = Minz_Request::param('export_feeds', array());
+
+ $export_files = array();
+ if ($export_opml) {
+ $export_files['feeds.opml'] = $this->generateOpml();
+ }
+
+ if ($export_starred) {
+ $export_files['starred.json'] = $this->generateArticles('starred');
+ }
+
+ foreach ($export_feeds as $feed_id) {
+ $feed = $this->feedDAO->searchById($feed_id);
+ if ($feed) {
+ $filename = 'feed_' . $feed->category() . '_'
+ . $feed->id() . '.json';
+ $export_files[$filename] = $this->generateArticles(
+ 'feed', $feed
+ );
+ }
+ }
+
+ $nb_files = count($export_files);
+ if ($nb_files > 1) {
+ // If there are more than 1 file to export, we need a zip archive.
+ try {
+ $this->exportZip($export_files);
+ } catch (Exception $e) {
+ # Oops, there is no Zip extension!
+ Minz_Request::bad(_t('export_no_zip_extension'),
+ array('c' => 'importExport', 'a' => 'index'));
+ }
+ } elseif ($nb_files === 1) {
+ // Only one file? Guess its type and export it.
+ $filename = key($export_files);
+ $type = $this->guessFileType($filename);
+ $this->exportFile('freshrss_' . $filename, $export_files[$filename], $type);
+ } else {
+ Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
+ }
+ }
+
+ private function generateOpml() {
+ $list = array();
+ foreach ($this->catDAO->listCategories() as $key => $cat) {
+ $list[$key]['name'] = $cat->name();
+ $list[$key]['feeds'] = $this->feedDAO->listByCategory($cat->id());
+ }
+
+ $this->view->categories = $list;
+ return $this->view->helperToString('export/opml');
+ }
+
+ private function generateArticles($type, $feed = NULL) {
+ $this->view->categories = $this->catDAO->listCategories();
+
+ if ($type == 'starred') {
+ $this->view->list_title = _t('starred_list');
+ $this->view->type = 'starred';
+ $unread_fav = $this->entryDAO->countUnreadReadFavorites();
+ $this->view->entries = $this->entryDAO->listWhere(
+ 's', '', FreshRSS_Entry::STATE_ALL, 'ASC',
+ $unread_fav['all']
+ );
+ } elseif ($type == 'feed' && !is_null($feed)) {
+ $this->view->list_title = _t('feed_list', $feed->name());
+ $this->view->type = 'feed/' . $feed->id();
+ $this->view->entries = $this->entryDAO->listWhere(
+ 'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC',
+ $this->view->conf->posts_per_page
+ );
+ $this->view->feed = $feed;
+ }
+
+ return $this->view->helperToString('export/articles');
+ }
+
+ private function exportZip($files) {
+ if (!extension_loaded('zip')) {
+ throw new Exception();
+ }
+
+ // From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly
+ $zip_file = tempnam('tmp', 'zip');
+ $zip = new ZipArchive();
+ $zip->open($zip_file, ZipArchive::OVERWRITE);
+
+ foreach ($files as $filename => $content) {
+ $zip->addFromString($filename, $content);
+ }
+
+ // Close and send to user
+ $zip->close();
+ header('Content-Type: application/zip');
+ header('Content-Length: ' . filesize($zip_file));
+ header('Content-Disposition: attachment; filename="freshrss_export.zip"');
+ readfile($zip_file);
+ unlink($zip_file);
+ }
+
+ private function exportFile($filename, $content, $type) {
+ if ($type === 'unknown') {
+ return;
+ }
+
+ $content_type = '';
+ if ($type === 'opml') {
+ $content_type = "text/opml";
+ } elseif ($type === 'json_feed' || $type === 'json_starred') {
+ $content_type = "text/json";
+ }
+
+ header('Content-Type: ' . $content_type . '; charset=utf-8');
+ header('Content-disposition: attachment; filename=' . $filename);
+ print($content);
+ }
+}
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 38f4c0e7c..e8e26b142 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -25,16 +25,12 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
}
- // construction of RSS url of this feed
$params = Minz_Request::params ();
- $params['output'] = 'rss';
if (isset ($params['search'])) {
$params['search'] = urlencode ($params['search']);
}
- if (!Minz_Configuration::allowAnonymous()) {
- $params['token'] = $token;
- }
- $this->view->rss_url = array (
+
+ $this->view->url = array (
'c' => 'index',
'a' => 'index',
'params' => $params
@@ -49,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 ();
@@ -73,31 +69,32 @@ 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 (
+ 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) . ')' : '') .
' · '
);
// On récupère les différents éléments de filtrage
- $this->view->state = $state = Minz_Request::param ('state', $this->view->conf->default_view);
+ $this->view->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 = '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', '');
- if ($state === 'not_read') { //Any unread article in this category at all?
+ $ajax_request = Minz_Request::param('ajax', false);
+ if ($output === 'reader') {
+ $nb = max(1, round($nb / 2));
+ }
+
+ if ($this->view->state === FreshRSS_Entry::STATE_NOT_READ) { //Any unread article in this category at all?
switch ($getType) {
case 'a':
$hasUnread = $this->view->nb_not_read > 0;
break;
case 's':
+ // This is deprecated. The favorite button does not exist anymore
$hasUnread = $this->view->nb_favorites['unread'] > 0;
break;
case 'c':
@@ -111,8 +108,8 @@ class FreshRSS_index_Controller extends Minz_ActionController {
$hasUnread = true;
break;
}
- if (!$hasUnread) {
- $this->view->state = $state = 'all';
+ if (!$hasUnread && ($state_param === null)) {
+ $this->view->state = FreshRSS_Entry::STATE_ALL;
}
}
@@ -125,15 +122,22 @@ class FreshRSS_index_Controller extends Minz_ActionController {
$keepHistoryDefault = $this->view->conf->keep_history_default;
try {
- $entries = $entryDAO->listWhere($getType, $getId, $state, $order, $nb + 1, $first, $filter, $date_min, $keepHistoryDefault);
+ $entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb + 1, $first, $filter, $date_min, true, $keepHistoryDefault);
// Si on a récupéré aucun article "non lus"
// on essaye de récupérer tous les articles
- if ($state === 'not_read' && empty($entries)) {
- Minz_Log::record ('Conflicting information about nbNotRead!', Minz_Log::DEBUG);
- $this->view->state = 'all';
- $entries = $entryDAO->listWhere($getType, $getId, 'all', $order, $nb, $first, $filter, $date_min, $keepHistoryDefault);
+ if ($this->view->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);
}
+ Minz_Request::_param('state', $this->view->state);
if (count($entries) <= $nb) {
$this->view->nextId = '';
@@ -186,7 +190,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) {
@@ -203,25 +207,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') . ' · ');
}
@@ -316,7 +301,46 @@ class FreshRSS_index_Controller extends Minz_ActionController {
Minz_Session::_param('passwordHash');
}
+ private static function makeLongTermCookie($username, $passwordHash) {
+ do {
+ $token = sha1(Minz_Configuration::salt() . $username . uniqid(mt_rand(), true));
+ $tokenFile = DATA_PATH . '/tokens/' . $token . '.txt';
+ } while (file_exists($tokenFile));
+ if (@file_put_contents($tokenFile, $username . "\t" . $passwordHash) === false) {
+ return false;
+ }
+ $expire = time() + 2629744; //1 month //TODO: Use a configuration instead
+ Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire);
+ Minz_Session::_param('token', $token);
+ return $token;
+ }
+
+ private static function deleteLongTermCookie() {
+ Minz_Session::deleteLongTermCookie('FreshRSS_login');
+ $token = Minz_Session::param('token', null);
+ if (ctype_alnum($token)) {
+ @unlink(DATA_PATH . '/tokens/' . $token . '.txt');
+ }
+ Minz_Session::_param('token');
+ if (rand(0, 10) === 1) {
+ self::purgeTokens();
+ }
+ }
+
+ private static function purgeTokens() {
+ $oldest = time() - 2629744; //1 month //TODO: Use a configuration instead
+ foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $fileInfo) {
+ if ($fileInfo->getExtension() === 'txt' && $fileInfo->getMTime() < $oldest) {
+ @unlink($fileInfo->getPathname());
+ }
+ }
+ }
+
public function formLoginAction () {
+ if ($this->view->loginOk) {
+ Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
+ }
+
if (Minz_Request::isPost()) {
$ok = false;
$nonce = Minz_Session::param('nonce');
@@ -333,6 +357,11 @@ class FreshRSS_index_Controller extends Minz_ActionController {
if ($ok) {
Minz_Session::_param('currentUser', $username);
Minz_Session::_param('passwordHash', $s);
+ if (Minz_Request::param('keep_logged_in', false)) {
+ self::makeLongTermCookie($username, $s);
+ } else {
+ self::deleteLongTermCookie();
+ }
} else {
Minz_Log::record('Password mismatch for user ' . $username . ', nonce=' . $nonce . ', c=' . $c, Minz_Log::WARNING);
}
@@ -351,6 +380,32 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
$this->view->_useLayout(false);
Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
+ } elseif (Minz_Configuration::unsafeAutologinEnabled() && isset($_GET['u']) && isset($_GET['p'])) {
+ Minz_Session::_param('currentUser');
+ Minz_Session::_param('mail');
+ Minz_Session::_param('passwordHash');
+ $username = ctype_alnum($_GET['u']) ? $_GET['u'] : '';
+ $passwordPlain = $_GET['p'];
+ Minz_Request::_param('p'); //Discard plain-text password ASAP
+ $_GET['p'] = '';
+ if (!function_exists('password_verify')) {
+ include_once(LIB_PATH . '/password_compat.php');
+ }
+ try {
+ $conf = new FreshRSS_Configuration($username);
+ $s = $conf->passwordHash;
+ $ok = password_verify($passwordPlain, $s);
+ unset($passwordPlain);
+ if ($ok) {
+ Minz_Session::_param('currentUser', $username);
+ Minz_Session::_param('passwordHash', $s);
+ } else {
+ Minz_Log::record('Unsafe password mismatch for user ' . $username, Minz_Log::WARNING);
+ }
+ } catch (Minz_Exception $me) {
+ Minz_Log::record('Unsafe login failure: ' . $me->getMessage(), Minz_Log::WARNING);
+ }
+ Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
} elseif (!Minz_Configuration::canLogIn()) {
Minz_Error::error (
403,
@@ -366,6 +421,78 @@ class FreshRSS_index_Controller extends Minz_ActionController {
Minz_Session::_param('currentUser');
Minz_Session::_param('mail');
Minz_Session::_param('passwordHash');
+ self::deleteLongTermCookie();
Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
}
+
+ public function resetAuthAction() {
+ Minz_View::prependTitle(_t('auth_reset') . ' · ');
+ Minz_View::appendScript(Minz_Url::display(
+ '/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js')
+ ));
+
+ $this->view->no_form = false;
+ // Enable changement of auth only if Persona!
+ if (Minz_Configuration::authType() != 'persona') {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('auth_not_persona')
+ );
+ $this->view->no_form = true;
+ return;
+ }
+
+ $conf = new FreshRSS_Configuration(Minz_Configuration::defaultUser());
+ // Admin user must have set its master password.
+ if (!$conf->passwordHash) {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('auth_no_password_set')
+ );
+ $this->view->no_form = true;
+ return;
+ }
+
+ invalidateHttpCache();
+
+ if (Minz_Request::isPost()) {
+ $nonce = Minz_Session::param('nonce');
+ $username = Minz_Request::param('username', '');
+ $c = Minz_Request::param('challenge', '');
+ if (!(ctype_alnum($username) && ctype_graph($c) && ctype_alnum($nonce))) {
+ Minz_Log::debug('Invalid credential parameters:' .
+ ' user=' . $username .
+ ' challenge=' . $c .
+ ' nonce=' . $nonce);
+ Minz_Request::bad(_t('invalid_login'),
+ array('c' => 'index', 'a' => 'resetAuth'));
+ }
+
+ if (!function_exists('password_verify')) {
+ include_once(LIB_PATH . '/password_compat.php');
+ }
+
+ $s = $conf->passwordHash;
+ $ok = password_verify($nonce . $s, $c);
+ if ($ok) {
+ Minz_Configuration::_authType('form');
+ $ok = Minz_Configuration::writeFile();
+
+ if ($ok) {
+ Minz_Request::good(_t('auth_form_set'));
+ } else {
+ Minz_Request::bad(_t('auth_form_not_set'),
+ array('c' => 'index', 'a' => 'resetAuth'));
+ }
+ } else {
+ Minz_Log::debug('Password mismatch for user ' . $username .
+ ', nonce=' . $nonce . ', c=' . $c);
+
+ Minz_Request::bad(_t('invalid_login'),
+ array('c' => 'index', 'a' => 'resetAuth'));
+ }
+ }
+ }
}
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..256543f37
--- /dev/null
+++ b/app/Controllers/statsController.php
@@ -0,0 +1,129 @@
+<?php
+
+/**
+ * Controller to handle application statistics.
+ */
+class FreshRSS_stats_Controller extends Minz_ActionController {
+
+ /**
+ * This action handles the statistic main page.
+ *
+ * It displays the statistic main page.
+ * The values computed to display the page are:
+ * - repartition of read/unread/favorite/not favorite
+ * - number of article per day
+ * - number of feed by category
+ * - number of article by category
+ * - list of most prolific feed
+ */
+ 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();
+ }
+
+ /**
+ * This action handles the idle feed statistic page.
+ *
+ * It displays the list of idle feed for different period. The supported
+ * periods are:
+ * - last year
+ * - last 6 months
+ * - last 3 months
+ * - last month
+ * - last week
+ */
+ public function idleAction() {
+ $statsDAO = FreshRSS_Factory::createStatsDAO();
+ $feeds = $statsDAO->calculateFeedLastDate();
+ $idleFeeds = array(
+ 'last_year' => array(),
+ 'last_6_month' => array(),
+ 'last_3_month' => array(),
+ 'last_month' => array(),
+ 'last_week' => 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 < $lastYear) {
+ $idleFeeds['last_year'][] = $feed;
+ } elseif ($feedDate < $last6Month) {
+ $idleFeeds['last_6_month'][] = $feed;
+ } elseif ($feedDate < $last3Month) {
+ $idleFeeds['last_3_month'][] = $feed;
+ } elseif ($feedDate < $lastMonth) {
+ $idleFeeds['last_month'][] = $feed;
+ } elseif ($feedDate < $lastWeek) {
+ $idleFeeds['last_week'][] = $feed;
+ }
+ }
+
+ $this->view->idleFeeds = $idleFeeds;
+ }
+
+ /**
+ * This action handles the article repartition statistic page.
+ *
+ * It displays the number of article and the average of article for the
+ * following periods:
+ * - hour of the day
+ * - day of the week
+ * - month
+ *
+ * @todo verify that the metrics used here make some sense. Especially
+ * for the average.
+ */
+ public function repartitionAction() {
+ $statsDAO = FreshRSS_Factory::createStatsDAO();
+ $categoryDAO = new FreshRSS_CategoryDAO();
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));
+ $id = Minz_Request::param ('id', null);
+ $this->view->categories = $categoryDAO->listCategories();
+ $this->view->feed = $feedDAO->searchById($id);
+ $this->view->days = $statsDAO->getDays();
+ $this->view->months = $statsDAO->getMonths();
+ $this->view->repartitionHour = $statsDAO->calculateEntryRepartitionPerFeedPerHour($id);
+ $this->view->averageHour = $statsDAO->calculateEntryAveragePerFeedPerHour($id);
+ $this->view->repartitionDayOfWeek = $statsDAO->calculateEntryRepartitionPerFeedPerDayOfWeek($id);
+ $this->view->averageDayOfWeek = $statsDAO->calculateEntryAveragePerFeedPerDayOfWeek($id);
+ $this->view->repartitionMonth = $statsDAO->calculateEntryRepartitionPerFeedPerMonth($id);
+ $this->view->averageMonth = $statsDAO->calculateEntryAveragePerFeedPerMonth($id);
+ }
+
+ /**
+ * This action is called before every other action in that class. It is
+ * the common boiler plate for every action. It is triggered by the
+ * underlying framework.
+ */
+ 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/updateController.php b/app/Controllers/updateController.php
new file mode 100644
index 000000000..da5bddc65
--- /dev/null
+++ b/app/Controllers/updateController.php
@@ -0,0 +1,129 @@
+<?php
+
+class FreshRSS_update_Controller extends Minz_ActionController {
+ public function firstAction() {
+ $current_user = Minz_Session::param('currentUser', '');
+ if (!$this->view->loginOk && Minz_Configuration::isAdmin($current_user)) {
+ Minz_Error::error(
+ 403,
+ array('error' => array(_t('access_denied')))
+ );
+ }
+
+ invalidateHttpCache();
+
+ Minz_View::prependTitle(_t('update_system') . ' · ');
+ $this->view->update_to_apply = false;
+ $this->view->last_update_time = 'unknown';
+ $this->view->check_last_hour = false;
+ $timestamp = (int)@file_get_contents(DATA_PATH . '/last_update.txt');
+ if (is_numeric($timestamp) && $timestamp > 0) {
+ $this->view->last_update_time = timestamptodate($timestamp);
+ $this->view->check_last_hour = (time() - 3600) <= $timestamp;
+ }
+ }
+
+ public function indexAction() {
+ if (file_exists(UPDATE_FILENAME) && !is_writable(FRESHRSS_PATH)) {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('file_is_nok', FRESHRSS_PATH)
+ );
+ } elseif (file_exists(UPDATE_FILENAME)) {
+ // There is an update file to apply!
+ $this->view->update_to_apply = true;
+ $this->view->message = array(
+ 'status' => 'good',
+ 'title' => _t('ok'),
+ 'body' => _t('update_can_apply')
+ );
+ }
+ }
+
+ public function checkAction() {
+ $this->view->change_view('update', 'index');
+
+ if (file_exists(UPDATE_FILENAME) || $this->view->check_last_hour) {
+ // There is already an update file to apply: we don't need to check
+ // the webserver!
+ // Or if already check during the last hour, do nothing.
+ Minz_Request::forward(array('c' => 'update'));
+
+ return;
+ }
+
+ $c = curl_init(FRESHRSS_UPDATE_WEBSITE);
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
+ curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
+ $result = curl_exec($c);
+ $c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
+ $c_error = curl_error($c);
+ curl_close($c);
+
+ if ($c_status !== 200) {
+ Minz_Log::error(
+ 'Error during update (HTTP code ' . $c_status . '): ' . $c_error
+ );
+
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('update_server_not_found', FRESHRSS_UPDATE_WEBSITE)
+ );
+ return;
+ }
+
+ $res_array = explode("\n", $result, 2);
+ $status = $res_array[0];
+ if (strpos($status, 'UPDATE') !== 0) {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('no_update')
+ );
+
+ @file_put_contents(DATA_PATH . '/last_update.txt', time());
+
+ return;
+ }
+
+ $script = $res_array[1];
+ if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
+ Minz_Request::forward(array('c' => 'update'));
+ } else {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('update_problem', 'Cannot save the update script')
+ );
+ }
+ }
+
+ public function applyAction() {
+ if (!file_exists(UPDATE_FILENAME) || !is_writable(FRESHRSS_PATH)) {
+ Minz_Request::forward(array('c' => 'update'), true);
+ }
+
+ require(UPDATE_FILENAME);
+
+ if (Minz_Request::isPost()) {
+ save_info_update();
+ }
+
+ if (!need_info_update()) {
+ $res = apply_update();
+
+ if ($res === true) {
+ @unlink(UPDATE_FILENAME);
+ @file_put_contents(DATA_PATH . '/last_update.txt', time());
+
+ Minz_Request::good(_t('update_finished'));
+ } else {
+ Minz_Request::bad(_t('update_problem', $res),
+ array('c' => 'update', 'a' => 'index'));
+ }
+ }
+ }
+}
diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php
index bb4f34c5e..a9e6c32bc 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,8 +32,20 @@ class FreshRSS_users_Controller extends Minz_ActionController {
}
Minz_Session::_param('passwordHash', $this->view->conf->passwordHash);
+ $passwordPlain = Minz_Request::param('apiPasswordPlain', '', true);
+ if ($passwordPlain != '') {
+ if (!function_exists('password_hash')) {
+ include_once(LIB_PATH . '/password_compat.php');
+ }
+ $passwordHash = password_hash($passwordPlain, PASSWORD_BCRYPT, array('cost' => self::BCRYPT_COST));
+ $passwordPlain = '';
+ $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash); //Compatibility with bcrypt.js
+ $ok &= ($passwordHash != '');
+ $this->view->conf->_apiPasswordHash($passwordHash);
+ }
+
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);
@@ -57,13 +69,19 @@ class FreshRSS_users_Controller extends Minz_ActionController {
$anon_refresh = Minz_Request::param('anon_refresh', false);
$anon_refresh = ((bool)$anon_refresh) && ($anon_refresh !== 'no');
$auth_type = Minz_Request::param('auth_type', 'none');
+ $unsafe_autologin = Minz_Request::param('unsafe_autologin', false);
+ $api_enabled = Minz_Request::param('api_enabled', false);
if ($anon != Minz_Configuration::allowAnonymous() ||
$auth_type != Minz_Configuration::authType() ||
- $anon_refresh != Minz_Configuration::allowAnonymousRefresh()) {
+ $anon_refresh != Minz_Configuration::allowAnonymousRefresh() ||
+ $unsafe_autologin != Minz_Configuration::unsafeAutologinEnabled() ||
+ $api_enabled != Minz_Configuration::apiEnabled()) {
Minz_Configuration::_authType($auth_type);
Minz_Configuration::_allowAnonymous($anon);
Minz_Configuration::_allowAnonymousRefresh($anon_refresh);
+ Minz_Configuration::_enableAutologin($unsafe_autologin);
+ Minz_Configuration::_enableApi($api_enabled);
$ok &= Minz_Configuration::writeFile();
}
}
@@ -81,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/install.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())) {
@@ -101,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
@@ -152,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/install.sql.' . $db['type'] . '.php');
$username = Minz_Request::param('username');
$ok = ctype_alnum($username);