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";
37 if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid) == true) {
40 title, feed_url, site_url,
41 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title";
42 $orderby = "ORDER BY cat_title, title";
46 $cat_feed = get_pref($link, 'ENABLE_FEED_CATS');
47 print "<!-- feeding cats is not enabled -->";
48 print "<!-- $cat_feed -->";
53 $result = db_query($link, $select." FROM ttrss_feeds ".$where." ".$orderby);
57 while ($line = db_fetch_assoc($result)) {
58 $title = htmlspecialchars($line["title"]);
59 $url = htmlspecialchars($line["feed_url"]);
60 $site_url = htmlspecialchars($line["site_url"]);
63 $cat_title = htmlspecialchars($line["cat_title"]);
65 if ($old_cat_title != $cat_title) {
71 print "<outline title=\"$cat_title\" text=\"$cat_title\" >\n";
74 $old_cat_title = $cat_title;
79 $html_url_qpart = "htmlUrl=\"$site_url\"";
84 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
87 if ($cat_mode && $old_cat_title) {
91 print "</body></opml>";
94 // FIXME there are some brackets issues here
96 $op = $_REQUEST["op"];
98 if (!$op) $op = "Export";
100 if ($op == "Export") {
102 login_sequence($link);
103 $owner_uid = $_SESSION["uid"];
104 return opml_export($link, $owner_uid);
106 if ($op == "publish"){
107 $key = db_escape_string($_REQUEST["key"]);
109 $result = db_query($link, "SELECT login, owner_uid
110 FROM ttrss_user_prefs, ttrss_users WHERE
111 pref_name = '_PREFS_PUBLISH_KEY' AND
113 ttrss_users.id = owner_uid");
115 if (db_num_rows($result) == 1) {
116 $owner = db_fetch_result($result, 0, "owner_uid");
117 return opml_export($link, $owner, True);
119 print "<error>User not found</error>";
123 if ($op == "Import") {
125 login_sequence($link);
126 $owner_uid = $_SESSION["uid"];
130 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
131 <title>".__("OPML Utility")."</title>
134 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
135 <h1>".__('OPML Utility')."</h1>";
137 db_query($link, "BEGIN");
139 /* create Imported feeds category just in case */
141 $result = db_query($link, "SELECT id FROM
142 ttrss_feed_categories WHERE title = 'Imported feeds' AND
143 owner_uid = '$owner_uid' LIMIT 1");
145 if (db_num_rows($result) == 0) {
146 db_query($link, "INSERT INTO ttrss_feed_categories
148 VALUES ('Imported feeds', '$owner_uid')");
151 db_query($link, "COMMIT");
153 /* Handle OPML import by DOMXML/DOMDocument */
155 if (function_exists('domxml_open_file')) {
156 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
157 require_once "modules/opml_domxml.php";
158 opml_import_domxml($link, $owner_uid);
159 } else if (PHP_VERSION
>= 5) {
160 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
161 require_once "modules/opml_domdoc.php";
162 opml_import_domdoc($link, $owner_uid);
164 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
167 print "<br><form method=\"GET\" action=\"prefs.php\">
168 <input type=\"submit\" value=\"".__("Return to preferences")."\">
171 print "</body></html>";
175 // if ($link) db_close($link);