]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
remove xml stuff from backend/dlg
[tt-rss.git] / classes / pref / feeds.php
index 285995dfc044c75191681d24519cc98be1d8795f..1983987ab372be1b7744f8b0b9769408258f8234 100644 (file)
@@ -14,8 +14,8 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function renamecat() {
-               $title = db_escape_string($_REQUEST['title']);
-               $id = db_escape_string($_REQUEST['id']);
+               $title = db_escape_string($this->link, $_REQUEST['title']);
+               $id = db_escape_string($this->link, $_REQUEST['id']);
 
                if ($title) {
                        db_query($this->link, "UPDATE ttrss_feed_categories SET
@@ -33,8 +33,10 @@ class Pref_Feeds extends Handler_Protected {
 
                if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
 
-               $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
-                       get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+               // first one is set by API
+               $show_empty_cats = $_REQUEST['force_show_empty'] ||
+                       ($_REQUEST['mode'] != 2 && !$search &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
 
                $items = array();
 
@@ -55,7 +57,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        $cat['items'] = $this->get_category_items($line['id']);
 
-                       $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+                       $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                        if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($items, $cat);
@@ -87,6 +89,10 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function getfeedtree() {
+               print json_encode($this->makefeedtree());
+       }
+
+       function makefeedtree() {
 
                if ($_REQUEST['mode'] != 2)
                        $search = $_SESSION["prefs_feed_search"];
@@ -115,6 +121,32 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($cat['items'], $this->feedlist_init_feed($i));
                        }
 
+                       /* Plugin feeds for -1 */
+
+                       global $pluginhost;
+
+                       $feeds = $pluginhost->get_feeds(-1);
+
+                       if ($feeds) {
+                               foreach ($feeds as $feed) {
+                                       $feed_id = PluginHost::pfeed_to_feed_id($feed['id']);
+
+                                       $item = array();
+                                       $item['id'] = 'FEED:' . $feed_id;
+                                       $item['bare_id'] = (int)$feed_id;
+                                       $item['name'] = $feed['title'];
+                                       $item['checkbox'] = false;
+                                       $item['error'] = '';
+                                       $item['icon'] = $feed['icon'];
+
+                                       $item['param'] = '';
+                                       $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']);
+                                       $item['type'] = 'feed';
+
+                                       array_push($cat['items'], $item);
+                               }
+                       }
+
                        if ($enable_cats) {
                                array_push($root['items'], $cat);
                        } else {
@@ -134,7 +166,7 @@ class Pref_Feeds extends Handler_Protected {
 
                                while ($line = db_fetch_assoc($result)) {
 
-                                       $label_id = -$line['id'] - 11;
+                                       $label_id = label_to_feed_id($line['id']);
 
                                        $feed = $this->feedlist_init_feed($label_id, false, 0);
 
@@ -153,8 +185,9 @@ class Pref_Feeds extends Handler_Protected {
                }
 
                if ($enable_cats) {
-                       $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
-                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+                       $show_empty_cats = $_REQUEST['force_show_empty'] ||
+                               ($_REQUEST['mode'] != 2 && !$search &&
+                               get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS'));
 
                        $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories
                                WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
@@ -172,7 +205,7 @@ class Pref_Feeds extends Handler_Protected {
 
                                $cat['items'] = $this->get_category_items($line['id']);
 
-                               $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+                               $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                                if (count($cat['items']) > 0 || $show_empty_cats)
                                        array_push($root['items'], $cat);
@@ -214,13 +247,13 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($cat['items'], $feed);
                        }
 
-                       $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+                       $cat['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                        if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($root['items'], $cat);
 
                        $root['param'] += count($cat['items']);
-                       $root['param'] = T_sprintf('(%d feeds)', $root['param']);
+                       $root['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
 
                } else {
                        $feed_result = db_query($this->link, "SELECT id, title, last_error,
@@ -245,7 +278,7 @@ class Pref_Feeds extends Handler_Protected {
                                array_push($root['items'], $feed);
                        }
 
-                       $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
+                       $root['param'] = vsprintf(ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
                }
 
                $fl = array();
@@ -258,8 +291,7 @@ class Pref_Feeds extends Handler_Protected {
                        $fl['items'] =& $root['items'];
                }
 
-               print json_encode($fl);
-               return;
+               return $fl;
        }
 
        function catsortreset() {
@@ -293,7 +325,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';
                        }
@@ -319,7 +351,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";
@@ -334,7 +366,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';
                                                }
@@ -424,7 +456,7 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function removeicon() {
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
+               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
 
                $result = db_query($this->link, "SELECT id FROM ttrss_feeds
                        WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
@@ -440,7 +472,7 @@ class Pref_Feeds extends Handler_Protected {
                header("Content-type: text/html");
 
                $icon_file = $_FILES['icon_file']['tmp_name'];
-               $feed_id = db_escape_string($_REQUEST["feed_id"]);
+               $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]);
 
                if (is_file($icon_file) && $feed_id) {
                        if (filesize($icon_file) < 20000) {
@@ -472,7 +504,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
@@ -708,9 +740,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\">";
@@ -862,27 +896,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"]));
+               $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"]));
+                       db_escape_string($this->link, $_POST["cache_images"]));
                $hide_images = checkbox_to_sql_bool(
-                       db_escape_string($_POST["hide_images"]));
+                       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"]));
+                       db_escape_string($this->link, $_POST["mark_unread_on_update"]));
 
                if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
                        if ($cat_id && $cat_id != 0) {
@@ -999,7 +1033,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"]);
@@ -1009,24 +1043,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) {
-                       $this->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"]);
+               $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) {
 
@@ -1132,9 +1166,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';
@@ -1156,14 +1190,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) {
                        $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);
        }
@@ -1205,7 +1239,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;
@@ -1365,7 +1399,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;
@@ -1402,7 +1436,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()\">".
@@ -1491,7 +1525,7 @@ class Pref_Feeds extends Handler_Protected {
                        GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
                        ORDER BY last_article");
 
-               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated with new content for 3 months (oldest first):") . "</div>";
+               print "<h2" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</h2>";
 
                print "<div dojoType=\"dijit.Toolbar\">";
                print "<div dojoType=\"dijit.form.DropDownButton\">".
@@ -1557,7 +1591,8 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function feedsWithErrors() {
-               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated because of errors:") . "</div>";
+               print "<h2>" . __("These feeds have not been updated because of errors:") .
+                       "</h2>";
 
                $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url
                FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
@@ -1657,7 +1692,7 @@ class Pref_Feeds extends Handler_Protected {
                ccache_remove($link, $id, $owner_uid, true);
        }
 
-       private function remove_feed($link, $id, $owner_uid) {
+       static function remove_feed($link, $id, $owner_uid) {
 
                if ($id > 0) {
 
@@ -1667,18 +1702,27 @@ class Pref_Feeds extends Handler_Protected {
 
                        /* prepare feed if necessary */
 
+                       $result = db_query($link, "SELECT feed_url FROM ttrss_feeds WHERE id = $id
+                               AND owner_uid = $owner_uid");
+
+                       $feed_url = db_escape_string($link, db_fetch_result($result, 0, "feed_url"));
+
                        $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
-                               WHERE id = '$id'");
+                               WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid");
 
                        if (db_num_rows($result) == 0) {
                                db_query($link, "INSERT INTO ttrss_archived_feeds
                                        (id, owner_uid, title, feed_url, site_url)
                                SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds
-                               WHERE id = '$id'");
+                               WHERE id = '$id'");
+
+                               $archive_id = $id;
+                       } else {
+                               $archive_id = db_fetch_result($result, 0, "id");
                        }
 
                        db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL,
-                               orig_feed_id = '$id' WHERE feed_id = '$id' AND
+                               orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND
                                        marked = true AND owner_uid = $owner_uid");
 
                        /* Remove access key for the feed */
@@ -1700,8 +1744,8 @@ class Pref_Feeds extends Handler_Protected {
                        ccache_remove($link, $id, $owner_uid);
 
                } else {
-                       label_remove($link, -11-$id, $owner_uid);
-                       ccache_remove($link, -11-$id, $owner_uid);
+                       label_remove($link, feed_to_label_id($id), $owner_uid);
+                       //ccache_remove($link, $id, $owner_uid); don't think labels are cached
                }
        }