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