]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref_feeds.php
fix drag-and-drop categorizing of feeds into nested cats
[tt-rss.git] / classes / pref_feeds.php
index b83abd789ac15679fdb67bddf501d393e38630a0..4056c8a4ebb25e86781ad481efe2e6c2917ab2a6 100644 (file)
@@ -2,7 +2,8 @@
 class Pref_Feeds extends Protected_Handler {
 
        function csrf_ignore($method) {
-               $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed");
+               $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
+                       "savefeedorder", "uploadicon");
 
                return array_search($method, $csrf_ignored) !== false;
        }
@@ -31,6 +32,61 @@ class Pref_Feeds extends Protected_Handler {
                return;
        }
 
+       private function get_category_items($cat_id) {
+               $show_empty_cats = $_REQUEST['mode'] != 2 &&
+                       get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+
+               $items = array();
+
+               $result = db_query($this->link, "SELECT id, title, collapsed 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)) {
+
+                       $cat = array();
+                       $cat['id'] = 'CAT:' . $line['id'];
+                       $cat['bare_id'] = (int)$line['id'];
+                       $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']));
+
+                       if (count($cat['items']) > 0 || $show_empty_cats)
+                               array_push($items, $cat);
+
+               }
+
+               $feed_result = db_query($this->link, "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)) {
+                       $feed = array();
+                       $feed['id'] = 'FEED:' . $feed_line['id'];
+                       $feed['bare_id'] = (int)$feed_line['id'];
+                       $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_line['last_updated'], true);
+
+                       array_push($items, $feed);
+               }
+
+               return $items;
+       }
+
        function getfeedtree() {
 
                $search = $_SESSION["prefs_feed_search"];
@@ -43,43 +99,84 @@ class Pref_Feeds extends Protected_Handler {
                $root['items'] = array();
                $root['type'] = 'category';
 
-               if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+               $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
+
+               if ($_REQUEST['mode'] == 2) {
+
+                       if ($enable_cats) {
+                               $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
+                               $cat = $this->feedlist_init_cat(-1, $cat_hidden);
+                       } else {
+                               $cat['items'] = array();
+                       }
+
+                       foreach (array(-4, -3, -1, -2, 0) as $i) {
+                               array_push($cat['items'], $this->feedlist_init_feed($i));
+                       }
+
+                       if ($enable_cats) {
+                               array_push($root['items'], $cat);
+                       } else {
+                               $root['items'] = array_merge($root['items'], $cat['items']);
+                       }
+
+                       $result = db_query($this->link, "SELECT * FROM
+                               ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption");
+
+                       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);
+                               } else {
+                                       $cat['items'] = array();
+                               }
+
+                               while ($line = db_fetch_assoc($result)) {
+
+                                       $label_id = -$line['id'] - 11;
+                                       $count = getFeedUnread($this->link, $label_id);
+
+                                       $feed = $this->feedlist_init_feed($label_id, false, $count);
+
+                                       $feed['fg_color'] = $line['fg_color'];
+                                       $feed['bg_color'] = $line['bg_color'];
+
+                                       array_push($cat['items'], $feed);
+                               }
+
+                               if ($enable_cats) {
+                                       array_push($root['items'], $cat);
+                               } else {
+                                       $root['items'] = array_merge($root['items'], $cat['items']);
+                               }
+                       }
+               }
 
