- require_once "modules/pref-prefs.php";
- require_once "modules/popup-dialog.php";
- require_once "modules/help.php";
- require_once "modules/pref-feeds.php";
- require_once "modules/pref-filters.php";
- require_once "modules/pref-labels.php";
- require_once "modules/pref-users.php";
-
- if (!sanity_check($link)) { return; }
-
- switch($op) { // Select action according to $op value.
- case "rpc":
- // Handle remote procedure calls.
- handle_rpc_request($link);
- break; // rpc
-
- case "feeds":
- if (ENABLE_GZIP_OUTPUT) {
- ob_start("ob_gzhandler");
- }
-
- $tags = $_REQUEST["tags"];
-
- $subop = $_REQUEST["subop"];
-
- switch($subop) {
- case "catchupAll":
- db_query($link, "UPDATE ttrss_user_entries SET
- last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
- ccache_zero_all($link, $_SESSION["uid"]);
-
- break;
-
- case "collapse":
- $cat_id = db_escape_string($_REQUEST["cid"]);
- toggle_collapse_cat($link, $cat_id);
- return;
- break;
-
- case "catsortreset":
- db_query($link, "UPDATE ttrss_feed_categories
- SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
- return;
- break;
-
- case "catsort":
- $corder = db_escape_string($_REQUEST["corder"]);
-
- $cats = split(",", $corder);
-
- for ($i = 0; $i < count($cats); $i++) {
- $cat_id = $cats[$i];
-
- if ($cat_id > 0) {
- db_query($link, "UPDATE ttrss_feed_categories
- SET order_id = '$i' WHERE id = '$cat_id' AND
- owner_uid = " . $_SESSION["uid"]);
- }
- }
-
- return;
- break;
-
- }
-
- $_SESSION["viewfeed:counters_stamp"] = time();
-
- outputFeedList($link, $tags);
- break; // feeds
-
- case "view":
-
- $id = db_escape_string($_REQUEST["id"]);
- $cids = split(",", db_escape_string($_REQUEST["cids"]));
- $mode = db_escape_string($_REQUEST["mode"]);
- $omode = db_escape_string($_REQUEST["omode"]);
-
- $csync = $_REQUEST["csync"];
-
- print "<reply>";
-
- // in prefetch mode we only output requested cids, main article
- // just gets marked as read (it already exists in client cache)
-
- if ($mode == "") {
- outputArticleXML($link, $id, false);
- } else if ($mode == "zoom") {
- outputArticleXML($link, $id, false, true, true);
- } else {
- catchupArticleById($link, $id, 0);
- }
-
- if (!$_SESSION["bw_limit"]) {
- foreach ($cids as $cid) {
- if ($cid) {
- outputArticleXML($link, $cid, false, false);
- }
- }
- }
-
-// if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
-
- if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
- print "<counters>";
- getAllCounters($link, $omode);
- print "</counters>";
- $_SESSION["view:counters_stamp"] = time();
- }
-
- print "</reply>";
- break; // view
-
- case "viewfeed":
-
- $print_exec_time = true;
- $timing_info = getmicrotime();
-
- print "<reply>";
-
- if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
-
- $omode = db_escape_string($_REQUEST["omode"]);
-
- $feed = db_escape_string($_REQUEST["feed"]);
- $subop = db_escape_string($_REQUEST["subop"]);
- $view_mode = db_escape_string($_REQUEST["view_mode"]);
- $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT");
- $cat_view = db_escape_string($_REQUEST["cat"]);
- $next_unread_feed = db_escape_string($_REQUEST["nuf"]);
- $offset = db_escape_string($_REQUEST["skip"]);
- $vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
- $csync = $_REQUEST["csync"];
- $order_by = db_escape_string($_REQUEST["order_by"]);
-
- /* Updating a label ccache means recalculating all of the caches
- * so for performance reasons we don't do that here */
-
-// if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
- if ($feed >= 0) {
- ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
- }
- $_SESSION["viewfeed:ccache_update_stamp"] = time();
-// }
-
- set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
- set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
- set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
-
- if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
- db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW()
- WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
- }
-
- if (!$next_unread_feed) {
- print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
- } else {
- print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
- }
-
- $override_order = false;
-
- switch ($order_by) {
- case "date":
- if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
- $override_order = "updated";
- } else {
- $override_order = "updated DESC";
- }
- break;
-
- case "title":
- $override_order = "updated DESC";
- break;
-
- case "score":
- $override_order = "score DESC";
- break;
- }
-
- $ret = outputHeadlinesList($link, $feed, $subop,
- $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
- $vgroup_last_feed, $override_order);
-
- $topmost_article_ids = $ret[0];
- $headlines_count = $ret[1];
- $returned_feed = $ret[2];
- $disable_cache = $ret[3];
- $vgroup_last_feed = $ret[4];
-
- print "]]></headlines>";
-
- print "<headlines-count value=\"$headlines_count\"/>";
- print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
-
- $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
- $cat_view, true);
-
- if ($headlines_unread == -1) {
- $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
-
- }
-
- print "<headlines-unread value=\"$headlines_unread\"/>";
- printf("<disable-cache value=\"%d\"/>", $disable_cache);
-
- if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
-
- if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
- print "<articles>";
- foreach ($topmost_article_ids as $id) {
- outputArticleXML($link, $id, $feed, false);
- }
- print "</articles>";
- }
-
- if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);