aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-09-29 20:47:17 +0200
committerGravatar GitHub <noreply@github.com> 2018-09-29 20:47:17 +0200
commit8ee8a573f1f7e9cc45f9b3c46627d15670f14f3a (patch)
tree14200758ab43e4031f60b46b8c6e9018b43e53af /app/Controllers
parent3ae1b57c9d2e23157be54e8fe9865b85872ff9e7 (diff)
Custom labels (#2027)
* First draft of custom tags https://github.com/FreshRSS/FreshRSS/issues/928 https://github.com/FreshRSS/FreshRSS/issues/1367 * SMALLINT to BIGINT for id_entry And uppercase SQL types * Fix layout for unreads * Start UI menu * Change menu order * Clean database helpers https://github.com/FreshRSS/FreshRSS/pull/2027#discussion_r217971535 * Travis rules do not understand PostgreSQL constants Grrr * Tag controller + UI * Add column attributes to tags * Use only favicon for now, for label * Fix styling for different themes * Constant for maximum InnoDB index length in Unicode https://github.com/FreshRSS/FreshRSS/pull/2027#discussion_r219052200 (I would have personnally prefered keeping the readability of a real value instead of a constant, in this case of many SQL fields) * Use FreshRSS_Factory::createCategoryDao * Add view of all articles containing any tag * Fix search in tags * Mark as read tags * Partial auto-update unread tags * More auto update tag unreads * Add tag deletion * Do not purge tagged articles * Minor comment * Fix SQLite and UI bug * Google Reader API support for user tags Add SQL check that tag names must be distinct from category names * whitespace * Add missing API for EasyRSS * Compatibility SQLite Problematic parentheses * Add SQL DISTINCT for cases with multiple tags * Fix for PostgreSQL PostgreSQL needs some additional type hint to avoid "could not determine data type of parameter $1" http://www.postgresql-archive.org/Could-not-determine-data-type-of-parameter-1-tp2171092p2171094.html
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/categoryController.php8
-rwxr-xr-xapp/Controllers/configureController.php10
-rwxr-xr-xapp/Controllers/entryController.php14
-rwxr-xr-xapp/Controllers/feedController.php6
-rwxr-xr-xapp/Controllers/indexController.php11
-rwxr-xr-xapp/Controllers/javascriptController.php4
-rw-r--r--app/Controllers/statsController.php2
-rw-r--r--app/Controllers/subscriptionController.php2
-rw-r--r--app/Controllers/tagController.php80
9 files changed, 121 insertions, 16 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..21d51af34 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) {
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 2f7495884..2c8cdaa5c 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 {
@@ -556,7 +556,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..8b905c881 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -32,8 +32,15 @@ class FreshRSS_index_Controller extends Minz_ActionController {
Minz_Error::error(404);
}
- $this->view->callbackBeforeContent = function($view) {
+ $this->view->callbackBeforeContent = function ($view) {
try {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $view->tags = $tagDAO->listTags(true);
+ $view->nbUnreadTags = 0;
+ foreach ($view->tags as $tag) {
+ $view->nbUnreadTags += $tag->nbUnread();
+ }
+
FreshRSS_Context::$number++; //+1 for pagination
$entries = FreshRSS_index_Controller::listEntriesByContext();
FreshRSS_Context::$number--;
@@ -158,7 +165,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..cdf14c7a0 100755
--- a/app/Controllers/javascriptController.php
+++ b/app/Controllers/javascriptController.php
@@ -13,8 +13,10 @@ class FreshRSS_javascript_Controller extends Minz_ActionController {
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..511cea11b 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();
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);
+ }
+}