-                       $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories
-                               WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title");
+               if ($enable_cats) {
+                       $show_empty_cats = $_REQUEST['mode'] != 2 &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+
+                       $result = db_query($this->link, "SELECT id, title, collapsed 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)) {
                                $cat = array();
                                $cat['id'] = 'CAT:' . $line['id'];
-                               $cat['bare_id'] = $feed_id;
+                               $cat['bare_id'] = (int)$line['id'];
                                $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;
 
-                               $feed_result = db_query($this->link, "SELECT id, title, last_error,
-                                       ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
-                                       FROM ttrss_feeds
-                                       WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"].
-                                       "$search_qpart ORDER BY order_id, title");
-
-                               while ($feed_line = db_fetch_assoc($feed_result)) {
-                                       $feed = array();
-                                       $feed['id'] = 'FEED:' . $feed_line['id'];
-                                       $feed['bare_id'] = $feed_line['id'];
-                                       $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_line['last_updated'], true);
-
-                                       array_push($cat['items'], $feed);
-                               }
+                               $cat['items'] = $this->get_category_items($line['id']);
 
                                $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
 
-                               if (count($cat['items']) > 0)
+                               if (count($cat['items']) > 0 || $show_empty_cats)
                                        array_push($root['items'], $cat);
 
                                $root['param'] += count($cat['items']);
@@ -92,8 +189,11 @@ class Pref_Feeds extends Protected_Handler {
                        $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;
+                       $cat['child_unread'] = 0;
 
                        $feed_result = db_query($this->link, "SELECT id, title,last_error,
                                ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
@@ -104,20 +204,22 @@ class Pref_Feeds extends Protected_Handler {
                        while ($feed_line = db_fetch_assoc($feed_result)) {
                                $feed = array();
                                $feed['id'] = 'FEED:' . $feed_line['id'];
-                               $feed['bare_id'] = $feed_line['id'];
+                               $feed['bare_id'] = (int)$feed_line['id'];
                                $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_line['last_updated'], true);
+                               $feed['unread'] = 0;
+                               $feed['type'] = 'feed';
 
                                array_push($cat['items'], $feed);
                        }
 
                        $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
 
-                       if (count($cat['items']) > 0)
+                       if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($root['items'], $cat);
 
                        $root['param'] += count($cat['items']);
@@ -133,25 +235,31 @@ class Pref_Feeds extends Protected_Handler {
                        while ($feed_line = db_fetch_assoc($feed_result)) {
                                $feed = array();
                                $feed['id'] = 'FEED:' . $feed_line['id'];
-                               $feed['bare_id'] = $feed_line['id'];
+                               $feed['bare_id'] = (int)$feed_line['id'];
                                $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_line['last_updated'], true);
+                               $feed['unread'] = 0;
+                               $feed['type'] = 'feed';
 
                                array_push($root['items'], $feed);
                        }
 
                        $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
-
                }
 
                $fl = array();
                $fl['identifier'] = 'id';
                $fl['label'] = 'name';
-               $fl['items'] = array($root);
+
+               if ($_REQUEST['mode'] != 2) {
+                       $fl['items'] = array($root);
+               } else {
+                       $fl['items'] =& $root['items'];
+               }
 
                print json_encode($fl);
                return;
@@ -169,17 +277,99 @@ class Pref_Feeds extends Protected_Handler {
                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"]);
+
+               $prefix = "";
+               for ($i = 0; $i < $nest_level; $i++)
+                       $prefix .= "   ";
+
+               if ($debug) _debug("$prefix C: $item_id P: $parent_id");
+
+               $bare_item_id = substr($item_id, strpos($item_id, ':')+1);
+
+               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);
+                       } else {
+                               $parent_qpart = 'NULL';
+                       }
+
+                       db_query($this->link, "UPDATE ttrss_feed_categories
+                               SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND
+                               owner_uid = " . $_SESSION["uid"]);
+               }
+
+               $order_id = 0;
+
+               $cat = $data_map[$item_id];
+
+               if ($cat && is_array($cat)) {
+                       foreach ($cat as $item) {
+                               $id = $item['_reference'];
+                               $bare_id = substr($id, strpos($id, ':')+1);
+
+                               if ($debug) _debug("$prefix [$order_id] $id/$bare_id");
+
+                               if ($item['_reference']) {
+
+                                       if (strpos($id, "FEED") === 0) {
+
+                                               $cat_id = ($item_id != "root") ?
+                                                       db_escape_string($bare_item_id) : "NULL";
+
+                                               db_query($this->link, "UPDATE ttrss_feeds
+                                                       SET order_id = $order_id, cat_id = '$cat_id'
+                                                       WHERE id = '$bare_id' AND
+                                                               owner_uid = " . $_SESSION["uid"]);
+
+                                       } else if (strpos($id, "CAT:") === 0) {
+                                               $this->process_category_order($data_map, $item['_reference'], $item_id,
+                                                       $nest_level+1);
+
+                                               if ($item_id != 'root') {
+                                                       $parent_qpart = db_escape_string($bare_id);
+                                               } else {
+                                                       $parent_qpart = 'NULL';
+                                               }
+
+                                               db_query($this->link, "UPDATE ttrss_feed_categories
+                                                               SET order_id = '$order_id' WHERE id = '$bare_id' AND
+                                                               owner_uid = " . $_SESSION["uid"]);
+                                       }
+                               }
+
+                               ++$order_id;
+                       }
+               }
+       }
+
        function savefeedorder() {
                $data = json_decode($_POST['payload'], true);
 
+               #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
+               #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
+
+               if (!is_array($data['items']))
+                       $data['items'] = json_decode($data['items'], true);
+
+#              print_r($data['items']);
+
                if (is_array($data) && is_array($data['items'])) {
                        $cat_order_id = 0;
 
                        $data_map = array();
+                       $root_item = false;
 
                        foreach ($data['items'] as $item) {
 
-                               if ($item['id'] != 'root') {
+#                              if ($item['id'] != 'root') {
                                        if (is_array($item['items'])) {
                                                if (isset($item['items']['_reference'])) {
                                                        $data_map[$item['id']] = array($item['items']);
@@ -187,10 +377,14 @@ class Pref_Feeds extends Protected_Handler {
                                                        $data_map[$item['id']] =& $item['items'];
                                                }
                                        }
+                               if ($item['id'] == 'root') {
+                                       $root_item = $item['id'];
                                }
                        }
 
-                       foreach ($data['items'][0]['items'] as $item) {
+                       $this->process_category_order($data_map, $root_item);
+
+                       /* foreach ($data['items'][0]['items'] as $item) {
                                $id = $item['_reference'];
                                $bare_id = substr($id, strpos($id, ':')+1);
 
@@ -223,7 +417,7 @@ class Pref_Feeds extends Protected_Handler {
                                                ++$feed_order_id;
                                        }
                                }
-                       }
+                       } */
                }
 
                return;
@@ -448,12 +642,10 @@ class Pref_Feeds extends Protected_Handler {
                        $checked = "";
                }
 
-               if (SIMPLEPIE_CACHE_IMAGES) {
-                       print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
-                       name=\"cache_images\"
+               print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
+               name=\"cache_images\"
                        $checked>&nbsp;<label for=\"cache_images\">".
-                       __('Cache images locally (SimplePie only)')."</label>";
-               }
+               __('Cache images locally')."</label>";
 
                $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
 
@@ -539,6 +731,8 @@ class Pref_Feeds extends Protected_Handler {
 
                $feed_ids = db_escape_string($_REQUEST["ids"]);
 
+               print "<div class=\"dialogNotice\">" . __("Enable the options you wish to apply using checkboxes on the right:") . "</div>";
+
                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\">";
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchEditSave\">";
@@ -655,16 +849,13 @@ class Pref_Feeds extends Protected_Handler {
 
                print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
 
-               if (SIMPLEPIE_CACHE_IMAGES) {
-                       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\"
-                               for=\"cache_images\">".
-                       __('Cache images locally')."</label>";
-
+               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\"
+                       for=\"cache_images\">".
+               __('Cache images locally')."</label>";
 
-                       print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
-               }
+               print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
 
                print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\"
                        name=\"mark_unread_on_update\"
@@ -741,11 +932,7 @@ class Pref_Feeds extends Protected_Handler {
                        $category_qpart_nocomma = "";
                }
 
-               if (SIMPLEPIE_CACHE_IMAGES) {
-                       $cache_images_qpart = "cache_images = $cache_images,";
-               } else {
-                       $cache_images_qpart = "";
-               }
+               $cache_images_qpart = "cache_images = $cache_images,";
 
                if (!$batch) {
 
@@ -807,31 +994,31 @@ class Pref_Feeds extends Protected_Handler {
                                                break;
 
                                        case "private":
-                                               $qpart = "private = '$private'";
+                                               $qpart = "private = $private";
                                                break;
 
                                        case "include_in_digest":
-                                               $qpart = "include_in_digest = '$include_in_digest'";
+                                               $qpart = "include_in_digest = $include_in_digest";
                                                break;
 
                                        case "always_display_enclosures":
-                                               $qpart = "always_display_enclosures = '$always_display_enclosures'";
+                                               $qpart = "always_display_enclosures = $always_display_enclosures";
                                                break;
 
                                        case "mark_unread_on_update":
-                                               $qpart = "mark_unread_on_update = '$mark_unread_on_update'";
+                                               $qpart = "mark_unread_on_update = $mark_unread_on_update";
                                                break;
 
                                        case "update_on_checksum_change":
-                                               $qpart = "update_on_checksum_change = '$update_on_checksum_change'";
+                                               $qpart = "update_on_checksum_change = $update_on_checksum_change";
                                                break;
 
                                        case "cache_images":
-                                               $qpart = "cache_images = '$cache_images'";
+                                               $qpart = "cache_images = $cache_images";
                                                break;
 
                                        case "rtl_content":
-                                               $qpart = "rtl_content = '$rtl_content'";
+                                               $qpart = "rtl_content = $rtl_content";
                                                break;
 
                                        case "update_method":
@@ -1000,14 +1187,15 @@ class Pref_Feeds extends Protected_Handler {
                $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
 
                if ($p_from != 'tt-rss') {
-                       header("Content-Type: text/html");
+                       header('Content-Type: text/html; charset=utf-8');
                        print "<html>
                                <head>
                                        <title>Tiny Tiny RSS</title>
                                        <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
+                                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
                                </head>
                                <body>
-                               <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\"
+                               <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
                                        alt=\"Tiny Tiny RSS\"/>
                                <h1>Subscribe to feed...</h1>";
                }
@@ -1028,7 +1216,7 @@ class Pref_Feeds extends Protected_Handler {
                        print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
                        break;
                case 4:
-                       print_notice("Multiple feed URLs found.");
+                       print_notice(__("Multiple feed URLs found."));
 
                        $feed_urls = get_feeds_from_html($feed_url);
                        break;
@@ -1117,138 +1305,17 @@ class Pref_Feeds extends Protected_Handler {
                db_query($this->link, "COMMIT");
        }
 
-       function editCats() {
-
-               $action = $_REQUEST["action"];
-
-               if ($action == "save") {
-
-                       $cat_title = db_escape_string(trim($_REQUEST["value"]));
-                       $cat_id = db_escape_string($_REQUEST["cid"]);
-
-                       db_query($this->link, "BEGIN");
-
-                       $result = db_query($this->link, "SELECT title FROM ttrss_feed_categories
-                               WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
-
-                       if (db_num_rows($result) == 1) {
-
-                               $old_title = db_fetch_result($result, 0, "title");
-
-                               if ($cat_title != "") {
-                                       $result = db_query($this->link, "UPDATE ttrss_feed_categories SET
-                                               title = '$cat_title' WHERE id = '$cat_id' AND
-                                               owner_uid = ".$_SESSION["uid"]);
-
-                                       print $cat_title;
-                               } else {
-                                       print $old_title;
-                               }
-                       } else {
-                               print $_REQUEST["value"];
-                       }
-
-                       db_query($this->link, "COMMIT");
-
-                       return;
-
-               }
-
-               if ($action == "add") {
-
-                       $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
-
-                       if (!add_feed_category($this->link, $feed_cat))
-                               print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat));
-
-               }
-
-               if ($action == "remove") {
-
-                       $ids = split(",", db_escape_string($_REQUEST["ids"]));
-
-                       foreach ($ids as $id) {
-                               remove_feed_category($this->link, $id, $_SESSION["uid"]);
-                       }
-               }
-
-               print "<div dojoType=\"dijit.Toolbar\">
-                       <input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\">
-                               <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">".
-                                       __('Create category')."</button></div>";
-
-               $result = db_query($this->link, "SELECT title,id FROM ttrss_feed_categories
-                       WHERE owner_uid = ".$_SESSION["uid"]."
-                       ORDER BY title");
-
-               if (db_num_rows($result) != 0) {
-
-                       print "<div class=\"prefFeedCatHolder\">";
-
-                       print "<table width=\"100%\" class=\"prefFeedCatList\"
-                               cellspacing=\"0\" id=\"prefFeedCatList\">";
-
-                       $lnum = 0;
-
-                       while ($line = db_fetch_assoc($result)) {
-
-                               $class = ($lnum % 2) ? "even" : "odd";
-
-                               $cat_id = $line["id"];
-                               $this_row_id = "id=\"FCATR-$cat_id\"";
-
-                               print "<tr class=\"\" $this_row_id>";
-
-                               $edit_title = htmlspecialchars($line["title"]);
-
-                               print "<td width='5%' align='center'><input
-                                       onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
-                                       type=\"checkbox\"></td>";
-
-                               print "<td>";
-
-                               print "<span dojoType=\"dijit.InlineEditBox\"
-                                       width=\"300px\" autoSave=\"false\"
-                                       cat-id=\"$cat_id\">" . $edit_title .
-                                       "<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
-                                               var elem = this;
-                                               dojo.xhrPost({
-                                                       url: 'backend.php',
-                                                       content: {op: 'pref-feeds', method: 'editCats',
-                                                               action: 'save',
-                                                               value: this.value,
-                                                               cid: this.srcNodeRef.getAttribute('cat-id')},
-                                                               load: function(response) {
-                                                                       elem.attr('value', response);
-                                                                       updateFeedList();
-                                                       }
-                                               });
-                                       </script>
-                               </span>";
-
-                               print "</td></tr>";
-
-                               ++$lnum;
-                       }
-
-                       print "</table>";
-                       print "</div>";
-
-               } else {
-                       print "<p>".__('No feed categories defined.')."</p>";
+       function removeCat() {
+               $ids = split(",", db_escape_string($_REQUEST["ids"]));
+               foreach ($ids as $id) {
+                       remove_feed_category($this->link, $id, $_SESSION["uid"]);
                }
+       }
 
-               print "<div class='dlgButtons'>
-                       <div style='float : left'>
-                       <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">".
-                       __('Remove selected categories')."</button>
-                       </div>";
-
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">".
-                       __('Close this window')."</button></div>";
-
-               return;
+       function addCat() {
+               $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
 
+               add_feed_category($this->link, $feed_cat);
        }
 
        function index() {
@@ -1325,14 +1392,18 @@ class Pref_Feeds extends Protected_Handler {
                        dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
                print "<div onclick=\"resetFeedOrder()\"
                        dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
+               print "<div onclick=\"batchSubscribe()\"
+                       dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
                print "</div></div>";
 
                if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
                        print "<div dojoType=\"dijit.form.DropDownButton\">".
                                        "<span>" . __('Categories')."</span>";
                        print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
-                       print "<div onclick=\"editFeedCats()\"
-                               dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>";
+                       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></div>";
@@ -1407,47 +1478,68 @@ class Pref_Feeds extends Protected_Handler {
 
                print "</div>"; # feeds pane
 
-               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
-
-               print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.") . " ";
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Import and export')."\">";
 
-               print "<span class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</span>";
+               print "<h3>" . __("OPML") . "</h3>";
 
-               print "</p>";
+               print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
 
-               print "<h3>" . __("Import") . "</h3>";
+               print __("Only main settings profile can be migrated using OPML.") . "</p>";
 
-               print "<br/><iframe id=\"upload_iframe\"
+               print "<iframe id=\"upload_iframe\"
                        name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
                        style=\"width: 400px; height: 100px; display: none;\"></iframe>";
 
                print "<form  name=\"opml_form\" style='display : block' target=\"upload_iframe\"
                        enctype=\"multipart/form-data\" method=\"POST\"
-                               action=\"backend.php\">
+                       action=\"backend.php\">
                        <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
                        <input type=\"hidden\" name=\"op\" value=\"dlg\">
                        <input type=\"hidden\" name=\"method\" value=\"importOpml\">
                        <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
-                       __('Import') . "</button>";
+                       __('Import my OPML') . "</button>";
 
-               print "<h3>" . __("Export") . "</h3>";
+               print "<hr>";
 
                print "<p>" . __('Filename:') .
             " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" />&nbsp;" .
-            __('Include settings') . "<input type=\"checkbox\" id=\"settings\" CHECKED />" .
+                               __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>";
 
-                       "<button dojoType=\"dijit.form.Button\"
+               print "</p><button dojoType=\"dijit.form.Button\"
                        onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
-              __('Export') . "</button></p></form>";
+              __('Export OPML') . "</button></p></form>";
 
-               print "<h3>" . __("Publish") . "</h3>";
+               print "<hr>";
 
                print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
 
-               print "<span class=\"insensitive\">" . __("Note: Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") .                         "</span>" . "</p>";
+               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')\">".
-                       __('Display URL')."</button> ";
+                       __('Display published OPML URL')."</button> ";
+
+
+               print "<h3>" . __("Article archive") . "</h3>";
+
+               print "<p>" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "</p>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"return exportData()\">".
+                       __('Export my data')."</button> ";
+
+               print "<hr>";
+
+               print "<iframe id=\"data_upload_iframe\"
+                       name=\"data_upload_iframe\" onload=\"dataImportComplete(this)\"
+                       style=\"width: 400px; height: 100px; display: none;\"></iframe>";
+
+               print "<form name=\"import_form\" style='display : block' target=\"data_upload_iframe\"
+                       enctype=\"multipart/form-data\" method=\"POST\"
+                       action=\"backend.php\">
+                       <input id=\"export_file\" name=\"export_file\" type=\"file\">&nbsp;
+                       <input type=\"hidden\" name=\"op\" value=\"dlg\">
+                       <input type=\"hidden\" name=\"method\" value=\"dataimport\">
+                       <button dojoType=\"dijit.form.Button\" onclick=\"return importData();\" type=\"submit\">" .
+                       __('Import') . "</button>";
 
 
                print "</div>"; # pane
@@ -1477,7 +1569,7 @@ class Pref_Feeds extends Protected_Handler {
 
                $bm_subscribe_url = str_replace('%s', '', add_feed_url());
 
-               $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?');
+               $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?'));
 
                $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}");
 
@@ -1485,7 +1577,7 @@ class Pref_Feeds extends Protected_Handler {
 
                print "</div>"; #pane
 
-               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles and generated feeds')."\">";
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
 
                print "<h3>" . __("Published articles and generated feeds") . "</h3>";
 
@@ -1541,5 +1633,49 @@ class Pref_Feeds extends Protected_Handler {
                print "</div>"; #container
 
        }
+
+       private function feedlist_init_cat($cat_id, $hidden = false) {
+               $obj = array();
+               $cat_id = (int) $cat_id;
+
+               if ($cat_id > 0) {
+                       $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
+               } else if ($cat_id == 0 || $cat_id == -2) {
+                       $cat_unread = getCategoryUnread($this->link, $cat_id);
+               }
+
+               $obj['id'] = 'CAT:' . $cat_id;
+               $obj['items'] = array();
+               $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;
+       }
+
+       private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
+               $obj = array();
+               $feed_id = (int) $feed_id;
+
+               if (!$title)
+                       $title = getFeedTitle($this->link, $feed_id, false);
+
+               if ($unread === false)
+                       $unread = getFeedUnread($this->link, $feed_id, false);
+
+               $obj['id'] = 'FEED:' . $feed_id;
+               $obj['name'] = $title;
+               $obj['unread'] = (int) $unread;
+               $obj['type'] = 'feed';
+               $obj['error'] = $error;
+               $obj['updated'] = $updated;
+               $obj['icon'] = getFeedIcon($feed_id);
+               $obj['bare_id'] = $feed_id;
+
+               return $obj;
+       }
+
 }
 ?>