Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.file.newStoryFile
on newStoryFile (folder, title, text, flOpml = true) { <<Changes <<4/6/02; 2:49:02 PM by DW <<If feature is enabled, create a shortcut for the new story. <<1/31/02; 10:49:42 PM by JES <<On MacOS, make sure that filenames are truncated such that the extension can be a four-character extension, not just three. <<1/28/02; 6:26:50 PM by JES <<Convert filenames to 7-bit strings. <<1/14/02; 4:01:50 PM by JES <<On MacOS, limit filename length to 31 characters. <<12/20/01; 1:05:27 AM by JES <<Use file.writeTextFile instead of file.writeWholeFile to write the new story to disk. <<10/31/01; 3:39:55 PM by JES <<Return the relative path as determined by a call to radio.file.getRelativePath. local (now = clock.now (), day, month, year, hour, minute, second); date.get (now, @day, @month, @year, @hour, @minute, @second); local (extension); if flOpml { extension = ".opml"} else { extension = ".txt"}; local (fname = string.dropnonalphas (string.innercasename (radio.string.convertTo7Bit (title)))); if system.environment.isMac { if sizeOf (fname) > (31 - sizeOf (".html")) { fname = string.mid (fname, 1, (31 - sizeOf (".html")) )}}; fname = fname + extension; month = string.padwithzeros (month, 2); day = string.padwithzeros (day, 2); local (pc = file.getpathchar ()); local (f = folder + year + pc + month + pc + day + pc + fname); file.surefilepath (f); local (filetext = "#title \"" + title + "\"\r\n#postTime \"" + now + "\"\r\n" + text); if flOpml { local (lo); op.newoutlineobject (filetext, @lo); filetext = op.outlinetoxml (@lo)}; file.writeTextFile (f, filetext); local (relativepath = radio.file.getRelativePath (f)); bundle { //add shortcut if enabled local (adrdata = radio.weblog.init ()); if adrdata^.shortcuts.prefs.flShortcutForStories { local (extension = "html"); bundle { //set extension, patterned after code in radio.upstream.getUpstreamText local (atts); radio.webServer.gatherAttributes (f, @atts); if defined (atts.renderedFileExtension) { extension = atts.renderedFileExtension; if extension beginsWith "." { //it's expected not to extension = string.delete (extension, 1, 1)}}}; local (url = radio.weblog.getUrl (adrdata) + string.popSuffix (relativepath) + "." + extension); radio.shortcuts.addStory (title, url)}}; return (relativepath)} <<bundle //test code <<local (folder = "C:\\Program Files\\Radio UserLand\\www\\stories\\") <<local (rp = newstoryfile (folder, "Test story", string.filledstring ("123456789 ", 100), flOpml:false)) <<webbrowser.openurl ("http://127.0.0.1:81/stories/" + rp)
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.