|
|
|
@ -15,7 +15,7 @@
|
|
|
|
|
require_once "db.php";
|
|
|
|
|
require_once "db-prefs.php";
|
|
|
|
|
|
|
|
|
|
// $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
|
|
|
|
|
$owner_uid = $_SESSION["uid"];
|
|
|
|
|
|
|
|
|
|
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
|
|
|
|
|
|
|
@ -75,106 +75,117 @@
|
|
|
|
|
print "</body></opml>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startElement($parser, $name, $attrs) {
|
|
|
|
|
if ($op == "Import") {
|
|
|
|
|
|
|
|
|
|
if ($name == "OUTLINE") {
|
|
|
|
|
if ($name == "OUTLINE") {
|
|
|
|
|
print "<html>
|
|
|
|
|
<head>
|
|
|
|
|
<link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
|
|
|
|
|
</head>
|
|
|
|
|
<body><h1>Importing OPML...</h1>
|
|
|
|
|
<div>";
|
|
|
|
|
|
|
|
|
|
$title = $attrs["TEXT"];
|
|
|
|
|
$url = $attrs["XMLURL"];
|
|
|
|
|
if (WEB_DEMO_MODE) {
|
|
|
|
|
print "OPML import is disabled in demo-mode.";
|
|
|
|
|
print "<p><a class=\"button\" href=\"prefs.php\">
|
|
|
|
|
Return to preferences</a></div></body></html>";
|
|
|
|
|
|
|
|
|
|
if (!$title) {
|
|
|
|
|
$title = $attrs['TITLE'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this is suboptimal */
|
|
|
|
|
if (is_file($_FILES['opml_file']['tmp_name'])) {
|
|
|
|
|
$dom = domxml_open_file($_FILES['opml_file']['tmp_name']);
|
|
|
|
|
|
|
|
|
|
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
|
|
|
if ($dom) {
|
|
|
|
|
$root = $dom->document_element();
|
|
|
|
|
|
|
|
|
|
if (!$link) return;
|
|
|
|
|
$body = $root->get_elements_by_tagname('body');
|
|
|
|
|
|
|
|
|
|
$title = db_escape_string_2($title, $link);
|
|
|
|
|
$url = db_escape_string_2($url, $link);
|
|
|
|
|
if ($body[0]) {
|
|
|
|
|
$body = $body[0];
|
|
|
|
|
|
|
|
|
|
if (!$title || !$url) return;
|
|
|
|
|
$outlines = $body->get_elements_by_tagname('outline');
|
|
|
|
|
|
|
|
|
|
print "Feed <b>$title</b> ($url)... ";
|
|
|
|
|
$active_category = '';
|
|
|
|
|
|
|
|
|
|
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
|
|
|
|
|
(title = '$title' OR feed_url = '$url') AND owner_uid = ".$_SESSION["uid"]);
|
|
|
|
|
foreach ($outlines as $outline) {
|
|
|
|
|
$feed_title = $outline->get_attribute('text');
|
|
|
|
|
$cat_title = $outline->get_attribute('title');
|
|
|
|
|
$feed_url = $outline->get_attribute('xmlUrl');
|
|
|
|
|
|
|
|
|
|
if ($result && db_num_rows($result) > 0) {
|
|
|
|
|
if ($cat_title) {
|
|
|
|
|
$active_category = $cat_title;
|
|
|
|
|
|
|
|
|
|
print " Already imported.<br>";
|
|
|
|
|
db_query($link, "BEGIN");
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$result = db_query($link, "SELECT id FROM
|
|
|
|
|
ttrss_feed_categories WHERE title = '$cat_title' AND
|
|
|
|
|
owner_uid = '$owner_uid' LIMIT 1");
|
|
|
|
|
|
|
|
|
|
$result = db_query($link, "INSERT INTO ttrss_feeds (title, feed_url,owner_uid) VALUES
|
|
|
|
|
('$title', '$url', '".$_SESSION["uid"]."')");
|
|
|
|
|
if (db_num_rows($result) == 0) {
|
|
|
|
|
|
|
|
|
|
print "<b>Done.</b><br>";
|
|
|
|
|
print "Adding category <b>$cat_title</b>...<br>";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
db_query($link, "INSERT INTO ttrss_feed_categories
|
|
|
|
|
(title,owner_uid) VALUES ('$cat_title', '$owner_uid')");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($link) db_close($link);
|
|
|
|
|
db_query($link, "COMMIT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// print "$active_category : $feed_title : $xmlurl<br>";
|
|
|
|
|
|
|
|
|
|
function endElement($parser, $name) {
|
|
|
|
|
if (!$feed_title || !$feed_url) continue;
|
|
|
|
|
|
|
|
|
|
db_query($link, "BEGIN");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
$cat_id = null;
|
|
|
|
|
|
|
|
|
|
if ($op == "Import") {
|
|
|
|
|
|
|
|
|
|
print "<html>
|
|
|
|
|
<head>
|
|
|
|
|
<link rel=\"stylesheet\" href=\"opml.css\" type=\"text/css\">
|
|
|
|
|
</head>
|
|
|
|
|
<body><h1>Importing OPML...</h1>
|
|
|
|
|
<div>";
|
|
|
|
|
|
|
|
|
|
if (WEB_DEMO_MODE) {
|
|
|
|
|
print "OPML import is disabled in demo-mode.";
|
|
|
|
|
print "<p><a class=\"button\" href=\"prefs.php\">
|
|
|
|
|
Return to preferences</a></div></body></html>";
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($active_category) {
|
|
|
|
|
|
|
|
|
|
if (is_file($_FILES['opml_file']['tmp_name'])) {
|
|
|
|
|
$result = db_query($link, "SELECT id FROM
|
|
|
|
|
ttrss_feed_categories WHERE title = '$active_category' AND
|
|
|
|
|
owner_uid = '$owner_uid' LIMIT 1");
|
|
|
|
|
|
|
|
|
|
$xml_parser = xml_parser_create();
|
|
|
|
|
if (db_num_rows($result) == 1) {
|
|
|
|
|
$cat_id = db_fetch_result($result, 0, "id");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xml_set_element_handler($xml_parser, "startElement", "endElement");
|
|
|
|
|
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
|
|
|
|
|
(title = '$feed_title' OR feed_url = '$feed_url')
|
|
|
|
|
AND owner_uid = '$owner_uid'");
|
|
|
|
|
|
|
|
|
|
$fp = fopen($_FILES['opml_file']['tmp_name'], "r");
|
|
|
|
|
print "Feed <b>$feed_title</b> ($feed_url)... ";
|
|
|
|
|
|
|
|
|
|
if ($fp) {
|
|
|
|
|
if (db_num_rows($result) > 0) {
|
|
|
|
|
print " Already imported.<br>";
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
while ($data = fread($fp, 4096)) {
|
|
|
|
|
if ($cat_id) {
|
|
|
|
|
$add_query = "INSERT INTO ttrss_feeds
|
|
|
|
|
(title, feed_url, owner_uid, cat_id) VALUES
|
|
|
|
|
('$feed_title', '$feed_url', '$owner_uid', '$cat_id')";
|
|
|
|
|
|
|
|
|
|
if (!xml_parse($xml_parser, $data, feof($fp))) {
|
|
|
|
|
} else {
|
|
|
|
|
$add_query = "INSERT INTO ttrss_feeds
|
|
|
|
|
(title, feed_url, owner_uid) VALUES
|
|
|
|
|
('$feed_title', '$feed_url', '$owner_uid')";
|
|
|
|
|
|
|
|
|
|
print sprintf("Unable to parse OPML file, XML error: %s at line %d",
|
|
|
|
|
xml_error_string(xml_get_error_code($xml_parser)),
|
|
|
|
|
xml_get_current_line_number($xml_parser));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print "<p><a class=\"button\" href=\"prefs.php\">
|
|
|
|
|
Return to preferences</a>";
|
|
|
|
|
db_query($link, $add_query);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
print "<b>Done.</b><br>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db_query($link, "COMMIT");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xml_parser_free($xml_parser);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
print "Error: can't find body element.";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
print("Error: Could not open OPML input.");
|
|
|
|
|
print "Error while parsing document.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|