]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
tweak display of tweet button
[tt-rss.git] / backend.php
index 8b1454ad74e2c84c6ff3debaaf7591649f040eb4..c64ceaa977fef9b427f12311663e53d5dd331e34 100644 (file)
@@ -50,7 +50,8 @@
 
        if ((!$op || $op == "rpc" || $op == "rss" || 
                        ($op == "view" && $mode != "zoom") || 
-                       $op == "digestSend" || $op == "viewfeed" || $op == "publish" ||
+                       $op == "digestSend" || $op == "dlg" || 
+                       $op == "viewfeed" || $op == "publish" ||
                        $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
                                header("Content-Type: application/xml; charset=utf-8");
 
        $update_methods = array(
                0   => __("Default"),
                1   => __("Magpie"),
-               2   => __("SimplePie"));
+               2   => __("SimplePie"), 
+               3   => __("Twitter OAuth"));
 
        if (DEFAULT_UPDATE_METHOD == "1") {
                $update_methods[0] .= ' (SimplePie)';
                break; // rpc
 
                case "feeds":
-                       if (ENABLE_GZIP_OUTPUT) {
-                               ob_start("ob_gzhandler");
-                       }
-
-                       $tags = $_REQUEST["tags"];
-
                        $subop = $_REQUEST["subop"];
+                       $root = (bool)$_REQUEST["root"];
 
                        switch($subop) {
                                case "catchupAll":
 
                                case "collapse":
                                        $cat_id = db_escape_string($_REQUEST["cid"]);
-                                       toggle_collapse_cat($link, $cat_id);
+                                       $mode = (int) db_escape_string($_REQUEST['mode']);
+                                       toggle_collapse_cat($link, $cat_id, $mode);
                                        return;
                                break;
+                       }
 
-                               case "catsortreset":
-                                       db_query($link, "UPDATE ttrss_feed_categories 
-                                                       SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
-                                       return;
-                               break;
+                       if (!$root) {
+                               print json_encode(outputFeedList($link));
+                       } else {
 
-                               case "catsort":
-                                       $corder = db_escape_string($_REQUEST["corder"]);
+                               $feeds = outputFeedList($link, false);
 
-                                       $cats = split(",", $corder);
+                               $root = array();
+                               $root['id'] = 'root';
+                               $root['name'] = __('Feeds');
+                               $root['items'] = $feeds['items'];
 
-                                       for ($i = 0; $i < count($cats); $i++) {
-                                               $cat_id = $cats[$i];
+                               $fl = array();
+                               $fl['identifier'] = 'id';
+                               $fl['label'] = 'name';
+                               $fl['items'] = array($root);
 
-                                               if ($cat_id > 0) {
-                                                       db_query($link, "UPDATE ttrss_feed_categories 
-                                                               SET order_id = '$i' WHERE id = '$cat_id' AND
-                                                               owner_uid = " . $_SESSION["uid"]);
-                                               }
-                                       }
+                               print json_encode($fl);
+                       }
 
-                                       return;
-                               break;
+               break; // feeds
 
-                       }
+               case "la":
+                       $id = db_escape_string($_REQUEST['id']);
 
-                       $_SESSION["viewfeed:counters_stamp"] = time();
+                       $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
+                               WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
 
-                       outputFeedList($link, $tags);
-               break; // feeds
+                       if (db_num_rows($result) == 1) {
+                               $article_url = db_fetch_result($result, 0, 'link');
+                               $article_url = str_replace("\n", "", $article_url);
+
+                               header("Location: $article_url");
+                               return;
+
+                       } else {
+                               print_error(__("Article not found."));
+                       }
+               break;
 
                case "view":
 
                        $mode = db_escape_string($_REQUEST["mode"]);
                        $omode = db_escape_string($_REQUEST["omode"]);
 
-                       $csync = $_REQUEST["csync"];
-
-                       print "<reply>";
+                       if ($mode != "zoom") print "<reply>";
 
                        // in prefetch mode we only output requested cids, main article 
                        // just gets marked as read (it already exists in client cache)
                                }
                        }
 
-//                     if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
-
-                       if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
+                       /* if ($mode == "prefetch") {
                                print "<counters><![CDATA[";
                                print json_encode(getAllCounters($link, $omode));
                                print "]]></counters>";
-                               $_SESSION["view:counters_stamp"] = time();
-                       }
+                       } */
 
-                       print "</reply>";
+                       if ($mode != "zoom") print "</reply>";
                break; // view
 
                case "viewfeed":
                        @$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"]);
 
                        /* Feed -5 is a special case: it is used to display auxiliary information
                        /* 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();
-//                     }
+                       if ($feed >= 0) {
+                               ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
+                       }
 
                        set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
                        set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
                        }
 
                        if (!$next_unread_feed) {
-                               print "<headlines id=\"$feed\" is_cat=\"$cat_view\"><![CDATA[";
+                               print "<headlines id=\"$feed\" is_cat=\"$cat_view\">";
                        } else {
-                               print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\"><![CDATA[";
+                               print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\">";
                        }
                
                        $override_order = false;
 
+                       if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
+                               $date_sort_field = "updated";
+                       } else {
+                               $date_sort_field = "date_entered";
+                       }
+
                        switch ($order_by) {
                                case "date":
                                        if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
-                                               $override_order = "date_entered";
+                                               $override_order = "$date_sort_field";
                                        } else {        
-                                               $override_order = "date_entered DESC";
+                                               $override_order = "$date_sort_field DESC";
                                        }
                                        break;
 
                                case "title":
                                        if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
-                                               $override_order = "title DESC, date_entered";
+                                               $override_order = "title DESC, $date_sort_field";
                                        } else {
-                                               $override_order = "title, date_entered DESC";
+                                               $override_order = "title, $date_sort_field DESC";
                                        }
                                        break;
 
                                case "score":
                                        if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) {
-                                               $override_order = "score, date_entered";
+                                               $override_order = "score, $date_sort_field";
                                        } else {
-                                               $override_order = "score DESC, date_entered DESC";
+                                               $override_order = "score DESC, $date_sort_field DESC";
                                        }
                                        break;
                        }
 
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
+
                        $ret = outputHeadlinesList($link, $feed, $subop, 
                                $view_mode, $limit, $cat_view, $next_unread_feed, $offset, 
                                $vgroup_last_feed, $override_order);
                        $disable_cache = $ret[3];
                        $vgroup_last_feed = $ret[4];
 
-                       print "]]></headlines>";
+                       print "</headlines>";
+
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
 
                        //print "<headlines-count value=\"$headlines_count\"/>";
                        //print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
 
                        if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
 
-                       if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop || 
-                               time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
-                               if (!$offset) {
-                                       print "<counters><![CDATA[";
-                                       print json_encode(getAllCounters($link, $omode, $feed));
-                                       print "]]></counters>";
-                                       $_SESSION["viewfeed:counters_stamp"] = time();
-                               }
-                       }
+                       //if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop) {
+                       if ($subop) {
+                               print "<counters><![CDATA[";
+                               print json_encode(getAllCounters($link, $omode, $feed));
+                               print "]]></counters>";
+                       } 
 
                        if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);