Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.html.changeCommunityServer
<<Changes
<<5/9/02; 11:22:10 AM by JES
<<When setting the rpcPath for the new community server, make sure it has a leading '/' character. When connecting to a new server, also set up user.radio.prefs.rssCloud and user.radio.prefs.webBugSimulator, just like we do in radio.thread.agents.installer, when setting up based on the contents of a defaultCloud.xml file.
<<3/11/02; 6:50:13 PM by JES
<<Clear the calendar and navigatorLinks caches after successfully registering with the new server.
<<3/11/02; 5:47:09 PM by JES
<<Call radio.cloud.registerWithServer instead of radio.registerWithServer. Same code, new location.
<<3/10/02; 11:20:09 PM by JS
<<Call radio.getInitialResources and radio.registerWithServer instead of rdio.bootstrap, to register with the server.
<<3/7/02; 2:56:51 PM by JES
<<Created. Render a page which lets a Radio user switch to a new community server.
<<When the form on this page is submitted, two things happen:
<<1) Radio gets the server's initial resources -- radioCommunityServer.getInitialResources.
<<2) Radio registers itself as a new user on that server -- xmlStorageSystem.register.
local (pta = html.getPageTableAddress ());
pta^.title = radio.string.getLocalizedString ("changeCommunityServer.title");
local (htmltext, indentlevel=0);
on add (s) {
htmltext = htmltext + (string.filledstring ("\t", indentlevel) + s + "\r\n");};
local (flError = false, errorMessage = "", flConfirmPage = false);
if pta^.method == "POST" {
<<workspace.pt = pta^; edit (@workspace.pt)
local (adrargs = @pta^.radioResponder.postArgs);
if defined (adrargs^.changeCommunityServer) {
local (password = adrargs^.["system.temp.radio.misc.newCommunityServerPassword"] );
local (repeatPassword = adrargs^.["system.temp.radio.misc.newCommunityServerPasswordRepeat"] );
bundle { //check that the password is ok, and that it matches the repeat password
if sizeOf (password) < 4 {
errorMessage = radio.string.getlocalizedstring ("changeCommunityServer.shortPasswordError");
flError = true};
if not flError {
if password != repeatPassword {
errorMessage = radio.string.getlocalizedstring ("changeCommunityServer.passwordMismatchError");
flError = true}};
temp.radio.misc.newCommunityServerPassword = "";
temp.radio.misc.newCommunityServerPasswordRepeat = ""};
if not flError { //get the server info from postArgs, and do the bootstrap
local (urlparts);
try { //check for malformed URLs
local (serverUrl = adrargs^.["system.temp.radio.misc.newCommunityServer"]);
if not (serverUrl beginsWith "http://") {
temp.radio.misc.newCommunityServer = "http://" + temp.radio.misc.newCommunityServer};
urlparts = string.urlSplit (serverUrl)}
else { //error
errorMessage = radio.string.getLocalizedString ("changeCommunityServer.badUrlError");
flError = true};
if not flError { //do the bootstrap
local (server = urlparts[2], port = 80);
if server contains ":" { //split out the port
port = number (string.nthField (server, ":", 2));
server = string.nthField (server, ":", 1)};
local (rpcPath = "/" + urlParts[3]);
local (originalUsernum, originalCloudData, originalPassword, originalRssCloud, originalWebBugData);
bundle { //record the current settings -- in case there's an error, we can restore them
originalUsernum = 0;
if defined (user.radio.prefs.usernum) {
originalUsernum = user.radio.prefs.usernum};
originalCloudData = user.radio.prefs.defaultCloud;
originalPassword = user.radio.prefs.passwords.default;
originalRssCloud = user.radio.prefs.rssCloud;
originalWebBugData = user.radio.prefs.webBugSimulator};
bundle { //set up items in user.radio.prefs: defaultCloud, rssCloud, webBugSimulator, and ...passwords.default
user.radio.prefs.defaultCloud.server = server;
user.radio.prefs.defaultCloud.port = port;
user.radio.prefs.defaultCloud.rpcPath = rpcPath;
user.radio.prefs.defaultCloud.protocol = "xml-rpc";
user.radio.prefs.rssCloud.server = server;
user.radio.prefs.rssCloud.port = port;
user.radio.prefs.rssCloud.rpcPath = rpcPath;
user.radio.prefs.rssCloud.protocol = "xml-rpc";
user.radio.prefs.webBugSimulator.server = server;
user.radio.prefs.webBugSimulator.port = port;
user.radio.prefs.webBugSimulator.rpcPath = rpcPath;
user.radio.prefs.passwords.default = password};
try { //trap network errors
if defined (user.radio.prefs.usernum) { //delete it so the bootstrap will actually register
delete (@user.radio.prefs.usernum)};
radio.cloud.registerWithServer (password, flNewUser:true, flGetInitialResources:true); //true, to register a new user
bundle { //clear the cached home folder URL
local (adrfolder = @user.radio.settings.files.[user.radio.prefs.upstream.folder]);
if defined (adrfolder^) {
if defined (adrfolder^.upstream) {
adrfolder^.upstream.url = ""}}};
bundle { //clear cached calendars and navigation links
local (adrdata = radio.weblog.init ());
if defined (adrdata^.cache) {
new (tableType, @adrdata^.cache.calendar)};
new (tableType, @system.temp.radio.navigatorLinksCache)};
flConfirmPage = true}
else { //network or other error
errorMessage = tryError;
flError = true};
if flError { //restore original settings
if originalUsernum == 0 {
delete (@user.radio.prefs.usernum)}
else {
user.radio.prefs.usernum = originalUsernum};
user.radio.prefs.defaultCloud = originalCloudData;
user.radio.prefs.passwords.default = originalPassword;
user.radio.prefs.rssCloud = originalRssCloud;
user.radio.prefs.webBugSimulator = originalWebBugData}}}};
if defined (adrargs^.["continue"]) { //redirect to home page
radio.webserver.redirect (radio.data.systemUrls.homePage);
return ("")}};
bundle { //get default values
temp.radio.misc.newCommunityServer = "http://";
if defined (pta^.radioResponder.getArgs.rcs) {
temp.radio.misc.newCommunityServer = pta^.radioResponder.getArgs.rcs};
temp.radio.misc.newCommunityServerPassword = "";
temp.radio.misc.newCommunityServerPasswordRepeat = ""};
if flConfirmPage { //render confirmation page
local (t); new (tableType, @t);
t.usernum = user.radio.prefs.usernum;
t.websiteUrl = radio.weblog.getUrl ();
add (radio.string.getLocalizedString ("changeCommunityServer.welcomeMessage", @t));
bundle { //add the Continue button
add ("<form method=\"POST\">");
add ("<input type=\"submit\" name=\"continue\" value=\"" + radio.string.getlocalizedstring ("setupRadio.continueButton") + "\">");
add ("</form>")}}
else { //render the form
bundle { //intro text, possibly error message
add ("<p>" + radio.string.getlocalizedstring ("changeCommunityServer.intro") + "</p>");
if flError {
add ("<p><font color=\"red\">" + errorMessage + "</font></p>")}};
bundle { //start the form and table
add ("<form method=\"POST\">"); indentlevel++;
add ("<table cellpadding=\"5\" callspacing=\"0\" border=\"0\">"); indentlevel++};
bundle { //add the fields
add (radio.prefs.stringPref ("Server URL", @temp.radio.misc.newCommunityServer, size:80, maxlength:255));
add (radio.prefs.stringPref ("Password", @temp.radio.misc.newCommunityServerPassword, "password", 25, 255, flCheckRepeatedPassword:false));
add (radio.prefs.stringPref ("Repeat Password", @temp.radio.misc.newCommunityServerPasswordRepeat, "password", 25, 255, flCheckRepeatedPassword:false))};
bundle { //submit button
add ("<tr><td> </td><td style=\"padding-top:14px\"><input type=\"submit\" name=\"changeCommunityServer\" value=\"" + radio.string.getlocalizedstring ("changeCommunityServer.submitButton") + "\"></td></tr>")};
bundle { //close the table and form
add ("</table>"); indentlevel--;
add ("</form>"); indentlevel--}};
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.