]>
git.wh0rd.org - tt-rss.git/blob - opml.php
2 require_once "functions.php";
3 require_once "sessions.php";
4 require_once "sanity_check.php";
5 require_once "config.php";
7 require_once "db-prefs.php";
9 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
11 init_connection($link);
13 function opml_export($link, $owner_uid, $hide_private_feeds=false, $include_settings=true) {
14 if (!$_REQUEST["debug"]) {
15 header("Content-type: application/xml+opml");
17 header("Content-type: text/xml");
19 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
21 print "<opml version=\"1.0\">";
23 <dateCreated>" . date("r", time()) . "</dateCreated>
24 <title>Tiny Tiny RSS Feed Export</title>
30 $select = "SELECT * ";
31 $where = "WHERE owner_uid = '$owner_uid'";
32 $orderby = "ORDER BY title";
33 if ($hide_private_feeds){
34 $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND
35 auth_login = '' AND auth_pass = ''";
40 if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
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";
49 $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
50 print "<!-- feeding cats is not enabled -->";
51 print "<!-- $cat_feed -->";
56 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
60 while ($line = db_fetch_assoc($result)) {
61 $title = htmlspecialchars($line["title"]);
62 $url = htmlspecialchars($line["feed_url"]);
63 $site_url = htmlspecialchars($line["site_url"]);
66 $cat_title = htmlspecialchars($line["cat_title"]);
68 if ($old_cat_title != $cat_title) {
74 print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
77 $old_cat_title = $cat_title;
82 $html_url_qpart = "htmlUrl=\"$site_url\"";
87 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
90 if ($cat_mode && $old_cat_title) {
94 # export tt-rss settings
96 if ($include_settings) {
97 print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION
."\">";
99 $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
100 profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
102 while ($line = db_fetch_assoc($result)) {
104 $name = $line["pref_name"];
105 $value = htmlspecialchars($line["value"]);
107 print "<outline pref-name=\"$name\" value=\"$value\">";
116 print "</body></opml>";
119 // FIXME there are some brackets issues here
121 $op = $_REQUEST["op"];
123 if (!$op) $op = "Export";
125 if ($op == "Export") {
127 login_sequence($link);
128 $owner_uid = $_SESSION["uid"];
129 return opml_export($link, $owner_uid);
132 if ($op == "publish"){
133 $key = db_escape_string($_REQUEST["key"]);
135 $result = db_query($link, "SELECT owner_uid
136 FROM ttrss_access_keys WHERE
137 access_key = '$key' AND feed_id = 'OPML:Publish'");
139 if (db_num_rows($result) == 1) {
140 $owner_uid = db_fetch_result($result, 0, "owner_uid");
141 return opml_export($link, $owner_uid, true, false);
143 print "<error>User not found</error>";
147 if ($op == "Import") {
149 login_sequence($link);
150 $owner_uid = $_SESSION["uid"];
152 header('Content-Type: text/html; charset=utf-8');
156 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
157 <title>".__("OPML Utility")."</title>
158 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
161 <div class=\"floatingLogo\"><img src=\"images/logo_wide.png\"></div>
162 <h1>".__('OPML Utility')."</h1>";
164 db_query($link, "BEGIN");
166 /* create Imported feeds category just in case */
168 $result = db_query($link, "SELECT id FROM
169 ttrss_feed_categories WHERE title = 'Imported feeds' AND
170 owner_uid = '$owner_uid' LIMIT 1");
172 if (db_num_rows($result) == 0) {
173 db_query($link, "INSERT INTO ttrss_feed_categories
175 VALUES ('Imported feeds', '$owner_uid')");
178 db_query($link, "COMMIT");
180 print "<p>".__("Importing OPML...")."</p>";
181 require_once "modules/opml_domdoc.php";
182 opml_import_domdoc($link, $owner_uid);
184 print "<br><form method=\"GET\" action=\"prefs.php\">
185 <input type=\"submit\" value=\"".__("Return to preferences")."\">
188 print "</body></html>";
192 // if ($link) db_close($link);