refactor OPML export/import code to be less horrible
This commit is contained in:
parent
78cc470193
commit
b3bc638a9f
|
@ -49,7 +49,7 @@ class Dlg extends Handler_Protected {
|
||||||
|
|
||||||
print "<div align='center'>";
|
print "<div align='center'>";
|
||||||
|
|
||||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">".
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Prefs.OPML.changeKey()\">".
|
||||||
__('Generate new URL')."</button> ";
|
__('Generate new URL')."</button> ";
|
||||||
|
|
||||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.closeInfoBox()\">".
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.closeInfoBox()\">".
|
||||||
|
|
|
@ -8,11 +8,8 @@ class Opml extends Handler_Protected {
|
||||||
}
|
}
|
||||||
|
|
||||||
function export() {
|
function export() {
|
||||||
$output_name = $_REQUEST["filename"];
|
$output_name = "tt-rss_".date("Y-m-d").".opml";
|
||||||
if (!$output_name) $output_name = "TinyTinyRSS.opml";
|
$show_settings = $_REQUEST["include_settings"];
|
||||||
|
|
||||||
$show_settings = $_REQUEST["settings"];
|
|
||||||
|
|
||||||
$owner_uid = $_SESSION["uid"];
|
$owner_uid = $_SESSION["uid"];
|
||||||
|
|
||||||
$rc = $this->opml_export($output_name, $owner_uid, false, ($show_settings == 1));
|
$rc = $this->opml_export($output_name, $owner_uid, false, ($show_settings == 1));
|
||||||
|
|
|
@ -1270,11 +1270,11 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
|
|
||||||
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
|
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.") .
|
print_notice(__("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") .
|
||||||
__("Only main settings profile can be migrated using OPML.") . "</p>";
|
__("Only main settings profile can be migrated using OPML."));
|
||||||
|
|
||||||
print "<iframe id=\"upload_iframe\"
|
print "<iframe id=\"upload_iframe\"
|
||||||
name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
|
name=\"upload_iframe\" onload=\"Prefs.OPML.onImportComplete(this)\"
|
||||||
style=\"width: 400px; height: 100px; display: none;\"></iframe>";
|
style=\"width: 400px; height: 100px; display: none;\"></iframe>";
|
||||||
|
|
||||||
print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
|
print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\"
|
||||||
|
@ -1285,24 +1285,29 @@ class Pref_Feeds extends Handler_Protected {
|
||||||
</label>
|
</label>
|
||||||
<input type=\"hidden\" name=\"op\" value=\"dlg\">
|
<input type=\"hidden\" name=\"op\" value=\"dlg\">
|
||||||
<input type=\"hidden\" name=\"method\" value=\"importOpml\">
|
<input type=\"hidden\" name=\"method\" value=\"importOpml\">
|
||||||
<button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" .
|
<button dojoType=\"dijit.form.Button\" onclick=\"return Prefs.OPML.import();\" type=\"submit\">" .
|
||||||
__('Import my OPML') . "</button>";
|
__('Import OPML') . "</button>";
|
||||||
|
|
||||||
|
print "</form>";
|
||||||
|
|
||||||
|
print "<p/>";
|
||||||
|
|
||||||
|
print "<form dojoType=\"dijit.form.Form\" id=\"opmlExportForm\">";
|
||||||
|
|
||||||
|
print "<button dojoType=\"dijit.form.Button\"
|
||||||
|
onclick=\"Prefs.OPML.export()\" >" .
|
||||||
|
__('Export OPML') . "</button>";
|
||||||
|
|
||||||
|
print "<label>";
|
||||||
|
print_checkbox("include_settings", true, "1", "");
|
||||||
|
print " " . __("Include settings");
|
||||||
|
print "</label>";
|
||||||
|
|
||||||
|
print "</form>";
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
|
|
||||||
$opml_export_filename = "TinyTinyRSS_".date("Y-m-d").".opml";
|
print_notice(__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.'));
|
||||||
|
|
||||||
print "<p>" . __('Filename:') .
|
|
||||||
" <input class=\"input input-text\" type=\"text\" id=\"filename\" value=\"$opml_export_filename\" /> " .
|
|
||||||
__('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>";
|
|
||||||
|
|
||||||
print "</p><button dojoType=\"dijit.form.Button\"
|
|
||||||
onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" .
|
|
||||||
__('Export OPML') . "</button></p></form>";
|
|
||||||
|
|
||||||
print "<hr>";
|
|
||||||
|
|
||||||
print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "</p>";
|
|
||||||
|
|
||||||
print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.");
|
print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.");
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,85 @@ define(["dojo/_base/declare"], function (declare) {
|
||||||
Notify.close();
|
Notify.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Prefs.OPML = {
|
||||||
|
import: function() {
|
||||||
|
const opml_file = $("opml_file");
|
||||||
|
|
||||||
|
if (opml_file.value.length == 0) {
|
||||||
|
alert(__("Please choose an OPML file first."));
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Notify.progress("Importing, please wait...", true);
|
||||||
|
|
||||||
|
Element.show("upload_iframe");
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onImportComplete: function(iframe) {
|
||||||
|
if (!iframe.contentDocument.body.innerHTML) return false;
|
||||||
|
|
||||||
|
Element.show(iframe);
|
||||||
|
|
||||||
|
Notify.close();
|
||||||
|
|
||||||
|
if (dijit.byId('opmlImportDlg'))
|
||||||
|
dijit.byId('opmlImportDlg').destroyRecursive();
|
||||||
|
|
||||||
|
const content = iframe.contentDocument.body.innerHTML;
|
||||||
|
|
||||||
|
const dialog = new dijit.Dialog({
|
||||||
|
id: "opmlImportDlg",
|
||||||
|
title: __("OPML Import"),
|
||||||
|
style: "width: 600px",
|
||||||
|
onCancel: function () {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
execute: function () {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
content: content
|
||||||
|
});
|
||||||
|
|
||||||
|
dojo.connect(dialog, "onShow", function () {
|
||||||
|
Element.hide(iframe);
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
},
|
||||||
|
export: function() {
|
||||||
|
console.log("export");
|
||||||
|
window.open("backend.php?op=opml&method=export&" + dojo.formToQuery("opmlExportForm"));
|
||||||
|
},
|
||||||
|
changeKey: function() {
|
||||||
|
if (confirm(__("Replace current OPML publishing address with a new one?"))) {
|
||||||
|
Notify.progress("Trying to change address...", true);
|
||||||
|
|
||||||
|
xhrJson("backend.php", {op: "pref-feeds", method: "regenOPMLKey"}, (reply) => {
|
||||||
|
if (reply) {
|
||||||
|
const new_link = reply.link;
|
||||||
|
const e = $('pub_opml_url');
|
||||||
|
|
||||||
|
if (new_link) {
|
||||||
|
e.href = new_link;
|
||||||
|
e.innerHTML = new_link;
|
||||||
|
|
||||||
|
new Effect.Highlight(e);
|
||||||
|
|
||||||
|
Notify.close();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Notify.error("Could not change feed URL.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return Prefs;
|
return Prefs;
|
||||||
});
|
});
|
||||||
|
|
75
js/prefs.js
75
js/prefs.js
|
@ -153,78 +153,3 @@ require(["dojo/_base/kernel",
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function opmlImportComplete(iframe) {
|
|
||||||
if (!iframe.contentDocument.body.innerHTML) return false;
|
|
||||||
|
|
||||||
Element.show(iframe);
|
|
||||||
|
|
||||||
Notify.close();
|
|
||||||
|
|
||||||
if (dijit.byId('opmlImportDlg'))
|
|
||||||
dijit.byId('opmlImportDlg').destroyRecursive();
|
|
||||||
|
|
||||||
const content = iframe.contentDocument.body.innerHTML;
|
|
||||||
|
|
||||||
const dialog = new dijit.Dialog({
|
|
||||||
id: "opmlImportDlg",
|
|
||||||
title: __("OPML Import"),
|
|
||||||
style: "width: 600px",
|
|
||||||
onCancel: function () {
|
|
||||||
window.location.reload();
|
|
||||||
},
|
|
||||||
execute: function () {
|
|
||||||
window.location.reload();
|
|
||||||
},
|
|
||||||
content: content
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
function opmlImport() {
|
|
||||||
|
|
||||||
const opml_file = $("opml_file");
|
|
||||||
|
|
||||||
if (opml_file.value.length == 0) {
|
|
||||||
alert(__("Please choose an OPML file first."));
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
Notify.progress("Importing, please wait...", true);
|
|
||||||
|
|
||||||
Element.show("upload_iframe");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function opmlRegenKey() {
|
|
||||||
if (confirm(__("Replace current OPML publishing address with a new one?"))) {
|
|
||||||
Notify.progress("Trying to change address...", true);
|
|
||||||
|
|
||||||
xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => {
|
|
||||||
if (reply) {
|
|
||||||
const new_link = reply.link;
|
|
||||||
const e = $('pub_opml_url');
|
|
||||||
|
|
||||||
if (new_link) {
|
|
||||||
e.href = new_link;
|
|
||||||
e.innerHTML = new_link;
|
|
||||||
|
|
||||||
new Effect.Highlight(e);
|
|
||||||
|
|
||||||
Notify.close();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Notify.error("Could not change feed URL.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function gotoExportOpml(filename, settings) {
|
|
||||||
const tmp = settings ? 1 : 0;
|
|
||||||
document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue