]>
Commit | Line | Data |
---|---|---|
97aba8ec | 1 | <? |
9db0fded AD |
2 | session_start(); |
3 | ||
4f17b5f9 AD |
4 | define('MAX_SCHEMA_VERSION', 4); |
5 | ||
97aba8ec AD |
6 | require_once "config.php"; |
7 | require_once "functions.php"; | |
8 | require_once "db.php"; | |
9 | ||
618f424e AD |
10 | if ($_GET["export"]) { |
11 | header("Content-Type: application/xml"); | |
12 | } | |
97aba8ec AD |
13 | ?> |
14 | ||
618f424e AD |
15 | <? if (!$_GET["export"]) { ?> |
16 | ||
17 | <html> | |
648cbec8 AD |
18 | <head> |
19 | <title>XML Export</title> | |
20 | <link rel="stylesheet" href="opml.css" type="text/css"> | |
21 | </head> | |
618f424e | 22 | <body> |
648cbec8 AD |
23 | <h1><img src="images/ttrss_logo.png"></h1> |
24 | ||
25 | <div class="opmlBody"> | |
26 | <h2>XML Export</h2> | |
27 | <form method="GET"> | |
28 | Limit to: <input type="checkbox" checked name="marked"> starred, | |
29 | <input type="checkbox" name="unread"> unread.<br> | |
30 | <p><input type="submit" class="button" name="export" value="Export"></p> | |
31 | </form> | |
32 | </div> | |
33 | ||
618f424e AD |
34 | </body> |
35 | </html> | |
36 | ||
37 | <? } else { ?> | |
38 | ||
97aba8ec AD |
39 | <xmldb> |
40 | ||
41 | <? | |
42 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
43 | ||
44 | if (!$link) { | |
45 | if (DB_TYPE == "mysql") { | |
46 | print mysql_error(); | |
47 | } | |
48 | // PG seems to display its own errors just fine by default. | |
49 | return; | |
50 | } | |
51 | ||
52 | if (DB_TYPE == "pgsql") { | |
53 | pg_query("set client_encoding = 'utf-8'"); | |
54 | } | |
55 | ||
56 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
57 | ||
58 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
59 | ||
618f424e | 60 | /* if ($schema_version != SCHEMA_VERSION) { |
ebb510ce AD |
61 | print "<error>Source database schema is invalid |
62 | (got version $schema_version; expected ".SCHEMA_VERSION.")</error>"; | |
63 | print "</xmldb>"; | |
97aba8ec | 64 | return; |
618f424e | 65 | } */ |
97aba8ec AD |
66 | |
67 | print "<schema_version>$schema_version</schema_version>"; | |
68 | ||
eadcf397 | 69 | if ($schema_version > 1) { |
618f424e AD |
70 | $owner_uid = $_SESSION["uid"]; |
71 | print "<owner_uid>$owner_uid</owner_uid>"; | |
72 | } | |
97aba8ec | 73 | |
618f424e AD |
74 | print "<exported>" . time() . "</exported>"; |
75 | ?> | |
97aba8ec AD |
76 | |
77 | <? | |
618f424e AD |
78 | if ($_GET["marked"]) { |
79 | $marked_qpart = "AND marked = true"; | |
80 | } | |
97aba8ec | 81 | |
618f424e AD |
82 | if ($_GET["unread"]) { |
83 | $unread_qpart = "AND unread = true"; | |
84 | } | |
97aba8ec | 85 | |
618f424e AD |
86 | if ($schema_version == 1) { |
87 | ||
88 | $result = db_query($link, "SELECT | |
89 | ttrss_entries.title AS title, | |
90 | content, | |
91 | marked, | |
92 | unread, | |
93 | updated, | |
94 | guid, | |
95 | link, | |
fa16f30b AD |
96 | SUBSTRING(date_entered,1,16) AS date_entered, |
97 | SUBSTRING(last_read,1,16) AS last_read, | |
618f424e AD |
98 | comments, |
99 | ttrss_feeds.feed_url AS feed_url, | |
100 | ttrss_feeds.title AS feed_title | |
101 | FROM | |
102 | ttrss_entries,ttrss_feeds | |
103 | WHERE | |
fa16f30b AD |
104 | feed_id = ttrss_feeds.id $marked_qpart $unread_qpart |
105 | ORDER BY ttrss_entries.id"); | |
618f424e | 106 | |
eadcf397 | 107 | } else if ($schema_version >= 2 && $schema_version <= MAX_SCHEMA_VERSION) { |
618f424e AD |
108 | |
109 | $result = db_query($link, "SELECT | |
110 | ttrss_entries.title AS title, | |
111 | content, | |
112 | marked, | |
113 | unread, | |
114 | updated, | |
115 | guid, | |
116 | link, | |
fa16f30b AD |
117 | SUBSTRING(date_entered,1,16) AS date_entered, |
118 | SUBSTRING(last_read,1,16) AS last_read, | |
618f424e AD |
119 | comments, |
120 | ttrss_feeds.feed_url AS feed_url, | |
121 | ttrss_feeds.title AS feed_title | |
122 | FROM | |
123 | ttrss_entries,ttrss_feeds,ttrss_user_entries | |
124 | WHERE | |
125 | ttrss_user_entries.owner_uid = '$owner_uid' AND | |
126 | ref_id = ttrss_entries.id AND | |
fa16f30b AD |
127 | feed_id = ttrss_feeds.id $marked_qpart $unread_qpart |
128 | ORDER BY ttrss_entries.id"); | |
618f424e AD |
129 | |
130 | } else { | |
131 | ||
132 | // BAD SCHEMA, NO COOKIE | |
133 | ||
134 | print "<error>Source database schema is invalid | |
135 | (got version $schema_version)</error>"; | |
136 | } | |
137 | ||
138 | print "<total_articles>" . db_num_rows($result) . "</total_articles>"; | |
139 | ||
140 | ?> | |
141 | ||
142 | <articles> | |
143 | ||
144 | <? | |
97aba8ec AD |
145 | while ($line = db_fetch_assoc($result)) { |
146 | print "<article>"; | |
147 | ||
148 | foreach (array_keys($line) as $key) { | |
618f424e AD |
149 | $line[$key] = str_replace("<![CDATA[", "", $line[$key]); |
150 | $line[$key] = str_replace("]]>", "", $line[$key]); | |
151 | ||
97aba8ec AD |
152 | print "<$key><![CDATA[".$line[$key]."]]></$key>"; |
153 | ||
154 | } | |
155 | ||
156 | print "</article>"; | |
157 | } | |
158 | ||
159 | ?> | |
160 | </articles> | |
161 | ||
162 | </xmldb> | |
618f424e AD |
163 | |
164 | <? } ?> |