]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
update translations
[tt-rss.git] / functions.php
index 51be96f7a88aa1428e958f336b77b24b2be30ff3..648ab3438657dc4a4ef36c60846a3c6810469ec4 100644 (file)
        }
 
        function printFeedEntry($feed_id, $class, $feed_title, $unread, $icon_file, $link,
-               $rtl_content = false, $last_updated = false, $last_error = false) {
+               $rtl_content = false, $last_updated = false, $last_error = false,
+               $fg_content = false, $bg_content = false) {
 
                if (file_exists($icon_file) && filesize($icon_file) > 0) {
                                $feed_icon = "<img id=\"FIMG-$feed_id\" src=\"$icon_file\">";
                $feed = "<a title=\"$link_title\" id=\"FEEDL-$feed_id\" 
                        href=\"javascript:viewfeed('$feed_id', '', false, '', false, 0);\">$feed_title</a>";
 
+/*             if ($feed_id < -10) {
+                       $bg_color = "#00ccff";
+                       $fg_color = "white";
+               }
+
+               if ($fg_color || $bg_color) {
+                       $color_str = "<div class='labelColorIndicator'
+                               style='color : $fg_color; background-color : $bg_color'>l</div>";
+               } 
+
+               print $color_str; */
+
                print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
                if (get_pref($link, 'ENABLE_FEED_ICONS')) {
                        print "$feed_icon";
                        print "<div class=\"feedExtInfo\">
                                <span id=\"FLUPD-$feed_id\">$last_updated ($total total) $error_notify_msg</span></div>";
                }
-                        
+
                print "</li>";
 
        }
 
                        if (!$_SESSION["uid"] || !validate_session($link)) {
                                render_login_form($link, $mobile);
+                               //header("Location: login.php");
                                exit;
                        } else {
                                /* bump login timestamp */
                }
        }
        
