forked from fossar/selfoss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItems.php
More file actions
154 lines (122 loc) · 3.53 KB
/
Items.php
File metadata and controls
154 lines (122 loc) · 3.53 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?PHP
namespace controllers;
/**
* Controller for item handling
*
* @package controllers
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <tobias.zeising@aditu.de>
*/
class Items extends BaseController {
/**
* mark items as read. Allows one id or an array of ids
* json
*
* @return void
*/
public function mark() {
if(\F3::get('PARAMS["item"]')!=null)
$lastid = \F3::get('PARAMS["item"]');
else if(isset($_POST['ids'])) {
$lastid = $_POST['ids'];
}
$itemDao = new \daos\Items();
// validate id or ids
if (!$itemDao->isValid('id', $lastid))
$this->view->error('invalid id');
$itemDao->mark($lastid);
$return = array(
'success' => true
);
// only for selfoss ui on mark all as read (update stats in navigation)
if(isset($_POST['ajax'])) {
// get new tag list with updated count values
$tagController = new \controllers\Tags();
$return['tags'] = $tagController->tagsListAsString();
// get new sources list
$sourcesController = new \controllers\Sources();
$return['sources'] = $sourcesController->sourcesListAsString();
}
$this->view->jsonSuccess($return);
}
/**
* mark item as unread
* json
*
* @return void
*/
public function unmark() {
$lastid = \F3::get('PARAMS["item"]');
$itemDao = new \daos\Items();
if (!$itemDao->isValid('id', $lastid))
$this->view->error('invalid id');
$itemDao->unmark($lastid);
$this->view->jsonSuccess(array(
'success' => true
));
}
/**
* starr item
* json
*
* @return void
*/
public function starr() {
$id = \F3::get('PARAMS["item"]');
$itemDao = new \daos\Items();
if (!$itemDao->isValid('id', $id))
$this->view->error('invalid id');
$itemDao->starr($id);
$this->view->jsonSuccess(array(
'success' => true
));
}
/**
* unstarr item
* json
*
* @return void
*/
public function unstarr() {
$id = \F3::get('PARAMS["item"]');
$itemDao = new \daos\Items();
if (!$itemDao->isValid('id', $id))
$this->view->error('invalid id');
$itemDao->unstarr($id);
$this->view->jsonSuccess(array(
'success' => true
));
}
/**
* returns items as json string
* json
*
* @return void
*/
public function listItems() {
// parse params
$options = array();
if(count($_GET)>0)
$options = $_GET;
// get items
$itemDao = new \daos\Items();
$items = $itemDao->get($options);
$this->view->jsonSuccess($items);
}
/**
* returns current basic stats
* json
*
* @return void
*/
public function stats() {
$itemsDao = new \daos\Items();
$return = array(
'all' => $itemsDao->numberOfItems(),
'unread' => $itemsDao->numberOfUnread(),
'starred' => $itemsDao->numberOfStarred()
);
$this->view->jsonSuccess($return);
}
}