]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
add special indication for categories having unread items in child categories
[tt-rss.git] / include / functions.php
index 394f540c95f21a9a8a5cd694f9f64b90107b18f7..b2319e6e1efabcad01d2897be89443af7306de32 100644 (file)
@@ -1,7 +1,8 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 25);
-       define('SCHEMA_VERSION', 92);
+       define('SCHEMA_VERSION', 93);
 
+       mb_internal_encoding("UTF-8");
        date_default_timezone_set('UTC');
        if (defined('E_DEPRECATED')) {
                error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
         * @return void
         */
        function _debug($msg) {
+               if (defined('QUIET') && QUIET) {
+                       return;
+               }
                $ts = strftime("%H:%M:%S", time());
                if (function_exists('posix_getpid')) {
                        $ts = "$ts/" . posix_getpid();
 
                array_push($ret_arr, $cv);
 
-               $result = db_query($link, "SELECT id AS cat_id, value AS unread
+               $result = db_query($link, "SELECT id AS cat_id, value AS unread,
+                       (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
+                               WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
                        FROM ttrss_feed_categories, ttrss_cat_counters_cache
                        WHERE ttrss_cat_counters_cache.feed_id = id AND
                        ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
                while ($line = db_fetch_assoc($result)) {
                        $line["cat_id"] = (int) $line["cat_id"];
 
+                       if ($line["num_children"] > 0) {
+                               $child_counter = getCategoryUnreadRecursive($link, $line["cat_id"], $_SESSION["uid"]);
+                       } else {
+                               $child_counter = 0;
+                       }
+
                        $cv = array("id" => $line["cat_id"], "kind" => "cat",
+                               "child_counter" => $child_counter,
                                "counter" => $line["unread"]);
 
                        array_push($ret_arr, $cv);
                return $ret_arr;
        }
 
+       // only accepts real cats (>= 0)
+       function getCategoryUnreadRecursive($link, $cat, $owner_uid = false) {
+               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+               $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE parent_cat = '$cat'
+                               AND owner_uid = $owner_uid");
+
+               $unread = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+                       $unread += getCategoryUnread($link, $line["id"], $owner_uid);
+                       $unread += getCategoryUnreadRecursive($link, $line["id"], $owner_uid);
+               }
+
+               return $unread;
+       }
+
        function getCategoryUnread($link, $cat, $owner_uid = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
                        return $output;
                }
        }
+
+       function read_stdin() {
+               $fp = fopen("php://stdin", "r");
+
+               if ($fp) {
+                       $line = trim(fgets($fp));
+                       fclose($fp);
+                       return $line;
+               }
+
+               return null;
+       }
 ?>