]>
git.wh0rd.org - tt-rss.git/blob - opml.php
2 // FIXME there are some brackets issues here
6 header("Content-type: application/xml");
7 print "<?xml version=\"1.0\"?>";
10 require_once "config.php";
11 require_once "db.php";
13 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
15 if (DB_TYPE
== "pgsql") {
16 pg_query($link, "set client_encoding = 'utf-8'");
19 if ($op == "Export") {
20 print "<opml version=\"1.0\">";
21 print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>";
24 $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title");
26 while ($line = db_fetch_assoc($result)) {
27 $title = htmlspecialchars($line["title"]);
28 $url = htmlspecialchars($line["feed_url"]);
30 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
33 print "</body></opml>";
36 function startElement($parser, $name, $attrs) {
38 if ($name == "OUTLINE") {
39 if ($name == "OUTLINE") {
41 $title = $attrs["TEXT"];
42 $url = $attrs["XMLURL"];
45 $title = $attrs['TITLE'];
49 /* this is suboptimal */
51 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
55 $title = db_escape_string_2($title, $link);
56 $url = db_escape_string_2($url, $link);
58 if (!$title ||
!$url) return;
60 print "Feed <b>$title</b> ($url)... ";
62 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
63 title = '$title' OR feed_url = '$url'");
65 if ($result && db_num_rows($result) > 0) {
67 print " Already imported.<br>";
71 $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url) VALUES
74 print "<b>Done.</b><br>";
78 if ($link) db_close($link);
83 function endElement($parser, $name) {
88 if ($op == "Import") {
92 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
94 <body><h1>Importing OPML...</h1>
98 print "OPML import is disabled in demo-mode.";
99 print "<p><a class=\"button\" href=\"prefs.php\">
100 Return to preferences</a></div></body></html>";
105 if (is_file($_FILES['opml_file']['tmp_name'])) {
107 $xml_parser = xml_parser_create();
109 xml_set_element_handler($xml_parser, "startElement", "endElement");
111 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
115 while ($data = fread($fp, 4096)) {
117 if (!xml_parse($xml_parser, $data, feof($fp))) {
119 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
120 xml_error_string(xml_get_error_code($xml_parser)),
121 xml_get_current_line_number($xml_parser));
123 print "<p><a class=\"button\" href=\"prefs.php\">
124 Return to preferences</a>";
131 xml_parser_free($xml_parser);
135 print("Error: Could not open OPML input.");
139 print "Error: please upload OPML file.";
142 print "<p><a class=\"button\" href=\"prefs.php\">
143 Return to preferences</a>";
145 print "</div></body></html>";
149 // if ($link) db_close($link);