]>
git.wh0rd.org - tt-rss.git/blob - opml.php
4 require_once "sanity_check.php";
6 // FIXME there are some brackets issues here
10 header("Content-type: application/xml");
11 print "<?xml version=\"1.0\"?>";
14 require_once "config.php";
15 require_once "db.php";
16 require_once "db-prefs.php";
18 // $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
20 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
22 if (DB_TYPE
== "pgsql") {
23 pg_query($link, "set client_encoding = 'utf-8'");
26 if ($op == "Export") {
27 print "<opml version=\"1.0\">";
28 print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>";
31 $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title");
33 while ($line = db_fetch_assoc($result)) {
34 $title = htmlspecialchars($line["title"]);
35 $url = htmlspecialchars($line["feed_url"]);
37 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
40 print "</body></opml>";
43 function startElement($parser, $name, $attrs) {
45 if ($name == "OUTLINE") {
46 if ($name == "OUTLINE") {
48 $title = $attrs["TEXT"];
49 $url = $attrs["XMLURL"];
52 $title = $attrs['TITLE'];
56 /* this is suboptimal */
58 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
62 $title = db_escape_string_2($title, $link);
63 $url = db_escape_string_2($url, $link);
65 if (!$title ||
!$url) return;
67 print "Feed <b>$title</b> ($url)... ";
69 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
70 (title = '$title' OR feed_url = '$url') AND owner_uid = ".$_SESSION["uid"]);
72 if ($result && db_num_rows($result) > 0) {
74 print " Already imported.<br>";
78 $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url,owner_uid) VALUES
79 ('$title', '$url', '".$_SESSION["uid"]."')");
81 print "<b>Done.</b><br>";
85 if ($link) db_close($link);
90 function endElement($parser, $name) {
95 if ($op == "Import") {
99 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
101 <body><h1>Importing OPML...</h1>
105 print "OPML import is disabled in demo-mode.";
106 print "<p><a class=\"button\" href=\"prefs.php\">
107 Return to preferences</a></div></body></html>";
112 if (is_file($_FILES['opml_file']['tmp_name'])) {
114 $xml_parser = xml_parser_create();
116 xml_set_element_handler($xml_parser, "startElement", "endElement");
118 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
122 while ($data = fread($fp, 4096)) {
124 if (!xml_parse($xml_parser, $data, feof($fp))) {
126 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
127 xml_error_string(xml_get_error_code($xml_parser)),
128 xml_get_current_line_number($xml_parser));
130 print "<p><a class=\"button\" href=\"prefs.php\">
131 Return to preferences</a>";
138 xml_parser_free($xml_parser);
142 print("Error: Could not open OPML input.");
146 print "Error: please upload OPML file.";
149 print "<p><a class=\"button\" href=\"prefs.php\">
150 Return to preferences</a>";
152 print "</div></body></html>";
156 // if ($link) db_close($link);