]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
pref-prefs: show default update interval as a dropdown
[tt-rss.git] / backend.php
index d68ede30a9817fa96664d14f2f32cd064a7df79f..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);
                return;
        }
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'UTF-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+       init_connection($link);
 
        $op = $_REQUEST["op"];
+       $subop = $_REQUEST["subop"];
+       $mode = $_REQUEST["mode"];
 
        $print_exec_time = false;
 
-       if ((!$op || $op == "rpc" || $op == "rss" || $op == "view" || 
+       if ((!$op || $op == "rpc" || $op == "rss" || 
+                       ($op == "view" && $mode != "zoom") || 
                        $op == "digestSend" || $op == "viewfeed" || $op == "publish" ||
                        $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
-               header("Content-Type: application/xml; charset=utf-8");
+                               header("Content-Type: application/xml; charset=utf-8");
+
+                               if (ENABLE_GZIP_OUTPUT) {
+                                       ob_start("ob_gzhandler");
+                               }
+                               
                } else {
                if (!$_REQUEST["noxml"]) {
                        header("Content-Type: text/html; charset=utf-8");
                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;
                90 => __("3 months old"));
 
        $update_intervals = array(
-               0   => __("Use default"),
+               0   => __("Default interval"),
                -1  => __("Disable updates"),
                15  => __("Each 15 minutes"),
                30  => __("Each 30 minutes"),
                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"),
+               2   => __("SimplePie"));
+
+       if (ENABLE_SIMPLEPIE) {
+               $update_methods[0] .= ' (SimplePie)';
+       } else {
+               $update_methods[0] .= ' (Magpie)';
+       }
 
        $access_level_names = array(
                0 => __("User"), 
+               5 => __("Power User"),
                10 => __("Administrator"));
 
        require_once "modules/pref-prefs.php";
        require_once "modules/pref-filters.php";
        require_once "modules/pref-labels.php";
        require_once "modules/pref-users.php";
-       require_once "modules/pref-feed-browser.php"; 
 
        if (!sanity_check($link)) { return; }
 
-       if ($op == "rpc") {
-               handle_rpc_request($link);
-       }
-       
-       if ($op == "feeds") {
+       switch($op) { // Select action according to $op value.
+               case "rpc":
+                       // Handle remote procedure calls.
+                       handle_rpc_request($link);
+               break; // rpc
 
-               $tags = $_GET["tags"];
+               case "feeds":
+                       if (ENABLE_GZIP_OUTPUT) {
+                               ob_start("ob_gzhandler");
+                       }
 
-               $subop = $_GET["subop"];
+                       $tags = $_REQUEST["tags"];
 
-               if ($subop == "catchupAll") {
-                       db_query($link, "UPDATE ttrss_user_entries SET 
-                               last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
-               }
+                       $subop = $_REQUEST["subop"];
 
-               if ($subop == "collapse") {
-                       $cat_id = db_escape_string($_GET["cid"]);
+                       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"]);
 
-                       db_query($link, "UPDATE ttrss_feed_categories SET
-                               collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . 
-                               $_SESSION["uid"]);
-                       return;
-               }
+                               break;
 
-               outputFeedList($link, $tags);
+                               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;
 
-       if ($op == "view") {
+                               case "catsort":
+                                       $corder = db_escape_string($_REQUEST["corder"]);
 
-               $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"]);
+                                       $cats = split(",", $corder);
 
-               print "<reply>";
+                                       for ($i = 0; $i < count($cats); $i++) {
+                                               $cat_id = $cats[$i];
 
-               // in prefetch mode we only output requested cids, main article 
-               // just gets marked as read (it already exists in client cache)
+                                               if ($cat_id > 0) {
+                                                       db_query($link, "UPDATE ttrss_feed_categories 
+                                                               SET order_id = '$i' WHERE id = '$cat_id' AND
+                                                               owner_uid = " . $_SESSION["uid"]);
+                                               }
+                                       }
 
-               if ($mode == "") {
-                       outputArticleXML($link, $id, $feed_id);
-               } else {
-                       catchupArticleById($link, $id, 0);
-               }
+                                       return;
+                               break;
 
-               foreach ($cids as $cid) {
-                       if ($cid) {
-                               outputArticleXML($link, $cid, $feed_id, false);
                        }
-               }
-
-               if ($mode != "prefetch_old") {
-                       print "<counters>";
-                       getAllCounters($link, $omode);
-                       print "</counters>";
-               }
-
-               print "</reply>";
-       }
-
-       if ($op == "viewfeed") {
-
-               $print_exec_time = true;
-               $timing_info = getmicrotime();
-
-               print "<reply>";
-
-               if ($_GET["debug"]) $timing_info = print_checkpoint("0", $timing_info);
-
-               $omode = db_escape_string($_GET["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"]);
-
-               set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
-               set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
-
-               print "<headlines id=\"$feed\"><![CDATA[";
 
-               $ret = outputHeadlinesList($link, $feed, $subop, 
-                       $view_mode, $limit, $cat_view, $next_unread_feed, $offset);
+                       $_SESSION["viewfeed:counters_stamp"] = time();
 
-               $topmost_article_ids = $ret[0];
-               $headlines_count = $ret[1];
-               $returned_feed = $ret[2];
-               $disable_cache = $ret[3];
+                       outputFeedList($link, $tags);
+               break; // feeds
 
-               print "]]></headlines>";
+               case "view":
 
-               print "<headlines-count value=\"$headlines_count\"/>";
+                       $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"]);
 
-               $headlines_unread = getFeedUnread($link, $returned_feed);
+                       $csync = $_REQUEST["csync"];
 
-               print "<headlines-unread value=\"$headlines_unread\"/>";
-               printf("<disable-cache value=\"%d\"/>", $disable_cache);
+                       print "<reply>";
 
-               if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
+                       // in prefetch mode we only output requested cids, main article 
+                       // just gets marked as read (it already exists in client cache)
 
-               if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE')) {
-                       print "<articles>";
-                       foreach ($topmost_article_ids as $id) {
-                               outputArticleXML($link, $id, $feed, false);
+                       if ($mode == "") {
+                               outputArticleXML($link, $id, false);
+                       } else if ($mode == "zoom") {
+                               outputArticleXML($link, $id, false, true, true);
+                       } else {
+                               catchupArticleById($link, $id, 0);
                        }
-                       print "</articles>";
-               }
-
-               if ($_GET["debug"]) $timing_info = print_checkpoint("20", $timing_info);
-
-               print "<counters>";
-               getAllCounters($link, $omode, $feed);
-               print "</counters>";
-
-               if ($_GET["debug"]) $timing_info = print_checkpoint("30", $timing_info);
-
-               print_runtime_info($link);
-
-               print "</reply>";
-       }
-
-       if ($op == "pref-feeds") {
-               module_pref_feeds($link);
-       }
 
-       if ($op == "pref-filters") {
-               module_pref_filters($link);
-       }
+                       if (!$_SESSION["bw_limit"]) {
+                               foreach ($cids as $cid) {
+                                       if ($cid) {
+                                               outputArticleXML($link, $cid, false, false);
+                                       }
+                               }
+                       }
 
-       if ($op == "pref-labels") {
-               module_pref_labels($link);
-       }
+//                     if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
 
-       if ($op == "pref-prefs") {
-               module_pref_prefs($link);
-       }
+                       if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
+                               print "<counters>";
+                               getAllCounters($link, $omode);
+                               print "</counters>";
+                               $_SESSION["view:counters_stamp"] = time();
+                       }
 
-       if ($op == "pref-users") {
-               module_pref_users($link);
-       }
+                       print "</reply>";
+               break; // view
 
-       if ($op == "help") {
-               module_help($link);
-       }
+               case "viewfeed":
 
-       if ($op == "dlg") {
-               module_popup_dialog($link);
-       }
+                       $print_exec_time = true;
+                       $timing_info = getmicrotime();
 
-       if ($op == "pref-pub-items") {
-               module_pref_pub_items($link);
-       }
+                       print "<reply>";
 
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
 
-       // update feeds of all users, may be used anonymously
-       if ($op == "globalUpdateFeeds") {
+                       $omode = db_escape_string($_REQUEST["omode"]);
 
-               $result = db_query($link, "SELECT id FROM ttrss_users");
+                       $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"]);
 
-               while ($line = db_fetch_assoc($result)) {
-                       $user_id = $line["id"];
-//                     print "<!-- updating feeds of uid $user_id -->";
-                       update_all_feeds($link, false, $user_id);
-               }
+                       /* Updating a label ccache means recalculating all of the caches
+                        * so for performance reasons we don't do that here */
 
-               print "<rpc-reply>
-                       <message msg=\"All feeds updated\"/>
-               </rpc-reply>";
+//                     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 ($op == "user-details") {
+                       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 (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
-                       return;
-               }
-                         
-/*             print "<html><head>
-                       <title>Tiny Tiny RSS : User Details</title>
-                       <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
-                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
-                       </head><body>"; */
-
-               $uid = sprintf("%d", $_GET["id"]);
-
-               print "<div id=\"infoBoxTitle\">User details</div>";
-
-               print "<div class='infoBoxContents'>";
-
-               $result = db_query($link, "SELECT login,
-                       SUBSTRING(last_login,1,16) AS last_login,
-                       access_level,
-                       (SELECT COUNT(int_id) FROM ttrss_user_entries 
-                               WHERE owner_uid = id) AS stored_articles,
-                       SUBSTRING(created,1,16) AS created
-                       FROM ttrss_users 
-                       WHERE id = '$uid'");
-                       
-               if (db_num_rows($result) == 0) {
-                       print "<h1>User not found</h1>";
-                       return;
-               }
+                       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[";
+                       }
                
-#              print "<h1>User Details</h1>";
-
-               $login = db_fetch_result($result, 0, "login");
-
-#              print "<h1>$login</h1>";
-
-               print "<table width='100%'>";
-
-               $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
-                       strtotime(db_fetch_result($result, 0, "last_login")));
-
-               $created = date(get_pref($link, 'LONG_DATE_FORMAT'),
-                       strtotime(db_fetch_result($result, 0, "created")));
+                       $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;
 
-               $access_level = db_fetch_result($result, 0, "access_level");
-               $stored_articles = db_fetch_result($result, 0, "stored_articles");
+                               case "title":
+                                       $override_order = "updated DESC";
+                                       break;
 
-#              print "<tr><td>Username</td><td>$login</td></tr>";
-#              print "<tr><td>Access level</td><td>$access_level</td></tr>";
-               print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
-               print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
-               print "<tr><td>".__('Stored articles')."</td><td>$stored_articles</td></tr>";
+                               case "score":
+                                       $override_order = "score DESC";
+                                       break;
+                       }
 
-               $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
-                       WHERE owner_uid = '$uid'");
+                       $ret = outputHeadlinesList($link, $feed, $subop, 
+                               $view_mode, $limit, $cat_view, $next_unread_feed, $offset, 
+                               $vgroup_last_feed, $override_order);
 
-               $num_feeds = db_fetch_result($result, 0, "num_feeds");
+                       $topmost_article_ids = $ret[0];
+                       $headlines_count = $ret[1];
+                       $returned_feed = $ret[2];
+                       $disable_cache = $ret[3];
+                       $vgroup_last_feed = $ret[4];
 
-               print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
+                       print "]]></headlines>";
 
-/*             $result = db_query($link, "SELECT 
-                       SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size 
-                       FROM ttrss_user_entries,ttrss_entries 
-                               WHERE owner_uid = '$uid' AND ref_id = id");
+                       print "<headlines-count value=\"$headlines_count\"/>";
+                       print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
 
-               $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
+                       $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
+                                       $cat_view, true);
 
-               print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>";  */
+                       if ($headlines_unread == -1) {
+                               $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
 
-               print "</table>";
+                       }
 
-               print "<h1>".__('Subscribed feeds')."</h1>";
+                       print "<headlines-unread value=\"$headlines_unread\"/>";
+                       printf("<disable-cache value=\"%d\"/>", $disable_cache);
 
-               $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
-                       WHERE owner_uid = '$uid' ORDER BY title");
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
 
-               print "<ul class=\"userFeedList\">";
+                       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>";
+                       }
 
-               $row_class = "odd";
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
 
-               while ($line = db_fetch_assoc($result)) {
 
-                       $icon_file = ICONS_URL."/".$line["id"].".ico";
+//                     if (get_pref($link, "SYNC_COUNTERS") ||                         
+//                                     time() - $_SESSION["get_all_counters_stamp"] > $viewfeed_ctr_interval) {
+//                             print "<counters>";
+//                             getAllCounters($link, $omode, $feed);
+//                             print "</counters>";
+//                     }
 
-                       if (file_exists($icon_file) && filesize($icon_file) > 0) {
-                               $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
-                       } else {
-                               $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
+                       if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop || 
+                               time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
+                               if (!$offset) {
+                                       print "<counters>";
+                                       getAllCounters($link, $omode, $feed);
+                                       print "</counters>";
+                                       $_SESSION["viewfeed:counters_stamp"] = time();
+                               }
                        }
 
-                       print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
+                       if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
 
-                       $row_class = toggleEvenOdd($row_class);
+                       print_runtime_info($link);
 
-               }
+                       print "</reply>";
+               break; // viewfeed
 
-               if (db_num_rows($result) < $num_feeds) {
-                        // FIXME - add link to show ALL subscribed feeds here somewhere
-                       print "<li><img 
-                               class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
-               }
-               
-               print "</ul>";
+               case "pref-feeds":
+                       module_pref_feeds($link);
+               break; // pref-feeds
 
-               print "</div>";
+               case "pref-filters":
+                       module_pref_filters($link);
+               break; // pref-filters
 
-               print "<div align='center'>
-                       <input type='submit' class='button'                     
-                       onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
+               case "pref-labels":
+                       module_pref_labels($link);
+               break; // pref-labels
 
-//             print "</body></html>"; 
+               case "pref-prefs":
+                       module_pref_prefs($link);
+               break; // pref-prefs
 
-       }
+               case "pref-users":
+                       module_pref_users($link);
+               break; // prefs-users
 
-       if ($op == "pref-feed-browser") {
-               module_pref_feed_browser($link);
-       }
+               case "help":
+                       module_help($link);
+               break; // help
 
-       if ($op == "publish") {
-               $key = db_escape_string($_GET["key"]);
+               case "dlg":
+                       module_popup_dialog($link);
+               break; // dlg
 
-               $result = db_query($link, "SELECT login, owner_uid 
-                       FROM ttrss_user_prefs, ttrss_users WHERE
-                       pref_name = '_PREFS_PUBLISH_KEY' AND 
-                       value = '$key' AND 
-                       ttrss_users.id = owner_uid");
+               case "pref-pub-items":
+                       module_pref_pub_items($link);
+               break; // pref-pub-items
 
-               if (db_num_rows($result) == 1) {
-                       $owner = db_fetch_result($result, 0, "owner_uid");
-                       $login = db_fetch_result($result, 0, "login");
+               case "globalUpdateFeeds":
+                       // update feeds of all users, may be used anonymously
 
-                       generate_syndicated_feed($link, $owner, -2, false);
+                       print "<!--";
+                       // Update all feeds needing a update.
+                       update_daemon_common($link, 0, true, true);
+                       print " -->";
 
-               } else {
-                       print "<error>User not found</error>";
-               }
+                       print "<rpc-reply>
+                               <message msg=\"All feeds updated\"/>
+                       </rpc-reply>";
+               break; // globalUpdateFeeds
 
-       }
+               case "pref-feed-browser":
+                       module_pref_feed_browser($link);
+               break; // pref-feed-browser
 
-       if ($op == "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;
+               case "publish":
+                       $key = db_escape_string($_REQUEST["key"]);
+                       $limit = (int)db_escape_string($_REQUEST["limit"]);
 
-               $search = db_escape_string($_GET["q"]);
-               $match_on = db_escape_string($_GET["m"]);
-               $search_mode = db_escape_string($_GET["smode"]);
+                       $result = db_query($link, "SELECT login, owner_uid 
+                               FROM ttrss_user_prefs, ttrss_users WHERE
+                               pref_name = '_PREFS_PUBLISH_KEY' AND 
+                               value = '$key' AND 
+                               ttrss_users.id = owner_uid");
 
-               if (!$_SESSION["uid"] && $user && $pass) {
-                       authenticate_user($link, $user, $pass);
-               }
+                       if (db_num_rows($result) == 1) {
+                               $owner = db_fetch_result($result, 0, "owner_uid");
+                               $login = db_fetch_result($result, 0, "login");
 
-               if ($_SESSION["uid"] ||
-                       http_authenticate_user($link)) {
+                               generate_syndicated_feed($link, $owner, -2, false, $limit);
 
-                               generate_syndicated_feed($link, 0, $feed, $is_cat, 
-                                       $search, $search_mode, $match_on);
-               }
+                       } else {
+                               print "<error>User not found</error>";
+                       }
+               break; // publish
 
-       }
+               case "rss":
+                       $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"]);
 
-       if ($op == "labelFromSearch") {
-               $search = db_escape_string($_GET["search"]);
-               $search_mode = db_escape_string($_GET["smode"]);
-               $match_on = db_escape_string($_GET["match"]);
-               $is_cat = db_escape_string($_GET["is_cat"]);
-               $title = db_escape_string($_GET["title"]);
-               $feed = sprintf("%d", $_GET["feed"]);
+                       $search = db_escape_string($_REQUEST["q"]);
+                       $match_on = db_escape_string($_REQUEST["m"]);
+                       $search_mode = db_escape_string($_REQUEST["smode"]);
 
-               $label_qparts = array();
+                       if (SINGLE_USER_MODE) {
+                               authenticate_user($link, "admin", null);
+                       }
 
-               $search_expr = getSearchSql($search, $match_on);
+                       if (!$_SESSION["uid"] && $user && $pass) {
+                               authenticate_user($link, $user, $pass);
+                       }
 
-               if ($is_cat) {
-                       if ($feed != 0) {
-                               $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
-                       } else {
-                               $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
+                       if ($_SESSION["uid"] ||
+                               http_authenticate_user($link)) {
+
+                                       generate_syndicated_feed($link, 0, $feed, $is_cat, $limit,
+                                               $search, $search_mode, $match_on);
                        }
-               } else {
-                       if ($search_mode == "all_feeds") {
-                               // NOOP
-                       } else if ($search_mode == "this_cat") {
+               break; // rss
+
+               case "getUnread":
+                       $login = db_escape_string($_REQUEST["login"]);
 
-                               $tmp_result = db_query($link, "SELECT cat_id
-                                       FROM ttrss_feeds WHERE id = '$feed'");
+                       header("Content-Type: text/plain; charset=utf-8");
 
-                               $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
+                       $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
 
-                               if ($cat_id > 0) {
-                                       $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
-                               } else {
-                                       $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
-                               }
+                       if (db_num_rows($result) == 1) {
+                               $uid = db_fetch_result($result, 0, "id");
+                               print getGlobalUnread($link, $uid);
                        } else {
-                               $search_expr .= " AND ttrss_feeds.id = $feed ";
+                               print "-1;User not found";
                        }
 
-               }
+                       $print_exec_time = false;
+               break; // getUnread
 
-               $search_expr = db_escape_string($search_expr);
+               case "digestTest":
+                       header("Content-Type: text/plain");
+                       print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
+                       $print_exec_time = false;
+               break; // digestTest
 
-               print $search_expr;
+               case "digestSend":
+                       header("Content-Type: text/plain");
+                       send_headlines_digests($link);
+                       $print_exec_time = false;
+               break; // digestSend
 
-               if ($title) {
-                       $result = db_query($link,
-                               "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) 
-                               VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
-               }
-       }
+               case "getProfiles":
+                       $login = db_escape_string($_REQUEST["login"]);
+                       $password = db_escape_string($_REQUEST["password"]);
 
-       if ($op == "getUnread") {
-               $login = db_escape_string($_GET["login"]);
+                       if (authenticate_user($link, $login, $password)) {
+                               $result = db_query($link, "SELECT * FROM ttrss_settings_profiles
+                                       WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
 
-               header("Content-Type: text/plain; charset=utf-8");
+                               print "<select style='width: 100%' name='profile'>";
 
-               $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
+                               print "<option value='0'>" . __("Default profile") . "</option>";
 
-               if (db_num_rows($result) == 1) {
-                       $uid = db_fetch_result($result, 0, "id");
-                       print getGlobalUnread($link, $uid);
-               } else {
-                       print "-1;User not found";
-               }
+                               while ($line = db_fetch_assoc($result)) {
+                                       $id = $line["id"];
+                                       $title = $line["title"];
 
-               $print_exec_time = false;
-       }
+                                       print "<option value='$id'>$title</option>";
+                               }
 
-       if ($op == "digestTest") {
-               header("Content-Type: text/plain");
-               print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
-               $print_exec_time = false;
+                               print "</select>";
 
-       }
+                               $_SESSION = array();
 
-       if ($op == "digestSend") {
-               header("Content-Type: text/plain");
-               send_headlines_digests($link);
-               $print_exec_time = false;
+               break;
+               }
 
-       }
+       } // Select action according to $op value.
 
+       // We close the connection to database.
        db_close($link);
 ?>