2 require_once "sessions.php";
4 require_once "sanity_check.php";
5 require_once "functions.php";
6 require_once "config.php";
8 require_once "db-prefs.php";
10 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
12 if (DB_TYPE == "pgsql") {
13 pg_query($link, "set client_encoding = 'utf-8'");
16 login_sequence($link);
18 $owner_uid = $_SESSION["uid"];
20 // FIXME there are some brackets issues here
22 $op = $_REQUEST["op"];
24 if (!$op) $op = "Export";
26 if ($op == "Export") {
27 header("Content-type: application/xml+opml");
28 print "<?xml version=\"1.0\"?>";
31 if ($op == "Export") {
32 print "<opml version=\"1.0\">";
34 <dateCreated>" . date("r", time()) . "</dateCreated>
35 <title>Tiny Tiny RSS Feed Export</title>
41 if (get_pref($link, 'ENABLE_FEED_CATS')) {
43 $result = db_query($link, "SELECT
44 title,feed_url,site_url,
45 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
48 owner_uid = '$owner_uid'
49 ORDER BY cat_title,title");
51 $result = db_query($link, "SELECT * FROM ttrss_feeds
52 ORDER BY title WHERE owner_uid = '$owner_uid'");
57 while ($line = db_fetch_assoc($result)) {
58 $title = htmlspecialchars($line["title"]);
59 $url = htmlspecialchars($line["feed_url"]);
60 $site_url = htmlspecialchars($line["site_url"]);
63 $cat_title = htmlspecialchars($line["cat_title"]);
65 if ($old_cat_title != $cat_title) {
71 print "<outline title=\"$cat_title\">\n";
74 $old_cat_title = $cat_title;
79 $html_url_qpart = "htmlUrl=\"$site_url\"";
84 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
87 if ($cat_mode && $old_cat_title) {
91 print "</body></opml>";
94 if ($op == "Import") {
98 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
101 <h1><img src=\"images/ttrss_logo.png\"></h1>
102 <div class=\"opmlBody\">
103 <h2>Importing OPML...</h2>";
106 print "OPML import is disabled in demo-mode.";
107 print "<p><a class=\"button\" href=\"prefs.php\">
108 Return to preferences</a></div></body></html>";
113 if (is_file($_FILES['opml_file']['tmp_name'])) {
114 $dom = domxml_open_file($_FILES['opml_file']['tmp_name']);
117 $root = $dom->document_element();
119 $body = $root->get_elements_by_tagname('body');
124 $outlines = $body->get_elements_by_tagname('outline');
128 foreach ($outlines as $outline) {
130 $feed_title = db_escape_string($outline->get_attribute('text'));
133 $feed_title = db_escape_string($outline->get_attribute('title'));
136 $cat_title = db_escape_string($outline->get_attribute('title'));
139 $cat_title = db_escape_string($outline->get_attribute('text'));
142 $feed_url = db_escape_string($outline->get_attribute('xmlUrl'));
143 $site_url = db_escape_string($outline->get_attribute('htmlUrl'));
145 if ($cat_title && !$feed_url) {
147 db_query($link, "BEGIN");
149 $result = db_query($link, "SELECT id FROM
150 ttrss_feed_categories WHERE title = '$cat_title' AND
151 owner_uid = '$owner_uid' LIMIT 1");
153 if (db_num_rows($result) == 0) {
155 print "Adding category <b>$cat_title</b>...<br>";
157 db_query($link, "INSERT INTO ttrss_feed_categories
159 VALUES ('$cat_title', '$owner_uid')");
162 db_query($link, "COMMIT");
165 // print "$active_category : $feed_title : $feed_url<br>";
167 if (!$feed_title || !$feed_url) continue;
169 db_query($link, "BEGIN");
173 $parent_node = $outline->parent_node();
175 if ($parent_node && $parent_node->node_name() == "outline") {
176 $element_category = $parent_node->get_attribute('title');
178 $element_category = '';
181 if ($element_category) {
183 $result = db_query($link, "SELECT id FROM
184 ttrss_feed_categories WHERE title = '$element_category' AND
185 owner_uid = '$owner_uid' LIMIT 1");
187 if (db_num_rows($result) == 1) {
188 $cat_id = db_fetch_result($result, 0, "id");
192 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
193 (title = '$feed_title' OR feed_url = '$feed_url')
194 AND owner_uid = '$owner_uid'");
196 print "<tr><td><a href='$site_url'><b>$feed_title</b></a></b>
197 (<a href=\"$feed_url\">rss</a>)</td>";
199 if (db_num_rows($result) > 0) {
200 print "<td>Already imported.</td>";
204 $add_query = "INSERT INTO ttrss_feeds
205 (title, feed_url, owner_uid, cat_id, site_url) VALUES
206 ('$feed_title', '$feed_url', '$owner_uid',
207 '$cat_id', '$site_url')";
210 $add_query = "INSERT INTO ttrss_feeds
211 (title, feed_url, owner_uid, site_url) VALUES
212 ('$feed_title', '$feed_url', '$owner_uid', '$site_url')";
216 db_query($link, $add_query);
218 print "<td><b>Done.</b></td>";
223 db_query($link, "COMMIT");
229 print "<div class=\"error\">Error: can't find body element.</div>";
232 print "<div class=\"error\">Error while parsing document.</div>";
236 print "<div class=\"error\">Error: please upload OPML file.</div>";
239 print "<p><a class=\"button\" href=\"prefs.php\">
240 Return to preferences</a>";
242 print "</div></body></html>";
246 // if ($link) db_close($link);