2 error_reporting(E_ERROR | E_WARNING | E_PARSE
);
4 require_once "sessions.php";
5 require_once "modules/backend-rpc.php";
7 /* if ($_GET["debug"]) {
8 define('DEFAULT_ERROR_LEVEL', E_ALL);
10 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
13 error_reporting(DEFAULT_ERROR_LEVEL); */
15 define('SCHEMA_VERSION', 13);
17 require_once "sanity_check.php";
18 require_once "config.php";
20 require_once "db.php";
21 require_once "db-prefs.php";
22 require_once "functions.php";
24 no_cache_incantation();
26 $script_started = getmicrotime();
28 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
31 if (DB_TYPE
== "mysql") {
34 // PG seems to display its own errors just fine by default.
38 if (DB_TYPE
== "pgsql") {
39 pg_query("set client_encoding = 'UTF-8'");
40 pg_set_client_encoding("UNICODE");
43 $op = $_REQUEST["op"];
45 $print_exec_time = false;
47 if ((!$op ||
$op == "rpc" ||
$op == "rss" ||
$op == "digestSend" ||
48 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
49 header("Content-Type: application/xml; charset=utf-8");
51 header("Content-Type: text/html; charset=utf-8");
55 header("Content-Type: application/xml");
56 print_error_xml(7); exit;
59 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
60 && $op != "rss" && $op != "getUnread") {
63 print_error_xml(6); die;
67 <p>Error: Not logged in.</p>
68 <script type=\"text/javascript\">
69 if (parent.window != 'undefined') {
70 parent.window.location = \"tt-rss.php\";
72 window.location = \"tt-rss.php\";
81 $purge_intervals = array(
82 0 => __("Use default"),
83 -1 => __("Never purge"),
84 5 => __("1 week old"),
85 14 => __("2 weeks old"),
86 31 => __("1 month old"),
87 60 => __("2 months old"),
88 90 => __("3 months old"));
90 $update_intervals = array(
91 0 => __("Use default"),
92 -1 => __("Disable updates"),
93 30 => __("Each 30 minutes"),
95 240 => __("Each 4 hours"),
96 720 => __("Each 12 hours"),
98 10080 => __("Weekly"));
101 $access_level_names = array(
103 10 => __("Administrator"));
105 require_once "modules/pref-prefs.php";
106 require_once "modules/popup-dialog.php";
107 require_once "modules/help.php";
108 require_once "modules/pref-feeds.php";
109 require_once "modules/pref-filters.php";
110 require_once "modules/pref-labels.php";
111 require_once "modules/pref-users.php";
112 require_once "modules/pref-feed-browser.php";
115 if (!sanity_check($link)) { return; }
118 handle_rpc_request($link);
121 if ($op == "feeds") {
123 $tags = $_GET["tags"];
125 $subop = $_GET["subop"];
127 if ($subop == "catchupAll") {
128 db_query($link, "UPDATE ttrss_user_entries SET
129 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
132 if ($subop == "collapse") {
133 $cat_id = db_escape_string($_GET["cid"]);
135 db_query($link, "UPDATE ttrss_feed_categories SET
136 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
141 outputFeedList($link, $tags);
147 $id = db_escape_string($_GET["id"]);
148 $feed_id = db_escape_string($_GET["feed"]);
150 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
151 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
153 if (db_num_rows($result) == 1) {
154 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
156 $rtl_content = false;
160 $rtl_tag = "dir=\"RTL\"";
167 $result = db_query($link, "UPDATE ttrss_user_entries
168 SET unread = false,last_read = NOW()
169 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
171 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
172 SUBSTRING(updated,1,16) as updated,
173 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
176 FROM ttrss_entries,ttrss_user_entries
177 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
183 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
184 $link_target = "target=\"_new\"";
187 $line = db_fetch_assoc($result);
189 if ($line["icon_url"]) {
190 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
192 $feed_icon = " ";
195 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
196 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
198 $entry_comments = "";
201 $num_comments = $line["num_comments"];
202 $entry_comments = "";
204 if ($num_comments > 0) {
205 if ($line["comments"]) {
206 $comments_url = $line["comments"];
208 $comments_url = $line["link"];
210 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
212 if ($line["comments"] && $line["link"] != $line["comments"]) {
213 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
217 print "<div class=\"postReply\">";
219 print "<div class=\"postHeader\">";
221 $entry_author = $line["author"];
224 $entry_author = __(" - by ") . $entry_author;
227 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
228 strtotime($line["updated"]));
230 print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
233 print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" .
234 $line["title"] . "</a>$entry_author</div>";
236 print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
239 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
240 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
248 while ($tmp_line = db_fetch_assoc($tmp_result)) {
250 $tag = $tmp_line["tag_name"];
251 $tag_str = "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
253 if ($num_tags == 6) {
254 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
255 } else if ($num_tags < 6) {
256 $tags_str .= $tag_str;
258 $f_tags_str .= $tag_str;
261 $tags_str = preg_replace("/, $/", "", $tags_str);
262 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
264 if (!$entry_comments) $entry_comments = " "; # placeholder
266 if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
268 print "<div style='float : right'>$tags_str
269 <a title=\"Edit tags for this article\"
270 href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
271 <div clear='both'>$entry_comments</div>";
275 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
276 print "<div class=\"postContent\">";
278 if (db_num_rows($tmp_result) > 0) {
279 print "<div id=\"allEntryTags\">".__('Tags:')."$f_tags_str</div>";
282 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
283 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
286 $line["content"] = sanitize_rss($line["content"]);
288 print $line["content"] . "</div>";
295 if ($op == "viewfeed") {
297 $feed = db_escape_string($_GET["feed"]);
298 $subop = db_escape_string($_GET["subop"]);
299 $view_mode = db_escape_string($_GET["view_mode"]);
300 $limit = db_escape_string($_GET["limit"]);
301 $cat_view = db_escape_string($_GET["cat"]);
302 $next_unread_feed = db_escape_string($_GET["nuf"]);
303 $offset = db_escape_string($_GET["skip"]);
305 if (!$offset) $offset = 0;
307 if ($subop == "undefined") $subop = "";
309 if ($subop == "CatchupSelected") {
310 $ids = split(",", db_escape_string($_GET["ids"]));
311 $cmode = sprintf("%d", $_GET["cmode"]);
313 catchupArticlesById($link, $ids, $cmode);
316 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
317 update_generic_feed($link, $feed, $cat_view);
320 if ($subop == "MarkAllRead") {
321 catchup_feed($link, $feed, $cat_view);
323 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
324 if ($next_unread_feed) {
325 $feed = $next_unread_feed;
331 $result = db_query($link,
332 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
334 if (db_num_rows($result) == 0) {
335 print "<div align='center'>".__('Feed not found.')."</div>";
340 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
342 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
343 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
345 if (db_num_rows($result) == 1) {
346 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
348 $rtl_content = false;
352 $rtl_tag = "dir=\"RTL\"";
358 $rtl_content = false;
361 $script_dt_add = get_script_dt_add();
363 /* print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
364 <script type=\"text/javascript\" src=\"prototype.js\"></script>
365 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
366 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
367 <!--[if gte IE 5.5000]>
368 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
369 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
371 </head><body $rtl_tag>
372 <script type=\"text/javascript\">
373 if (document.addEventListener) {
374 document.addEventListener(\"DOMContentLoaded\", init, null);
376 window.onload = init;
379 /// START /////////////////////////////////////////////////////////////////////////////////
381 $search = db_escape_string($_GET["query"]);
382 $search_mode = db_escape_string($_GET["search_mode"]);
383 $match_on = db_escape_string($_GET["match_on"]);
389 $real_offset = $offset * $limit;
391 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
392 $search, $search_mode, $match_on, false, $real_offset);
394 $result = $qfh_ret[0];
395 $feed_title = $qfh_ret[1];
396 $feed_site_url = $qfh_ret[2];
397 $last_error = $qfh_ret[3];
399 /// STOP //////////////////////////////////////////////////////////////////////////////////
401 print "<div id=\"headlinesContainer\" $rtl_tag>";
404 print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
408 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
409 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
412 print "<div id=\"headlinesInnerContainer\">";
414 if (db_num_rows($result) > 0) {
416 # print "\{$offset}";
418 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
419 print "<table class=\"headlinesList\" id=\"headlinesList\"
420 cellspacing=\"0\" width=\"100%\">";
425 error_reporting (DEFAULT_ERROR_LEVEL
);
429 while ($line = db_fetch_assoc($result)) {
431 $class = ($lnum %
2) ?
"even" : "odd";
434 $feed_id = $line["feed_id"];
436 if ($line["last_read"] == "" &&
437 ($line["unread"] != "t" && $line["unread"] != "1")) {
439 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
442 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
446 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
454 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
455 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
457 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
459 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
461 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
464 # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
465 # $line["title"] . "</a>";
467 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
468 $line["title"] . "</a>";
470 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
471 # $line["title"] . "</a>";
473 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
474 $updated_fmt = smart_date_time(strtotime($line["updated"]));
476 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
477 $updated_fmt = date($short_date, strtotime($line["updated"]));
480 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
481 $content_preview = truncate_string(strip_tags($line["content_preview"]),
485 $entry_author = $line["author"];
488 $entry_author = " - by $entry_author";
491 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
493 print "<tr class='$class' id='RROW-$id'>";
495 print "<td class='hlUpdatePic'>$update_pic</td>";
497 print "<td class='hlSelectRow'>
498 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
499 class=\"feedCheckBox\" id=\"RCHK-$id\">
502 print "<td class='hlMarkedPic'>$marked_pic</td>";
504 if ($line["feed_title"]) {
505 print "<td class='hlContent'>$content_link</td>";
506 print "<td class='hlFeed'>
507 <a href=\"javascript:viewfeed($feed_id, '', false)\">".
508 $line["feed_title"]."</a> </td>";
510 print "<td class='hlContent' valign='middle'>";
512 print "<a href=\"javascript:view($id,$feed_id);\">" .
515 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
516 if ($content_preview) {
517 print "<span class=\"contentPreview\"> - $content_preview</span>";
525 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
532 $add_class = "Unread";
537 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
539 print "<div class=\"cdmHeader\">";
541 print "<div class=\"articleUpdated\">$updated_fmt</div>";
543 print "<a class=\"title\"
544 onclick=\"javascript:toggleUnread($id, 0)\"
545 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
549 if ($line["feed_title"]) {
550 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
555 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
557 print "<div class=\"cdmFooter\">";
561 print "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
562 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
564 $tags = get_article_tags($link, $id);
568 foreach ($tags as $tag) {
570 $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
573 $tags_str = preg_replace("/, $/", "", $tags_str);
575 if ($tags_str == "") $tags_str = "no tags";
577 print " $tags_str <a title=\"Edit tags for this article\"
578 href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>";
582 # print "<div align=\"center\"><a class=\"cdmToggleLink\"
583 # href=\"javascript:toggleUnread($id)\">
584 # Toggle unread</a></div>";
593 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
597 // print_headline_subtoolbar($link,
598 // "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
602 print "<div class='whiteBox'>".__('No articles found.')."</div>";
610 if ($op == "pref-feeds") {
611 module_pref_feeds($link);
614 if ($op == "pref-filters") {
615 module_pref_filters($link);
618 if ($op == "pref-labels") {
619 module_pref_labels($link);
622 if ($op == "pref-prefs") {
623 module_pref_prefs($link);
626 if ($op == "pref-users") {
627 module_pref_users($link);
635 module_popup_dialog($link);
638 // update feeds of all users, may be used anonymously
639 if ($op == "globalUpdateFeeds") {
641 $result = db_query($link, "SELECT id FROM ttrss_users");
643 while ($line = db_fetch_assoc($result)) {
644 $user_id = $line["id"];
645 // print "<!-- updating feeds of uid $user_id -->";
646 update_all_feeds($link, false, $user_id);
650 <message msg=\"All feeds updated\"/>
655 if ($op == "user-details") {
657 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
661 /* print "<html><head>
662 <title>Tiny Tiny RSS : User Details</title>
663 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
664 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
667 $uid = sprintf("%d", $_GET["id"]);
669 print "<div id=\"infoBoxTitle\">User details</div>";
671 print "<div class='infoBoxContents'>";
673 $result = db_query($link, "SELECT login,
674 SUBSTRING(last_login,1,16) AS last_login,
676 (SELECT COUNT(int_id) FROM ttrss_user_entries
677 WHERE owner_uid = id) AS stored_articles
681 if (db_num_rows($result) == 0) {
682 print "<h1>User not found</h1>";
686 # print "<h1>User Details</h1>";
688 $login = db_fetch_result($result, 0, "login");
690 # print "<h1>$login</h1>";
692 print "<table width='100%'>";
694 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
695 strtotime(db_fetch_result($result, 0, "last_login")));
696 $access_level = db_fetch_result($result, 0, "access_level");
697 $stored_articles = db_fetch_result($result, 0, "stored_articles");
699 # print "<tr><td>Username</td><td>$login</td></tr>";
700 # print "<tr><td>Access level</td><td>$access_level</td></tr>";
701 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
702 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
704 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
705 WHERE owner_uid = '$uid'");
707 $num_feeds = db_fetch_result($result, 0, "num_feeds");
709 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
711 /* $result = db_query($link, "SELECT
712 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
713 FROM ttrss_user_entries,ttrss_entries
714 WHERE owner_uid = '$uid' AND ref_id = id");
716 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
718 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
722 print "<h1>Subscribed feeds</h1>";
724 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
725 WHERE owner_uid = '$uid' ORDER BY title");
727 print "<ul class=\"userFeedList\">";
731 while ($line = db_fetch_assoc($result)) {
733 $icon_file = ICONS_URL
."/".$line["id"].".ico";
735 if (file_exists($icon_file) && filesize($icon_file) > 0) {
736 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
738 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
741 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
743 $row_class = toggleEvenOdd($row_class);
747 if (db_num_rows($result) < $num_feeds) {
748 // FIXME - add link to show ALL subscribed feeds here somewhere
750 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
757 print "<div align='center'>
758 <input type='submit' class='button'
759 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
761 // print "</body></html>";
765 if ($op == "pref-feed-browser") {
766 module_pref_feed_browser($link);
770 $feed = db_escape_string($_GET["id"]);
771 $user = db_escape_string($_GET["user"]);
772 $pass = db_escape_string($_GET["pass"]);
773 $is_cat = $_GET["is_cat"] != false;
775 $search = db_escape_string($_GET["q"]);
776 $match_on = db_escape_string($_GET["m"]);
777 $search_mode = db_escape_string($_GET["smode"]);
779 if (!$_SESSION["uid"] && $user && $pass) {
780 authenticate_user($link, $user, $pass);
783 if ($_SESSION["uid"] ||
784 http_authenticate_user($link)) {
786 generate_syndicated_feed($link, $feed, $is_cat,
787 $search, $search_mode, $match_on);
791 if ($op == "labelFromSearch") {
792 $search = db_escape_string($_GET["search"]);
793 $search_mode = db_escape_string($_GET["smode"]);
794 $match_on = db_escape_string($_GET["match"]);
795 $is_cat = db_escape_string($_GET["is_cat"]);
796 $title = db_escape_string($_GET["title"]);
797 $feed = sprintf("%d", $_GET["feed"]);
799 $label_qparts = array();
801 $search_expr = getSearchSql($search, $match_on);
805 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
807 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
810 if ($search_mode == "all_feeds") {
812 } else if ($search_mode == "this_cat") {
814 $tmp_result = db_query($link, "SELECT cat_id
815 FROM ttrss_feeds WHERE id = '$feed'");
817 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
820 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
822 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
825 $search_expr .= " AND ttrss_feeds.id = $feed ";
830 $search_expr = db_escape_string($search_expr);
835 $result = db_query($link,
836 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
837 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
841 if ($op == "getUnread") {
842 $login = db_escape_string($_GET["login"]);
844 header("Content-Type: text/plain; charset=utf-8");
846 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
848 if (db_num_rows($result) == 1) {
849 $uid = db_fetch_result($result, 0, "id");
850 print getGlobalUnread($link, $uid);
852 print "-1;User not found";
855 $print_exec_time = false;
858 if ($op == "digestTest") {
859 header("Content-Type: text/plain");
860 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
861 $print_exec_time = false;
865 if ($op == "digestSend") {
866 header("Content-Type: text/plain");
867 send_headlines_digests($link);
868 $print_exec_time = false;
875 <?php
if ($print_exec_time) { ?
>
876 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->