]>
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") { |
d212ce0e AD |
39 | if ($name == "OUTLINE") { |
40 | ||
41 | $title = $attrs["TEXT"]; | |
42 | $url = $attrs["XMLURL"]; | |
43 | ||
44 | if (!$title) { | |
45 | $title = $attrs['TITLE']; | |
46 | } | |
47 | } | |
9f311df6 | 48 | |
f179a35d AD |
49 | if (!$title || !$url) return; |
50 | ||
9f311df6 AD |
51 | print "Feed <b>$title</b> ($url)... "; |
52 | ||
20fcff19 | 53 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
b76cdb2f AD |
54 | |
55 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
9f311df6 AD |
56 | title = '$title' OR feed_url = '$url'"); |
57 | ||
b76cdb2f | 58 | if ($result && db_num_rows($result) > 0) { |
9f311df6 AD |
59 | |
60 | print " Already imported.<br>"; | |
61 | ||
62 | } else { | |
b76cdb2f AD |
63 | |
64 | $result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url) VALUES | |
9f311df6 AD |
65 | ('$title', '$url')"); |
66 | ||
67 | print "<b>Done.</b><br>"; | |
68 | ||
69 | } | |
70 | ||
7118b7ac AD |
71 | if ($link) db_close($link); |
72 | ||
9f311df6 AD |
73 | } |
74 | } | |
75 | ||
76 | function endElement($parser, $name) { | |
77 | ||
78 | ||
79 | } | |
80 | ||
81 | if ($op == "Import") { | |
eac7480c | 82 | |
9f311df6 AD |
83 | print "<html> |
84 | <head> | |
85 | <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\"> | |
86 | </head> | |
87 | <body><h1>Importing OPML...</h1> | |
88 | <div>"; | |
89 | ||
eac7480c AD |
90 | if (WEB_DEMO_MODE) { |
91 | print "OPML import is disabled in demo-mode."; | |
92 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
93 | Return to preferences</a></div></body></html>"; | |
94 | ||
95 | return; | |
96 | } | |
97 | ||
98 | if (is_file($_FILES['opml_file']['tmp_name'])) { | |
9f311df6 AD |
99 | |
100 | $xml_parser = xml_parser_create(); | |
101 | ||
102 | xml_set_element_handler($xml_parser, "startElement", "endElement"); | |
103 | ||
104 | $fp = fopen($_FILES['opml_file']['tmp_name'], "r"); | |
105 | ||
106 | if ($fp) { | |
107 | ||
108 | while ($data = fread($fp, 4096)) { | |
109 | ||
110 | if (!xml_parse($xml_parser, $data, feof($fp))) { | |
111 | ||
112 | print sprintf("Unable to parse OPML file, XML error: %s at line %d", | |
113 | xml_error_string(xml_get_error_code($xml_parser)), | |
114 | xml_get_current_line_number($xml_parser)); | |
115 | ||
116 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
117 | Return to preferences</a>"; | |
118 | ||
119 | return; | |
120 | ||
121 | } | |
122 | } | |
123 | ||
124 | xml_parser_free($xml_parser); | |
125 | fclose($fp); | |
126 | ||
127 | } else { | |
128 | print("Error: Could not open OPML input."); | |
129 | } | |
130 | ||
131 | } else { | |
132 | print "Error: please upload OPML file."; | |
133 | } | |
134 | ||
135 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
136 | Return to preferences</a>"; | |
137 | ||
138 | print "</div></body></html>"; | |
139 | ||
140 | } | |
141 | ||
3d477c2c | 142 | // if ($link) db_close($link); |
9f311df6 | 143 | |
9a4506c8 | 144 | ?> |