]>
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 $owner_uid = $_SESSION["uid"];
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 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
40 ORDER BY cat_title,title");
42 $result = db_query($link, "SELECT * FROM ttrss_feeds
48 while ($line = db_fetch_assoc($result)) {
49 $title = htmlspecialchars($line["title"]);
50 $url = htmlspecialchars($line["feed_url"]);
53 $cat_title = htmlspecialchars($line["cat_title"]);
55 if ($old_cat_title != $cat_title) {
60 print "<outline title=\"$cat_title\">";
62 $old_cat_title = $cat_title;
66 print "<outline text=\"$title\" xmlUrl=\"$url\"/>";
69 if ($cat_mode && $old_cat_title) {
73 print "</body></opml>";
76 if ($op == "Import") {
80 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
82 <body><h1>Importing OPML...</h1>
86 print "OPML import is disabled in demo-mode.";
87 print "<p><a class=\"button\" href=\"prefs.php\">
88 Return to preferences</a></div></body></html>";
93 if (is_file($_FILES['opml_file']['tmp_name'])) {
94 $dom = domxml_open_file($_FILES['opml_file']['tmp_name']);
97 $root = $dom->document_element();
99 $body = $root->get_elements_by_tagname('body');
104 $outlines = $body->get_elements_by_tagname('outline');
106 $active_category = '';
108 foreach ($outlines as $outline) {
109 $feed_title = $outline->get_attribute('text');
110 $cat_title = $outline->get_attribute('title');
111 $feed_url = $outline->get_attribute('xmlUrl');
114 $active_category = $cat_title;
116 db_query($link, "BEGIN");
118 $result = db_query($link, "SELECT id FROM
119 ttrss_feed_categories WHERE title = '$cat_title' AND
120 owner_uid = '$owner_uid' LIMIT 1");
122 if (db_num_rows($result) == 0) {
124 print "Adding category <b>$cat_title</b>...<br>";
126 db_query($link, "INSERT INTO ttrss_feed_categories
127 (title,owner_uid) VALUES ('$cat_title', '$owner_uid')");
130 db_query($link, "COMMIT");
133 // print "$active_category : $feed_title : $xmlurl<br>";
135 if (!$feed_title ||
!$feed_url) continue;
137 db_query($link, "BEGIN");
141 if ($active_category) {
143 $result = db_query($link, "SELECT id FROM
144 ttrss_feed_categories WHERE title = '$active_category' AND
145 owner_uid = '$owner_uid' LIMIT 1");
147 if (db_num_rows($result) == 1) {
148 $cat_id = db_fetch_result($result, 0, "id");
152 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
153 (title = '$feed_title' OR feed_url = '$feed_url')
154 AND owner_uid = '$owner_uid'");
156 print "Feed <b>$feed_title</b> ($feed_url)... ";
158 if (db_num_rows($result) > 0) {
159 print " Already imported.<br>";
163 $add_query = "INSERT INTO ttrss_feeds
164 (title, feed_url, owner_uid, cat_id) VALUES
165 ('$feed_title', '$feed_url', '$owner_uid', '$cat_id')";
168 $add_query = "INSERT INTO ttrss_feeds
169 (title, feed_url, owner_uid) VALUES
170 ('$feed_title', '$feed_url', '$owner_uid')";
174 db_query($link, $add_query);
176 print "<b>Done.</b><br>";
179 db_query($link, "COMMIT");
183 print "Error: can't find body element.";
186 print "Error while parsing document.";
190 print "Error: please upload OPML file.";
193 print "<p><a class=\"button\" href=\"prefs.php\">
194 Return to preferences</a>";
196 print "</div></body></html>";
200 // if ($link) db_close($link);