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