Wednesday, December 01, 2010 at 4:42 AM.

scripting2Suite.server.buildMonthPage

on buildMonthPage (username, themonth) {
	<<Changes
		<<12/1/10; 4:03:56 AM by DW
			<<Fix first year rollover bug. Make sure the next year exists in the calendar structure. 
		<<6/7/10; 8:41:07 PM by DW
			<<Created. 
	local (adrdata = scripting2suite.inituser (username), adrcal = @adrdata^.calendar);
	local (whenLastSave = date (0), htmltext, adrmonth, monthstring, path);
	bundle { //set adrmonth, monthstring, path
		local (day, month, year, hour, minute, second);
		date.get (themonth, @day, @month, @year, @hour, @minute, @second);
		local (padmonth = string.padwithzeros (month, 2));
		adrmonth = @adrcal^.[year].[padmonth];
		monthstring = date.monthtostring (month) + " " + year;
		path = year + "/" + padmonth + ".html"};
	bundle { //get htmltext
		local (indentlevel = 0, i);
		htmltext = "\r\r";
		on add (s) {
			htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
		on decode (s) {
			return (xml.entitydecode (s, true))};
		for i = sizeof (adrmonth^) downto 1 {
			local (adrday = @adrmonth^ [i], j);
			for j = sizeof (adrday^) downto 1 {
				local (adrstory = @adrday^ [j]);
				if scripting2Suite.server.isStoryVisible (adrstory) {
					add (scripting2Suite.server.getStoryText (adrstory, flComments:adrdata^.prefs.flDisqusComments));
					if adrstory^.whenLastSave > whenLastSave {
						whenLastSave = adrstory^.whenLastSave}}}};
		htmltext = scripting2Suite.server.glossarySubstitution (@adrdata^.prefs.glossary, htmltext);
		htmltext = scripting2Suite.server.glossarySubstitution (@scripting2Suite.data.systemGlossary, htmltext)};
	bundle { //run it through the template
		local (t);
		new (tabletype, @t);
		t.whenLastUpdate = whenLastSave;
		t.title = monthstring;
		scripting2Suite.server.setupMacrosTable (username, @t); //add common elements
		scripting2Suite.server.getCalendarText (username, themonth, t.baseurl, @t.calendar, @t.nextPrevMonths);
		t.crumbTrail = scripting2Suite.server.getCrumbTrail (t.baseurl, themonth, flmonthbold:true); //6/8/10 by DW
		bundle { //set nextPrev
			local (nextlink = "Next", prevlink = "Previous", nexturl = "", prevurl = "");
			on getmonthaddress (d) {
				local (day, month, year, hour, minute, second);
				date.get (d, @day, @month, @year, @hour, @minute, @second);
				local (padmonth = string.padwithzeros (month, 2));
				adrmonth = @adrcal^.[year].[padmonth];
				return (adrmonth)};
			on monthtourl (d) {
				local (day, month, year, hour, minute, second);
				date.get (d, @day, @month, @year, @hour, @minute, @second);
				url = t.baseurl + year + "/" + string.padwithzeros (month, 2) + ".html";
				return (url)};
			bundle { //set nexturl
				local (d = date.nextmonth (themonth));
				try { //it will fail if you're getting January's address in December, 12/1/10 by DW
					local (adrnextmonth = getmonthaddress (d));
					if defined (adrnextmonth^) {
						nexturl = monthtourl (d)}}};
			bundle { //set prevurl
				local (d = date.prevmonth (themonth));
				local (adrprevmonth = getmonthaddress (d));
				if defined (adrprevmonth^) {
					prevurl = monthtourl (d)}};
			if prevurl != "" {
				prevlink = "<a href=\"" + prevurl + "\">" + prevlink + "</a>"};
			if nexturl != "" {
				nextlink = "<a href=\"" + nexturl + "\">" + nextlink + "</a>"};
			t.nextPrev = prevlink + " / " + nextlink};
		bundle { //do simple replacements on the blogroll, 6/7/10 by DW
			local (tsmall);
			new (tabletype, @tsmall);
			tsmall.calendar = t.calendar;
			tsmall.nextPrevMonths = t.nextPrevMonths;
			t.blogroll = string.multiplereplaceall (t.blogroll, @tsmall, false, "<%", "%>")};
		t.bodytext = htmltext;
		htmltext = string.multiplereplaceall (string (adrdata^.prefs.hometemplate), @t, false, "<%", "%>")};
	bundle { //upload it
		return (scripting2Suite.writeStaticFile (username, path, htmltext))}};
bundle { //test code
	for month = 2 to 6 {
		webbrowser.openurl (buildMonthPage ("davewiner", date.set (1, month, 2010, 0, 0, 0)))}}



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.