Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.html.viewTools
<<Changes: <<3/6/02; 5:28:49 PM by JES <<If the Tool's info table contains a non-empty localUrl, use that url for the link on the Tool's name. <<1/6/02; 4:25:58 AM by JES <<Added table css classes. <<12/3/01; 5:20:24 PM by JES <<Changed the format of a Tool's cell in the table to: myTool v1.0; description text blah blah blah. Author: Jake Savin; Released: 12/3/01. [globe] <<Moved the Submit button to underneath the table. <<12/3/01; 1:43:38 PM by JES <<Cleaned up initialization of default values. Don't include "(no description available)" if the Tool doesn't have description text. Don't get html for the help icon -- it's never used. <<11/26/01; 11:17:38 PM by JES <<Don't install Tools' website files in the www folder here. Now this happens in radio.callbacks.installTool. <<11/26/01; 2:08:46 AM by JES <<When installing Tools which have a website that doesn't have its own #template, loop over the Tool's website table, and write its pages out to the www folder, in the Tool's sub-folder, to integrate the Tool's website with Radio's desktop website. <<When installing a Tool's website in the www folder, delete its entry in the website framework responder's docTree, so that the Radio responder will handle the Tool's hits. <<11/25/01; 6:09:44 PM by JES <<Re-formatted the table to look like the other tables in the Radio 7.1 desktop website. The webserver log and events log and news pages are the models. <<11/24/01; 3:00:10 PM by DW <<Linked into help system. <<11/1/01; 2:30:35 PM by JES <<Fixed misspelling in explanatory text: ckeckbox -> checkbox. <<10/23/01; 11:30:45 AM by PBS <<Refresh the menu when uninstalling a tool by calling menus.buildMenuBar. This prevents a crash. <<10/19/01; 3:12:34 PM by PBS <<If a Tool gdb is moved on a Macintosh, the path in user.tools.databases may change with it, since filespecs follow files around on Macs. So when checking if a Tool can be enabled, check to see that it's actually in the Tools folder, since it may have been moved. <<Frontier.tools.init () local (htmltext, indentlevel=0); on add (s) { htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"}; local (pta = html.getpagetableaddress ()); <<workspace.pt = pta^; edit (@workspace.pt) local (pc = file.getPathChar ()); <<local (helpIcon = radio.userInterface.helpIcon ()) local (globeIcon = radio.images.systemImageRef ("qbullet/remote", flFileUrl:pta^.radioResponder.flSameMachine)); pta^.title = radio.string.getlocalizedstring ("tools.title"); local (checkboxval = "x"); if pta^.method == "POST" { local (adrargs = @pta^.radioResponder.postArgs); if defined (adrargs^.submit) and adrargs^.submit == "Submit" { local (adrtable); for adrtable in @user.tools.databases { //loop over all Tools, and enable/disable pased on args local (name = nameOf (adrtable^)); local (f = adrtable^.path); if defined (adrargs^.[name]) { //enabled tool if defined ([f]) { //already enabled continue}; if file.exists (f) { //reality check filemenu.open (f, true); Frontier.tools.enable (f, true); Frontier.tools.install (f)}} <<bundle //possibly install pages from the tool's website into the filesystem <<local (cleanName = Frontier.tools.cleanToolName (name)) <<local (adrsite = @[f].[cleanName + "Website"]) <<if defined (adrsite^) <<if not defined (adrsite^.["#template"]) <<local (folder = user.radio.prefs.wwwfolder + cleanName + pc) <<bundle //write a #upstream.xml to the folder, whose type is none <<local (f = folder + radio.data.fileNames.upstreamFileName) <<file.sureFilePath (f) <<file.writeWholeFile (f, "<upstream type=\"none\"/>") <<local (adritem) <<on installItem (adritem, folder) <<local (itemname = nameOf (adritem^)) <<if not (itemname beginsWith "#") //a page or a table <<local (filetext, extension = ".txt") <<case typeOf (adritem^) <<tableType <<local (subfolder = folder + itemname + pc) <<local (adrsubitem) <<for adrsubitem in adritem <<installItem (adrsubitem, subfolder) <<continue <<scriptType //make a wrapper file <<local (adrpage = string.popFileFromAddress (adritem)) <<filetext = "<%" + adrpage + " ()%>" <<outlineType //convert to opml <<filetext = op.outlineToXml (adritem) <<extension = ".opml" <<else //coerce to string, and write the file <<filetext = string (adritem^) <<local (f = folder + itemname + extension) <<file.sureFilePath (f) <<file.writeWholeFile (f, filetext) <<for adritem in adrsite //install the tool's website pages into the www folder <<installItem (adritem, folder) <<bundle //delete the entry for the Tool's website in the websiteFramework responder's docTree, so the radio responder will handle the hits <<if defined (user.webserver.responders.websiteFramework.data.docTree.[cleanName]) <<delete (@user.webserver.responders.websiteFramework.data.docTree.[cleanName]) else { //disabled tool if defined ([f]) { fileMenu.saveMyRoot (@[f]); bundle { //possibly delete the tool's pages from the filesystem local (cleanName = Frontier.tools.cleanToolName (name)); local (adrsite = @[f].[cleanName + "Website"]); if defined (adrsite^) { local (folder = user.radio.prefs.wwwfolder + cleanname + pc); if file.exists (folder) { if file.isFolder (folder) { try { //avoid file permissions errors file.deleteFolder (folder)}}}}}; Frontier.tools.uninstall (f); menus.buildMenuBar (); //PBS 10/23/01: refresh the menu Frontier.tools.enable (f, false); local (oldTarget = target.set (@[f])); fileMenu.close (); try {target.set (oldtarget)}}}}}}; bundle { //explanatory text add (radio.string.getlocalizedstring ("tools.intro") + " " + radio.userInterface.helpLink ("The Tools command") + "<p>")}; bundle { //start the form add ("<form method=\"POST\">"); indentlevel++}; bundle { //wrapper table for nice borders add ("<table class=\"dwsFrameTable\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr bgcolor=\"" + radio.data.htmlColors.framecolor + "\"><td>"); indentlevel++}; bundle { //start the table add ("<table class=\"dwsTable\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">"); indentlevel++}; <<bundle //add header <<add ("<tr bgcolor=\"" + radio.data.htmlColors.cellbgcolor + "\"><td> </td><td><b>Name</b></td><td><b>Author</b></td><td align=\"right\"><b>Version</b></td><td align=\"right\"><b>Released</b></td><td align=\"center\"><b>Docs</b></td></tr>") bundle { //add the Tools local (adrtable); for adrtable in @user.tools.databases { local (name = nameOf (adrtable^)); local (adrdata = @user.tools.databases.[name]); local (f = adrdata^.path); local (toolsFolder = Frontier.tools.getToolsFolderPath ()); if not file.exists (f) { continue}; bundle { //PBS 10/19/01: make sure it's actually in the Tools folder <<Mac filespecs may follow the Tool when it has been moved out of the Tools folder. local (folder = file.folderFromPath (f)); if string.lower (folder) != string.lower (toolsFolder) { //check to see if its parent is the Tools folder continue}}; local (adrtempdata = @system.temp.Frontier.tools.[frontier.tools.cleanToolName (name)]); if not defined (adrtempdata^) { new (tableType, adrtempdata)}; local (adrinfo = @adrtempdata^.info); local (flGetInfo = false); if not defined (adrtempdata^.lastModified) { adrtempdata^.lastModified = date (0)}; if adrtempdata^.lastModified != file.modified (f) { flGetInfo = true}; if flGetInfo { //try to get the info out of the Tool local (flCloseFile = false); if not defined ([f]) { //try to open the database try { //avoid possible permissions problems on MacOS X if system.environment.isMac { //set type and creator if needed if not (file.type (f) == 'TABL') { file.setType (f, 'TABL'); file.setCreator (f, 'LAND')}}; fileMenu.open (f, true); flCloseFile = true}}; local (adrinfotable = @[name + "Info"]); if defined (adrinfotable^) { //copy the info to the temp.Frontier.tools table adrinfo^ = adrinfotable^}; if flCloseFile { //close the file if it had been opened filemenu.close (f)}; adrtempdata^.lastModified = file.modified (f)}; add ("<tr>"); indentlevel++; bundle { //add checkbox local (check = checkboxval); if adrdata^.flInstalled and defined ([f]) { check = check + " checked"}; add ("<td class=\"dwsTableCell\" bgcolor=\"" + radio.data.htmlColors.cellbgcolor + "\" valign=\"top\"><input type=\"checkbox\" name=\"" + radio.html.translateToEntities (name) + "\" value=" + check + "></td>")}; local (displayName = name, homePageUrl = "", author = "", authorEmail = "", version = "", releaseDate = "", description = "", localUrl = ""); if defined (adrinfo^) { if defined (adrinfo^.name) { displayName = adrinfo^.name} else { displayName = name}; if defined (adrinfo^.homePageUrl) { homePageUrl = adrinfo^.homePageUrl} else { homePageUrl = ""}; if defined (adrinfo^.author) { author = adrinfo^.author} else { author = ""}; if defined (adrinfo^.authorEmail) { authorEmail = adrinfo^.authorEmail; if author == "" { author = authorEmail}} else { authorEmail = ""}; if defined (adrinfo^.version) { version = adrinfo^.version} else { version = ""}; if defined (adrinfo^.releaseDate) { releaseDate = date.shortString (adrinfo^.releaseDate)} else { releaseDate = ""}; if defined (adrinfo^.description) { description = string (adrinfo^.description)} else { description = ""}; if defined (adrinfo^.localUrl) { localUrl = adrinfo^.localUrl}}; bundle { //add the tool info displayName = "<b>" + displayName + "</b>"; local (nameLink = displayName, docslink = "", authorLink = author); if defined (system.temp.Frontier.tools.[name].url) { //make the Tool's name a link to the Tool's page nameLink = html.getLink (displayName, system.temp.Frontier.tools.[name].url)}; if localUrl != "" { nameLink = html.getLink (displayName, localUrl)}; if version != "" { //add the version next to the name nameLink = nameLink + " v" + version}; if homePageUrl != "" { //link the globe to the home page docslink = " " + html.getLink (globeicon, homePageUrl)}; if authorEmail != "" { //mailto link on the author name authorLink = html.getLink (author, "mailto:" + authorEmail)}; bundle { //add the author and release date to the description if authorLink != "" { description = description + " Author: " + authorLink; if releaseDate == "" { description = description + "."} else { description = description + "; "}}; if releaseDate != "" { description = description + " Released: " + releaseDate + "."}}; local (s = nameLink); if description != "" { //add the description s = s + ": " + description}; s = s + docsLink; add ("<td class=\"dwsTableCell\" bgcolor=\"" + radio.data.htmlColors.cellbgcolor + "\">"); indentlevel++; add ("<div>" + s + "</div>"); add ("</td>"); indentlevel--}; <<bundle //add the tool info <<local (nameLink = displayName, authorLink = author, helpLink = "") <<if defined ([name + "Website"]) <<nameLink = html.getLink (displayName, "http://127.0.0.1:5335/" + name + "/") <<if homePageUrl != "" //link the question-mark to the home page <<helpLink = html.getLink (helpIcon, homePageUrl) <<add ("<td valign=\"top\"><font size=\"-1\">" + nameLink + "</font></td>") <<if authorEmail != "" //mailto link on the author name <<authorLink = html.getLink (author, "mailto:" + authorEmail) <<add ("<td valign=\"top\"><font size=\"-1\">" + authorLink + "</font></td>") <<add ("<td align=\"right\" valign=\"top\"><font size=\"-1\">" + version + "</font></td>") <<add ("<td align=\"right\" valign=\"top\"><font size=\"-1\">" + releaseDate + "</font></td>") <<add ("<td align=\"center\" valign=\"top\">" + helpLink + "</td>") add ("</tr>"); indentlevel--}}; add ("</table>"); indentlevel--; add ("</td></tr>"); bundle { //submit button add ("<tr><td align=\"right\" bgcolor=\"" + radio.data.htmlColors.cellbgcolor + "\" style=\"padding-left:9px\"><br><input type=\"submit\" name=\"submit\" value=\"" + radio.string.getlocalizedstring ("tools.submitButton") + "\"></td></tr>")}; add ("</table>"); indentlevel--; add ("</form>"); 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.