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