Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.server.saveOutlineFromUrl

on saveOutlineFromUrl (username, url, opmltext) {
	<<Changes
		<<8/1/10; 5:58:30 PM by DW
			<<Run the text through the replaceTable to change special characters to their proper XML equivalent.
		<<7/16/10; 8:08:11 PM by DW
			<<Added logging.
		<<6/27/10; 9:34:08 AM by DW
			<<See comment at the head of scripting2Suite.server.getOutlineFromUrl.
		<<6/12/10; 7:06:11 AM by DW
			<<When saving the blogroll or a template, rebuild the home page. When saving the stylesheet upload it immediately, don't wait for synching.
		<<6/11/10; 10:32:03 PM by DW
			<<Created. 
	local (adrdata = scripting2suite.inituser (username), startticks = clock.ticks (), type, adrstory, flbuild = false);
	local (lowerurl = string.lower (url), now = clock.now ());
	bundle { //run opmltext through the replaceTable, 8/1/10 by DW
		opmltext = string.multiplereplaceall (opmltext, @xml.rss.data.replaceTable, false)};
	if lowerurl beginswith "http://" {
		scripting2Suite.server.urlToStory (username, url, @type, @adrstory);
		if type == "stories" {
			adrstory^.opmltext = opmltext;
			xml.compile (opmltext, @adrstory^.xstruct);
			if defined (adrstory^.textCache) {
				delete (@adrstory^.textCache)};
			bundle { //bump counter
				if not defined (adrstory^.ctSaveFromUrls) {
					adrstory^.ctSaveFromUrls = 0};
				adrstory^.ctSaveFromUrls++;
				adrstory^.whenLastSaveFromUrl = now}}}
	else {
		case lowerurl {
			<<"stories"
				<<adrstory^.opmltext = opmltext
				<<xml.compile (opmltext, @adrstory^.xstruct)
				<<if defined (adrstory^.textCache)
					<<delete (@adrstory^.textCache)
				<<bundle //bump counter
					<<if not defined (adrstory^.ctSaveFromUrls)
						<<adrstory^.ctSaveFromUrls = 0
					<<adrstory^.ctSaveFromUrls++
					<<adrstory^.whenLastSaveFromUrl = now
			"blogroll" {
				local (adrblogroll = @adrdata^.prefs.blogroll);
				op.xmltooutline (opmltext, adrblogroll);
				adrdata^.stats.urlBlogroll = scripting2Suite.server.saveSpecialOutline (username, adrblogroll);
				flbuild = true};
			"hometemplate" {
				local (adroutline = @adrdata^.prefs.homeTemplate);
				op.xmltooutline (opmltext, adroutline);
				if adrdata^.prefs.flShareTemplates {
					adrdata^.stats.urlHomeTemplate = scripting2Suite.server.saveSpecialOutline (username, adroutline, flText:true)};
				flbuild = true};
			"storytemplate" {
				local (adroutline = @adrdata^.prefs.storyTemplate);
				op.xmltooutline (opmltext, adroutline);
				if adrdata^.prefs.flShareTemplates {
					adrdata^.stats.urlStoryTemplate = scripting2Suite.server.saveSpecialOutline (username, adroutline, flText:true)};
				flbuild = true};
			"stylesheet" {
				op.xmltooutline (opmltext, @adrdata^.prefs.stylesheet);
				thread.callscript (@scripting2Suite.server.saveStylesheet, {username, true})};
			"instantoutline" {
				adrdata^.prefs.instantoutline.opmltext = opmltext;
				adrdata^.prefs.instantoutline.ctsaves++;
				adrdata^.prefs.instantoutline.whenLastSave = now;
				bundle { //push a realtime update
					local (htmltext = "User \"" + username + "\" updated his or her instant outline.");
					scripting2Suite.server.pushRealtimeUpdate (htmltext, "instantOutline", username, opmltext)}}};
		bundle { //save opmltext in folder structure
			local (folder = adrdata^.prefs.opmlfolder + url + file.getpathchar () + file.getdatepath (theDate:now), f);
			bundle { //set f
				local (day, month, year, hour, minute, second);
				date.get (now, @day, @month, @year, @hour, @minute, @second);
				hour = string.padwithzeros (hour, 2);
				minute = string.padwithzeros (minute, 2);
				second = string.padwithzeros (second, 2);
				f = folder + hour + "-" + minute + "-" + second + ".opml"};
			file.surefilepath (f);
			file.writewholefile (f, opmltext)};
		bundle { //logging
			local (htmltext = "Updated the " + url + " for user \"" + username + ".\"");
			scripting2Suite.server.addToLog (scripting2Info.name, "Save", htmltext, startticks)}};
	if flbuild {
		thread.callscript (@scripting2Suite.server.buildHomePage, {username})}} //6/12/10 by DW



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.