]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
implement upload-related support for open_basedir
[tt-rss.git] / classes / pref / feeds.php
index 78518c61dc6c3b7b7858b323b48d7a8295d7fa62..f57cc37d6fdebf2ea52cd88189679bafc114cfd1 100644 (file)
@@ -3,7 +3,8 @@ class Pref_Feeds extends Handler_Protected {
 
        function csrf_ignore($method) {
                $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
-                       "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds");
+                       "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds",
+                       "batchsubscribe");
 
                return array_search($method, $csrf_ignored) !== false;
        }
@@ -14,8 +15,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
@@ -33,12 +34,14 @@ class Pref_Feeds extends Handler_Protected {
 
                if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
 
-               $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
-                       get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+               // first one is set by API
+               $show_empty_cats = $_REQUEST['force_show_empty'] ||
+                       ($_REQUEST['mode'] != 2 && !$search &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
 
                $items = array();
 
-               $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)) {
@@ -49,14 +52,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);
@@ -88,6 +90,10 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function getfeedtree() {
+               print json_encode($this->makefeedtree());
+       }
+
+       function makefeedtree() {
 
                if ($_REQUEST['mode'] != 2)
                        $search = $_SESSION["prefs_feed_search"];
@@ -107,8 +113,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();
                        }
@@ -117,6 +122,32 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($cat['items'], $this->feedlist_init_feed($i));
                        }
 
