]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
experimental split of public calls into public.php (refs #389)
[tt-rss.git] / backend.php
index d2c68a64f7d7a5bb846b40894f70f9992576f417..c702c9fb8a0ea76dba1098b278fd367929da666b 100644 (file)
                $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
        }
 
+       $op = $_REQUEST["op"];
+
        require_once "functions.php";
-       require_once "sessions.php";
+       if ($op != "share") require_once "sessions.php";
        require_once "modules/backend-rpc.php";
        require_once "sanity_check.php";
        require_once "config.php";
@@ -40,7 +42,6 @@
 
        init_connection($link);
 
-       $op = $_REQUEST["op"];
        $subop = $_REQUEST["subop"];
        $mode = $_REQUEST["mode"];
 
                authenticate_user($link, "admin", null);
        }
 
-       if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" &&
-                       $op != "rss" && $op != "getUnread" && $op != "getProfiles" &&
-                       $op != "fbexport" && $op != "logout" && $op != "pubsub") {
+       $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
+               "fbexport", "logout", "pubsub");
+
+       if (array_search($op, $public_calls) !== false) {
+
+               handle_public_request($link, $op);
+               return;
 
+       } else if (!($_SESSION["uid"] && validate_session($link))) {
                if ($op == 'pref-feeds' && $_REQUEST['subop'] == 'add') {
                        header("Content-Type: text/html");
                        login_sequence($link);
                        $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"]);
+                       @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
                        @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
                        @$offset = db_escape_string($_REQUEST["skip"]);
                        @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
                        $order_by = db_escape_string($_REQUEST["order_by"]);
 
+                       if (is_numeric($feed)) $feed = (int) $feed;
+
                        /* Feed -5 is a special case: it is used to display auxiliary information
                         * when there's nothing to load - e.g. no stuff in fresh feed */
 
                                $label_feed = -11-$feed;
                                $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE
                                        id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
-                       } else if (!$cat_view && $feed > 0) {
+                       } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
                                $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
                                        id = '$feed' AND owner_uid = " . $_SESSION['uid']);
-                       } else if ($cat_view && $feed > 0) {
+                       } else if ($cat_view && is_numeric($feed) && $feed > 0) {
                                $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE
                                        id = '$feed' AND owner_uid = " . $_SESSION['uid']);
                        }
                        $disable_cache = $ret[3];
                        $vgroup_last_feed = $ret[4];
 
-                       $reply['headlines']['content'] = $ret[5];
-                       $reply['headlines']['toolbar'] = $ret[6];
-
-                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
+//                     if ($_REQUEST["debug"]) print_r($ret);
 
-                       $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
-                                       $cat_view, true);
+                       $reply['headlines']['content'] =& $ret[5]['content'];
+                       $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
 
-                       if ($headlines_unread == -1) {
-                               $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
-                       }
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
 
                        $reply['headlines-info'] = array("count" => (int) $headlines_count,
                                "vgroup_last_feed" => $vgroup_last_feed,
-                               "unread" => (int) $headlines_unread,
                                "disable_cache" => (bool) $disable_cache);
 
                        if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
                                $reply['articles'] = $articles;
                        }
 
-                       if ($subop) {
-                               $reply['counters'] = getAllCounters($link, $omode, $feed);
-                       }
+//                     if ($subop) {
+//                             $reply['counters'] = getAllCounters($link, $omode, $feed);
+//                     }
 
                        if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
 
                        module_pref_pub_items($link);
                break; // pref-pub-items
 
-               case "globalUpdateFeeds":
-                       // Update all feeds needing a update.
-                       update_daemon_common($link, 0, true, true);
-               break; // globalUpdateFeeds
-
                case "pref-feed-browser":
                        module_pref_feed_browser($link);
                break; // pref-feed-browser
                        module_pref_instances($link);
                break; // pref-instances
 
