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