]> git.wh0rd.org - tt-rss.git/blob - opml.php
mysql: disable utf8
[tt-rss.git] / opml.php
1 <?php
2 error_reporting(E_ERROR | E_WARNING | E_PARSE);
3
4 require_once "sessions.php";
5 require_once "sanity_check.php";
6 require_once "functions.php";
7 require_once "config.php";
8 require_once "db.php";
9 require_once "db-prefs.php";
10
11 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
12
13 if (DB_TYPE == "pgsql") {
14 pg_query($link, "set client_encoding = 'utf-8'");
15 pg_set_client_encoding("UNICODE");
16 } else {
17 // db_query($link, "SET NAMES utf8");
18 // db_query($link, "SET CHARACTER SET utf8");
19 }
20
21 login_sequence($link);
22
23 $owner_uid = $_SESSION["uid"];
24
25 function opml_export($link, $owner_uid) {
26 header("Content-type: application/xml+opml");
27 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
28
29 print "<opml version=\"1.0\">";
30 print "<head>
31 <dateCreated>" . date("r", time()) . "</dateCreated>
32 <title>Tiny Tiny RSS Feed Export</title>
33 </head>";
34 print "<body>";
35
36 $cat_mode = false;
37
38 if (get_pref($link, 'ENABLE_FEED_CATS')) {
39 $cat_mode = true;
40 $result = db_query($link, "SELECT
41 title,feed_url,site_url,
42 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
43 FROM ttrss_feeds
44 WHERE
45 owner_uid = '$owner_uid'
46 ORDER BY cat_title,title");
47 } else {
48 $result = db_query($link, "SELECT * FROM ttrss_feeds
49 WHERE owner_uid = '$owner_uid' ORDER BY title");
50 }
51
52 $old_cat_title = "";
53
54 while ($line = db_fetch_assoc($result)) {
55 $title = htmlspecialchars($line["title"]);
56 $url = htmlspecialchars($line["feed_url"]);
57 $site_url = htmlspecialchars($line["site_url"]);
58
59 if ($cat_mode) {
60 $cat_title = htmlspecialchars($line["cat_title"]);
61
62 if ($old_cat_title != $cat_title) {
63 if ($old_cat_title) {
64 print "</outline>\n";
65 }
66
67 if ($cat_title) {
68 print "<outline title=\"$cat_title\">\n";
69 }
70
71 $old_cat_title = $cat_title;
72 }
73 }
74
75 if ($site_url) {
76 $html_url_qpart = "htmlUrl=\"$site_url\"";
77 } else {
78 $html_url_qpart = "";
79 }
80
81 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
82 }
83
84 if ($cat_mode && $old_cat_title) {
85 print "</outline>\n";
86 }
87
88 print "</body></opml>";
89 }
90
91 // FIXME there are some brackets issues here
92
93 $op = $_REQUEST["op"];
94
95 if (!$op) $op = "Export";
96
97 if ($op == "Export") {
98 return opml_export($link, $owner_uid);
99 }
100
101 if ($op == "Import") {
102
103 print "<html>
104 <head>
105 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
106 <title>".__("OPML Utility")."</title>
107 </head>
108 <body>
109 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
110 <h1>".__('OPML Utility')."</h1>";
111
112 if (function_exists('domxml_open_file')) {
113 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
114 require_once "modules/opml_domxml.php";
115 opml_import_domxml($link, $owner_uid);
116 } else if (PHP_VERSION >= 5) {
117 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
118 require_once "modules/opml_domdoc.php";
119 opml_import_domdoc($link, $owner_uid);
120 } else {
121 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
122 }
123
124 print "<br><form method=\"GET\" action=\"prefs.php\">
125 <input type=\"submit\" value=\"".__("Return to preferences")."\">
126 </form>";
127
128 print "</body></html>";
129
130 }
131
132 // if ($link) db_close($link);
133
134 ?>