]> git.wh0rd.org - tt-rss.git/blob - modules/pref-feeds.php
854ca0dc2adebbacfc6d095aa02974aa8c64d8a2
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2
3 function module_pref_feeds($link) {
4
5 global $update_intervals;
6 global $purge_intervals;
7 global $update_methods;
8
9 $subop = $_REQUEST["subop"];
10 $quiet = $_REQUEST["quiet"];
11
12 if ($subop == "massSubscribe") {
13 $ids = split(",", db_escape_string($_GET["ids"]));
14
15 $subscribed = array();
16
17 foreach ($ids as $id) {
18 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
19 WHERE id = '$id'");
20
21 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
22 $title = db_escape_string(db_fetch_result($result, 0, "title"));
23
24 $title_orig = db_fetch_result($result, 0, "title");
25
26 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
27 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
28
29 if (db_num_rows($result) == 0) {
30 $result = db_query($link,
31 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
32 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
33
34 array_push($subscribed, $title_orig);
35 }
36 }
37
38 if (count($subscribed) > 0) {
39 $msg = "<b>".__('Subscribed to feeds:')."</b>".
40 "<ul class=\"nomarks\">";
41
42 foreach ($subscribed as $title) {
43 $msg .= "<li>$title</li>";
44 }
45 $msg .= "</ul>";
46
47 print format_notice($msg);
48 }
49 }
50
51 if ($subop == "browse") {
52
53 if (!ENABLE_FEED_BROWSER) {
54 print __("Feed browser is administratively disabled.");
55 return;
56 }
57
58 print "<div id=\"infoBoxTitle\">".__('Other feeds: Top 25')."</div>";
59
60 print "<div class=\"infoBoxContents\">";
61
62 print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
63
64 # $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
65 # FROM ttrss_feeds
66 # WHERE auth_login = '' AND auth_pass = '' AND private = false
67 # GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
68
69 $owner_uid = $_SESSION["uid"];
70
71 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
72 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
73 WHERE tf.feed_url = ttrss_feeds.feed_url
74 AND owner_uid = '$owner_uid') GROUP BY feed_url
75 ORDER BY subscribers DESC LIMIT 25");
76
77 print "<ul class='browseFeedList' id='browseFeedList'>";
78
79 $feedctr = 0;
80
81 while ($line = db_fetch_assoc($result)) {
82 $feed_url = $line["feed_url"];
83 $subscribers = $line["subscribers"];
84
85 $det_result = db_query($link, "SELECT site_url,title,id
86 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
87
88 $details = db_fetch_assoc($det_result);
89
90 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
91
92 if (file_exists($icon_file) && filesize($icon_file) > 0) {
93 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
94 "/".$details["id"].".ico\">";
95 } else {
96 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
97 }
98
99 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
100 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
101
102 $class = ($feedctr % 2) ? "even" : "odd";
103
104 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
105 "$feed_icon " . $details["title"] .
106 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
107
108 ++$feedctr;
109 }
110
111 if ($feedctr == 0) {
112 print "<li>".__('No feeds found to subscribe.')."</li>";
113 }
114
115 print "</ul>";
116
117 print "<div align='center'>
118 <input type=\"submit\" class=\"button\"
119 onclick=\"feedBrowserSubscribe()\" value=\"".__('Subscribe')."\">
120 <input type='submit' class='button'
121 onclick=\"closeInfoBox()\" value=\"".__('Cancel')."\"></div>";
122
123 print "</div>";
124 return;
125 }
126
127 if ($subop == "editfeed") {
128 $feed_id = db_escape_string($_REQUEST["id"]);
129
130 $result = db_query($link,
131 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
132 owner_uid = " . $_SESSION["uid"]);
133
134 $title = htmlspecialchars(db_fetch_result($result,
135 0, "title"));
136
137 $icon_file = ICONS_DIR . "/$feed_id.ico";
138
139 if (file_exists($icon_file) && filesize($icon_file) > 0) {
140 $feed_icon = "<img width=\"16\" height=\"16\"
141 src=\"" . ICONS_URL . "/$feed_id.ico\">";
142 } else {
143 $feed_icon = "";
144 }
145
146 print "<div id=\"infoBoxTitle\">".__('Feed editor')."</div>";
147
148 print "<div class=\"infoBoxContents\">";
149
150 print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
151
152 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
153 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
154 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
155
156 print "<table width='100%'>";
157
158 print "<tr><td>".__('Title:')."</td>";
159 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
160 name=\"title\" value=\"$title\"></td></tr>";
161
162 $feed_url = db_fetch_result($result, 0, "feed_url");
163 $feed_url = htmlspecialchars(db_fetch_result($result,
164 0, "feed_url"));
165
166 print "<tr><td>".__('Feed URL:')."</td>";
167 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
168 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
169
170 if (get_pref($link, 'ENABLE_FEED_CATS')) {
171
172 $cat_id = db_fetch_result($result, 0, "cat_id");
173
174 print "<tr><td>".__('Category:')."</td>";
175 print "<td>";
176
177 $parent_feed = db_fetch_result($result, 0, "parent_feed");
178
179 if (sprintf("%d", $parent_feed) > 0) {
180 $disabled = "disabled";
181 } else {
182 $disabled = "";
183 }
184
185 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled");
186
187 print "</td>";
188 print "</td></tr>";
189
190 }
191
192 $update_interval = db_fetch_result($result, 0, "update_interval");
193
194 print "<tr><td>".__('Update Interval:')."</td>";
195
196 print "<td>";
197
198 print_select_hash("update_interval", $update_interval, $update_intervals,
199 "class=\"iedit\"");
200
201 print "</td>";
202
203 print "<tr><td>".__('Link to:')."</td><td>";
204
205 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
206 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
207
208 $linked_count = db_fetch_result($tmp_result, 0, "count");
209
210 $parent_feed = db_fetch_result($result, 0, "parent_feed");
211
212 if ($linked_count > 0) {
213 $disabled = "disabled";
214 } else {
215 $disabled = "";
216 }
217
218 print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
219
220 print "<option value=\"0\">".__('Not linked')."</option>";
221
222 if (get_pref($link, 'ENABLE_FEED_CATS')) {
223 if ($cat_id) {
224 $cat_qpart = "AND cat_id = '$cat_id'";
225 } else {
226 $cat_qpart = "AND cat_id IS NULL";
227 }
228 }
229
230 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
231 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
232 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
233 $cat_qpart ORDER BY title");
234
235 if (db_num_rows($tmp_result) > 0) {
236 print "<option disabled>--------</option>";
237 }
238
239 while ($tmp_line = db_fetch_assoc($tmp_result)) {
240 if ($tmp_line["id"] == $parent_feed) {
241 $is_selected = "selected";
242 } else {
243 $is_selected = "";
244 }
245 printf("<option $is_selected value='%d'>%s</option>",
246 $tmp_line["id"], $tmp_line["title"]);
247 }
248
249 print "</select>";
250 print "</td></tr>";
251
252 $purge_interval = db_fetch_result($result, 0, "purge_interval");
253
254 print "<tr><td>".__('Article purging:')."</td>";
255
256 print "<td>";
257
258 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
259 "class=\"iedit\"");
260
261 print "</td>";
262
263 if (ALLOW_SELECT_UPDATE_METHOD) {
264
265 $update_method = db_fetch_result($result, 0, "update_method");
266
267 print "<tr><td>".__('Update using:')."</td>";
268
269 print "<td>";
270
271 print_select_hash("update_method", $update_method, $update_methods,
272 "class=\"iedit\"");
273
274 print "</td>";
275 }
276
277 $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
278
279 print "<tr><td>".__('Login:')."</td>";
280 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
281 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
282
283 $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
284
285 print "<tr><td>".__('Password:')."</td>";
286 print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
287 onkeypress=\"return filterCR(event, feedEditSave)\"
288 value=\"$auth_pass\"></td></tr>";
289
290 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
291
292 if ($private) {
293 $checked = "checked";
294 } else {
295 $checked = "";
296 }
297
298 print "<tr><td valign='top'>".__('Options:')."</td>";
299 print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
300 $checked><label for=\"private\">".__('Hide from "Other Feeds"')."</label>";
301
302 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
303
304 if ($rtl_content) {
305 $checked = "checked";
306 } else {
307 $checked = "";
308 }
309
310 print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
311 $checked><label for=\"rtl_content\">".__('Right-to-left content')."</label>";
312
313 $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
314
315 if ($hidden) {
316 $checked = "checked";
317 } else {
318 $checked = "";
319 }
320
321 print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
322 $checked><label for=\"hidden\">".__('Hide from my feed list')."</label>";
323
324 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
325
326 if ($include_in_digest) {
327 $checked = "checked";
328 } else {
329 $checked = "";
330 }
331
332 print "<br><input type=\"checkbox\" id=\"include_in_digest\"
333 name=\"include_in_digest\"
334 $checked><label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
335
336 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
337
338 if ($cache_images) {
339 $checked = "checked";
340 } else {
341 $checked = "";
342 }
343
344 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
345 $disabled = "";
346 $label_class = "";
347 } else {
348 $disabled = "disabled";
349 $label_class = "class='insensitive'";
350 }
351
352 print "<br><input type=\"checkbox\" id=\"cache_images\"
353 name=\"cache_images\" $disabled
354 $checked><label $label_class for=\"cache_images\">".
355 __('Cache images locally')."</label>";
356
357 print "</td></tr>";
358
359 print "</table>";
360
361 print "</form>";
362
363 print "<div align='right'>
364 <input type=\"submit\" class=\"button\"
365 onclick=\"return feedEditSave()\" value=\"".__('Save')."\">
366 <input type='submit' class='button'
367 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\"></div>";
368
369 print "</div>";
370
371 return;
372 }
373
374 if ($subop == "editSave") {
375
376 $feed_title = db_escape_string(trim($_POST["title"]));
377 $feed_link = db_escape_string(trim($_POST["feed_url"]));
378 $upd_intl = db_escape_string($_POST["update_interval"]);
379 $purge_intl = db_escape_string($_POST["purge_interval"]);
380 $feed_id = db_escape_string($_POST["id"]);
381 $cat_id = db_escape_string($_POST["cat_id"]);
382 $auth_login = db_escape_string(trim($_POST["auth_login"]));
383 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
384 $parent_feed = db_escape_string($_POST["parent_feed"]);
385 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
386 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
387 $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
388 $include_in_digest = checkbox_to_sql_bool(
389 db_escape_string($_POST["include_in_digest"]));
390 $cache_images = checkbox_to_sql_bool(
391 db_escape_string($_POST["cache_images"]));
392 $update_method = (int) db_escape_string($_POST["update_method"]);
393
394 if (get_pref($link, 'ENABLE_FEED_CATS')) {
395 if ($cat_id && $cat_id != 0) {
396 $category_qpart = "cat_id = '$cat_id',";
397 $category_qpart_nocomma = "cat_id = '$cat_id'";
398 } else {
399 $category_qpart = 'cat_id = NULL,';
400 $category_qpart_nocomma = 'cat_id = NULL';
401 }
402 } else {
403 $category_qpart = "";
404 $category_qpart_nocomma = "";
405 }
406
407 if ($parent_feed && $parent_feed != 0) {
408 $parent_qpart = "parent_feed = '$parent_feed'";
409 } else {
410 $parent_qpart = 'parent_feed = NULL';
411 }
412
413 if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
414 $cache_images_qpart = "cache_images = $cache_images,";
415 } else {
416 $cache_images_qpart = "";
417 }
418
419 $result = db_query($link, "UPDATE ttrss_feeds SET
420 $category_qpart $parent_qpart,
421 title = '$feed_title', feed_url = '$feed_link',
422 update_interval = '$upd_intl',
423 purge_interval = '$purge_intl',
424 auth_login = '$auth_login',
425 auth_pass = '$auth_pass',
426 private = $private,
427 rtl_content = $rtl_content,
428 hidden = $hidden,
429 $cache_images_qpart
430 include_in_digest = $include_in_digest,
431 update_method = '$update_method'
432 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
433
434 if (get_pref($link, 'ENABLE_FEED_CATS')) {
435 # update linked feed categories
436 $result = db_query($link, "UPDATE ttrss_feeds SET
437 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
438 owner_uid = " . $_SESSION["uid"]);
439 }
440 }
441
442 if ($subop == "remove") {
443
444 if (!WEB_DEMO_MODE) {
445
446 $ids = split(",", db_escape_string($_GET["ids"]));
447
448 foreach ($ids as $id) {
449
450 if ($id > 0) {
451
452 db_query($link, "DELETE FROM ttrss_feeds
453 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
454
455 $icons_dir = ICONS_DIR;
456
457 if (file_exists($icons_dir . "/$id.ico")) {
458 unlink($icons_dir . "/$id.ico");
459 }
460 } else if ($id < -10) {
461
462 $label_id = -$id - 11;
463
464 db_query($link, "DELETE FROM ttrss_labels
465 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
466 }
467 }
468 }
469 }
470
471 if ($subop == "clear") {
472 $id = db_escape_string($_GET["id"]);
473 clear_feed_articles($link, $id);
474 }
475
476 if ($subop == "add") {
477
478 if (!WEB_DEMO_MODE) {
479
480 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
481 $cat_id = db_escape_string($_REQUEST["cat_id"]);
482 $p_from = db_escape_string($_REQUEST["from"]);
483
484 /* only read authentication information from POST */
485
486 $auth_login = db_escape_string(trim($_POST["auth_login"]));
487 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
488
489 if ($p_from != 'tt-rss') {
490 print "<html>
491 <head>
492 <title>Tiny Tiny RSS - Subscribe to feed...</title>
493 <link rel=\"stylesheet\" type=\"text/css\" href=\"quicksub.css\">
494 </head>
495 <body>
496 <img class=\"logo\" src=\"images/ttrss_logo.png\"
497 alt=\"Tiny Tiny RSS\"/>
498 <h1>Subscribe to feed...</h1>
499 <div class=\"content\">";
500 }
501
502 if (subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass)) {
503 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
504 } else {
505 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
506 }
507
508 if ($p_from != 'tt-rss') {
509 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
510
511
512 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
513
514 print "<p><a href='$tt_uri'>Return to Tiny Tiny RSS</a> |";
515
516 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
517 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
518
519 $feed_id = db_fetch_result($result, 0, "id");
520
521 if ($feed_id) {
522 print "<a href='$tp_uri?tab=feedConfig&subop=editFeed:$feed_id'>
523 Edit subscription options</a> | ";
524 }
525
526 print "<a href='javascript:window.close()'>Close this window</a>.</p>";
527
528 print "</div></body></html>";
529 return;
530 }
531
532 }
533 }
534
535 if ($subop == "categorize") {
536
537 if (!WEB_DEMO_MODE) {
538
539 $ids = split(",", db_escape_string($_GET["ids"]));
540
541 $cat_id = db_escape_string($_GET["cat_id"]);
542
543 if ($cat_id == 0) {
544 $cat_id_qpart = 'NULL';
545 } else {
546 $cat_id_qpart = "'$cat_id'";
547 }
548
549 db_query($link, "BEGIN");
550
551 foreach ($ids as $id) {
552
553 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
554 WHERE id = '$id' AND parent_feed IS NULL
555 AND owner_uid = " . $_SESSION["uid"]);
556
557 # update linked feed categories
558 db_query($link, "UPDATE ttrss_feeds SET
559 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
560 owner_uid = " . $_SESSION["uid"]);
561
562 }
563
564 db_query($link, "COMMIT");
565 }
566
567 }
568
569 if ($subop == "editCats") {
570
571 $action = $_REQUEST["action"];
572
573 if ($action == "save") {
574
575 $cat_title = db_escape_string(trim($_REQUEST["value"]));
576 $cat_id = db_escape_string($_GET["cid"]);
577
578 $result = db_query($link, "UPDATE ttrss_feed_categories SET
579 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
580
581 print $_REQUEST["value"];
582
583 return;
584
585 }
586
587 print "<div id=\"infoBoxTitle\">".__('Category editor')."</div>";
588
589 print "<div class=\"infoBoxContents\">";
590
591
592 if ($action == "add") {
593
594 if (!WEB_DEMO_MODE) {
595
596 $feed_cat = db_escape_string(trim($_GET["cat"]));
597
598 $result = db_query($link,
599 "SELECT id FROM ttrss_feed_categories
600 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
601
602 if (db_num_rows($result) == 0) {
603
604 $result = db_query($link,
605 "INSERT INTO ttrss_feed_categories (owner_uid,title)
606 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
607
608 } else {
609
610 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.",
611 $feed_cat));
612 }
613
614 }
615 }
616
617 if ($action == "remove") {
618
619 if (!WEB_DEMO_MODE) {
620
621 $ids = split(",", db_escape_string($_GET["ids"]));
622
623 foreach ($ids as $id) {
624
625 db_query($link, "BEGIN");
626
627 $result = db_query($link,
628 "SELECT count(id) as num_feeds FROM ttrss_feeds
629 WHERE cat_id = '$id'");
630
631 $num_feeds = db_fetch_result($result, 0, "num_feeds");
632
633 if ($num_feeds == 0) {
634 db_query($link, "DELETE FROM ttrss_feed_categories
635 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
636 } else {
637
638 print format_warning(__("Unable to delete non empty feed categories."));
639
640 }
641
642 db_query($link, "COMMIT");
643 }
644 }
645 }
646
647 print "<div class=\"prefGenericAddBox\">
648 <input id=\"fadd_cat\"
649 onkeypress=\"return filterCR(event, addFeedCat)\"
650 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
651 onchange=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
652 size=\"40\">&nbsp;
653 <input
654 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
655 onclick=\"javascript:addFeedCat()\" value=\"".__('Create category')."\"></div>";
656
657 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
658 WHERE owner_uid = ".$_SESSION["uid"]."
659 ORDER BY title");
660
661 print "<p>";
662
663 if (db_num_rows($result) != 0) {
664
665 print "<table width=\"100%\" class=\"prefFeedCatList\"
666 cellspacing=\"0\">";
667
668 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
669 ".__('Select:')."
670 <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
671 <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>
672 </td></tr>";
673
674 print "</table>";
675
676 print "<div class=\"prefFeedCatHolder\">";
677
678 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
679
680 print "<table width=\"100%\" class=\"prefFeedCatList\"
681 cellspacing=\"0\" id=\"prefFeedCatList\">";
682
683 $lnum = 0;
684
685 while ($line = db_fetch_assoc($result)) {
686
687 $class = ($lnum % 2) ? "even" : "odd";
688
689 $cat_id = $line["id"];
690 $this_row_id = "id=\"FCATR-$cat_id\"";
691
692 print "<tr class=\"$class\" $this_row_id>";
693
694 $edit_title = htmlspecialchars($line["title"]);
695
696 print "<td width='5%' align='center'><input
697 onclick='toggleSelectPrefRow(this, \"fcat\");'
698 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
699
700 print "<td><span id=\"FCATT-$cat_id\">" .
701 $edit_title . "</span></td>";
702
703 print "</tr>";
704
705 ++$lnum;
706 }
707
708 print "</table>";
709
710 print "</form>";
711
712 print "</div>";
713
714 } else {
715 print "<p>".__('No feed categories defined.')."</p>";
716 }
717
718 print "<div style='float : right'>
719 <input type='submit' class='button'
720 onclick=\"selectTab('feedConfig')\" value=\"".__('Close this window')."\"></div>";
721
722 print "<div id=\"catOpToolbar\">";
723
724 print "
725 <input type=\"submit\" class=\"button\" disabled=\"true\"
726 onclick=\"return removeSelectedFeedCats()\" value=\"".__('Remove')."\">";
727
728 print "</div>";
729
730 print "</div>";
731
732 return;
733
734 }
735
736 if ($quiet) return;
737
738 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
739
740 $result = db_query($link, "SELECT COUNT(id) AS num_errors
741 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
742
743 $num_errors = db_fetch_result($result, 0, "num_errors");
744
745 if ($num_errors > 0) {
746
747 print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
748 __('Some feeds have update errors (click for details)')."</a>");
749 }
750
751 $feed_search = db_escape_string($_GET["search"]);
752
753 if (array_key_exists("search", $_GET)) {
754 $_SESSION["prefs_feed_search"] = $feed_search;
755 } else {
756 $feed_search = $_SESSION["prefs_feed_search"];
757 }
758
759 print "<div class=\"feedEditSearch\">
760 <input id=\"feed_search\" size=\"20\" type=\"search\"
761 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
762 <input type=\"submit\" class=\"button\"
763 onclick=\"javascript:updateFeedList()\" value=\"".__('Search')."\">
764 </div>";
765
766 /* print "<input id=\"fadd_link\"
767 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
768 onchange=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
769 size=\"40\">
770 <input type=\"submit\" class=\"button\"
771 disabled=\"true\" id=\"fadd_submit_btn\"
772 onclick=\"addFeed()\" value=\"".__('Subscribe')."\">"; */
773
774 print "<input onclick=\"javascript:displayDlg('quickAddFeed')\"
775 type=\"submit\" id=\"subscribe_to_feed_btn\"
776 class=\"button\" value=\"".__('Subscribe to feed')."\">";
777
778 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
779 print " <input type=\"submit\" class=\"button\"
780 id=\"top25_feeds_btn\"
781 onclick=\"javascript:browseFeeds()\" value=\"".__('Top 25')."\">";
782 }
783
784 $feeds_sort = db_escape_string($_GET["sort"]);
785
786 if (!$feeds_sort || $feeds_sort == "undefined") {
787 $feeds_sort = $_SESSION["pref_sort_feeds"];
788 if (!$feeds_sort) $feeds_sort = "title";
789 }
790
791 $_SESSION["pref_sort_feeds"] = $feeds_sort;
792
793 if ($feed_search) {
794 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
795 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
796 } else {
797 $search_qpart = "";
798 }
799
800 $show_last_article_info = false;
801 $show_last_article_checked = "";
802 $show_last_article_qpart = "";
803
804 if ($_GET["slat"] == "true") {
805 $show_last_article_info = true;
806 $show_last_article_checked = "checked";
807 $show_last_article_qpart = ", (SELECT SUBSTRING(MAX(updated),1,16) FROM ttrss_user_entries,
808 ttrss_entries WHERE ref_id = ttrss_entries.id
809 AND feed_id = F1.id) AS last_article";
810 } else if ($feeds_sort == "last_article") {
811 $feeds_sort = "title";
812 }
813
814 if (get_pref($link, 'ENABLE_FEED_CATS')) {
815 $order_by_qpart = "category,$feeds_sort,title";
816 } else {
817 $order_by_qpart = "$feeds_sort,title";
818 }
819
820 $result = db_query($link, "SELECT
821 F1.id,
822 F1.title,
823 F1.feed_url,
824 substring(F1.last_updated,1,16) AS last_updated,
825 F1.parent_feed,
826 F1.update_interval,
827 F1.last_error,
828 F1.purge_interval,
829 F1.cat_id,
830 F2.title AS parent_title,
831 C1.title AS category,
832 F1.hidden,
833 F1.include_in_digest
834 $show_last_article_qpart
835 FROM
836 ttrss_feeds AS F1
837 LEFT JOIN ttrss_feeds AS F2
838 ON (F1.parent_feed = F2.id)
839 LEFT JOIN ttrss_feed_categories AS C1
840 ON (F1.cat_id = C1.id)
841 WHERE
842 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
843 ORDER by $order_by_qpart");
844
845 if (db_num_rows($result) != 0) {
846
847 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
848
849 print "<p><table width=\"100%\" cellspacing=\"0\"
850 class=\"prefFeedList\" id=\"prefFeedList\">";
851 print "<tr><td class=\"selectPrompt\" colspan=\"8\">".
852 "<div style='float : right'>".
853 "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'
854 $show_last_article_checked><label
855 for='show_last_article_times'>".__('Show last article times')."</label></div>".
856 __('Select:')."
857 <a href=\"javascript:selectPrefRows('feed', true)\">".__('All')."</a>,
858 <a href=\"javascript:selectPrefRows('feed', false)\">".__('None')."</a>
859 </td</tr>";
860
861 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
862 print "<tr class=\"title\">
863 <td width='5%' align='center'>&nbsp;</td>";
864
865 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
866 print "<td width='3%'>&nbsp;</td>";
867 }
868
869 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
870
871 if ($show_last_article_info) {
872 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
873 }
874
875 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
876 }
877
878 $lnum = 0;
879
880 $cur_cat_id = -1;
881
882 while ($line = db_fetch_assoc($result)) {
883
884 $feed_id = $line["id"];
885 $cat_id = $line["cat_id"];
886
887 $edit_title = htmlspecialchars($line["title"]);
888 $edit_cat = htmlspecialchars($line["category"]);
889
890 $hidden = sql_bool_to_bool($line["hidden"]);
891
892 $last_error = $line["last_error"];
893
894 if (!$edit_cat) $edit_cat = __("Uncategorized");
895
896 $last_updated = $line["last_updated"];
897
898 if (!$last_updated) {
899 $last_updated = "&mdash;";
900 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
901 $last_updated = smart_date_time(strtotime($last_updated));
902 } else {
903 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
904 $last_updated = date($short_date, strtotime($last_updated));
905 }
906
907 $last_article = $line["last_article"];
908
909 if (!$last_article) {
910 $last_article = "&mdash;";
911 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
912 $last_article = smart_date_time(strtotime($last_article));
913 } else {
914 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
915 $last_article = date($short_date, strtotime($last_article));
916 }
917
918 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
919 $lnum = 0;
920
921 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
922
923 print "<tr class=\"title\">
924 <td width='5%'>&nbsp;</td>";
925
926 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
927 print "<td width='3%'>&nbsp;</td>";
928 }
929
930 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
931
932 if ($show_last_article_info) {
933 print "<td width='20%' align='right'>
934 <a href=\"javascript:updateFeedList('last_article')\">".__('Last&nbsp;Article')."</a></td>";
935 }
936
937 print "<td width='20%' align='right'>
938 <a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
939
940 $cur_cat_id = $cat_id;
941 }
942
943 $class = ($lnum % 2) ? "even" : "odd";
944 $this_row_id = "id=\"FEEDR-$feed_id\"";
945
946 print "<tr class=\"$class\" $this_row_id>";
947
948 $icon_file = ICONS_DIR . "/$feed_id.ico";
949
950 if (file_exists($icon_file) && filesize($icon_file) > 0) {
951 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
952 } else {
953 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
954 }
955
956 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
957 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
958
959 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
960 print "<td class='feedIcon'>$feed_icon</td>";
961 }
962
963 if ($hidden) {
964 $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
965 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
966 $last_article = "<span class=\"insensitive\">$last_article</span>";
967 }
968
969 if ($last_error) {
970 $edit_title = "<span class=\"feed_error\">$edit_title</span>";
971 $last_updated = "<span class=\"feed_error\">$last_updated</span>";
972 $last_article = "<span class=\"feed_error\">$last_article</span>";
973 }
974
975 $parent_title = $line["parent_title"];
976 if ($parent_title) {
977 $parent_title = "<span class='groupPrompt'>(linked to
978 $parent_title)</span>";
979 }
980
981 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
982 "$edit_title $parent_title" . "</a></td>";
983
984 if ($show_last_article_info) {
985 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
986 "$last_article</a></td>";
987 }
988
989 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
990 "$last_updated</a></td>";
991
992 print "</tr>";
993
994 ++$lnum;
995 }
996
997 print "</table>";
998
999 print "<p>";
1000
1001 print "<div id=\"feedOpToolbar\">";
1002
1003 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1004
1005 print __('Selection:') . " ";
1006
1007 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1008
1009 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1010 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"".
1011 __('Recategorize')."\">";
1012 }
1013
1014 print "</div>";
1015
1016 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1017 <option value=\"facDefault\" selected>".__('Actions...')."</option>
1018 <option disabled>--------</option>
1019 <option style=\"color : #5050aa\" disabled>".__('Selection:')."</option>
1020 <option value=\"facEdit\">&nbsp;&nbsp;".__('Edit')."</option>
1021 <option value=\"facPurge\">&nbsp;&nbsp;".__('Manual purge')."</option>
1022 <option value=\"facClear\">&nbsp;&nbsp;".__('Clear feed data')."</option>
1023 <option value=\"facUnsubscribe\">&nbsp;&nbsp;".__('Unsubscribe')."</option>";
1024
1025 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1026
1027 print "<option disabled>--------</option>
1028 <option style=\"color : #5050aa\" disabled>".__('Other:')."</option>
1029 <option value=\"facEditCats\">&nbsp;&nbsp;".__('Edit categories')."
1030 </option>";
1031 }
1032
1033 print "</select>";
1034
1035 /* print "<input type=\"submit\" class=\"button\" disabled=\"true\"
1036 onclick=\"javascript:editSelectedFeed()\" value=\"".__('Edit')."\">
1037 <input type=\"submit\" class=\"button\" disabled=\"true\"
1038 onclick=\"javascript:removeSelectedFeeds()\"
1039 value=\"".__('Unsubscribe')."\">"; */
1040
1041 // if (get_pref($link, 'ENABLE_FEED_CATS')) {
1042
1043 /* print " <input type=\"submit\" class=\"button\"
1044 onclick=\"javascript:editFeedCats()\" value=\"".
1045 __("Edit categories")."\">"; */
1046
1047 # print "&nbsp;|&nbsp;";
1048
1049 // }
1050 } else {
1051
1052 // print "<p>No feeds defined.</p>";
1053
1054 }
1055
1056 print "<h3>".__('OPML')."</h3>
1057
1058 <div style='float : left'>
1059 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1060 ".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1061 <input type=\"hidden\" name=\"op\" value=\"Import\">
1062 <input class=\"button\" onclick=\"return validateOpmlImport();\"
1063 type=\"submit\" value=\"".__('Import')."\">
1064 </form></div>";
1065
1066 print "&nbsp;";
1067
1068 print "<input type=\"submit\"
1069 class=\"button\" onclick=\"gotoExportOpml()\"
1070 value=\"".__('Export OPML')."\">";
1071
1072
1073 print "<h3>" . __("Firefox Integration") . "</h3>";
1074
1075 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.');
1076 print "</p><p class=\"small\"> <a href='javascript:window.navigator.registerContentHandler(" .
1077 "\"application/vnd.mozilla.maybe.feed\", " .
1078 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1079 __('Click here to register this site as a feed reader.') . "</a></p>";
1080
1081
1082 print "<h3>".__("Published articles")."</h3>";
1083
1084 if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
1085 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
1086 }
1087
1088 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the address specified below.')."</p>";
1089
1090 $url_path = article_publish_url($link);
1091
1092 print "<p class=\"small\"><a id=\"pubGenAddress\" target=\"_new\" href=\"$url_path\">$url_path</a></p>";
1093
1094 print "<p><input type=\"submit\" onclick=\"return pubRegenKey()\" class=\"button\"
1095 value=\"".__('Generate another address')."\"></p>";
1096
1097 }
1098 ?>