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