]> git.wh0rd.org - tt-rss.git/blame - opml.php
reduce the number of always included libraries
[tt-rss.git] / opml.php
CommitLineData
1d3a17c7 1<?php
fb074239 2 require_once "functions.php";
1559e374 3 require_once "sessions.php";
66581886 4 require_once "sanity_check.php";
9a4506c8 5 require_once "config.php";
8158c57a 6 require_once "db.php";
a0111294 7 require_once "db-prefs.php";
9a4506c8 8
0a13e84e 9 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
9f311df6 10
f29ba148 11 init_connection($link);
4e9f5c24 12
08ae2a5b 13 function opml_export($link, $name, $owner_uid, $hide_private_feeds=false, $include_settings=true) {
e9558345
AD
14 if (!$_REQUEST["debug"]) {
15 header("Content-type: application/xml+opml");
16 } else {
17 header("Content-type: text/xml");
18 }
08ae2a5b
CM
19 header("Content-Disposition: attachment; filename=" . $name );
20
981e8107 21 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
4e9f5c24 22
9a4506c8 23 print "<opml version=\"1.0\">";
a90005e6
AD
24 print "<head>
25 <dateCreated>" . date("r", time()) . "</dateCreated>
26 <title>Tiny Tiny RSS Feed Export</title>
0a13e84e 27 </head>";
9a4506c8
AD
28 print "<body>";
29
da49ccf5 30 $cat_mode = false;
0a13e84e 31
86e26f1a
MK
32 $select = "SELECT * ";
33 $where = "WHERE owner_uid = '$owner_uid'";
34 $orderby = "ORDER BY title";
35 if ($hide_private_feeds){
0a13e84e 36 $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND
c107797c 37 auth_login = '' AND auth_pass = ''";
86e26f1a 38 }
da49ccf5 39
fee909d5
MK
40
41
42 if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
da49ccf5 43 $cat_mode = true;
0a13e84e 44 $select = "SELECT
86e26f1a
MK
45 title, feed_url, site_url,
46 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
47 $orderby = "ORDER BY cat_title, title";
48
da49ccf5 49 }
fee909d5
MK
50 else{
51 $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
52 print "<!-- feeding cats is not enabled -->";
53 print "<!-- $cat_feed -->";
54
55 }
56
da49ccf5 57
86e26f1a
MK
58 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
59
da49ccf5 60 $old_cat_title = "";
9a4506c8 61
8158c57a 62 while ($line = db_fetch_assoc($result)) {
6e0584e9
AD
63 $title = htmlspecialchars($line["title"]);
64 $url = htmlspecialchars($line["feed_url"]);
fa7b8749 65 $site_url = htmlspecialchars($line["site_url"]);
9a4506c8 66
da49ccf5
AD
67 if ($cat_mode) {
68 $cat_title = htmlspecialchars($line["cat_title"]);
69
70 if ($old_cat_title != $cat_title) {
71 if ($old_cat_title) {
0a13e84e 72 print "</outline>\n";
da49ccf5
AD
73 }
74
5b9af2b9 75 if ($cat_title) {
fee909d5 76 print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
5b9af2b9 77 }
da49ccf5
AD
78
79 $old_cat_title = $cat_title;
80 }
81 }
82
fa7b8749
AD
83 if ($site_url) {
84 $html_url_qpart = "htmlUrl=\"$site_url\"";
85 } else {
86 $html_url_qpart = "";
87 }
88
89 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
9a4506c8
AD
90 }
91
da49ccf5 92 if ($cat_mode && $old_cat_title) {
0a13e84e 93 print "</outline>\n";
da49ccf5
AD
94 }
95
e9558345
AD
96 # export tt-rss settings
97
442f326b
AD
98 if ($include_settings) {
99 print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">";
e9558345 100
442f326b
AD
101 $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
102 profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
e9558345 103
442f326b 104 while ($line = db_fetch_assoc($result)) {
e9558345 105
442f326b
AD
106 $name = $line["pref_name"];
107 $value = htmlspecialchars($line["value"]);
0a13e84e 108
442f326b 109 print "<outline pref-name=\"$name\" value=\"$value\">";
e9558345 110
442f326b 111 print "</outline>";
e9558345 112
0a13e84e 113 }
e9558345 114
442f326b
AD
115 print "</outline>";
116 }
e9558345 117
9a4506c8
AD
118 print "</body></opml>";
119 }
120
30f782a2
AD
121 // FIXME there are some brackets issues here
122
123 $op = $_REQUEST["op"];
08ae2a5b
CM
124 if (!$op) $op = "Export";
125
126 $output_name = $_REQUEST["filename"];
127 if (!$output_name) $output_name = "TinyTinyRSS.opml";
0a13e84e 128
08ae2a5b 129 $show_settings = $_REQUEST["settings"];
0a13e84e 130
30f782a2 131 if ($op == "Export") {
0a13e84e 132
a4234239
MK
133 login_sequence($link);
134 $owner_uid = $_SESSION["uid"];
08ae2a5b 135 return opml_export($link, $output_name, $owner_uid, false, ($show_settings == 1));
30f782a2 136 }
0a13e84e 137
442f326b 138 if ($op == "publish"){
86e26f1a
MK
139 $key = db_escape_string($_REQUEST["key"]);
140
2e7f046f
AD
141 $result = db_query($link, "SELECT owner_uid
142 FROM ttrss_access_keys WHERE
143 access_key = '$key' AND feed_id = 'OPML:Publish'");
86e26f1a
MK
144
145 if (db_num_rows($result) == 1) {
2e7f046f 146 $owner_uid = db_fetch_result($result, 0, "owner_uid");
08ae2a5b 147 return opml_export($link, "", $owner_uid, true, false);
86e26f1a
MK
148 } else {
149 print "<error>User not found</error>";
150 }
151 }
30f782a2 152
e98a3f65 153 if ($op == "Import") {
8158c57a 154
a4234239
MK
155 login_sequence($link);
156 $owner_uid = $_SESSION["uid"];
157
e9558345
AD
158 header('Content-Type: text/html; charset=utf-8');
159
e98a3f65
AD
160 print "<html>
161 <head>
ef59e6e8 162 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
1025ad87 163 <title>".__("OPML Utility")."</title>
e9558345 164 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
e98a3f65 165 </head>
04f6df27 166 <body>
0ae2bb2a 167 <div class=\"floatingLogo\"><img src=\"images/logo_wide.png\"></div>
d1db26aa 168 <h1>".__('OPML Utility')."</h1>";
9f311df6 169
c03cf250
AD
170 db_query($link, "BEGIN");
171
172 /* create Imported feeds category just in case */
173
174 $result = db_query($link, "SELECT id FROM
175 ttrss_feed_categories WHERE title = 'Imported feeds' AND
176 owner_uid = '$owner_uid' LIMIT 1");
177
178 if (db_num_rows($result) == 0) {
179 db_query($link, "INSERT INTO ttrss_feed_categories
0a13e84e 180 (title,owner_uid)
c03cf250
AD
181 VALUES ('Imported feeds', '$owner_uid')");
182 }
183
184 db_query($link, "COMMIT");
185
0a13e84e
AD
186 print "<p>".__("Importing OPML...")."</p>";
187 require_once "modules/opml_domdoc.php";
188 opml_import_domdoc($link, $owner_uid);
9f311df6 189
d7c848d9 190 print "<br><form method=\"GET\" action=\"prefs.php\">
1025ad87 191 <input type=\"submit\" value=\"".__("Return to preferences")."\">
d7c848d9 192 </form>";
9f311df6 193
30f782a2 194 print "</body></html>";
9f311df6
AD
195
196 }
197
3d477c2c 198// if ($link) db_close($link);
9f311df6 199
9a4506c8 200?>