]>
git.wh0rd.org - tt-rss.git/blob - opml.php
4 require_once "sanity_check.php";
6 // FIXME there are some brackets issues here
10 header("Content-type: application/xml");
11 print "<?xml version=\"1.0\"?>";
14 require_once "config.php";
15 require_once "db.php";
16 require_once "db-prefs.php";
18 // $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
20 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
22 if (DB_TYPE
== "pgsql") {
23 pg_query($link, "set client_encoding = 'utf-8'");
26 if ($op == "Export") {
27 print "<opml version=\"1.0\">";
28 print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>";
33 if (get_pref($link, 'ENABLE_FEED_CATS')) {
35 $result = db_query($link, "SELECT
36 ttrss_feeds.feed_url AS feed_url,
37 ttrss_feeds.title AS title,
38 ttrss_feed_categories.title AS cat_title
39 FROM ttrss_feeds,ttrss_feed_categories
41 cat_id = ttrss_feed_categories.id
42 ORDER BY ttrss_feed_categories.title,ttrss_feeds.title");
44 $result = db_query($link, "SELECT * FROM ttrss_feeds
50 while ($line = db_fetch_assoc($result)) {
51 $title = htmlspecialchars($line["title"]);
52 $url = htmlspecialchars($line["feed_url"]);
55 $cat_title = htmlspecialchars($line["cat_title"]);
57 if ($old_cat_title != $cat_title) {
62 print "<outline text=\"$cat_title\">";
64 $old_cat_title = $cat_title;
68 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
71 if ($cat_mode && $old_cat_title) {
75 print "</body></opml>";
78 function startElement($parser, $name, $attrs) {
80 if ($name == "OUTLINE") {
81 if ($name == "OUTLINE") {
83 $title = $attrs["TEXT"];
84 $url = $attrs["XMLURL"];
87 $title = $attrs['TITLE'];
91 /* this is suboptimal */
93 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
97 $title = db_escape_string_2($title, $link);
98 $url = db_escape_string_2($url, $link);
100 if (!$title ||
!$url) return;
102 print "Feed <b>$title</b> ($url)... ";
104 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
105 (title = '$title' OR feed_url = '$url') AND owner_uid = ".$_SESSION["uid"]);
107 if ($result && db_num_rows($result) > 0) {
109 print " Already imported.<br>";
113 $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url,owner_uid) VALUES
114 ('$title', '$url', '".$_SESSION["uid"]."')");
116 print "<b>Done.</b><br>";
120 if ($link) db_close($link);
125 function endElement($parser, $name) {
130 if ($op == "Import") {
134 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
136 <body><h1>Importing OPML...</h1>
140 print "OPML import is disabled in demo-mode.";
141 print "<p><a class=\"button\" href=\"prefs.php\">
142 Return to preferences</a></div></body></html>";
147 if (is_file($_FILES['opml_file']['tmp_name'])) {
149 $xml_parser = xml_parser_create();
151 xml_set_element_handler($xml_parser, "startElement", "endElement");
153 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
157 while ($data = fread($fp, 4096)) {
159 if (!xml_parse($xml_parser, $data, feof($fp))) {
161 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
162 xml_error_string(xml_get_error_code($xml_parser)),
163 xml_get_current_line_number($xml_parser));
165 print "<p><a class=\"button\" href=\"prefs.php\">
166 Return to preferences</a>";
173 xml_parser_free($xml_parser);
177 print("Error: Could not open OPML input.");
181 print "Error: please upload OPML file.";
184 print "<p><a class=\"button\" href=\"prefs.php\">
185 Return to preferences</a>";
187 print "</div></body></html>";
191 // if ($link) db_close($link);