+                       /* Plugin feeds for -1 */
+
+                       global $pluginhost;
+
+                       $feeds = $pluginhost->get_feeds(-1);
+
+                       if ($feeds) {
+                               foreach ($feeds as $feed) {
+                                       $feed_id = PluginHost::pfeed_to_feed_id($feed['id']);
+
+                                       $item = array();
+                                       $item['id'] = 'FEED:' . $feed_id;
+                                       $item['bare_id'] = (int)$feed_id;
+                                       $item['name'] = $feed['title'];
+                                       $item['checkbox'] = false;
+                                       $item['error'] = '';
+                                       $item['icon'] = $feed['icon'];
+
+                                       $item['param'] = '';
+                                       $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']);
+                                       $item['type'] = 'feed';
+
+                                       array_push($cat['items'], $item);
+                               }
+                       }
+
                        if ($enable_cats) {
                                array_push($root['items'], $cat);
                        } else {
@@ -129,18 +160,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'];
@@ -157,10 +186,11 @@ class Pref_Feeds extends Handler_Protected {
                }
 
                if ($enable_cats) {
-                       $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
-                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+                       $show_empty_cats = $_REQUEST['force_show_empty'] ||
+                               ($_REQUEST['mode'] != 2 && !$search &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
 
-                       $result = db_query($this->link, "SELECT id, title, 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)) {
@@ -170,14 +200,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);
@@ -192,7 +221,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;
@@ -220,13 +248,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,
@@ -251,7 +279,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();
@@ -264,8 +292,7 @@ class Pref_Feeds extends Handler_Protected {
                        $fl['items'] =& $root['items'];
                }
 
-               print json_encode($fl);
-               return;
+               return $fl;
        }
 
        function catsortreset() {
@@ -299,7 +326,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';
                        }
@@ -325,7 +352,7 @@ 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";
@@ -340,7 +367,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';
                                                }
@@ -430,21 +457,38 @@ 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"]);
 
                if (db_num_rows($result) != 0) {
-                       unlink(ICONS_DIR . "/$feed_id.ico");
+                       @unlink(ICONS_DIR . "/$feed_id.ico");
                }
 
                return;
        }
 
        function uploadicon() {
-               $icon_file = $_FILES['icon_file']['tmp_name'];
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
+               header("Content-type: text/html");
+
+               $tmp_file = false;
+
+               if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
+                       $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon');
+
+                       $result = move_uploaded_file($_FILES['icon_file']['tmp_name'],
+                               $tmp_file);
+
+                       if (!$result) {
+                               return;
+                       }
+               } else {
+                       return;
+               }
+
+               $icon_file = $tmp_file;
+               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
 
                if (is_file($icon_file) && $feed_id) {
                        if (filesize($icon_file) < 20000) {
@@ -453,8 +497,8 @@ class Pref_Feeds extends Handler_Protected {
                                        WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
 
                                if (db_num_rows($result) != 0) {
-                                       unlink(ICONS_DIR . "/$feed_id.ico");
-                                       move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico");
+                                       @unlink(ICONS_DIR . "/$feed_id.ico");
+                                       rename($icon_file, ICONS_DIR . "/$feed_id.ico");
                                        $rc = 0;
                                } else {
                                        $rc = 2;
@@ -466,6 +510,8 @@ class Pref_Feeds extends Handler_Protected {
                        $rc = 2;
                }
 
+               @unlink($icon_file);
+
                print "<script type=\"text/javascript\">";
                print "parent.uploadIconHandler($rc);";
                print "</script>";
@@ -476,7 +522,7 @@ class Pref_Feeds extends Handler_Protected {
                global $purge_intervals;
                global $update_intervals;
 
-               $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
@@ -592,17 +638,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) {
@@ -628,32 +663,31 @@ 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"));
 
-               $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
-
-               if ($cache_images) {
+               if ($hide_images) {
                        $checked = "checked=\"1\"";
                } else {
                        $checked = "";
                }
 
-               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
-               name=\"cache_images\"
-                       $checked>&nbsp;<label for=\"cache_images\">".
-               __('Cache images locally')."</label>";
+               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_content = sql_bool_to_bool(db_fetch_result($result, 0, "cache_content"));
+               $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
 
-               if ($cache_content) {
+               if ($cache_images) {
                        $checked = "checked=\"1\"";
                } else {
                        $checked = "";
                }
 
-               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_content\"
-               name=\"cache_content\"
-                       $checked>&nbsp;<label for=\"cache_content\">".
-               __('Cache content locally')."</label>";
+               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
+               name=\"cache_images\"
+                       $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"));
 
@@ -667,18 +701,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 */
@@ -736,9 +758,11 @@ class Pref_Feeds extends Handler_Protected {
                global $purge_intervals;
                global $update_intervals;
 
-               $feed_ids = db_escape_string($_REQUEST["ids"]);
+               $feed_ids = db_escape_string($this->link, $_REQUEST["ids"]);
+
+               print_notice("Enable the options you wish to apply using checkboxes on the right:");
 
-               print "<div class=\"dialogNotice\">" . __("Enable the options you wish to apply using checkboxes on the right:") . "</div>";
+               print "<p>";
 
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
@@ -832,11 +856,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>";
@@ -849,6 +868,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\"
@@ -863,12 +890,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'>
@@ -893,32 +914,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"]));
-               $cache_content = checkbox_to_sql_bool(
-                       db_escape_string($_POST["cache_content"]));
-
+                       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) {
@@ -943,13 +959,11 @@ class Pref_Feeds extends Handler_Protected {
                                auth_login = '$auth_login',
                                auth_pass = '$auth_pass',
                                private = $private,
-                               rtl_content = $rtl_content,
                                cache_images = $cache_images,
-                               cache_content = $cache_content,
+                               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
+                               mark_unread_on_update = $mark_unread_on_update
                        WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
                } else {
@@ -1008,20 +1022,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 "cache_content":
-                                               $qpart = "cache_content = $cache_content";
-                                               break;
-
-                                       case "rtl_content":
-                                               $qpart = "rtl_content = $rtl_content";
+                                       case "hide_images":
+                                               $qpart = "hide_images = $hide_images";
                                                break;
 
                                        case "cat_id":
@@ -1045,7 +1051,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"]);
@@ -1055,24 +1061,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() {
                require_once "rssfuncs.php";
 
-               $ids = split(",", db_escape_string($_REQUEST["ids"]));
+               $ids = split(",", db_escape_string($this->link, $_REQUEST["ids"]));
 
                foreach ($ids as $id) {
 
@@ -1178,9 +1184,9 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        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';
@@ -1202,14 +1208,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);
        }
@@ -1251,7 +1257,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;
@@ -1290,6 +1296,8 @@ class Pref_Feeds extends Handler_Protected {
                        dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
                print "<div onclick=\"batchSubscribe()\"
                        dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
+               print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">"
+                       .__('Unsubscribe')."</div> ";
                print "</div></div>";
 
                if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
@@ -1298,8 +1306,6 @@ class Pref_Feeds extends Handler_Protected {
                        print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
                        print "<div onclick=\"createCategory()\"
                                dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
-                       print "<div onclick=\"toggleHiddenFeedCats()\"
-                               dojoType=\"dijit.MenuItem\">".__('(Un)hide empty categories')."</div>";
                        print "<div onclick=\"resetCatOrder()\"
                                dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
                        print "<div onclick=\"removeSelectedCategories()\"
@@ -1311,8 +1317,8 @@ class Pref_Feeds extends Handler_Protected {
                print $error_button;
                print $inactive_button;
 
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">"
-                       .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> ";
+               print "<button onclick=\"toggleHiddenFeedCats()\"
+                       dojoType=\"dijit.form.Button\">".__('(Un)hide empty categories')."</button>";
 
                if (defined('_ENABLE_FEED_DEBUGGING')) {
 
@@ -1411,7 +1417,7 @@ class Pref_Feeds extends Handler_Protected {
 
                print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>";
 
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
                        __('Display published OPML URL')."</button> ";
 
                global $pluginhost;
@@ -1448,7 +1454,7 @@ class Pref_Feeds extends Handler_Protected {
                $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
                                "/public.php?op=rss&id=-2&view-mode=all_articles");;
 
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '$rss_url')\">".
+               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()\">".
@@ -1475,7 +1481,7 @@ class Pref_Feeds extends Handler_Protected {
                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;
 
@@ -1490,7 +1496,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;
@@ -1538,7 +1543,7 @@ class Pref_Feeds extends Handler_Protected {
                        GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
                        ORDER BY last_article");
 
-               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated with new content for 3 months (oldest first):") . "</div>";
+               print "<h2" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</h2>";
 
                print "<div dojoType=\"dijit.Toolbar\">";
                print "<div dojoType=\"dijit.form.DropDownButton\">".
@@ -1604,7 +1609,8 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function feedsWithErrors() {
-               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated because of errors:") . "</div>";
+               print "<h2>" . __("These feeds have not been updated because of errors:") .
+                       "</h2>";
 
                $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url
                FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
@@ -1673,5 +1679,229 @@ class Pref_Feeds extends Handler_Protected {
                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 feed_url FROM ttrss_feeds WHERE id = $id
+                               AND owner_uid = $owner_uid");
+
+                       $feed_url = db_escape_string($link, db_fetch_result($result, 0, "feed_url"));
+
+                       $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
+                               WHERE 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");
+                               $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
+
+                               db_query($link, "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'");
+
+                               $archive_id = $new_feed_id;
+                       } else {
+                               $archive_id = db_fetch_result($result, 0, "id");
+                       }
+
+                       db_query($link, "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
+                               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
+               }
+       }
+
+       function batchSubscribe() {
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">";
+
+               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')) {
+                       print __('Place in category:') . " ";
+                       print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"');
+               }
+               print "</td></tr><tr><td colspan='2'>";
+               print "<textarea
+                       style='font-size : 12px; width : 100%; height: 200px;'
+                       placeHolder=\"".__("Feeds to subscribe, One per line")."\"
+                       dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
+
+               print "</td></tr><tr><td colspan='2'>";
+
+               print "<div id='feedDlg_loginContainer' style='display : none'>
+                               " .
+                               " <input dojoType=\"dijit.form.TextBox\" name='login'\"
+                                       placeHolder=\"".__("Login")."\"
+                                       style=\"width : 10em;\"> ".
+                               " <input
+                                       placeHolder=\"".__("Password")."\"
+                                       dojoType=\"dijit.form.TextBox\" type='password'
+                                       style=\"width : 10em;\" name='pass'\">".
+                               "</div>";
+
+               print "</td></tr><tr><td colspan='2'>";
+
+               print "<div style=\"clear : both\">
+                       <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
+                                       onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
+                               <label for=\"feedDlg_loginCheck\">".
+                               __('Feeds require authentication.')."</div>";
+
+               print "</form>";
+
+               print "</td></tr></table>";
+
+               print "<div class=\"dlgButtons\">
+                       <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button>
+                       <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button>
+                       </div>";
+       }
+
+       function batchAddFeeds() {
+               $cat_id = db_escape_string($this->link, $_REQUEST['cat']);
+               $feeds = explode("\n", $_REQUEST['feeds']);
+               $login = db_escape_string($this->link, $_REQUEST['login']);
+               $pass = db_escape_string($this->link, $_REQUEST['pass']);
+
+               foreach ($feeds as $feed) {
+                       $feed = db_escape_string($this->link, trim($feed));
+
+                       if (validate_feed_url($feed)) {
+
+                               db_query($this->link, "BEGIN");
+
+                               if ($cat_id == "0" || !$cat_id) {
+                                       $cat_qpart = "NULL";
+                               } else {
+                                       $cat_qpart = "'$cat_id'";
+                               }
+
+                               $result = db_query($this->link,
+                                       "SELECT id FROM ttrss_feeds
+                                       WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]);
+
+                               if (db_num_rows($result) == 0) {
+                                       $result = db_query($this->link,
+                                               "INSERT INTO ttrss_feeds
+                                                       (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method)
+                                               VALUES ('".$_SESSION["uid"]."', '$feed',
+                                                       '[Unknown]', $cat_qpart, '$login', '$pass', 0)");
+                               }
+
+                               db_query($this->link, "COMMIT");
+                       }
+               }
+       }
+
+       function regenOPMLKey() {
+               $this->update_feed_access_key($this->link, 'OPML:Publish',
+               false, $_SESSION["uid"]);
+
+               $new_link = Opml::opml_publish_url($this->link);
+
+               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";
+
+               $new_key = $this->update_feed_access_key($this->link, $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) {
+               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
+                       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)));
+
+                       db_query($link, "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);
+               }
+       }
+
+       // Silent
+       function clearKeys() {
+               db_query($this->link, "DELETE FROM ttrss_access_keys WHERE
+                       owner_uid = " . $_SESSION["uid"]);
+       }
+
+
 }
 ?>