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