]>
Commit | Line | Data |
---|---|---|
1d3a17c7 | 1 | <?php |
36bfab86 | 2 | require_once "sessions.php"; |
5d3f29da | 3 | |
66581886 | 4 | require_once "sanity_check.php"; |
4e9f5c24 | 5 | require_once "functions.php"; |
9a4506c8 | 6 | require_once "config.php"; |
8158c57a | 7 | require_once "db.php"; |
a0111294 | 8 | require_once "db-prefs.php"; |
9a4506c8 | 9 | |
8158c57a | 10 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
9f311df6 | 11 | |
8158c57a AD |
12 | if (DB_TYPE == "pgsql") { |
13 | pg_query($link, "set client_encoding = 'utf-8'"); | |
ef063748 | 14 | pg_set_client_encoding("UNICODE"); |
8158c57a | 15 | } |
9a4506c8 | 16 | |
4e9f5c24 AD |
17 | login_sequence($link); |
18 | ||
19 | $owner_uid = $_SESSION["uid"]; | |
20 | ||
21 | // FIXME there are some brackets issues here | |
22 | ||
23 | $op = $_REQUEST["op"]; | |
24 | ||
25 | if (!$op) $op = "Export"; | |
26 | ||
27 | if ($op == "Export") { | |
12ec37f3 | 28 | header("Content-type: application/xml+opml"); |
1d3a17c7 | 29 | print "<?phpxml version=\"1.0\"?>"; |
4e9f5c24 AD |
30 | } |
31 | ||
9f311df6 | 32 | if ($op == "Export") { |
9a4506c8 | 33 | print "<opml version=\"1.0\">"; |
a90005e6 AD |
34 | print "<head> |
35 | <dateCreated>" . date("r", time()) . "</dateCreated> | |
36 | <title>Tiny Tiny RSS Feed Export</title> | |
37 | </head>"; | |
9a4506c8 AD |
38 | print "<body>"; |
39 | ||
da49ccf5 AD |
40 | $cat_mode = false; |
41 | ||
42 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
43 | $cat_mode = true; | |
44 | $result = db_query($link, "SELECT | |
fa7b8749 | 45 | title,feed_url,site_url, |
18d37445 AD |
46 | (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title |
47 | FROM ttrss_feeds | |
bc15240d AD |
48 | WHERE |
49 | owner_uid = '$owner_uid' | |
18d37445 | 50 | ORDER BY cat_title,title"); |
da49ccf5 AD |
51 | } else { |
52 | $result = db_query($link, "SELECT * FROM ttrss_feeds | |
2513ae2b | 53 | WHERE owner_uid = '$owner_uid' ORDER BY title"); |
da49ccf5 AD |
54 | } |
55 | ||
56 | $old_cat_title = ""; | |
9a4506c8 | 57 | |
8158c57a | 58 | while ($line = db_fetch_assoc($result)) { |
6e0584e9 AD |
59 | $title = htmlspecialchars($line["title"]); |
60 | $url = htmlspecialchars($line["feed_url"]); | |
fa7b8749 | 61 | $site_url = htmlspecialchars($line["site_url"]); |
9a4506c8 | 62 | |
da49ccf5 AD |
63 | if ($cat_mode) { |
64 | $cat_title = htmlspecialchars($line["cat_title"]); | |
65 | ||
66 | if ($old_cat_title != $cat_title) { | |
67 | if ($old_cat_title) { | |
5b9af2b9 | 68 | print "</outline>\n"; |
da49ccf5 AD |
69 | } |
70 | ||
5b9af2b9 AD |
71 | if ($cat_title) { |
72 | print "<outline title=\"$cat_title\">\n"; | |
73 | } | |
da49ccf5 AD |
74 | |
75 | $old_cat_title = $cat_title; | |
76 | } | |
77 | } | |
78 | ||
fa7b8749 AD |
79 | if ($site_url) { |
80 | $html_url_qpart = "htmlUrl=\"$site_url\""; | |
81 | } else { | |
82 | $html_url_qpart = ""; | |
83 | } | |
84 | ||
85 | print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n"; | |
9a4506c8 AD |
86 | } |
87 | ||
da49ccf5 | 88 | if ($cat_mode && $old_cat_title) { |
5b9af2b9 | 89 | print "</outline>\n"; |
da49ccf5 AD |
90 | } |
91 | ||
9a4506c8 AD |
92 | print "</body></opml>"; |
93 | } | |
94 | ||
e98a3f65 | 95 | if ($op == "Import") { |
8158c57a | 96 | |
e98a3f65 AD |
97 | print "<html> |
98 | <head> | |
99 | <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\"> | |
100 | </head> | |
04f6df27 | 101 | <body> |
4e9f5c24 AD |
102 | <h1><img src=\"images/ttrss_logo.png\"></h1> |
103 | <div class=\"opmlBody\"> | |
01e89f1b | 104 | <h2>"._('Importing OPML...')."</h2>"; |
9f311df6 | 105 | |
e98a3f65 AD |
106 | if (is_file($_FILES['opml_file']['tmp_name'])) { |
107 | $dom = domxml_open_file($_FILES['opml_file']['tmp_name']); | |
8b7395bb | 108 | |
e98a3f65 AD |
109 | if ($dom) { |
110 | $root = $dom->document_element(); | |
8b7395bb | 111 | |
e98a3f65 | 112 | $body = $root->get_elements_by_tagname('body'); |
8b7395bb | 113 | |
e98a3f65 AD |
114 | if ($body[0]) { |
115 | $body = $body[0]; | |
8b7395bb | 116 | |
e98a3f65 | 117 | $outlines = $body->get_elements_by_tagname('outline'); |
f179a35d | 118 | |
4e9f5c24 AD |
119 | print "<table>"; |
120 | ||
e98a3f65 | 121 | foreach ($outlines as $outline) { |
8ddf4cdc | 122 | |
04f6df27 | 123 | $feed_title = db_escape_string($outline->get_attribute('text')); |
8ddf4cdc AD |
124 | |
125 | if (!$feed_title) { | |
126 | $feed_title = db_escape_string($outline->get_attribute('title')); | |
127 | } | |
380539ce | 128 | |
04f6df27 | 129 | $cat_title = db_escape_string($outline->get_attribute('title')); |
380539ce AD |
130 | |
131 | if (!$cat_title) { | |
132 | $cat_title = db_escape_string($outline->get_attribute('text')); | |
133 | } | |
134 | ||
04f6df27 | 135 | $feed_url = db_escape_string($outline->get_attribute('xmlUrl')); |
4e9f5c24 | 136 | $site_url = db_escape_string($outline->get_attribute('htmlUrl')); |
9f311df6 | 137 | |
fa7b8749 | 138 | if ($cat_title && !$feed_url) { |
9f311df6 | 139 | |
e98a3f65 AD |
140 | db_query($link, "BEGIN"); |
141 | ||
142 | $result = db_query($link, "SELECT id FROM | |
143 | ttrss_feed_categories WHERE title = '$cat_title' AND | |
144 | owner_uid = '$owner_uid' LIMIT 1"); | |
9f311df6 | 145 | |
e98a3f65 | 146 | if (db_num_rows($result) == 0) { |
9f311df6 | 147 | |
01e89f1b AD |
148 | printf(_("Adding category <b>%s</b>..."), $cat_title); |
149 | print "<br>"; | |
9f311df6 | 150 | |
e98a3f65 | 151 | db_query($link, "INSERT INTO ttrss_feed_categories |
8ddf4cdc AD |
152 | (title,owner_uid) |
153 | VALUES ('$cat_title', '$owner_uid')"); | |
e98a3f65 | 154 | } |
7118b7ac | 155 | |
e98a3f65 AD |
156 | db_query($link, "COMMIT"); |
157 | } | |
9f311df6 | 158 | |
8ddf4cdc | 159 | // print "$active_category : $feed_title : $feed_url<br>"; |
9f311df6 | 160 | |
e98a3f65 | 161 | if (!$feed_title || !$feed_url) continue; |
9f311df6 | 162 | |
e98a3f65 | 163 | db_query($link, "BEGIN"); |
9f311df6 | 164 | |
e98a3f65 | 165 | $cat_id = null; |
eac7480c | 166 | |
04f6df27 AD |
167 | $parent_node = $outline->parent_node(); |
168 | ||
169 | if ($parent_node && $parent_node->node_name() == "outline") { | |
170 | $element_category = $parent_node->get_attribute('title'); | |
171 | } else { | |
172 | $element_category = ''; | |
173 | } | |
174 | ||
175 | if ($element_category) { | |
9f311df6 | 176 | |
e98a3f65 | 177 | $result = db_query($link, "SELECT id FROM |
04f6df27 | 178 | ttrss_feed_categories WHERE title = '$element_category' AND |
e98a3f65 | 179 | owner_uid = '$owner_uid' LIMIT 1"); |
eac7480c | 180 | |
e98a3f65 AD |
181 | if (db_num_rows($result) == 1) { |
182 | $cat_id = db_fetch_result($result, 0, "id"); | |
183 | } | |
184 | } | |
eac7480c | 185 | |
e98a3f65 AD |
186 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE |
187 | (title = '$feed_title' OR feed_url = '$feed_url') | |
188 | AND owner_uid = '$owner_uid'"); | |
9f311df6 | 189 | |
4e9f5c24 AD |
190 | print "<tr><td><a href='$site_url'><b>$feed_title</b></a></b> |
191 | (<a href=\"$feed_url\">rss</a>)</td>"; | |
9f311df6 | 192 | |
e98a3f65 | 193 | if (db_num_rows($result) > 0) { |
01e89f1b | 194 | print "<td>"._("Already imported.")."</td>"; |
e98a3f65 | 195 | } else { |
9f311df6 | 196 | |
e98a3f65 AD |
197 | if ($cat_id) { |
198 | $add_query = "INSERT INTO ttrss_feeds | |
8ddf4cdc AD |
199 | (title, feed_url, owner_uid, cat_id, site_url) VALUES |
200 | ('$feed_title', '$feed_url', '$owner_uid', | |
201 | '$cat_id', '$site_url')"; | |
9f311df6 | 202 | |
e98a3f65 AD |
203 | } else { |
204 | $add_query = "INSERT INTO ttrss_feeds | |
8ddf4cdc AD |
205 | (title, feed_url, owner_uid, site_url) VALUES |
206 | ('$feed_title', '$feed_url', '$owner_uid', '$site_url')"; | |
9f311df6 | 207 | |
e98a3f65 | 208 | } |
04f6df27 | 209 | |
e98a3f65 AD |
210 | db_query($link, $add_query); |
211 | ||
01e89f1b | 212 | print "<td><b>"._('Done.')."</b></td>"; |
e98a3f65 | 213 | } |
4e9f5c24 AD |
214 | |
215 | print "</tr>"; | |
9f311df6 | 216 | |
e98a3f65 | 217 | db_query($link, "COMMIT"); |
9f311df6 | 218 | } |
9f311df6 | 219 | |
4e9f5c24 AD |
220 | print "</table>"; |
221 | ||
e98a3f65 | 222 | } else { |
01e89f1b | 223 | print "<div class=\"error\">"._("Error: can't find body element.")."</div>"; |
e98a3f65 | 224 | } |
9f311df6 | 225 | } else { |
01e89f1b | 226 | print "<div class=\"error\">"._("Error while parsing document.")."</div>"; |
9f311df6 AD |
227 | } |
228 | ||
e98a3f65 | 229 | } else { |
01e89f1b | 230 | print "<div class=\"error\">"._("Error: please upload OPML file.")."</div>"; |
9f311df6 AD |
231 | } |
232 | ||
233 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
01e89f1b | 234 | "._("Return to preferences")."</a>"; |
9f311df6 AD |
235 | |
236 | print "</div></body></html>"; | |
237 | ||
238 | } | |
239 | ||
3d477c2c | 240 | // if ($link) db_close($link); |
9f311df6 | 241 | |
9a4506c8 | 242 | ?> |