]>
Commit | Line | Data |
---|---|---|
3f9de6cc | 1 | <?php |
369dbc19 | 2 | class Opml extends Handler_Protected { |
3f9de6cc AD |
3 | |
4 | function csrf_ignore($method) { | |
5 | $csrf_ignored = array("export", "import"); | |
6 | ||
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
10 | function export() { | |
11 | $output_name = $_REQUEST["filename"]; | |
12 | if (!$output_name) $output_name = "TinyTinyRSS.opml"; | |
13 | ||
14 | $show_settings = $_REQUEST["settings"]; | |
15 | ||
16 | $owner_uid = $_SESSION["uid"]; | |
17 | return $this->opml_export($output_name, $owner_uid, false, ($show_settings == 1)); | |
18 | } | |
19 | ||
20 | function import() { | |
21 | $owner_uid = $_SESSION["uid"]; | |
22 | ||
23 | header('Content-Type: text/html; charset=utf-8'); | |
24 | ||
25 | print "<html> | |
26 | <head> | |
27 | <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\"> | |
28 | <title>".__("OPML Utility")."</title> | |
29 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> | |
30 | </head> | |
31 | <body> | |
884d1650 AD |
32 | <div class=\"floatingLogo\"><img src=\"images/logo_small.png\"></div> |
33 | <h1>".__('OPML Utility')."</h1><div class='content'>"; | |
3f9de6cc | 34 | |
a42c55f0 | 35 | add_feed_category("Imported feeds"); |
3f9de6cc AD |
36 | |
37 | $this->opml_notice(__("Importing OPML...")); | |
38 | $this->opml_import($owner_uid); | |
39 | ||
40 | print "<br><form method=\"GET\" action=\"prefs.php\"> | |
41 | <input type=\"submit\" value=\"".__("Return to preferences")."\"> | |
42 | </form>"; | |
43 | ||
884d1650 | 44 | print "</div></body></html>"; |
3f9de6cc AD |
45 | |
46 | ||
47 | } | |
48 | ||
49 | // Export | |
50 | ||
51 | private function opml_export_category($owner_uid, $cat_id, $hide_private_feeds=false) { | |
52 | ||
53 | if ($cat_id) { | |
54 | $cat_qpart = "parent_cat = '$cat_id'"; | |
55 | $feed_cat_qpart = "cat_id = '$cat_id'"; | |
56 | } else { | |
57 | $cat_qpart = "parent_cat IS NULL"; | |
58 | $feed_cat_qpart = "cat_id IS NULL"; | |
59 | } | |
60 | ||
61 | if ($hide_private_feeds) | |
62 | $hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')"; | |
63 | else | |
64 | $hide_qpart = "true"; | |
65 | ||
66 | $out = ""; | |
67 | ||
68 | if ($cat_id) { | |
d9c85e0f | 69 | $result = $this->dbh->query("SELECT title FROM ttrss_feed_categories WHERE id = '$cat_id' |
3f9de6cc | 70 | AND owner_uid = '$owner_uid'"); |
d9c85e0f | 71 | $cat_title = htmlspecialchars($this->dbh->fetch_result($result, 0, "title")); |
3f9de6cc AD |
72 | } |
73 | ||
fd087799 | 74 | if ($cat_title) $out .= "<outline text=\"$cat_title\">\n"; |
3f9de6cc | 75 | |
d9c85e0f | 76 | $result = $this->dbh->query("SELECT id,title |
3f9de6cc AD |
77 | FROM ttrss_feed_categories WHERE |
78 | $cat_qpart AND owner_uid = '$owner_uid' ORDER BY order_id, title"); | |
79 | ||
d9c85e0f | 80 | while ($line = $this->dbh->fetch_assoc($result)) { |
3f9de6cc AD |
81 | $title = htmlspecialchars($line["title"]); |
82 | $out .= $this->opml_export_category($owner_uid, $line["id"], $hide_private_feeds); | |
83 | } | |
84 | ||
d9c85e0f | 85 | $feeds_result = $this->dbh->query("select title, feed_url, site_url |
3f9de6cc AD |
86 | from ttrss_feeds where $feed_cat_qpart AND owner_uid = '$owner_uid' AND $hide_qpart |
87 | order by order_id, title"); | |
88 | ||
d9c85e0f | 89 | while ($fline = $this->dbh->fetch_assoc($feeds_result)) { |
3f9de6cc AD |
90 | $title = htmlspecialchars($fline["title"]); |
91 | $url = htmlspecialchars($fline["feed_url"]); | |
92 | $site_url = htmlspecialchars($fline["site_url"]); | |
93 | ||
94 | if ($site_url) { | |
95 | $html_url_qpart = "htmlUrl=\"$site_url\""; | |
96 | } else { | |
97 | $html_url_qpart = ""; | |
98 | } | |
99 | ||
100 | $out .= "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n"; | |
101 | } | |
102 | ||
103 | if ($cat_title) $out .= "</outline>\n"; | |
104 | ||
105 | return $out; | |
106 | } | |
107 | ||
108 | function opml_export($name, $owner_uid, $hide_private_feeds=false, $include_settings=true) { | |
109 | if (!$owner_uid) return; | |
110 | ||
111 | if (!isset($_REQUEST["debug"])) { | |
112 | header("Content-type: application/xml+opml"); | |
113 | header("Content-Disposition: attachment; filename=" . $name ); | |
114 | } else { | |
115 | header("Content-type: text/xml"); | |
116 | } | |
117 | ||
118 | $out = "<?xml version=\"1.0\" encoding=\"utf-8\"?".">"; | |
119 | ||
120 | $out .= "<opml version=\"1.0\">"; | |
121 | $out .= "<head> | |
122 | <dateCreated>" . date("r", time()) . "</dateCreated> | |
123 | <title>Tiny Tiny RSS Feed Export</title> | |
124 | </head>"; | |
125 | $out .= "<body>"; | |
126 | ||
127 | $out .= $this->opml_export_category($owner_uid, false, $hide_private_feeds); | |
128 | ||
129 | # export tt-rss settings | |
130 | ||
131 | if ($include_settings) { | |
fd087799 | 132 | $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; |
3f9de6cc | 133 | |
d9c85e0f | 134 | $result = $this->dbh->query("SELECT pref_name, value FROM ttrss_user_prefs WHERE |
3f9de6cc AD |
135 | profile IS NULL AND owner_uid = " . $_SESSION["uid"] . " ORDER BY pref_name"); |
136 | ||
d9c85e0f | 137 | while ($line = $this->dbh->fetch_assoc($result)) { |
3f9de6cc AD |
138 | $name = $line["pref_name"]; |
139 | $value = htmlspecialchars($line["value"]); | |
140 | ||
141 | $out .= "<outline pref-name=\"$name\" value=\"$value\"/>"; | |
142 | } | |
143 | ||
144 | $out .= "</outline>"; | |
145 | ||
fd087799 | 146 | $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">"; |
3f9de6cc | 147 | |
d9c85e0f | 148 | $result = $this->dbh->query("SELECT * FROM ttrss_labels2 WHERE |
3f9de6cc AD |
149 | owner_uid = " . $_SESSION['uid']); |
150 | ||
d9c85e0f | 151 | while ($line = $this->dbh->fetch_assoc($result)) { |
3f9de6cc AD |
152 | $name = htmlspecialchars($line['caption']); |
153 | $fg_color = htmlspecialchars($line['fg_color']); | |
154 | $bg_color = htmlspecialchars($line['bg_color']); | |
155 | ||
156 | $out .= "<outline label-name=\"$name\" label-fg-color=\"$fg_color\" label-bg-color=\"$bg_color\"/>"; | |
157 | ||
158 | } | |
159 | ||
160 | $out .= "</outline>"; | |
161 | ||
fd087799 | 162 | $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">"; |
3f9de6cc | 163 | |
d9c85e0f | 164 | $result = $this->dbh->query("SELECT * FROM ttrss_filters2 |
fd994f1a | 165 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY id"); |
3f9de6cc | 166 | |
d9c85e0f | 167 | while ($line = $this->dbh->fetch_assoc($result)) { |
8b6e08a1 | 168 | foreach (array('enabled', 'match_any_rule') as $b) { |
3f9de6cc AD |
169 | $line[$b] = sql_bool_to_bool($line[$b]); |
170 | } | |
171 | ||
fd994f1a AD |
172 | $line["rules"] = array(); |
173 | $line["actions"] = array(); | |
174 | ||
d9c85e0f | 175 | $tmp_result = $this->dbh->query("SELECT * FROM ttrss_filters2_rules |
fd994f1a AD |
176 | WHERE filter_id = ".$line["id"]); |
177 | ||
d9c85e0f | 178 | while ($tmp_line = $this->dbh->fetch_assoc($tmp_result)) { |
fd994f1a AD |
179 | unset($tmp_line["id"]); |
180 | unset($tmp_line["filter_id"]); | |
181 | ||
182 | $cat_filter = sql_bool_to_bool($tmp_line["cat_filter"]); | |
183 | ||
184 | if ($cat_filter && $tmp_line["cat_id"] || $tmp_line["feed_id"]) { | |
6322ac79 | 185 | $tmp_line["feed"] = getFeedTitle( |
fd994f1a AD |
186 | $cat_filter ? $tmp_line["cat_id"] : $tmp_line["feed_id"], |
187 | $cat_filter); | |
188 | } else { | |
189 | $tmp_line["feed"] = ""; | |
190 | } | |
191 | ||
8592a8e3 AD |
192 | $tmp_line["cat_filter"] = sql_bool_to_bool($tmp_line["cat_filter"]); |
193 | ||
fd994f1a AD |
194 | unset($tmp_line["feed_id"]); |
195 | unset($tmp_line["cat_id"]); | |
196 | ||
197 | array_push($line["rules"], $tmp_line); | |
198 | } | |
199 | ||
d9c85e0f | 200 | $tmp_result = $this->dbh->query("SELECT * FROM ttrss_filters2_actions |
fd994f1a AD |
201 | WHERE filter_id = ".$line["id"]); |
202 | ||
d9c85e0f | 203 | while ($tmp_line = $this->dbh->fetch_assoc($tmp_result)) { |
fd994f1a AD |
204 | unset($tmp_line["id"]); |
205 | unset($tmp_line["filter_id"]); | |
206 | ||
207 | array_push($line["actions"], $tmp_line); | |
208 | } | |
209 | ||
210 | unset($line["id"]); | |
211 | unset($line["owner_uid"]); | |
3f9de6cc AD |
212 | $filter = json_encode($line); |
213 | ||
dd0a17b0 | 214 | $out .= "<outline filter-type=\"2\"><![CDATA[$filter]]></outline>"; |
3f9de6cc AD |
215 | |
216 | } | |
217 | ||
218 | ||
fd994f1a | 219 | $out .= "</outline>"; |
3f9de6cc AD |
220 | } |
221 | ||
222 | $out .= "</body></opml>"; | |
223 | ||
224 | // Format output. | |
225 | $doc = new DOMDocument(); | |
226 | $doc->formatOutput = true; | |
227 | $doc->preserveWhiteSpace = false; | |
228 | $doc->loadXML($out); | |
229 | ||
230 | $xpath = new DOMXpath($doc); | |
231 | $outlines = $xpath->query("//outline[@title]"); | |
232 | ||
233 | // cleanup empty categories | |
234 | foreach ($outlines as $node) { | |
235 | if ($node->getElementsByTagName('outline')->length == 0) | |
236 | $node->parentNode->removeChild($node); | |
237 | } | |
238 | ||
239 | $res = $doc->saveXML(); | |
240 | ||
dd0a17b0 | 241 | /* // saveXML uses a two-space indent. Change to tabs. |
3f9de6cc AD |
242 | $res = preg_replace_callback('/^(?: )+/mu', |
243 | create_function( | |
244 | '$matches', | |
245 | 'return str_repeat("\t", intval(strlen($matches[0])/2));'), | |
dd0a17b0 | 246 | $res); */ |
3f9de6cc AD |
247 | |
248 | print $res; | |
249 | } | |
250 | ||
251 | // Import | |
252 | ||
253 | private function opml_import_feed($doc, $node, $cat_id, $owner_uid) { | |
254 | $attrs = $node->attributes; | |
255 | ||
d9c85e0f AD |
256 | $feed_title = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250)); |
257 | if (!$feed_title) $feed_title = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('title')->nodeValue, 0, 250)); | |
3f9de6cc | 258 | |
d9c85e0f AD |
259 | $feed_url = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('xmlUrl')->nodeValue, 0, 250)); |
260 | if (!$feed_url) $feed_url = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('xmlURL')->nodeValue, 0, 250)); | |
3f9de6cc | 261 | |
d9c85e0f | 262 | $site_url = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('htmlUrl')->nodeValue, 0, 250)); |
3f9de6cc AD |
263 | |
264 | if ($feed_url && $feed_title) { | |
d9c85e0f | 265 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
3f9de6cc AD |
266 | feed_url = '$feed_url' AND owner_uid = '$owner_uid'"); |
267 | ||
d9c85e0f | 268 | if ($this->dbh->num_rows($result) == 0) { |
3f9de6cc AD |
269 | #$this->opml_notice("[FEED] [$feed_title/$feed_url] dst_CAT=$cat_id"); |
270 | $this->opml_notice(T_sprintf("Adding feed: %s", $feed_title)); | |
271 | ||
dd0a17b0 AD |
272 | if (!$cat_id) $cat_id = 'NULL'; |
273 | ||
3f9de6cc AD |
274 | $query = "INSERT INTO ttrss_feeds |
275 | (title, feed_url, owner_uid, cat_id, site_url, order_id) VALUES | |
276 | ('$feed_title', '$feed_url', '$owner_uid', | |
dd0a17b0 | 277 | $cat_id, '$site_url', 0)"; |
d9c85e0f | 278 | $this->dbh->query($query); |
3f9de6cc AD |
279 | |
280 | } else { | |
281 | $this->opml_notice(T_sprintf("Duplicate feed: %s", $feed_title)); | |
282 | } | |
283 | } | |
284 | } | |
285 | ||
286 | private function opml_import_label($doc, $node, $owner_uid) { | |
287 | $attrs = $node->attributes; | |
d9c85e0f | 288 | $label_name = $this->dbh->escape_string($attrs->getNamedItem('label-name')->nodeValue); |
3f9de6cc AD |
289 | |
290 | if ($label_name) { | |
d9c85e0f AD |
291 | $fg_color = $this->dbh->escape_string($attrs->getNamedItem('label-fg-color')->nodeValue); |
292 | $bg_color = $this->dbh->escape_string($attrs->getNamedItem('label-bg-color')->nodeValue); | |
3f9de6cc | 293 | |
a42c55f0 | 294 | if (!label_find_id($label_name, $_SESSION['uid'])) { |
3f9de6cc | 295 | $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name))); |
a42c55f0 | 296 | label_create($label_name, $fg_color, $bg_color, $owner_uid); |
3f9de6cc AD |
297 | } else { |
298 | $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name))); | |
299 | } | |
300 | } | |
301 | } | |
302 | ||
303 | private function opml_import_preference($doc, $node, $owner_uid) { | |
304 | $attrs = $node->attributes; | |
d9c85e0f | 305 | $pref_name = $this->dbh->escape_string($attrs->getNamedItem('pref-name')->nodeValue); |
3f9de6cc AD |
306 | |
307 | if ($pref_name) { | |
d9c85e0f | 308 | $pref_value = $this->dbh->escape_string($attrs->getNamedItem('value')->nodeValue); |
3f9de6cc AD |
309 | |
310 | $this->opml_notice(T_sprintf("Setting preference key %s to %s", | |
311 | $pref_name, $pref_value)); | |
312 | ||
a42c55f0 | 313 | set_pref($pref_name, $pref_value); |
3f9de6cc AD |
314 | } |
315 | } | |
316 | ||
3b003f63 | 317 | private function opml_import_filter($doc, $node, $owner_uid) { |
3f9de6cc AD |
318 | $attrs = $node->attributes; |
319 | ||
d9c85e0f | 320 | $filter_type = $this->dbh->escape_string($attrs->getNamedItem('filter-type')->nodeValue); |
3f9de6cc | 321 | |
3b003f63 AD |
322 | if ($filter_type == '2') { |
323 | $filter = json_decode($node->nodeValue, true); | |
3f9de6cc AD |
324 | |
325 | if ($filter) { | |
3b003f63 AD |
326 | $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]); |
327 | $enabled = bool_to_sql_bool($filter["enabled"]); | |
3f9de6cc | 328 | |
d9c85e0f | 329 | $this->dbh->query("BEGIN"); |
3f9de6cc | 330 | |
d9c85e0f | 331 | $this->dbh->query("INSERT INTO ttrss_filters2 (match_any_rule,enabled,owner_uid) |
3b003f63 AD |
332 | VALUES ($match_any_rule, $enabled,".$_SESSION["uid"].")"); |
333 | ||
d9c85e0f | 334 | $result = $this->dbh->query("SELECT MAX(id) AS id FROM ttrss_filters2 WHERE |
3b003f63 | 335 | owner_uid = ".$_SESSION["uid"]); |
d9c85e0f | 336 | $filter_id = $this->dbh->fetch_result($result, 0, "id"); |
3b003f63 AD |
337 | |
338 | if ($filter_id) { | |
339 | $this->opml_notice(T_sprintf("Adding filter...")); | |
340 | ||
341 | foreach ($filter["rules"] as $rule) { | |
342 | $feed_id = "NULL"; | |
3f9de6cc | 343 | $cat_id = "NULL"; |
3f9de6cc | 344 | |
3b003f63 | 345 | if (!$rule["cat_filter"]) { |
d9c85e0f AD |
346 | $tmp_result = $this->dbh->query("SELECT id FROM ttrss_feeds |
347 | WHERE title = '".$this->dbh->escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]); | |
348 | if ($this->dbh->num_rows($tmp_result) > 0) { | |
349 | $feed_id = $this->dbh->fetch_result($tmp_result, 0, "id"); | |
3b003f63 AD |
350 | } |
351 | } else { | |
d9c85e0f AD |
352 | $tmp_result = $this->dbh->query("SELECT id FROM ttrss_feed_categories |
353 | WHERE title = '".$this->dbh->escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]); | |
3b003f63 | 354 | |
d9c85e0f AD |
355 | if ($this->dbh->num_rows($tmp_result) > 0) { |
356 | $cat_id = $this->dbh->fetch_result($tmp_result, 0, "id"); | |
3b003f63 AD |
357 | } |
358 | } | |
359 | ||
360 | $cat_filter = bool_to_sql_bool($rule["cat_filter"]); | |
d9c85e0f | 361 | $reg_exp = $this->dbh->escape_string($rule["reg_exp"]); |
3b003f63 AD |
362 | $filter_type = (int)$rule["filter_type"]; |
363 | ||
d9c85e0f | 364 | $this->dbh->query("INSERT INTO ttrss_filters2_rules (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter) |
3b003f63 AD |
365 | VALUES ($feed_id, $cat_id, $filter_id, $filter_type, '$reg_exp', $cat_filter)"); |
366 | } | |
3f9de6cc | 367 | |
3b003f63 | 368 | foreach ($filter["actions"] as $action) { |
3f9de6cc | 369 | |
3b003f63 | 370 | $action_id = (int)$action["action_id"]; |
d9c85e0f | 371 | $action_param = $this->dbh->escape_string($action["action_param"]); |
3f9de6cc | 372 | |
d9c85e0f | 373 | $this->dbh->query("INSERT INTO ttrss_filters2_actions (filter_id,action_id,action_param) |
3b003f63 AD |
374 | VALUES ($filter_id, $action_id, '$action_param')"); |
375 | } | |
3f9de6cc | 376 | } |
3b003f63 | 377 | |
d9c85e0f | 378 | $this->dbh->query("COMMIT"); |
3f9de6cc AD |
379 | } |
380 | } | |
3b003f63 | 381 | } |
3f9de6cc AD |
382 | |
383 | private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { | |
384 | $body = $doc->getElementsByTagName('body'); | |
385 | ||
a42c55f0 | 386 | $default_cat_id = (int) get_feed_category('Imported feeds', false); |
3f9de6cc AD |
387 | |
388 | if ($root_node) { | |
d9c85e0f | 389 | $cat_title = $this->dbh->escape_string(mb_substr($root_node->attributes->getNamedItem('text')->nodeValue, 0, 250)); |
3f9de6cc | 390 | |
cc616ea1 | 391 | if (!$cat_title) |
d9c85e0f | 392 | $cat_title = $this->dbh->escape_string(mb_substr($root_node->attributes->getNamedItem('title')->nodeValue, 0, 250)); |
cc616ea1 | 393 | |
3f9de6cc | 394 | if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { |
a42c55f0 | 395 | $cat_id = get_feed_category($cat_title, $parent_id); |
d9c85e0f | 396 | $this->dbh->query("BEGIN"); |
3f9de6cc | 397 | if ($cat_id === false) { |
a42c55f0 AD |
398 | add_feed_category($cat_title, $parent_id); |
399 | $cat_id = get_feed_category($cat_title, $parent_id); | |
3f9de6cc | 400 | } |
d9c85e0f | 401 | $this->dbh->query("COMMIT"); |
3f9de6cc AD |
402 | } else { |
403 | $cat_id = 0; | |
404 | } | |
405 | ||
406 | $outlines = $root_node->childNodes; | |
407 | ||
408 | } else { | |
409 | $xpath = new DOMXpath($doc); | |
410 | $outlines = $xpath->query("//opml/body/outline"); | |
411 | ||
412 | $cat_id = 0; | |
413 | } | |
414 | ||
415 | #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); | |
416 | $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized"))); | |
417 | ||
418 | foreach ($outlines as $node) { | |
419 | if ($node->hasAttributes() && strtolower($node->tagName) == "outline") { | |
420 | $attrs = $node->attributes; | |
d9c85e0f | 421 | $node_cat_title = $this->dbh->escape_string($attrs->getNamedItem('text')->nodeValue); |
cc616ea1 AD |
422 | |
423 | if (!$node_cat_title) | |
d9c85e0f | 424 | $node_cat_title = $this->dbh->escape_string($attrs->getNamedItem('title')->nodeValue); |
cc616ea1 | 425 | |
d9c85e0f | 426 | $node_feed_url = $this->dbh->escape_string($attrs->getNamedItem('xmlUrl')->nodeValue); |
3f9de6cc AD |
427 | |
428 | if ($node_cat_title && !$node_feed_url) { | |
429 | $this->opml_import_category($doc, $node, $owner_uid, $cat_id); | |
430 | } else { | |
431 | ||
432 | if (!$cat_id) { | |
433 | $dst_cat_id = $default_cat_id; | |
434 | } else { | |
435 | $dst_cat_id = $cat_id; | |
436 | } | |
437 | ||
438 | switch ($cat_title) { | |
439 | case "tt-rss-prefs": | |
440 | $this->opml_import_preference($doc, $node, $owner_uid); | |
441 | break; | |
442 | case "tt-rss-labels": | |
443 | $this->opml_import_label($doc, $node, $owner_uid); | |
444 | break; | |
445 | case "tt-rss-filters": | |
3b003f63 | 446 | $this->opml_import_filter($doc, $node, $owner_uid); |
3f9de6cc AD |
447 | break; |
448 | default: | |
449 | $this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid); | |
450 | } | |
451 | } | |
452 | } | |
453 | } | |
454 | } | |
455 | ||
456 | function opml_import($owner_uid) { | |
457 | if (!$owner_uid) return; | |
458 | ||
459 | $debug = isset($_REQUEST["debug"]); | |
460 | $doc = false; | |
461 | ||
5a49ed95 | 462 | # if ($debug) $doc = DOMDocument::load("/tmp/test.opml"); |
3f9de6cc | 463 | |
3306daec AD |
464 | if ($_FILES['opml_file']['error'] != 0) { |
465 | print_error(T_sprintf("Upload failed with error code %d", | |
466 | $_FILES['opml_file']['error'])); | |
467 | return; | |
468 | } | |
469 | ||
470 | $tmp_file = false; | |
471 | ||
472 | if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { | |
473 | $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml'); | |
474 | ||
475 | $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], | |
476 | $tmp_file); | |
477 | ||
478 | if (!$result) { | |
479 | print_error(__("Unable to move uploaded file.")); | |
480 | return; | |
481 | } | |
482 | } else { | |
483 | print_error(__('Error: please upload OPML file.')); | |
484 | return; | |
485 | } | |
486 | ||
487 | if (is_file($tmp_file)) { | |
98c39afc | 488 | $doc = new DOMDocument(); |
3306daec AD |
489 | $doc->load($tmp_file); |
490 | unlink($tmp_file); | |
3f9de6cc | 491 | } else if (!$doc) { |
3306daec | 492 | print_error(__('Error: unable to find moved OPML file.')); |
3f9de6cc AD |
493 | return; |
494 | } | |
495 | ||
496 | if ($doc) { | |
497 | $this->opml_import_category($doc, false, $owner_uid, false); | |
498 | } else { | |
499 | print_error(__('Error while parsing document.')); | |
500 | } | |
501 | } | |
502 | ||
503 | private function opml_notice($msg) { | |
504 | print "$msg<br/>"; | |
505 | } | |
506 | ||
6322ac79 | 507 | static function opml_publish_url(){ |
50832719 AD |
508 | |
509 | $url_path = get_self_url_prefix(); | |
510 | $url_path .= "/opml.php?op=publish&key=" . | |
a42c55f0 | 511 | get_feed_access_key('OPML:Publish', false, $_SESSION["uid"]); |
50832719 AD |
512 | |
513 | return $url_path; | |
514 | } | |
515 | ||
516 | ||
3f9de6cc AD |
517 | } |
518 | ?> |