]> git.wh0rd.org - tt-rss.git/blame - opml.php
adding in the backend connection bits so that the dialog works
[tt-rss.git] / opml.php
CommitLineData
1d3a17c7 1<?php
d65981e2
AD
2 error_reporting(E_ERROR | E_WARNING | E_PARSE);
3
1559e374 4 require_once "sessions.php";
66581886 5 require_once "sanity_check.php";
4e9f5c24 6 require_once "functions.php";
9a4506c8 7 require_once "config.php";
8158c57a 8 require_once "db.php";
a0111294 9 require_once "db-prefs.php";
9a4506c8 10
8158c57a 11 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
9f311df6 12
f29ba148 13 init_connection($link);
4e9f5c24
AD
14 login_sequence($link);
15
16 $owner_uid = $_SESSION["uid"];
17
579bf16e 18 function opml_export($link, $owner_uid) {
12ec37f3 19 header("Content-type: application/xml+opml");
981e8107 20 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
4e9f5c24 21
9a4506c8 22 print "<opml version=\"1.0\">";
a90005e6
AD
23 print "<head>
24 <dateCreated>" . date("r", time()) . "</dateCreated>
25 <title>Tiny Tiny RSS Feed Export</title>
26 </head>";
9a4506c8
AD
27 print "<body>";
28
da49ccf5
AD
29 $cat_mode = false;
30
31 if (get_pref($link, 'ENABLE_FEED_CATS')) {
32 $cat_mode = true;
33 $result = db_query($link, "SELECT
fa7b8749 34 title,feed_url,site_url,
18d37445
AD
35 (SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title
36 FROM ttrss_feeds
bc15240d
AD
37 WHERE
38 owner_uid = '$owner_uid'
18d37445 39 ORDER BY cat_title,title");
da49ccf5
AD
40 } else {
41 $result = db_query($link, "SELECT * FROM ttrss_feeds
2513ae2b 42 WHERE owner_uid = '$owner_uid' ORDER BY title");
da49ccf5
AD
43 }
44
45 $old_cat_title = "";
9a4506c8 46
8158c57a 47 while ($line = db_fetch_assoc($result)) {
6e0584e9
AD
48 $title = htmlspecialchars($line["title"]);
49 $url = htmlspecialchars($line["feed_url"]);
fa7b8749 50 $site_url = htmlspecialchars($line["site_url"]);
9a4506c8 51
da49ccf5
AD
52 if ($cat_mode) {
53 $cat_title = htmlspecialchars($line["cat_title"]);
54
55 if ($old_cat_title != $cat_title) {
56 if ($old_cat_title) {
5b9af2b9 57 print "</outline>\n";
da49ccf5
AD
58 }
59
5b9af2b9
AD
60 if ($cat_title) {
61 print "<outline title=\"$cat_title\">\n";
62 }
da49ccf5
AD
63
64 $old_cat_title = $cat_title;
65 }
66 }
67
fa7b8749
AD
68 if ($site_url) {
69 $html_url_qpart = "htmlUrl=\"$site_url\"";
70 } else {
71 $html_url_qpart = "";
72 }
73
74 print "<outline text=\"$title\" xmlUrl=\"$url\" $html_url_qpart/>\n";
9a4506c8
AD
75 }
76
da49ccf5 77 if ($cat_mode && $old_cat_title) {
5b9af2b9 78 print "</outline>\n";
da49ccf5
AD
79 }
80
9a4506c8
AD
81 print "</body></opml>";
82 }
83
30f782a2
AD
84 // FIXME there are some brackets issues here
85
86 $op = $_REQUEST["op"];
87
88 if (!$op) $op = "Export";
89
90 if ($op == "Export") {
579bf16e 91 return opml_export($link, $owner_uid);
30f782a2
AD
92 }
93
e98a3f65 94 if ($op == "Import") {
8158c57a 95
e98a3f65
AD
96 print "<html>
97 <head>
ef59e6e8 98 <link rel=\"stylesheet\" href=\"utility.css\" type=\"text/css\">
1025ad87 99 <title>".__("OPML Utility")."</title>
e98a3f65 100 </head>
04f6df27 101 <body>
ef59e6e8 102 <div class=\"floatingLogo\"><img src=\"images/ttrss_logo.png\"></div>
d1db26aa 103 <h1>".__('OPML Utility')."</h1>";
9f311df6 104
c03cf250
AD
105 db_query($link, "BEGIN");
106
107 /* create Imported feeds category just in case */
108
109 $result = db_query($link, "SELECT id FROM
110 ttrss_feed_categories WHERE title = 'Imported feeds' AND
111 owner_uid = '$owner_uid' LIMIT 1");
112
113 if (db_num_rows($result) == 0) {
114 db_query($link, "INSERT INTO ttrss_feed_categories
115 (title,owner_uid)
116 VALUES ('Imported feeds', '$owner_uid')");
117 }
118
119 db_query($link, "COMMIT");
120
121 /* Handle OPML import by DOMXML/DOMDocument */
122
30f782a2 123 if (function_exists('domxml_open_file')) {
06719138 124 print "<p>".__("Importing OPML (using DOMXML extension)...")."</p>";
30f782a2
AD
125 require_once "modules/opml_domxml.php";
126 opml_import_domxml($link, $owner_uid);
5eb66ed7 127 } else if (PHP_VERSION >= 5) {
06719138 128 print "<p>".__("Importing OPML (using DOMDocument extension)...")."</p>";
30f782a2
AD
129 require_once "modules/opml_domdoc.php";
130 opml_import_domdoc($link, $owner_uid);
5eb66ed7
AD
131 } else {
132 print_error(__("DOMXML extension is not found. It is required for PHP versions below 5."));
9f311df6
AD
133 }
134
d7c848d9 135 print "<br><form method=\"GET\" action=\"prefs.php\">
1025ad87 136 <input type=\"submit\" value=\"".__("Return to preferences")."\">
d7c848d9 137 </form>";
9f311df6 138
30f782a2 139 print "</body></html>";
9f311df6
AD
140
141 }
142
3d477c2c 143// if ($link) db_close($link);
9f311df6 144
9a4506c8 145?>