]> git.wh0rd.org Git - tt-rss.git/commitdiff
rpc: no longer use XML
authorAndrew Dolgov <fox@fakecake.org>
Fri, 18 Mar 2011 16:12:38 +0000 (19:12 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 18 Mar 2011 16:19:00 +0000 (19:19 +0300)
backend.php
modules/backend-rpc.php

index d13b2d62a474481048c386ba1ab967787e898b02..016e1898687ac95168ca479651d7f50311e3bcd1 100644 (file)
 
        $print_exec_time = false;
 
-       if ((!$op || $op == "rpc" || $op == "rss" ||
-                       $op == "digestSend" || $op == "dlg" ||
-                       $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
-                               header("Content-Type: application/xml; charset=utf-8");
-
-               } else {
-               if (!$_REQUEST["noxml"]) {
-                       header("Content-Type: text/html; charset=utf-8");
-               } else {
+       if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) {
+                       header("Content-Type: application/xml; charset=utf-8");
+       } else {
                        header("Content-Type: text/plain; charset=utf-8");
-               }
        }
 
        if (ENABLE_GZIP_OUTPUT) {
                break; // pref-pub-items
 
                case "globalUpdateFeeds":
-                       // update feeds of all users, may be used anonymously
-
-                       print "<!--";
                        // Update all feeds needing a update.
                        update_daemon_common($link, 0, true, true);
-                       print " -->";
-
-                       print "<rpc-reply>
-                               <message msg=\"All feeds updated\"/>
-                       </rpc-reply>";
                break; // globalUpdateFeeds
 
                case "pref-feed-browser":
                        $login = db_escape_string($_REQUEST["login"]);
                        $fresh = $_REQUEST["fresh"] == "1";
 
-                       header("Content-Type: text/plain; charset=utf-8");
-
                        $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
 
                        if (db_num_rows($result) == 1) {
                break; // getUnread
 
                case "digestTest":
-                       header("Content-Type: text/plain");
                        print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
                        $print_exec_time = false;
                break; // digestTest
 
                case "digestSend":
-                       header("Content-Type: text/plain");
                        send_headlines_digests($link);
                        $print_exec_time = false;
                break; // digestSend
index ea1867e0c4e2dc04739434f40f5896d1ff81b94a..1810d585e75c8363d5cd150796710154d6865db5 100644 (file)
                }
 
                if ($subop == "addfeed") {
-                       header("Content-Type: text/plain");
-
                        $feed = db_escape_string($_REQUEST['feed']);
                        $cat = db_escape_string($_REQUEST['cat']);
                        $login = db_escape_string($_REQUEST['login']);
                }
 
                if ($subop == "extractfeedurls") {
-                       header("Content-Type: text/plain");
 
                        $urls = get_feeds_from_html($_REQUEST['url']);
 
                }
 
                if ($subop == "togglepref") {
-                       header("Content-Type: text/plain");
-
                        $key = db_escape_string($_REQUEST["key"]);
                        set_pref($link, $key, !get_pref($link, $key));
                        $value = get_pref($link, $key);
                }
 
                if ($subop == "setpref") {
-                       header("Content-Type: text/plain");
-
                        $value = str_replace("\n", "<br/>", $_REQUEST['value']);
 
                        $key = db_escape_string($_REQUEST["key"]);
                }
 
                if ($subop == "mark") {
-                       header("Content-Type: text/plain");
-
                        $mark = $_REQUEST["mark"];
                        $id = db_escape_string($_REQUEST["id"]);
 
                }
 
                if ($subop == "delete") {
-                       header("Content-Type: text/plain");
-
                        $ids = db_escape_string($_REQUEST["ids"]);
 
                        $result = db_query($link, "DELETE FROM ttrss_user_entries
                }
 
                if ($subop == "unarchive") {
-                       header("Content-Type: text/plain");
-
                        $ids = db_escape_string($_REQUEST["ids"]);
 
                        $result = db_query($link, "UPDATE ttrss_user_entries
                }
 
                if ($subop == "archive") {
-                       header("Content-Type: text/plain");
-
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
                        foreach ($ids as $id) {
                }
 
                if ($subop == "publ") {
-                       header("Content-Type: text/plain");
-
                        $pub = $_REQUEST["pub"];
                        $id = db_escape_string($_REQUEST["id"]);
                        $note = trim(strip_tags(db_escape_string($_REQUEST["note"])));
                } */
 
                if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
-
-                       header("Content-Type: text/plain");
-
                        $last_article_id = (int) $_REQUEST["last_article_id"];
 
                        $reply = array();
 
                /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
                if ($subop == "catchupSelected") {
-                       header("Content-Type: text/plain");
-
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                        $cmode = sprintf("%d", $_REQUEST["cmode"]);
 
                }
 
                if ($subop == "markSelected") {
-                       header("Content-Type: text/plain");
-
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                        $cmode = sprintf("%d", $_REQUEST["cmode"]);
 
                }
 
                if ($subop == "publishSelected") {
-                       header("Content-Type: text/plain");
-
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                        $cmode = sprintf("%d", $_REQUEST["cmode"]);
 
                }
 
                if ($subop == "sanityCheck") {
-                       header("Content-Type: text/plain");
-
                        $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
 
                        $reply = array();
                } */
 
                if ($subop == "setArticleTags") {
-                       header("Content-Type: text/plain");
-
                        global $memcache;
 
                        $id = db_escape_string($_REQUEST["id"]);
                }
 
                if ($subop == "regenOPMLKey") {
-                       header("Content-Type: text/plain");
-
                        update_feed_access_key($link, 'OPML:Publish',
                                false, $_SESSION["uid"]);
 
                        return;
                }
 
-               // XML method
-               if ($subop == "logout") {
-                       logout_user();
-                       print_error_xml(6);
-                       return;
-               }
-
                if ($subop == "completeTags") {
-                       header("Content-Type: text/plain");
-
                        $search = db_escape_string($_REQUEST["search"]);
 
                        $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
                } */
 
                if ($subop == "getArticles") {
-                       header("Content-Type: text/plain");
-
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                        $articles = array();
 
                }
 
                if ($subop == "checkDate") {
-                       header("Content-Type: text/plain");
-
                        $date = db_escape_string($_REQUEST["date"]);
                        $date_parsed = strtotime($date);
 
                }
 
                if ($subop == "assignToLabel" || $subop == "removeFromLabel") {
-                       header("Content-Type: text/plain");
-
                        $reply = array();
 
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                }
 
                if ($subop == "updateFeedBrowser") {
-                       header("Content-Type: text/plain");
-
                        $search = db_escape_string($_REQUEST["search"]);
                        $limit = db_escape_string($_REQUEST["limit"]);
                        $mode = (int) db_escape_string($_REQUEST["mode"]);
                }
 
                if ($subop == "digest-get-contents") {
-                       header("Content-Type: text/plain");
-
                        $article_id = db_escape_string($_REQUEST['article_id']);
 
                        $result = db_query($link, "SELECT content
                }
 
                if ($subop == "digest-update") {
-                       header("Content-Type: text/plain");
-
                        $feed_id = db_escape_string($_REQUEST['feed_id']);
                        $offset = db_escape_string($_REQUEST['offset']);
                        $seq = db_escape_string($_REQUEST['seq']);
                }
 
                if ($subop == "digest-init") {
-                       header("Content-Type: text/plain");
-
                        $tmp_feeds = api_get_feeds($link, -3, true, false, 0);
 
                        $feeds = array();
                }
 
                if ($subop == "sendEmail") {
-                       header("Content-Type: text/plain");
-
                        $secretkey = $_REQUEST['secretkey'];
 
                        $reply = array();
                }
 
                if ($subop == "completeEmails") {
-                       header("Content-Type: text/plain");
-
                        $search = db_escape_string($_REQUEST["search"]);
 
                        print "<ul>";
                }
 
                if ($subop == "quickAddCat") {
-                       header("Content-Type: text/plain");
-
                        $cat = db_escape_string($_REQUEST["cat"]);
 
                        add_feed_category($link, $cat);
                }
 
                if ($subop == "regenFeedKey") {
-                       header("Content-Type: text/plain");
-
                        $feed_id = db_escape_string($_REQUEST['id']);
                        $is_cat = (bool) db_escape_string($_REQUEST['is_cat']);
 
                }
 
                if ($subop == "verifyRegexp") {
-                       header("Content-Type: text/plain");
-
                        $reg_exp = $_REQUEST["reg_exp"];
 
                        $status = @preg_match("/$reg_exp/i", "TEST") !== false;
 
                // TODO: unify with digest-get-contents?
                if ($subop == "cdmGetArticle") {
-                       header("Content-Type: text/plain");
-
                        $id = db_escape_string($_REQUEST["id"]);
 
                        $result = db_query($link, "SELECT content,
                }
 
                if ($subop == "scheduleFeedUpdate") {
-                       header("Content-Type: text/plain");
-
                        $feed_id = db_escape_string($_REQUEST["id"]);
                        $is_cat =  db_escape_string($_REQUEST['is_cat']) == 'true';
 
                }
 
                if ($subop == "getTweetInfo") {
-                       header("Content-Type: text/plain");
                        $id = db_escape_string($_REQUEST['id']);
 
                        $result = db_query($link, "SELECT title, link
                }
 
                if ($subop == "setNote") {
-                       header("Content-Type: text/plain");
-
                        $id = db_escape_string($_REQUEST["id"]);
                        $note = strip_tags(db_escape_string($_REQUEST["note"]));
 
                        return;
                }
 
-               print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
+               print json_encode(array("error" => array("code" => 7,
+                       "message" => "Unknown method: $subop")));
        }
 ?>