1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
<?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' => '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('error_occured'), $url_redirect);
}
}
Minz_Request::forward($url_redirect, true);
}
/**
* This action deletes all the feeds relative to a given category
*
* Request parameter is:
* - id (of a category)
*/
public function emptyAction() {
$feedDAO = FreshRSS_Factory::createFeedDao();
$url_redirect = array('c' => 'configure', 'a' => 'categorize');
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_occured'), $url_redirect);
}
}
Minz_Request::forward($url_redirect, true);
}
}
|