X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=opml.php;h=bdee88e081694a516cc711290023b3a7d0e09854;hb=50052fb78a3a9d1bb3fa488e7fd7b23125c38124;hp=c178211309b5c8c60bfffde9cc4f1c6bc91f88b9;hpb=eac7480c09689647e2f1cd0c1b4f9304bd217aa3;p=tt-rss.git diff --git a/opml.php b/opml.php index c1782113..bdee88e0 100644 --- a/opml.php +++ b/opml.php @@ -1,128 +1,37 @@ -"; - } - - require_once "config.php"; + require_once "autoload.php"; require_once "functions.php"; + require_once "sessions.php"; + require_once "sanity_check.php"; + require_once "config.php"; + require_once "db.php"; + require_once "db-prefs.php"; - $link = pg_connect(DB_CONN); - - pg_query($link, "set client_encoding = 'utf-8'"); - - if ($op == "Export") { - print ""; - print "" . date("r", time()) . ""; - print ""; - - $result = pg_query("SELECT * FROM ttrss_feeds ORDER BY title"); - - while ($line = pg_fetch_assoc($result)) { - $title = $line["title"]; - $url = $line["feed_url"]; - - print ""; - } - - print ""; - } - - function startElement($parser, $name, $attrs) { - if ($name == "OUTLINE") { - $title = pg_escape_string($attrs['TEXT']); - $url = pg_escape_string($attrs['XMLURL']); - - print "Feed $title ($url)... "; - - $result = pg_query("SELECT id FROM ttrss_feeds WHERE - title = '$title' OR feed_url = '$url'"); - - if (pg_num_rows($result) > 0) { - - print " Already imported.
"; - - } else { - - $result = pg_query("INSERT INTO ttrss_feeds (title, feed_url) VALUES - ('$title', '$url')"); - - print "Done.
"; - - } - - } - } - - function endElement($parser, $name) { - - - } - - if ($op == "Import") { - - print " - - - -

Importing OPML...

-
"; - - if (WEB_DEMO_MODE) { - print "OPML import is disabled in demo-mode."; - print "

- Return to preferences

"; - - return; - } - - if (is_file($_FILES['opml_file']['tmp_name'])) { - - $xml_parser = xml_parser_create(); - - xml_set_element_handler($xml_parser, "startElement", "endElement"); - - $fp = fopen($_FILES['opml_file']['tmp_name'], "r"); - - if ($fp) { - - while ($data = fread($fp, 4096)) { - - if (!xml_parse($xml_parser, $data, feof($fp))) { - - 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)); + if (!init_plugins()) return; - print "

- Return to preferences"; + $op = $_REQUEST['op']; - return; + if ($op == "publish"){ + $key = $_REQUEST["key"]; + $pdo = Db::pdo(); - } - } + $sth = $pdo->prepare( "SELECT owner_uid + FROM ttrss_access_keys WHERE + access_key = ? AND feed_id = 'OPML:Publish'"); + $sth->execute([$key]); - xml_parser_free($xml_parser); - fclose($fp); + if ($row = $sth->fetch()) { + $owner_uid = $row['owner_uid']; - } else { - print("Error: Could not open OPML input."); - } + $opml = new Opml($_REQUEST); + $opml->opml_export("", $owner_uid, true, false); - } else { - print "Error: please upload OPML file."; + } else { + print "User not found"; } - - print "

- Return to preferences"; - - print ""; - } - pg_close($link); - ?>