Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.html.publishStaticPage
on publishStaticPage (fileBeingRendered) { <<Changes <<10/15/01; 1:44:31 AM by JES <<Loosened the semaphore -- now lock a semaphore on this+fileBeingRendered, so that you can publish more than one page at a time. <<10/11/01; 2:23:10 PM by JES <<New verb. Publishes a static page to its corresponding sub-folder of the www/system/upstream/ folder. <<10/17/01; 3:31:36 PM by PBS <<Set and delete the page table address. radio.webserver.setTemplate needs the page table address. semaphore.lock (this + ":" + fileBeingRendered, 3600); local (f, pc = file.getpathchar (), fileMimeType = radio.webserver.getFileMimeType (fileBeingRendered)); bundle { //set f local (relpath = string.delete (fileBeingRendered, 1, sizeOf (user.radio.prefs.wwwFolder))); f = user.radio.prefs.upstream.folder + relPath; if file.fileFromPath (f) contains "." { f = string.popSuffix (f, "."); f = f + ".html"}; file.sureFilePath (f)}; local (atts); radio.webServer.gatherAttributes (user.radio.prefs.wwwfolder, @atts); local (filetext, sizestring = ""); bundle { //set filetext filetext = string (file.readwholefile (fileBeingRendered)); if fileMimeType == "text/x-opml" { op.xmlToOutline (filetext, @filetext)}; sizestring = string.countwords (string (filetext)) + " words"}; local (htmltext, pagetable); bundle { //render the page into htmltext local (oldPta); try {oldPta = html.getPageTableAddress ()}; local (adrsite = @radio.data.website, adrpage = @radio.data.website.default); if fileMimeType == "text/x-opml" { //create an outline object table.assign (adrpage, filetext)} //it's an outline else { //create a wptext object wp.newtextobject (filetext, adrpage)}; new (tabletype, @pagetable); new (tabletype, @pagetable.radioResponder); pagetable.radioResponder.fileBeingRendered = fileBeingRendered; radio.file.getFileAttributes (fileBeingRendered, @pagetable.radioResponder.adrFileTable); pagetable.radioResponder.atts = atts; pagetable.radioResponder.flStaticRendering = true; pagetable.radioResponder.flSameMachine = false; pagetable.radioResponder.flImagePatching = true; pagetable.radioResponder.adrblog = radio.weblog.init (); html.setPageTableAddress (@pageTable); //PBS 10/17/01: radio.webserver.settemplate needs this radio.webserver.settemplate (@atts, false, adrsite); local (fname = file.filefrompath (f)); pagetable.title = fname; htmltext = html.buildObject (adrpage, @pagetable); if oldPta != nil { html.setPageTableAddress (oldPta)} else { html.deletePageTableAddress ()}}; //PBS 10/17/01: delete dangling ptas; they can cause crashes local (uri); bundle { //calculate uri <<uri = string.replaceAll (string.delete (fileBeingRendered, 1, sizeOf (user.radio.prefs.wwwfolder)), pc, "/") local (nomad = file.folderFromPath (f)); loop { //deal with nested upstream specs if nomad == user.radio.prefs.upstream.folder { break}; if nomad == user.radio.prefs.wwwFolder { break}; if string.countFields (nomad, pc) == 1 { break}; local (specpath = nomad + radio.data.fileNames.upstreamFileName); if file.exists (specpath) { //pop off leading folders uri = string.replaceAll (string.delete (f, 1, sizeOf (nomad)), pc, "/"); break} else { nomad = file.folderFromPath (nomad)}}}; bundle { //write out the image files, patch image URLs if defined (pagetable.radioResponder.imagefiles) { local (imagefolder = user.radio.prefs.wwwFolder + "images" + pc); local (imagefolderurl); bundle { //get imagefolderurl imagefolderurl = string.replaceAll (string.delete (imagefolder, 1, sizeOf (user.radio.prefs.wwwfolder)), pc, "/"); loop { //pop off matching folder names local (pathpart = string.nthField (imagefolderurl, "/", 1)); if pathpart == string.nthField (uri, "/", 1) { imagefolderurl = string.delete (imagefolderurl, 1, sizeOf (pathpart) + 1); uri = string.delete (uri, 1, sizeOf (pathpart) + 1)} else { break}}; local (reldepth = string.countFields (uri, '/') - 1); if reldepth > 0 { imagefolderurl = string.filledString ("../", reldepth) + imagefolderurl}}; local (adrimagefile); for adrimagefile in @pagetable.radioResponder.imagefiles { local (fsource = user.radio.prefs.wwwfolder + nameof (adrimagefile^)); local (fdest = imagefolder + file.filefrompath (fsource)); file.surefilepath (fdest); local (flcopy = true); if file.exists (fdest) { if file.modified (fsource) == file.modified (fdest) { flcopy = false}}; if flcopy { file.copy (fsource, fdest); file.setmodified (fdest, file.modified (fsource)); file.setcreated (fdest, file.created (fsource))}; bundle { //patch the HTML text local (searchfor = "=\"" + adrimagefile^ + "\""); //the url is the value local (replacewith = "=\"" + imagefolderurl + file.filefrompath (fsource) + "\""); htmltext = string.replaceall (htmltext, searchfor, replacewith, false)}}}}; bundle { //patch link URLs local (staticUrl = "", dynamicUrl = ""); bundle { //get dynamicUrl dynamicUrl = "http://" + tcp.dns.getMyDottedId (); if string (user.inetd.config.http.port) != "80" { dynamicUrl = dynamicUrl + ":" + user.inetd.config.http.port}; dynamicUrl = dynamicUrl + "/"}; htmltext = radio.html.patchLinks (htmltext, staticUrl, dynamicUrl, uri)}; file.writewholefile (f, htmltext); //write out the HTML file semaphore.unlock (this + ":" + fileBeingRendered); return (f)} <<bundle //test code <<local (pt); new (tableType, @pt) <<html.setPageTableAddress (@pt) <<publishStaticPage ("Backup:Radio UserLand:www:sh6:Stories:2001:10:11:usmanFarman.opml") <<html.deletePageTableAddress ()
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.