aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-02 09:36:32 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-02 09:36:32 +0200
commitf1a5a174ea8731cbfbe8d9d692976765030b5f80 (patch)
tree38af1844daeab2b430bddd02a4b07d9879d27142 /app/Controllers
parent7be9613fa6bf4718e700d01f58f599c8d50e1501 (diff)
parentbbedca510bb0b88850476bf2e2aa6af8c02ac741 (diff)
Merge branch '646-new-cat-system' into dev
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/categoryController.php187
-rwxr-xr-xapp/Controllers/configureController.php162
-rwxr-xr-xapp/Controllers/feedController.php80
-rw-r--r--app/Controllers/subscriptionController.php119
4 files changed, 334 insertions, 214 deletions
diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php
new file mode 100644
index 000000000..c79f37fa4
--- /dev/null
+++ b/app/Controllers/categoryController.php
@@ -0,0 +1,187 @@
+<?php
+
+/**
+ * Controller to handle actions relative to categories.
+ * User needs to be connected.
+ */
+class FreshRSS_category_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 (!$this->view->loginOk) {
+ Minz_Error::error(
+ 403,
+ array('error' => array(_t('access_denied')))
+ );
+ }
+
+ $catDAO = new FreshRSS_CategoryDAO();
+ $catDAO->checkDefault();
+ }
+
+ /**
+ * This action creates a new category.
+ *
+ * Request parameter is:
+ * - new-category
+ */
+ public function createAction() {
+ $catDAO = new FreshRSS_CategoryDAO();
+ $url_redirect = array('c' => 'subscription', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ invalidateHttpCache();
+
+ $cat_name = Minz_Request::param('new-category');
+ if (!$cat_name) {
+ Minz_Request::bad(_t('category_no_name'), $url_redirect);
+ }
+
+ $cat = new FreshRSS_Category($cat_name);
+
+ if ($catDAO->searchByName($cat->name()) != null) {
+ Minz_Request::bad(_t('category_name_exists'), $url_redirect);
+ }
+
+ $values = array(
+ 'id' => $cat->id(),
+ 'name' => $cat->name(),
+ );
+
+ if ($catDAO->addCategory($values)) {
+ Minz_Request::good(_t('category_created', $cat->name()), $url_redirect);
+ } else {
+ Minz_Request::bad(_t('error_occurred'), $url_redirect);
+ }
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+
+ /**
+ * This action updates the given category.
+ *
+ * Request parameters are:
+ * - id
+ * - name
+ */
+ public function updateAction() {
+ $catDAO = new FreshRSS_CategoryDAO();
+ $url_redirect = array('c' => 'subscription', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ invalidateHttpCache();
+
+ $id = Minz_Request::param('id');
+ $name = Minz_Request::param('name', '');
+ if (strlen($name) <= 0) {
+ Minz_Request::bad(_t('category_no_name'), $url_redirect);
+ }
+
+ if ($catDAO->searchById($id) == null) {
+ Minz_Request::bad(_t('category_not_exist'), $url_redirect);
+ }
+
+ $cat = new FreshRSS_Category($name);
+ $values = array(
+ 'name' => $cat->name(),
+ );
+
+ if ($catDAO->updateCategory($id, $values)) {
+ Minz_Request::good(_t('category_updated'), $url_redirect);
+ } else {
+ Minz_Request::bad(_t('error_occurred'), $url_redirect);
+ }
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+
+ /**
+ * This action deletes a category.
+ * Feeds in the given category are moved in the default category.
+ * Related user queries are deleted too.
+ *
+ * Request parameter is:
+ * - id (of a category)
+ */
+ public function deleteAction() {
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $catDAO = new FreshRSS_CategoryDAO();
+ $default_category = $catDAO->getDefault();
+ $url_redirect = array('c' => 'subscription', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ invalidateHttpCache();
+
+ $id = Minz_Request::param('id');
+ if (!$id) {
+ Minz_Request::bad(_t('category_no_id'), $url_redirect);
+ }
+
+ if ($id === $default_category->id()) {
+ Minz_Request::bad(_t('category_not_delete_default'), $url_redirect);
+ }
+
+ if ($feedDAO->changeCategory($id, $default_category->id()) === false) {
+ Minz_Request::bad(_t('error_occurred'), $url_redirect);
+ }
+
+ if ($catDAO->deleteCategory($id) === false) {
+ Minz_Request::bad(_t('error_occurred'), $url_redirect);
+ }
+
+ // Remove related queries.
+ $this->view->conf->remove_query_by_get('c_' . $id);
+ $this->view->conf->save();
+
+ Minz_Request::good(_t('category_deleted'), $url_redirect);
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+
+ /**
+ * This action deletes all the feeds relative to a given category.
+ * Feed-related queries are deleted.
+ *
+ * Request parameter is:
+ * - id (of a category)
+ */
+ public function emptyAction() {
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $url_redirect = array('c' => 'subscription', 'a' => 'index');
+
+ if (Minz_Request::isPost()) {
+ invalidateHttpCache();
+
+ $id = Minz_Request::param('id');
+ if (!$id) {
+ Minz_Request::bad(_t('category_no_id'), $url_redirect);
+ }
+
+ // List feeds to remove then related user queries.
+ $feeds = $feedDAO->listByCategory($id);
+
+ if ($feedDAO->deleteFeedByCategory($id)) {
+ // TODO: Delete old favicons
+
+ // Remove related queries
+ foreach ($feeds as $feed) {
+ $this->view->conf->remove_query_by_get('f_' . $feed->id());
+ }
+ $this->view->conf->save();
+
+ Minz_Request::good(_t('category_emptied'), $url_redirect);
+ } else {
+ Minz_Request::bad(_t('error_occurred'), $url_redirect);
+ }
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+}
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 231865bd7..b7b88b3ba 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -8,9 +8,6 @@ class FreshRSS_configure_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.
- *
- * @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) {
@@ -19,165 +16,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
array('error' => array(_t('access_denied')))
);
}
-
- $catDAO = new FreshRSS_CategoryDAO();
- $catDAO->checkDefault();
- }
-
- /**
- * 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', ''));
-
- foreach ($cats as $key => $name) {
- if (strlen($name) > 0) {
- $cat = new FreshRSS_Category($name);
- $values = array(
- 'name' => $cat->name(),
- );
- $catDAO->updateCategory($ids[$key], $values);
- } elseif ($ids[$key] != $defaultId) {
- $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(),
- );
-
- if ($catDAO->searchByName($newCat) == null) {
- $catDAO->addCategory($values);
- }
- }
- invalidateHttpCache();
-
- 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();
-
- Minz_View::prependTitle(_t('categories_management') . ' · ');
- }
-
- /**
- * 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;
- if ($id != false) {
- $this->view->flux = $this->view->feeds[$id];
-
- if (!$this->view->flux) {
- Minz_Error::error(
- 404,
- 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', '');
-
- $httpAuth = '';
- if ($user != '' || $pass != '') {
- $httpAuth = $user . ':' . $pass;
- }
-
- $cat = intval(Minz_Request::param('category', 0));
-
- $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)),
- 'httpAuth' => $httpAuth,
- '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);
- $this->view->flux->faviconPrepare();
- $notif = array(
- 'type' => 'good',
- 'content' => _t('feed_updated')
- );
- } else {
- $notif = array(
- 'type' => 'bad',
- '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_View::prependTitle(_t('rss_feed_management') . ' — ' . $this->view->flux->name() . ' · ');
- }
- } else {
- Minz_View::prependTitle(_t('rss_feed_management') . ' · ');
- }
}
/**
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index c7cc25fbb..e4859b110 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -26,8 +26,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
if ($url === false) {
Minz_Request::forward(array(
- 'c' => 'configure',
- 'a' => 'feed'
+ 'c' => 'subscription',
+ 'a' => 'index'
), true);
}
@@ -166,7 +166,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feedDAO->rollBack ();
}
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => $params), true);
+ Minz_Request::forward (array ('c' => 'subscription', 'a' => 'index', 'params' => $params), true);
} else {
// GET request so we must ask confirmation to user
@@ -193,8 +193,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
Minz_Session::_param('notification', $notif);
Minz_Request::forward(array(
- 'c' => 'configure',
- 'a' => 'feed',
+ 'c' => 'subscription',
+ 'a' => 'index',
'params' => array(
'id' => $feed->id()
)
@@ -214,7 +214,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
);
Minz_Session::_param ('notification', $notif);
invalidateHttpCache();
- Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array('id' => $id)), true);
+ Minz_Request::forward (array ('c' => 'subscription',
+ 'a' => 'index',
+ 'params' => array('id' => $id)), true);
}
}
@@ -376,62 +378,36 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
}
- public function deleteAction () {
- if (Minz_Request::isPost ()) {
- $type = Minz_Request::param ('type', 'feed');
- $id = Minz_Request::param ('id');
-
+ public function deleteAction() {
+ if (Minz_Request::isPost()) {
+ $id = Minz_Request::param('id');
$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')
- );
- //TODO: Delete old favicons
- } else {
- $notif = array (
- 'type' => 'bad',
- 'content' => Minz_Translate::t ('error_occured')
- );
- }
- } else {
- if ($feedDAO->deleteFeed ($id)) {
- // Remove related queries
- $this->view->conf->remove_query_by_get('f_' . $id);
- $this->view->conf->save();
+ if ($feedDAO->deleteFeed($id)) {
+ // TODO: Delete old favicon
- $notif = array (
- 'type' => 'good',
- 'content' => Minz_Translate::t ('feed_deleted')
- );
- //TODO: Delete old favicon
- } else {
- $notif = array (
- 'type' => 'bad',
- 'content' => Minz_Translate::t ('error_occured')
- );
- }
+ // Remove related queries
+ $this->view->conf->remove_query_by_get('f_' . $id);
+ $this->view->conf->save();
+
+ $notif = array(
+ 'type' => 'good',
+ 'content' => _t('feed_deleted')
+ );
+ } else {
+ $notif = array(
+ 'type' => 'bad',
+ 'content' => _t('error_occured')
+ );
}
- Minz_Session::_param ('notification', $notif);
+ Minz_Session::_param('notification', $notif);
$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);
+ Minz_Request::forward(array('c' => 'subscription', 'a' => 'index'), true);
}
}
}
diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php
new file mode 100644
index 000000000..aabae7b8f
--- /dev/null
+++ b/app/Controllers/subscriptionController.php
@@ -0,0 +1,119 @@
+<?php
+
+/**
+ * Controller to handle subscription actions.
+ */
+class FreshRSS_subscription_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 (!$this->view->loginOk) {
+ Minz_Error::error(
+ 403,
+ array('error' => array(_t('access_denied')))
+ );
+ }
+
+ $catDAO = new FreshRSS_CategoryDAO();
+
+ $catDAO->checkDefault();
+ $this->view->categories = $catDAO->listCategories(false);
+ $this->view->default_category = $catDAO->getDefault();
+ }
+
+ /**
+ * This action handles the main subscription page
+ *
+ * It displays categories and associated feeds.
+ */
+ public function indexAction() {
+ Minz_View::prependTitle(_t('subscription_management') . ' · ');
+
+ $id = Minz_Request::param('id');
+ if ($id !== false) {
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $this->view->feed = $feedDAO->searchById($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() {
+ if (Minz_Request::param('ajax')) {
+ $this->view->_useLayout(false);
+ }
+
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ $this->view->feeds = $feedDAO->listFeeds();
+
+ $id = Minz_Request::param('id');
+ if ($id === false || !isset($this->view->feeds[$id])) {
+ Minz_Error::error(
+ 404,
+ array('error' => array(_t('page_not_found')))
+ );
+ return;
+ }
+
+ $this->view->feed = $this->view->feeds[$id];
+
+ Minz_View::prependTitle(_t('rss_feed_management') . ' · ' . $this->view->feed->name() . ' · ');
+
+ if (Minz_Request::isPost()) {
+ $user = Minz_Request::param('http_user', '');
+ $pass = Minz_Request::param('http_pass', '');
+
+ $httpAuth = '';
+ if ($user != '' || $pass != '') {
+ $httpAuth = $user . ':' . $pass;
+ }
+
+ $cat = intval(Minz_Request::param('category', 0));
+
+ $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)),
+ 'httpAuth' => $httpAuth,
+ 'keep_history' => intval(Minz_Request::param('keep_history', -2)),
+ 'ttl' => intval(Minz_Request::param('ttl', -2)),
+ );
+
+ invalidateHttpCache();
+
+ if ($feedDAO->updateFeed($id, $values)) {
+ $this->view->feed->_category($cat);
+ $this->view->feed->faviconPrepare();
+
+ Minz_Request::good(_t('feed_updated'), array('c' => 'subscription', 'params' => array('id' => $id)));
+ } else {
+ Minz_Request::bad(_t('error_occurred_update'), array('c' => 'subscription'));
+ }
+ }
+ }
+}