]> git.wh0rd.org - tt-rss.git/blame - opml.php
use update.css as generic minimal utility css
[tt-rss.git] / opml.php
CommitLineData
1d3a17c7 1<?php
1559e374 2 require_once "sessions.php";
66581886 3 require_once "sanity_check.php";
4e9f5c24 4 require_once "functions.php";
9a4506c8 5 require_once "config.php";
8158c57a 6 require_once "db.php";
a0111294 7 require_once "db-prefs.php";
9a4506c8 8
8158c57a 9 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
9f311df6 10
8158c57a
AD
11 if (DB_TYPE == "pgsql") {
12 pg_query($link, "set client_encoding = 'utf-8'");
ef063748 13 pg_set_client_encoding("UNICODE");
8158c57a 14 }
9a4506c8 15
4e9f5c24
AD
16 login_sequence($link);
17
18 $owner_uid = $_SESSION["uid"];
19
30f782a2 20 function opml_export($link) {
12ec37f3 21 header("Content-type: application/xml+opml");
1d3a17c7 22 print "<?phpxml version=\"1.0\"?>";
4e9f5c24 23
9a4506c8 24 print "<opml version=\"1.0\">";
a90005e6
AD
25 print "<head>
26 <dateCreated>" . date("r", time()) . "</dateCreated>
27 <title>Tiny Tiny RSS Feed Export</title>
28 </head>";
9a4506c8
AD
29 print "<body>";
30
da49ccf5
AD
31 $cat_mode = false;
32
33 if (get_pref($link, 'ENABLE_FEED_CATS')) {
34 $cat_mode = true;
35 $result = db_query($link, "SELECT
fa7b8749 36 title,feed_url,site_url,
18d37445
AD
37 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
38 FROM ttrss_feeds
bc15240d
AD
39 WHERE
40 owner_uid = '$owner_uid'
18d37445 41 ORDER BY cat_title,title");
da49ccf5
AD
42 } else {
43 $result = db_query($link, "SELECT * FROM ttrss_feeds
2513ae2b 44 WHERE owner_uid = '$owner_uid' ORDER BY title");
da49ccf5
AD
45 }
46
47 $old_cat_title = "";
9a4506c8 48
8158c57a 49 while ($line = db_fetch_assoc($result)) {
6e0584e9
AD
50 $title = htmlspecialchars($line["title"]);
51 $url = htmlspecialchars($line["feed_url"]);
fa7b8749 52 $site_url = htmlspecialchars($line["site_url"]);
9a4506c8 53
da49ccf5
AD
54 if ($cat_mode) {
55 $cat_title = htmlspecialchars($line["cat_title"]);
56
57 if ($old_cat_title != $cat_title) {
58 if ($old_cat_title) {
5b9af2b9 59 print "</outline>\n";
da49ccf5
AD
60 }
61
5b9af2b9
AD
62 if ($cat_title) {
63 print "<outline title=\"$cat_title\">\n";
64 }
da49ccf5
AD
65
66 $old_cat_title = $cat_title;
67 }
68 }
69
fa7b8749
AD
70 if ($site_url) {
71 $html_url_qpart = "htmlUrl=\"$site_url\"";
72 } else {
73 $html_url_qpart = "";
74 }
75
76 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
9a4506c8
AD
77 }
78
da49ccf5 79 if ($cat_mode && $old_cat_title) {
5b9af2b9 80 print "</outline>\n";
da49ccf5
AD
81 }
82
9a4506c8
AD
83 print "</body></opml>";
84 }
85
30f782a2
AD
86 // FIXME there are some brackets issues here
87
88 $op = $_REQUEST["op"];
89
90 if (!$op) $op = "Export";
91
92 if ($op == "Export") {
93 return opml_export($link);
94 }
95
e98a3f65 96 if ($op == "Import") {
8158c57a 97
e98a3f65
AD
98 print "<html>
99 <head>
100 <link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
101 </head>
04f6df27 102 <body>
30f782a2
AD
103 <div style='float : right'><img src=\"images/ttrss_logo.png\"></div>
104 <h1>"._('OPML Import')."</h1>";
9f311df6 105
30f782a2
AD
106 if (function_exists('domxml_open_file')) {
107 print "<p class='insensitive'>Using DOMXML library</p>";
108 require_once "modules/opml_domxml.php";
109 opml_import_domxml($link, $owner_uid);
e98a3f65 110 } else {
30f782a2
AD
111 print "<p class='insensitive'>Using DOMDocument library (PHP5)</p>";
112 require_once "modules/opml_domdoc.php";
113 opml_import_domdoc($link, $owner_uid);
9f311df6
AD
114 }
115
d7c848d9
AD
116 print "<br><form method=\"GET\" action=\"prefs.php\">
117 <input type=\"submit\" value=\"Return to preferences\">
118 </form>";
9f311df6 119
30f782a2 120 print "</body></html>";
9f311df6
AD
121
122 }
123
3d477c2c 124// if ($link) db_close($link);
9f311df6 125
9a4506c8 126?>