]>
git.wh0rd.org - tt-rss.git/blob - opml.php
2 set_include_path(get_include_path() . PATH_SEPARATOR
. "include");
4 require_once "functions.php";
5 require_once "sessions.php";
6 require_once "sanity_check.php";
7 require_once "config.php";
9 require_once "db-prefs.php";
11 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
13 if (!init_connection($link)) return;
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");
19 header("Content-type: text/xml");
21 header("Content-Disposition: attachment; filename=" . $name );
23 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
25 print "<opml version=\"1.0\">";
27 <dateCreated>" . date("r", time()) . "</dateCreated>
28 <title>Tiny Tiny RSS Feed Export</title>
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 = ''";
44 if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
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";
53 $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
54 print "<!-- feeding cats is not enabled -->";
55 print "<!-- $cat_feed -->";
60 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
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"]);
70 $cat_title = htmlspecialchars($line["cat_title"]);
72 if ($old_cat_title != $cat_title) {
78 print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
81 $old_cat_title = $cat_title;
86 $html_url_qpart = "htmlUrl=\"$site_url\"";
91 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
94 if ($cat_mode && $old_cat_title) {
98 # export tt-rss settings
100 if ($include_settings) {
101 print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION
."\">";
103 $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
104 profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
106 while ($line = db_fetch_assoc($result)) {
108 $name = $line["pref_name"];
109 $value = htmlspecialchars($line["value"]);
111 print "<outline pref-name=\"$name\" value=\"$value\">";
120 print "</body></opml>";
123 // FIXME there are some brackets issues here
125 $op = $_REQUEST["op"];
126 if (!$op) $op = "Export";
128 $output_name = $_REQUEST["filename"];
129 if (!$output_name) $output_name = "TinyTinyRSS.opml";
131 $show_settings = $_REQUEST["settings"];
133 if ($op == "Export") {
135 login_sequence($link);
136 $owner_uid = $_SESSION["uid"];
137 return opml_export($link, $output_name, $owner_uid, false, ($show_settings == 1));
140 if ($op == "publish"){
141 $key = db_escape_string($_REQUEST["key"]);
143 $result = db_query($link, "SELECT owner_uid
144 FROM ttrss_access_keys WHERE
145 access_key = '$key' AND feed_id = 'OPML:Publish'");
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);
151 print "<error>User not found</error>";
155 if ($op == "Import") {
157 login_sequence($link);
158 $owner_uid = $_SESSION["uid"];
160 header('Content-Type: text/html; charset=utf-8');
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\"/>
169 <div class=\"floatingLogo\"><img src=\"images/logo_wide.png\"></div>
170 <h1>".__('OPML Utility')."</h1>";
172 db_query($link, "BEGIN");
174 /* create Imported feeds category just in case */
176 $result = db_query($link, "SELECT id FROM
177 ttrss_feed_categories WHERE title = 'Imported feeds' AND
178 owner_uid = '$owner_uid' LIMIT 1");
180 if (db_num_rows($result) == 0) {
181 db_query($link, "INSERT INTO ttrss_feed_categories
183 VALUES ('Imported feeds', '$owner_uid')");
186 db_query($link, "COMMIT");
188 print "<p>".__("Importing OPML...")."</p>";
189 require_once "modules/opml_domdoc.php";
190 opml_import_domdoc($link, $owner_uid);
192 print "<br><form method=\"GET\" action=\"prefs.php\">
193 <input type=\"submit\" value=\"".__("Return to preferences")."\">
196 print "</body></html>";
200 // if ($link) db_close($link);