]>
git.wh0rd.org - tt-rss.git/blob - opml.php
2 // FIXME there are some brackets issues here
6 header("Content-type: application/xml");
9 require_once "config.php";
10 require_once "functions.php";
12 $link = pg_connect(DB_CONN
);
14 pg_query($link, "set client_encoding = 'utf-8'");
16 if ($op == "Export") {
17 print "<?xml version=\"1.0\"?>";
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 print "Feed <b>$title</b> ($url)... ";
41 $result = pg_query("SELECT id FROM ttrss_feeds WHERE
42 title = '$title' OR feed_url = '$url'");
44 if (pg_num_rows($result) > 0) {
46 print " Already imported.<br>";
50 $result = pg_query("INSERT INTO ttrss_feeds (title, feed_url) VALUES
53 print "<b>Done.</b><br>";
60 function endElement($parser, $name) {
65 if ($op == "Import") {
68 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
70 <body><h1>Importing OPML...</h1>
73 if (is_file($_FILES['opml_file']['tmp_name'])) {
75 $xml_parser = xml_parser_create();
77 xml_set_element_handler($xml_parser, "startElement", "endElement");
79 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
83 while ($data = fread($fp, 4096)) {
85 if (!xml_parse($xml_parser, $data, feof($fp))) {
87 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
88 xml_error_string(xml_get_error_code($xml_parser)),
89 xml_get_current_line_number($xml_parser));
91 print "<p><a class=\"button\" href=\"prefs.php\">
92 Return to preferences</a>";
99 xml_parser_free($xml_parser);
103 print("Error: Could not open OPML input.");
107 print "Error: please upload OPML file.";
110 print "<p><a class=\"button\" href=\"prefs.php\">
111 Return to preferences</a>";
113 print "</div></body></html>";