]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
experimentally rebase labels; make base index configurable
[tt-rss.git] / classes / pref / feeds.php
index ef308ee1c9751f95e66d7f2c421050a4bc3f7b1b..a6811f3fc1bfeda80e54ba0e574ebb6b7bf66d13 100644 (file)
@@ -3,7 +3,7 @@ class Pref_Feeds extends Handler_Protected {
 
        function csrf_ignore($method) {
                $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
-                       "savefeedorder", "uploadicon");
+                       "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds");
 
                return array_search($method, $csrf_ignored) !== false;
        }
@@ -14,8 +14,8 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function renamecat() {
-               $title = db_escape_string($_REQUEST['title']);
-               $id = db_escape_string($_REQUEST['id']);
+               $title = db_escape_string($this->link, $_REQUEST['title']);
+               $id = db_escape_string($this->link, $_REQUEST['id']);
 
                if ($title) {
                        db_query($this->link, "UPDATE ttrss_feed_categories SET
@@ -25,12 +25,20 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        private function get_category_items($cat_id) {
-               $show_empty_cats = $_REQUEST['mode'] != 2 &&
+
+               if ($_REQUEST['mode'] != 2)
+                       $search = $_SESSION["prefs_feed_search"];
+               else
+                       $search = "";
+
+               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');
 
                $items = array();
 
-               $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
+               $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories
                                WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title");
 
                while ($line = db_fetch_assoc($result)) {
@@ -41,14 +49,13 @@ class Pref_Feeds extends Handler_Protected {
                        $cat['name'] = $line['title'];
                        $cat['items'] = array();
                        $cat['checkbox'] = false;
-                       $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
                        $cat['type'] = 'category';
                        $cat['unread'] = 0;
                        $cat['child_unread'] = 0;
 
                        $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);
@@ -81,7 +88,10 @@ class Pref_Feeds extends Handler_Protected {
 
        function getfeedtree() {
 
-               $search = $_SESSION["prefs_feed_search"];
+               if ($_REQUEST['mode'] != 2)
+                       $search = $_SESSION["prefs_feed_search"];
+               else
+                       $search = "";
 
                if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
 
@@ -96,8 +106,7 @@ class Pref_Feeds extends Handler_Protected {
                if ($_REQUEST['mode'] == 2) {
 
                        if ($enable_cats) {
-                               $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
-                               $cat = $this->feedlist_init_cat(-1, $cat_hidden);
+                               $cat = $this->feedlist_init_cat(-1);
                        } else {
                                $cat['items'] = array();
                        }
@@ -118,18 +127,16 @@ class Pref_Feeds extends Handler_Protected {
                        if (db_num_rows($result) > 0) {
 
                                if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
-                                       $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
-                                       $cat = $this->feedlist_init_cat(-2, $cat_hidden);
+                                       $cat = $this->feedlist_init_cat(-2);
                                } else {
                                        $cat['items'] = array();
                                }
 
                                while ($line = db_fetch_assoc($result)) {
 
-                                       $label_id = -$line['id'] - 11;
-                                       $count = getFeedUnread($this->link, $label_id);
+                                       $label_id = label_to_feed_id($line['id']);
 
-                                       $feed = $this->feedlist_init_feed($label_id, false, $count);
+                                       $feed = $this->feedlist_init_feed($label_id, false, 0);
 
                                        $feed['fg_color'] = $line['fg_color'];
                                        $feed['bg_color'] = $line['bg_color'];
@@ -146,10 +153,10 @@ class Pref_Feeds extends Handler_Protected {
                }
 
                if ($enable_cats) {
-                       $show_empty_cats = $_REQUEST['mode'] != 2 &&
+                       $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
                                get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
 
-                       $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
+                       $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");
 
                        while ($line = db_fetch_assoc($result)) {
@@ -159,14 +166,13 @@ class Pref_Feeds extends Handler_Protected {
                                $cat['name'] = $line['title'];
                                $cat['items'] = array();
                                $cat['checkbox'] = false;
-                               $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
                                $cat['type'] = 'category';
                                $cat['unread'] = 0;
                                $cat['child_unread'] = 0;
 
                                $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);
@@ -181,7 +187,6 @@ class Pref_Feeds extends Handler_Protected {
                        $cat['bare_id'] = 0;
                        $cat['name'] = __("Uncategorized");
                        $cat['items'] = array();
-                       $cat['hidden'] = get_pref($this->link, "_COLLAPSED_UNCAT");
                        $cat['type'] = 'category';
                        $cat['checkbox'] = false;
                        $cat['unread'] = 0;
@@ -209,13 +214,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,
@@ -240,7 +245,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();
@@ -288,7 +293,7 @@ class Pref_Feeds extends Handler_Protected {
                if ($item_id != 'root') {
                        if ($parent_id && $parent_id != 'root') {
                                $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1);
-                               $parent_qpart = db_escape_string($parent_bare_id);
+                               $parent_qpart = db_escape_string($this->link, $parent_bare_id);
                        } else {
                                $parent_qpart = 'NULL';
                        }
@@ -314,10 +319,13 @@ class Pref_Feeds extends Handler_Protected {
                                        if (strpos($id, "FEED") === 0) {
 
                                                $cat_id = ($item_id != "root") ?
-                                                       db_escape_string($bare_item_id) : "NULL";
+                                                       db_escape_string($this->link, $bare_item_id) : "NULL";
+
+                                               $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" :
+                                                       "cat_id = NULL";
 
                                                db_query($this->link, "UPDATE ttrss_feeds
-                                                       SET order_id = $order_id, cat_id = '$cat_id'
+                                                       SET order_id = $order_id, $cat_qpart
                                                        WHERE id = '$bare_id' AND
                                                                owner_uid = " . $_SESSION["uid"]);
 
@@ -326,7 +334,7 @@ class Pref_Feeds extends Handler_Protected {
                                                        $nest_level+1);
 
                                                if ($item_id != 'root') {
-                                                       $parent_qpart = db_escape_string($bare_id);
+                                                       $parent_qpart = db_escape_string($this->link, $bare_id);
                                                } else {
                                                        $parent_qpart = 'NULL';
                                                }
@@ -416,7 +424,7 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function removeicon() {
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
+               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
 
                $result = db_query($this->link, "SELECT id FROM ttrss_feeds
                        WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
@@ -429,8 +437,10 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function uploadicon() {
+               header("Content-type: text/html");
+
                $icon_file = $_FILES['icon_file']['tmp_name'];
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
+               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
 
                if (is_file($icon_file) && $feed_id) {
                        if (filesize($icon_file) < 20000) {
@@ -461,9 +471,8 @@ class Pref_Feeds extends Handler_Protected {
        function editfeed() {
                global $purge_intervals;
                global $update_intervals;
-               global $update_methods;
 
-               $feed_id = db_escape_string($_REQUEST["id"]);
+               $feed_id = db_escape_string($this->link, $_REQUEST["id"]);
 
                $result = db_query($this->link,
                        "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
@@ -533,20 +542,10 @@ class Pref_Feeds extends Handler_Protected {
                print_select_hash("update_interval", $update_interval, $update_intervals,
                        'dojoType="dijit.form.Select"');
 
-               /* Update method */
-
-               $update_method = db_fetch_result($result, 0, "update_method",
-                       'dojoType="dijit.form.Select"');
-
-               print " " . __('using') . " ";
-               print_select_hash("update_method", $update_method, $update_methods,
-                       'dojoType="dijit.form.Select"');
+               /* Purge intl */
 
                $purge_interval = db_fetch_result($result, 0, "purge_interval");
 
-
-                       /* Purge intl */
-
                print "<hr/>";
                print __('Article purging:') . " ";
 
@@ -589,17 +588,6 @@ class Pref_Feeds extends Handler_Protected {
                print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"
                        $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
 
-               $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
-
-               if ($rtl_content) {
-                       $checked = "checked=\"1\"";
-               } else {
-                       $checked = "";
-               }
-
-               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
-                       $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
-
                $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
 
                if ($include_in_digest) {
@@ -625,6 +613,18 @@ class Pref_Feeds extends Handler_Protected {
                        name=\"always_display_enclosures\"
                        $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
 
+               $hide_images = sql_bool_to_bool(db_fetch_result($result, 0, "hide_images"));
+
+               if ($hide_images) {
+                       $checked = "checked=\"1\"";
+               } else {
+                       $checked = "";
+               }
+
+               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\"
+               name=\"hide_images\"
+                       $checked>&nbsp;<label for=\"hide_images\">".
+               __('Do not embed images')."</label>";
 
                $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
 
@@ -651,18 +651,6 @@ class Pref_Feeds extends Handler_Protected {
                        name=\"mark_unread_on_update\"
                        $checked>&nbsp;<label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>";
 
-               $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
-
-               if ($update_on_checksum_change) {
-                       $checked = "checked";
-               } else {
-                       $checked = "";
-               }
-
-               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"update_on_checksum_change\"
-                       name=\"update_on_checksum_change\"
-                       $checked>&nbsp;<label for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>";
-
                print "</div>";
 
                /* Icon */
@@ -719,9 +707,8 @@ class Pref_Feeds extends Handler_Protected {
        function editfeeds() {
                global $purge_intervals;
                global $update_intervals;
-               global $update_methods;
 
-               $feed_ids = db_escape_string($_REQUEST["ids"]);
+               $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>";
 
@@ -778,13 +765,6 @@ class Pref_Feeds extends Handler_Protected {
 
                $this->batch_edit_cbox("update_interval");
 
-               /* Update method */
-
-               print " " . __('using') . " ";
-               print_select_hash("update_method", $update_method, $update_methods,
-                       'disabled="1" dojoType="dijit.form.Select"');
-               $this->batch_edit_cbox("update_method");
-
                /* Purge intl */
 
                if (FORCE_ARTICLE_PURGE == 0) {
@@ -824,11 +804,6 @@ class Pref_Feeds extends Handler_Protected {
 
                print "&nbsp;"; $this->batch_edit_cbox("private", "private_l");
 
-               print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
-                       dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
-
-               print "&nbsp;"; $this->batch_edit_cbox("rtl_content", "rtl_content_l");
-
                print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
                        name=\"include_in_digest\"
                        dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
@@ -841,6 +816,14 @@ class Pref_Feeds extends Handler_Protected {
 
                print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
 
+               print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\"
+                       name=\"hide_images\"
+                       dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"hide_images_l\"
+                       for=\"hide_images\">".
+               __('Do not embed images')."</label>";
+
+               print "&nbsp;"; $this->batch_edit_cbox("hide_images", "hide_images_l");
+
                print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
                        name=\"cache_images\"
                        dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
@@ -855,12 +838,6 @@ class Pref_Feeds extends Handler_Protected {
 
                print "&nbsp;"; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
 
-               print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"update_on_checksum_change\"
-                       name=\"update_on_checksum_change\"
-                       dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"update_on_checksum_change_l\" class='insensitive' for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>";
-
-               print "&nbsp;"; $this->batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l");
-
                print "</div>";
 
                print "<div class='dlgButtons'>
@@ -885,31 +862,27 @@ class Pref_Feeds extends Handler_Protected {
 
        function editsaveops($batch) {
 
-               $feed_title = db_escape_string(trim($_POST["title"]));
-               $feed_link = db_escape_string(trim($_POST["feed_url"]));
-               $upd_intl = (int) db_escape_string($_POST["update_interval"]);
-               $purge_intl = (int) db_escape_string($_POST["purge_interval"]);
-               $feed_id = (int) db_escape_string($_POST["id"]); /* editSave */
-               $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */
-               $cat_id = (int) db_escape_string($_POST["cat_id"]);
-               $auth_login = db_escape_string(trim($_POST["auth_login"]));
-               $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
-               $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
-               $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
+               $feed_title = db_escape_string($this->link, trim($_POST["title"]));
+               $feed_link = db_escape_string($this->link, trim($_POST["feed_url"]));
+               $upd_intl = (int) db_escape_string($this->link, $_POST["update_interval"]);
+               $purge_intl = (int) db_escape_string($this->link, $_POST["purge_interval"]);
+               $feed_id = (int) db_escape_string($this->link, $_POST["id"]); /* editSave */
+               $feed_ids = db_escape_string($this->link, $_POST["ids"]); /* batchEditSave */
+               $cat_id = (int) db_escape_string($this->link, $_POST["cat_id"]);
+               $auth_login = db_escape_string($this->link, trim($_POST["auth_login"]));
+               $auth_pass = db_escape_string($this->link, trim($_POST["auth_pass"]));
+               $private = checkbox_to_sql_bool(db_escape_string($this->link, $_POST["private"]));
                $include_in_digest = checkbox_to_sql_bool(
-                       db_escape_string($_POST["include_in_digest"]));
+                       db_escape_string($this->link, $_POST["include_in_digest"]));
                $cache_images = checkbox_to_sql_bool(
-                       db_escape_string($_POST["cache_images"]));
-               $update_method = (int) db_escape_string($_POST["update_method"]);
-
+                       db_escape_string($this->link, $_POST["cache_images"]));
+               $hide_images = checkbox_to_sql_bool(
+                       db_escape_string($this->link, $_POST["hide_images"]));
                $always_display_enclosures = checkbox_to_sql_bool(
-                       db_escape_string($_POST["always_display_enclosures"]));
+                       db_escape_string($this->link, $_POST["always_display_enclosures"]));
 
                $mark_unread_on_update = checkbox_to_sql_bool(
-                       db_escape_string($_POST["mark_unread_on_update"]));
-
-               $update_on_checksum_change = checkbox_to_sql_bool(
-                       db_escape_string($_POST["update_on_checksum_change"]));
+                       db_escape_string($this->link, $_POST["mark_unread_on_update"]));
 
                if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
                        if ($cat_id && $cat_id != 0) {
@@ -924,8 +897,6 @@ class Pref_Feeds extends Handler_Protected {
                        $category_qpart_nocomma = "";
                }
 
-               $cache_images_qpart = "cache_images = $cache_images,";
-
                if (!$batch) {
 
                        $result = db_query($this->link, "UPDATE ttrss_feeds SET
@@ -936,14 +907,12 @@ class Pref_Feeds extends Handler_Protected {
                                auth_login = '$auth_login',
                                auth_pass = '$auth_pass',
                                private = $private,
-                               rtl_content = $rtl_content,
-                               $cache_images_qpart
+                               cache_images = $cache_images,
+                               hide_images = $hide_images,
                                include_in_digest = $include_in_digest,
                                always_display_enclosures = $always_display_enclosures,
-                               mark_unread_on_update = $mark_unread_on_update,
-                               update_on_checksum_change = $update_on_checksum_change,
-                               update_method = '$update_method'
-                               WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
+                               mark_unread_on_update = $mark_unread_on_update
+                       WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
                } else {
                        $feed_data = array();
@@ -1001,20 +970,12 @@ class Pref_Feeds extends Handler_Protected {
                                                $qpart = "mark_unread_on_update = $mark_unread_on_update";
                                                break;
 
-                                       case "update_on_checksum_change":
-                                               $qpart = "update_on_checksum_change = $update_on_checksum_change";
-                                               break;
-
                                        case "cache_images":
                                                $qpart = "cache_images = $cache_images";
                                                break;
 
-                                       case "rtl_content":
-                                               $qpart = "rtl_content = $rtl_content";
-                                               break;
-
-                                       case "update_method":
-                                               $qpart = "update_method = '$update_method'";
+                                       case "hide_images":
+                                               $qpart = "hide_images = $hide_images";
                                                break;
 
                                        case "cat_id":
@@ -1038,7 +999,7 @@ class Pref_Feeds extends Handler_Protected {
 
        function resetPubSub() {
 
-               $ids = db_escape_string($_REQUEST["ids"]);
+               $ids = db_escape_string($this->link, $_REQUEST["ids"]);
 
                db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids)
                        AND owner_uid = " . $_SESSION["uid"]);
@@ -1048,22 +1009,24 @@ class Pref_Feeds extends Handler_Protected {
 
        function remove() {
 
-               $ids = split(",", db_escape_string($_REQUEST["ids"]));
+               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
 
                foreach ($ids as $id) {
-                       remove_feed($this->link, $id, $_SESSION["uid"]);
+                       Pref_Feeds::remove_feed($this->link, $id, $_SESSION["uid"]);
                }
 
                return;
        }
 
        function clear() {
-               $id = db_escape_string($_REQUEST["id"]);
-               clear_feed_articles($this->link, $id);
+               $id = db_escape_string($this->link, $_REQUEST["id"]);
+               $this->clear_feed_articles($this->link, $id);
        }
 
        function rescore() {
-               $ids = split(",", db_escape_string($_REQUEST["ids"]));
+               require_once "rssfuncs.php";
+
+               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
 
                foreach ($ids as $id) {
 
@@ -1168,115 +1131,10 @@ class Pref_Feeds extends Handler_Protected {
 
        }
 
-       function add() {
-               $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
-               $cat_id = db_escape_string($_REQUEST["cat_id"]);
-               $p_from = db_escape_string($_REQUEST["from"]);
-
-               /* only read authentication information from POST */
-
-               $auth_login = db_escape_string(trim($_POST["auth_login"]));
-               $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
-
-               if ($p_from != 'tt-rss') {
-                       header('Content-Type: text/html; charset=utf-8');
-                       print "<html>
-                               <head>
-                                       <title>Tiny Tiny RSS</title>
-                                       <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
-                                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
-                               </head>
-                               <body>
-                               <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
-                                       alt=\"Tiny Tiny RSS\"/>
-                               <h1>Subscribe to feed...</h1>";
-               }
-
-               $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
-
-               switch ($rc) {
-               case 1:
-                       print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
-                       break;
-               case 2:
-                       print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
-                       break;
-               case 3:
-                       print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
-                       break;
-               case 0:
-                       print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
-                       break;
-               case 4:
-                       print_notice(__("Multiple feed URLs found."));
-
-                       $feed_urls = get_feeds_from_html($feed_url);
-                       break;
-               case 5:
-                       print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
-                       break;
-               }
-
-               if ($p_from != 'tt-rss') {
-
-                       if ($feed_urls) {
-
-                               print "<form action=\"backend.php\">";
-                               print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
-                               print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
-                               print "<input type=\"hidden\" name=\"method\" value=\"add\">";
-
-                               print "<select name=\"feed_url\">";
-
-                               foreach ($feed_urls as $url => $name) {
-                                       $url = htmlspecialchars($url);
-                                       $name = htmlspecialchars($name);
-
-                                       print "<option value=\"$url\">$name</option>";
-                               }
-
-                               print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
-                                       "\">";
-
-                               print "</form>";
-                       }
-
-                       $tp_uri = get_self_url_prefix() . "/prefs.php";
-                       $tt_uri = get_self_url_prefix();
-
-                       if ($rc <= 2){
-                               $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
-                                       feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
-
-                               $feed_id = db_fetch_result($result, 0, "id");
-                       } else {
-                               $feed_id = 0;
-                       }
-                       print "<p>";
-
-                       if ($feed_id) {
-                               print "<form method=\"GET\" style='display: inline'
-                                       action=\"$tp_uri\">
-                                       <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
-                                       <input type=\"hidden\" name=\"method\" value=\"editFeed\">
-                                       <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
-                                       <input type=\"submit\" value=\"".__("Edit subscription options")."\">
-                                       </form>";
-                       }
-
-                       print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
-                               <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
-                               </form></p>";
-
-                       print "</body></html>";
-                       return;
-               }
-       }
-
        function categorize() {
-               $ids = split(",", db_escape_string($_REQUEST["ids"]));
+               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
 
-               $cat_id = db_escape_string($_REQUEST["cat_id"]);
+               $cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]);
 
                if ($cat_id == 0) {
                        $cat_id_qpart = 'NULL';
@@ -1298,14 +1156,14 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function removeCat() {
-               $ids = split(",", db_escape_string($_REQUEST["ids"]));
+               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
                foreach ($ids as $id) {
-                       remove_feed_category($this->link, $id, $_SESSION["uid"]);
+                       $this->remove_feed_category($this->link, $id, $_SESSION["uid"]);
                }
        }
 
        function addCat() {
-               $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
+               $feed_cat = db_escape_string($this->link, trim($_REQUEST["cat"]));
 
                add_feed_category($this->link, $feed_cat);
        }
@@ -1347,7 +1205,7 @@ class Pref_Feeds extends Handler_Protected {
                                        __("Inactive feeds") . "</button>";
                }
 
-               $feed_search = db_escape_string($_REQUEST["search"]);
+               $feed_search = db_escape_string($this->link, $_REQUEST["search"]);
 
                if (array_key_exists("search", $_REQUEST)) {
                        $_SESSION["prefs_feed_search"] = $feed_search;
@@ -1472,9 +1330,7 @@ class Pref_Feeds extends Handler_Protected {
 
                print "</div>"; # feeds pane
 
-               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Import and export')."\">";
-
-               print "<h3>" . __("OPML") . "</h3>";
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
 
                print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
 
@@ -1512,29 +1368,9 @@ class Pref_Feeds extends Handler_Protected {
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
                        __('Display published OPML URL')."</button> ";
 
-
-               print "<h3>" . __("Article archive") . "</h3>";
-
-               print "<p>" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "</p>";
-
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return exportData()\">".
-                       __('Export my data')."</button> ";
-
-               print "<hr>";
-
-               print "<iframe id=\"data_upload_iframe\"
-                       name=\"data_upload_iframe\" onload=\"dataImportComplete(this)\"
-                       style=\"width: 400px; height: 100px; display: none;\"></iframe>";
-
-               print "<form name=\"import_form\" style='display : block' target=\"data_upload_iframe\"
-                       enctype=\"multipart/form-data\" method=\"POST\"
-                       action=\"backend.php\">
-                       <input id=\"export_file\" name=\"export_file\" type=\"file\">&nbsp;
-                       <input type=\"hidden\" name=\"op\" value=\"dlg\">
-                       <input type=\"hidden\" name=\"method\" value=\"dataimport\">
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return importData();\" type=\"submit\">" .
-                       __('Import') . "</button>";
-
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefFeedsOPML");
 
                print "</div>"; # pane
 
@@ -1557,20 +1393,6 @@ class Pref_Feeds extends Handler_Protected {
                        print "</div>"; # pane
                }
 
-               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
-
-               print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>";
-
-               $bm_subscribe_url = str_replace('%s', '', add_feed_url());
-
-               $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?'));
-
-               $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
-
-               print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
-
-               print "</div>"; #pane
-
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
 
                print "<h3>" . __("Published articles and generated feeds") . "</h3>";
@@ -1593,13 +1415,21 @@ class Pref_Feeds extends Handler_Protected {
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
                        __('Unshare all articles')."</button> ";
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
+
                print "</div>"; #pane
 
-               print "</div>"; #container
+               global $pluginhost;
 
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
+                       "hook_prefs_tab", "prefFeeds");
+
+               print "</div>"; #container
        }
 
-       private function feedlist_init_cat($cat_id, $hidden = false) {
+       private function feedlist_init_cat($cat_id) {
                $obj = array();
                $cat_id = (int) $cat_id;
 
@@ -1614,7 +1444,6 @@ class Pref_Feeds extends Handler_Protected {
                $obj['name'] = getCategoryTitle($this->link, $cat_id);
                $obj['type'] = 'category';
                $obj['unread'] = (int) $cat_unread;
-               $obj['hidden'] = $hidden;
                $obj['bare_id'] = $cat_id;
 
                return $obj;
@@ -1642,5 +1471,239 @@ class Pref_Feeds extends Handler_Protected {
                return $obj;
        }
 
+       function inactiveFeeds() {
+
+               if (DB_TYPE == "pgsql") {
+                       $interval_qpart = "NOW() - INTERVAL '3 months'";
+               } else {
+                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
+               }
+
+               $result = db_query($this->link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
+                               ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
+                       FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
+                               (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
+                                       ttrss_entries.id = ref_id AND
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
+                       AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND
+                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                               ttrss_entries.id = ref_id
+                       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 "<div dojoType=\"dijit.Toolbar\">";
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
+               print "</div>"; #toolbar
+
+               print "<div class=\"inactiveFeedHolder\">";
+
+               print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
+
+               $lnum = 1;
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $class = ($lnum % 2) ? "even" : "odd";
+                       $feed_id = $line["id"];
+                       $this_row_id = "id=\"FUPDD-$feed_id\"";
+
+                       # class needed for selectTableRows()
+                       print "<tr class=\"placeholder\" $this_row_id>";
+
+                       $edit_title = htmlspecialchars($line["title"]);
+
+                       # id needed for selectTableRows()
+                       print "<td width='5%' align='center'><input
+                               onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
+                               type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>";
+                       print "<td>";
+
+                       print "<a class=\"visibleLink\" href=\"#\" ".
+                               "title=\"".__("Click to edit feed")."\" ".
+                               "onclick=\"editFeed(".$line["id"].")\">".
+                               htmlspecialchars($line["title"])."</a>";
+
+                       print "</td><td class=\"insensitive\" align='right'>";
+                       print make_local_datetime($this->link, $line['last_article'], false);
+                       print "</td>";
+                       print "</tr>";
+
+                       ++$lnum;
+               }
+
+               print "</table>";
+               print "</div>";
+
+               print "<div class='dlgButtons'>";
+               print "<div style='float : left'>";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">"
+                       .__('Unsubscribe from selected feeds')."</button> ";
+               print "</div>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">".
+                       __('Close this window')."</button>";
+
+               print "</div>";
+
+       }
+
+       function feedsWithErrors() {
+               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated because of errors:") . "</div>";
+
+               $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"]);
+
+               print "<div dojoType=\"dijit.Toolbar\">";
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
+               print "</div>"; #toolbar
+
+               print "<div class=\"inactiveFeedHolder\">";
+
+               print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
+
+               $lnum = 1;
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $class = ($lnum % 2) ? "even" : "odd";
+                       $feed_id = $line["id"];
+                       $this_row_id = "id=\"FERDD-$feed_id\"";
+
+                       # class needed for selectTableRows()
+                       print "<tr class=\"placeholder\" $this_row_id>";
+
+                       $edit_title = htmlspecialchars($line["title"]);
+
+                       # id needed for selectTableRows()
+                       print "<td width='5%' align='center'><input
+                               onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
+                               type=\"checkbox\" id=\"FERDC-$feed_id\"></td>";
+                       print "<td>";
+
+                       print "<a class=\"visibleLink\" href=\"#\" ".
+                               "title=\"".__("Click to edit feed")."\" ".
+                               "onclick=\"editFeed(".$line["id"].")\">".
+                               htmlspecialchars($line["title"])."</a>: ";
+
+                       print "<span class=\"insensitive\">";
+                       print htmlspecialchars($line["last_error"]);
+                       print "</span>";
+
+                       print "</td>";
+                       print "</tr>";
+
+                       ++$lnum;
+               }
+
+               print "</table>";
+               print "</div>";
+
+               print "<div class='dlgButtons'>";
+               print "<div style='float : left'>";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">"
+                       .__('Unsubscribe from selected feeds')."</button> ";
+               print "</div>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">".
+                       __('Close this window')."</button>";
+
+               print "</div>";
+       }
+
+       /**
+        * Purge a feed contents, marked articles excepted.
+        *
+        * @param mixed $link The database connection.
+        * @param integer $id The id of the feed to purge.
+        * @return void
+        */
+       private function clear_feed_articles($link, $id) {
+
+               if ($id != 0) {
+                       $result = db_query($link, "DELETE FROM ttrss_user_entries
+                       WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
+               } else {
+                       $result = db_query($link, "DELETE FROM ttrss_user_entries
+                       WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
+               }
+
+               $result = db_query($link, "DELETE FROM ttrss_entries WHERE
+                       (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
+
+               ccache_update($link, $id, $_SESSION['uid']);
+       } // function clear_feed_articles
+
+       private function remove_feed_category($link, $id, $owner_uid) {
+
+               db_query($link, "DELETE FROM ttrss_feed_categories
+                       WHERE id = '$id' AND owner_uid = $owner_uid");
+
+               ccache_remove($link, $id, $owner_uid, true);
+       }
+
+       static function remove_feed($link, $id, $owner_uid) {
+
+               if ($id > 0) {
+
+                       /* save starred articles in Archived feed */
+
+                       db_query($link, "BEGIN");
+
+                       /* prepare feed if necessary */
+
+                       $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
+                               WHERE id = '$id'");
+
+                       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'");
+                       }
+
+                       db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL,
+                               orig_feed_id = '$id' WHERE feed_id = '$id' AND
+                                       marked = true AND owner_uid = $owner_uid");
+
+                       /* Remove access key for the feed */
+
+                       db_query($link, "DELETE FROM ttrss_access_keys WHERE
+                               feed_id = '$id' AND owner_uid = $owner_uid");
+
+                       /* remove the feed */
+
+                       db_query($link, "DELETE FROM ttrss_feeds
+                                       WHERE id = '$id' AND owner_uid = $owner_uid");
+
+                       db_query($link, "COMMIT");
+
+                       if (file_exists(ICONS_DIR . "/$id.ico")) {
+                               unlink(ICONS_DIR . "/$id.ico");
+                       }
+
+                       ccache_remove($link, $id, $owner_uid);
+
+               } else {
+                       label_remove($link, feed_to_label_id($id), $owner_uid);
+                       //ccache_remove($link, $id, $owner_uid); don't think labels are cached
+               }
+       }
+
 }
 ?>