aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/categoryController.php8
-rwxr-xr-xapp/Controllers/configureController.php10
-rwxr-xr-xapp/Controllers/entryController.php17
-rwxr-xr-xapp/Controllers/feedController.php12
-rwxr-xr-xapp/Controllers/indexController.php35
-rwxr-xr-xapp/Controllers/javascriptController.php5
-rw-r--r--app/Controllers/statsController.php2
-rw-r--r--app/Controllers/subscriptionController.php3
-rw-r--r--app/Controllers/tagController.php80
-rw-r--r--app/Controllers/updateController.php8
-rw-r--r--app/Controllers/userController.php23
11 files changed, 171 insertions, 32 deletions
diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php
index f3b35a323..2551a79d4 100644
--- a/app/Controllers/categoryController.php
+++ b/app/Controllers/categoryController.php
@@ -16,7 +16,7 @@ class FreshRSS_category_Controller extends Minz_ActionController {
Minz_Error::error(403);
}
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$catDAO->checkDefault();
}
@@ -27,7 +27,7 @@ class FreshRSS_category_Controller extends Minz_ActionController {
* - new-category
*/
public function createAction() {
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$url_redirect = array('c' => 'subscription', 'a' => 'index');
$limits = FreshRSS_Context::$system_conf->limits;
@@ -75,7 +75,7 @@ class FreshRSS_category_Controller extends Minz_ActionController {
* - name
*/
public function updateAction() {
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$url_redirect = array('c' => 'subscription', 'a' => 'index');
if (Minz_Request::isPost()) {
@@ -116,7 +116,7 @@ class FreshRSS_category_Controller extends Minz_ActionController {
*/
public function deleteAction() {
$feedDAO = FreshRSS_Factory::createFeedDao();
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$url_redirect = array('c' => 'subscription', 'a' => 'index');
if (Minz_Request::isPost()) {
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index d34b5d59d..20bcd2e76 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -243,8 +243,9 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* checking if categories and feeds are still in use.
*/
public function queriesAction() {
- $category_dao = new FreshRSS_CategoryDAO();
+ $category_dao = FreshRSS_Factory::createCategoryDao();
$feed_dao = FreshRSS_Factory::createFeedDao();
+ $tag_dao = FreshRSS_Factory::createTagDao();
if (Minz_Request::isPost()) {
$params = Minz_Request::param('queries', array());
@@ -277,16 +278,17 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* lean data.
*/
public function addQueryAction() {
- $category_dao = new FreshRSS_CategoryDAO();
+ $category_dao = FreshRSS_Factory::createCategoryDao();
$feed_dao = FreshRSS_Factory::createFeedDao();
+ $tag_dao = FreshRSS_Factory::createTagDao();
$queries = array();
foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
- $queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
+ $queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao);
}
$params = Minz_Request::fetchGET();
$params['url'] = Minz_Url::display(array('params' => $params));
$params['name'] = _t('conf.query.number', count($queries) + 1);
- $queries[] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao);
+ $queries[] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao, $tag_dao);
FreshRSS_Context::$user_conf->queries = $queries;
FreshRSS_Context::$user_conf->save();
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index 16a15c447..fc0af0639 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -53,6 +53,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
}
$params = array();
+ $this->view->tags = array();
$entryDAO = FreshRSS_Factory::createEntryDao();
if ($id === false) {
@@ -81,6 +82,12 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
case 'a':
$entryDAO->markReadEntries($id_max, false, 0, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read);
break;
+ case 't':
+ $entryDAO->markReadTag($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read);
+ break;
+ case 'T':
+ $entryDAO->markReadTag('', $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read);
+ break;
}
if ($next_get !== 'a') {
@@ -91,6 +98,13 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
}
} else {
$entryDAO->markRead($id, $is_read);
+
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ foreach ($tagDAO->getTagsForEntry($id) as $tag) {
+ if (!empty($tag['checked'])) {
+ $this->view->tags[] = $tag['id'];
+ }
+ }
}
if (!$this->ajax) {
@@ -193,6 +207,9 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$feedDAO->updateCachedValues();
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+ $databaseDAO->minorDbMaintenance();
+
invalidateHttpCache();
Minz_Request::good(_t('feedback.sub.purge_completed', $nb_total), array(
'c' => 'configure',
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 2f7495884..f2b1b8960 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -43,7 +43,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
FreshRSS_UserDAO::touch();
@set_time_limit(300);
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$url = trim($url);
@@ -192,7 +192,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
// GET request: we must ask confirmation to user before adding feed.
Minz_View::prependTitle(_t('sub.feed.title_add') . ' · ');
- $this->catDAO = new FreshRSS_CategoryDAO();
+ $this->catDAO = FreshRSS_Factory::createCategoryDao();
$this->view->categories = $this->catDAO->listCategories(false);
$this->view->feed = new FreshRSS_Feed($url);
try {
@@ -481,6 +481,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
if ($entryDAO->inTransaction()) {
$entryDAO->commit();
}
+
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+ $databaseDAO->minorDbMaintenance();
}
return array($updated_feeds, reset($feeds), $nb_new_articles);
}
@@ -511,6 +514,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$entryDAO->commitNewEntries();
$feedDAO->updateCachedValues();
$entryDAO->commit();
+
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+ $databaseDAO->minorDbMaintenance();
} else {
list($updated_feeds, $feed, $nb_new_articles) = self::actualizeFeed($id, $url, $force, null, false, $noCommit);
}
@@ -556,7 +562,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
FreshRSS_UserDAO::touch();
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
if ($cat_id > 0) {
$cat = $catDAO->searchById($cat_id);
$cat_id = $cat == null ? 0 : $cat->id();
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index ddffdba73..fa914ef87 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -32,7 +32,29 @@ class FreshRSS_index_Controller extends Minz_ActionController {
Minz_Error::error(404);
}
- $this->view->callbackBeforeContent = function($view) {
+ $this->view->categories = FreshRSS_Context::$categories;
+
+ $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();
+ $title = FreshRSS_Context::$name;
+ if (FreshRSS_Context::$get_unread > 0) {
+ $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title;
+ }
+ Minz_View::prependTitle($title . ' · ');
+
+ $this->view->callbackBeforeFeeds = function ($view) {
+ try {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $view->tags = $tagDAO->listTags(true);
+ $view->nbUnreadTags = 0;
+ foreach ($view->tags as $tag) {
+ $view->nbUnreadTags += $tag->nbUnread();
+ }
+ } catch (Exception $e) {
+ Minz_Log::notice($e->getMessage());
+ }
+ };
+
+ $this->view->callbackBeforeEntries = function ($view) {
try {
FreshRSS_Context::$number++; //+1 for pagination
$entries = FreshRSS_index_Controller::listEntriesByContext();
@@ -60,15 +82,6 @@ class FreshRSS_index_Controller extends Minz_ActionController {
Minz_Log::notice($e->getMessage());
Minz_Error::error(404);
}
-
- $view->categories = FreshRSS_Context::$categories;
-
- $view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();
- $title = FreshRSS_Context::$name;
- if (FreshRSS_Context::$get_unread > 0) {
- $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title;
- }
- Minz_View::prependTitle($title . ' · ');
};
}
@@ -158,7 +171,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
*/
private function updateContext() {
if (empty(FreshRSS_Context::$categories)) {
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
FreshRSS_Context::$categories = $catDAO->listCategories();
}
diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php
index 9d7acf647..d56da9cbb 100755
--- a/app/Controllers/javascriptController.php
+++ b/app/Controllers/javascriptController.php
@@ -7,14 +7,17 @@ class FreshRSS_javascript_Controller extends Minz_ActionController {
public function actualizeAction() {
header('Content-Type: application/json; charset=UTF-8');
+ Minz_Session::_param('actualize_feeds', false);
$feedDAO = FreshRSS_Factory::createFeedDao();
$this->view->feeds = $feedDAO->listFeedsOrderUpdate(FreshRSS_Context::$user_conf->ttl_default);
}
public function nbUnreadsPerFeedAction() {
header('Content-Type: application/json; charset=UTF-8');
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$this->view->categories = $catDAO->listCategories(true, false);
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $this->view->tags = $tagDAO->listTags(true);
}
//For Web-form login
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php
index 5d1dee72c..acfacb890 100644
--- a/app/Controllers/statsController.php
+++ b/app/Controllers/statsController.php
@@ -131,7 +131,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController {
*/
public function repartitionAction() {
$statsDAO = FreshRSS_Factory::createStatsDAO();
- $categoryDAO = new FreshRSS_CategoryDAO();
+ $categoryDAO = FreshRSS_Factory::createCategoryDao();
$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);
diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php
index 701a588e0..0b1439ba5 100644
--- a/app/Controllers/subscriptionController.php
+++ b/app/Controllers/subscriptionController.php
@@ -14,7 +14,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
Minz_Error::error(403);
}
- $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO = FreshRSS_Factory::createCategoryDao();
$feedDAO = FreshRSS_Factory::createFeedDao();
$catDAO->checkDefault();
@@ -98,6 +98,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
$feed->_attributes('mark_updated_article_unread', Minz_Request::paramTernary('mark_updated_article_unread'));
$feed->_attributes('read_upon_reception', Minz_Request::paramTernary('read_upon_reception'));
+ $feed->_attributes('clear_cache', Minz_Request::paramTernary('clear_cache'));
if (FreshRSS_Auth::hasAccess('admin')) {
$feed->_attributes('ssl_verify', Minz_Request::paramTernary('ssl_verify'));
diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php
new file mode 100644
index 000000000..106e0afa8
--- /dev/null
+++ b/app/Controllers/tagController.php
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * Controller to handle every tag actions.
+ */
+class FreshRSS_tag_Controller extends Minz_ActionController {
+ /**
+ * 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 (!FreshRSS_Auth::hasAccess()) {
+ Minz_Error::error(403);
+ }
+ // If ajax request, we do not print layout
+ $this->ajax = Minz_Request::param('ajax');
+ if ($this->ajax) {
+ $this->view->_useLayout(false);
+ Minz_Request::_param('ajax');
+ }
+ }
+
+ /**
+ * This action adds (checked=true) or removes (checked=false) a tag to an entry.
+ */
+ public function tagEntryAction() {
+ if (Minz_Request::isPost()) {
+ $id_tag = Minz_Request::param('id_tag');
+ $name_tag = trim(Minz_Request::param('name_tag'));
+ $id_entry = Minz_Request::param('id_entry');
+ $checked = Minz_Request::paramTernary('checked');
+ if ($id_entry != false) {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ if ($id_tag == 0 && $name_tag != '' && $checked) {
+ //Create new tag
+ $id_tag = $tagDAO->addTag(array('name' => $name_tag));
+ }
+ if ($id_tag != 0) {
+ $tagDAO->tagEntry($id_tag, $id_entry, $checked);
+ }
+ }
+ } else {
+ Minz_Error::error(405);
+ }
+ if (!$this->ajax) {
+ Minz_Request::forward(array(
+ 'c' => 'index',
+ 'a' => 'index',
+ ), true);
+ }
+ }
+
+ public function deleteAction() {
+ if (Minz_Request::isPost()) {
+ $id_tag = Minz_Request::param('id_tag');
+ if ($id_tag != false) {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $tagDAO->deleteTag($id_tag);
+ }
+ } else {
+ Minz_Error::error(405);
+ }
+ if (!$this->ajax) {
+ Minz_Request::forward(array(
+ 'c' => 'index',
+ 'a' => 'index',
+ ), true);
+ }
+ }
+
+ public function getTagsForEntryAction() {
+ $this->view->_useLayout(false);
+ header('Content-Type: application/json; charset=UTF-8');
+ header('Cache-Control: private, no-cache, no-store, must-revalidate');
+ $id_entry = Minz_Request::param('id_entry', 0);
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $this->view->tags = $tagDAO->getTagsForEntry($id_entry);
+ }
+}
diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php
index c67b358bb..2be644c85 100644
--- a/app/Controllers/updateController.php
+++ b/app/Controllers/updateController.php
@@ -32,7 +32,13 @@ class FreshRSS_update_Controller extends Minz_ActionController {
$output = array();
$return = 1;
try {
- exec('git pull --ff-only', $output, $return);
+ exec('git clean -f -d -f', $output, $return);
+ if ($return == 0) {
+ exec('git pull --ff-only', $output, $return);
+ } else {
+ $line = is_array($output) ? implode('; ', $output) : '' . $output;
+ Minz_Log::warning('git clean warning:' . $line);
+ }
} catch (Exception $e) {
Minz_Log::warning('git pull error:' . $e->getMessage());
}
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 75a4303d6..2338c8b2a 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -38,7 +38,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
* The username is also used as folder name, file name, and part of SQL table name.
* '_' is a reserved internal username.
*/
- const USERNAME_PATTERN = '[0-9a-zA-Z_]{2,38}|[0-9a-zA-Z]';
+ const USERNAME_PATTERN = '[0-9a-zA-Z_][0-9a-zA-Z_.]{1,38}|[0-9a-zA-Z]';
public static function checkUsername($username) {
return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1;
@@ -91,6 +91,10 @@ class FreshRSS_user_Controller extends Minz_ActionController {
}
public function updateAction() {
+ if (!FreshRSS_Auth::hasAccess('admin')) {
+ Minz_Error::error(403);
+ }
+
if (Minz_Request::isPost()) {
$passwordPlain = Minz_Request::param('newPasswordPlain', '', true);
Minz_Request::_param('newPasswordPlain'); //Discard plain-text password ASAP
@@ -104,8 +108,12 @@ class FreshRSS_user_Controller extends Minz_ActionController {
));
if ($ok) {
- Minz_Request::good(_t('feedback.user.updated', $username),
- array('c' => 'user', 'a' => 'manage'));
+ $isSelfUpdate = Minz_Session::param('currentUser', '_') === $username;
+ if ($passwordPlain == '' || !$isSelfUpdate) {
+ Minz_Request::good(_t('feedback.user.updated', $username), array('c' => 'user', 'a' => 'manage'));
+ } else {
+ Minz_Request::good(_t('feedback.profile.updated'), array('c' => 'index', 'a' => 'index'));
+ }
} else {
Minz_Request::bad(_t('feedback.user.updated.error', $username),
array('c' => 'user', 'a' => 'manage'));
@@ -138,8 +146,11 @@ class FreshRSS_user_Controller extends Minz_ActionController {
Minz_Session::_param('passwordHash', FreshRSS_Context::$user_conf->passwordHash);
if ($ok) {
- Minz_Request::good(_t('feedback.profile.updated'),
- array('c' => 'user', 'a' => 'profile'));
+ if ($passwordPlain == '') {
+ Minz_Request::good(_t('feedback.profile.updated'), array('c' => 'user', 'a' => 'profile'));
+ } else {
+ Minz_Request::good(_t('feedback.profile.updated'), array('c' => 'index', 'a' => 'index'));
+ }
} else {
Minz_Request::bad(_t('feedback.profile.error'),
array('c' => 'user', 'a' => 'profile'));
@@ -166,7 +177,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
$entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user);
$this->view->nb_articles = $entryDAO->count();
- $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO($this->view->current_user);
$this->view->size_user = $databaseDAO->size();
}
}