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