+       function bool_to_sql_bool($s) {
+               if ($s) {
+                       return "true";
+               } else {
+                       return "false";
+               }
+       }
 
        function toggleEvenOdd($a) {
                if ($a == "even") 
                        
                                if ($cat_view) {
 
-                                       if ($feed > 0) {
-                                               $cat_qpart = "cat_id = '$feed'";
-                                       } else {
-                                               $cat_qpart = "cat_id IS NULL";
-                                       }
+                                       if ($feed >= 0) {
+
+                                               if ($feed > 0) {
+                                                       $cat_qpart = "cat_id = '$feed'";
+                                               } else {
+                                                       $cat_qpart = "cat_id IS NULL";
+                                               }
                                        
-                                       $tmp_result = db_query($link, "SELECT id 
-                                               FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " . 
-                                               $_SESSION["uid"]);
+                                               $tmp_result = db_query($link, "SELECT id 
+                                                       FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " . 
+                                                       $_SESSION["uid"]);
 
-                                       while ($tmp_line = db_fetch_assoc($tmp_result)) {
+                                               while ($tmp_line = db_fetch_assoc($tmp_result)) {
+
+                                                       $tmp_feed = $tmp_line["id"];
+
+                                                       db_query($link, "UPDATE ttrss_user_entries 
+                                                               SET unread = false,last_read = NOW() 
+                                                               WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]);
+                                               }
+                                       } else if ($feed == -2) {
 
-                                               $tmp_feed = $tmp_line["id"];
 
                                                db_query($link, "UPDATE ttrss_user_entries 
-                                                       SET unread = false,last_read = NOW() 
-                                                       WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]);
+                                                       SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) 
+                                                               FROM ttrss_user_labels2 WHERE article_id = ref_id) > 0 
+                                                       AND unread = true AND owner_uid = " . $_SESSION["uid"]);
                                        }
 
                                } else if ($feed > 0) {
                                        $label_id = -$feed - 11;
 
                                        db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2 
-                                               SET unread = false WHERE label_id = '$label_id' AND unread = true
+                                               SET unread = false, last_read = NOW() 
+                                                       WHERE label_id = '$label_id' AND unread = true
                                                        AND owner_uid = '".$_SESSION["uid"]."' AND ref_id = article_id");
 
                                }
        }
 
        function get_script_dt_add() {
-               if (strpos(VERSION, ".99") === false) {
+/*             if (strpos(VERSION, ".99") === false) {
                        return VERSION;
                } else {
                        return time();
-               }
+               } */
+               return time();
        }
 
        function get_pgsql_version($link) {
                print "<param key=\"hide_read_feeds\" value=\"" . 
                        (int) get_pref($link, "HIDE_READ_FEEDS") . "\"/>";
 
+               print "<param key=\"enable_feed_cats\" value=\"" . 
+                       (int) get_pref($link, "ENABLE_FEED_CATS") . "\"/>";
+
                print "<param key=\"feeds_sort_by_unread\" value=\"" . 
                        (int) get_pref($link, "FEEDS_SORT_BY_UNREAD") . "\"/>";
 
 
                print "<param key=\"sync_counters\" value=\"1\"/>";
 
+               print "<param key=\"offline_enabled\" value=\"".
+                       (int) get_pref($link, "ENABLE_OFFLINE_READING") . "\"/>";
+
+               $result = db_query($link, "SELECT COUNT(*) AS cf FROM
+                       ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
+
+               $num_feeds = db_fetch_result($result, 0, "cf");
+
+               print "<param key=\"num_feeds\" value=\"".
+                       (int)$num_feeds. "\"/>";
+
                print "</init-params>";
        }
 
        function print_runtime_info($link) {
                print "<runtime-info>";
 
+               $result = db_query($link, "SELECT COUNT(*) AS cf FROM
+                       ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
+
+               $num_feeds = db_fetch_result($result, 0, "cf");
+
+               print "<param key=\"num_feeds\" value=\"".
+                       (int)$num_feeds. "\"/>";
+
                if (ENABLE_UPDATE_DAEMON) {
                        print "<param key=\"daemon_is_running\" value=\"".
                                sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>";
                if (!$tags) {
 
 
-                               $result = db_query($link, "SELECT id,caption FROM                                       
+                               $result = db_query($link, "SELECT * FROM
                                        ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
                
                                if (db_num_rows($result) > 0) {
        
                                        printFeedEntry($label_id, 
                                                $class, $line["caption"], 
-                                               $count, "images/label.png", $link);
+                                               $count, "images/label.png", $link, 
+                                               false, false, false,
+                                               $line['fg_color'], $line['bg_color']);
                
                                }
 
                                $feed_id = $line["feed_id"];
 
                                $labels = get_article_labels($link, $id);
-                               $labels_str = "<span id=\"HLLCTR-$id\">";
-
-                               foreach ($labels as $l) {
-                                       $labels_str .= "<span 
-                                               class='hlLabelRef'>".
-                                               $l[1]."</span>";
-                               }
 
+                               $labels_str = "<span id=\"HLLCTR-$id\">";
+                               $labels_str .= format_article_labels($labels, $id);
                                $labels_str .= "</span>";
-
+       
                                if (count($topmost_article_ids) < 5) {
                                        array_push($topmost_article_ids, $id);
                                }
 
        function get_article_labels($link, $id) {
                $result = db_query($link, 
-                       "SELECT DISTINCT label_id,caption 
+                       "SELECT DISTINCT label_id,caption,fg_color,bg_color 
                                FROM ttrss_labels2, ttrss_user_labels2 
                        WHERE id = label_id 
                                AND article_id = '$id' 
                $rv = array();
 
                while ($line = db_fetch_assoc($result)) {
-                       $rk = array($line["label_id"], $line["caption"]);
+                       $rk = array($line["label_id"], $line["caption"], $line["fg_color"],
+                               $line["bg_color"]);
                        array_push($rv, $rk);
                }
 
                return $tags_str;
 
        }
+
+       function format_article_labels($labels, $id) {
+
+               $labels_str = "";
+
+               foreach ($labels as $l) {
+                       $labels_str .= sprintf("<span class='hlLabelRef' 
+                               style='color : %s; background-color : %s'>%s</span>",
+                                       $l[2], $l[3], $l[1]);
+                       }
+
+               return $labels_str;
+
+       }
 ?>