]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
pref-prefs: show default update interval as a dropdown
[tt-rss.git] / backend.php
index a87b7f4ff39f14265c14264e8599a2e4d5e1b318..b9b60a5425f9dc478f3e9164c060a81a3ab0b81b 100644 (file)
@@ -4,7 +4,7 @@
        /* remove ill effects of magic quotes */
 
        if (get_magic_quotes_gpc()) {
-               $_GET = array_map('stripslashes', $_GET);
+               $_REQUEST = array_map('stripslashes', $_REQUEST);
                $_POST = array_map('stripslashes', $_POST);
                $_REQUEST = array_map('stripslashes', $_REQUEST);
                $_COOKIE = array_map('stripslashes', $_COOKIE);
@@ -13,7 +13,7 @@
        require_once "sessions.php";
        require_once "modules/backend-rpc.php";
 
-/*     if ($_GET["debug"]) {
+/*     if ($_REQUEST["debug"]) {
                define('DEFAULT_ERROR_LEVEL', E_ALL);
        } else {
                define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
@@ -49,6 +49,7 @@
        init_connection($link);
 
        $op = $_REQUEST["op"];
+       $subop = $_REQUEST["subop"];
        $mode = $_REQUEST["mode"];
 
        $print_exec_time = false;
                header("Content-Type: application/xml");
                print_error_xml(7); exit;
        }
-       
+
+       if (SINGLE_USER_MODE) {
+               authenticate_user($link, "admin", null);
+       }
+
        if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" 
-                       && $op != "rss" && $op != "getUnread" && $op != "publish") {
+               && $op != "rss" && $op != "getUnread" && $op != "publish" && $op != "getProfiles") {
 
                if ($op == "rpc" || $op == "viewfeed" || $op == "view") {
                        print_error_xml(6); die;
                1440 => __("Daily"),
                10080 => __("Weekly"));
 
+       $update_intervals_nodefault = array(
+               -1  => __("Disable updates"),
+               15  => __("Each 15 minutes"),
+               30  => __("Each 30 minutes"),
+               60  => __("Hourly"),
+               240 => __("Each 4 hours"),
+               720 => __("Each 12 hours"),
+               1440 => __("Daily"),
+               10080 => __("Weekly"));
+
        $update_methods = array(
                0   => __("Default"),
                1   => __("Magpie"),
                                ob_start("ob_gzhandler");
                        }
 
-                       $tags = $_GET["tags"];
+                       $tags = $_REQUEST["tags"];
 
-                       $subop = $_GET["subop"];
+                       $subop = $_REQUEST["subop"];
 
                        switch($subop) {
                                case "catchupAll":
                                break;
 
                                case "collapse":
-                                       $cat_id = db_escape_string($_GET["cid"]);
-
-                                       db_query($link, "UPDATE ttrss_feed_categories SET
-                                               collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . 
-                                               $_SESSION["uid"]);
+                                       $cat_id = db_escape_string($_REQUEST["cid"]);
+                                       toggle_collapse_cat($link, $cat_id);
                                        return;
                                break;
 
                                break;
 
                                case "catsort":
-                                       $corder = db_escape_string($_GET["corder"]);
+                                       $corder = db_escape_string($_REQUEST["corder"]);
 
                                        $cats = split(",", $corder);
 
 
                        }
 
+                       $_SESSION["viewfeed:counters_stamp"] = time();
+
                        outputFeedList($link, $tags);
                break; // feeds
 
                case "view":
 
-                       $id = db_escape_string($_GET["id"]);
-                       $feed_id = db_escape_string($_GET["feed"]);
-                       $cids = split(",", db_escape_string($_GET["cids"]));
-                       $mode = db_escape_string($_GET["mode"]);
-                       $omode = db_escape_string($_GET["omode"]);
+                       $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 = $_GET["csync"];
+                       $csync = $_REQUEST["csync"];
 
                        print "<reply>";
 
                        // just gets marked as read (it already exists in client cache)
 
                        if ($mode == "") {
-                               outputArticleXML($link, $id, $feed_id);
+                               outputArticleXML($link, $id, false);
                        } else if ($mode == "zoom") {
-                               outputArticleXML($link, $id, $feed_id, true, true);
+                               outputArticleXML($link, $id, false, true, true);
                        } else {
                                catchupArticleById($link, $id, 0);
-                               ccache_update($link, $feed_id, $_SESSION["uid"]);
                        }
 
                        if (!$_SESSION["bw_limit"]) {
                                foreach ($cids as $cid) {
                                        if ($cid) {
-                                               outputArticleXML($link, $cid, $feed_id, false);
+                                               outputArticleXML($link, $cid, false, false);
                                        }
                                }
                        }
 
 //                     if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
 
-                       if (time() - $_SESSION["view:counters_stamp"] > 3 && $mode == "prefetch") {
+                       if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
                                print "<counters>";
                                getAllCounters($link, $omode);
                                print "</counters>";
 
                        print "<reply>";
 
-                       if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info);
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
 
-                       $omode = db_escape_string($_GET["omode"]);
+                       $omode = db_escape_string($_REQUEST["omode"]);
 
-                       $feed = db_escape_string($_GET["feed"]);
-                       $subop = db_escape_string($_GET["subop"]);
-                       $view_mode = db_escape_string($_GET["view_mode"]);
-                       $limit = db_escape_string($_GET["limit"]);
-                       $cat_view = db_escape_string($_GET["cat"]);
-                       $next_unread_feed = db_escape_string($_GET["nuf"]);
-                       $offset = db_escape_string($_GET["skip"]);
-                       $vgroup_last_feed = db_escape_string($_GET["vgrlf"]);
-                       $csync = $_GET["csync"];
-                       $order_by = db_escape_string($_GET["order_by"]);
+                       $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 */
                        print "<headlines-unread value=\"$headlines_unread\"/>";
                        printf("<disable-cache value=\"%d\"/>", $disable_cache);
 
-                       if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
+                       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>";
                                print "</articles>";
                        }
 
