Tuesday, August 18, 2009 at 7:54 PM.

howtoSuite.saveDocument

on saveDocument (adroutline, flClosing) {
	<<Changes
		<<8/4/08; 2:43:04 PM by DW
			<<Fix a bug that caused the View command not to work properly.
		<<8/1/08; 10:42:28 AM by DW
			<<Set a window attribute named "lastSaved" as respected by Frontier.tools.windowTypes.isWindowDirty.
		<<7/31/08; 12:23:19 PM by DW
			<<Created.
	local (username = user.identica.prefs.username, password = user.identica.prefs.password);
	local (opmltext = op.outlinetoxml (adroutline), htmltext, path, flprofile = false);
	window.attributes.getone ("outlineDocumentPath", @path, adroutline);
	bundle { //generate htmltext
		local (pagetable, tc = clock.ticks ());
		new (tabletype, @pagetable);
		pagetable.howToPath = path;
		<<http://frontier.userland.com/stories/storyReader$1033
		howtoWebsite.["#ftpSite"].method = "odb";
		howtoWebsite.["#ftpSite"].odbAddress = @system.temp.howTo.renderedText;
		table.assign (@howtoWebsite.page, howtoSuite.renderOutline (adroutline, @pagetable.title));
		bundle { //set pagetable.pubDate
			local (pubDate = clock.now ());
			if window.attributes.getone ("whenFirstSaveOnServer", @pubDate, adroutline) {
				pubDate = date (pubDate)}; //convert from GMT to local time
			pagetable.pubDate = date.longstring (pubdate) + ", " + date.timestring (pubdate) + "."};
		if flprofile {
			script.startprofile (true)};
		html.buildonepage (@howtoWebsite.page, @pagetable);
		if flprofile {
			script.stopprofile (@scratchpad.profiledata)};
		htmltext = string (system.temp.howTo.renderedText.["page.html"]);
		user.howto.stats.ctSecsLastPageBuild = (double (clock.ticks ()) - double (tc)) / 60.0};
	local (atts = [user.howto.prefs.client.serverUrl].howto.saveOutline (username, password, opmltext, htmltext, path));
	bundle { //mirror locally, if enabled
		if user.howto.prefs.client.flLocalMirror {
			local (f);
			if path beginswith "/" {
				path = string.delete (path, 1, 1)};
			f = user.howto.prefs.client.localMirrorFolder + string.replaceall (path, "/", file.getpathchar ());
			file.surefilepath (f);
			file.writewholefile (f, opmltext)}};
	window.attributes.setone ("outlineDocumentUrl", atts.opmlUrl, adroutline);
	window.attributes.setone ("htmlDocumentUrl", atts.htmlUrl, adroutline);
	window.attributes.setone ("lastSaved", clock.now (), adroutline);
	speaker.ouch ()};
bundle { //test code
	saveDocument (window.frontmost (), false)}



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.