3 function batch_edit_cbox($elem, $label = false) {
4 print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
5 onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">";
8 function module_pref_feeds($link) {
10 global $update_intervals;
11 global $purge_intervals;
12 global $update_methods;
14 $subop = $_REQUEST["subop"];
15 $quiet = $_REQUEST["quiet"];
17 if ($subop == "massSubscribe") {
18 $ids = split(",", db_escape_string($_GET["ids"]));
20 $subscribed = array();
22 foreach ($ids as $id) {
23 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
26 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
27 $title = db_escape_string(db_fetch_result($result, 0, "title"));
29 $title_orig = db_fetch_result($result, 0, "title");
31 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
32 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
34 if (db_num_rows($result) == 0) {
35 $result = db_query($link,
36 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
37 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
39 array_push($subscribed, $title_orig);
43 if (count($subscribed) > 0) {
44 $msg = "<b>".__('Subscribed to feeds:')."</b>".
45 "<ul class=\"nomarks\">";
47 foreach ($subscribed as $title) {
48 $msg .= "<li>$title</li>";
52 print format_notice($msg);
56 if ($subop == "browse") {
58 if (!ENABLE_FEED_BROWSER
) {
59 print __("Feed browser is administratively disabled.");
63 print "<div id=\"infoBoxTitle\">".__('Feed Browser')."</div>";
65 print "<div class=\"infoBoxContents\">";
67 $browser_search = db_escape_string($_GET["search"]);
69 //print "<p>".__("Showing top 25 registered feeds, sorted by popularity:")."</p>";
72 <div style='float : right'>
73 <input id=\"feed_browser_search\" size=\"20\" type=\"search\"
74 onfocus=\"javascript:disableHotkeys();\"
75 onblur=\"javascript:enableHotkeys();\"
76 onchange=\"javascript:updateFeedBrowser()\" value=\"$browser_search\">
77 <input type=\"submit\" class=\"button\"
78 onclick=\"javascript:updateFeedBrowser()\" value=\"".__('Search')."\">
81 print __('Top')." <select id=\"feed_browser_limit\">";
83 foreach (array(25, 50, 100, 200) as $l) {
84 $issel = ($l == $limit) ?
"selected" : "";
85 print "<option $issel>$l</option>";
89 <input type=\"submit\" class=\"button\"
90 onclick=\"updateFeedBrowser()\" value=\"".__('Show')."\">";
94 $owner_uid = $_SESSION["uid"];
96 print "<ul class='browseFeedList' id='browseFeedList'>";
97 $subscribe_btn_disabled = print_feed_browser($link, $search, 25) == 0 ?
"disabled" : "";
100 print "<div align='center'>
101 <input type=\"submit\" class=\"button\" id=\"feed_browser_subscribe\"
102 $subscribe_btn_disabled
103 onclick=\"feedBrowserSubscribe()\" value=\"".__('Subscribe')."\">
104 <input type='submit' class='button'
105 onclick=\"closeInfoBox()\" value=\"".__('Cancel')."\"></div>";
111 if ($subop == "editfeed") {
112 $feed_id = db_escape_string($_REQUEST["id"]);
114 $result = db_query($link,
115 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
116 owner_uid = " . $_SESSION["uid"]);
118 $title = htmlspecialchars(db_fetch_result($result,
121 $icon_file = ICONS_DIR
. "/$feed_id.ico";
123 if (file_exists($icon_file) && filesize($icon_file) > 0) {
124 $feed_icon = "<img width=\"16\" height=\"16\"
125 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
130 print "<div id=\"infoBoxTitle\">".__('Feed Editor')."</div>";
132 print "<div class=\"infoBoxContents\">";
134 print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
136 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
137 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
138 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
140 print "<div class=\"dlgSec\">".__("Feed")."</div>";
141 print "<div class=\"dlgSecCont\">";
145 print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
146 name=\"title\" value=\"$title\">";
150 $feed_url = db_fetch_result($result, 0, "feed_url");
151 $feed_url = htmlspecialchars(db_fetch_result($result,
156 print __('URL:') . " ";
157 print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
158 name=\"feed_url\" value=\"$feed_url\">";
162 if (get_pref($link, 'ENABLE_FEED_CATS')) {
164 $cat_id = db_fetch_result($result, 0, "cat_id");
168 print __('Place in category:') . " ";
170 $parent_feed = db_fetch_result($result, 0, "parent_feed");
172 if (sprintf("%d", $parent_feed) > 0) {
173 $disabled = "disabled";
178 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
185 print __('Link to feed:') . " ";
187 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
188 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
190 $linked_count = db_fetch_result($tmp_result, 0, "count");
192 $parent_feed = db_fetch_result($result, 0, "parent_feed");
194 if ($linked_count > 0) {
195 $disabled = "disabled";
200 print "<select $disabled name=\"parent_feed\">";
202 print "<option value=\"0\">".__('Not linked')."</option>";
204 if (get_pref($link, 'ENABLE_FEED_CATS')) {
206 $cat_qpart = "AND cat_id = '$cat_id'";
208 $cat_qpart = "AND cat_id IS NULL";
212 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
213 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
214 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
215 $cat_qpart ORDER BY title");
217 if (db_num_rows($tmp_result) > 0) {
218 print "<option disabled>--------</option>";
221 while ($tmp_line = db_fetch_assoc($tmp_result)) {
222 if ($tmp_line["id"] == $parent_feed) {
223 $is_selected = "selected";
227 printf("<option $is_selected value='%d'>%s</option>",
228 $tmp_line["id"], $tmp_line["title"]);
236 print "<div class=\"dlgSec\">".__("Update")."</div>";
237 print "<div class=\"dlgSecCont\">";
239 /* Update Interval */
241 $update_interval = db_fetch_result($result, 0, "update_interval");
243 print_select_hash("update_interval", $update_interval, $update_intervals);
247 if (ALLOW_SELECT_UPDATE_METHOD
) {
248 $update_method = db_fetch_result($result, 0, "update_method");
250 print " " . __('using') . " ";
251 print_select_hash("update_method", $update_method, $update_methods);
254 $purge_interval = db_fetch_result($result, 0, "purge_interval");
256 if (FORCE_ARTICLE_PURGE
== 0) {
262 print __('Article purging:') . " ";
264 print_select_hash("purge_interval", $purge_interval, $purge_intervals);
267 print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
272 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
273 print "<div class=\"dlgSecCont\">";
275 $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
279 print "<tr><td>" . __('Login:') . "</td><td>";
281 print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
282 name=\"auth_login\" value=\"$auth_login\">";
284 print "</tr><tr><td>" . __("Password:") . "</td><td>";
286 $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
288 print "<input size=\"20\" type=\"password\" name=\"auth_pass\"
289 onkeypress=\"return filterCR(event, feedEditSave)\"
290 value=\"$auth_pass\">";
292 print "</td></tr></table>";
295 print "<div class=\"dlgSec\">".__("Options")."</div>";
296 print "<div class=\"dlgSecCont\">";
298 print "<div style=\"line-height : 100%\">";
300 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
303 $checked = "checked";
308 print "<input type=\"checkbox\" name=\"private\" id=\"private\"
309 $checked> <label for=\"private\">".__('Hide from "Other Feeds"')."</label>";
311 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
314 $checked = "checked";
319 print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
320 $checked> <label for=\"rtl_content\">".__('Right-to-left content')."</label>";
322 $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
325 $checked = "checked";
330 print "<br/><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
331 $checked> <label for=\"hidden\">".__('Hide from my feed list')."</label>";
333 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
335 if ($include_in_digest) {
336 $checked = "checked";
341 print "<br/><input type=\"checkbox\" id=\"include_in_digest\"
342 name=\"include_in_digest\"
343 $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
346 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
348 if ($always_display_enclosures) {
349 $checked = "checked";
354 print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\"
355 name=\"always_display_enclosures\"
356 $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
359 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
362 $checked = "checked";
367 if (ENABLE_SIMPLEPIE
&& SIMPLEPIE_CACHE_IMAGES
) {
371 $disabled = "disabled";
372 $label_class = "class='insensitive'";
375 print "<br/><input type=\"checkbox\" id=\"cache_images\"
376 name=\"cache_images\" $disabled
377 $checked> <label $label_class for=\"cache_images\">".
378 __('Cache images locally')."</label>";
386 $title = htmlspecialchars($title, ENT_QUOTES
);
388 print "<div class='dlgButtons'>
389 <div style=\"float : left\">
390 <input type='submit' class='button'
391 onclick='return unsubscribeFeed($feed_id, \"$title\")' value=\"".__('Unsubscribe')."\">
393 <input type=\"submit\" class=\"button\"
394 onclick=\"return feedEditSave()\" value=\"".__('Save')."\">
395 <input type='submit' class='button'
396 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
402 if ($subop == "editfeeds") {
404 $feed_ids = db_escape_string($_REQUEST["ids"]);
406 print "<div id=\"infoBoxTitle\">".__('Multiple Feed Editor')."</div>";
408 print "<div class=\"infoBoxContents\">";
410 print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";
412 print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
413 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
414 print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
416 print "<div class=\"dlgSec\">".__("Feed")."</div>";
417 print "<div class=\"dlgSecCont\">";
421 print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
422 name=\"title\" value=\"$title\">";
424 batch_edit_cbox("title");
430 print __('URL:') . " ";
431 print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
432 name=\"feed_url\" value=\"$feed_url\">";
434 batch_edit_cbox("feed_url");
438 if (get_pref($link, 'ENABLE_FEED_CATS')) {
442 print __('Place in category:') . " ";
444 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
446 batch_edit_cbox("cat_id");
452 print "<div class=\"dlgSec\">".__("Update")."</div>";
453 print "<div class=\"dlgSecCont\">";
455 /* Update Interval */
457 print_select_hash("update_interval", $update_interval, $update_intervals,
460 batch_edit_cbox("update_interval");
464 if (ALLOW_SELECT_UPDATE_METHOD
) {
465 print " " . __('using') . " ";
466 print_select_hash("update_method", $update_method, $update_methods,
468 batch_edit_cbox("update_method");
473 if (FORCE_ARTICLE_PURGE
!= 0) {
477 print __('Article purging:') . " ";
479 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
482 batch_edit_cbox("purge_interval");
486 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
487 print "<div class=\"dlgSecCont\">";
489 print __('Login:') . " ";
490 print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
491 name=\"auth_login\" value=\"$auth_login\">";
493 batch_edit_cbox("auth_login");
495 print " " . __("Password:") . " ";
497 print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\"
498 onkeypress=\"return filterCR(event, feedEditSave)\"
499 value=\"$auth_pass\">";
501 batch_edit_cbox("auth_pass");
504 print "<div class=\"dlgSec\">".__("Options")."</div>";
505 print "<div class=\"dlgSecCont\">";
507 print "<div style=\"line-height : 100%\">";
509 print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\"
510 $checked> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from "Other Feeds"')."</label>";
512 print " "; batch_edit_cbox("private", "private_l");
514 print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
515 $checked> <label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
517 print " "; batch_edit_cbox("rtl_content", "rtl_content_l");
519 print "<br/><input disabled type=\"checkbox\" id=\"hidden\" name=\"hidden\"
520 $checked> <label class='insensitive' id=\"hidden_l\" for=\"hidden\">".__('Hide from my feed list')."</label>";
522 print " "; batch_edit_cbox("hidden", "hidden_l");
524 print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\"
525 name=\"include_in_digest\"
526 $checked> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
528 print " "; batch_edit_cbox("include_in_digest", "include_in_digest_l");
530 print "<br/><input disabled type=\"checkbox\" id=\"cache_images\"
531 name=\"cache_images\"
532 $checked> <label class='insensitive' id=\"cache_images_l\"
533 for=\"cache_images\">".
534 __('Cache images locally')."</label>";
537 if (ENABLE_SIMPLEPIE
&& SIMPLEPIE_CACHE_IMAGES
) {
538 print " "; batch_edit_cbox("cache_images", "cache_images_l");
546 print "<div class='dlgButtons'>
547 <input type=\"submit\" class=\"button\"
548 onclick=\"return feedsEditSave()\" value=\"".__('Save')."\">
549 <input type='submit' class='button'
550 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
556 if ($subop == "editSave" ||
$subop == "batchEditSave") {
558 $feed_title = db_escape_string(trim($_POST["title"]));
559 $feed_link = db_escape_string(trim($_POST["feed_url"]));
560 $upd_intl = db_escape_string($_POST["update_interval"]);
561 $purge_intl = db_escape_string($_POST["purge_interval"]);
562 $feed_id = db_escape_string($_POST["id"]); /* editSave */
563 $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
564 $cat_id = db_escape_string($_POST["cat_id"]);
565 $auth_login = db_escape_string(trim($_POST["auth_login"]));
566 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
567 $parent_feed = db_escape_string($_POST["parent_feed"]);
568 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
569 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
570 $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
571 $include_in_digest = checkbox_to_sql_bool(
572 db_escape_string($_POST["include_in_digest"]));
573 $cache_images = checkbox_to_sql_bool(
574 db_escape_string($_POST["cache_images"]));
575 $update_method = (int) db_escape_string($_POST["update_method"]);
577 $always_display_enclosures = checkbox_to_sql_bool(
578 db_escape_string($_POST["always_display_enclosures"]));
580 if (get_pref($link, 'ENABLE_FEED_CATS')) {
581 if ($cat_id && $cat_id != 0) {
582 $category_qpart = "cat_id = '$cat_id',";
583 $category_qpart_nocomma = "cat_id = '$cat_id'";
585 $category_qpart = 'cat_id = NULL,';
586 $category_qpart_nocomma = 'cat_id = NULL';
589 $category_qpart = "";
590 $category_qpart_nocomma = "";
593 if ($parent_feed && $parent_feed != 0) {
594 $parent_qpart = "parent_feed = '$parent_feed'";
596 $parent_qpart = 'parent_feed = NULL';
599 if (ENABLE_SIMPLEPIE
&& SIMPLEPIE_CACHE_IMAGES
) {
600 $cache_images_qpart = "cache_images = $cache_images,";
602 $cache_images_qpart = "";
605 if ($subop == "editSave") {
607 $result = db_query($link, "UPDATE ttrss_feeds SET
608 $category_qpart $parent_qpart,
609 title = '$feed_title', feed_url = '$feed_link',
610 update_interval = '$upd_intl',
611 purge_interval = '$purge_intl',
612 auth_login = '$auth_login',
613 auth_pass = '$auth_pass',
615 rtl_content = $rtl_content,
618 include_in_digest = $include_in_digest,
619 always_display_enclosures = $always_display_enclosures,
620 update_method = '$update_method'
621 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
623 if (get_pref($link, 'ENABLE_FEED_CATS')) {
624 # update linked feed categories
625 $result = db_query($link, "UPDATE ttrss_feeds SET
626 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
627 owner_uid = " . $_SESSION["uid"]);
629 } else if ($subop == "batchEditSave") {
630 $feed_data = array();
632 foreach (array_keys($_POST) as $k) {
633 if ($k != "op" && $k != "subop" && $k != "ids") {
634 $feed_data[$k] = $_POST[$k];
638 db_query($link, "BEGIN");
640 foreach (array_keys($feed_data) as $k) {
646 $qpart = "title = '$feed_title'";
650 $qpart = "feed_url = '$feed_link'";
653 case "update_interval":
654 $qpart = "update_interval = '$upd_intl'";
657 case "purge_interval":
658 $qpart = "purge_interval = '$purge_intl'";
662 $qpart = "auth_login = '$auth_login'";
666 $qpart = "auth_pass = '$auth_pass'";
670 $qpart = "private = '$private'";
674 $qpart = "hidden = '$hidden'";
677 case "include_in_digest":
678 $qpart = "include_in_digest = '$include_in_digest'";
682 $qpart = "cache_images = '$cache_images'";
686 $qpart = "rtl_content = '$rtl_content'";
689 case "update_method":
690 $qpart = "update_method = '$update_method'";
694 $qpart = $category_qpart_nocomma;
701 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
702 AND owner_uid = " . $_SESSION["uid"]);
707 db_query($link, "COMMIT");
712 if ($subop == "remove") {
714 $ids = split(",", db_escape_string($_GET["ids"]));
716 foreach ($ids as $id) {
720 db_query($link, "DELETE FROM ttrss_feeds
721 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
723 $icons_dir = ICONS_DIR
;
725 if (file_exists($icons_dir . "/$id.ico")) {
726 unlink($icons_dir . "/$id.ico");
729 ccache_remove($link, $id, $_SESSION["uid"]);
732 label_remove($link, -11-$id, $_SESSION["uid"]);
733 ccache_remove($link, -11-$id, $_SESSION["uid"]);
738 if ($subop == "clear") {
739 $id = db_escape_string($_GET["id"]);
740 clear_feed_articles($link, $id);
743 if ($subop == "rescore") {
744 $ids = split(",", db_escape_string($_GET["ids"]));
746 foreach ($ids as $id) {
748 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
750 $result = db_query($link, "SELECT title, content, link, ref_id FROM
751 ttrss_user_entries, ttrss_entries
752 WHERE ref_id = id AND feed_id = '$id' AND
753 owner_uid = " .$_SESSION['uid']."
758 while ($line = db_fetch_assoc($result)) {
760 $article_filters = get_article_filters($filters, $line['title'],
761 $line['content'], $line['link']);
763 $new_score = calculate_article_score($article_filters);
765 if (!$scores[$new_score]) $scores[$new_score] = array();
767 array_push($scores[$new_score], $line['ref_id']);
770 foreach (array_keys($scores) as $s) {
772 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
774 ref_id IN (" . join(',', $scores[$s]) . ")");
775 } else if ($s < -500) {
776 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
778 ref_id IN (" . join(',', $scores[$s]) . ")");
780 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
781 ref_id IN (" . join(',', $scores[$s]) . ")");
786 print __("All done.");
790 if ($subop == "rescoreAll") {
792 $result = db_query($link,
793 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
795 while ($feed_line = db_fetch_assoc($result)) {
797 $id = $feed_line["id"];
799 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
801 $tmp_result = db_query($link, "SELECT title, content, link, ref_id FROM
802 ttrss_user_entries, ttrss_entries
803 WHERE ref_id = id AND feed_id = '$id' AND
804 owner_uid = " .$_SESSION['uid']."
809 while ($line = db_fetch_assoc($tmp_result)) {
811 $article_filters = get_article_filters($filters, $line['title'],
812 $line['content'], $line['link']);
814 $new_score = calculate_article_score($article_filters);
816 if (!$scores[$new_score]) $scores[$new_score] = array();
818 array_push($scores[$new_score], $line['ref_id']);
821 foreach (array_keys($scores) as $s) {
823 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
825 ref_id IN (" . join(',', $scores[$s]) . ")");
827 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
828 ref_id IN (" . join(',', $scores[$s]) . ")");
833 print __("All done.");
837 if ($subop == "add") {
839 if (!WEB_DEMO_MODE
) {
841 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
842 $cat_id = db_escape_string($_REQUEST["cat_id"]);
843 $p_from = db_escape_string($_REQUEST["from"]);
845 /* only read authentication information from POST */
847 $auth_login = db_escape_string(trim($_POST["auth_login"]));
848 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
850 if ($p_from != 'tt-rss') {
853 <title>Tiny Tiny RSS</title>
854 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
857 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
858 alt=\"Tiny Tiny RSS\"/>
859 <h1>Subscribe to feed...</h1>";
862 if (subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass)) {
863 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
865 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
868 if ($p_from != 'tt-rss') {
869 $tt_uri = ($_SERVER['HTTPS'] != "on" ?
'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
872 $tp_uri = ($_SERVER['HTTPS'] != "on" ?
'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
874 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
875 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
877 $feed_id = db_fetch_result($result, 0, "id");
882 print "<form method=\"GET\" style='display: inline'
884 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
885 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
886 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
887 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
891 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
892 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
895 print "</body></html>";
902 if ($subop == "categorize") {
904 if (!WEB_DEMO_MODE
) {
906 $ids = split(",", db_escape_string($_GET["ids"]));
908 $cat_id = db_escape_string($_GET["cat_id"]);
911 $cat_id_qpart = 'NULL';
913 $cat_id_qpart = "'$cat_id'";
916 db_query($link, "BEGIN");
918 foreach ($ids as $id) {
920 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
921 WHERE id = '$id' AND parent_feed IS NULL
922 AND owner_uid = " . $_SESSION["uid"]);
924 # update linked feed categories
925 db_query($link, "UPDATE ttrss_feeds SET
926 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
927 owner_uid = " . $_SESSION["uid"]);
931 db_query($link, "COMMIT");
936 if ($subop == "editCats") {
938 $action = $_REQUEST["action"];
940 if ($action == "save") {
942 $cat_title = db_escape_string(trim($_REQUEST["value"]));
943 $cat_id = db_escape_string($_GET["cid"]);
945 db_query($link, "BEGIN");
947 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
948 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
950 if (db_num_rows($result) == 1) {
952 $old_title = db_fetch_result($result, 0, "title");
954 if ($cat_title != "") {
955 $result = db_query($link, "UPDATE ttrss_feed_categories SET
956 title = '$cat_title' WHERE id = '$cat_id' AND
957 owner_uid = ".$_SESSION["uid"]);
964 print $_REQUEST["value"];
967 db_query($link, "COMMIT");
973 print "<div id=\"infoBoxTitle\">".__('Category editor')."</div>";
975 print "<div class=\"infoBoxContents\">";
978 if ($action == "add") {
980 if (!WEB_DEMO_MODE
) {
982 $feed_cat = db_escape_string(trim($_GET["cat"]));
984 $result = db_query($link,
985 "SELECT id FROM ttrss_feed_categories
986 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
988 if (db_num_rows($result) == 0) {
990 $result = db_query($link,
991 "INSERT INTO ttrss_feed_categories (owner_uid,title)
992 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
996 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.",
1003 if ($action == "remove") {
1005 if (!WEB_DEMO_MODE
) {
1007 $ids = split(",", db_escape_string($_GET["ids"]));
1009 foreach ($ids as $id) {
1011 db_query($link, "BEGIN");
1013 $result = db_query($link,
1014 "SELECT count(id) as num_feeds FROM ttrss_feeds
1015 WHERE cat_id = '$id'");
1017 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1019 if ($num_feeds == 0) {
1020 db_query($link, "DELETE FROM ttrss_feed_categories
1021 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1023 ccache_remove($link, $id, $_SESSION["uid"], true);
1027 print format_warning(__("Unable to delete non empty feed categories."));
1031 db_query($link, "COMMIT");
1036 print "<div class=\"prefGenericAddBox\">
1037 <input id=\"fadd_cat\"
1038 onkeypress=\"return filterCR(event, addFeedCat)\"
1039 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1040 onchange=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1043 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
1044 onclick=\"javascript:addFeedCat()\" value=\"".__('Create category')."\"></div>";
1046 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1047 WHERE owner_uid = ".$_SESSION["uid"]."
1052 if (db_num_rows($result) != 0) {
1054 print "<table width=\"100%\" class=\"prefFeedCatList\"
1055 cellspacing=\"0\">";
1057 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1059 <a href=\"javascript:selectPrefRows('fcat', true)\">".__('All')."</a>,
1060 <a href=\"javascript:selectPrefRows('fcat', false)\">".__('None')."</a>
1065 print "<div class=\"prefFeedCatHolder\">";
1067 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1069 print "<table width=\"100%\" class=\"prefFeedCatList\"
1070 cellspacing=\"0\" id=\"prefFeedCatList\">";
1074 while ($line = db_fetch_assoc($result)) {
1076 $class = ($lnum %
2) ?
"even" : "odd";
1078 $cat_id = $line["id"];
1079 $this_row_id = "id=\"FCATR-$cat_id\"";
1081 print "<tr class=\"$class\" $this_row_id>";
1083 $edit_title = htmlspecialchars($line["title"]);
1085 print "<td width='5%' align='center'><input
1086 onclick='toggleSelectPrefRow(this, \"fcat\");'
1087 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
1089 print "<td><span id=\"FCATT-$cat_id\">" .
1090 $edit_title . "</span></td>";
1104 print "<p>".__('No feed categories defined.')."</p>";
1107 print "<div style='float : right'>
1108 <input type='submit' class='button'
1109 onclick=\"selectTab('feedConfig')\" value=\"".__('Close this window')."\"></div>";
1111 print "<div id=\"catOpToolbar\">";
1114 <input type=\"submit\" class=\"button\" disabled=\"true\"
1115 onclick=\"return removeSelectedFeedCats()\" value=\"".__('Remove')."\">";
1127 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
1129 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1130 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1132 $num_errors = db_fetch_result($result, 0, "num_errors");
1134 if ($num_errors > 0) {
1136 print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1137 __('Some feeds have update errors (click for details)')."</a>");
1140 $feed_search = db_escape_string($_GET["search"]);
1142 if (array_key_exists("search", $_GET)) {
1143 $_SESSION["prefs_feed_search"] = $feed_search;
1145 $feed_search = $_SESSION["prefs_feed_search"];
1148 print "<div class=\"feedEditSearch\">
1149 <input id=\"feed_search\" size=\"20\" type=\"search\"
1150 onfocus=\"javascript:disableHotkeys();\"
1151 onblur=\"javascript:enableHotkeys();\"
1152 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
1153 <input type=\"submit\" class=\"button\"
1154 onclick=\"javascript:updateFeedList()\" value=\"".__('Search')."\">
1157 print "<input onclick=\"javascript:displayDlg('quickAddFeed')\"
1158 type=\"submit\" id=\"subscribe_to_feed_btn\"
1159 class=\"button\" value=\"".__('Subscribe to feed')."\">";
1161 if (ENABLE_FEED_BROWSER
&& !SINGLE_USER_MODE
) {
1162 print " <input type=\"submit\" class=\"button\"
1163 id=\"top25_feeds_btn\"
1164 onclick=\"javascript:browseFeeds()\" value=\"".__('More Feeds')."\">";
1167 $feeds_sort = db_escape_string($_GET["sort"]);
1169 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1170 $feeds_sort = $_SESSION["pref_sort_feeds"];
1171 if (!$feeds_sort) $feeds_sort = "title";
1174 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1177 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1178 UPPER(C1.title) LIKE UPPER('%$feed_search%') OR
1179 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1184 $show_last_article_info = false;
1185 $show_last_article_checked = "";
1186 $show_last_article_qpart = "";
1188 if ($_GET["slat"] == "true") {
1189 $show_last_article_info = true;
1190 $show_last_article_checked = "checked";
1191 $show_last_article_qpart = ", (SELECT ".SUBSTRING_FOR_DATE
."(MAX(updated),1,16) FROM ttrss_user_entries,
1192 ttrss_entries WHERE ref_id = ttrss_entries.id
1193 AND feed_id = F1.id) AS last_article";
1194 } else if ($feeds_sort == "last_article") {
1195 $feeds_sort = "title";
1198 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1199 $order_by_qpart = "category,$feeds_sort,title";
1201 $order_by_qpart = "$feeds_sort,title";
1204 $result = db_query($link, "SELECT
1208 ".SUBSTRING_FOR_DATE
."(F1.last_updated,1,16) AS last_updated,
1214 F2.title AS parent_title,
1215 C1.title AS category,
1217 F1.include_in_digest
1218 $show_last_article_qpart
1221 LEFT JOIN ttrss_feeds AS F2
1222 ON (F1.parent_feed = F2.id)
1223 LEFT JOIN ttrss_feed_categories AS C1
1224 ON (F1.cat_id = C1.id)
1226 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1227 ORDER by $order_by_qpart");
1229 if (db_num_rows($result) != 0) {
1231 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1233 print "<p><table width=\"100%\" cellspacing=\"0\"
1234 class=\"prefFeedList\" id=\"prefFeedList\">";
1235 print "<tr><td class=\"selectPrompt\" colspan=\"8\">".
1236 "<div style='float : right'>".
1237 "<input id='show_last_article_times' type='checkbox' onchange='feedlistToggleSLAT()'
1238 $show_last_article_checked><label
1239 for='show_last_article_times'>".__('Show last article times')."</label></div>".
1241 <a href=\"javascript:selectPrefRows('feed', true)\">".__('All')."</a>,
1242 <a href=\"javascript:selectPrefRows('feed', false)\">".__('None')."</a>
1245 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1246 print "<tr class=\"title\">
1247 <td width='5%' align='center'> </td>";
1249 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1250 print "<td width='3%'> </td>";
1253 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1255 if ($show_last_article_info) {
1256 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_article')\">".__('Last Article')."</a></td>";
1259 print "<td width='20%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
1266 while ($line = db_fetch_assoc($result)) {
1268 $feed_id = $line["id"];
1269 $cat_id = $line["cat_id"];
1271 $edit_title = htmlspecialchars($line["title"]);
1272 $edit_cat = htmlspecialchars($line["category"]);
1274 $hidden = sql_bool_to_bool($line["hidden"]);
1276 $last_error = $line["last_error"];
1278 if (!$edit_cat) $edit_cat = __("Uncategorized");
1280 $last_updated = $line["last_updated"];
1282 if (!$last_updated) {
1283 $last_updated = "—";
1284 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1285 $last_updated = smart_date_time(strtotime($last_updated));
1287 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1288 $last_updated = date($short_date, strtotime($last_updated));
1291 $last_article = $line["last_article"];
1293 if (!$last_article) {
1294 $last_article = "—";
1295 } else if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1296 $last_article = smart_date_time(strtotime($last_article));
1298 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1299 $last_article = date($short_date, strtotime($last_article));
1302 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1305 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1307 print "<tr class=\"title\">
1308 <td width='5%'> </td>";
1310 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1311 print "<td width='3%'> </td>";
1314 print "<td width='60%'><a href=\"javascript:updateFeedList('title')\">".__('Title')."</a></td>";
1316 if ($show_last_article_info) {
1317 print "<td width='20%' align='right'>
1318 <a href=\"javascript:updateFeedList('last_article')\">".__('Last Article')."</a></td>";
1321 print "<td width='20%' align='right'>
1322 <a href=\"javascript:updateFeedList('last_updated')\">".__('Updated')."</a></td>";
1324 $cur_cat_id = $cat_id;
1327 $class = ($lnum %
2) ?
"even" : "odd";
1328 $this_row_id = "id=\"FEEDR-$feed_id\"";
1330 print "<tr class=\"$class\" $this_row_id>";
1332 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1334 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1335 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1337 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1340 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1341 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1343 $onclick = "onclick='editFeed($feed_id)' title='".__('Click to edit')."'";
1345 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1346 print "<td $onclick class='feedIcon'>$feed_icon</td>";
1350 $edit_title = "<span class=\"insensitive\">$edit_title ".
1351 __('(Hidden)')."</span>";
1352 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
1353 $last_article = "<span class=\"insensitive\">$last_article</span>";
1357 $edit_title = "<span class=\"feed_error\">$edit_title</span>";
1358 $last_updated = "<span class=\"feed_error\">$last_updated</span>";
1359 $last_article = "<span class=\"feed_error\">$last_article</span>";
1362 $parent_title = $line["parent_title"];
1363 if ($parent_title) {
1364 $linked_to = sprintf(__("(linked to %s)"), $parent_title);
1365 $parent_title = "<span class='groupPrompt'>$linked_to</span>";
1368 print "<td $onclick>" . "$edit_title $parent_title" . "</td>";
1370 if ($show_last_article_info) {
1371 print "<td align='right' $onclick>" .
1372 "$last_article</td>";
1375 print "<td $onclick align='right'>$last_updated</td>";
1386 print "<div id=\"feedOpToolbar\">";
1388 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1390 print __('Selection:') . " ";
1392 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1394 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1395 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"".
1396 __('Recategorize')."\">";
1401 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1402 <option value=\"facDefault\" selected>".__('Actions...')."</option>
1403 <optgroup label=\"".__('Selection:')."\">
1404 <option value=\"facEdit\">".__('Edit')."</option>";
1406 if (FORCE_ARTICLE_PURGE
== 0) {
1408 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1412 <option value=\"facClear\">".__('Clear feed data')."</option>
1413 <option value=\"facRescore\">".__('Rescore articles')."</option>
1414 <option value=\"facUnsubscribe\">".__('Unsubscribe')."</option>";
1416 print "</optgroup>";
1418 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1420 print "<optgroup label=\"".__('Other:')."\">
1421 <option value=\"facEditCats\">".__('Edit categories')."
1432 if (!$feed_search) {
1433 print_warning(__("You don't have any subscribed feeds."));
1435 print_warning(__('No matching feeds found.'));
1441 print "<h3>".__('OPML')."</h3>
1443 <div style='float : left'>
1444 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1445 ".__('File:')." <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1446 <input type=\"hidden\" name=\"op\" value=\"Import\">
1447 <input class=\"button\" onclick=\"return validateOpmlImport();\"
1448 type=\"submit\" value=\"".__('Import')."\">
1453 print "<input type=\"submit\"
1454 class=\"button\" onclick=\"gotoExportOpml()\"
1455 value=\"".__('Export OPML')."\">";
1458 print "<h3>" . __("Firefox Integration") . "</h3>";
1460 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.');
1461 print "</p><p> <a class='visibleLinkB' href='javascript:window.navigator.registerContentHandler(" .
1462 "\"application/vnd.mozilla.maybe.feed\", " .
1463 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1464 __('Click here to register this site as a feed reader.') . "</a></p>";
1467 print "<h3>".__("Published articles")."</h3>";
1469 if (!get_pref($link, "_PREFS_PUBLISH_KEY")) {
1470 set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key());
1473 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1475 $url_path = article_publish_url($link);
1477 print "<p><a class=\"visibleLinkB\" id=\"pubGenAddress\" target=\"_blank\" href=\"$url_path\">".__("Link to published articles feed.")."</a></p>";
1479 print "<p><input type=\"submit\" onclick=\"return pubRegenKey()\" class=\"button\"
1480 value=\"".__('Generate another link')."\">";
1481 /* print " <input type=\"submit\" onclick=\"return pubToClipboard()\" class=\"button\"
1482 value=\"".__('Copy link to clipboard')."\">"; */
1487 function print_feed_browser($link, $search, $limit) {
1489 $owner_uid = $_SESSION["uid"];
1492 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1493 UPPER(title) LIKE UPPER('%$search%'))";
1498 $result = db_query($link, "SELECT feed_url, subscribers FROM
1499 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1500 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1501 AND owner_uid = '$owner_uid') $search_qpart
1502 ORDER BY subscribers DESC LIMIT $limit");
1506 while ($line = db_fetch_assoc($result)) {
1507 $feed_url = $line["feed_url"];
1508 $subscribers = $line["subscribers"];
1510 $det_result = db_query($link, "SELECT site_url,title,id
1511 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1513 $details = db_fetch_assoc($det_result);
1515 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
1517 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1518 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
1519 "/".$details["id"].".ico\">";
1521 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1524 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1525 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1527 $class = ($feedctr %
2) ?
"even" : "odd";
1529 if ($details["site_url"]) {
1530 $site_url = "<a target=\"_blank\" href=\"".$details["site_url"]."\">
1531 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1536 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1537 "$feed_icon " . $details["title"] .
1538 " <span class='subscribers'>($subscribers)</span>
1545 if ($feedctr == 0) {
1546 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";