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) {
16 header("Content-type: application/xml+opml");
17 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
19 print "<opml version=\"1.0\">";
21 <dateCreated>" . date("r", time()) . "</dateCreated>
22 <title>Tiny Tiny RSS Feed Export</title>
28 $select = "SELECT * ";
29 $where = "WHERE owner_uid = '$owner_uid'";
30 $orderby = "ORDER BY title";
31 if ($hide_private_feeds){
32 $where = "WHERE owner_uid = '$owner_uid' AND private IS false";
35 if (get_pref($link, 'ENABLE_FEED_CATS')) {
38 title, feed_url, site_url,
39 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
40 $orderby = "ORDER BY cat_title, title";
44 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
48 while ($line = db_fetch_assoc($result)) {
49 $title = htmlspecialchars($line["title"]);
50 $url = htmlspecialchars($line["feed_url"]);
51 $site_url = htmlspecialchars($line["site_url"]);
54 $cat_title = htmlspecialchars($line["cat_title"]);
56 if ($old_cat_title != $cat_title) {
62 print "<outline title=\"$cat_title\">\n";
65 $old_cat_title = $cat_title;
70 $html_url_qpart = "htmlUrl=\"$site_url\"";
75 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
78 if ($cat_mode && $old_cat_title) {
82 print "</body></opml>";
85 // FIXME there are some brackets issues here
87 $op = $_REQUEST["op"];
89 if (!$op) $op = "Export";
91 if ($op == "Export") {
93 login_sequence($link);
94 $owner_uid = $_SESSION["uid"];
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") {
116 login_sequence($link);
117 $owner_uid = $_SESSION["uid"];
121 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
122 <title>".__("OPML Utility")."</title>
125 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
126 <h1>".__('OPML Utility')."</h1>";
128 db_query($link, "BEGIN");
130 /* create Imported feeds category just in case */
132 $result = db_query($link, "SELECT id FROM
133 ttrss_feed_categories WHERE title = 'Imported feeds' AND
134 owner_uid = '$owner_uid' LIMIT 1");
136 if (db_num_rows($result) == 0) {
137 db_query($link, "INSERT INTO ttrss_feed_categories
139 VALUES ('Imported feeds', '$owner_uid')");
142 db_query($link, "COMMIT");
144 /* Handle OPML import by DOMXML/DOMDocument */
146 if (function_exists('domxml_open_file')) {
147 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
148 require_once "modules/opml_domxml.php";
149 opml_import_domxml($link, $owner_uid);
150 } else if (PHP_VERSION
>= 5) {
151 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
152 require_once "modules/opml_domdoc.php";
153 opml_import_domdoc($link, $owner_uid);
155 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
158 print "<br><form method=\"GET\" action=\"prefs.php\">
159 <input type=\"submit\" value=\"".__("Return to preferences")."\">
162 print "</body></html>";
166 // if ($link) db_close($link);