]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
add (disabled) per-feed view_settings handling placeholder
[tt-rss.git] / classes / pref / feeds.php
index 6828e3ff2923323934648469a8fb432500e8f632..7895a0396795889ef559893c798d0231832b76a1 100644 (file)
@@ -33,8 +33,10 @@ class Pref_Feeds extends Handler_Protected {
 
                if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
 
-               $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
-                       get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+               // first one is set by API
+               $show_empty_cats = $_REQUEST['force_show_empty'] ||
+                       ($_REQUEST['mode'] != 2 && !$search &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
 
                $items = array();
 
@@ -55,7 +57,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        $cat['items'] = $this->get_category_items($line['id']);
 
-                       $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+                       $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                        if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($items, $cat);
@@ -87,6 +89,10 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function getfeedtree() {
+               print json_encode($this->makefeedtree());
+       }
+
+       function makefeedtree() {
 
                if ($_REQUEST['mode'] != 2)
                        $search = $_SESSION["prefs_feed_search"];
@@ -115,6 +121,32 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($cat['items'], $this->feedlist_init_feed($i));
                        }
 
+                       /* Plugin feeds for -1 */
+
+                       global $pluginhost;
+
+                       $feeds = $pluginhost->get_feeds(-1);
+
+                       if ($feeds) {
+                               foreach ($feeds as $feed) {
+                                       $feed_id = PluginHost::pfeed_to_feed_id($feed['id']);
+
+                                       $item = array();
+                                       $item['id'] = 'FEED:' . $feed_id;
+                                       $item['bare_id'] = (int)$feed_id;
+                                       $item['name'] = $feed['title'];
+                                       $item['checkbox'] = false;
+                                       $item['error'] = '';
+                                       $item['icon'] = $feed['icon'];
+
+                                       $item['param'] = '';
+                                       $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']);
+                                       $item['type'] = 'feed';
+
+                                       array_push($cat['items'], $item);
+                               }
+                       }
+
                        if ($enable_cats) {
                                array_push($root['items'], $cat);
                        } else {
@@ -134,7 +166,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);
 
@@ -153,8 +185,9 @@ class Pref_Feeds extends Handler_Protected {
                }
 
                if ($enable_cats) {
-                       $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
-                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+                       $show_empty_cats = $_REQUEST['force_show_empty'] ||
+                               ($_REQUEST['mode'] != 2 && !$search &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
 
                        $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories
                                WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
@@ -172,7 +205,7 @@ class Pref_Feeds extends Handler_Protected {
 
                                $cat['items'] = $this->get_category_items($line['id']);
 
-                               $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+                               $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                                if (count($cat['items']) > 0 || $show_empty_cats)
                                        array_push($root['items'], $cat);
@@ -214,13 +247,13 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($cat['items'], $feed);
                        }
 
-                       $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+                       $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                        if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($root['items'], $cat);
 
                        $root['param'] += count($cat['items']);
-                       $root['param'] = T_sprintf('(%d feeds)', $root['param']);
+                       $root['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                } else {
                        $feed_result = db_query($this->link, "SELECT id, title, last_error,
@@ -245,7 +278,7 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($root['items'], $feed);
                        }
 
-                       $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
+                       $root['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
                }
 
                $fl = array();
@@ -258,8 +291,7 @@ class Pref_Feeds extends Handler_Protected {
                        $fl['items'] =& $root['items'];
                }
 
-               print json_encode($fl);
-               return;
+               return $fl;
        }
 
        function catsortreset() {
@@ -710,7 +742,9 @@ class Pref_Feeds extends Handler_Protected {
 
                $feed_ids = db_escape_string($this->link, $_REQUEST["ids"]);
 
-               print "<div class=\"dialogNotice\">" . __("Enable the options you wish to apply using checkboxes on the right:") . "</div>";
+               print_notice("Enable the options you wish to apply using checkboxes on the right:");
+
+               print "<p>";
 
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
@@ -1491,7 +1525,7 @@ class Pref_Feeds extends Handler_Protected {
                        GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
                        ORDER BY last_article");
 
-               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated with new content for 3 months (oldest first):") . "</div>";
+               print "<h2" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</h2>";
 
                print "<div dojoType=\"dijit.Toolbar\">";
                print "<div dojoType=\"dijit.form.DropDownButton\">".
@@ -1557,7 +1591,8 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function feedsWithErrors() {
-               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated because of errors:") . "</div>";
+               print "<h2>" . __("These feeds have not been updated because of errors:") .
+                       "</h2>";
 
                $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url
                FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
@@ -1667,18 +1702,27 @@ class Pref_Feeds extends Handler_Protected {
 
                        /* prepare feed if necessary */
 
+                       $result = db_query($link, "SELECT feed_url FROM ttrss_feeds WHERE id = $id
+                               AND owner_uid = $owner_uid");
+
+                       $feed_url = db_escape_string($link, db_fetch_result($result, 0, "feed_url"));
+
                        $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
-                               WHERE id = '$id'");
+                               WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid");
 
                        if (db_num_rows($result) == 0) {
                                db_query($link, "INSERT INTO ttrss_archived_feeds
                                        (id, owner_uid, title, feed_url, site_url)
                                SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds
-                               WHERE id = '$id'");
+                               WHERE id = '$id'");
+
+                               $archive_id = $id;
+                       } else {
+                               $archive_id = db_fetch_result($result, 0, "id");
                        }
 
                        db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL,
-                               orig_feed_id = '$id' WHERE feed_id = '$id' AND
+                               orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND
                                        marked = true AND owner_uid = $owner_uid");
 
                        /* Remove access key for the feed */
@@ -1700,8 +1744,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
                }
        }