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