X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=opml.php;h=ab71493b1fba3e8690a0e07839b620461ec2164d;hb=5f0a3741d0a549849b503eca7b6d7b87d9903069;hp=0e601e111040b68d90440c761babefc530ea4842;hpb=20fcff19c63288054253b80ebe99c510990462cb;p=tt-rss.git diff --git a/opml.php b/opml.php index 0e601e11..ab71493b 100644 --- a/opml.php +++ b/opml.php @@ -1,135 +1,202 @@ -"; - } +"; - if ($op == "Export") { print ""; - print "" . date("r", time()) . ""; + print " + " . date("r", time()) . " + Tiny Tiny RSS Feed Export + "; print ""; - $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title"); + $cat_mode = false; - while ($line = db_fetch_assoc($result)) { - $title = $line["title"]; - $url = $line["feed_url"]; + $select = "SELECT * "; + $where = "WHERE owner_uid = '$owner_uid'"; + $orderby = "ORDER BY title"; + if ($hide_private_feeds){ + $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND + auth_login = '' AND auth_pass = ''"; + } + + + + if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) { + $cat_mode = true; + $select = "SELECT + title, feed_url, site_url, + (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title"; + $orderby = "ORDER BY cat_title, title"; - print ""; } + else{ + $cat_feed = get_pref($link, 'ENABLE_FEED_CATS'); + print ""; + print ""; - print ""; - } + } - function startElement($parser, $name, $attrs) { - if ($name == "OUTLINE") { - $title = db_escape_string($attrs['TEXT']); - $url = db_escape_string($attrs['XMLURL']); + $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby); - if (!$title || !$url) return; + $old_cat_title = ""; - print "Feed $title ($url)... "; + while ($line = db_fetch_assoc($result)) { + $title = htmlspecialchars($line["title"]); + $url = htmlspecialchars($line["feed_url"]); + $site_url = htmlspecialchars($line["site_url"]); - $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); + if ($cat_mode) { + $cat_title = htmlspecialchars($line["cat_title"]); - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - title = '$title' OR feed_url = '$url'"); + if ($old_cat_title != $cat_title) { + if ($old_cat_title) { + print "\n"; + } - if ($result && db_num_rows($result) > 0) { - - print " Already imported.
"; + if ($cat_title) { + print "\n"; + } + $old_cat_title = $cat_title; + } + } + + if ($site_url) { + $html_url_qpart = "htmlUrl=\"$site_url\""; } else { - - $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url) VALUES - ('$title', '$url')"); + $html_url_qpart = ""; + } + + print "\n"; + } + + if ($cat_mode && $old_cat_title) { + print "\n"; + } + + # export tt-rss settings - print "Done.
"; + if ($include_settings) { + print ""; + + $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE + profile IS NULL AND owner_uid = " . $_SESSION["uid"]); + + while ($line = db_fetch_assoc($result)) { + + $name = $line["pref_name"]; + $value = htmlspecialchars($line["value"]); + + print ""; + + print ""; } + print ""; } + + print ""; } - function endElement($parser, $name) { + // FIXME there are some brackets issues here + $op = $_REQUEST["op"]; + if (!$op) $op = "Export"; - } + $output_name = $_REQUEST["filename"]; + if (!$output_name) $output_name = "TinyTinyRSS.opml"; - if ($op == "Import") { + $show_settings = $_REQUEST["settings"]; - print " - - - -

Importing OPML...

-
"; + if ($op == "Export") { - if (WEB_DEMO_MODE) { - print "OPML import is disabled in demo-mode."; - print "

- Return to preferences

"; + login_sequence($link); + $owner_uid = $_SESSION["uid"]; + return opml_export($link, $output_name, $owner_uid, false, ($show_settings == 1)); + } - return; - } + if ($op == "publish"){ + $key = db_escape_string($_REQUEST["key"]); - if (is_file($_FILES['opml_file']['tmp_name'])) { - - $xml_parser = xml_parser_create(); + $result = db_query($link, "SELECT owner_uid + FROM ttrss_access_keys WHERE + access_key = '$key' AND feed_id = 'OPML:Publish'"); - xml_set_element_handler($xml_parser, "startElement", "endElement"); + if (db_num_rows($result) == 1) { + $owner_uid = db_fetch_result($result, 0, "owner_uid"); + return opml_export($link, "", $owner_uid, true, false); + } else { + print "User not found"; + } + } - $fp = fopen($_FILES['opml_file']['tmp_name'], "r"); + if ($op == "Import") { - if ($fp) { + login_sequence($link); + $owner_uid = $_SESSION["uid"]; - while ($data = fread($fp, 4096)) { + header('Content-Type: text/html; charset=utf-8'); - if (!xml_parse($xml_parser, $data, feof($fp))) { - - print sprintf("Unable to parse OPML file, XML error: %s at line %d", - xml_error_string(xml_get_error_code($xml_parser)), - xml_get_current_line_number($xml_parser)); + print " + + + ".__("OPML Utility")." + + + +
+

".__('OPML Utility')."

"; - print "

- Return to preferences"; + db_query($link, "BEGIN"); - return; + /* 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"); - xml_parser_free($xml_parser); - fclose($fp); + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_feed_categories + (title,owner_uid) + VALUES ('Imported feeds', '$owner_uid')"); + } - } else { - print("Error: Could not open OPML input."); - } + db_query($link, "COMMIT"); - } else { - print "Error: please upload OPML file."; - } + print "

".__("Importing OPML...")."

"; + require_once "modules/opml_domdoc.php"; + opml_import_domdoc($link, $owner_uid); - print "

- Return to preferences"; + print "

+ +
"; - print ""; + print ""; } - db_close($link); +// if ($link) db_close($link); ?>