aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-09-30 15:02:56 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-09-30 15:02:56 +0200
commitedb02c8fefdb292c96d7b37ad4e2c311e9d43b44 (patch)
tree2b9d28dc68a87a0603c93e24f927e00ea20169ea
parent46ae0a3f5ada751c9442eca275e15450fad85509 (diff)
Move creation of categories in a new Controller
Category names are 255 chars max
-rw-r--r--app/Controllers/categoryController.php64
-rwxr-xr-xapp/Controllers/configureController.php12
-rw-r--r--app/Models/Category.php2
-rw-r--r--app/views/configure/categorize.phtml2
4 files changed, 66 insertions, 14 deletions
diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php
new file mode 100644
index 000000000..e2d98a509
--- /dev/null
+++ b/app/Controllers/categoryController.php
@@ -0,0 +1,64 @@
+<?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.
+ *
+ * URL parameter is:
+ * - new-category
+ */
+ public function createAction() {
+ $catDAO = new FreshRSS_CategoryDAO();
+ $url_redirect = array('c' => 'configure', 'a' => 'categorize');
+
+ 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('category_not_created'), $url_redirect);
+ }
+ }
+
+ Minz_Request::forward($url_redirect, true);
+ }
+}
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 231865bd7..7ef144090 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -45,7 +45,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
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) {
@@ -64,17 +63,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
}
}
- 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'),
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 0a0dbd3ca..e5f6c4334 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -61,7 +61,7 @@ class FreshRSS_Category extends Minz_Model {
$this->id = $value;
}
public function _name ($value) {
- $this->name = $value;
+ $this->name = substr(trim($value), 0, 255);
}
public function _feeds ($values) {
if (!is_array ($values)) {
diff --git a/app/views/configure/categorize.phtml b/app/views/configure/categorize.phtml
index 7091ff1cf..e7435e1c7 100644
--- a/app/views/configure/categorize.phtml
+++ b/app/views/configure/categorize.phtml
@@ -7,7 +7,7 @@
<div class="box-title"><label for="new-category"><?php echo _t('add_category'); ?></label></div>
<div class="box-content">
- <form action="" methos="post">
+ <form action="<?php echo _url('category', 'create'); ?>" method="post">
<input type="text" id="new-category" name="new-category" placeholder="<?php echo _t('new_category'); ?>" />
<input type="submit" value="<?php echo _t('submit'); ?>" />
</form>