X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=opml.php;h=44e94ee37e60bf76429650cd407d794a54f7bc98;hb=b7665618dbf7680524cb6323345e08ff5bf436f5;hp=9adeb4025ca99379d8df687e5ee78a50e6b36abc;hpb=66581886f8ace4076d2c08431904974d3f1a4f7a;p=tt-rss.git diff --git a/opml.php b/opml.php index 9adeb402..44e94ee3 100644 --- a/opml.php +++ b/opml.php @@ -1,155 +1,142 @@ -"; - } - + require_once "functions.php"; require_once "config.php"; require_once "db.php"; require_once "db-prefs.php"; -// $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder - $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (DB_TYPE == "pgsql") { - pg_query($link, "set client_encoding = 'utf-8'"); - } + init_connection($link); + login_sequence($link); + + $owner_uid = $_SESSION["uid"]; + + function opml_export($link, $owner_uid) { + header("Content-type: application/xml+opml"); + print ""; - 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; + + if (get_pref($link, 'ENABLE_FEED_CATS')) { + $cat_mode = true; + $result = db_query($link, "SELECT + title,feed_url,site_url, + (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title + FROM ttrss_feeds + WHERE + owner_uid = '$owner_uid' + ORDER BY cat_title,title"); + } else { + $result = db_query($link, "SELECT * FROM ttrss_feeds + WHERE owner_uid = '$owner_uid' ORDER BY title"); + } + + $old_cat_title = ""; while ($line = db_fetch_assoc($result)) { $title = htmlspecialchars($line["title"]); $url = htmlspecialchars($line["feed_url"]); + $site_url = htmlspecialchars($line["site_url"]); - print ""; - } + if ($cat_mode) { + $cat_title = htmlspecialchars($line["cat_title"]); - print ""; - } - - function startElement($parser, $name, $attrs) { - - if ($name == "OUTLINE") { - if ($name == "OUTLINE") { + if ($old_cat_title != $cat_title) { + if ($old_cat_title) { + print "\n"; + } - $title = $attrs["TEXT"]; - $url = $attrs["XMLURL"]; + if ($cat_title) { + print "\n"; + } - if (!$title) { - $title = $attrs['TITLE']; + $old_cat_title = $cat_title; } } - /* this is suboptimal */ - - $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - - if (!$link) return; - - $title = db_escape_string_2($title, $link); - $url = db_escape_string_2($url, $link); - - if (!$title || !$url) return; - - print "Feed $title ($url)... "; - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - (title = '$title' OR feed_url = '$url') AND owner_uid = ".$_SESSION["uid"]); - - if ($result && db_num_rows($result) > 0) { - - print " Already imported.
"; - + if ($site_url) { + $html_url_qpart = "htmlUrl=\"$site_url\""; } else { - - $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url,owner_uid) VALUES - ('$title', '$url', '".$_SESSION["uid"]."')"); - - print "Done.
"; - + $html_url_qpart = ""; } - if ($link) db_close($link); + print "\n"; + } + if ($cat_mode && $old_cat_title) { + print "\n"; } - } - function endElement($parser, $name) { + print ""; + } + // FIXME there are some brackets issues here + $op = $_REQUEST["op"]; + + if (!$op) $op = "Export"; + + if ($op == "Export") { + return opml_export($link, $owner_uid); } if ($op == "Import") { print " - + + ".__("OPML Utility")." -

Importing OPML...

-
"; + +
+

".__('OPML Utility')."

"; - if (WEB_DEMO_MODE) { - print "OPML import is disabled in demo-mode."; - print "

- Return to preferences

"; + db_query($link, "BEGIN"); - return; - } + /* create Imported feeds category just in case */ - if (is_file($_FILES['opml_file']['tmp_name'])) { - - $xml_parser = xml_parser_create(); + $result = db_query($link, "SELECT id FROM + ttrss_feed_categories WHERE title = 'Imported feeds' AND + owner_uid = '$owner_uid' LIMIT 1"); - xml_set_element_handler($xml_parser, "startElement", "endElement"); - - $fp = fopen($_FILES['opml_file']['tmp_name'], "r"); - - if ($fp) { - - while ($data = fread($fp, 4096)) { - - 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 "

- Return to preferences"; - - return; - - } - } + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_feed_categories + (title,owner_uid) + VALUES ('Imported feeds', '$owner_uid')"); + } - xml_parser_free($xml_parser); - fclose($fp); + db_query($link, "COMMIT"); - } else { - print("Error: Could not open OPML input."); - } + /* Handle OPML import by DOMXML/DOMDocument */ - } else { - print "Error: please upload OPML file."; + if (function_exists('domxml_open_file')) { + print "

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

"; + require_once "modules/opml_domxml.php"; + opml_import_domxml($link, $owner_uid); + } else if (PHP_VERSION >= 5) { + print "

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

"; + require_once "modules/opml_domdoc.php"; + opml_import_domdoc($link, $owner_uid); + } else { + print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); } - print "

- Return to preferences"; + print "

+ +
"; - print ""; + print ""; }