-                       if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info);
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
 
 
 //                     if (get_pref($link, "SYNC_COUNTERS") ||                         
 //                     }
 
                        if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop || 
-                               time() - $_SESSION["viewfeed:counters_stamp"] > 60) {
+                               time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
                                if (!$offset) {
                                        print "<counters>";
                                        getAllCounters($link, $omode, $feed);
                                }
                        }
 
-                       if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info);
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
 
                        print_runtime_info($link);
 
                break; // pref-feed-browser
 
                case "publish":
-                       $key = db_escape_string($_GET["key"]);
-                       $limit = (int)db_escape_string($_GET["limit"]);
+                       $key = db_escape_string($_REQUEST["key"]);
+                       $limit = (int)db_escape_string($_REQUEST["limit"]);
 
                        $result = db_query($link, "SELECT login, owner_uid 
                                FROM ttrss_user_prefs, ttrss_users WHERE
                break; // publish
 
                case "rss":
-                       $feed = db_escape_string($_GET["id"]);
-                       $user = db_escape_string($_GET["user"]);
-                       $pass = db_escape_string($_GET["pass"]);
-                       $is_cat = $_GET["is_cat"] != false;
-                       $limit = (int)db_escape_string($_GET["limit"]);
-
-                       $search = db_escape_string($_GET["q"]);
-                       $match_on = db_escape_string($_GET["m"]);
-                       $search_mode = db_escape_string($_GET["smode"]);
+                       $feed = db_escape_string($_REQUEST["id"]);
+                       $user = db_escape_string($_REQUEST["user"]);
+                       $pass = db_escape_string($_REQUEST["pass"]);
+                       $is_cat = $_REQUEST["is_cat"] != false;
+                       $limit = (int)db_escape_string($_REQUEST["limit"]);
+
+                       $search = db_escape_string($_REQUEST["q"]);
+                       $match_on = db_escape_string($_REQUEST["m"]);
+                       $search_mode = db_escape_string($_REQUEST["smode"]);
+
+                       if (SINGLE_USER_MODE) {
+                               authenticate_user($link, "admin", null);
+                       }
 
                        if (!$_SESSION["uid"] && $user && $pass) {
                                authenticate_user($link, $user, $pass);
                break; // rss
 
                case "getUnread":
-                       $login = db_escape_string($_GET["login"]);
+                       $login = db_escape_string($_REQUEST["login"]);
 
                        header("Content-Type: text/plain; charset=utf-8");
 
                        $print_exec_time = false;
                break; // digestSend
 
+               case "getProfiles":
+                       $login = db_escape_string($_REQUEST["login"]);
+                       $password = db_escape_string($_REQUEST["password"]);
+
+                       if (authenticate_user($link, $login, $password)) {
+                               $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
+                                       WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
+
+                               print "<select style='width: 100%' name='profile'>";
+
+                               print "<option value='0'>" . __("Default profile") . "</option>";
+
+                               while ($line = db_fetch_assoc($result)) {
+                                       $id = $line["id"];
+                                       $title = $line["title"];
+
+                                       print "<option value='$id'>$title</option>";
+                               }
+
+                               print "</select>";
+
+                               $_SESSION = array();
+
+               break;
+               }
+
        } // Select action according to $op value.
 
        // We close the connection to database.