]>
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 AD |
6 | header("Content-type: application/xml"); |
7 | } | |
8 | ||
9 | require_once "config.php"; | |
10 | require_once "functions.php"; | |
11 | ||
12 | $link = pg_connect(DB_CONN); | |
9f311df6 | 13 | |
9a4506c8 AD |
14 | pg_query($link, "set client_encoding = 'utf-8'"); |
15 | ||
9f311df6 | 16 | if ($op == "Export") { |
9a4506c8 AD |
17 | print "<?xml version=\"1.0\"?>"; |
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") { | |
66 | print "<html> | |
67 | <head> | |
68 | <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\"> | |
69 | </head> | |
70 | <body><h1>Importing OPML...</h1> | |
71 | <div>"; | |
72 | ||
73 | if (is_file($_FILES['opml_file']['tmp_name'])) { | |
74 | ||
75 | $xml_parser = xml_parser_create(); | |
76 | ||
77 | xml_set_element_handler($xml_parser, "startElement", "endElement"); | |
78 | ||
79 | $fp = fopen($_FILES['opml_file']['tmp_name'], "r"); | |
80 | ||
81 | if ($fp) { | |
82 | ||
83 | while ($data = fread($fp, 4096)) { | |
84 | ||
85 | if (!xml_parse($xml_parser, $data, feof($fp))) { | |
86 | ||
87 | print sprintf("Unable to parse OPML file, XML error: %s at line %d", | |
88 | xml_error_string(xml_get_error_code($xml_parser)), | |
89 | xml_get_current_line_number($xml_parser)); | |
90 | ||
91 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
92 | Return to preferences</a>"; | |
93 | ||
94 | return; | |
95 | ||
96 | } | |
97 | } | |
98 | ||
99 | xml_parser_free($xml_parser); | |
100 | fclose($fp); | |
101 | ||
102 | } else { | |
103 | print("Error: Could not open OPML input."); | |
104 | } | |
105 | ||
106 | } else { | |
107 | print "Error: please upload OPML file."; | |
108 | } | |
109 | ||
110 | print "<p><a class=\"button\" href=\"prefs.php\"> | |
111 | Return to preferences</a>"; | |
112 | ||
113 | print "</div></body></html>"; | |
114 | ||
115 | } | |
116 | ||
117 | pg_close($link); | |
118 | ||
9a4506c8 | 119 | ?> |