2 error_reporting(E_ERROR | E_WARNING | E_PARSE
);
4 require_once "sessions.php";
5 require_once "sanity_check.php";
6 require_once "functions.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 init_connection($link);
15 function opml_export($link, $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 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
23 print "<opml version=\"1.0\">";
25 <dateCreated>" . date("r", time()) . "</dateCreated>
26 <title>Tiny Tiny RSS Feed Export</title>
32 $select = "SELECT * ";
33 $where = "WHERE owner_uid = '$owner_uid'";
34 $orderby = "ORDER BY title";
35 if ($hide_private_feeds){
36 $where = "WHERE owner_uid = '$owner_uid' AND private IS false AND
37 auth_login = '' AND auth_pass = ''";
42 if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
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";
51 $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
52 print "<!-- feeding cats is not enabled -->";
53 print "<!-- $cat_feed -->";
58 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
62 while ($line = db_fetch_assoc($result)) {
63 $title = htmlspecialchars($line["title"]);
64 $url = htmlspecialchars($line["feed_url"]);
65 $site_url = htmlspecialchars($line["site_url"]);
68 $cat_title = htmlspecialchars($line["cat_title"]);
70 if ($old_cat_title != $cat_title) {
76 print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
79 $old_cat_title = $cat_title;
84 $html_url_qpart = "htmlUrl=\"$site_url\"";
89 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
92 if ($cat_mode && $old_cat_title) {
96 # export tt-rss settings
98 if ($include_settings) {
99 print "<outline title=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION
."\">";
101 $result = db_query($link, "SELECT pref_name, value FROM ttrss_user_prefs WHERE
102 profile IS NULL AND owner_uid = " . $_SESSION["uid"]);
104 while ($line = db_fetch_assoc($result)) {
106 $name = $line["pref_name"];
107 $value = htmlspecialchars($line["value"]);
109 print "<outline pref-name=\"$name\" value=\"$value\">";
118 print "</body></opml>";
121 // FIXME there are some brackets issues here
123 $op = $_REQUEST["op"];
125 if (!$op) $op = "Export";
127 if ($op == "Export") {
129 login_sequence($link);
130 $owner_uid = $_SESSION["uid"];
131 return opml_export($link, $owner_uid);
134 if ($op == "publish"){
135 $key = db_escape_string($_REQUEST["key"]);
137 $result = db_query($link, "SELECT login, owner_uid
138 FROM ttrss_user_prefs, ttrss_users WHERE
139 pref_name = '_PREFS_PUBLISH_KEY' AND
141 ttrss_users.id = owner_uid");
143 if (db_num_rows($result) == 1) {
144 $owner = db_fetch_result($result, 0, "owner_uid");
145 return opml_export($link, $owner, true, false);
147 print "<error>User not found</error>";
151 if ($op == "Import") {
153 login_sequence($link);
154 $owner_uid = $_SESSION["uid"];
156 header('Content-Type: text/html; charset=utf-8');
160 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
161 <title>".__("OPML Utility")."</title>
162 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
165 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
166 <h1>".__('OPML Utility')."</h1>";
168 db_query($link, "BEGIN");
170 /* create Imported feeds category just in case */
172 $result = db_query($link, "SELECT id FROM
173 ttrss_feed_categories WHERE title = 'Imported feeds' AND
174 owner_uid = '$owner_uid' LIMIT 1");
176 if (db_num_rows($result) == 0) {
177 db_query($link, "INSERT INTO ttrss_feed_categories
179 VALUES ('Imported feeds', '$owner_uid')");
182 db_query($link, "COMMIT");
184 /* Handle OPML import by DOMXML/DOMDocument */
186 if (function_exists('domxml_open_file')) {
187 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
188 require_once "modules/opml_domxml.php";
189 opml_import_domxml($link, $owner_uid);
190 } else if (PHP_VERSION
>= 5) {
191 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
192 require_once "modules/opml_domdoc.php";
193 opml_import_domdoc($link, $owner_uid);
195 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
198 print "<br><form method=\"GET\" action=\"prefs.php\">
199 <input type=\"submit\" value=\"".__("Return to preferences")."\">
202 print "</body></html>";
206 // if ($link) db_close($link);