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