]>
git.wh0rd.org - tt-rss.git/blob - xml-export.php
4 define('MAX_SCHEMA_VERSION', 4);
6 require_once "config.php";
7 require_once "functions.php";
10 if ($_GET["export"]) {
11 header("Content-Type: application/xml");
15 <?
if (!$_GET["export"]) { ?
>
19 <title
>XML Export
</title
>
20 <link rel
="stylesheet" href
="opml.css" type
="text/css">
23 <h1
><img src
="images/ttrss_logo.png"></h1
>
25 <div
class="opmlBody">
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
>
42 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
45 if (DB_TYPE
== "mysql") {
48 // PG seems to display its own errors just fine by default.
52 if (DB_TYPE
== "pgsql") {
53 pg_query("set client_encoding = 'utf-8'");
56 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
58 $schema_version = db_fetch_result($result, 0, "schema_version");
60 /* if ($schema_version != SCHEMA_VERSION) {
61 print "<error>Source database schema is invalid
62 (got version $schema_version; expected ".SCHEMA_VERSION.")</error>";
67 print "<schema_version>$schema_version</schema_version>";
69 if ($schema_version > 1) {
70 $owner_uid = $_SESSION["uid"];
71 print "<owner_uid>$owner_uid</owner_uid>";
74 print "<exported>" . time() . "</exported>";
78 if ($_GET["marked"]) {
79 $marked_qpart = "AND marked = true";
82 if ($_GET["unread"]) {
83 $unread_qpart = "AND unread = true";
86 if ($schema_version == 1) {
88 $result = db_query($link, "SELECT
89 ttrss_entries.title AS title,
96 SUBSTRING(date_entered,1,16) AS date_entered,
97 SUBSTRING(last_read,1,16) AS last_read,
99 ttrss_feeds.feed_url AS feed_url,
100 ttrss_feeds.title AS feed_title
102 ttrss_entries,ttrss_feeds
104 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
105 ORDER BY ttrss_entries.id");
107 } else if ($schema_version >= 2 && $schema_version <= MAX_SCHEMA_VERSION
) {
109 $result = db_query($link, "SELECT
110 ttrss_entries.title AS title,
117 SUBSTRING(date_entered,1,16) AS date_entered,
118 SUBSTRING(last_read,1,16) AS last_read,
120 ttrss_feeds.feed_url AS feed_url,
121 ttrss_feeds.title AS feed_title
123 ttrss_entries,ttrss_feeds,ttrss_user_entries
125 ttrss_user_entries.owner_uid = '$owner_uid' AND
126 ref_id = ttrss_entries.id AND
127 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
128 ORDER BY ttrss_entries.id");
132 // BAD SCHEMA, NO COOKIE
134 print "<error>Source database schema is invalid
135 (got version $schema_version)</error>";
138 print "<total_articles>" . db_num_rows($result) . "</total_articles>";
145 while ($line = db_fetch_assoc($result)) {
148 foreach (array_keys($line) as $key) {
149 $line[$key] = str_replace("<![CDATA[", "", $line[$key]);
150 $line[$key] = str_replace("]]>", "", $line[$key]);
152 print "<$key><![CDATA[".$line[$key]."]]></$key>";