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