move data import/export to a separate plugin

This commit is contained in:
Andrew Dolgov
2012-12-24 15:03:19 +04:00
parent 41b82aa4b9
commit 6c2637d973
9 changed files with 559 additions and 512 deletions

View File

@@ -16,24 +16,6 @@ class Dlg extends Handler_Protected {
print "</dlg>";
}
function exportData() {
print "<p style='text-align : center' id='export_status_message'>You need to prepare exported data first by clicking the button below.</p>";
print "<div align='center'>";
print "<button dojoType=\"dijit.form.Button\"
onclick=\"dijit.byId('dataExportDlg').prepare()\">".
__('Prepare data')."</button>";
print "<button dojoType=\"dijit.form.Button\"
onclick=\"dijit.byId('dataExportDlg').hide()\">".
__('Close this window')."</button>";
print "</div>";
}
function importOpml() {
header("Content-Type: text/html"); # required for iframe
@@ -704,29 +686,6 @@ class Dlg extends Handler_Protected {
return;
}
function dataImport() {
header("Content-Type: text/html"); # required for iframe
print "<div style='text-align : center'>";
if (is_file($_FILES['export_file']['tmp_name'])) {
perform_data_import($this->link, $_FILES['export_file']['tmp_name'], $_SESSION['uid']);
} else {
print "<p>" . T_sprintf("Could not upload file. You might need to adjust upload_max_filesize
in PHP.ini (current value = %s)", ini_get("upload_max_filesize")) . " or use CLI import tool.</p>";
}
print "<button dojoType=\"dijit.form.Button\"
onclick=\"dijit.byId('dataImportDlg').hide()\">".
__('Close this window')."</button>";
print "</div>";
}
function batchSubscribe() {
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">";

View File

@@ -1376,9 +1376,7 @@ class Pref_Feeds extends Handler_Protected {
print "</div>"; # feeds pane
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Import and export')."\">";
print "<h3>" . __("OPML") . "</h3>";
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
@@ -1416,30 +1414,6 @@ class Pref_Feeds extends Handler_Protected {
print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">".
__('Display published OPML URL')."</button> ";
print "<h3>" . __("Article archive") . "</h3>";
print "<p>" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "</p>";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return exportData()\">".
__('Export my data')."</button> ";
print "<hr>";
print "<iframe id=\"data_upload_iframe\"
name=\"data_upload_iframe\" onload=\"dataImportComplete(this)\"
style=\"width: 400px; height: 100px; display: none;\"></iframe>";
print "<form name=\"import_form\" style='display : block' target=\"data_upload_iframe\"
enctype=\"multipart/form-data\" method=\"POST\"
action=\"backend.php\">
<input id=\"export_file\" name=\"export_file\" type=\"file\">&nbsp;
<input type=\"hidden\" name=\"op\" value=\"dlg\">
<input type=\"hidden\" name=\"method\" value=\"dataimport\">
<button dojoType=\"dijit.form.Button\" onclick=\"return importData();\" type=\"submit\">" .
__('Import') . "</button>";
print "</div>"; # pane
if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {

View File

@@ -2,7 +2,7 @@
class RPC extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "completelabels");
$csrf_ignored = array("sanitycheck", "completelabels");
return array_search($method, $csrf_ignored) !== false;
}
@@ -14,89 +14,6 @@ class RPC extends Handler_Protected {
$_SESSION["prefs_cache"] = array();
}
function exportget() {
$exportname = CACHE_DIR . "/export/" .
sha1($_SESSION['uid'] . $_SESSION['login']) . ".xml";
if (file_exists($exportname)) {
header("Content-type: text/xml");
if (function_exists('gzencode')) {
header("Content-Disposition: attachment; filename=TinyTinyRSS_exported.xml.gz");
echo gzencode(file_get_contents($exportname));
} else {
header("Content-Disposition: attachment; filename=TinyTinyRSS_exported.xml");
echo file_get_contents($exportname);
}
} else {
echo "File not found.";
}
}
function exportrun() {
$offset = (int) db_escape_string($_REQUEST['offset']);
$exported = 0;
$limit = 250;
if ($offset < 10000 && is_writable(CACHE_DIR . "/export")) {
$result = db_query($this->link, "SELECT
ttrss_entries.guid,
ttrss_entries.title,
content,
marked,
published,
score,
note,
link,
tag_cache,
label_cache,
ttrss_feeds.title AS feed_title,
ttrss_feeds.feed_url AS feed_url,
ttrss_entries.updated
FROM
ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id),
ttrss_entries
WHERE
(marked = true OR feed_id IS NULL) AND
ref_id = ttrss_entries.id AND
ttrss_user_entries.owner_uid = " . $_SESSION['uid'] . "
ORDER BY ttrss_entries.id LIMIT $limit OFFSET $offset");
$exportname = sha1($_SESSION['uid'] . $_SESSION['login']);
if ($offset == 0) {
$fp = fopen(CACHE_DIR . "/export/$exportname.xml", "w");
fputs($fp, "<articles schema-version=\"".SCHEMA_VERSION."\">");
} else {
$fp = fopen(CACHE_DIR . "/export/$exportname.xml", "a");
}
if ($fp) {
while ($line = db_fetch_assoc($result)) {
fputs($fp, "<article>");
foreach ($line as $k => $v) {
fputs($fp, "<$k><![CDATA[$v]]></$k>");
}
fputs($fp, "</article>");
}
$exported = db_num_rows($result);
if ($exported < $limit && $exported > 0) {
fputs($fp, "</articles>");
}
fclose($fp);
}
}
print json_encode(array("exported" => $exported));
}
function remprofiles() {
$ids = explode(",", db_escape_string(trim($_REQUEST["ids"])));