-               case "rss":
-                       $feed = db_escape_string($_REQUEST["id"]);
-                       $key = db_escape_string($_REQUEST["key"]);
-                       $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"]);
-                       $view_mode = db_escape_string($_REQUEST["view-mode"]);
-
-                       if (SINGLE_USER_MODE) {
-                               authenticate_user($link, "admin", null);
-                       }
-
-                       $owner_id = false;
-
-                       if ($key) {
-                               $result = db_query($link, "SELECT owner_uid FROM
-                                       ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
-
-                               if (db_num_rows($result) == 1)
-                                       $owner_id = db_fetch_result($result, 0, "owner_uid");
-                       }
-
-                       if ($owner_id) {
-                               $_SESSION['uid'] = $owner_id;
-
-                               generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
-                                       $search, $search_mode, $match_on, $view_mode);
-                       } else {
-                               header('HTTP/1.1 403 Forbidden');
-                       }
-               break; // rss
-
-               case "getUnread":
-                       $login = db_escape_string($_REQUEST["login"]);
-                       $fresh = $_REQUEST["fresh"] == "1";
-
-                       $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
-
-                       if (db_num_rows($result) == 1) {
-                               $uid = db_fetch_result($result, 0, "id");
-
-                               print getGlobalUnread($link, $uid);
-
-                               if ($fresh) {
-                                       print ";";
-                                       print getFeedArticles($link, -3, false, true, $uid);
-                               }
-
-                       } else {
-                               print "-1;User not found";
-                       }
-
-               break; // getUnread
-
                case "digestTest":
                        print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
                break; // digestTest
                                "<img src='images/indicator_tiny.gif'>";
                break; // loading
 
-               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; // getprofiles
-
-               case "pubsub":
-                       $mode = db_escape_string($_REQUEST['hub_mode']);
-                       $feed_id = db_escape_string($_REQUEST['id']);
-                       $feed_url = db_escape_string($_REQUEST['hub_topic']);
-
-                       // TODO: implement hub_verifytoken checking
-
-                       $result = db_query($link, "SELECT feed_url FROM ttrss_feeds
-                               WHERE id = '$feed_id'");
-
-                       if (db_num_rows($result) != 0) {
-
-                               $check_feed_url = db_fetch_result($result, 0, "feed_url");
-
-                               if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
-                                       if ($mode == "subscribe") {
-
-                                               db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 2
-                                                       WHERE id = '$feed_id'");
-
-                                               print $_REQUEST['hub_challenge'];
-                                               return;
-
-                                       } else if ($mode == "unsubscribe") {
-
-                                               db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 0
-                                                       WHERE id = '$feed_id'");
-
-                                               print $_REQUEST['hub_challenge'];
-                                               return;
-
-                                       } else if (!$mode) {
-
-                                               // Received update ping, schedule feed update.
-
-                                               update_rss_feed($link, $feed_id, true, true);
-
-                                       }
-                               } else {
-                                       header('HTTP/1.0 404 Not Found');
-                                       echo "404 Not found";
-                               }
-                       } else {
-                               header('HTTP/1.0 404 Not Found');
-                               echo "404 Not found";
-                       }
-
-               break; // pubsub
-
-               case "logout":
-                       logout_user();
-                       header("Location: tt-rss.php");
-               break; // logout
-
-               case "fbexport":
-
-                       $access_key = db_escape_string($_POST["key"]);
-
-                       // TODO: rate limit checking using last_connected
-                       $result = db_query($link, "SELECT id FROM ttrss_linked_instances
-                               WHERE access_key = '$access_key'");
-
-                       if (db_num_rows($result) == 1) {
-
-                               $instance_id = db_fetch_result($result, 0, "id");
-
-                               $result = db_query($link, "SELECT feed_url, site_url, title, subscribers
-                                       FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
-
-                               $feeds = array();
-
-                               while ($line = db_fetch_assoc($result)) {
-                                       array_push($feeds, $line);
-                               }
-
-                               db_query($link, "UPDATE ttrss_linked_instances SET
-                                       last_status_in = 1 WHERE id = '$instance_id'");
-
-                               print json_encode(array("feeds" => $feeds));
-                       } else {
-                               print json_encode(array("error" => array("code" => 6)));
-                       }
-               break; // fbexport
-
                default:
                        header("Content-Type: text/plain");
                        print json_encode(array("error" => array("code" => 7)));