]>
git.wh0rd.org - tt-rss.git/blob - utils/xml-export.php
2 require_once "sessions.php";
4 define('MAX_SCHEMA_VERSION', 5);
6 require_once "config.php";
7 require_once "functions.php";
10 if ($_GET["export"]) {
11 header("Content-Type: application/xml");
14 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
17 if (DB_TYPE
== "mysql") {
20 // PG seems to display its own errors just fine by default.
24 if (DB_TYPE
== "pgsql") {
25 pg_query("set client_encoding = 'utf-8'");
28 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
30 $schema_version = db_fetch_result($result, 0, "schema_version");
32 if ($schema_version > 1) login_sequence($link);
36 <?
if (!$_GET["export"]) { ?
>
40 <title
>XML Export
</title
>
41 <link rel
="stylesheet" href
="opml.css" type
="text/css">
44 <h1
><img src
="images/ttrss_logo.png"></h1
>
46 <div
class="opmlBody">
49 Limit to
: <input type
="checkbox" checked name
="marked"> starred
,
50 <input type
="checkbox" name
="unread"> unread
.<br
>
51 <p
><input type
="submit" class="button" name
="export" value
="Export"></p
>
64 /* if ($schema_version != SCHEMA_VERSION) {
65 print "<error>Source database schema is invalid
66 (got version $schema_version; expected ".SCHEMA_VERSION.")</error>";
71 print "<schema_version>$schema_version</schema_version>";
73 if ($schema_version > 1) {
74 $owner_uid = $_SESSION["uid"];
75 print "<owner_uid>$owner_uid</owner_uid>";
78 print "<exported>" . time() . "</exported>";
82 if ($_GET["marked"]) {
83 $marked_qpart = "AND marked = true";
86 if ($_GET["unread"]) {
87 $unread_qpart = "AND unread = true";
90 if ($schema_version == 1) {
92 $result = db_query($link, "SELECT
93 ttrss_entries.title AS title,
100 SUBSTRING(date_entered,1,16) AS date_entered,
101 SUBSTRING(last_read,1,16) AS last_read,
103 ttrss_feeds.feed_url AS feed_url,
104 ttrss_feeds.title AS feed_title
106 ttrss_entries,ttrss_feeds
108 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
109 ORDER BY ttrss_entries.id");
111 } else if ($schema_version >= 2 && $schema_version <= MAX_SCHEMA_VERSION
) {
113 $result = db_query($link, "SELECT
114 ttrss_entries.title AS title,
121 SUBSTRING(date_entered,1,16) AS date_entered,
122 SUBSTRING(last_read,1,16) AS last_read,
124 ttrss_feeds.feed_url AS feed_url,
125 ttrss_feeds.title AS feed_title
127 ttrss_entries,ttrss_feeds,ttrss_user_entries
129 ttrss_user_entries.owner_uid = '$owner_uid' AND
130 ref_id = ttrss_entries.id AND
131 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
132 ORDER BY ttrss_entries.id");
136 // BAD SCHEMA, NO COOKIE
138 print "<error>Source database schema is invalid
139 (got version $schema_version)</error>";
142 print "<total_articles>" . db_num_rows($result) . "</total_articles>";
149 while ($line = db_fetch_assoc($result)) {
152 foreach (array_keys($line) as $key) {
153 $line[$key] = str_replace("<![CDATA[", "", $line[$key]);
154 $line[$key] = str_replace("]]>", "", $line[$key]);
156 print "<$key><![CDATA[".$line[$key]."]]></$key>";