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"];
16 $mode = $_REQUEST["mode"];
18 if ($subop == "renamecat") {
19 $title = db_escape_string($_REQUEST['title']);
20 $id = db_escape_string($_REQUEST['id']);
23 db_query($link, "UPDATE ttrss_feed_categories SET
24 title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
29 if ($subop == "getfeedtree") {
33 $root['name'] = __('Feeds');
34 $root['items'] = array();
35 $root['type'] = 'category';
37 if (get_pref($link, 'ENABLE_FEED_CATS')) {
39 $result = db_query($link, "SELECT id, title FROM ttrss_feed_categories
40 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title");
42 while ($line = db_fetch_assoc($result)) {
44 $cat['id'] = 'CAT:' . $line['id'];
45 $cat['bare_id'] = $feed_id;
46 $cat['name'] = $line['title'];
47 $cat['items'] = array();
48 $cat['type'] = 'category';
50 $feed_result = db_query($link, "SELECT id, title, last_error
52 WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"].
53 " ORDER BY order_id, title");
55 while ($feed_line = db_fetch_assoc($feed_result)) {
57 $feed['id'] = 'FEED:' . $feed_line['id'];
58 $feed['bare_id'] = $feed_line['id'];
59 $feed['name'] = $feed_line['title'];
60 $feed['checkbox'] = false;
61 $feed['error'] = $feed_line['last_error'];
62 $feed['icon'] = getFeedIcon($feed_line['id']);
64 array_push($cat['items'], $feed);
67 array_push($root['items'], $cat);
70 /* Uncategorized is a special case */
75 $cat['name'] = __("Uncategorized");
76 $cat['items'] = array();
77 $cat['type'] = 'category';
79 $feed_result = db_query($link, "SELECT id, title,last_error
81 WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"].
82 " ORDER BY order_id, title");
84 while ($feed_line = db_fetch_assoc($feed_result)) {
86 $feed['id'] = 'FEED:' . $feed_line['id'];
87 $feed['bare_id'] = $feed_line['id'];
88 $feed['name'] = $feed_line['title'];
89 $feed['checkbox'] = false;
90 $feed['error'] = $feed_line['last_error'];
91 $feed['icon'] = getFeedIcon($feed_line['id']);
93 array_push($cat['items'], $feed);
96 array_push($root['items'], $cat);
98 $feed_result = db_query($link, "SELECT id, title, last_error
100 WHERE owner_uid = ".$_SESSION["uid"].
101 " ORDER BY order_id, title");
103 while ($feed_line = db_fetch_assoc($feed_result)) {
105 $feed['id'] = 'FEED:' . $feed_line['id'];
106 $feed['bare_id'] = $feed_line['id'];
107 $feed['name'] = $feed_line['title'];
108 $feed['checkbox'] = false;
109 $feed['error'] = $feed_line['last_error'];
110 $feed['icon'] = getFeedIcon($feed_line['id']);
112 array_push($root['items'], $feed);
117 $fl['identifier'] = 'id';
118 $fl['label'] = 'name';
119 $fl['items'] = array($root);
121 print json_encode($fl);
125 if ($subop == "catsortreset") {
126 db_query($link, "UPDATE ttrss_feed_categories
127 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
131 if ($subop == "feedsortreset") {
132 db_query($link, "UPDATE ttrss_feeds
133 SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
137 if ($subop == "savefeedorder") {
138 # if ($_POST['payload']) {
139 # file_put_contents("/tmp/blahblah.txt", $_POST['payload']);
140 # $data = json_decode($_POST['payload'], true);
142 # $data = json_decode(file_get_contents("/tmp/blahblah.txt"), true);
145 $data = json_decode($_POST['payload'], true);
147 if (is_array($data) && is_array($data['items'])) {
152 foreach ($data['items'] as $item) {
154 if ($item['id'] != 'root') {
155 if (is_array($item['items'])) {
156 if (isset($item['items']['_reference'])) {
157 $data_map[$item['id']] = array($item['items']);
159 $data_map[$item['id']] =& $item['items'];
165 foreach ($data['items'][0]['items'] as $item) {
166 $id = $item['_reference'];
167 $bare_id = substr($id, strpos($id, ':')+1);
172 db_query($link, "UPDATE ttrss_feed_categories
173 SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND
174 owner_uid = " . $_SESSION["uid"]);
179 if (is_array($data_map[$id])) {
180 foreach ($data_map[$id] as $feed) {
181 $id = $feed['_reference'];
182 $feed_id = substr($id, strpos($id, ':')+1);
185 $cat_query = "cat_id = '$bare_id'";
187 $cat_query = "cat_id = NULL";
189 db_query($link, "UPDATE ttrss_feeds
190 SET order_id = '$feed_order_id',
192 WHERE id = '$feed_id' AND
193 owner_uid = " . $_SESSION["uid"]);
204 if ($subop == "removeicon") {
205 $feed_id = db_escape_string($_REQUEST["feed_id"]);
207 $result = db_query($link, "SELECT id FROM ttrss_feeds
208 WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
210 if (db_num_rows($result) != 0) {
211 unlink(ICONS_DIR . "/$feed_id.ico");
217 if ($subop == "uploadicon") {
218 $icon_file = $_FILES['icon_file']['tmp_name'];
219 $feed_id = db_escape_string($_REQUEST["feed_id"]);
221 if (is_file($icon_file) && $feed_id) {
222 if (filesize($icon_file) < 20000) {
224 $result = db_query($link, "SELECT id FROM ttrss_feeds
225 WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
227 if (db_num_rows($result) != 0) {
228 unlink(ICONS_DIR . "/$feed_id.ico");
229 move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico");
241 print "<script type=\"text/javascript\">";
242 print "parent.uploadIconHandler($rc);";
247 if ($subop == "editfeed") {
248 header("Content-Type: text/xml");
250 print "<dlg id=\"$subop\">";
251 print "<title>".__('Feed Editor')."</title>";
252 print "<content><![CDATA[";
254 $feed_id = db_escape_string($_REQUEST["id"]);
256 $result = db_query($link,
257 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
258 owner_uid = " . $_SESSION["uid"]);
260 $title = htmlspecialchars(db_fetch_result($result,
263 $icon_file = ICONS_DIR . "/$feed_id.ico";
265 if (file_exists($icon_file) && filesize($icon_file) > 0) {
266 $feed_icon = "<img width=\"16\" height=\"16\"
267 src=\"" . ICONS_URL . "/$feed_id.ico\">";
272 print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
274 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
275 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
276 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
278 print "<div class=\"dlgSec\">".__("Feed")."</div>";
279 print "<div class=\"dlgSecCont\">";
283 print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
284 name=\"title\" value=\"$title\">";
288 $feed_url = db_fetch_result($result, 0, "feed_url");
289 $feed_url = htmlspecialchars(db_fetch_result($result,
294 print __('URL:') . " ";
295 print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
296 name=\"feed_url\" value=\"$feed_url\">";
300 if (get_pref($link, 'ENABLE_FEED_CATS')) {
302 $cat_id = db_fetch_result($result, 0, "cat_id");
306 print __('Place in category:') . " ";
308 print_feed_cat_select($link, "cat_id", $cat_id, $disabled);
313 print "<div class=\"dlgSec\">".__("Update")."</div>";
314 print "<div class=\"dlgSecCont\">";
316 /* Update Interval */
318 $update_interval = db_fetch_result($result, 0, "update_interval");
320 print_select_hash("update_interval", $update_interval, $update_intervals);
324 $update_method = db_fetch_result($result, 0, "update_method");
326 print " " . __('using') . " ";
327 print_select_hash("update_method", $update_method, $update_methods);
329 $purge_interval = db_fetch_result($result, 0, "purge_interval");
331 if (FORCE_ARTICLE_PURGE == 0) {
337 print __('Article purging:') . " ";
339 print_select_hash("purge_interval", $purge_interval, $purge_intervals);
342 print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
347 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
348 print "<div class=\"dlgSecCont\">";
350 $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
354 print "<tr><td>" . __('Login:') . "</td><td>";
356 print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\"
357 name=\"auth_login\" value=\"$auth_login\">";
359 print "</tr><tr><td>" . __("Password:") . "</td><td>";
361 $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
363 print "<input size=\"20\" type=\"password\" name=\"auth_pass\"
364 onkeypress=\"return filterCR(event, feedEditSave)\"
365 value=\"$auth_pass\">";
367 print "</td></tr></table>";
370 print "<div class=\"dlgSec\">".__("Options")."</div>";
371 print "<div class=\"dlgSecCont\">";
373 print "<div style=\"line-height : 100%\">";
375 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
378 $checked = "checked";
383 print "<input type=\"checkbox\" name=\"private\" id=\"private\"
384 $checked> <label for=\"private\">".__('Hide from Popular feeds')."</label>";
386 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
389 $checked = "checked";
394 print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
395 $checked> <label for=\"rtl_content\">".__('Right-to-left content')."</label>";
397 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
399 if ($include_in_digest) {
400 $checked = "checked";
405 print "<br/><input type=\"checkbox\" id=\"include_in_digest\"
406 name=\"include_in_digest\"
407 $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
410 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
412 if ($always_display_enclosures) {
413 $checked = "checked";
418 print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\"
419 name=\"always_display_enclosures\"
420 $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
423 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
426 $checked = "checked";
431 if (SIMPLEPIE_CACHE_IMAGES) {
435 $disabled = "disabled";
436 $label_class = "class='insensitive'";
439 print "<br/><input type=\"checkbox\" id=\"cache_images\"
440 name=\"cache_images\" $disabled
441 $checked> <label $label_class for=\"cache_images\">".
442 __('Cache images locally')."</label>";
454 print "<div class=\"dlgSec\">".__("Icon")."</div>";
455 print "<div class=\"dlgSecCont\">";
457 print "<iframe name=\"icon_upload_iframe\"
458 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
460 print "<form style='display : block' target=\"icon_upload_iframe\"
461 enctype=\"multipart/form-data\" method=\"POST\"
462 action=\"backend.php\">
463 <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
464 <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
465 <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
466 <input type=\"hidden\" name=\"subop\" value=\"uploadicon\">
467 <button onclick=\"return uploadFeedIcon();\"
468 type=\"submit\">".__('Replace')."</button>
469 <button onclick=\"return removeFeedIcon($feed_id);\"
470 type=\"submit\">".__('Remove')."</button>
475 $title = htmlspecialchars($title, ENT_QUOTES);
477 print "<div class='dlgButtons'>
478 <div style=\"float : left\">
479 <button onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
480 __('Unsubscribe')."</button>
482 <button onclick=\"return feedEditSave()\">".__('Save')."</button>
483 <button onclick=\"return feedEditCancel()\">".__('Cancel')."</button>
486 print "]]></content></dlg>";
491 if ($subop == "editfeeds") {
493 $feed_ids = db_escape_string($_REQUEST["ids"]);
495 header("Content-Type: text/xml");
496 print "<dlg id=\"$subop\">";
497 print "<title>".__('Multiple Feed Editor')."</title>";
498 print "<content><![CDATA[";
500 print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">";
502 print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">";
503 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
504 print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
506 print "<div class=\"dlgSec\">".__("Feed")."</div>";
507 print "<div class=\"dlgSecCont\">";
511 print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\"
512 name=\"title\" value=\"$title\">";
514 batch_edit_cbox("title");
520 print __('URL:') . " ";
521 print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\"
522 name=\"feed_url\" value=\"$feed_url\">";
524 batch_edit_cbox("feed_url");
528 if (get_pref($link, 'ENABLE_FEED_CATS')) {
532 print __('Place in category:') . " ";
534 print_feed_cat_select($link, "cat_id", $cat_id, "disabled");
536 batch_edit_cbox("cat_id");
542 print "<div class=\"dlgSec\">".__("Update")."</div>";
543 print "<div class=\"dlgSecCont\">";
545 /* Update Interval */
547 print_select_hash("update_interval", $update_interval, $update_intervals,
550 batch_edit_cbox("update_interval");
554 print " " . __('using') . " ";
555 print_select_hash("update_method", $update_method, $update_methods,
557 batch_edit_cbox("update_method");
561 if (FORCE_ARTICLE_PURGE != 0) {
565 print __('Article purging:') . " ";
567 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
570 batch_edit_cbox("purge_interval");
574 print "<div class=\"dlgSec\">".__("Authentication")."</div>";
575 print "<div class=\"dlgSecCont\">";
577 print __('Login:') . " ";
578 print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\"
579 name=\"auth_login\" value=\"$auth_login\">";
581 batch_edit_cbox("auth_login");
583 print " " . __("Password:") . " ";
585 print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\"
586 onkeypress=\"return filterCR(event, feedEditSave)\"
587 value=\"$auth_pass\">";
589 batch_edit_cbox("auth_pass");
592 print "<div class=\"dlgSec\">".__("Options")."</div>";
593 print "<div class=\"dlgSecCont\">";
595 print "<div style=\"line-height : 100%\">";
597 print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\"
598 $checked> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
600 print " "; batch_edit_cbox("private", "private_l");
602 print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
603 $checked> <label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
605 print " "; batch_edit_cbox("rtl_content", "rtl_content_l");
607 print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\"
608 name=\"include_in_digest\"
609 $checked> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
611 print " "; batch_edit_cbox("include_in_digest", "include_in_digest_l");
613 print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\"
614 name=\"always_display_enclosures\"
615 $checked> <label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
617 print " "; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
619 print "<br/><input disabled type=\"checkbox\" id=\"cache_images\"
620 name=\"cache_images\"
621 $checked> <label class='insensitive' id=\"cache_images_l\"
622 for=\"cache_images\">".
623 __('Cache images locally')."</label>";
626 if (SIMPLEPIE_CACHE_IMAGES) {
627 print " "; batch_edit_cbox("cache_images", "cache_images_l");
635 print "<div class='dlgButtons'>
636 <input type=\"submit\" class=\"button\"
637 onclick=\"return feedsEditSave()\" value=\"".__('Save')."\">
638 <input type='submit' class='button'
639 onclick=\"return feedEditCancel()\" value=\"".__('Cancel')."\">
642 print "]]></content></dlg>";
647 if ($subop == "editSave" || $subop == "batchEditSave") {
649 $feed_title = db_escape_string(trim($_POST["title"]));
650 $feed_link = db_escape_string(trim($_POST["feed_url"]));
651 $upd_intl = db_escape_string($_POST["update_interval"]);
652 $purge_intl = db_escape_string($_POST["purge_interval"]);
653 $feed_id = db_escape_string($_POST["id"]); /* editSave */
654 $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
655 $cat_id = db_escape_string($_POST["cat_id"]);
656 $auth_login = db_escape_string(trim($_POST["auth_login"]));
657 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
658 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
659 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
660 $include_in_digest = checkbox_to_sql_bool(
661 db_escape_string($_POST["include_in_digest"]));
662 $cache_images = checkbox_to_sql_bool(
663 db_escape_string($_POST["cache_images"]));
664 $update_method = (int) db_escape_string($_POST["update_method"]);
666 $always_display_enclosures = checkbox_to_sql_bool(
667 db_escape_string($_POST["always_display_enclosures"]));
669 if (get_pref($link, 'ENABLE_FEED_CATS')) {
670 if ($cat_id && $cat_id != 0) {
671 $category_qpart = "cat_id = '$cat_id',";
672 $category_qpart_nocomma = "cat_id = '$cat_id'";
674 $category_qpart = 'cat_id = NULL,';
675 $category_qpart_nocomma = 'cat_id = NULL';
678 $category_qpart = "";
679 $category_qpart_nocomma = "";
682 if (SIMPLEPIE_CACHE_IMAGES) {
683 $cache_images_qpart = "cache_images = $cache_images,";
685 $cache_images_qpart = "";
688 if ($subop == "editSave") {
690 $result = db_query($link, "UPDATE ttrss_feeds SET
692 title = '$feed_title', feed_url = '$feed_link',
693 update_interval = '$upd_intl',
694 purge_interval = '$purge_intl',
695 auth_login = '$auth_login',
696 auth_pass = '$auth_pass',
698 rtl_content = $rtl_content,
700 include_in_digest = $include_in_digest,
701 always_display_enclosures = $always_display_enclosures,
702 update_method = '$update_method'
703 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
705 } else if ($subop == "batchEditSave") {
706 $feed_data = array();
708 foreach (array_keys($_POST) as $k) {
709 if ($k != "op" && $k != "subop" && $k != "ids") {
710 $feed_data[$k] = $_POST[$k];
714 db_query($link, "BEGIN");
716 foreach (array_keys($feed_data) as $k) {
722 $qpart = "title = '$feed_title'";
726 $qpart = "feed_url = '$feed_link'";
729 case "update_interval":
730 $qpart = "update_interval = '$upd_intl'";
733 case "purge_interval":
734 $qpart = "purge_interval = '$purge_intl'";
738 $qpart = "auth_login = '$auth_login'";
742 $qpart = "auth_pass = '$auth_pass'";
746 $qpart = "private = '$private'";
749 case "include_in_digest":
750 $qpart = "include_in_digest = '$include_in_digest'";
753 case "always_display_enclosures":
754 $qpart = "always_display_enclosures = '$always_display_enclosures'";
758 $qpart = "cache_images = '$cache_images'";
762 $qpart = "rtl_content = '$rtl_content'";
765 case "update_method":
766 $qpart = "update_method = '$update_method'";
770 $qpart = $category_qpart_nocomma;
777 "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
778 AND owner_uid = " . $_SESSION["uid"]);
783 db_query($link, "COMMIT");
788 if ($subop == "remove") {
790 $ids = split(",", db_escape_string($_REQUEST["ids"]));
792 foreach ($ids as $id) {
793 remove_feed($link, $id, $_SESSION["uid"]);
799 if ($subop == "clear") {
800 $id = db_escape_string($_REQUEST["id"]);
801 clear_feed_articles($link, $id);
804 if ($subop == "rescore") {
805 $ids = split(",", db_escape_string($_REQUEST["ids"]));
807 foreach ($ids as $id) {
809 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
811 $result = db_query($link, "SELECT
812 title, content, link, ref_id, author,".
813 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
815 ttrss_user_entries, ttrss_entries
816 WHERE ref_id = id AND feed_id = '$id' AND
817 owner_uid = " .$_SESSION['uid']."
822 while ($line = db_fetch_assoc($result)) {
824 $tags = get_article_tags($link, $line["ref_id"]);
826 $article_filters = get_article_filters($filters, $line['title'],
827 $line['content'], $line['link'], strtotime($line['updated']),
828 $line['author'], $tags);
830 $new_score = calculate_article_score($article_filters);
832 if (!$scores[$new_score]) $scores[$new_score] = array();
834 array_push($scores[$new_score], $line['ref_id']);
837 foreach (array_keys($scores) as $s) {
839 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
841 ref_id IN (" . join(',', $scores[$s]) . ")");
842 } else if ($s < -500) {
843 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
845 ref_id IN (" . join(',', $scores[$s]) . ")");
847 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
848 ref_id IN (" . join(',', $scores[$s]) . ")");
853 print __("All done.");
857 if ($subop == "rescoreAll") {
859 $result = db_query($link,
860 "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
862 while ($feed_line = db_fetch_assoc($result)) {
864 $id = $feed_line["id"];
866 $filters = load_filters($link, $id, $_SESSION["uid"], 6);
868 $tmp_result = db_query($link, "SELECT
869 title, content, link, ref_id, author,".
870 SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
872 ttrss_user_entries, ttrss_entries
873 WHERE ref_id = id AND feed_id = '$id' AND
874 owner_uid = " .$_SESSION['uid']."
879 while ($line = db_fetch_assoc($tmp_result)) {
881 $tags = get_article_tags($link, $line["ref_id"]);
883 $article_filters = get_article_filters($filters, $line['title'],
884 $line['content'], $line['link'], strtotime($line['updated']),
885 $line['author'], $tags);
887 $new_score = calculate_article_score($article_filters);
889 if (!$scores[$new_score]) $scores[$new_score] = array();
891 array_push($scores[$new_score], $line['ref_id']);
894 foreach (array_keys($scores) as $s) {
896 db_query($link, "UPDATE ttrss_user_entries SET score = '$s',
898 ref_id IN (" . join(',', $scores[$s]) . ")");
900 db_query($link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
901 ref_id IN (" . join(',', $scores[$s]) . ")");
906 print __("All done.");
910 if ($subop == "add") {
912 $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
913 $cat_id = db_escape_string($_REQUEST["cat_id"]);
914 $p_from = db_escape_string($_REQUEST["from"]);
916 /* only read authentication information from POST */
918 $auth_login = db_escape_string(trim($_POST["auth_login"]));
919 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
921 if ($p_from != 'tt-rss') {
924 <title>Tiny Tiny RSS</title>
925 <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
928 <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
929 alt=\"Tiny Tiny RSS\"/>
930 <h1>Subscribe to feed...</h1>";
933 $rc = subscribe_to_feed($link, $feed_url, $cat_id, $auth_login, $auth_pass);
937 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
940 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
943 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
947 if ($p_from != 'tt-rss') {
948 $tt_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'tt-rss.php', $_SERVER["REQUEST_URI"]);
951 $tp_uri = ($_SERVER['HTTPS'] != "on" ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . preg_replace('/backend\.php.*$/', 'prefs.php', $_SERVER["REQUEST_URI"]);
953 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
954 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
956 $feed_id = db_fetch_result($result, 0, "id");
961 print "<form method=\"GET\" style='display: inline'
963 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
964 <input type=\"hidden\" name=\"subop\" value=\"editFeed\">
965 <input type=\"hidden\" name=\"subopparam\" value=\"$feed_id\">
966 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
970 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
971 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
974 print "</body></html>";
979 if ($subop == "categorize") {
982 $ids = split(",", db_escape_string($_REQUEST["ids"]));
984 $cat_id = db_escape_string($_REQUEST["cat_id"]);
987 $cat_id_qpart = 'NULL';
989 $cat_id_qpart = "'$cat_id'";
992 db_query($link, "BEGIN");
994 foreach ($ids as $id) {
996 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
998 AND owner_uid = " . $_SESSION["uid"]);
1002 db_query($link, "COMMIT");
1006 if ($subop == "editCats") {
1008 $action = $_REQUEST["action"];
1010 if ($action == "save") {
1012 $cat_title = db_escape_string(trim($_REQUEST["value"]));
1013 $cat_id = db_escape_string($_REQUEST["cid"]);
1015 db_query($link, "BEGIN");
1017 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1018 WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1020 if (db_num_rows($result) == 1) {
1022 $old_title = db_fetch_result($result, 0, "title");
1024 if ($cat_title != "") {
1025 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1026 title = '$cat_title' WHERE id = '$cat_id' AND
1027 owner_uid = ".$_SESSION["uid"]);
1034 print $_REQUEST["value"];
1037 db_query($link, "COMMIT");
1043 header("Content-Type: text/xml");
1044 print "<dlg id=\"$subop\">";
1045 print "<title>".__('Category editor')."</title>";
1046 print "<content><![CDATA[";
1048 if ($action == "add") {
1050 $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
1052 if (!add_feed_category($link, $feed_cat))
1053 print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat));
1057 if ($action == "remove") {
1059 $ids = split(",", db_escape_string($_REQUEST["ids"]));
1061 foreach ($ids as $id) {
1062 remove_feed_category($link, $id, $_SESSION["uid"]);
1066 print "<div dojoType=\"dijit.Toolbar\">
1067 <input id=\"fadd_cat\"
1068 onkeypress=\"return filterCR(event, addFeedCat)\"
1070 <button onclick=\"addFeedCat()\">".
1071 __('Create category')."</button></div>";
1073 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1074 WHERE owner_uid = ".$_SESSION["uid"]."
1079 if (db_num_rows($result) != 0) {
1081 # print __('Select:')."
1082 # <a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'all')\">".__('All')."</a>,
1083 # <a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'none')\">".__('None')."</a>";
1085 print "<div class=\"prefFeedCatHolder\">";
1087 print "<form id=\"feed_cat_edit_form\" onsubmit=\"return false\">";
1089 print "<table width=\"100%\" class=\"prefFeedCatList\"
1090 cellspacing=\"0\" id=\"prefFeedCatList\">";
1094 while ($line = db_fetch_assoc($result)) {
1096 $class = ($lnum % 2) ? "even" : "odd";
1098 $cat_id = $line["id"];
1099 $this_row_id = "id=\"FCATR-$cat_id\"";
1101 print "<tr class=\"\" $this_row_id>";
1103 $edit_title = htmlspecialchars($line["title"]);
1105 print "<td width='5%' align='center'><input
1106 onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
1107 type=\"checkbox\" id=\"FCCHK-$cat_id\"></td>";
1111 # print "<span id=\"FCATT-$cat_id\">" .
1112 # $edit_title . "</span>";
1114 print "<span dojoType=\"dijit.InlineEditBox\"
1115 width=\"300px\" autoSave=\"false\"
1116 cat-id=\"$cat_id\">" . $edit_title .
1117 "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
1121 content: {op: 'pref-feeds', subop: 'editCats',
1124 cid: this.srcNodeRef.getAttribute('cat-id')},
1125 load: function(response) {
1126 elem.attr('value', response);
1144 print "<p>".__('No feed categories defined.')."</p>";
1147 print "<div class='dlgButtons'>
1148 <div style='float : left'>
1149 <button onclick=\"return removeSelectedFeedCats()\">".
1150 __('Remove')."</button>
1153 print "<button onclick=\"selectTab('feedConfig')\">".
1154 __('Close this window')."</button></div>";
1156 print "]]></content></dlg>";
1164 print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
1165 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
1167 set_pref($link, "_PREFS_ACTIVE_TAB", "feedConfig");
1169 $result = db_query($link, "SELECT COUNT(id) AS num_errors
1170 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1172 $num_errors = db_fetch_result($result, 0, "num_errors");
1174 if ($num_errors > 0) {
1176 $error_button = "<button dojoType=\"dijit.form.Button\"
1177 onclick=\"showFeedsWithErrors\" id=\"errorButton\">" .
1178 __("Feeds with errors") . "</button>";
1180 // print format_notice("<a href=\"javascript:showFeedsWithErrors()\">".
1181 // __('Some feeds have update errors (click for details)')."</a>");
1184 $feed_search = db_escape_string($_REQUEST["search"]);
1186 if (array_key_exists("search", $_REQUEST)) {
1187 $_SESSION["prefs_feed_search"] = $feed_search;
1189 $feed_search = $_SESSION["prefs_feed_search"];
1192 print "<div dojoType=\"dijit.Toolbar\">";
1195 print "<div style='float : right'>
1196 <input id=\"feed_search\" size=\"20\" type=\"search\"
1197 onfocus=\"disableHotkeys();\"
1198 onblur=\"enableHotkeys();\"
1199 onchange=\"updateFeedList()\" value=\"$feed_search\">
1200 <button onclick=\"updateFeedList()\">".
1201 __('Search')."</button>
1204 print "<div dojoType=\"dijit.form.DropDownButton\">".
1205 "<span>" . __('Select')."</span>";
1206 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1207 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
1208 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
1209 print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
1210 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
1211 print "</div></div>";
1213 print "<div dojoType=\"dijit.form.DropDownButton\">".
1214 "<span>" . __('Feeds')."</span>";
1215 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1216 print "<div onclick=\"quickAddFeed()\"
1217 dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
1218 print "<div onclick=\"editSelectedFeed()\"
1219 dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
1220 print "<div onclick=\"resetFeedOrder()\"
1221 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1222 print "</div></div>";
1224 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1225 print "<div dojoType=\"dijit.form.DropDownButton\">".
1226 "<span>" . __('Categories')."</span>";
1227 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
1228 print "<div onclick=\"editFeedCats()\"
1229 dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
1230 print "<div onclick=\"resetCatOrder()\"
1231 dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
1232 print "</div></div>";
1236 print $error_button;
1238 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
1239 .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
1241 if (defined('_ENABLE_FEED_DEBUGGING')) {
1243 print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
1244 <option value=\"facDefault\" selected>".__('More actions...')."</option>";
1246 if (FORCE_ARTICLE_PURGE == 0) {
1248 "<option value=\"facPurge\">".__('Manual purge')."</option>";
1252 <option value=\"facClear\">".__('Clear feed data')."</option>
1253 <option value=\"facRescore\">".__('Rescore articles')."</option>";
1259 print "</div>"; # toolbar
1261 print "<div id=\"feedlistLoading\">
1262 <img src='images/indicator_tiny.gif'>".
1263 __("Loading, please wait...")."</div>";
1265 print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
1266 url=\"backend.php?op=pref-feeds&subop=getfeedtree\">
1268 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
1269 query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
1270 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
1272 <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
1273 dndController=\"dijit.tree.dndSource\"
1274 betweenThreshold=\"5\"
1275 model=\"feedModel\" openOnClick=\"false\">
1276 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
1277 var id = String(item.id);
1278 var bare_id = id.substr(id.indexOf(':')+1);
1280 if (id.match('FEED:')) {
1281 editFeed(bare_id, event);
1282 } else if (id.match('CAT:')) {
1283 editCat(bare_id, item, event);
1286 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
1287 Element.hide(\"feedlistLoading\");
1291 print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
1292 <b>Hint:</b> you can drag feeds and categories around.
1295 print "</div>"; # feeds pane
1297 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
1299 print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.");
1301 print "<div class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</div>";
1305 print "<iframe name=\"upload_iframe\"
1306 style=\"width: 400px; height: 100px; display: none;\"></iframe>";
1308 print "<div style='float : left'>";
1309 print "<form style='display : block' target=\"upload_iframe\"
1310 enctype=\"multipart/form-data\" method=\"POST\"
1311 action=\"backend.php\">
1312 <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1313 <input type=\"hidden\" name=\"op\" value=\"dlg\">
1314 <input type=\"hidden\" name=\"id\" value=\"importOpml\">
1315 <button onclick=\"return opmlImport();\"
1316 type=\"submit\">".__('Import')."</button>
1318 print "</div> ";
1320 print "<button onclick=\"gotoExportOpml()\">".__('Export OPML')."</button>";
1322 print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.');
1324 print "<div class=\"insensitive\">" . __("Note: Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</div>" . "</p>";
1326 print "<button onclick=\"return displayDlg('pubOPMLUrl')\">".
1327 __('Display URL')."</button> ";
1330 print "</div>"; # pane
1332 if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
1334 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
1336 print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
1340 print "<button onclick='window.navigator.registerContentHandler(" .
1341 "\"application/vnd.mozilla.maybe.feed\", " .
1342 "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" .
1343 __('Click here to register this site as a feed reader.') .
1348 print "</div>"; # pane
1351 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
1353 print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>";
1355 $bm_subscribe_url = str_replace('%s', '', add_feed_url());
1357 $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
1359 $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
1361 print "<a href=\"$bm_url\" class='visibleLink'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
1363 print "</div>"; #pane
1365 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published articles and generated feeds')."\">";
1367 print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
1369 $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
1370 "/backend.php?op=rss&id=-2&view-mode=all_articles");;
1372 print "<button onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
1373 __('Display URL')."</button> ";
1375 print "<button onclick=\"return clearFeedAccessKeys()\">".
1376 __('Clear all generated URLs')."</button> ";
1378 print "</div>"; #pane
1379 print "</div>"; #container
1383 function print_feed_browser($link, $search, $limit, $mode = 1) {
1385 $owner_uid = $_SESSION["uid"];
1388 $search_qpart = "AND (UPPER(feed_url) LIKE UPPER('%$search%') OR
1389 UPPER(title) LIKE UPPER('%$search%'))";
1395 $result = db_query($link, "SELECT feed_url, subscribers FROM
1396 ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1397 WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url
1398 AND owner_uid = '$owner_uid') $search_qpart
1399 ORDER BY subscribers DESC LIMIT $limit");
1400 } else if ($mode == 2) {
1401 $result = db_query($link, "SELECT *,
1402 (SELECT COUNT(*) FROM ttrss_user_entries WHERE
1403 orig_feed_id = ttrss_archived_feeds.id) AS articles_archived
1405 ttrss_archived_feeds
1407 (SELECT COUNT(*) FROM ttrss_feeds
1408 WHERE ttrss_feeds.feed_url = ttrss_archived_feeds.feed_url AND
1409 owner_uid = '$owner_uid') = 0 AND
1410 owner_uid = '$owner_uid' $search_qpart
1411 ORDER BY id DESC LIMIT $limit");
1416 while ($line = db_fetch_assoc($result)) {
1420 $feed_url = $line["feed_url"];
1421 $subscribers = $line["subscribers"];
1423 $det_result = db_query($link, "SELECT site_url,title,id
1424 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1426 $details = db_fetch_assoc($det_result);
1428 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1430 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1431 $feed_icon = "<img style=\"vertical-align : middle\" class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1432 "/".$details["id"].".ico\">";
1434 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1437 $check_box = "<input onclick='toggleSelectListRow2(this)'
1438 dojoType=\"dijit.form.CheckBox\"
1439 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1441 $class = ($feedctr % 2) ? "even" : "odd";
1443 $feed_url = htmlspecialchars($line["feed_url"]);
1445 if ($details["site_url"]) {
1446 $site_url = "<a target=\"_blank\" href=\"".
1447 htmlspecialchars($details["site_url"])."\">
1448 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1453 $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
1454 style='border-width : 0px; vertical-align : middle'
1455 src='images/feed-icon-12x12.png'></a>";
1457 print "<li title=\"".htmlspecialchars($details["site_url"])."\"
1458 id=\"FBROW-".$details["id"]."\">$check_box".
1459 "$feed_icon $feed_url " . htmlspecialchars($details["title"]) .
1460 " <span class='subscribers'>($subscribers)</span>
1463 } else if ($mode == 2) {
1464 $feed_url = htmlspecialchars($line["feed_url"]);
1465 $site_url = htmlspecialchars($line["site_url"]);
1466 $title = htmlspecialchars($line["title"]);
1468 $icon_file = ICONS_DIR . "/" . $line["id"] . ".ico";
1470 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1471 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1472 "/".$line["id"].".ico\">";
1474 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1477 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1478 type=\"checkbox\" id=\"FBCHK-" . $line["id"] . "\">";
1480 $class = ($feedctr % 2) ? "even" : "odd";
1482 if ($line['articles_archived'] > 0) {
1483 $archived = sprintf(__("%d archived articles"), $line['articles_archived']);
1484 $archived = " <span class='subscribers'>($archived)</span>";
1489 if ($line["site_url"]) {
1490 $site_url = "<a target=\"_blank\" href=\"$site_url\">
1491 <img style='border-width : 0px' src='images/www.png' alt='www'></a>";
1496 $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
1497 style='border-width : 0px; vertical-align : middle'
1498 src='images/feed-icon-12x12.png'></a>";
1500 print "<li title='".$line['site_url']."' class='$class'
1501 id=\"FBROW-".$line["id"]."\">".
1502 $check_box . "$feed_icon $feed_url " . $title .
1503 $archived . $site_url . "</li>";
1511 if ($feedctr == 0) {
1512 print "<li style=\"text-align : center\"><p>".__('No feeds found.')."</p></li>";