]>
Commit | Line | Data |
---|---|---|
afcfe6ca | 1 | <?php |
369dbc19 | 2 | class Pref_Feeds extends Handler_Protected { |
df659891 AD |
3 | public static $feed_languages = array("English", "Danish", "Dutch", "Finnish", "French", "German", "Hungarian", "Italian", "Norwegian", |
4 | "Portuguese", "Russian", "Spanish", "Swedish", "Turkish", "Simple"); | |
8484ce22 AD |
5 | |
6 | function csrf_ignore($method) { | |
f6cd767b | 7 | $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
201bb1ca AD |
8 | "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
9 | "batchsubscribe"); | |
8484ce22 AD |
10 | |
11 | return array_search($method, $csrf_ignored) !== false; | |
12 | } | |
13 | ||
afcfe6ca AD |
14 | function batch_edit_cbox($elem, $label = false) { |
15 | print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" | |
16 | onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">"; | |
17 | } | |
18 | ||
19 | function renamecat() { | |
e6532439 AD |
20 | $title = clean($_REQUEST['title']); |
21 | $id = clean($_REQUEST['id']); | |
afcfe6ca AD |
22 | |
23 | if ($title) { | |
bf4a79ea AD |
24 | $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET |
25 | title = ? WHERE id = ? AND owner_uid = ?"); | |
26 | $sth->execute([$title, $id, $_SESSION['uid']]); | |
afcfe6ca | 27 | } |
afcfe6ca AD |
28 | } |
29 | ||
2a060a94 | 30 | private function get_category_items($cat_id) { |
6e0ee833 | 31 | |
e6532439 | 32 | if (clean($_REQUEST['mode']) != 2) |
6e0ee833 AD |
33 | $search = $_SESSION["prefs_feed_search"]; |
34 | else | |
35 | $search = ""; | |
17c755f0 | 36 | |
66ca7c30 | 37 | // first one is set by API |
e6532439 AD |
38 | $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
39 | (clean($_REQUEST['mode']) != 2 && !$search); | |
2a060a94 AD |
40 | |
41 | $items = array(); | |
42 | ||
bf4a79ea AD |
43 | $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
44 | WHERE owner_uid = ? AND parent_cat = ? ORDER BY order_id, title"); | |
45 | $sth->execute([$_SESSION['uid'], $cat_id]); | |
2a060a94 | 46 | |
bf4a79ea | 47 | while ($line = $sth->fetch()) { |
2a060a94 AD |
48 | |
49 | $cat = array(); | |
50 | $cat['id'] = 'CAT:' . $line['id']; | |
2ecd2df5 | 51 | $cat['bare_id'] = (int)$line['id']; |
2a060a94 AD |
52 | $cat['name'] = $line['title']; |
53 | $cat['items'] = array(); | |
54 | $cat['checkbox'] = false; | |
55 | $cat['type'] = 'category'; | |
2ecd2df5 | 56 | $cat['unread'] = 0; |
2c5f231e | 57 | $cat['child_unread'] = 0; |
c594eca0 | 58 | $cat['auxcounter'] = 0; |
d922b09c | 59 | $cat['parent_id'] = $cat_id; |
2a060a94 AD |
60 | |
61 | $cat['items'] = $this->get_category_items($line['id']); | |
62 | ||
496195db | 63 | $num_children = $this->calculate_children_count($cat); |
967f0619 | 64 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
2a060a94 | 65 | |
496195db | 66 | if ($num_children > 0 || $show_empty_cats) |
2a060a94 AD |
67 | array_push($items, $cat); |
68 | ||
69 | } | |
70 | ||
bf4a79ea | 71 | $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
f6269d1b | 72 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
2a060a94 | 73 | FROM ttrss_feeds |
3a029230 | 74 | WHERE cat_id = :cat AND |
bf4a79ea AD |
75 | owner_uid = :uid AND |
76 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) | |
77 | ORDER BY order_id, title"); | |
78 | ||
79 | $fsth->execute([":cat" => $cat_id, ":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); | |
2a060a94 | 80 | |
bf4a79ea | 81 | while ($feed_line = $fsth->fetch()) { |
2a060a94 AD |
82 | $feed = array(); |
83 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 84 | $feed['bare_id'] = (int)$feed_line['id']; |
c594eca0 | 85 | $feed['auxcounter'] = 0; |
2a060a94 AD |
86 | $feed['name'] = $feed_line['title']; |
87 | $feed['checkbox'] = false; | |
2ecd2df5 | 88 | $feed['unread'] = 0; |
2a060a94 | 89 | $feed['error'] = $feed_line['last_error']; |
86a8351c | 90 | $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
6322ac79 | 91 | $feed['param'] = make_local_datetime( |
2a060a94 | 92 | $feed_line['last_updated'], true); |
f6269d1b | 93 | $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
2a060a94 AD |
94 | |
95 | array_push($items, $feed); | |
96 | } | |
97 | ||
98 | return $items; | |
99 | } | |
100 | ||
afcfe6ca | 101 | function getfeedtree() { |
0bb5833b AD |
102 | print json_encode($this->makefeedtree()); |
103 | } | |
104 | ||
105 | function makefeedtree() { | |
afcfe6ca | 106 | |
e6532439 | 107 | if (clean($_REQUEST['mode']) != 2) |
6e0ee833 AD |
108 | $search = $_SESSION["prefs_feed_search"]; |
109 | else | |
110 | $search = ""; | |
afcfe6ca | 111 | |
afcfe6ca AD |
112 | $root = array(); |
113 | $root['id'] = 'root'; | |
114 | $root['name'] = __('Feeds'); | |
115 | $root['items'] = array(); | |
116 | $root['type'] = 'category'; | |
117 | ||
a42c55f0 | 118 | $enable_cats = get_pref('ENABLE_FEED_CATS'); |
2ecd2df5 | 119 | |
e6532439 | 120 | if (clean($_REQUEST['mode']) == 2) { |
2ecd2df5 AD |
121 | |
122 | if ($enable_cats) { | |
88918ca6 | 123 | $cat = $this->feedlist_init_cat(-1); |
2ecd2df5 AD |
124 | } else { |
125 | $cat['items'] = array(); | |
126 | } | |
127 | ||
5417fbd7 | 128 | foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
2ecd2df5 AD |
129 | array_push($cat['items'], $this->feedlist_init_feed($i)); |
130 | } | |
131 | ||
a413f53e AD |
132 | /* Plugin feeds for -1 */ |
133 | ||
1ffe3391 | 134 | $feeds = PluginHost::getInstance()->get_feeds(-1); |
a413f53e AD |
135 | |
136 | if ($feeds) { | |
137 | foreach ($feeds as $feed) { | |
138 | $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); | |
139 | ||
140 | $item = array(); | |
141 | $item['id'] = 'FEED:' . $feed_id; | |
142 | $item['bare_id'] = (int)$feed_id; | |
c594eca0 | 143 | $item['auxcounter'] = 0; |
a413f53e AD |
144 | $item['name'] = $feed['title']; |
145 | $item['checkbox'] = false; | |
146 | $item['error'] = ''; | |
147 | $item['icon'] = $feed['icon']; | |
148 | ||
149 | $item['param'] = ''; | |
150 | $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']); | |
151 | $item['type'] = 'feed'; | |
152 | ||
153 | array_push($cat['items'], $item); | |
154 | } | |
155 | } | |
156 | ||
2ecd2df5 AD |
157 | if ($enable_cats) { |
158 | array_push($root['items'], $cat); | |
159 | } else { | |
160 | $root['items'] = array_merge($root['items'], $cat['items']); | |
161 | } | |
afcfe6ca | 162 | |
91d67966 AD |
163 | $sth = $this->pdo->prepare("SELECT * FROM |
164 | ttrss_labels2 WHERE owner_uid = ? ORDER by caption"); | |
165 | $sth->execute([$_SESSION['uid']]); | |
2ecd2df5 | 166 | |
91d67966 AD |
167 | if (get_pref('ENABLE_FEED_CATS')) { |
168 | $cat = $this->feedlist_init_cat(-2); | |
169 | } else { | |
170 | $cat['items'] = array(); | |
171 | } | |
2ecd2df5 | 172 | |
91d67966 AD |
173 | $num_labels = 0; |
174 | while ($line = $sth->fetch()) { | |
175 | ++$num_labels; | |
2ecd2df5 | 176 | |
91d67966 | 177 | $label_id = Labels::label_to_feed_id($line['id']); |
2ecd2df5 | 178 | |
91d67966 | 179 | $feed = $this->feedlist_init_feed($label_id, false, 0); |
2ecd2df5 | 180 | |
91d67966 AD |
181 | $feed['fg_color'] = $line['fg_color']; |
182 | $feed['bg_color'] = $line['bg_color']; | |
2ecd2df5 | 183 | |
91d67966 AD |
184 | array_push($cat['items'], $feed); |
185 | } | |
2ecd2df5 | 186 | |
91d67966 | 187 | if ($num_labels) { |
2ecd2df5 AD |
188 | if ($enable_cats) { |
189 | array_push($root['items'], $cat); | |
190 | } else { | |
191 | $root['items'] = array_merge($root['items'], $cat['items']); | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
196 | if ($enable_cats) { | |
e6532439 AD |
197 | $show_empty_cats = clean($_REQUEST['force_show_empty']) || |
198 | (clean($_REQUEST['mode']) != 2 && !$search); | |
2ecd2df5 | 199 | |
91d67966 AD |
200 | $sth = $this->pdo->prepare("SELECT id, title FROM ttrss_feed_categories |
201 | WHERE owner_uid = ? AND parent_cat IS NULL ORDER BY order_id, title"); | |
202 | $sth->execute([$_SESSION['uid']]); | |
afcfe6ca | 203 | |
91d67966 | 204 | while ($line = $sth->fetch()) { |
afcfe6ca AD |
205 | $cat = array(); |
206 | $cat['id'] = 'CAT:' . $line['id']; | |
2ecd2df5 | 207 | $cat['bare_id'] = (int)$line['id']; |
c594eca0 | 208 | $cat['auxcounter'] = 0; |
afcfe6ca AD |
209 | $cat['name'] = $line['title']; |
210 | $cat['items'] = array(); | |
211 | $cat['checkbox'] = false; | |
212 | $cat['type'] = 'category'; | |
2ecd2df5 | 213 | $cat['unread'] = 0; |
2c5f231e | 214 | $cat['child_unread'] = 0; |
afcfe6ca | 215 | |
2a060a94 | 216 | $cat['items'] = $this->get_category_items($line['id']); |
afcfe6ca | 217 | |
496195db | 218 | $num_children = $this->calculate_children_count($cat); |
967f0619 | 219 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
afcfe6ca | 220 | |
496195db | 221 | if ($num_children > 0 || $show_empty_cats) |
afcfe6ca AD |
222 | array_push($root['items'], $cat); |
223 | ||
224 | $root['param'] += count($cat['items']); | |
225 | } | |
226 | ||
227 | /* Uncategorized is a special case */ | |
228 | ||
229 | $cat = array(); | |
230 | $cat['id'] = 'CAT:0'; | |
231 | $cat['bare_id'] = 0; | |
c594eca0 | 232 | $cat['auxcounter'] = 0; |
afcfe6ca AD |
233 | $cat['name'] = __("Uncategorized"); |
234 | $cat['items'] = array(); | |
235 | $cat['type'] = 'category'; | |
236 | $cat['checkbox'] = false; | |
2ecd2df5 | 237 | $cat['unread'] = 0; |
2c5f231e | 238 | $cat['child_unread'] = 0; |
afcfe6ca | 239 | |
91d67966 | 240 | $fsth = $this->pdo->prepare("SELECT id, title,last_error, |
3a029230 | 241 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
afcfe6ca | 242 | FROM ttrss_feeds |
3a029230 | 243 | WHERE cat_id IS NULL AND |
91d67966 AD |
244 | owner_uid = :uid AND |
245 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) | |
246 | ORDER BY order_id, title"); | |
247 | $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); | |
afcfe6ca | 248 | |
91d67966 | 249 | while ($feed_line = $fsth->fetch()) { |
afcfe6ca AD |
250 | $feed = array(); |
251 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 252 | $feed['bare_id'] = (int)$feed_line['id']; |
c594eca0 | 253 | $feed['auxcounter'] = 0; |
afcfe6ca AD |
254 | $feed['name'] = $feed_line['title']; |
255 | $feed['checkbox'] = false; | |
256 | $feed['error'] = $feed_line['last_error']; | |
86a8351c | 257 | $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
6322ac79 | 258 | $feed['param'] = make_local_datetime( |
afcfe6ca | 259 | $feed_line['last_updated'], true); |
2ecd2df5 AD |
260 | $feed['unread'] = 0; |
261 | $feed['type'] = 'feed'; | |
f6269d1b | 262 | $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
afcfe6ca AD |
263 | |
264 | array_push($cat['items'], $feed); | |
265 | } | |
266 | ||
1a293f10 | 267 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca | 268 | |
5b7bd238 | 269 | if (count($cat['items']) > 0 || $show_empty_cats) |
afcfe6ca AD |
270 | array_push($root['items'], $cat); |
271 | ||
496195db | 272 | $num_children = $this->calculate_children_count($root); |
967f0619 | 273 | $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
afcfe6ca AD |
274 | |
275 | } else { | |
91d67966 | 276 | $fsth = $this->pdo->prepare("SELECT id, title, last_error, |
f6269d1b | 277 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated, update_interval |
afcfe6ca | 278 | FROM ttrss_feeds |
91d67966 AD |
279 | WHERE owner_uid = :uid AND |
280 | (:search = '' OR (LOWER(title) LIKE :search OR LOWER(feed_url) LIKE :search)) | |
281 | ORDER BY order_id, title"); | |
282 | $fsth->execute([":uid" => $_SESSION['uid'], ":search" => $search ? "%$search%" : ""]); | |
afcfe6ca | 283 | |
91d67966 | 284 | while ($feed_line = $fsth->fetch()) { |
afcfe6ca AD |
285 | $feed = array(); |
286 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 287 | $feed['bare_id'] = (int)$feed_line['id']; |
c594eca0 | 288 | $feed['auxcounter'] = 0; |
afcfe6ca AD |
289 | $feed['name'] = $feed_line['title']; |
290 | $feed['checkbox'] = false; | |
291 | $feed['error'] = $feed_line['last_error']; | |
86a8351c | 292 | $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
6322ac79 | 293 | $feed['param'] = make_local_datetime( |
afcfe6ca | 294 | $feed_line['last_updated'], true); |
2ecd2df5 AD |
295 | $feed['unread'] = 0; |
296 | $feed['type'] = 'feed'; | |
f6269d1b | 297 | $feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0); |
afcfe6ca AD |
298 | |
299 | array_push($root['items'], $feed); | |
300 | } | |
301 | ||
1a293f10 | 302 | $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca AD |
303 | } |
304 | ||
305 | $fl = array(); | |
306 | $fl['identifier'] = 'id'; | |
307 | $fl['label'] = 'name'; | |
2ecd2df5 | 308 | |
e6532439 | 309 | if (clean($_REQUEST['mode']) != 2) { |
2ecd2df5 AD |
310 | $fl['items'] = array($root); |
311 | } else { | |
1bd552ee | 312 | $fl['items'] = $root['items']; |
2ecd2df5 | 313 | } |
afcfe6ca | 314 | |
0bb5833b | 315 | return $fl; |
afcfe6ca AD |
316 | } |
317 | ||
318 | function catsortreset() { | |
91d67966 AD |
319 | $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
320 | SET order_id = 0 WHERE owner_uid = ?"); | |
321 | $sth->execute([$_SESSION['uid']]); | |
afcfe6ca AD |
322 | } |
323 | ||
324 | function feedsortreset() { | |
91d67966 AD |
325 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
326 | SET order_id = 0 WHERE owner_uid = ?"); | |
327 | $sth->execute([$_SESSION['uid']]); | |
afcfe6ca AD |
328 | } |
329 | ||
95ee44b3 | 330 | private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
95ee44b3 AD |
331 | |
332 | $prefix = ""; | |
333 | for ($i = 0; $i < $nest_level; $i++) | |
334 | $prefix .= " "; | |
335 | ||
c10a4306 | 336 | Debug::log("$prefix C: $item_id P: $parent_id"); |
95ee44b3 | 337 | |
bf4a79ea | 338 | $bare_item_id = substr($item_id, strpos($item_id, ':')+1); |
2a060a94 AD |
339 | |
340 | if ($item_id != 'root') { | |
341 | if ($parent_id && $parent_id != 'root') { | |
342 | $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1); | |
bf4a79ea | 343 | $parent_qpart = $parent_bare_id; |
2a060a94 | 344 | } else { |
91d67966 | 345 | $parent_qpart = null; |
2a060a94 AD |
346 | } |
347 | ||
91d67966 AD |
348 | $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
349 | SET parent_cat = ? WHERE id = ? AND | |
350 | owner_uid = ?"); | |
351 | $sth->execute([$parent_qpart, $bare_item_id, $_SESSION['uid']]); | |
2a060a94 AD |
352 | } |
353 | ||
c053b976 | 354 | $order_id = 1; |
2a060a94 AD |
355 | |
356 | $cat = $data_map[$item_id]; | |
357 | ||
358 | if ($cat && is_array($cat)) { | |
359 | foreach ($cat as $item) { | |
360 | $id = $item['_reference']; | |
bf4a79ea | 361 | $bare_id = substr($id, strpos($id, ':')+1); |
2a060a94 | 362 | |
c10a4306 | 363 | Debug::log("$prefix [$order_id] $id/$bare_id"); |
2a060a94 AD |
364 | |
365 | if ($item['_reference']) { | |
366 | ||
367 | if (strpos($id, "FEED") === 0) { | |
368 | ||
91d67966 | 369 | $cat_id = ($item_id != "root") ? $bare_item_id : null; |
95ee44b3 | 370 | |
91d67966 AD |
371 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
372 | SET order_id = ?, cat_id = ? | |
373 | WHERE id = ? AND owner_uid = ?"); | |
49b2401e | 374 | |
91d67966 | 375 | $sth->execute([$order_id, $cat_id ? $cat_id : null, $bare_id, $_SESSION['uid']]); |
2a060a94 AD |
376 | |
377 | } else if (strpos($id, "CAT:") === 0) { | |
95ee44b3 AD |
378 | $this->process_category_order($data_map, $item['_reference'], $item_id, |
379 | $nest_level+1); | |
2a060a94 | 380 | |
91d67966 AD |
381 | $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories |
382 | SET order_id = ? WHERE id = ? AND | |
383 | owner_uid = ?"); | |
384 | $sth->execute([$order_id, $bare_id, $_SESSION['uid']]); | |
2a060a94 AD |
385 | } |
386 | } | |
387 | ||
388 | ++$order_id; | |
389 | } | |
390 | } | |
391 | } | |
392 | ||
afcfe6ca | 393 | function savefeedorder() { |
67bf38af | 394 | $data = json_decode($_POST['payload'], true); |
afcfe6ca | 395 | |
e6532439 | 396 | #file_put_contents("/tmp/saveorder.json", clean($_POST['payload'])); |
2a060a94 | 397 | #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); |
a26f57e6 | 398 | |
95ee44b3 AD |
399 | if (!is_array($data['items'])) |
400 | $data['items'] = json_decode($data['items'], true); | |
401 | ||
402 | # print_r($data['items']); | |
2a060a94 | 403 | |
afcfe6ca | 404 | if (is_array($data) && is_array($data['items'])) { |
4a80c57c | 405 | # $cat_order_id = 0; |
afcfe6ca AD |
406 | |
407 | $data_map = array(); | |
2a060a94 | 408 | $root_item = false; |
afcfe6ca AD |
409 | |
410 | foreach ($data['items'] as $item) { | |
411 | ||
2a060a94 | 412 | # if ($item['id'] != 'root') { |
afcfe6ca AD |
413 | if (is_array($item['items'])) { |
414 | if (isset($item['items']['_reference'])) { | |
415 | $data_map[$item['id']] = array($item['items']); | |
416 | } else { | |
1bd552ee | 417 | $data_map[$item['id']] = $item['items']; |
afcfe6ca AD |
418 | } |
419 | } | |
2a060a94 AD |
420 | if ($item['id'] == 'root') { |
421 | $root_item = $item['id']; | |
afcfe6ca AD |
422 | } |
423 | } | |
424 | ||
d04f8c82 | 425 | $this->process_category_order($data_map, $root_item); |
afcfe6ca | 426 | } |
afcfe6ca AD |
427 | } |
428 | ||
429 | function removeicon() { | |
e6532439 | 430 | $feed_id = clean($_REQUEST["feed_id"]); |
afcfe6ca | 431 | |
91d67966 AD |
432 | $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
433 | WHERE id = ? AND owner_uid = ?"); | |
434 | $sth->execute([$feed_id, $_SESSION['uid']]); | |
afcfe6ca | 435 | |
91d67966 | 436 | if ($row = $sth->fetch()) { |
3306daec | 437 | @unlink(ICONS_DIR . "/$feed_id.ico"); |
bc7a144d | 438 | |
91d67966 AD |
439 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL |
440 | where id = ?"); | |
441 | $sth->execute([$feed_id]); | |
afcfe6ca | 442 | } |
afcfe6ca AD |
443 | } |
444 | ||
445 | function uploadicon() { | |
350e3944 AD |
446 | header("Content-type: text/html"); |
447 | ||
3306daec AD |
448 | if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { |
449 | $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); | |
450 | ||
451 | $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], | |
452 | $tmp_file); | |
453 | ||
454 | if (!$result) { | |
455 | return; | |
456 | } | |
457 | } else { | |
458 | return; | |
459 | } | |
460 | ||
461 | $icon_file = $tmp_file; | |
e6532439 | 462 | $feed_id = clean($_REQUEST["feed_id"]); |
afcfe6ca AD |
463 | |
464 | if (is_file($icon_file) && $feed_id) { | |
4a1d122c | 465 | if (filesize($icon_file) < 65535) { |
afcfe6ca | 466 | |
91d67966 AD |
467 | $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
468 | WHERE id = ? AND owner_uid = ?"); | |
469 | $sth->execute([$feed_id, $_SESSION['uid']]); | |
afcfe6ca | 470 | |
91d67966 | 471 | if ($row = $sth->fetch()) { |
3306daec | 472 | @unlink(ICONS_DIR . "/$feed_id.ico"); |
bc7a144d | 473 | if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { |
91d67966 AD |
474 | |
475 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET | |
258068b3 | 476 | favicon_avg_color = '' |
91d67966 AD |
477 | WHERE id = ?"); |
478 | $sth->execute([$feed_id]); | |
bc7a144d AD |
479 | |
480 | $rc = 0; | |
481 | } | |
afcfe6ca AD |
482 | } else { |
483 | $rc = 2; | |
484 | } | |
485 | } else { | |
486 | $rc = 1; | |
487 | } | |
488 | } else { | |
489 | $rc = 2; | |
490 | } | |
491 | ||
3306daec AD |
492 | @unlink($icon_file); |
493 | ||
afcfe6ca AD |
494 | print "<script type=\"text/javascript\">"; |
495 | print "parent.uploadIconHandler($rc);"; | |
496 | print "</script>"; | |
497 | return; | |
498 | } | |
499 | ||
500 | function editfeed() { | |
501 | global $purge_intervals; | |
502 | global $update_intervals; | |
afcfe6ca | 503 | |
d9877997 | 504 | |
e6532439 | 505 | $feed_id = clean($_REQUEST["id"]); |
afcfe6ca | 506 | |
bf6db17b AD |
507 | $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND |
508 | owner_uid = ?"); | |
509 | $sth->execute([$feed_id, $_SESSION['uid']]); | |
afcfe6ca | 510 | |
bf6db17b AD |
511 | if ($row = $sth->fetch()) { |
512 | print '<div dojoType="dijit.layout.TabContainer" style="height : 450px"> | |
513 | <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">'; | |
044cff2d | 514 | |
bf6db17b | 515 | $title = htmlspecialchars($row["title"]); |
afcfe6ca | 516 | |
bf6db17b AD |
517 | print_hidden("id", "$feed_id"); |
518 | print_hidden("op", "pref-feeds"); | |
519 | print_hidden("method", "editSave"); | |
520 | ||
521 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
522 | print "<div class=\"dlgSecCont\">"; | |
afcfe6ca | 523 | |
bf6db17b | 524 | /* Title */ |
afcfe6ca | 525 | |
bf6db17b | 526 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" |
afcfe6ca AD |
527 | placeHolder=\"".__("Feed Title")."\" |
528 | style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">"; | |
529 | ||
bf6db17b | 530 | /* Feed URL */ |
afcfe6ca | 531 | |
bf6db17b | 532 | $feed_url = htmlspecialchars($row["feed_url"]); |
afcfe6ca | 533 | |
bf6db17b | 534 | print "<hr/>"; |
afcfe6ca | 535 | |
bf6db17b AD |
536 | print __('URL:') . " "; |
537 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" | |
afcfe6ca AD |
538 | placeHolder=\"".__("Feed URL")."\" |
539 | regExp='^(http|https)://.*' style=\"width : 20em\" | |
540 | name=\"feed_url\" value=\"$feed_url\">"; | |
541 | ||
bf6db17b | 542 | $last_error = $row["last_error"]; |
afcfe6ca | 543 | |
bf6db17b AD |
544 | if ($last_error) { |
545 | print " <img src=\"images/error.png\" alt=\"(error)\" | |
1a545dcb AD |
546 | style=\"vertical-align : middle\" |
547 | title=\"".htmlspecialchars($last_error)."\">"; | |
afcfe6ca | 548 | |
bf6db17b | 549 | } |
afcfe6ca | 550 | |
bf6db17b | 551 | /* Category */ |
afcfe6ca | 552 | |
bf6db17b | 553 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca | 554 | |
bf6db17b | 555 | $cat_id = $row["cat_id"]; |
afcfe6ca | 556 | |
bf6db17b | 557 | print "<hr/>"; |
afcfe6ca | 558 | |
bf6db17b | 559 | print __('Place in category:') . " "; |
afcfe6ca | 560 | |
bf6db17b AD |
561 | print_feed_cat_select("cat_id", $cat_id, |
562 | 'dojoType="dijit.form.Select"'); | |
563 | } | |
afcfe6ca | 564 | |
c9a5e5aa AD |
565 | /* Site URL */ |
566 | ||
567 | $site_url = htmlspecialchars($row["site_url"]); | |
568 | ||
569 | print "<hr/>"; | |
570 | ||
571 | print __('Site URL:') . " "; | |
572 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" | |
573 | placeHolder=\"".__("Site URL")."\" | |
574 | regExp='^(http|https)://.*' style=\"width : 15em\" | |
575 | name=\"site_url\" value=\"$site_url\">"; | |
576 | ||
bf6db17b | 577 | /* FTS Stemming Language */ |
df659891 | 578 | |
bf6db17b AD |
579 | if (DB_TYPE == "pgsql") { |
580 | $feed_language = $row["feed_language"]; | |
df659891 | 581 | |
bf6db17b | 582 | print "<hr/>"; |
df659891 | 583 | |
bf6db17b AD |
584 | print __('Language:') . " "; |
585 | print_select("feed_language", $feed_language, $this::$feed_languages, | |
586 | 'dojoType="dijit.form.Select"'); | |
587 | } | |
df659891 | 588 | |
bf6db17b | 589 | print "</div>"; |
afcfe6ca | 590 | |
bf6db17b AD |
591 | print "<div class=\"dlgSec\">".__("Update")."</div>"; |
592 | print "<div class=\"dlgSecCont\">"; | |
afcfe6ca | 593 | |
bf6db17b | 594 | /* Update Interval */ |
afcfe6ca | 595 | |
bf6db17b | 596 | $update_interval = $row["update_interval"]; |
afcfe6ca | 597 | |
bf6db17b AD |
598 | print_select_hash("update_interval", $update_interval, $update_intervals, |
599 | 'dojoType="dijit.form.Select"'); | |
afcfe6ca | 600 | |
bf6db17b | 601 | /* Purge intl */ |
afcfe6ca | 602 | |
fbff72e0 | 603 | if (FORCE_ARTICLE_PURGE == 0) { |
bf6db17b | 604 | $purge_interval = $row["purge_interval"]; |
afcfe6ca | 605 | |
bf6db17b AD |
606 | print "<hr/>"; |
607 | print __('Article purging:') . " "; | |
afcfe6ca | 608 | |
bf6db17b AD |
609 | print_select_hash("purge_interval", $purge_interval, $purge_intervals, |
610 | 'dojoType="dijit.form.Select" ' . | |
afcfe6ca | 611 | ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); |
fbff72e0 | 612 | } |
afcfe6ca | 613 | |
bf6db17b | 614 | print "</div>"; |
afcfe6ca | 615 | |
bf6db17b | 616 | $auth_login = htmlspecialchars($row["auth_login"]); |
069aea59 | 617 | $auth_pass = htmlspecialchars($row["auth_pass"]); |
044cff2d | 618 | |
bf6db17b | 619 | $auth_enabled = $auth_login !== '' || $auth_pass !== ''; |
cc50affb | 620 | |
bf6db17b AD |
621 | $auth_style = $auth_enabled ? '' : 'display: none'; |
622 | print "<div id='feedEditDlg_loginContainer' style='$auth_style'>"; | |
623 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
624 | print "<div class=\"dlgSecCont\">"; | |
cc50affb | 625 | |
bf6db17b | 626 | print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\" |
cc50affb FE |
627 | placeHolder=\"".__("Login")."\" |
628 | autocomplete=\"new-password\" | |
629 | name=\"auth_login\" value=\"$auth_login\"><hr/>"; | |
630 | ||
bf6db17b | 631 | print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" |
ec21abb8 | 632 | autocomplete=\"new-password\" |
afcfe6ca AD |
633 | placeHolder=\"".__("Password")."\" |
634 | value=\"$auth_pass\">"; | |
635 | ||
bf6db17b | 636 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\"> |
afcfe6ca AD |
637 | ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." |
638 | </div>"; | |
639 | ||
bf6db17b | 640 | print "</div></div>"; |
cc50affb | 641 | |
bf6db17b AD |
642 | $auth_checked = $auth_enabled ? 'checked' : ''; |
643 | print "<div style=\"clear : both\"> | |
cc50affb FE |
644 | <input type=\"checkbox\" $auth_checked name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedEditDlg_loginCheck\" |
645 | onclick='checkboxToggleElement(this, \"feedEditDlg_loginContainer\")'> | |
646 | <label for=\"feedEditDlg_loginCheck\">". | |
bf6db17b | 647 | __('This feed requires authentication.')."</div>"; |
d9877997 | 648 | |
bf6db17b | 649 | print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">'; |
d9877997 | 650 | |
bf6db17b AD |
651 | //print "<div class=\"dlgSec\">".__("Options")."</div>"; |
652 | print "<div class=\"dlgSecSimple\">"; | |
afcfe6ca | 653 | |
187abfe7 | 654 | $private = $row["private"]; |
afcfe6ca | 655 | |
bf6db17b AD |
656 | if ($private) { |
657 | $checked = "checked=\"1\""; | |
658 | } else { | |
659 | $checked = ""; | |
660 | } | |
afcfe6ca | 661 | |
bf6db17b | 662 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\" |
afcfe6ca AD |
663 | $checked> <label for=\"private\">".__('Hide from Popular feeds')."</label>"; |
664 | ||
81fc862e | 665 | if (DIGEST_SUBJECT !== false) { |
187abfe7 | 666 | $include_in_digest = $row["include_in_digest"]; |
afcfe6ca | 667 | |
bf6db17b AD |
668 | if ($include_in_digest) { |
669 | $checked = "checked=\"1\""; | |
670 | } else { | |
671 | $checked = ""; | |
672 | } | |
afcfe6ca | 673 | |
bf6db17b | 674 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" |
afcfe6ca AD |
675 | name=\"include_in_digest\" |
676 | $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
81fc862e | 677 | } |
afcfe6ca AD |
678 | |
679 | ||
187abfe7 | 680 | $always_display_enclosures = $row["always_display_enclosures"]; |
afcfe6ca | 681 | |
bf6db17b AD |
682 | if ($always_display_enclosures) { |
683 | $checked = "checked"; | |
684 | } else { | |
685 | $checked = ""; | |
686 | } | |
afcfe6ca | 687 | |
bf6db17b | 688 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" |
afcfe6ca AD |
689 | name=\"always_display_enclosures\" |
690 | $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
691 | ||
187abfe7 | 692 | $hide_images = $row["hide_images"]; |
bfd61d3f | 693 | |
bf6db17b AD |
694 | if ($hide_images) { |
695 | $checked = "checked=\"1\""; | |
696 | } else { | |
697 | $checked = ""; | |
698 | } | |
bfd61d3f | 699 | |
bf6db17b | 700 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\" |
bfd61d3f AD |
701 | name=\"hide_images\" |
702 | $checked> <label for=\"hide_images\">". | |
d4fef362 | 703 | __('Do not embed media')."</label>"; |
afcfe6ca | 704 | |
187abfe7 | 705 | $cache_images = $row["cache_images"]; |
afcfe6ca | 706 | |
bf6db17b AD |
707 | if ($cache_images) { |
708 | $checked = "checked=\"1\""; | |
709 | } else { | |
710 | $checked = ""; | |
711 | } | |
afcfe6ca | 712 | |
bf6db17b | 713 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\" |
3c696512 | 714 | name=\"cache_images\" |
afcfe6ca | 715 | $checked> <label for=\"cache_images\">". |
bf6db17b | 716 | __('Cache media')."</label>"; |
afcfe6ca | 717 | |
187abfe7 | 718 | $mark_unread_on_update = $row["mark_unread_on_update"]; |
afcfe6ca | 719 | |
bf6db17b AD |
720 | if ($mark_unread_on_update) { |
721 | $checked = "checked"; | |
722 | } else { | |
723 | $checked = ""; | |
724 | } | |
afcfe6ca | 725 | |
bf6db17b | 726 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\" |
afcfe6ca AD |
727 | name=\"mark_unread_on_update\" |
728 | $checked> <label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
729 | ||
bf6db17b | 730 | print "</div>"; |
afcfe6ca | 731 | |
bf6db17b | 732 | print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">'; |
d9877997 | 733 | |
bf6db17b | 734 | /* Icon */ |
afcfe6ca | 735 | |
bf6db17b | 736 | print "<div class=\"dlgSecSimple\">"; |
afcfe6ca | 737 | |
5f5b0de4 AD |
738 | print "<img class=\"feedIcon\" src=\"".Feeds::getFeedIcon($feed_id)."\">"; |
739 | ||
bf6db17b | 740 | print "<iframe name=\"icon_upload_iframe\" |
5f5b0de4 | 741 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; |
afcfe6ca | 742 | |
bf6db17b | 743 | print "<form style='display : block' target=\"icon_upload_iframe\" |
afcfe6ca AD |
744 | enctype=\"multipart/form-data\" method=\"POST\" |
745 | action=\"backend.php\"> | |
5f5b0de4 AD |
746 | <label class=\"dijitButton\">".__("Choose file...")." |
747 | <input style=\"display: none\" id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\"> | |
748 | </label> | |
afcfe6ca AD |
749 | <input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> |
750 | <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\"> | |
3a029230 | 751 | <input type=\"hidden\" name=\"method\" value=\"uploadicon\"> |
d9877997 | 752 | <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\" |
afcfe6ca | 753 | type=\"submit\">".__('Replace')."</button> |
6fb5ce5e | 754 | <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\" |
afcfe6ca AD |
755 | type=\"submit\">".__('Remove')."</button> |
756 | </form>"; | |
757 | ||
bf6db17b | 758 | print "</div>"; |
afcfe6ca | 759 | |
bf6db17b | 760 | print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">'; |
d9877997 | 761 | |
bf6db17b AD |
762 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
763 | "hook_prefs_edit_feed", $feed_id); | |
057177eb | 764 | |
d9877997 | 765 | |
bf6db17b | 766 | print "</div></div>"; |
d9877997 | 767 | |
bf6db17b | 768 | $title = htmlspecialchars($title, ENT_QUOTES); |
afcfe6ca | 769 | |
bf6db17b | 770 | print "<div class='dlgButtons'> |
afcfe6ca | 771 | <div style=\"float : left\"> |
6fb5ce5e | 772 | <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>". |
afcfe6ca AD |
773 | __('Unsubscribe')."</button>"; |
774 | ||
bf6db17b | 775 | print "</div>"; |
afcfe6ca | 776 | |
bf6db17b AD |
777 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> |
778 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> | |
779 | </div>"; | |
780 | } | |
afcfe6ca AD |
781 | } |
782 | ||
783 | function editfeeds() { | |
784 | global $purge_intervals; | |
785 | global $update_intervals; | |
46da73c2 | 786 | |
e6532439 | 787 | $feed_ids = clean($_REQUEST["ids"]); |
afcfe6ca | 788 | |
fcef9eea AD |
789 | print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
790 | ||
791 | print "<p>"; | |
ca6a0741 | 792 | |
328118d1 AD |
793 | print_hidden("ids", "$feed_ids"); |
794 | print_hidden("op", "pref-feeds"); | |
795 | print_hidden("method", "batchEditSave"); | |
afcfe6ca AD |
796 | |
797 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
798 | print "<div class=\"dlgSecCont\">"; | |
799 | ||
afcfe6ca AD |
800 | /* Category */ |
801 | ||
a42c55f0 | 802 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca | 803 | |
afcfe6ca AD |
804 | print __('Place in category:') . " "; |
805 | ||
d29357fa | 806 | print_feed_cat_select("cat_id", false, |
afcfe6ca AD |
807 | 'disabled="1" dojoType="dijit.form.Select"'); |
808 | ||
809 | $this->batch_edit_cbox("cat_id"); | |
810 | ||
811 | } | |
812 | ||
df659891 AD |
813 | /* FTS Stemming Language */ |
814 | ||
815 | if (DB_TYPE == "pgsql") { | |
816 | print "<hr/>"; | |
817 | ||
818 | print __('Language:') . " "; | |
819 | print_select("feed_language", "", $this::$feed_languages, | |
820 | 'disabled="1" dojoType="dijit.form.Select"'); | |
821 | ||
822 | $this->batch_edit_cbox("feed_language"); | |
823 | } | |
824 | ||
afcfe6ca AD |
825 | print "</div>"; |
826 | ||
827 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
828 | print "<div class=\"dlgSecCont\">"; | |
829 | ||
830 | /* Update Interval */ | |
831 | ||
d29357fa | 832 | print_select_hash("update_interval", "", $update_intervals, |
afcfe6ca AD |
833 | 'disabled="1" dojoType="dijit.form.Select"'); |
834 | ||
835 | $this->batch_edit_cbox("update_interval"); | |
836 | ||
afcfe6ca AD |
837 | /* Purge intl */ |
838 | ||
839 | if (FORCE_ARTICLE_PURGE == 0) { | |
840 | ||
841 | print "<br/>"; | |
842 | ||
843 | print __('Article purging:') . " "; | |
844 | ||
d29357fa | 845 | print_select_hash("purge_interval", "", $purge_intervals, |
afcfe6ca AD |
846 | 'disabled="1" dojoType="dijit.form.Select"'); |
847 | ||
848 | $this->batch_edit_cbox("purge_interval"); | |
849 | } | |
850 | ||
851 | print "</div>"; | |
852 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
853 | print "<div class=\"dlgSecCont\">"; | |
854 | ||
855 | print "<input dojoType=\"dijit.form.TextBox\" | |
856 | placeHolder=\"".__("Login")."\" disabled=\"1\" | |
ec21abb8 | 857 | autocomplete=\"new-password\" |
d29357fa | 858 | name=\"auth_login\" value=\"\">"; |
afcfe6ca AD |
859 | |
860 | $this->batch_edit_cbox("auth_login"); | |
861 | ||
44727c79 | 862 | print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" |
ec21abb8 | 863 | autocomplete=\"new-password\" |
afcfe6ca | 864 | placeHolder=\"".__("Password")."\" disabled=\"1\" |
d29357fa | 865 | value=\"\">"; |
afcfe6ca AD |
866 | |
867 | $this->batch_edit_cbox("auth_pass"); | |
868 | ||
869 | print "</div>"; | |
870 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
871 | print "<div class=\"dlgSecCont\">"; | |
872 | ||
873 | print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\" | |
874 | dojoType=\"dijit.form.CheckBox\"> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
875 | ||
876 | print " "; $this->batch_edit_cbox("private", "private_l"); | |
877 | ||
afcfe6ca AD |
878 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\" |
879 | name=\"include_in_digest\" | |
880 | dojoType=\"dijit.form.CheckBox\"> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
881 | ||
882 | print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); | |
883 | ||
884 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\" | |
885 | name=\"always_display_enclosures\" | |
886 | dojoType=\"dijit.form.CheckBox\"> <label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
887 | ||
888 | print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); | |
889 | ||
bfd61d3f AD |
890 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\" |
891 | name=\"hide_images\" | |
892 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"hide_images_l\" | |
893 | for=\"hide_images\">". | |
d4fef362 | 894 | __('Do not embed media')."</label>"; |
bfd61d3f AD |
895 | |
896 | print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); | |
897 | ||
3c696512 AD |
898 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\" |
899 | name=\"cache_images\" | |
900 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"cache_images_l\" | |
901 | for=\"cache_images\">". | |
9c3c0ace | 902 | __('Cache media')."</label>"; |
afcfe6ca | 903 | |
3c696512 | 904 | print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
afcfe6ca AD |
905 | |
906 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
907 | name=\"mark_unread_on_update\" | |
908 | dojoType=\"dijit.form.CheckBox\"> <label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
909 | ||
910 | print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); | |
911 | ||
afcfe6ca AD |
912 | print "</div>"; |
913 | ||
914 | print "<div class='dlgButtons'> | |
915 | <button dojoType=\"dijit.form.Button\" | |
916 | onclick=\"return dijit.byId('feedEditDlg').execute()\">". | |
917 | __('Save')."</button> | |
918 | <button dojoType=\"dijit.form.Button\" | |
919 | onclick=\"return dijit.byId('feedEditDlg').hide()\">". | |
920 | __('Cancel')."</button> | |
921 | </div>"; | |
922 | ||
923 | return; | |
924 | } | |
925 | ||
926 | function batchEditSave() { | |
3a76e2a2 | 927 | return $this->editsaveops(true); |
afcfe6ca | 928 | } |
46da73c2 | 929 | |
afcfe6ca | 930 | function editSave() { |
3a76e2a2 | 931 | return $this->editsaveops(false); |
afcfe6ca | 932 | } |
46da73c2 AD |
933 | |
934 | function editsaveops($batch) { | |
935 | ||
e6532439 AD |
936 | $feed_title = trim(clean($_POST["title"])); |
937 | $feed_url = trim(clean($_POST["feed_url"])); | |
c9a5e5aa | 938 | $site_url = trim(clean($_POST["site_url"])); |
e6532439 AD |
939 | $upd_intl = (int) clean($_POST["update_interval"]); |
940 | $purge_intl = (int) clean($_POST["purge_interval"]); | |
941 | $feed_id = (int) clean($_POST["id"]); /* editSave */ | |
942 | $feed_ids = explode(",", clean($_POST["ids"])); /* batchEditSave */ | |
943 | $cat_id = (int) clean($_POST["cat_id"]); | |
944 | $auth_login = trim(clean($_POST["auth_login"])); | |
945 | $auth_pass = trim(clean($_POST["auth_pass"])); | |
946 | $private = checkbox_to_sql_bool(clean($_POST["private"])); | |
afcfe6ca | 947 | $include_in_digest = checkbox_to_sql_bool( |
e6532439 | 948 | clean($_POST["include_in_digest"])); |
afcfe6ca | 949 | $cache_images = checkbox_to_sql_bool( |
e6532439 | 950 | clean($_POST["cache_images"])); |
bfd61d3f | 951 | $hide_images = checkbox_to_sql_bool( |
e6532439 | 952 | clean($_POST["hide_images"])); |
afcfe6ca | 953 | $always_display_enclosures = checkbox_to_sql_bool( |
e6532439 | 954 | clean($_POST["always_display_enclosures"])); |
afcfe6ca AD |
955 | |
956 | $mark_unread_on_update = checkbox_to_sql_bool( | |
e6532439 | 957 | clean($_POST["mark_unread_on_update"])); |
afcfe6ca | 958 | |
e6532439 | 959 | $feed_language = trim(clean($_POST["feed_language"])); |
df659891 | 960 | |
3a76e2a2 | 961 | if (!$batch) { |
e6532439 | 962 | if (clean($_POST["need_auth"]) !== 'on') { |
cc50affb FE |
963 | $auth_login = ''; |
964 | $auth_pass = ''; | |
965 | } | |
afcfe6ca | 966 | |
c9a5e5aa | 967 | /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); |
91d67966 | 968 | $sth->execute([$feed_id]); |
c9a5e5aa | 969 | $row = $sth->fetch();$orig_feed_url = $row["feed_url"]; |
91d67966 | 970 | |
c9a5e5aa | 971 | $reset_basic_info = $orig_feed_url != $feed_url; */ |
91d67966 AD |
972 | |
973 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET | |
974 | cat_id = :cat_id, | |
3a029230 | 975 | title = :title, |
91d67966 | 976 | feed_url = :feed_url, |
c9a5e5aa | 977 | site_url = :site_url, |
91d67966 AD |
978 | update_interval = :upd_intl, |
979 | purge_interval = :purge_intl, | |
980 | auth_login = :auth_login, | |
981 | auth_pass = :auth_pass, | |
51b521c3 | 982 | auth_pass_encrypted = false, |
91d67966 AD |
983 | private = :private, |
984 | cache_images = :cache_images, | |
985 | hide_images = :hide_images, | |
986 | include_in_digest = :include_in_digest, | |
987 | always_display_enclosures = :always_display_enclosures, | |
988 | mark_unread_on_update = :mark_unread_on_update, | |
989 | feed_language = :feed_language | |
990 | WHERE id = :id AND owner_uid = :uid"); | |
991 | ||
992 | $sth->execute([":title" => $feed_title, | |
993 | ":cat_id" => $cat_id ? $cat_id : null, | |
994 | ":feed_url" => $feed_url, | |
c9a5e5aa | 995 | ":site_url" => $site_url, |
91d67966 AD |
996 | ":upd_intl" => $upd_intl, |
997 | ":purge_intl" => $purge_intl, | |
998 | ":auth_login" => $auth_login, | |
999 | ":auth_pass" => $auth_pass, | |
1000 | ":private" => (int)$private, | |
1001 | ":cache_images" => (int)$cache_images, | |
1002 | ":hide_images" => (int)$hide_images, | |
1003 | ":include_in_digest" => (int)$include_in_digest, | |
1004 | ":always_display_enclosures" => (int)$always_display_enclosures, | |
1005 | ":mark_unread_on_update" => (int)$mark_unread_on_update, | |
1006 | ":feed_language" => $feed_language, | |
1007 | ":id" => $feed_id, | |
1008 | ":uid" => $_SESSION['uid']]); | |
afcfe6ca | 1009 | |
c9a5e5aa | 1010 | /* if ($reset_basic_info) { |
e6c886bf | 1011 | RSSUtils::set_basic_feed_info($feed_id); |
c9a5e5aa | 1012 | } */ |
91837f0a | 1013 | |
8cefe38a AD |
1014 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
1015 | "hook_prefs_save_feed", $feed_id); | |
1016 | ||
3a76e2a2 | 1017 | } else { |
afcfe6ca AD |
1018 | $feed_data = array(); |
1019 | ||
1020 | foreach (array_keys($_POST) as $k) { | |
1021 | if ($k != "op" && $k != "method" && $k != "ids") { | |
e6532439 | 1022 | $feed_data[$k] = clean($_POST[$k]); |
afcfe6ca AD |
1023 | } |
1024 | } | |
1025 | ||
91d67966 AD |
1026 | $this->pdo->beginTransaction(); |
1027 | ||
1028 | $feed_ids_qmarks = arr_qmarks($feed_ids); | |
afcfe6ca AD |
1029 | |
1030 | foreach (array_keys($feed_data) as $k) { | |
1031 | ||
1032 | $qpart = ""; | |
1033 | ||
1034 | switch ($k) { | |
1035 | case "title": | |
91d67966 | 1036 | $qpart = "title = " . $this->pdo->quote($feed_title); |
afcfe6ca AD |
1037 | break; |
1038 | ||
1039 | case "feed_url": | |
91d67966 | 1040 | $qpart = "feed_url = " . $this->pdo->quote($feed_url); |
afcfe6ca AD |
1041 | break; |
1042 | ||
1043 | case "update_interval": | |
91d67966 | 1044 | $qpart = "update_interval = " . $this->pdo->quote($upd_intl); |
afcfe6ca AD |
1045 | break; |
1046 | ||
1047 | case "purge_interval": | |
91d67966 | 1048 | $qpart = "purge_interval =" . $this->pdo->quote($purge_intl); |
afcfe6ca AD |
1049 | break; |
1050 | ||
1051 | case "auth_login": | |
91d67966 | 1052 | $qpart = "auth_login = " . $this->pdo->quote($auth_login); |
afcfe6ca AD |
1053 | break; |
1054 | ||
1055 | case "auth_pass": | |
91d67966 | 1056 | $qpart = "auth_pass =" . $this->pdo->quote($auth_pass). ", auth_pass_encrypted = false"; |
afcfe6ca AD |
1057 | break; |
1058 | ||
1059 | case "private": | |
91d67966 | 1060 | $qpart = "private = " . $this->pdo->quote($private); |
afcfe6ca AD |
1061 | break; |
1062 | ||
1063 | case "include_in_digest": | |
91d67966 | 1064 | $qpart = "include_in_digest = " . $this->pdo->quote($include_in_digest); |
afcfe6ca AD |
1065 | break; |
1066 | ||
1067 | case "always_display_enclosures": | |
91d67966 | 1068 | $qpart = "always_display_enclosures = " . $this->pdo->quote($always_display_enclosures); |
afcfe6ca AD |
1069 | break; |
1070 | ||
1071 | case "mark_unread_on_update": | |
91d67966 | 1072 | $qpart = "mark_unread_on_update = " . $this->pdo->quote($mark_unread_on_update); |
afcfe6ca AD |
1073 | break; |
1074 | ||
afcfe6ca | 1075 | case "cache_images": |
91d67966 | 1076 | $qpart = "cache_images = " . $this->pdo->quote($cache_images); |
afcfe6ca AD |
1077 | break; |
1078 | ||
bfd61d3f | 1079 | case "hide_images": |
91d67966 | 1080 | $qpart = "hide_images = " . $this->pdo->quote($hide_images); |
bfd61d3f AD |
1081 | break; |
1082 | ||
afcfe6ca | 1083 | case "cat_id": |
91d67966 AD |
1084 | if (get_pref('ENABLE_FEED_CATS')) { |
1085 | if ($cat_id) { | |
1086 | $qpart = "cat_id = " . $this->pdo->quote($cat_id); | |
1087 | } else { | |
1088 | $qpart = 'cat_id = NULL'; | |
1089 | } | |
1090 | } else { | |
1091 | $qpart = ""; | |
1092 | } | |
1093 | ||
afcfe6ca AD |
1094 | break; |
1095 | ||
df659891 | 1096 | case "feed_language": |
91d67966 | 1097 | $qpart = "feed_language = " . $this->pdo->quote($feed_language); |
df659891 AD |
1098 | break; |
1099 | ||
afcfe6ca AD |
1100 | } |
1101 | ||
1102 | if ($qpart) { | |
91d67966 AD |
1103 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks) |
1104 | AND owner_uid = ?"); | |
1105 | $sth->execute(array_merge($feed_ids, [$_SESSION['uid']])); | |
afcfe6ca AD |
1106 | } |
1107 | } | |
1108 | ||
91d67966 | 1109 | $this->pdo->commit(); |
afcfe6ca AD |
1110 | } |
1111 | return; | |
1112 | } | |
1113 | ||
afcfe6ca AD |
1114 | function remove() { |
1115 | ||
e6532439 | 1116 | $ids = explode(",", clean($_REQUEST["ids"])); |
afcfe6ca AD |
1117 | |
1118 | foreach ($ids as $id) { | |
a42c55f0 | 1119 | Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
afcfe6ca AD |
1120 | } |
1121 | ||
1122 | return; | |
1123 | } | |
1124 | ||
28537341 | 1125 | function removeCat() { |
e6532439 | 1126 | $ids = explode(",", clean($_REQUEST["ids"])); |
28537341 | 1127 | foreach ($ids as $id) { |
a42c55f0 | 1128 | $this->remove_feed_category($id, $_SESSION["uid"]); |
28537341 AD |
1129 | } |
1130 | } | |
1131 | ||
1132 | function addCat() { | |
e6532439 | 1133 | $feed_cat = trim(clean($_REQUEST["cat"])); |
28537341 | 1134 | |
a42c55f0 | 1135 | add_feed_category($feed_cat); |
28537341 AD |
1136 | } |
1137 | ||
afcfe6ca AD |
1138 | function index() { |
1139 | ||
1140 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; | |
1141 | print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">"; | |
1142 | ||
bf6db17b AD |
1143 | $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
1144 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); | |
1145 | $sth->execute([$_SESSION['uid']]); | |
afcfe6ca | 1146 | |
bf6db17b AD |
1147 | if ($row = $sth->fetch()) { |
1148 | $num_errors = $row["num_errors"]; | |
1149 | } else { | |
1150 | $num_errors = 0; | |
1151 | } | |
afcfe6ca AD |
1152 | |
1153 | if ($num_errors > 0) { | |
1154 | ||
1155 | $error_button = "<button dojoType=\"dijit.form.Button\" | |
1156 | onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" . | |
1157 | __("Feeds with errors") . "</button>"; | |
1158 | } | |
1159 | ||
f9c1f8b0 AD |
1160 | $inactive_button = "<button dojoType=\"dijit.form.Button\" |
1161 | id=\"pref_feeds_inactive_btn\" | |
1162 | style=\"display : none\" | |
1163 | onclick=\"showInactiveFeeds()\">" . | |
1164 | __("Inactive feeds") . "</button>"; | |
afcfe6ca | 1165 | |
e6532439 | 1166 | $feed_search = clean($_REQUEST["search"]); |
afcfe6ca AD |
1167 | |
1168 | if (array_key_exists("search", $_REQUEST)) { | |
1169 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1170 | } else { | |
1171 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1172 | } | |
1173 | ||
1174 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
1175 | ||
1176 | print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar | |
1177 | ||
1178 | print "<div style='float : right; padding-right : 4px;'> | |
1179 | <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" | |
1180 | value=\"$feed_search\"> | |
1181 | <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">". | |
1182 | __('Search')."</button> | |
1183 | </div>"; | |
1184 | ||
1185 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1186 | "<span>" . __('Select')."</span>"; | |
1187 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1188 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" | |
1189 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1190 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" | |
1191 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1192 | print "</div></div>"; | |
1193 | ||
1194 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1195 | "<span>" . __('Feeds')."</span>"; | |
1196 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1197 | print "<div onclick=\"quickAddFeed()\" | |
1198 | dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; | |
1199 | print "<div onclick=\"editSelectedFeed()\" | |
1200 | dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; | |
1201 | print "<div onclick=\"resetFeedOrder()\" | |
1202 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
33f0fdd0 AD |
1203 | print "<div onclick=\"batchSubscribe()\" |
1204 | dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>"; | |
0671359f AD |
1205 | print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">" |
1206 | .__('Unsubscribe')."</div> "; | |
afcfe6ca AD |
1207 | print "</div></div>"; |
1208 | ||
a42c55f0 | 1209 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca AD |
1210 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
1211 | "<span>" . __('Categories')."</span>"; | |
1212 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
5ef071e0 AD |
1213 | print "<div onclick=\"createCategory()\" |
1214 | dojoType=\"dijit.MenuItem\">".__('Add category')."</div>"; | |
afcfe6ca AD |
1215 | print "<div onclick=\"resetCatOrder()\" |
1216 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
fd26d5bf AD |
1217 | print "<div onclick=\"removeSelectedCategories()\" |
1218 | dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>"; | |
afcfe6ca AD |
1219 | print "</div></div>"; |
1220 | ||
1221 | } | |
1222 | ||
1223 | print $error_button; | |
1224 | print $inactive_button; | |
1225 | ||
afcfe6ca AD |
1226 | print "</div>"; # toolbar |
1227 | ||
1228 | //print '</div>'; | |
1229 | print '<div dojoType="dijit.layout.ContentPane" region="center">'; | |
1230 | ||
1231 | print "<div id=\"feedlistLoading\"> | |
1232 | <img src='images/indicator_tiny.gif'>". | |
1233 | __("Loading, please wait...")."</div>"; | |
1234 | ||
f1415df4 AD |
1235 | $auto_expand = $feed_search != "" ? "true" : "false"; |
1236 | ||
afcfe6ca AD |
1237 | print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" |
1238 | url=\"backend.php?op=pref-feeds&method=getfeedtree\"> | |
1239 | </div> | |
1240 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" | |
1241 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
1242 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
1243 | </div> | |
1244 | <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\" | |
1245 | dndController=\"dijit.tree.dndSource\" | |
1246 | betweenThreshold=\"5\" | |
f1415df4 | 1247 | autoExpand='$auto_expand' |
afcfe6ca AD |
1248 | model=\"feedModel\" openOnClick=\"false\"> |
1249 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
1250 | var id = String(item.id); | |
1251 | var bare_id = id.substr(id.indexOf(':')+1); | |
1252 | ||
1253 | if (id.match('FEED:')) { | |
1254 | editFeed(bare_id); | |
1255 | } else if (id.match('CAT:')) { | |
1256 | editCat(bare_id, item); | |
1257 | } | |
1258 | </script> | |
1259 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
1260 | Element.hide(\"feedlistLoading\"); | |
f9c1f8b0 AD |
1261 | |
1262 | checkInactiveFeeds(); | |
afcfe6ca AD |
1263 | </script> |
1264 | </div>"; | |
1265 | ||
ba5296a1 AD |
1266 | # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\"> |
1267 | # ".__('<b>Hint:</b> you can drag feeds and categories around.')." | |
1268 | # </div>"; | |
afcfe6ca AD |
1269 | |
1270 | print '</div>'; | |
1271 | print '</div>'; | |
1272 | ||
1273 | print "</div>"; # feeds pane | |
1274 | ||
6c2637d9 | 1275 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">"; |
afcfe6ca | 1276 | |
73dfda1d AD |
1277 | print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . |
1278 | __("Only main settings profile can be migrated using OPML.") . "</p>"; | |
afcfe6ca | 1279 | |
55f34b81 | 1280 | print "<iframe id=\"upload_iframe\" |
afcfe6ca AD |
1281 | name=\"upload_iframe\" onload=\"opmlImportComplete(this)\" |
1282 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
1283 | ||
1284 | print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\" | |
1285 | enctype=\"multipart/form-data\" method=\"POST\" | |
55f34b81 | 1286 | action=\"backend.php\"> |
5f5b0de4 AD |
1287 | <label class=\"dijitButton\">".__("Choose file...")." |
1288 | <input style=\"display : none\" id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
1289 | </label> | |
afcfe6ca | 1290 | <input type=\"hidden\" name=\"op\" value=\"dlg\"> |
c4c74732 | 1291 | <input type=\"hidden\" name=\"method\" value=\"importOpml\"> |
afcfe6ca | 1292 | <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" . |
a1159c01 | 1293 | __('Import my OPML') . "</button>"; |
afcfe6ca | 1294 | |
a1159c01 | 1295 | print "<hr>"; |
afcfe6ca | 1296 | |
77e81006 AD |
1297 | $opml_export_filename = "TinyTinyRSS_".date("Y-m-d").".opml"; |
1298 | ||
afcfe6ca | 1299 | print "<p>" . __('Filename:') . |
5f5b0de4 | 1300 | " <input class=\"input input-text\" type=\"text\" id=\"filename\" value=\"$opml_export_filename\" /> " . |
a1159c01 | 1301 | __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>"; |
afcfe6ca | 1302 | |
a1159c01 | 1303 | print "</p><button dojoType=\"dijit.form.Button\" |
afcfe6ca | 1304 | onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" . |
a1159c01 | 1305 | __('Export OPML') . "</button></p></form>"; |
afcfe6ca | 1306 | |
a1159c01 | 1307 | print "<hr>"; |
afcfe6ca | 1308 | |
73dfda1d | 1309 | print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "</p>"; |
afcfe6ca | 1310 | |
73dfda1d | 1311 | print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds."); |
afcfe6ca | 1312 | |
fb54e3b1 | 1313 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
a1159c01 | 1314 | __('Display published OPML URL')."</button> "; |
afcfe6ca | 1315 | |
1ffe3391 | 1316 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
1317 | "hook_prefs_tab_section", "prefFeedsOPML"); |
1318 | ||
afcfe6ca AD |
1319 | print "</div>"; # pane |
1320 | ||
e95e7819 | 1321 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">"; |
afcfe6ca | 1322 | |
73dfda1d | 1323 | print "<p>" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "</p>"; |
afcfe6ca AD |
1324 | |
1325 | $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . | |
1326 | "/public.php?op=rss&id=-2&view-mode=all_articles");; | |
1327 | ||
11334fdf AD |
1328 | print "<p>"; |
1329 | ||
fb54e3b1 | 1330 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">". |
afcfe6ca AD |
1331 | __('Display URL')."</button> "; |
1332 | ||
73dfda1d | 1333 | print "<button class=\"warning\" dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">". |
afcfe6ca AD |
1334 | __('Clear all generated URLs')."</button> "; |
1335 | ||
11334fdf | 1336 | print "</p>"; |
afcfe6ca | 1337 | |
1ffe3391 | 1338 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
1339 | "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
1340 | ||
afcfe6ca AD |
1341 | print "</div>"; #pane |
1342 | ||
1ffe3391 | 1343 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
1344 | "hook_prefs_tab", "prefFeeds"); |
1345 | ||
afcfe6ca | 1346 | print "</div>"; #container |
afcfe6ca | 1347 | } |
2ecd2df5 | 1348 | |
88918ca6 | 1349 | private function feedlist_init_cat($cat_id) { |
2ecd2df5 AD |
1350 | $obj = array(); |
1351 | $cat_id = (int) $cat_id; | |
1352 | ||
1353 | if ($cat_id > 0) { | |
2ed0d6c4 | 1354 | $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); |
2ecd2df5 | 1355 | } else if ($cat_id == 0 || $cat_id == -2) { |
86a8351c | 1356 | $cat_unread = Feeds::getCategoryUnread($cat_id); |
2ecd2df5 AD |
1357 | } |
1358 | ||
1359 | $obj['id'] = 'CAT:' . $cat_id; | |
1360 | $obj['items'] = array(); | |
a230bf88 | 1361 | $obj['name'] = Feeds::getCategoryTitle($cat_id); |
2ecd2df5 AD |
1362 | $obj['type'] = 'category'; |
1363 | $obj['unread'] = (int) $cat_unread; | |
2ecd2df5 AD |
1364 | $obj['bare_id'] = $cat_id; |
1365 | ||
1366 | return $obj; | |
1367 | } | |
1368 | ||
1369 | private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { | |
1370 | $obj = array(); | |
1371 | $feed_id = (int) $feed_id; | |
1372 | ||
1373 | if (!$title) | |
86a8351c | 1374 | $title = Feeds::getFeedTitle($feed_id, false); |
2ecd2df5 AD |
1375 | |
1376 | if ($unread === false) | |
a42c55f0 | 1377 | $unread = getFeedUnread($feed_id, false); |
2ecd2df5 AD |
1378 | |
1379 | $obj['id'] = 'FEED:' . $feed_id; | |
1380 | $obj['name'] = $title; | |
1381 | $obj['unread'] = (int) $unread; | |
1382 | $obj['type'] = 'feed'; | |
1383 | $obj['error'] = $error; | |
1384 | $obj['updated'] = $updated; | |
86a8351c | 1385 | $obj['icon'] = Feeds::getFeedIcon($feed_id); |
2ecd2df5 | 1386 | $obj['bare_id'] = $feed_id; |
c594eca0 | 1387 | $obj['auxcounter'] = 0; |
2ecd2df5 AD |
1388 | |
1389 | return $obj; | |
1390 | } | |
1391 | ||
bc6fa236 AD |
1392 | function inactiveFeeds() { |
1393 | ||
1394 | if (DB_TYPE == "pgsql") { | |
1395 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1396 | } else { | |
1397 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1398 | } | |
1399 | ||
7a1872c1 | 1400 | $sth = $this->pdo->prepare("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
bc6fa236 AD |
1401 | ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article |
1402 | FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE | |
1403 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE | |
1404 | ttrss_entries.id = ref_id AND | |
1405 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart | |
7a1872c1 | 1406 | AND ttrss_feeds.owner_uid = ? AND |
bc6fa236 AD |
1407 | ttrss_user_entries.feed_id = ttrss_feeds.id AND |
1408 | ttrss_entries.id = ref_id | |
1409 | GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url | |
1410 | ORDER BY last_article"); | |
7a1872c1 | 1411 | $sth->execute([$_SESSION['uid']]); |
bc6fa236 | 1412 | |
11334fdf | 1413 | print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>"; |
bc6fa236 AD |
1414 | |
1415 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1416 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1417 | "<span>" . __('Select')."</span>"; | |
1418 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1419 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\" | |
1420 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1421 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\" | |
1422 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1423 | print "</div></div>"; | |
1424 | print "</div>"; #toolbar | |
1425 | ||
1426 | print "<div class=\"inactiveFeedHolder\">"; | |
1427 | ||
1428 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">"; | |
1429 | ||
1430 | $lnum = 1; | |
1431 | ||
7a1872c1 | 1432 | while ($line = $sth->fetch()) { |
bc6fa236 | 1433 | |
bc6fa236 AD |
1434 | $feed_id = $line["id"]; |
1435 | $this_row_id = "id=\"FUPDD-$feed_id\""; | |
1436 | ||
1437 | # class needed for selectTableRows() | |
1438 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1439 | ||
bc6fa236 AD |
1440 | # id needed for selectTableRows() |
1441 | print "<td width='5%' align='center'><input | |
1442 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1443 | type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>"; | |
1444 | print "<td>"; | |
1445 | ||
1446 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1447 | "title=\"".__("Click to edit feed")."\" ". | |
1448 | "onclick=\"editFeed(".$line["id"].")\">". | |
1449 | htmlspecialchars($line["title"])."</a>"; | |
1450 | ||
1451 | print "</td><td class=\"insensitive\" align='right'>"; | |
a42c55f0 | 1452 | print make_local_datetime($line['last_article'], false); |
bc6fa236 AD |
1453 | print "</td>"; |
1454 | print "</tr>"; | |
1455 | ||
1456 | ++$lnum; | |
1457 | } | |
1458 | ||
1459 | print "</table>"; | |
1460 | print "</div>"; | |
1461 | ||
1462 | print "<div class='dlgButtons'>"; | |
1463 | print "<div style='float : left'>"; | |
6fb5ce5e | 1464 | print "<button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" |
bc6fa236 AD |
1465 | .__('Unsubscribe from selected feeds')."</button> "; |
1466 | print "</div>"; | |
1467 | ||
1468 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">". | |
1469 | __('Close this window')."</button>"; | |
1470 | ||
1471 | print "</div>"; | |
1472 | ||
1473 | } | |
1474 | ||
1475 | function feedsWithErrors() { | |
7a1872c1 AD |
1476 | $sth = $this->pdo->prepare("SELECT id,title,feed_url,last_error,site_url |
1477 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); | |
1478 | $sth->execute([$_SESSION['uid']]); | |
bc6fa236 AD |
1479 | |
1480 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1481 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1482 | "<span>" . __('Select')."</span>"; | |
1483 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1484 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\" | |
1485 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1486 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\" | |
1487 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1488 | print "</div></div>"; | |
1489 | print "</div>"; #toolbar | |
1490 | ||
1491 | print "<div class=\"inactiveFeedHolder\">"; | |
1492 | ||
1493 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; | |
1494 | ||
1495 | $lnum = 1; | |
1496 | ||
7a1872c1 | 1497 | while ($line = $sth->fetch()) { |
bc6fa236 | 1498 | |
bc6fa236 AD |
1499 | $feed_id = $line["id"]; |
1500 | $this_row_id = "id=\"FERDD-$feed_id\""; | |
1501 | ||
1502 | # class needed for selectTableRows() | |
1503 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1504 | ||
bc6fa236 AD |
1505 | # id needed for selectTableRows() |
1506 | print "<td width='5%' align='center'><input | |
1507 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1508 | type=\"checkbox\" id=\"FERDC-$feed_id\"></td>"; | |
1509 | print "<td>"; | |
1510 | ||
1511 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1512 | "title=\"".__("Click to edit feed")."\" ". | |
1513 | "onclick=\"editFeed(".$line["id"].")\">". | |
1514 | htmlspecialchars($line["title"])."</a>: "; | |
1515 | ||
1516 | print "<span class=\"insensitive\">"; | |
1517 | print htmlspecialchars($line["last_error"]); | |
1518 | print "</span>"; | |
1519 | ||
1520 | print "</td>"; | |
1521 | print "</tr>"; | |
1522 | ||
1523 | ++$lnum; | |
1524 | } | |
1525 | ||
1526 | print "</table>"; | |
1527 | print "</div>"; | |
1528 | ||
1529 | print "<div class='dlgButtons'>"; | |
1530 | print "<div style='float : left'>"; | |
6fb5ce5e | 1531 | print "<button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" |
bc6fa236 AD |
1532 | .__('Unsubscribe from selected feeds')."</button> "; |
1533 | print "</div>"; | |
1534 | ||
1535 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". | |
1536 | __('Close this window')."</button>"; | |
1537 | ||
1538 | print "</div>"; | |
1539 | } | |
1540 | ||
a42c55f0 | 1541 | private function remove_feed_category($id, $owner_uid) { |
a6a9b812 | 1542 | |
7a1872c1 AD |
1543 | $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories |
1544 | WHERE id = ? AND owner_uid = ?"); | |
1545 | $sth->execute([$id, $owner_uid]); | |
a6a9b812 | 1546 | |
2ed0d6c4 | 1547 | CCache::remove($id, $owner_uid, true); |
a6a9b812 AD |
1548 | } |
1549 | ||
a42c55f0 | 1550 | static function remove_feed($id, $owner_uid) { |
53955264 | 1551 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_UNSUBSCRIBE_FEED) as $p) { |
c10a4306 AD |
1552 | if (! $p->hook_unsubscribe_feed($id, $owner_uid)) { |
1553 | user_error("Feed $id (owner: $owner_uid) not removed due to plugin error (HOOK_UNSUBSCRIBE_FEED).", E_USER_WARNING); | |
1554 | return; | |
e58a14de | 1555 | } |
53955264 | 1556 | } |
a6a9b812 | 1557 | |
7a1872c1 AD |
1558 | $pdo = Db::pdo(); |
1559 | ||
a6a9b812 | 1560 | if ($id > 0) { |
7a1872c1 | 1561 | $pdo->beginTransaction(); |
a6a9b812 AD |
1562 | |
1563 | /* save starred articles in Archived feed */ | |
1564 | ||
a6a9b812 AD |
1565 | /* prepare feed if necessary */ |
1566 | ||
7a1872c1 AD |
1567 | $sth = $pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ? |
1568 | AND owner_uid = ?"); | |
1569 | $sth->execute([$id, $owner_uid]); | |
aa5ac2cd | 1570 | |
7a1872c1 AD |
1571 | if ($row = $sth->fetch()) { |
1572 | $feed_url = $row["feed_url"]; | |
aa5ac2cd | 1573 | |
7a1872c1 AD |
1574 | $sth = $pdo->prepare("SELECT id FROM ttrss_archived_feeds |
1575 | WHERE feed_url = ? AND owner_uid = ?"); | |
1576 | $sth->execute([$feed_url, $owner_uid]); | |
a6a9b812 | 1577 | |
7a1872c1 AD |
1578 | if ($row = $sth->fetch()) { |
1579 | $archive_id = $row["id"]; | |
1580 | } else { | |
1581 | $res = $pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); | |
1582 | $row = $res->fetch(); | |
b1df14d0 | 1583 | |
7a1872c1 | 1584 | $new_feed_id = (int)$row['id'] + 1; |
aa5ac2cd | 1585 | |
7a1872c1 AD |
1586 | $sth = $pdo->prepare("INSERT INTO ttrss_archived_feeds |
1587 | (id, owner_uid, title, feed_url, site_url) | |
1588 | SELECT ?, owner_uid, title, feed_url, site_url from ttrss_feeds | |
1589 | WHERE id = ?"); | |
1590 | $sth->execute([$new_feed_id, $id]); | |
1591 | ||
1592 | $archive_id = $new_feed_id; | |
1593 | } | |
a6a9b812 | 1594 | |
7a1872c1 AD |
1595 | $sth = $pdo->prepare("UPDATE ttrss_user_entries SET feed_id = NULL, |
1596 | orig_feed_id = ? WHERE feed_id = ? AND | |
1597 | marked = true AND owner_uid = ?"); | |
a6a9b812 | 1598 | |
7a1872c1 | 1599 | $sth->execute([$archive_id, $id, $owner_uid]); |
a6a9b812 | 1600 | |
7a1872c1 | 1601 | /* Remove access key for the feed */ |
a6a9b812 | 1602 | |
7a1872c1 AD |
1603 | $sth = $pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
1604 | feed_id = ? AND owner_uid = ?"); | |
1605 | $sth->execute([$id, $owner_uid]); | |
a6a9b812 | 1606 | |
7a1872c1 AD |
1607 | /* remove the feed */ |
1608 | ||
1609 | $sth = $pdo->prepare("DELETE FROM ttrss_feeds | |
1610 | WHERE id = ? AND owner_uid = ?"); | |
1611 | $sth->execute([$id, $owner_uid]); | |
1612 | } | |
a6a9b812 | 1613 | |
7a1872c1 | 1614 | $pdo->commit(); |
a6a9b812 AD |
1615 | |
1616 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
1617 | unlink(ICONS_DIR . "/$id.ico"); | |
1618 | } | |
1619 | ||
2ed0d6c4 | 1620 | CCache::remove($id, $owner_uid); |
a6a9b812 AD |
1621 | |
1622 | } else { | |
7c9b5a3f | 1623 | Labels::remove(Labels::feed_to_label_id($id), $owner_uid); |
2ed0d6c4 | 1624 | //CCache::remove($id, $owner_uid); don't think labels are cached |
a6a9b812 AD |
1625 | } |
1626 | } | |
87d7e850 | 1627 | |
201bb1ca | 1628 | function batchSubscribe() { |
328118d1 AD |
1629 | print_hidden("op", "pref-feeds"); |
1630 | print_hidden("method", "batchaddfeeds"); | |
201bb1ca AD |
1631 | |
1632 | print "<table width='100%'><tr><td> | |
1633 | ".__("Add one valid RSS feed per line (no feed detection is done)")." | |
1634 | </td><td align='right'>"; | |
a42c55f0 | 1635 | if (get_pref('ENABLE_FEED_CATS')) { |
201bb1ca | 1636 | print __('Place in category:') . " "; |
a42c55f0 | 1637 | print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); |
201bb1ca AD |
1638 | } |
1639 | print "</td></tr><tr><td colspan='2'>"; | |
1640 | print "<textarea | |
fb8a032a | 1641 | style='font-size : 12px; width : 98%; height: 200px;' |
201bb1ca AD |
1642 | placeHolder=\"".__("Feeds to subscribe, One per line")."\" |
1643 | dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>"; | |
1644 | ||
1645 | print "</td></tr><tr><td colspan='2'>"; | |
1646 | ||
1647 | print "<div id='feedDlg_loginContainer' style='display : none'> | |
1648 | " . | |
1649 | " <input dojoType=\"dijit.form.TextBox\" name='login'\" | |
1650 | placeHolder=\"".__("Login")."\" | |
1651 | style=\"width : 10em;\"> ". | |
1652 | " <input | |
1653 | placeHolder=\"".__("Password")."\" | |
1654 | dojoType=\"dijit.form.TextBox\" type='password' | |
ec21abb8 | 1655 | autocomplete=\"new-password\" |
201bb1ca AD |
1656 | style=\"width : 10em;\" name='pass'\">". |
1657 | "</div>"; | |
1658 | ||
1659 | print "</td></tr><tr><td colspan='2'>"; | |
1660 | ||
1661 | print "<div style=\"clear : both\"> | |
1662 | <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\" | |
1663 | onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'> | |
1664 | <label for=\"feedDlg_loginCheck\">". | |
1665 | __('Feeds require authentication.')."</div>"; | |
1666 | ||
1667 | print "</form>"; | |
1668 | ||
1669 | print "</td></tr></table>"; | |
1670 | ||
1671 | print "<div class=\"dlgButtons\"> | |
1672 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button> | |
1673 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button> | |
1674 | </div>"; | |
1675 | } | |
1676 | ||
96e3ae8c | 1677 | function batchAddFeeds() { |
e6532439 AD |
1678 | $cat_id = clean($_REQUEST['cat']); |
1679 | $feeds = explode("\n", clean($_REQUEST['feeds'])); | |
1680 | $login = clean($_REQUEST['login']); | |
1681 | $pass = trim(clean($_REQUEST['pass'])); | |
96e3ae8c AD |
1682 | |
1683 | foreach ($feeds as $feed) { | |
bf4a79ea | 1684 | $feed = trim($feed); |
96e3ae8c AD |
1685 | |
1686 | if (validate_feed_url($feed)) { | |
1687 | ||
2e52e4fd | 1688 | $this->pdo->beginTransaction(); |
96e3ae8c | 1689 | |
2e52e4fd AD |
1690 | $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds |
1691 | WHERE feed_url = ? AND owner_uid = ?"); | |
1692 | $sth->execute([$feed, $_SESSION['uid']]); | |
41694a95 | 1693 | |
2e52e4fd AD |
1694 | if (!$sth->fetch()) { |
1695 | $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds | |
044cff2d | 1696 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) |
2e52e4fd AD |
1697 | VALUES (?, ?, '[Unknown]', ?, ?, ?, 0, false)"); |
1698 | ||
1699 | $sth->execute([$_SESSION['uid'], $feed, $cat_id ? $cat_id : null, $login, $pass]); | |
96e3ae8c AD |
1700 | } |
1701 | ||
2e52e4fd | 1702 | $this->pdo->commit(); |
96e3ae8c AD |
1703 | } |
1704 | } | |
1705 | } | |
201bb1ca | 1706 | |
195187c4 | 1707 | function regenOPMLKey() { |
a42c55f0 | 1708 | $this->update_feed_access_key('OPML:Publish', |
195187c4 AD |
1709 | false, $_SESSION["uid"]); |
1710 | ||
6322ac79 | 1711 | $new_link = Opml::opml_publish_url(); |
195187c4 AD |
1712 | |
1713 | print json_encode(array("link" => $new_link)); | |
1714 | } | |
1715 | ||
1716 | function regenFeedKey() { | |
e6532439 | 1717 | $feed_id = clean($_REQUEST['id']); |
fc0a3050 | 1718 | $is_cat = clean($_REQUEST['is_cat']); |
195187c4 | 1719 | |
a42c55f0 | 1720 | $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
195187c4 | 1721 | |
fc0a3050 | 1722 | print json_encode(["link" => $new_key]); |
195187c4 AD |
1723 | } |
1724 | ||
1725 | ||
a42c55f0 | 1726 | private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
195187c4 AD |
1727 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
1728 | ||
bf6db17b AD |
1729 | // clear old value and generate new one |
1730 | $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys | |
1731 | WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?"); | |
fc0a3050 | 1732 | $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]); |
195187c4 | 1733 | |
bf6db17b | 1734 | return get_feed_access_key($feed_id, $is_cat, $owner_uid); |
195187c4 AD |
1735 | } |
1736 | ||
1737 | // Silent | |
1738 | function clearKeys() { | |
2e52e4fd AD |
1739 | $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE |
1740 | owner_uid = ?"); | |
1741 | $sth->execute([$_SESSION['uid']]); | |
195187c4 AD |
1742 | } |
1743 | ||
496195db AD |
1744 | private function calculate_children_count($cat) { |
1745 | $c = 0; | |
1746 | ||
1747 | foreach ($cat['items'] as $child) { | |
1748 | if ($child['type'] == 'category') { | |
1749 | $c += $this->calculate_children_count($child); | |
1750 | } else { | |
1751 | $c += 1; | |
1752 | } | |
1753 | } | |
1754 | ||
1755 | return $c; | |
1756 | } | |
195187c4 | 1757 | |
f9c1f8b0 AD |
1758 | function getinactivefeeds() { |
1759 | if (DB_TYPE == "pgsql") { | |
1760 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1761 | } else { | |
1762 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1763 | } | |
1764 | ||
2e52e4fd | 1765 | $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_inactive FROM ttrss_feeds WHERE |
f9c1f8b0 AD |
1766 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE |
1767 | ttrss_entries.id = ref_id AND | |
1768 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND | |
2e52e4fd AD |
1769 | ttrss_feeds.owner_uid = ?"); |
1770 | $sth->execute([$_SESSION['uid']]); | |
f9c1f8b0 | 1771 | |
2e52e4fd AD |
1772 | if ($row = $sth->fetch()) { |
1773 | print (int)$row["num_inactive"]; | |
1774 | } | |
f9c1f8b0 | 1775 | } |
c114a259 AD |
1776 | |
1777 | static function subscribe_to_feed_url() { | |
1778 | $url_path = get_self_url_prefix() . | |
1779 | "/public.php?op=subscribe&feed_url=%s"; | |
1780 | return $url_path; | |
1781 | } | |
1782 | ||
53955264 | 1783 | } |