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