]> git.wh0rd.org Git - tt-rss.git/commitdiff
add simple op=getUnread call to return global unread counter
authorAndrew Dolgov <fox@bah.spb.su>
Sun, 20 Aug 2006 03:35:47 +0000 (04:35 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sun, 20 Aug 2006 03:35:47 +0000 (04:35 +0100)
backend.php
functions.php

index 1b530ac551a41c24a02b059e78049af4c91e872d..36fe325379fd66ef5191a1b6059b933efcb00a85 100644 (file)
                header("Content-Type: application/xml");
        }
 
-       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss") {
+       if (!$op) {
+               header("Content-Type: application/xml");
+               print_error_xml(7); exit;
+       }
+
+       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss" && $op != "getUnread") {
 
                if ($op == "rpc") {
                        print_error_xml(6); die;
                exit;
        }
 
-       if (!$op) {
-               print_error_xml(7); exit;
-       }
-
        $purge_intervals = array(
                0  => "Use default",
                -1 => "Never purge",
                }
        }
 
+       if ($op == "getUnread") {
+               $login = db_escape_string($_GET["login"]);
+
+               header("Content-Type: text/plain");
+
+               $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);
+               } else {
+                       print "Error: user not found";
+               }
+       }
+
        db_close($link);
 ?>
 
+<?php if ($op != "getUnread") { ?>
 <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
-
+<?php } ?>
index 2b6e53b3cab5c5eb3eefff70384e23495ab85cb3..5feba77f08b1953058a7966bf199163797a6e99d 100644 (file)
 
        /* FIXME this needs reworking */
 
-       function getGlobalUnread($link) {
+       function getGlobalUnread($link, $user_id = false) {
+
+               if (!$user_id) {
+                       $user_id = $_SESSION["uid"];
+               }
+
                $result = db_query($link, "SELECT count(ttrss_entries.id) as c_id FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
                        WHERE unread = true AND 
                        ttrss_user_entries.feed_id = ttrss_feeds.id AND
                        ttrss_user_entries.ref_id = ttrss_entries.id AND 
                        hidden = false AND
-                       ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
+                       ttrss_user_entries.owner_uid = '$user_id'");
                $c_id = db_fetch_result($result, 0, "c_id");
                return $c_id;
        }