Tuesday, April 12, 2011 at 1:05 AM.

scripting2Suite.initUser

on initUser (username, flCreateNewUser=false) {
	<<Changes
		<<4/11/11; 6:49:48 PM by DW
			<<Add buildRss user-level callback. (I'm saving my main feed to S3 to try to take pressure off my Windows server.)
		<<3/17/11; 9:43:58 AM by DW
			<<A nice default header image for new blogs.
		<<3/16/11; 4:09:44 PM by DW
			<<Most blogs are stored in a sub-directory of the main directory. However some, like Scripting News, are at the top level of the directory. flBlogInRootDirectory is the pref that determines if it's a special blog.
		<<3/8/11; 6:23:05 PM by DW
			<<Init S3 prefs, stats.
		<<7/25/10; 8:30:04 PM by DW
			<<Disqus comment default is true, group is "scripting2."
		<<7/18/10; 8:40:49 PM by DW
			<<Init callbacks table, starting with beforeBuildHomePage.
		<<7/4/10; 5:22:50 PM by DW
			<<Init prefs for Disqus comments.
		<<6/27/10; 7:52:48 AM by DW
			<<Init adrdata^.stats.flBuildToc to true. At the top of the next minute we'll set it false and rebuild the TOC. When the blog is newly created, it needs a fresh build. Also once a day (the calendar changes).
		<<6/12/10; 8:39:57 AM by DW
			<<Init adrdata^.stats.whenLastBuildAfterSave.
		<<6/9/10; 5:56:46 AM by DW
			<<Add optional parameter flCreateNewUser, default false.
		<<5/29/10; 8:02:07 AM by DW
			<<Created. 
	local (adrdata = scripting2Suite.init ());
	local (basefolder = adrdata^.prefs.basefolder);
	adrdata = @adrdata^.server.users.[username];
	if not defined (adrdata^) {
		if flCreateNewUser {
			new (tabletype, adrdata)}
		else {
			scripterror ("Can't process the request because there is no user named \"" + username + ".\"")}};
	if not defined (adrdata^.calendar) {
		new (tabletype, @adrdata^.calendar)};
	bundle { //callbacks, 7/18/10 by DW
		if not defined (adrdata^.callbacks) {
			new (tabletype, @adrdata^.callbacks)};
		if not defined (adrdata^.callbacks.beforeBuildHomePage) {
			new (tabletype, @adrdata^.callbacks.beforeBuildHomePage)};
		if not defined (adrdata^.callbacks.buildRss) { //4/11/11 by DW
			new (tabletype, @adrdata^.callbacks.buildRss)}};
	bundle { //prefs
		if not defined (adrdata^.prefs) {
			new (tabletype, @adrdata^.prefs)};
		if not defined (adrdata^.prefs.enabled) {
			adrdata^.prefs.enabled = true};
		if not defined (adrdata^.prefs.baseFolder) {
			local (pc = file.getpathchar ());
			adrdata^.prefs.baseFolder = basefolder + "server" + pc + username + pc};
		<<if not defined (adrdata^.prefs.baseUrl)
			<<adrdata^.prefs.baseUrl = ""
		if not defined (adrdata^.prefs.opmlFolder) {
			adrdata^.prefs.opmlFolder = adrdata^.prefs.basefolder + "opml" + file.getpathchar ()};
		if not defined (adrdata^.prefs.weblogName) {
			adrdata^.prefs.weblogName = ""};
		if not defined (adrdata^.prefs.homeTemplate) {
			adrdata^.prefs.homeTemplate = scripting2Suite.data.virgin.homeTemplate};
		if not defined (adrdata^.prefs.storyTemplate) {
			adrdata^.prefs.storyTemplate = scripting2Suite.data.virgin.storyTemplate};
		<<if not defined (adrdata^.prefs.aboutTheAuthor)
			<<adrdata^.prefs.aboutTheAuthor = ""
		if not defined (adrdata^.prefs.ownerName) {
			adrdata^.prefs.ownerName = ""};
		if not defined (adrdata^.prefs.ownerEmail) {
			adrdata^.prefs.ownerEmail = ""};
		if not defined (adrdata^.prefs.tagline) {
			adrdata^.prefs.tagline = ""};
		if not defined (adrdata^.prefs.password) {
			adrdata^.prefs.password = binary (string.getrandompassword (10))};
		<<if not defined (adrdata^.prefs.footerText)
			<<adrdata^.prefs.footerText = "© Copyright " + date.year () + " Your Name Here."
		<<if not defined (adrdata^.prefs.crumbTrailForStaticPage)
			<<adrdata^.prefs.crumbTrailForStaticPage = ""
		<<if not defined (adrdata^.prefs.ctDaysOnHomePage)
			<<adrdata^.prefs.ctDaysOnHomePage = 3
		if not defined (adrdata^.prefs.ctStoriesOnHomePage) {
			adrdata^.prefs.ctStoriesOnHomePage = 20};
		if not defined (adrdata^.prefs.headerImage) { //3/17/11 by DW
			adrdata^.prefs.headerImage = string (scripting2Suite.data.html.allBaking)};
		if not defined (adrdata^.prefs.stylesheet) { //6/6/10 by DW
			adrdata^.prefs.stylesheet = scripting2Suite.data.virgin.styleSheet};
		if not defined (adrdata^.prefs.glossary) { //6/6/10 by DW
			adrdata^.prefs.glossary = scripting2Suite.data.virgin.glossary};
		if not defined (adrdata^.prefs.flPgfPermalinks) { //6/6/10 by DW
			adrdata^.prefs.flPgfPermalinks = true};
		if not defined (adrdata^.prefs.timeZoneName) { //6/6/10 by DW
			adrdata^.prefs.timeZoneName = "GMT"};
		if not defined (adrdata^.prefs.timeZone) { //6/6/10 by DW
			adrdata^.prefs.timeZone = 0};
		if not defined (adrdata^.prefs.spacerWidth) { //6/6/10 by DW
			adrdata^.prefs.spacerWidth = 45};
		if not defined (adrdata^.prefs.spacerHeight) { //6/6/10 by DW
			adrdata^.prefs.spacerHeight = 45};
		if not defined (adrdata^.prefs.blogroll) { //6/27/10 by DW
			adrdata^.prefs.blogroll = scripting2Suite.data.virgin.blogroll};
		bundle { //instantOutline
			if defined (adrdata^.prefs.instantOutline) {
				if typeof (adrdata^.prefs.instantOutline) == outlinetype {
					delete (@adrdata^.prefs.instantOutline)}};
			if not defined (adrdata^.prefs.instantOutline) { //7/15/10 by DW
				new (tabletype, @adrdata^.prefs.instantOutline);
				adrdata^.prefs.instantOutline.opmltext = "";
				adrdata^.prefs.instantOutline.ctSaves = 0;
				adrdata^.prefs.instantOutline.whenLastSave = date (0)}};
		if not defined (adrdata^.prefs.archiveStartDate) { //6/8/10 by DW
			adrdata^.prefs.archiveStartDate = clock.now ()};
		if not defined (adrdata^.prefs.flShareTemplates) { //6/13/10 by DW
			adrdata^.prefs.flShareTemplates = true};
		if not defined (adrdata^.prefs.flDisqusComments) { //7/4/10 by DW
			adrdata^.prefs.flDisqusComments = true};
		if not defined (adrdata^.prefs.disqusShortName) { //7/4/10 by DW
			adrdata^.prefs.disqusShortName = "scripting2"};
		if not defined (adrdata^.prefs.flRealtimeUpdates) { //7/13/10 by DW
			adrdata^.prefs.flRealtimeUpdates = true};
		if not defined (adrdata^.prefs.flBlogInRootDirectory) { //3/16/11 by DW
			adrdata^.prefs.flBlogInRootDirectory = false};
		bundle { //ftp prefs -- if you want to override the defaults, 6/8/10 by DW
			if not defined (adrdata^.prefs.ftp) {
				new (tabletype, @adrdata^.prefs.ftp)};
			if not defined (adrdata^.prefs.ftp.enabled) {
				adrdata^.prefs.ftp.enabled = false};
			if not defined (adrdata^.prefs.ftp.path) {
				adrdata^.prefs.ftp.path = ""};
			if not defined (adrdata^.prefs.ftp.url) {
				adrdata^.prefs.ftp.url = ""}};
		bundle { //localFolder prefs -- if you want to override the defaults, 8/25/10 by DW
			if not defined (adrdata^.prefs.localFolder) {
				new (tabletype, @adrdata^.prefs.localFolder)};
			if not defined (adrdata^.prefs.localFolder.enabled) {
				adrdata^.prefs.localFolder.enabled = false};
			if not defined (adrdata^.prefs.localFolder.folder) {
				adrdata^.prefs.localFolder.folder = ""};
			if not defined (adrdata^.prefs.localFolder.url) {
				adrdata^.prefs.localFolder.url = ""}};
		<<bundle //headerImage
			<<if not defined (adrdata^.prefs.headerImage)
				<<new (tabletype, @adrdata^.prefs.headerImage)
			<<if not defined (adrdata^.prefs.headerImage.enabled)
				<<adrdata^.prefs.headerImage.enabled = false
			<<if not defined (adrdata^.prefs.headerImage.url)
				<<adrdata^.prefs.headerImage.url = ""
			<<if not defined (adrdata^.prefs.headerImage.alt)
				<<adrdata^.prefs.headerImage.alt = ""
			<<if not defined (adrdata^.prefs.headerImage.title)
				<<adrdata^.prefs.headerImage.title = ""
			<<if not defined (adrdata^.prefs.headerImage.context)
				<<adrdata^.prefs.headerImage.context = ""
			<<if not defined (adrdata^.prefs.headerImage.width)
				<<adrdata^.prefs.headerImage.width = 0
			<<if not defined (adrdata^.prefs.headerImage.height)
				<<adrdata^.prefs.headerImage.height = 0
			<<if not defined (adrdata^.prefs.headerImage.when)
				<<adrdata^.prefs.headerImage.when = date (0)
		<<bundle //search
			<<if not defined (adrdata^.prefs.search)
				<<new (tabletype, @adrdata^.prefs.search)
			<<if not defined (adrdata^.prefs.search.enabled)
				<<adrdata^.prefs.search.enabled = false
			<<if not defined (adrdata^.prefs.search.today)
				<<adrdata^.prefs.search.today = clock.now ()
			<<if not defined (adrdata^.prefs.search.ctcalls)
				<<adrdata^.prefs.search.ctcalls = 0
			<<if not defined (adrdata^.prefs.search.ctcallstoday)
				<<adrdata^.prefs.search.ctcallstoday = 0
			<<if not defined (adrdata^.prefs.search.cthistory)
				<<adrdata^.prefs.search.cthistory = 0
			<<if not defined (adrdata^.prefs.search.history)
				<<new (tabletype, @adrdata^.prefs.search.history)
		<<bundle //nightlyEmail
			<<if not defined (adrdata^.prefs.nightlyEmail)
				<<new (tabletype, @adrdata^.prefs.nightlyEmail)
			<<if not defined (adrdata^.prefs.nightlyEmail.enabled)
				<<adrdata^.prefs.nightlyEmail.enabled = true
			<<if not defined (adrdata^.prefs.nightlyEmail.hourToSend)
				<<adrdata^.prefs.nightlyEmail.hourToSend = 22
			<<if not defined (adrdata^.prefs.nightlyEmail.subscribers)
				<<new (tabletype, @adrdata^.prefs.nightlyEmail.subscribers)
			<<if not defined (adrdata^.prefs.nightlyEmail.whenLastSend)
				<<adrdata^.prefs.nightlyEmail.whenLastSend = date (0)
			<<if not defined (adrdata^.prefs.nightlyEmail.adrLastDay)
				<<adrdata^.prefs.nightlyEmail.adrLastDay = nil
			<<if not defined (adrdata^.prefs.nightlyEmail.subject)
				<<adrdata^.prefs.nightlyEmail.subject = "Nightly email from my weblog"
			<<if not defined (adrdata^.prefs.nightlyEmail.sender)
				<<adrdata^.prefs.nightlyEmail.sender = adrdata^.prefs.ownerEmail
		bundle { //rssHeader
			if not defined (adrdata^.prefs.rssHeader) {
				new (tabletype, @adrdata^.prefs.rssHeader)};
			if not defined (adrdata^.prefs.rssHeader.title) {
				adrdata^.prefs.rssHeader.title = ""};
			if not defined (adrdata^.prefs.rssHeader.link) {
				adrdata^.prefs.rssHeader.link = ""};
			if not defined (adrdata^.prefs.rssHeader.description) {
				adrdata^.prefs.rssHeader.description = ""};
			if not defined (adrdata^.prefs.rssHeader.language) {
				adrdata^.prefs.rssHeader.language = "en-us"};
			if not defined (adrdata^.prefs.rssHeader.copyrightHolder) {
				adrdata^.prefs.rssHeader.copyrightHolder = ""};
			if not defined (adrdata^.prefs.rssHeader.managingEditor) {
				adrdata^.prefs.rssHeader.managingEditor = ""};
			if not defined (adrdata^.prefs.rssHeader.webMaster) {
				adrdata^.prefs.rssHeader.webMaster = ""}};
		bundle { //ping
			if not defined (adrdata^.prefs.ping) {
				new (tabletype, @adrdata^.prefs.ping)};
			if not defined (adrdata^.prefs.ping.enabled) {
				adrdata^.prefs.ping.enabled = true};
			if not defined (adrdata^.prefs.ping.url) {
				adrdata^.prefs.ping.url = ""};
			if not defined (adrdata^.prefs.ping.server) {
				adrdata^.prefs.ping.server = "xmlrpc://rpc.weblogs.com/RPC2"};
			if not defined (adrdata^.prefs.ping.result) {
				new (tabletype, @adrdata^.prefs.ping.result)};
			if not defined (adrdata^.prefs.ping.when) {
				adrdata^.prefs.ping.when = clock.now ()}};
		<<bundle //directoryPlace
			<<if not defined (adrdata^.prefs.directoryPlace)
				<<new (tabletype, @adrdata^.prefs.directoryPlace)
			<<if not defined (adrdata^.prefs.directoryPlace.adrManilaWebsite)
				<<adrdata^.prefs.directoryPlace.adrManilaWebsite = nil
			<<if not defined (adrdata^.prefs.directoryPlace.msgnum)
				<<adrdata^.prefs.directoryPlace.msgnum = 0
		bundle { //s3 -- 3/8/11 by DW
			if not defined (adrdata^.prefs.s3) {
				new (tabletype, @adrdata^.prefs.s3)};
			if not defined (adrdata^.prefs.s3.enabled) {
				adrdata^.prefs.s3.enabled = false};
			if not defined (adrdata^.prefs.s3.path) {
				adrdata^.prefs.s3.path = ""};
			if not defined (adrdata^.prefs.s3.url) {
				adrdata^.prefs.s3.url = ""}}};
	bundle { //stats
		if not defined (adrdata^.stats) {
			new (tabletype, @adrdata^.stats)};
		if not defined (adrdata^.stats.whenLastUpdate) {
			adrdata^.stats.whenLastUpdate = date (0)};
		if not defined (adrdata^.stats.ctUpdates) {
			adrdata^.stats.ctUpdates = 0};
		if not defined (adrdata^.stats.whenLastBuild) {
			adrdata^.stats.whenLastBuild = date (0)};
		if not defined (adrdata^.stats.ctBuilds) {
			adrdata^.stats.ctBuilds = 0};
		if not defined (adrdata^.stats.ctStoryBuilds) {
			adrdata^.stats.ctStoryBuilds = 0};
		if not defined (adrdata^.stats.storySerialNum) {
			adrdata^.stats.storySerialNum = 1};
		if not defined (adrdata^.stats.whenLastStylesheetSave) {
			adrdata^.stats.whenLastStylesheetSave = date (0)};
		if not defined (adrdata^.stats.ctStylesheetSaves) {
			adrdata^.stats.ctStylesheetSaves = 0};
		if not defined (adrdata^.stats.urlStylesheet) {
			adrdata^.stats.urlStylesheet = ""};
		if not defined (adrdata^.stats.urlBlogroll) { //6/13/10 by DW
			adrdata^.stats.urlBlogroll = ""};
		if not defined (adrdata^.stats.urlHomeTemplate) { //6/13/10 by DW
			adrdata^.stats.urlHomeTemplate = ""};
		if not defined (adrdata^.stats.urlStoryTemplate) { //6/13/10 by DW
			adrdata^.stats.urlStoryTemplate = ""};
		if not defined (adrdata^.stats.whenLastBuildAfterSave) { //6/12/10 by DW
			adrdata^.stats.whenLastBuildAfterSave = date (0)};
		if not defined (adrdata^.stats.ctBuildEverythings) { //6/14/10 by DW
			adrdata^.stats.ctBuildEverythings = 0};
		if not defined (adrdata^.stats.flBuildToc) { //6/27/10 by DW
			adrdata^.stats.flBuildToc = true};
		if not defined (adrdata^.stats.ctTocBuilds) { //6/27/10 by DW
			adrdata^.stats.ctTocBuilds = 0};
		if not defined (adrdata^.stats.whenLastTocBuild) { //7/8/10 by DW
			adrdata^.stats.whenLastTocBuild = date (0)};
		if not defined (adrdata^.stats.newPostTokens) { //7/3/10 by DW
			new (tabletype, @adrdata^.stats.newPostTokens)};
		if not defined (adrdata^.stats.ctRealtimeUpdates) { //7/13/10 by DW
			adrdata^.stats.ctRealtimeUpdates = 0};
		bundle { //s3 -- 3/8/11 by DW
			if not defined (adrdata^.stats.s3) {
				new (tabletype, @adrdata^.stats.s3)};
			if not defined (adrdata^.stats.s3.ctWrites) {
				adrdata^.stats.s3.ctWrites = 0};
			if not defined (adrdata^.stats.s3.ctErrors) {
				adrdata^.stats.s3.ctErrors = 0}}};
	<<bundle //website
		<<if not defined (adrdata^.website)
			<<adrdata^.website = scripting2Suite.data.virginWebsite
	bundle { //system.temp sub-table
		local (adrsub = @system.temp.scripting2.server.users.[username]);
		if not defined (adrsub^) {
			new (tabletype, adrsub)};
		if not defined (adrsub^.realtimeUpdates) {
			new (tabletype, @adrsub^.realtimeUpdates)}};
	return (adrdata)};
bundle { //test code
	initUser ("davewiner")}



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.