X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=inline;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 @@
-
- session_start();
+";
- }
-
+ 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 "
Importing OPML...
- ";
+
+
+
".__('OPML Utility')."
";
- if (WEB_DEMO_MODE) {
- print "OPML import is disabled in demo-mode.";
- print "
- Return to preferences
";
+ }
+ // 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 "