Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.upstream.builtinDrivers.ftp.configPage
on configPage (adrfolder, adrspec) {
local (pta = html.getPageTableAddress ());
pta^.title = "Upstream Settings";
local (htmltext = "");
on add (s) {
htmltext = htmltext + s + "\r"};
local (adrdata = @temp.radio.upstreamSettingsForm); //temp storage for the prefs browser
new (tableType, adrdata);
bundle { //cleanup items in the pageTable for the prefs browser
if pta^.method == "POST" {
local (adrargs = @pta^.radioResponder.postArgs);
if defined (adrargs^.command) {
case adrargs^.command {
"postUpstreamSettings" { //clean up custom items in the post args
delete (@adrargs^.command);
table.rename (@adrargs^.passwordName, "temp.radio.upstreamSettingsForm.passwordName")};
"upstreamSettings" {
pta^.method = "GET"}}}}}; //tell the prefs browser not to treat this as a POST
if adrspec == nil { //get default settings
adrdata^.username = string.nthField (user.prefs.mailAddress, '@', 1);
adrdata^.passwordName = nameOf (user.radio.prefs.passwords[1]);
local (server = string.nthField (user.prefs.mailAddress, '@', 2));
while string.countFields (server, '.') > 2 {
server = server - (string.nthField (server, '.', 1) + ".")};
adrdata^.server = "ftp." + server;
adrdata^.path = "";
adrdata^.url = "http://www." + server + "/" + adrdata^.username + "/"}
else { //get settings from the cached spec
adrdata^.username = adrspec^.username;
adrdata^.passwordName = adrspec^.passwordName;
adrdata^.server = adrspec^.server;
adrdata^.path = adrspec^.path;
adrdata^.url = adrspec^.url};
local (folder = nameOf (adrfolder^), folderlink);
bundle { //build folderlink
local (parentfolder = file.folderfrompath (user.radio.prefs.wwwfolder));
local (foldername = string.replaceall (string.delete (folder, 1, sizeof (parentfolder)), file.getpathchar (), "/"));
local (folderpath = string.replaceall (string.delete (folder, 1, sizeof (user.radio.prefs.wwwfolder)), file.getpathchar (), "/"));
folderpath = string.replaceAll (folderpath, file.getPathChar (), "/");
folderlink = "<a href=\"/" + folderpath + "?folderView=1\">" + foldername + "</a>"};
htmltext = string.replace (radio.prefs.browser ("prefsWizardUpstreamFtp.opml"), "[[folder]]", folderlink);
if pta^.method == "POST" { //handle a post of the prefs form
local (adrargs = @pta^.radioResponder.postArgs);
bundle { //write out the #upstream.xml file
local (f = folder + radio.data.fileNames.upstreamFileName);
local (adrdriver = parentOf (this^));
with adrdata^ {
adrdriver^.saveUpstreamSpec (f, username, passwordName, server, path, url)}};
bundle { //try to connect to the server, report error messages
try {
with adrdata^ {
local (adrconnection = tcp.ftp.openConnection (server, username, user.radio.prefs.passwords.[passwordName], true));
tcp.ftp.closeConnection (adrconnection);
htmltext = "<p><font color=\"darkblue\">Upstream settings have been saved, and your account has been verified.</font></p>\r" + htmltext;
bundle { //invalidate the cache for all files in this folder
local (adr);
for adr in @user.radio.settings.files {
local (name = nameOf (adr^));
if name beginsWith folder {
adr^.modified = date (0);
adr^.upstream.url = "";
adr^.upstream.whenLastUploaded = date (0)}}}}}
else { //report the error
htmltext = "<p><font color=\"red\">Error connecting to the server: " + tryError + "</font></p>\r" + htmltext};
msg ("")}; //clear the About window
delete (adrdata)}; //delete temporary storage
return (htmltext)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.