]> git.wh0rd.org Git - tt-rss.git/commitdiff
experimentally rebase labels; make base index configurable
authorAndrew Dolgov <fox@fakecake.org>
Wed, 27 Mar 2013 05:40:07 +0000 (09:40 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Wed, 27 Mar 2013 05:40:07 +0000 (09:40 +0400)
classes/feeds.php
classes/pref/feeds.php
include/functions.php
include/labels.php
js/FeedTree.js
js/functions.js
js/viewfeed.js
plugins/mobile/mobile-functions.php

index 89ebd4a0a077d3983e20bcffd5357a2b96062733..2c45da2ddb03585e8acaffa989f82e731381d201 100644 (file)
@@ -700,7 +700,7 @@ class Feeds extends Handler_Protected {
                                        $message = __("No starred articles found to display.");
                                        break;
                                default:
-                                       if ($feed < -10) {
+                                       if ($feed < LABEL_BASE_INDEX) {
                                                $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
                                        } else {
                                                $message = __("No articles found to display.");
@@ -777,8 +777,8 @@ class Feeds extends Handler_Protected {
 
                $result = false;
 
-               if ($feed < -10) {
-                       $label_feed = -11-$feed;
+               if ($feed < LABEL_BASE_INDEX) {
+                       $label_feed = feed_to_label_id($feed);
                        $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
                                                        id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
                } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
index ca4ae344f18ca48f036e307dcaf88442cd668fa8..a6811f3fc1bfeda80e54ba0e574ebb6b7bf66d13 100644 (file)
@@ -134,7 +134,7 @@ class Pref_Feeds extends Handler_Protected {
 
                                while ($line = db_fetch_assoc($result)) {
 
-                                       $label_id = -$line['id'] - 11;
+                                       $label_id = label_to_feed_id($line['id']);
 
                                        $feed = $this->feedlist_init_feed($label_id, false, 0);
 
@@ -1700,8 +1700,8 @@ class Pref_Feeds extends Handler_Protected {
                        ccache_remove($link, $id, $owner_uid);
 
                } else {
-                       label_remove($link, -11-$id, $owner_uid);
-                       ccache_remove($link, -11-$id, $owner_uid);
+                       label_remove($link, feed_to_label_id($id), $owner_uid);
+                       //ccache_remove($link, $id, $owner_uid); don't think labels are cached
                }
        }
 
index a9c7d95f53789f035cd385e0d600259acf13f570..e926c03414637a2baa5431ab3c92b9e20e2849a1 100644 (file)
@@ -2,6 +2,8 @@
        define('EXPECTED_CONFIG_VERSION', 26);
        define('SCHEMA_VERSION', 108);
 
+       define('LABEL_BASE_INDEX', -1024);
+
        $fetch_last_error = false;
        $pluginhost = false;
 
                                                        AND $ref_check_qpart AND unread = true
                                                        AND owner_uid = $owner_uid");
 
-                               } else if ($feed < 0 && $feed > -10) { // special, like starred
+                               } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred
 
                                        if ($feed == -1) {
                                                db_query($link, "UPDATE ttrss_user_entries
                                                        owner_uid = $owner_uid");
                                        }
 
-                               } else if ($feed < -10) { // label
+                               } else if ($feed < LABEL_BASE_INDEX) { // label
 
-                                       $label_id = -$feed - 11;
+                                       $label_id = feed_to_label_id($feed);
 
                                        db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2
                                                SET unread = false, last_read = NOW()
                                $match_part = "feed_id IS NULL";
                        }
 
-               } else if ($feed < -10) {
+               } else if ($feed < LABEL_BASE_INDEX) {
 
-                       $label_id = -$feed - 11;
+                       $label_id = feed_to_label_id($feed);
 
                        return getLabelUnread($link, $label_id, $owner_uid);
 
 
                while ($line = db_fetch_assoc($result)) {
 
-                       $id = -$line["id"] - 11;
+                       $id = label_to_feed_id($line["id"]);
 
                        $label_name = $line["caption"];
                        $count = $line["unread"];
        function getFeedCatTitle($link, $id) {
                if ($id == -1) {
                        return __("Special");
-               } else if ($id < -10) {
+               } else if ($id < LABEL_BASE_INDEX) {
                        return __("Labels");
                } else if ($id > 0) {
                        $result = db_query($link, "SELECT ttrss_feed_categories.title
                        return "images/recently_read.png";
                        break;
                default:
-                       if ($id < -10) {
+                       if ($id < LABEL_BASE_INDEX) {
                                return "images/label.png";
                        } else {
                                if (file_exists(ICONS_DIR . "/$id.ico"))
                        return __("Archived articles");
                } else if ($id == -6) {
                        return __("Recently read");
-               } else if ($id < -10) {
-                       $label_id = -$id - 11;
+               } else if ($id < LABEL_BASE_INDEX) {
+                       $label_id = feed_to_label_id($id);
                        $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'");
                        if (db_num_rows($result) == 1) {
                                return db_fetch_result($result, 0, "caption");
                        } else if ($feed == -4) { // all articles virtual feed
                                $query_strategy_part = "true";
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
-                       } else if ($feed <= -10) { // labels
-                               $label_id = -$feed - 11;
+                       } else if ($feed <= LABEL_BASE_INDEX) { // labels
+                               $label_id = feed_to_label_id($feed);
 
                                $query_strategy_part = "label_id = '$label_id' AND
                                        ttrss_labels2.id = ttrss_user_labels2.label_id AND
                }
        }
 
+       function label_to_feed_id($label) {
+               return LABEL_BASE_INDEX - 1 - abs($label);
+       }
+
+       function feed_to_label_id($feed) {
+               return LABEL_BASE_INDEX - 1 + abs($feed);
+       }
+
 ?>
index 75936007ede38057b4839ec30b9316d5f89e1a10..5ac8794d94c861c0f8ef49decef6351f555f30f7 100644 (file)
 
                        /* Remove access key for the label */
 
-                       $ext_id = -11 - $id;
+                       $ext_id = LABEL_BASE_INDEX - 1 - $id;
 
                        db_query($link, "DELETE FROM ttrss_access_keys WHERE
                                feed_id = '$ext_id' AND owner_uid = $owner_uid");
index e0b068f177fb2b2f402604573fc4bb75cbc929d5..620efdbf674245aa1e0f001d4e3b64e98ef8d89e 100644 (file)
@@ -106,7 +106,7 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                var id = args.item.id[0];
                var bare_id = parseInt(id.substr(id.indexOf(':')+1));
 
-               if (bare_id < -10) {
+               if (bare_id < _label_base_index) {
                        var span = dojo.doc.createElement('span');
                        var fg_color = args.item.fg_color[0];
                        var bg_color = args.item.bg_color[0];
@@ -380,7 +380,7 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                                var node = tree._itemNodesMap[id];
 
                                if (node) {
-                                       if (hide && unread == 0 && (bare_id > 0 || bare_id < -10 || !show_special)) {
+                                       if (hide && unread == 0 && (bare_id > 0 || bare_id < _label_base_index || !show_special)) {
                                                Effect.Fade(node[0].rowNode, {duration : 0.3,
                                                        queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
                                        } else {
index a9367da60704e4f14c00794adf087a135d3cfb9d..fcf82a8eacddca7fcb8794aa6b722c7f9c9ebdfb 100644 (file)
@@ -2,6 +2,7 @@ var notify_silent = false;
 var loading_progress = 0;
 var sanity_check_done = false;
 var init_params = {};
+var _label_base_index = -1024;
 
 Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
        function (callOriginal, options) {
@@ -1986,3 +1987,13 @@ function htmlspecialchars_decode (string, quote_style) {
 
   return string;
 }
+
+
+function label_to_feed_id(label) {
+       return _label_base_index - 1 - Math.abs(label);
+}
+
+function feed_to_label_id(feed) {
+       return _label_base_index - 1 + Math.abs(feed);
+}
+
index 794e94952d566099afca3a1e0be003638753a140..cc14461f4c5d6bb196f28a5957b71ecb8aa89acf 100644 (file)
@@ -1920,7 +1920,7 @@ function initHeadlinesMenu() {
                                var bare_id = id.substr(id.indexOf(":")+1);
                                var name = label.name[0];
 
-                               bare_id = -11-bare_id;
+                               bare_id = feed_to_label_id(bare_id);
 
                                labelAddMenu.addChild(new dijit.MenuItem({
                                        label: name,
@@ -2120,3 +2120,4 @@ function displayArticleUrl(id) {
                exception_error("changeScore", e);
        }
 }
+
index 8c2ab88cf5b0bd204cc85c55c71f930a9e6b1291..8e5cb7010a7049cb9f4abb3b13fcfad4117dde87 100644 (file)
 
                        while ($line = db_fetch_assoc($result)) {
 
-                               $id = -$line["id"] - 11;
+                               $id = label_to_feed_id($line["id"]);
 
                                $unread = getFeedUnread($link, $id);
                                $title = $line["caption"];