From c03cf250e8cef7f6d49e1b1980c40de7eebf9b89 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 17 Nov 2007 10:23:44 +0100 Subject: [PATCH] place imported feeds in a separate category unless otherwise specified (closes #162) --- modules/opml_domdoc.php | 15 +++++++++++++-- modules/opml_domxml.php | 15 +++++++++++++-- opml.php | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/modules/opml_domdoc.php b/modules/opml_domdoc.php index 98eba69fa..1c0404c34 100644 --- a/modules/opml_domdoc.php +++ b/modules/opml_domdoc.php @@ -4,6 +4,16 @@ if (is_file($_FILES['opml_file']['tmp_name'])) { $doc = DOMDocument::load($_FILES['opml_file']['tmp_name']); + $result = db_query($link, "SELECT id FROM + ttrss_feed_categories WHERE title = 'Imported feeds' AND + owner_uid = '$owner_uid' LIMIT 1"); + + if (db_num_rows($result) == 1) { + $default_cat_id = db_fetch_result($result, 0, "id"); + } else { + $default_cat_id = 0; + } + if ($doc) { $body = $doc->getElementsByTagName('body'); @@ -101,8 +111,9 @@ } else { $add_query = "INSERT INTO ttrss_feeds - (title, feed_url, owner_uid, site_url) VALUES - ('$feed_title', '$feed_url', '$owner_uid', '$site_url')"; + (title, feed_url, owner_uid, cat_id, site_url) VALUES + ('$feed_title', '$feed_url', '$owner_uid', '$default_cat_id', + '$site_url')"; } diff --git a/modules/opml_domxml.php b/modules/opml_domxml.php index 54ec76b90..5b1e4067d 100644 --- a/modules/opml_domxml.php +++ b/modules/opml_domxml.php @@ -4,6 +4,16 @@ if (is_file($_FILES['opml_file']['tmp_name'])) { $dom = domxml_open_file($_FILES['opml_file']['tmp_name']); + $result = db_query($link, "SELECT id FROM + ttrss_feed_categories WHERE title = 'Imported feeds' AND + owner_uid = '$owner_uid' LIMIT 1"); + + if (db_num_rows($result) == 1) { + $default_cat_id = db_fetch_result($result, 0, "id"); + } else { + $default_cat_id = 0; + } + if ($dom) { $root = $dom->document_element(); @@ -104,8 +114,9 @@ } else { $add_query = "INSERT INTO ttrss_feeds - (title, feed_url, owner_uid, site_url) VALUES - ('$feed_title', '$feed_url', '$owner_uid', '$site_url')"; + (title, feed_url, owner_uid, cat_id, site_url) VALUES + ('$feed_title', '$feed_url', '$owner_uid', '$default_cat_id', + '$site_url')"; } diff --git a/opml.php b/opml.php index 883ddd0d9..35d7a070c 100644 --- a/opml.php +++ b/opml.php @@ -111,6 +111,24 @@

".__('OPML Utility')."

"; + db_query($link, "BEGIN"); + + /* create Imported feeds category just in case */ + + $result = db_query($link, "SELECT id FROM + ttrss_feed_categories WHERE title = 'Imported feeds' AND + owner_uid = '$owner_uid' LIMIT 1"); + + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_feed_categories + (title,owner_uid) + VALUES ('Imported feeds', '$owner_uid')"); + } + + db_query($link, "COMMIT"); + + /* Handle OPML import by DOMXML/DOMDocument */ + if (function_exists('domxml_open_file')) { print "

".__("Importing OPML (using DOMXML extension)...")."

"; require_once "modules/opml_domxml.php";