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 if (DB_TYPE
== "pgsql") {
14 pg_query($link, "set client_encoding = 'utf-8'");
15 pg_set_client_encoding("UNICODE");
17 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET
) {
18 db_query($link, "SET NAMES " . MYSQL_CHARSET
);
19 // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
23 login_sequence($link);
25 $owner_uid = $_SESSION["uid"];
27 function opml_export($link, $owner_uid) {
28 header("Content-type: application/xml+opml");
29 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
31 print "<opml version=\"1.0\">";
33 <dateCreated>" . date("r", time()) . "</dateCreated>
34 <title>Tiny Tiny RSS Feed Export</title>
40 if (get_pref($link, 'ENABLE_FEED_CATS')) {
42 $result = db_query($link, "SELECT
43 title,feed_url,site_url,
44 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
47 owner_uid = '$owner_uid'
48 ORDER BY cat_title,title");
50 $result = db_query($link, "SELECT * FROM ttrss_feeds
51 WHERE owner_uid = '$owner_uid' ORDER BY title");
56 while ($line = db_fetch_assoc($result)) {
57 $title = htmlspecialchars($line["title"]);
58 $url = htmlspecialchars($line["feed_url"]);
59 $site_url = htmlspecialchars($line["site_url"]);
62 $cat_title = htmlspecialchars($line["cat_title"]);
64 if ($old_cat_title != $cat_title) {
70 print "<outline title=\"$cat_title\">\n";
73 $old_cat_title = $cat_title;
78 $html_url_qpart = "htmlUrl=\"$site_url\"";
83 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
86 if ($cat_mode && $old_cat_title) {
90 print "</body></opml>";
93 // FIXME there are some brackets issues here
95 $op = $_REQUEST["op"];
97 if (!$op) $op = "Export";
99 if ($op == "Export") {
100 return opml_export($link, $owner_uid);
103 if ($op == "Import") {
107 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
108 <title>".__("OPML Utility")."</title>
111 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
112 <h1>".__('OPML Utility')."</h1>";
114 db_query($link, "BEGIN");
116 /* create Imported feeds category just in case */
118 $result = db_query($link, "SELECT id FROM
119 ttrss_feed_categories WHERE title = 'Imported feeds' AND
120 owner_uid = '$owner_uid' LIMIT 1");
122 if (db_num_rows($result) == 0) {
123 db_query($link, "INSERT INTO ttrss_feed_categories
125 VALUES ('Imported feeds', '$owner_uid')");
128 db_query($link, "COMMIT");
130 /* Handle OPML import by DOMXML/DOMDocument */
132 if (function_exists('domxml_open_file')) {
133 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
134 require_once "modules/opml_domxml.php";
135 opml_import_domxml($link, $owner_uid);
136 } else if (PHP_VERSION
>= 5) {
137 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
138 require_once "modules/opml_domdoc.php";
139 opml_import_domdoc($link, $owner_uid);
141 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
144 print "<br><form method=\"GET\" action=\"prefs.php\">
145 <input type=\"submit\" value=\"".__("Return to preferences")."\">
148 print "</body></html>";
152 // if ($link) db_close($link);