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);
14 login_sequence($link);
16 $owner_uid = $_SESSION["uid"];
18 function opml_export($link, $owner_uid) {
19 header("Content-type: application/xml+opml");
20 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
22 print "<opml version=\"1.0\">";
24 <dateCreated>" . date("r", time()) . "</dateCreated>
25 <title>Tiny Tiny RSS Feed Export</title>
31 if (get_pref($link, 'ENABLE_FEED_CATS')) {
33 $result = db_query($link, "SELECT
34 title,feed_url,site_url,
35 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
38 owner_uid = '$owner_uid'
39 ORDER BY cat_title,title");
41 $result = db_query($link, "SELECT * FROM ttrss_feeds
42 WHERE owner_uid = '$owner_uid' ORDER BY title");
47 while ($line = db_fetch_assoc($result)) {
48 $title = htmlspecialchars($line["title"]);
49 $url = htmlspecialchars($line["feed_url"]);
50 $site_url = htmlspecialchars($line["site_url"]);
53 $cat_title = htmlspecialchars($line["cat_title"]);
55 if ($old_cat_title != $cat_title) {
61 print "<outline title=\"$cat_title\">\n";
64 $old_cat_title = $cat_title;
69 $html_url_qpart = "htmlUrl=\"$site_url\"";
74 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
77 if ($cat_mode && $old_cat_title) {
81 print "</body></opml>";
84 // FIXME there are some brackets issues here
86 $op = $_REQUEST["op"];
88 if (!$op) $op = "Export";
90 if ($op == "Export") {
91 return opml_export($link, $owner_uid);
94 if ($op == "Import") {
98 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
99 <title>".__("OPML Utility")."</title>
102 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
103 <h1>".__('OPML Utility')."</h1>";
105 db_query($link, "BEGIN");
107 /* create Imported feeds category just in case */
109 $result = db_query($link, "SELECT id FROM
110 ttrss_feed_categories WHERE title = 'Imported feeds' AND
111 owner_uid = '$owner_uid' LIMIT 1");
113 if (db_num_rows($result) == 0) {
114 db_query($link, "INSERT INTO ttrss_feed_categories
116 VALUES ('Imported feeds', '$owner_uid')");
119 db_query($link, "COMMIT");
121 /* Handle OPML import by DOMXML/DOMDocument */
123 if (function_exists('domxml_open_file')) {
124 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
125 require_once "modules/opml_domxml.php";
126 opml_import_domxml($link, $owner_uid);
127 } else if (PHP_VERSION >= 5) {
128 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
129 require_once "modules/opml_domdoc.php";
130 opml_import_domdoc($link, $owner_uid);
132 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
135 print "<br><form method=\"GET\" action=\"prefs.php\">
136 <input type=\"submit\" value=\"".__("Return to preferences")."\">
139 print "</body></html>";
143 // if ($link) db_close($link);