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, $hide_private_feeds=False) {
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 $select = "SELECT * ";
32 $where = "WHERE owner_uid = '$owner_uid'";
33 $orderby = "ORDER BY title";
34 if ($hide_private_feeds){
35 $where = "WHERE owner_uid = '$owner_uid' AND private IS false";
38 if (get_pref($link, 'ENABLE_FEED_CATS')) {
41 title, feed_url, site_url,
42 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
43 $orderby = "ORDER BY cat_title, title";
47 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
51 while ($line = db_fetch_assoc($result)) {
52 $title = htmlspecialchars($line["title"]);
53 $url = htmlspecialchars($line["feed_url"]);
54 $site_url = htmlspecialchars($line["site_url"]);
57 $cat_title = htmlspecialchars($line["cat_title"]);
59 if ($old_cat_title != $cat_title) {
65 print "<outline title=\"$cat_title\">\n";
68 $old_cat_title = $cat_title;
73 $html_url_qpart = "htmlUrl=\"$site_url\"";
78 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
81 if ($cat_mode && $old_cat_title) {
85 print "</body></opml>";
88 // FIXME there are some brackets issues here
90 $op = $_REQUEST["op"];
92 if (!$op) $op = "Export";
94 if ($op == "Export") {
95 return opml_export($link, $owner_uid);
97 if ($op == "publish"){
98 $key = db_escape_string($_REQUEST["key"]);
100 $result = db_query($link, "SELECT login, owner_uid
101 FROM ttrss_user_prefs, ttrss_users WHERE
102 pref_name = '_PREFS_PUBLISH_KEY' AND
104 ttrss_users.id = owner_uid");
106 if (db_num_rows($result) == 1) {
107 $owner = db_fetch_result($result, 0, "owner_uid");
108 return opml_export($link, $owner, True);
110 print "<error>User not found</error>";
114 if ($op == "Import") {
118 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
119 <title>".__("OPML Utility")."</title>
122 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
123 <h1>".__('OPML Utility')."</h1>";
125 db_query($link, "BEGIN");
127 /* create Imported feeds category just in case */
129 $result = db_query($link, "SELECT id FROM
130 ttrss_feed_categories WHERE title = 'Imported feeds' AND
131 owner_uid = '$owner_uid' LIMIT 1");
133 if (db_num_rows($result) == 0) {
134 db_query($link, "INSERT INTO ttrss_feed_categories
136 VALUES ('Imported feeds', '$owner_uid')");
139 db_query($link, "COMMIT");
141 /* Handle OPML import by DOMXML/DOMDocument */
143 if (function_exists('domxml_open_file')) {
144 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
145 require_once "modules/opml_domxml.php";
146 opml_import_domxml($link, $owner_uid);
147 } else if (PHP_VERSION
>= 5) {
148 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
149 require_once "modules/opml_domdoc.php";
150 opml_import_domdoc($link, $owner_uid);
152 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
155 print "<br><form method=\"GET\" action=\"prefs.php\">
156 <input type=\"submit\" value=\"".__("Return to preferences")."\">
159 print "</body></html>";
163 // if ($link) db_close($link);