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