]>
git.wh0rd.org - tt-rss.git/blob - xml-export.php
2 require_once "config.php";
3 require_once "functions.php";
7 header("Content-Type: application/xml");
11 <?
if (!$_GET["export"]) { ?
>
15 <title
>XML Export
</title
>
16 <link rel
="stylesheet" href
="opml.css" type
="text/css">
19 <h1
><img src
="images/ttrss_logo.png"></h1
>
21 <div
class="opmlBody">
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
>
38 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
41 if (DB_TYPE
== "mysql") {
44 // PG seems to display its own errors just fine by default.
48 if (DB_TYPE
== "pgsql") {
49 pg_query("set client_encoding = 'utf-8'");
52 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
54 $schema_version = db_fetch_result($result, 0, "schema_version");
56 /* if ($schema_version != SCHEMA_VERSION) {
57 print "<error>Source database schema is invalid
58 (got version $schema_version; expected ".SCHEMA_VERSION.")</error>";
63 print "<schema_version>$schema_version</schema_version>";
65 if ($schema_version > 1) {
66 $owner_uid = $_SESSION["uid"];
67 print "<owner_uid>$owner_uid</owner_uid>";
70 print "<exported>" . time() . "</exported>";
74 if ($_GET["marked"]) {
75 $marked_qpart = "AND marked = true";
78 if ($_GET["unread"]) {
79 $unread_qpart = "AND unread = true";
82 if ($schema_version == 1) {
84 $result = db_query($link, "SELECT
85 ttrss_entries.title AS title,
92 SUBSTRING(date_entered,1,16) AS date_entered,
93 SUBSTRING(last_read,1,16) AS last_read,
95 ttrss_feeds.feed_url AS feed_url,
96 ttrss_feeds.title AS feed_title
98 ttrss_entries,ttrss_feeds
100 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
101 ORDER BY ttrss_entries.id");
103 } else if ($schema_version == 2) {
105 $result = db_query($link, "SELECT
106 ttrss_entries.title AS title,
113 SUBSTRING(date_entered,1,16) AS date_entered,
114 SUBSTRING(last_read,1,16) AS last_read,
116 ttrss_feeds.feed_url AS feed_url,
117 ttrss_feeds.title AS feed_title
119 ttrss_entries,ttrss_feeds,ttrss_user_entries
121 ttrss_user_entries.owner_uid = '$owner_uid' AND
122 ref_id = ttrss_entries.id AND
123 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
124 ORDER BY ttrss_entries.id");
128 // BAD SCHEMA, NO COOKIE
130 print "<error>Source database schema is invalid
131 (got version $schema_version)</error>";
134 print "<total_articles>" . db_num_rows($result) . "</total_articles>";
141 while ($line = db_fetch_assoc($result)) {
144 foreach (array_keys($line) as $key) {
145 $line[$key] = str_replace("<![CDATA[", "", $line[$key]);
146 $line[$key] = str_replace("]]>", "", $line[$key]);
148 print "<$key><![CDATA[".$line[$key]."]]></$key>";