]>
git.wh0rd.org - tt-rss.git/blob - opml.php
89f9a94615a87f07985a3fc81911c13d789ff736
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";
12 require_once "db-prefs.php";
14 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
16 if (DB_TYPE
== "pgsql") {
17 pg_query($link, "set client_encoding = 'utf-8'");
20 if ($op == "Export") {
21 print "<opml version=\"1.0\">";
22 print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>";
25 $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title");
27 while ($line = db_fetch_assoc($result)) {
28 $title = htmlspecialchars($line["title"]);
29 $url = htmlspecialchars($line["feed_url"]);
31 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
34 print "</body></opml>";
37 function startElement($parser, $name, $attrs) {
39 if ($name == "OUTLINE") {
40 if ($name == "OUTLINE") {
42 $title = $attrs["TEXT"];
43 $url = $attrs["XMLURL"];
46 $title = $attrs['TITLE'];
50 /* this is suboptimal */
52 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
56 $title = db_escape_string_2($title, $link);
57 $url = db_escape_string_2($url, $link);
59 if (!$title ||
!$url) return;
61 print "Feed <b>$title</b> ($url)... ";
63 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
64 title = '$title' OR feed_url = '$url'");
66 if ($result && db_num_rows($result) > 0) {
68 print " Already imported.<br>";
72 $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url) VALUES
75 print "<b>Done.</b><br>";
79 if ($link) db_close($link);
84 function endElement($parser, $name) {
89 if ($op == "Import") {
93 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
95 <body><h1>Importing OPML...</h1>
98 if (get_pref($link, 'WEB_DEMO_MODE')) {
99 print "OPML import is disabled in demo-mode.";
100 print "<p><a class=\"button\" href=\"prefs.php\">
101 Return to preferences</a></div></body></html>";
106 if (is_file($_FILES['opml_file']['tmp_name'])) {
108 $xml_parser = xml_parser_create();
110 xml_set_element_handler($xml_parser, "startElement", "endElement");
112 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
116 while ($data = fread($fp, 4096)) {
118 if (!xml_parse($xml_parser, $data, feof($fp))) {
120 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
121 xml_error_string(xml_get_error_code($xml_parser)),
122 xml_get_current_line_number($xml_parser));
124 print "<p><a class=\"button\" href=\"prefs.php\">
125 Return to preferences</a>";
132 xml_parser_free($xml_parser);
136 print("Error: Could not open OPML input.");
140 print "Error: please upload OPML file.";
143 print "<p><a class=\"button\" href=\"prefs.php\">
144 Return to preferences</a>";
146 print "</div></body></html>";
150 // if ($link) db_close($link);