]> git.wh0rd.org - tt-rss.git/blame - opml.php
updated mysql schema
[tt-rss.git] / opml.php
CommitLineData
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
f179a35d
AD
39 if (!$title || !$url) return;
40
9f311df6
AD
41 print "Feed <b>$title</b> ($url)... ";
42
43 $result = pg_query("SELECT id FROM ttrss_feeds WHERE
44 title = '$title' OR feed_url = '$url'");
45
46 if (pg_num_rows($result) > 0) {
47
48 print " Already imported.<br>";
49
50 } else {
51
52 $result = pg_query("INSERT INTO ttrss_feeds (title, feed_url) VALUES
53 ('$title', '$url')");
54
55 print "<b>Done.</b><br>";
56
57 }
58
59 }
60 }
61
62 function endElement($parser, $name) {
63
64
65 }
66
67 if ($op == "Import") {
eac7480c 68
9f311df6
AD
69 print "<html>
70 <head>
71 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
72 </head>
73 <body><h1>Importing OPML...</h1>
74 <div>";
75
eac7480c
AD
76 if (WEB_DEMO_MODE) {
77 print "OPML import is disabled in demo-mode.";
78 print "<p><a class=\"button\" href=\"prefs.php\">
79 Return to preferences</a></div></body></html>";
80
81 return;
82 }
83
84 if (is_file($_FILES['opml_file']['tmp_name'])) {
9f311df6
AD
85
86 $xml_parser = xml_parser_create();
87
88 xml_set_element_handler($xml_parser, "startElement", "endElement");
89
90 $fp = fopen($_FILES['opml_file']['tmp_name'], "r");
91
92 if ($fp) {
93
94 while ($data = fread($fp, 4096)) {
95
96 if (!xml_parse($xml_parser, $data, feof($fp))) {
97
98 print sprintf("Unable to parse OPML file, XML error: %s at line %d",
99 xml_error_string(xml_get_error_code($xml_parser)),
100 xml_get_current_line_number($xml_parser));
101
102 print "<p><a class=\"button\" href=\"prefs.php\">
103 Return to preferences</a>";
104
105 return;
106
107 }
108 }
109
110 xml_parser_free($xml_parser);
111 fclose($fp);
112
113 } else {
114 print("Error: Could not open OPML input.");
115 }
116
117 } else {
118 print "Error: please upload OPML file.";
119 }
120
121 print "<p><a class=\"button\" href=\"prefs.php\">
122 Return to preferences</a>";
123
124 print "</div></body></html>";
125
126 }
127
128 pg_close($link);
129
9a4506c8 130?>