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