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