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