]>
git.wh0rd.org - tt-rss.git/blob - xml-export.php
4 require_once "config.php";
5 require_once "functions.php";
9 header("Content-Type: application/xml");
13 <?
if (!$_GET["export"]) { ?
>
17 <title
>XML Export
</title
>
18 <link rel
="stylesheet" href
="opml.css" type
="text/css">
21 <h1
><img src
="images/ttrss_logo.png"></h1
>
23 <div
class="opmlBody">
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
>
40 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
43 if (DB_TYPE
== "mysql") {
46 // PG seems to display its own errors just fine by default.
50 if (DB_TYPE
== "pgsql") {
51 pg_query("set client_encoding = 'utf-8'");
54 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
56 $schema_version = db_fetch_result($result, 0, "schema_version");
58 /* if ($schema_version != SCHEMA_VERSION) {
59 print "<error>Source database schema is invalid
60 (got version $schema_version; expected ".SCHEMA_VERSION.")</error>";
65 print "<schema_version>$schema_version</schema_version>";
67 if ($schema_version > 1) {
68 $owner_uid = $_SESSION["uid"];
69 print "<owner_uid>$owner_uid</owner_uid>";
72 print "<exported>" . time() . "</exported>";
76 if ($_GET["marked"]) {
77 $marked_qpart = "AND marked = true";
80 if ($_GET["unread"]) {
81 $unread_qpart = "AND unread = true";
84 if ($schema_version == 1) {
86 $result = db_query($link, "SELECT
87 ttrss_entries.title AS title,
94 SUBSTRING(date_entered,1,16) AS date_entered,
95 SUBSTRING(last_read,1,16) AS last_read,
97 ttrss_feeds.feed_url AS feed_url,
98 ttrss_feeds.title AS feed_title
100 ttrss_entries,ttrss_feeds
102 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
103 ORDER BY ttrss_entries.id");
105 } else if ($schema_version == 2) {
107 $result = db_query($link, "SELECT
108 ttrss_entries.title AS title,
115 SUBSTRING(date_entered,1,16) AS date_entered,
116 SUBSTRING(last_read,1,16) AS last_read,
118 ttrss_feeds.feed_url AS feed_url,
119 ttrss_feeds.title AS feed_title
121 ttrss_entries,ttrss_feeds,ttrss_user_entries
123 ttrss_user_entries.owner_uid = '$owner_uid' AND
124 ref_id = ttrss_entries.id AND
125 feed_id = ttrss_feeds.id $marked_qpart $unread_qpart
126 ORDER BY ttrss_entries.id");
130 // BAD SCHEMA, NO COOKIE
132 print "<error>Source database schema is invalid
133 (got version $schema_version)</error>";
136 print "<total_articles>" . db_num_rows($result) . "</total_articles>";
143 while ($line = db_fetch_assoc($result)) {
146 foreach (array_keys($line) as $key) {
147 $line[$key] = str_replace("<![CDATA[", "", $line[$key]);
148 $line[$key] = str_replace("]]>", "", $line[$key]);
150 print "<$key><![CDATA[".$line[$key]."]]></$key>";