]>
Commit | Line | Data |
---|---|---|
9a4506c8 AD |
1 | <? |
2 | // FIXME there are some brackets issues here | |
3 | ||
9f311df6 AD |
4 | $op = $_REQUEST["op"]; |
5 | if ($op == "Export") { | |
9a4506c8 | 6 | header("Content-type: application/xml"); |
eac7480c | 7 | print "<?xml version=\"1.0\"?>"; |
9a4506c8 AD |
8 | } |
9 | ||
10 | require_once "config.php"; | |
8158c57a | 11 | require_once "db.php"; |
9a4506c8 | 12 | |
8158c57a | 13 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
9f311df6 | 14 | |
8158c57a AD |
15 | if (DB_TYPE == "pgsql") { |
16 | pg_query($link, "set client_encoding = 'utf-8'"); | |
17 | } | |
9a4506c8 | 18 | |
9f311df6 | 19 | if ($op == "Export") { |
9a4506c8 AD |
20 | print "<opml version=\"1.0\">"; |
21 | print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>"; | |
22 | print "<body>"; | |
23 | ||
8158c57a | 24 | $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title"); |
9a4506c8 | 25 | |
8158c57a | 26 | while ($line = db_fetch_assoc($result)) { |
9a4506c8 AD |
27 | $title = $line["title"]; |
28 | $url = $line["feed_url"]; | |
29 | ||
30 | print "<outline text=\"$title\" xmlUrl=\"$url\"/>"; | |
31 | } | |
32 | ||
33 | print "</body></opml>"; | |
34 | } | |
35 | ||
9f311df6 | 36 | function startElement($parser, $name, $attrs) { |
8158c57a | 37 | |
9f311df6 | 38 | if ($name == "OUTLINE") { |
8158c57a AD |
39 | $title = db_escape_string($attrs['TEXT']); |
40 | $url = db_escape_string($attrs['XMLURL']); | |
9f311df6 | 41 | |
f179a35d AD |
42 | if (!$title || !$url) return; |
43 | ||
9f311df6 AD |
44 | print "Feed <b>$title</b> ($url)... "; |
45 | ||
8158c57a | 46 | $result = db_query_2("SELECT id FROM ttrss_feeds WHERE |
9f311df6 AD |
47 | title = '$title' OR feed_url = '$url'"); |
48 | ||
8158c57a | 49 | if (db_num_rows($result) > 0) { |
9f311df6 AD |
50 | |
51 | print " Already imported.<br>"; | |
52 | ||
53 | } else { | |
54 | ||
8158c57a | 55 | $result = db_query_2("INSERT INTO ttrss_feeds (title, feed_url) VALUES |
9f311df6 AD |
56 | ('$title', '$url')"); |
57 | ||
58 | print "<b>Done.</b><br>"; | |
59 | ||
60 | } | |
61 | ||
62 | } | |
63 | } | |
64 | ||
65 | function endElement($parser, $name) { | |
66 | ||
67 | ||
68 | } | |
69 | ||
70 | if ($op == "Import") { | |
eac7480c | 71 | |
9f311df6 AD |
72 | print "<html> |
73 | <head> | |
74 | <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\"> | |
75 | </head> | |
76 | <body><h1>Importing OPML...</h1> | |
77 | <div>"; | |
78 | ||
eac7480c AD |
79 | if (WEB_DEMO_MODE) { |
80 | print "OPML import is disabled in demo-mode."; | |
81 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
82 | Return to preferences</a></div></body></html>"; | |
83 | ||
84 | return; | |
85 | } | |
86 | ||
87 | if (is_file($_FILES['opml_file']['tmp_name'])) { | |
9f311df6 AD |
88 | |
89 | $xml_parser = xml_parser_create(); | |
90 | ||
91 | xml_set_element_handler($xml_parser, "startElement", "endElement"); | |
92 | ||
93 | $fp = fopen($_FILES['opml_file']['tmp_name'], "r"); | |
94 | ||
95 | if ($fp) { | |
96 | ||
97 | while ($data = fread($fp, 4096)) { | |
98 | ||
99 | if (!xml_parse($xml_parser, $data, feof($fp))) { | |
100 | ||
101 | print sprintf("Unable to parse OPML file, XML error: %s at line %d", | |
102 | xml_error_string(xml_get_error_code($xml_parser)), | |
103 | xml_get_current_line_number($xml_parser)); | |
104 | ||
105 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
106 | Return to preferences</a>"; | |
107 | ||
108 | return; | |
109 | ||
110 | } | |
111 | } | |
112 | ||
113 | xml_parser_free($xml_parser); | |
114 | fclose($fp); | |
115 | ||
116 | } else { | |
117 | print("Error: Could not open OPML input."); | |
118 | } | |
119 | ||
120 | } else { | |
121 | print "Error: please upload OPML file."; | |
122 | } | |
123 | ||
124 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
125 | Return to preferences</a>"; | |
126 | ||
127 | print "</div></body></html>"; | |
128 | ||
129 | } | |
130 | ||
8158c57a | 131 | db_close($link); |
9f311df6 | 132 | |
9a4506c8 | 133 | ?> |