]>
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 "functions.php";
13 $link = pg_connect(DB_CONN
);
15 pg_query($link, "set client_encoding = 'utf-8'");
17 if ($op == "Export") {
18 print "<opml version=\"1.0\">";
19 print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>";
22 $result = pg_query("SELECT * FROM ttrss_feeds ORDER BY title");
24 while ($line = pg_fetch_assoc($result)) {
25 $title = $line["title"];
26 $url = $line["feed_url"];
28 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
31 print "</body></opml>";
34 function startElement($parser, $name, $attrs) {
35 if ($name == "OUTLINE") {
36 $title = pg_escape_string($attrs['TEXT']);
37 $url = pg_escape_string($attrs['XMLURL']);
39 if (!$title ||
!$url) return;
41 print "Feed <b>$title</b> ($url)... ";
43 $result = pg_query("SELECT id FROM ttrss_feeds WHERE
44 title = '$title' OR feed_url = '$url'");
46 if (pg_num_rows($result) > 0) {
48 print " Already imported.<br>";
52 $result = pg_query("INSERT INTO ttrss_feeds (title, feed_url) VALUES
55 print "<b>Done.</b><br>";
62 function endElement($parser, $name) {
67 if ($op == "Import") {
71 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
73 <body><h1>Importing OPML...</h1>
77 print "OPML import is disabled in demo-mode.";
78 print "<p><a class=\"button\" href=\"prefs.php\">
79 Return to preferences</a></div></body></html>";
84 if (is_file($_FILES['opml_file']['tmp_name'])) {
86 $xml_parser = xml_parser_create();
88 xml_set_element_handler($xml_parser, "startElement", "endElement");
90 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
94 while ($data = fread($fp, 4096)) {
96 if (!xml_parse($xml_parser, $data, feof($fp))) {
98 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
99 xml_error_string(xml_get_error_code($xml_parser)),
100 xml_get_current_line_number($xml_parser));
102 print "<p><a class=\"button\" href=\"prefs.php\">
103 Return to preferences</a>";
110 xml_parser_free($xml_parser);
114 print("Error: Could not open OPML input.");
118 print "Error: please upload OPML file.";
121 print "<p><a class=\"button\" href=\"prefs.php\">
122 Return to preferences</a>";
124 print "</div></body></html>";