]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
edit feed: smaller buttons for icon upload; allow uploading larger favicons
[tt-rss.git] / classes / pref / feeds.php
index c57cccc44e9f17fd2e5ce2fc4ec6e78c364f4a8e..d70c1a26add83d7d2e88751c58b4d24946a4e8cc 100644 (file)
@@ -15,11 +15,11 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function renamecat() {
-               $title = db_escape_string($this->link, $_REQUEST['title']);
-               $id = db_escape_string($this->link, $_REQUEST['id']);
+               $title = $this->dbh->escape_string($_REQUEST['title']);
+               $id = $this->dbh->escape_string($_REQUEST['id']);
 
                if ($title) {
-                       db_query($this->link, "UPDATE ttrss_feed_categories SET
+                       $this->dbh->query("UPDATE ttrss_feed_categories SET
                                title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
                }
                return;
@@ -36,15 +36,14 @@ class Pref_Feeds extends Handler_Protected {
 
                // 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'));
+                       ($_REQUEST['mode'] != 2 && !$search);
 
                $items = array();
 
-               $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories
+               $result = $this->dbh->query("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)) {
+               while ($line = $this->dbh->fetch_assoc($result)) {
 
                        $cat = array();
                        $cat['id'] = 'CAT:' . $line['id'];
@@ -55,32 +54,36 @@ class Pref_Feeds extends Handler_Protected {
                        $cat['type'] = 'category';
                        $cat['unread'] = 0;
                        $cat['child_unread'] = 0;
+                       $cat['auxcounter'] = 0;
+                       $cat['parent_id'] = $cat_id;
 
                        $cat['items'] = $this->get_category_items($line['id']);
 
-                       $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+                       $num_children = $this->calculate_children_count($cat);
+                       $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
 
-                       if (count($cat['items']) > 0 || $show_empty_cats)
+                       if ($num_children > 0 || $show_empty_cats)
                                array_push($items, $cat);
 
                }
 
-               $feed_result = db_query($this->link, "SELECT id, title, last_error,
+               $feed_result = $this->dbh->query("SELECT id, title, last_error,
                        ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
                        FROM ttrss_feeds
                        WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"].
                        "$search_qpart ORDER BY order_id, title");
 
-               while ($feed_line = db_fetch_assoc($feed_result)) {
+               while ($feed_line = $this->dbh->fetch_assoc($feed_result)) {
                        $feed = array();
                        $feed['id'] = 'FEED:' . $feed_line['id'];
                        $feed['bare_id'] = (int)$feed_line['id'];
+                       $feed['auxcounter'] = 0;
                        $feed['name'] = $feed_line['title'];
                        $feed['checkbox'] = false;
                        $feed['unread'] = 0;
                        $feed['error'] = $feed_line['last_error'];
                        $feed['icon'] = getFeedIcon($feed_line['id']);
-                       $feed['param'] = make_local_datetime($this->link,
+                       $feed['param'] = make_local_datetime(
                                $feed_line['last_updated'], true);
 
                        array_push($items, $feed);
@@ -108,7 +111,7 @@ class Pref_Feeds extends Handler_Protected {
                $root['items'] = array();
                $root['type'] = 'category';
 
-               $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
+               $enable_cats = get_pref('ENABLE_FEED_CATS');
 
                if ($_REQUEST['mode'] == 2) {
 
@@ -124,9 +127,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        /* Plugin feeds for -1 */
 
-                       global $pluginhost;
-
-                       $feeds = $pluginhost->get_feeds(-1);
+                       $feeds = PluginHost::getInstance()->get_feeds(-1);
 
                        if ($feeds) {
                                foreach ($feeds as $feed) {
@@ -135,6 +136,7 @@ class Pref_Feeds extends Handler_Protected {
                                        $item = array();
                                        $item['id'] = 'FEED:' . $feed_id;
                                        $item['bare_id'] = (int)$feed_id;
+                                       $item['auxcounter'] = 0;
                                        $item['name'] = $feed['title'];
                                        $item['checkbox'] = false;
                                        $item['error'] = '';
@@ -154,18 +156,18 @@ class Pref_Feeds extends Handler_Protected {
                                $root['items'] = array_merge($root['items'], $cat['items']);
                        }
 
-                       $result = db_query($this->link, "SELECT * FROM
+                       $result = $this->dbh->query("SELECT * FROM
                                ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption");
 
-                       if (db_num_rows($result) > 0) {
+                       if ($this->dbh->num_rows($result) > 0) {
 
-                               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+                               if (get_pref('ENABLE_FEED_CATS')) {
                                        $cat = $this->feedlist_init_cat(-2);
                                } else {
                                        $cat['items'] = array();
                                }
 
-                               while ($line = db_fetch_assoc($result)) {
+                               while ($line = $this->dbh->fetch_assoc($result)) {
 
                                        $label_id = label_to_feed_id($line['id']);
 
@@ -187,16 +189,16 @@ class Pref_Feeds extends Handler_Protected {
 
                if ($enable_cats) {
                        $show_empty_cats = $_REQUEST['force_show_empty'] ||
-                               ($_REQUEST['mode'] != 2 && !$search &&
-                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
+                               ($_REQUEST['mode'] != 2 && !$search);
 
-                       $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories
+                       $result = $this->dbh->query("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)) {
+                       while ($line = $this->dbh->fetch_assoc($result)) {
                                $cat = array();
                                $cat['id'] = 'CAT:' . $line['id'];
                                $cat['bare_id'] = (int)$line['id'];
+                               $cat['auxcounter'] = 0;
                                $cat['name'] = $line['title'];
                                $cat['items'] = array();
                                $cat['checkbox'] = false;
@@ -206,9 +208,10 @@ class Pref_Feeds extends Handler_Protected {
 
                                $cat['items'] = $this->get_category_items($line['id']);
 
-                               $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+                               $num_children = $this->calculate_children_count($cat);
+                               $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
 
-                               if (count($cat['items']) > 0 || $show_empty_cats)
+                               if ($num_children > 0 || $show_empty_cats)
                                        array_push($root['items'], $cat);
 
                                $root['param'] += count($cat['items']);
@@ -219,6 +222,7 @@ class Pref_Feeds extends Handler_Protected {
                        $cat = array();
                        $cat['id'] = 'CAT:0';
                        $cat['bare_id'] = 0;
+                       $cat['auxcounter'] = 0;
                        $cat['name'] = __("Uncategorized");
                        $cat['items'] = array();
                        $cat['type'] = 'category';
@@ -226,21 +230,22 @@ class Pref_Feeds extends Handler_Protected {
                        $cat['unread'] = 0;
                        $cat['child_unread'] = 0;
 
-                       $feed_result = db_query($this->link, "SELECT id, title,last_error,
+                       $feed_result = $this->dbh->query("SELECT id, title,last_error,
                                ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
                                FROM ttrss_feeds
                                WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"].
                                "$search_qpart ORDER BY order_id, title");
 
-                       while ($feed_line = db_fetch_assoc($feed_result)) {
+                       while ($feed_line = $this->dbh->fetch_assoc($feed_result)) {
                                $feed = array();
                                $feed['id'] = 'FEED:' . $feed_line['id'];
                                $feed['bare_id'] = (int)$feed_line['id'];
+                               $feed['auxcounter'] = 0;
                                $feed['name'] = $feed_line['title'];
                                $feed['checkbox'] = false;
                                $feed['error'] = $feed_line['last_error'];
                                $feed['icon'] = getFeedIcon($feed_line['id']);
-                               $feed['param'] = make_local_datetime($this->link,
+                               $feed['param'] = make_local_datetime(
                                        $feed_line['last_updated'], true);
                                $feed['unread'] = 0;
                                $feed['type'] = 'feed';
@@ -253,25 +258,26 @@ class Pref_Feeds extends Handler_Protected {
                        if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($root['items'], $cat);
 
-                       $root['param'] += count($cat['items']);
-                       $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+                       $num_children = $this->calculate_children_count($root);
+                       $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
 
                } else {
-                       $feed_result = db_query($this->link, "SELECT id, title, last_error,
+                       $feed_result = $this->dbh->query("SELECT id, title, last_error,
                                ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
                                FROM ttrss_feeds
                                WHERE owner_uid = ".$_SESSION["uid"].
                                "$search_qpart ORDER BY order_id, title");
 
-                       while ($feed_line = db_fetch_assoc($feed_result)) {
+                       while ($feed_line = $this->dbh->fetch_assoc($feed_result)) {
                                $feed = array();
                                $feed['id'] = 'FEED:' . $feed_line['id'];
                                $feed['bare_id'] = (int)$feed_line['id'];
+                               $feed['auxcounter'] = 0;
                                $feed['name'] = $feed_line['title'];
                                $feed['checkbox'] = false;
                                $feed['error'] = $feed_line['last_error'];
                                $feed['icon'] = getFeedIcon($feed_line['id']);
-                               $feed['param'] = make_local_datetime($this->link,
+                               $feed['param'] = make_local_datetime(
                                        $feed_line['last_updated'], true);
                                $feed['unread'] = 0;
                                $feed['type'] = 'feed';
@@ -296,22 +302,17 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function catsortreset() {
-               db_query($this->link, "UPDATE ttrss_feed_categories
+               $this->dbh->query("UPDATE ttrss_feed_categories
                                SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
                return;
        }
 
        function feedsortreset() {
-               db_query($this->link, "UPDATE ttrss_feeds
+               $this->dbh->query("UPDATE ttrss_feeds
                                SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
                return;
        }
 
-       function togglehiddenfeedcats() {
-               set_pref($this->link, '_PREFS_SHOW_EMPTY_CATS',
-                       (get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
-       }
-
        private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
                $debug = isset($_REQUEST["debug"]);
 
@@ -326,12 +327,12 @@ 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($this->link, $parent_bare_id);
+                               $parent_qpart = $this->dbh->escape_string($parent_bare_id);
                        } else {
                                $parent_qpart = 'NULL';
                        }
 
-                       db_query($this->link, "UPDATE ttrss_feed_categories
+                       $this->dbh->query("UPDATE ttrss_feed_categories
                                SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND
                                owner_uid = " . $_SESSION["uid"]);
                }
@@ -352,12 +353,12 @@ class Pref_Feeds extends Handler_Protected {
                                        if (strpos($id, "FEED") === 0) {
 
                                                $cat_id = ($item_id != "root") ?
-                                                       db_escape_string($this->link, $bare_item_id) : "NULL";
+                                                       $this->dbh->escape_string($bare_item_id) : "NULL";
 
                                                $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" :
                                                        "cat_id = NULL";
 
-                                               db_query($this->link, "UPDATE ttrss_feeds
+                                               $this->dbh->query("UPDATE ttrss_feeds
                                                        SET order_id = $order_id, $cat_qpart
                                                        WHERE id = '$bare_id' AND
                                                                owner_uid = " . $_SESSION["uid"]);
@@ -367,12 +368,12 @@ class Pref_Feeds extends Handler_Protected {
                                                        $nest_level+1);
 
                                                if ($item_id != 'root') {
-                                                       $parent_qpart = db_escape_string($this->link, $bare_id);
+                                                       $parent_qpart = $this->dbh->escape_string($bare_id);
                                                } else {
                                                        $parent_qpart = 'NULL';
                                                }
 
-                                               db_query($this->link, "UPDATE ttrss_feed_categories
+                                               $this->dbh->query("UPDATE ttrss_feed_categories
                                                                SET order_id = '$order_id' WHERE id = '$bare_id' AND
                                                                owner_uid = " . $_SESSION["uid"]);
                                        }
@@ -395,7 +396,7 @@ class Pref_Feeds extends Handler_Protected {
 #              print_r($data['items']);
 
                if (is_array($data) && is_array($data['items'])) {
-                       $cat_order_id = 0;
+#                      $cat_order_id = 0;
 
                        $data_map = array();
                        $root_item = false;
@@ -424,7 +425,7 @@ class Pref_Feeds extends Handler_Protected {
                                ++$cat_order_id;
 
                                if ($bare_id > 0) {
-                                       db_query($this->link, "UPDATE ttrss_feed_categories
+                                       $this->dbh->query("UPDATE ttrss_feed_categories
                                                SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND
                                                owner_uid = " . $_SESSION["uid"]);
                                }
@@ -441,7 +442,7 @@ class Pref_Feeds extends Handler_Protected {
                                                else
                                                        $cat_query = "cat_id = NULL";
 
-                                               db_query($this->link, "UPDATE ttrss_feeds
+                                               $this->dbh->query("UPDATE ttrss_feeds
                                                        SET order_id = '$feed_order_id',
                                                        $cat_query
                                                        WHERE id = '$feed_id' AND
@@ -457,13 +458,16 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function removeicon() {
-               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
+               $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]);
 
-               $result = db_query($this->link, "SELECT id FROM ttrss_feeds
+               $result = $this->dbh->query("SELECT id FROM ttrss_feeds
                        WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
 
-               if (db_num_rows($result) != 0) {
+               if ($this->dbh->num_rows($result) != 0) {
                        @unlink(ICONS_DIR . "/$feed_id.ico");
+
+                       $this->dbh->query("UPDATE ttrss_feeds SET favicon_avg_color = NULL
+                               where id = '$feed_id'");
                }
 
                return;
@@ -488,18 +492,23 @@ class Pref_Feeds extends Handler_Protected {
                }
 
                $icon_file = $tmp_file;
-               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
+               $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]);
 
                if (is_file($icon_file) && $feed_id) {
-                       if (filesize($icon_file) < 20000) {
+                       if (filesize($icon_file) < 65535) {
 
-                               $result = db_query($this->link, "SELECT id FROM ttrss_feeds
+                               $result = $this->dbh->query("SELECT id FROM ttrss_feeds
                                        WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
 
-                               if (db_num_rows($result) != 0) {
+                               if ($this->dbh->num_rows($result) != 0) {
                                        @unlink(ICONS_DIR . "/$feed_id.ico");
-                                       rename($icon_file, ICONS_DIR . "/$feed_id.ico");
-                                       $rc = 0;
+                                       if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) {
+                                               $this->dbh->query("UPDATE ttrss_feeds SET
+                                                       favicon_avg_color = ''
+                                                       WHERE id = '$feed_id'");
+
+                                               $rc = 0;
+                                       }
                                } else {
                                        $rc = 2;
                                }
@@ -522,16 +531,16 @@ class Pref_Feeds extends Handler_Protected {
                global $purge_intervals;
                global $update_intervals;
 
-               $feed_id = db_escape_string($this->link, $_REQUEST["id"]);
+               $feed_id = $this->dbh->escape_string($_REQUEST["id"]);
 
-               $result = db_query($this->link,
+               $result = $this->dbh->query(
                        "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
                                owner_uid = " . $_SESSION["uid"]);
 
-               $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result, 0,
+               $auth_pass_encrypted = sql_bool_to_bool($this->dbh->fetch_result($result, 0,
                        "auth_pass_encrypted"));
 
-               $title = htmlspecialchars(db_fetch_result($result,
+               $title = htmlspecialchars($this->dbh->fetch_result($result,
                        0, "title"));
 
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$feed_id\">";
@@ -549,8 +558,8 @@ class Pref_Feeds extends Handler_Protected {
 
                /* Feed URL */
 
-               $feed_url = db_fetch_result($result, 0, "feed_url");
-               $feed_url = htmlspecialchars(db_fetch_result($result,
+               $feed_url = $this->dbh->fetch_result($result, 0, "feed_url");
+               $feed_url = htmlspecialchars($this->dbh->fetch_result($result,
                        0, "feed_url"));
 
                print "<hr/>";
@@ -561,25 +570,26 @@ class Pref_Feeds extends Handler_Protected {
                        regExp='^(http|https)://.*' style=\"width : 20em\"
                        name=\"feed_url\" value=\"$feed_url\">";
 
-               $last_error = db_fetch_result($result, 0, "last_error");
+               $last_error = $this->dbh->fetch_result($result, 0, "last_error");
 
                if ($last_error) {
-                       print "&nbsp;<span title=\"".htmlspecialchars($last_error)."\"
-                               class=\"feed_error\">(error)</span>";
+                       print "&nbsp;<img src=\"images/error.png\" alt=\"(error)\"
+                               style=\"vertical-align : middle\"
+                               title=\"".htmlspecialchars($last_error)."\">";
 
                }
 
                /* Category */
 
-               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+               if (get_pref('ENABLE_FEED_CATS')) {
 
-                       $cat_id = db_fetch_result($result, 0, "cat_id");
+                       $cat_id = $this->dbh->fetch_result($result, 0, "cat_id");
 
                        print "<hr/>";
 
                        print __('Place in category:') . " ";
 
-                       print_feed_cat_select($this->link, "cat_id", $cat_id,
+                       print_feed_cat_select("cat_id", $cat_id,
                                'dojoType="dijit.form.Select"');
                }
 
@@ -590,14 +600,14 @@ class Pref_Feeds extends Handler_Protected {
 
                /* Update Interval */
 
-               $update_interval = db_fetch_result($result, 0, "update_interval");
+               $update_interval = $this->dbh->fetch_result($result, 0, "update_interval");
 
                print_select_hash("update_interval", $update_interval, $update_intervals,
                        'dojoType="dijit.form.Select"');
 
                /* Purge intl */
 
-               $purge_interval = db_fetch_result($result, 0, "purge_interval");
+               $purge_interval = $this->dbh->fetch_result($result, 0, "purge_interval");
 
                print "<hr/>";
                print __('Article purging:') . " ";
@@ -610,13 +620,13 @@ class Pref_Feeds extends Handler_Protected {
                print "<div class=\"dlgSec\">".__("Authentication")."</div>";
                print "<div class=\"dlgSecCont\">";
 
-               $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login"));
+               $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login"));
 
                print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\"
                        placeHolder=\"".__("Login")."\"
                        name=\"auth_login\" value=\"$auth_login\"><hr/>";
 
-               $auth_pass = db_fetch_result($result, 0, "auth_pass");
+               $auth_pass = $this->dbh->fetch_result($result, 0, "auth_pass");
 
                if ($auth_pass_encrypted) {
                        require_once "crypt.php";
@@ -637,7 +647,7 @@ class Pref_Feeds extends Handler_Protected {
                print "<div class=\"dlgSec\">".__("Options")."</div>";
                print "<div class=\"dlgSecCont\">";
 
-               $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
+               $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private"));
 
                if ($private) {
                        $checked = "checked=\"1\"";
@@ -648,7 +658,7 @@ 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>";
 
-               $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
+               $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest"));
 
                if ($include_in_digest) {
                        $checked = "checked=\"1\"";
@@ -661,7 +671,7 @@ class Pref_Feeds extends Handler_Protected {
                        $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
 
 
-               $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
+               $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures"));
 
                if ($always_display_enclosures) {
                        $checked = "checked";
@@ -673,7 +683,7 @@ 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"));
+               $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images"));
 
                if ($hide_images) {
                        $checked = "checked=\"1\"";
@@ -686,7 +696,7 @@ class Pref_Feeds extends Handler_Protected {
                        $checked>&nbsp;<label for=\"hide_images\">".
                __('Do not embed images')."</label>";
 
-               $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
+               $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images"));
 
                if ($cache_images) {
                        $checked = "checked=\"1\"";
@@ -699,7 +709,7 @@ class Pref_Feeds extends Handler_Protected {
                        $checked>&nbsp;<label for=\"cache_images\">".
                __('Cache images locally')."</label>";
 
-               $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
+               $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update"));
 
                if ($mark_unread_on_update) {
                        $checked = "checked";
@@ -728,14 +738,17 @@ class Pref_Feeds extends Handler_Protected {
                        <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
                        <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
                        <input type=\"hidden\" name=\"method\" value=\"uploadicon\">
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
+                       <button class=\"small\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
                                type=\"submit\">".__('Replace')."</button>
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
+                       <button class=\"small\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
                                type=\"submit\">".__('Remove')."</button>
                        </form>";
 
                print "</div>";
 
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED,
+                       "hook_prefs_edit_feed", $feed_id);
+
                $title = htmlspecialchars($title, ENT_QUOTES);
 
                print "<div class='dlgButtons'>
@@ -744,7 +757,7 @@ class Pref_Feeds extends Handler_Protected {
                                __('Unsubscribe')."</button>";
 
                if (PUBSUBHUBBUB_ENABLED) {
-                       $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
+                       $pubsub_state = $this->dbh->fetch_result($result, 0, "pubsub_state");
                        $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\"";
 
                        print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled
@@ -768,7 +781,7 @@ class Pref_Feeds extends Handler_Protected {
                global $purge_intervals;
                global $update_intervals;
 
-               $feed_ids = db_escape_string($this->link, $_REQUEST["ids"]);
+               $feed_ids = $this->dbh->escape_string($_REQUEST["ids"]);
 
                print_notice("Enable the options you wish to apply using checkboxes on the right:");
 
@@ -781,34 +794,13 @@ class Pref_Feeds extends Handler_Protected {
                print "<div class=\"dlgSec\">".__("Feed")."</div>";
                print "<div class=\"dlgSecCont\">";
 
-               /* Title */
-
-               print "<input dojoType=\"dijit.form.ValidationTextBox\"
-                       disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"
-                       name=\"title\" value=\"$title\">";
-
-               $this->batch_edit_cbox("title");
-
-               /* Feed URL */
-
-               print "<br/>";
-
-               print __('URL:') . " ";
-               print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"
-                       required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"
-                       name=\"feed_url\" value=\"$feed_url\">";
-
-               $this->batch_edit_cbox("feed_url");
-
                /* Category */
 
-               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
-
-                       print "<br/>";
+               if (get_pref('ENABLE_FEED_CATS')) {
 
                        print __('Place in category:') . " ";
 
-                       print_feed_cat_select($this->link, "cat_id", $cat_id,
+                       print_feed_cat_select("cat_id", false,
                                'disabled="1" dojoType="dijit.form.Select"');
 
                        $this->batch_edit_cbox("cat_id");
@@ -822,7 +814,7 @@ class Pref_Feeds extends Handler_Protected {
 
                /* Update Interval */
 
-               print_select_hash("update_interval", $update_interval, $update_intervals,
+               print_select_hash("update_interval", "", $update_intervals,
                        'disabled="1" dojoType="dijit.form.Select"');
 
                $this->batch_edit_cbox("update_interval");
@@ -835,7 +827,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        print __('Article purging:') . " ";
 
-                       print_select_hash("purge_interval", $purge_interval, $purge_intervals,
+                       print_select_hash("purge_interval", "", $purge_intervals,
                                'disabled="1" dojoType="dijit.form.Select"');
 
                        $this->batch_edit_cbox("purge_interval");
@@ -847,13 +839,13 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<input dojoType=\"dijit.form.TextBox\"
                        placeHolder=\"".__("Login")."\" disabled=\"1\"
-                       name=\"auth_login\" value=\"$auth_login\">";
+                       name=\"auth_login\" value=\"\">";
 
                $this->batch_edit_cbox("auth_login");
 
-               print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
+               print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
                        placeHolder=\"".__("Password")."\" disabled=\"1\"
-                       value=\"$auth_pass\">";
+                       value=\"\">";
 
                $this->batch_edit_cbox("auth_pass");
 
@@ -924,27 +916,27 @@ class Pref_Feeds extends Handler_Protected {
 
        function editsaveops($batch) {
 
-               $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"]));
+               $feed_title = $this->dbh->escape_string(trim($_POST["title"]));
+               $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"]));
+               $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]);
+               $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]);
+               $feed_id = (int) $this->dbh->escape_string($_POST["id"]); /* editSave */
+               $feed_ids = $this->dbh->escape_string($_POST["ids"]); /* batchEditSave */
+               $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]);
+               $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
                $auth_pass = trim($_POST["auth_pass"]);
-               $private = checkbox_to_sql_bool(db_escape_string($this->link, $_POST["private"]));
+               $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"]));
                $include_in_digest = checkbox_to_sql_bool(
-                       db_escape_string($this->link, $_POST["include_in_digest"]));
+                       $this->dbh->escape_string($_POST["include_in_digest"]));
                $cache_images = checkbox_to_sql_bool(
-                       db_escape_string($this->link, $_POST["cache_images"]));
+                       $this->dbh->escape_string($_POST["cache_images"]));
                $hide_images = checkbox_to_sql_bool(
-                       db_escape_string($this->link, $_POST["hide_images"]));
+                       $this->dbh->escape_string($_POST["hide_images"]));
                $always_display_enclosures = checkbox_to_sql_bool(
-                       db_escape_string($this->link, $_POST["always_display_enclosures"]));
+                       $this->dbh->escape_string($_POST["always_display_enclosures"]));
 
                $mark_unread_on_update = checkbox_to_sql_bool(
-                       db_escape_string($this->link, $_POST["mark_unread_on_update"]));
+                       $this->dbh->escape_string($_POST["mark_unread_on_update"]));
 
                if (strlen(FEED_CRYPT_KEY) > 0) {
                        require_once "crypt.php";
@@ -954,9 +946,9 @@ class Pref_Feeds extends Handler_Protected {
                        $auth_pass_encrypted = 'false';
                }
 
-               $auth_pass = db_escape_string($this->link, $auth_pass);
+               $auth_pass = $this->dbh->escape_string($auth_pass);
 
-               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+               if (get_pref('ENABLE_FEED_CATS')) {
                        if ($cat_id && $cat_id != 0) {
                                $category_qpart = "cat_id = '$cat_id',";
                                $category_qpart_nocomma = "cat_id = '$cat_id'";
@@ -971,7 +963,7 @@ class Pref_Feeds extends Handler_Protected {
 
                if (!$batch) {
 
-                       $result = db_query($this->link, "UPDATE ttrss_feeds SET
+                       $this->dbh->query("UPDATE ttrss_feeds SET
                                $category_qpart
                                title = '$feed_title', feed_url = '$feed_link',
                                update_interval = '$upd_intl',
@@ -987,6 +979,9 @@ class Pref_Feeds extends Handler_Protected {
                                mark_unread_on_update = $mark_unread_on_update
                        WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
+                       PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED,
+                               "hook_prefs_save_feed", $feed_id);
+
                } else {
                        $feed_data = array();
 
@@ -996,7 +991,7 @@ class Pref_Feeds extends Handler_Protected {
                                }
                        }
 
-                       db_query($this->link, "BEGIN");
+                       $this->dbh->query("BEGIN");
 
                        foreach (array_keys($feed_data) as $k) {
 
@@ -1059,23 +1054,23 @@ class Pref_Feeds extends Handler_Protected {
                                }
 
                                if ($qpart) {
-                                       db_query($this->link,
+                                       $this->dbh->query(
                                                "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids)
                                                AND owner_uid = " . $_SESSION["uid"]);
                                        print "<br/>";
                                }
                        }
 
-                       db_query($this->link, "COMMIT");
+                       $this->dbh->query("COMMIT");
                }
                return;
        }
 
        function resetPubSub() {
 
-               $ids = db_escape_string($this->link, $_REQUEST["ids"]);
+               $ids = $this->dbh->escape_string($_REQUEST["ids"]);
 
-               db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids)
+               $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids)
                        AND owner_uid = " . $_SESSION["uid"]);
 
                return;
@@ -1083,30 +1078,30 @@ class Pref_Feeds extends Handler_Protected {
 
        function remove() {
 
-               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
+               $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
 
                foreach ($ids as $id) {
-                       Pref_Feeds::remove_feed($this->link, $id, $_SESSION["uid"]);
+                       Pref_Feeds::remove_feed($id, $_SESSION["uid"]);
                }
 
                return;
        }
 
        function clear() {
-               $id = db_escape_string($this->link, $_REQUEST["id"]);
-               $this->clear_feed_articles($this->link, $id);
+               $id = $this->dbh->escape_string($_REQUEST["id"]);
+               $this->clear_feed_articles($id);
        }
 
        function rescore() {
                require_once "rssfuncs.php";
 
-               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
+               $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
 
                foreach ($ids as $id) {
 
-                       $filters = load_filters($this->link, $id, $_SESSION["uid"], 6);
+                       $filters = load_filters($id, $_SESSION["uid"], 6);
 
-                       $result = db_query($this->link, "SELECT
+                       $result = $this->dbh->query("SELECT
                                title, content, link, ref_id, author,".
                                SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
                                FROM
@@ -1117,9 +1112,9 @@ class Pref_Feeds extends Handler_Protected {
 
                        $scores = array();
 
-                       while ($line = db_fetch_assoc($result)) {
+                       while ($line = $this->dbh->fetch_assoc($result)) {
 
-                               $tags = get_article_tags($this->link, $line["ref_id"]);
+                               $tags = get_article_tags($line["ref_id"]);
 
                                $article_filters = get_article_filters($filters, $line['title'],
                                        $line['content'], $line['link'], strtotime($line['updated']),
@@ -1134,15 +1129,15 @@ class Pref_Feeds extends Handler_Protected {
 
                        foreach (array_keys($scores) as $s) {
                                if ($s > 1000) {
-                                       db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s',
+                                       $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
                                                marked = true WHERE
                                                ref_id IN (" . join(',', $scores[$s]) . ")");
                                } else if ($s < -500) {
-                                       db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s',
+                                       $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
                                                unread = false WHERE
                                                ref_id IN (" . join(',', $scores[$s]) . ")");
                                } else {
-                                       db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
+                                       $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE
                                                ref_id IN (" . join(',', $scores[$s]) . ")");
                                }
                        }
@@ -1154,16 +1149,16 @@ class Pref_Feeds extends Handler_Protected {
 
        function rescoreAll() {
 
-               $result = db_query($this->link,
+               $result = $this->dbh->query(
                        "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']);
 
-               while ($feed_line = db_fetch_assoc($result)) {
+               while ($feed_line = $this->dbh->fetch_assoc($result)) {
 
                        $id = $feed_line["id"];
 
-                       $filters = load_filters($this->link, $id, $_SESSION["uid"], 6);
+                       $filters = load_filters($id, $_SESSION["uid"], 6);
 
-                       $tmp_result = db_query($this->link, "SELECT
+                       $tmp_result = $this->dbh->query("SELECT
                                title, content, link, ref_id, author,".
                                        SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated
                                        FROM
@@ -1174,9 +1169,9 @@ class Pref_Feeds extends Handler_Protected {
 
                        $scores = array();
 
-                       while ($line = db_fetch_assoc($tmp_result)) {
+                       while ($line = $this->dbh->fetch_assoc($tmp_result)) {
 
-                               $tags = get_article_tags($this->link, $line["ref_id"]);
+                               $tags = get_article_tags($line["ref_id"]);
 
                                $article_filters = get_article_filters($filters, $line['title'],
                                        $line['content'], $line['link'], strtotime($line['updated']),
@@ -1191,11 +1186,11 @@ class Pref_Feeds extends Handler_Protected {
 
                        foreach (array_keys($scores) as $s) {
                                if ($s > 1000) {
-                                       db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s',
+                                       $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s',
                                                marked = true WHERE
                                                ref_id IN (" . join(',', $scores[$s]) . ")");
                                } else {
-                                       db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s' WHERE
+                                       $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE
                                                ref_id IN (" . join(',', $scores[$s]) . ")");
                                }
                        }
@@ -1206,9 +1201,9 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function categorize() {
-               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
+               $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
 
-               $cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]);
+               $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
 
                if ($cat_id == 0) {
                        $cat_id_qpart = 'NULL';
@@ -1216,30 +1211,30 @@ class Pref_Feeds extends Handler_Protected {
                        $cat_id_qpart = "'$cat_id'";
                }
 
-               db_query($this->link, "BEGIN");
+               $this->dbh->query("BEGIN");
 
                foreach ($ids as $id) {
 
-                       db_query($this->link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
+                       $this->dbh->query("UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
                                WHERE id = '$id'
                                AND owner_uid = " . $_SESSION["uid"]);
 
                }
 
-               db_query($this->link, "COMMIT");
+               $this->dbh->query("COMMIT");
        }
 
        function removeCat() {
-               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
+               $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
                foreach ($ids as $id) {
-                       $this->remove_feed_category($this->link, $id, $_SESSION["uid"]);
+                       $this->remove_feed_category($id, $_SESSION["uid"]);
                }
        }
 
        function addCat() {
-               $feed_cat = db_escape_string($this->link, trim($_REQUEST["cat"]));
+               $feed_cat = $this->dbh->escape_string(trim($_REQUEST["cat"]));
 
-               add_feed_category($this->link, $feed_cat);
+               add_feed_category($feed_cat);
        }
 
        function index() {
@@ -1247,10 +1242,10 @@ class Pref_Feeds extends Handler_Protected {
                print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
                print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">";
 
-               $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
+               $result = $this->dbh->query("SELECT COUNT(id) AS num_errors
                        FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
 
-               $num_errors = db_fetch_result($result, 0, "num_errors");
+               $num_errors = $this->dbh->fetch_result($result, 0, "num_errors");
 
                if ($num_errors > 0) {
 
@@ -1265,13 +1260,18 @@ class Pref_Feeds extends Handler_Protected {
                        $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
                }
 
-               $result = db_query($this->link, "SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
+               // could be performance-intensive and prevent feeds pref-panel from showing
+               if (!defined('_DISABLE_INACTIVE_FEEDS') || !_DISABLE_INACTIVE_FEEDS) {
+                       $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds 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"]);
 
-               $num_inactive = db_fetch_result($result, 0, "num_inactive");
+                       $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive");
+               } else {
+                       $num_inactive = 0;
+               }
 
                if ($num_inactive > 0) {
                        $inactive_button = "<button dojoType=\"dijit.form.Button\"
@@ -1279,7 +1279,7 @@ class Pref_Feeds extends Handler_Protected {
                                        __("Inactive feeds") . "</button>";
                }
 
-               $feed_search = db_escape_string($this->link, $_REQUEST["search"]);
+               $feed_search = $this->dbh->escape_string($_REQUEST["search"]);
 
                if (array_key_exists("search", $_REQUEST)) {
                        $_SESSION["prefs_feed_search"] = $feed_search;
@@ -1322,7 +1322,7 @@ class Pref_Feeds extends Handler_Protected {
                        .__('Unsubscribe')."</div> ";
                print "</div></div>";
 
-               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+               if (get_pref('ENABLE_FEED_CATS')) {
                        print "<div dojoType=\"dijit.form.DropDownButton\">".
                                        "<span>" . __('Categories')."</span>";
                        print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
@@ -1339,9 +1339,6 @@ class Pref_Feeds extends Handler_Protected {
                print $error_button;
                print $inactive_button;
 
-               print "<button onclick=\"toggleHiddenFeedCats()\"
-                       dojoType=\"dijit.form.Button\">".__('(Un)hide empty categories')."</button>";
-
                if (defined('_ENABLE_FEED_DEBUGGING')) {
 
                        print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
@@ -1406,9 +1403,7 @@ class Pref_Feeds extends Handler_Protected {
 
                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.") . " ";
-
-               print __("Only main settings profile can be migrated using OPML.") . "</p>";
+               print_notice(__("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . __("Only main settings profile can be migrated using OPML."));
 
                print "<iframe id=\"upload_iframe\"
                        name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
@@ -1442,8 +1437,7 @@ class Pref_Feeds extends Handler_Protected {
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
                        __('Display published OPML URL')."</button> ";
 
-               global $pluginhost;
-               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefFeedsOPML");
 
                print "</div>"; # pane
@@ -1452,7 +1446,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
 
-                       print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
+                       print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.'));
 
                        print "<p>";
 
@@ -1469,35 +1463,27 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
 
-               print "<h3>" . __("Published articles and generated feeds") . "</h3>";
-
-               print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
+               print_notice(__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.'));
 
                $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
                                "/public.php?op=rss&id=-2&view-mode=all_articles");;
 
+               print "<p>";
+
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
                        __('Display URL')."</button> ";
 
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
                        __('Clear all generated URLs')."</button> ";
 
-               print "<h3>" . __("Articles shared by URL") . "</h3>";
-
-               print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
+               print "</p>";
 
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
-                       __('Unshare all articles')."</button> ";
-
-               global $pluginhost;
-               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
 
                print "</div>"; #pane
 
-               global $pluginhost;
-
-               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB,
                        "hook_prefs_tab", "prefFeeds");
 
                print "</div>"; #container
@@ -1508,14 +1494,14 @@ class Pref_Feeds extends Handler_Protected {
                $cat_id = (int) $cat_id;
 
                if ($cat_id > 0) {
-                       $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
+                       $cat_unread = ccache_find($cat_id, $_SESSION["uid"], true);
                } else if ($cat_id == 0 || $cat_id == -2) {
-                       $cat_unread = getCategoryUnread($this->link, $cat_id);
+                       $cat_unread = getCategoryUnread($cat_id);
                }
 
                $obj['id'] = 'CAT:' . $cat_id;
                $obj['items'] = array();
-               $obj['name'] = getCategoryTitle($this->link, $cat_id);
+               $obj['name'] = getCategoryTitle($cat_id);
                $obj['type'] = 'category';
                $obj['unread'] = (int) $cat_unread;
                $obj['bare_id'] = $cat_id;
@@ -1528,10 +1514,10 @@ class Pref_Feeds extends Handler_Protected {
                $feed_id = (int) $feed_id;
 
                if (!$title)
-                       $title = getFeedTitle($this->link, $feed_id, false);
+                       $title = getFeedTitle($feed_id, false);
 
                if ($unread === false)
-                       $unread = getFeedUnread($this->link, $feed_id, false);
+                       $unread = getFeedUnread($feed_id, false);
 
                $obj['id'] = 'FEED:' . $feed_id;
                $obj['name'] = $title;
@@ -1541,6 +1527,7 @@ class Pref_Feeds extends Handler_Protected {
                $obj['updated'] = $updated;
                $obj['icon'] = getFeedIcon($feed_id);
                $obj['bare_id'] = $feed_id;
+               $obj['auxcounter'] = 0;
 
                return $obj;
        }
@@ -1553,7 +1540,7 @@ class Pref_Feeds extends Handler_Protected {
                        $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
                }
 
-               $result = db_query($this->link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
+               $result = $this->dbh->query("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
@@ -1565,7 +1552,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 "<h2" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</h2>";
+               print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>";
 
                print "<div dojoType=\"dijit.Toolbar\">";
                print "<div dojoType=\"dijit.form.DropDownButton\">".
@@ -1584,17 +1571,14 @@ class Pref_Feeds extends Handler_Protected {
 
                $lnum = 1;
 
-               while ($line = db_fetch_assoc($result)) {
+               while ($line = $this->dbh->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\"
@@ -1607,7 +1591,7 @@ class Pref_Feeds extends Handler_Protected {
                                htmlspecialchars($line["title"])."</a>";
 
                        print "</td><td class=\"insensitive\" align='right'>";
-                       print make_local_datetime($this->link, $line['last_article'], false);
+                       print make_local_datetime($line['last_article'], false);
                        print "</td>";
                        print "</tr>";
 
@@ -1631,10 +1615,7 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function feedsWithErrors() {
-               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
+               $result = $this->dbh->query("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\">";
@@ -1654,17 +1635,14 @@ class Pref_Feeds extends Handler_Protected {
 
                $lnum = 1;
 
-               while ($line = db_fetch_assoc($result)) {
+               while ($line = $this->dbh->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\"
@@ -1708,53 +1686,53 @@ class Pref_Feeds extends Handler_Protected {
         * @param integer $id The id of the feed to purge.
         * @return void
         */
-       private function clear_feed_articles($link, $id) {
+       private function clear_feed_articles($id) {
 
                if ($id != 0) {
-                       $result = db_query($link, "DELETE FROM ttrss_user_entries
+                       $result = $this->dbh->query("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
+                       $result = $this->dbh->query("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
+               $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE
                        (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
 
-               ccache_update($link, $id, $_SESSION['uid']);
+               ccache_update($id, $_SESSION['uid']);
        } // function clear_feed_articles
 
-       private function remove_feed_category($link, $id, $owner_uid) {
+       private function remove_feed_category($id, $owner_uid) {
 
-               db_query($link, "DELETE FROM ttrss_feed_categories
+               $this->dbh->query("DELETE FROM ttrss_feed_categories
                        WHERE id = '$id' AND owner_uid = $owner_uid");
 
-               ccache_remove($link, $id, $owner_uid, true);
+               ccache_remove($id, $owner_uid, true);
        }
 
-       static function remove_feed($link, $id, $owner_uid) {
+       static function remove_feed($id, $owner_uid) {
 
                if ($id > 0) {
 
                        /* save starred articles in Archived feed */
 
-                       db_query($link, "BEGIN");
+                       db_query("BEGIN");
 
                        /* prepare feed if necessary */
 
-                       $result = db_query($link, "SELECT feed_url FROM ttrss_feeds WHERE id = $id
+                       $result = db_query("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"));
+                       $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
 
-                       $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
+                       $result = db_query("SELECT id FROM ttrss_archived_feeds
                                WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid");
 
                        if (db_num_rows($result) == 0) {
-                               $result = db_query($link, "SELECT MAX(id) AS id FROM ttrss_archived_feeds");
+                               $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
                                $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
 
-                               db_query($link, "INSERT INTO ttrss_archived_feeds
+                               db_query("INSERT INTO ttrss_archived_feeds
                                        (id, owner_uid, title, feed_url, site_url)
                                SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds
                                WHERE id = '$id'");
@@ -1764,31 +1742,31 @@ class Pref_Feeds extends Handler_Protected {
                                $archive_id = db_fetch_result($result, 0, "id");
                        }
 
-                       db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL,
+                       db_query("UPDATE ttrss_user_entries SET feed_id = NULL,
                                orig_feed_id = '$archive_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
+                       db_query("DELETE FROM ttrss_access_keys WHERE
                                feed_id = '$id' AND owner_uid = $owner_uid");
 
                        /* remove the feed */
 
-                       db_query($link, "DELETE FROM ttrss_feeds
+                       db_query("DELETE FROM ttrss_feeds
                                        WHERE id = '$id' AND owner_uid = $owner_uid");
 
-                       db_query($link, "COMMIT");
+                       db_query("COMMIT");
 
                        if (file_exists(ICONS_DIR . "/$id.ico")) {
                                unlink(ICONS_DIR . "/$id.ico");
                        }
 
-                       ccache_remove($link, $id, $owner_uid);
+                       ccache_remove($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
+                       label_remove(feed_to_label_id($id), $owner_uid);
+                       //ccache_remove($id, $owner_uid); don't think labels are cached
                }
        }
 
@@ -1799,9 +1777,9 @@ class Pref_Feeds extends Handler_Protected {
                print "<table width='100%'><tr><td>
                        ".__("Add one valid RSS feed per line (no feed detection is done)")."
                </td><td align='right'>";
-               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+               if (get_pref('ENABLE_FEED_CATS')) {
                        print __('Place in category:') . " ";
-                       print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"');
+                       print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
                }
                print "</td></tr><tr><td colspan='2'>";
                print "<textarea
@@ -1841,17 +1819,17 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function batchAddFeeds() {
-               $cat_id = db_escape_string($this->link, $_REQUEST['cat']);
+               $cat_id = $this->dbh->escape_string($_REQUEST['cat']);
                $feeds = explode("\n", $_REQUEST['feeds']);
-               $login = db_escape_string($this->link, $_REQUEST['login']);
+               $login = $this->dbh->escape_string($_REQUEST['login']);
                $pass = trim($_REQUEST['pass']);
 
                foreach ($feeds as $feed) {
-                       $feed = db_escape_string($this->link, trim($feed));
+                       $feed = $this->dbh->escape_string(trim($feed));
 
                        if (validate_feed_url($feed)) {
 
-                               db_query($this->link, "BEGIN");
+                               $this->dbh->query("BEGIN");
 
                                if ($cat_id == "0" || !$cat_id) {
                                        $cat_qpart = "NULL";
@@ -1859,7 +1837,7 @@ class Pref_Feeds extends Handler_Protected {
                                        $cat_qpart = "'$cat_id'";
                                }
 
-                               $result = db_query($this->link,
+                               $result = $this->dbh->query(
                                        "SELECT id FROM ttrss_feeds
                                        WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]);
 
@@ -1871,69 +1849,82 @@ class Pref_Feeds extends Handler_Protected {
                                        $auth_pass_encrypted = 'false';
                                }
 
-                               $pass = db_escape_string($this->link, $pass);
+                               $pass = $this->dbh->escape_string($pass);
 
-                               if (db_num_rows($result) == 0) {
-                                       $result = db_query($this->link,
+                               if ($this->dbh->num_rows($result) == 0) {
+                                       $result = $this->dbh->query(
                                                "INSERT INTO ttrss_feeds
                                                        (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
                                                VALUES ('".$_SESSION["uid"]."', '$feed',
                                                        '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)");
                                }
 
-                               db_query($this->link, "COMMIT");
+                               $this->dbh->query("COMMIT");
                        }
                }
        }
 
        function regenOPMLKey() {
-               $this->update_feed_access_key($this->link, 'OPML:Publish',
+               $this->update_feed_access_key('OPML:Publish',
                false, $_SESSION["uid"]);
 
-               $new_link = Opml::opml_publish_url($this->link);
+               $new_link = Opml::opml_publish_url();
 
                print json_encode(array("link" => $new_link));
        }
 
        function regenFeedKey() {
-               $feed_id = db_escape_string($this->link, $_REQUEST['id']);
-               $is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true";
+               $feed_id = $this->dbh->escape_string($_REQUEST['id']);
+               $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true";
 
-               $new_key = $this->update_feed_access_key($this->link, $feed_id, $is_cat);
+               $new_key = $this->update_feed_access_key($feed_id, $is_cat);
 
                print json_encode(array("link" => $new_key));
        }
 
 
-       private function update_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) {
+       private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) {
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
                $sql_is_cat = bool_to_sql_bool($is_cat);
 
-               $result = db_query($link, "SELECT access_key FROM ttrss_access_keys
+               $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys
                        WHERE feed_id = '$feed_id'      AND is_cat = $sql_is_cat
                        AND owner_uid = " . $owner_uid);
 
-               if (db_num_rows($result) == 1) {
-                       $key = db_escape_string($this->link, sha1(uniqid(rand(), true)));
+               if ($this->dbh->num_rows($result) == 1) {
+                       $key = $this->dbh->escape_string(uniqid(base_convert(rand(), 10, 36)));
 
-                       db_query($link, "UPDATE ttrss_access_keys SET access_key = '$key'
+                       $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key'
                                WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
                                AND owner_uid = " . $owner_uid);
 
                        return $key;
 
                } else {
-                       return get_feed_access_key($link, $feed_id, $is_cat, $owner_uid);
+                       return get_feed_access_key($feed_id, $is_cat, $owner_uid);
                }
        }
 
        // Silent
        function clearKeys() {
-               db_query($this->link, "DELETE FROM ttrss_access_keys WHERE
+               $this->dbh->query("DELETE FROM ttrss_access_keys WHERE
                        owner_uid = " . $_SESSION["uid"]);
        }
 
+       private function calculate_children_count($cat) {
+               $c = 0;
+
+               foreach ($cat['items'] as $child) {
+                       if ($child['type'] == 'category') {
+                               $c += $this->calculate_children_count($child);
+                       } else {
+                               $c += 1;
+                       }
+               }
+
+               return $c;
+       }
 
 }
 ?>