]>
git.wh0rd.org - tt-rss.git/blob - opml.php
4 // FIXME there are some brackets issues here
8 header("Content-type: application/xml");
9 print "<?xml version=\"1.0\"?>";
12 require_once "config.php";
13 require_once "db.php";
14 require_once "db-prefs.php";
16 $_SESSION["uid"] = PLACEHOLDER_UID
; // FIXME: placeholder
18 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
20 if (DB_TYPE
== "pgsql") {
21 pg_query($link, "set client_encoding = 'utf-8'");
24 if ($op == "Export") {
25 print "<opml version=\"1.0\">";
26 print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>";
29 $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title");
31 while ($line = db_fetch_assoc($result)) {
32 $title = htmlspecialchars($line["title"]);
33 $url = htmlspecialchars($line["feed_url"]);
35 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
38 print "</body></opml>";
41 function startElement($parser, $name, $attrs) {
43 if ($name == "OUTLINE") {
44 if ($name == "OUTLINE") {
46 $title = $attrs["TEXT"];
47 $url = $attrs["XMLURL"];
50 $title = $attrs['TITLE'];
54 /* this is suboptimal */
56 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
60 $title = db_escape_string_2($title, $link);
61 $url = db_escape_string_2($url, $link);
63 if (!$title ||
!$url) return;
65 print "Feed <b>$title</b> ($url)... ";
67 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
68 (title = '$title' OR feed_url = '$url') AND owner_uid = ".$_SESSION["uid"]);
70 if ($result && db_num_rows($result) > 0) {
72 print " Already imported.<br>";
76 $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url,owner_uid) VALUES
77 ('$title', '$url', '".$_SESSION["uid"]."')");
79 print "<b>Done.</b><br>";
83 if ($link) db_close($link);
88 function endElement($parser, $name) {
93 if ($op == "Import") {
97 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
99 <body><h1>Importing OPML...</h1>
103 print "OPML import is disabled in demo-mode.";
104 print "<p><a class=\"button\" href=\"prefs.php\">
105 Return to preferences</a></div></body></html>";
110 if (is_file($_FILES['opml_file']['tmp_name'])) {
112 $xml_parser = xml_parser_create();
114 xml_set_element_handler($xml_parser, "startElement", "endElement");
116 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
120 while ($data = fread($fp, 4096)) {
122 if (!xml_parse($xml_parser, $data, feof($fp))) {
124 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
125 xml_error_string(xml_get_error_code($xml_parser)),
126 xml_get_current_line_number($xml_parser));
128 print "<p><a class=\"button\" href=\"prefs.php\">
129 Return to preferences</a>";
136 xml_parser_free($xml_parser);
140 print("Error: Could not open OPML input.");
144 print "Error: please upload OPML file.";
147 print "<p><a class=\"button\" href=\"prefs.php\">
148 Return to preferences</a>";
150 print "</div></body></html>";
154 // if ($link) db_close($link);