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

system.verbs.builtins.mainResponder.discuss.listDay

on listDay (d, bgColor="ivory", otherColor="beige", tableWidth=425, pta=nil, headerColor="black", headerTextColor=nil, cssPrefix="") {
	<<List the discussion group messages for a single day.
		<<Changes:
			<<Sat, 27 Feb 1999 23:16:13 GMT by AR
				<<Modified call to mainresponder.calendar.getdayaddress so it doesn't create the calendar entry
				<<Tweaked the html code to use valign=middle instead of valign=center
			<<Mon, 01 Mar 1999 15:01:02 GMT by AR
				<<The script's parameter must be a date type - otherwise a scripterror will be thrown.
					<<To convert other date representations to date type, take a look at mainResponder.calendar.getAddressDay and mainResponder.calendar.pathArgsToDate
			<<Sat, 06 Mar 1999 17:08:06 GMT by AR
				<<Commented out code for caching table lines.
			<<Wed, 26 May 1999 01:10:41 GMT by AR
				<<Added new optional paramaters bgcolor, othercolor, and tablewidth to allow the calling script more influence over the layout of the table.
				<<Changed value of membershipGroup from config.mainresponder.globals.defaultMembershipGroup to pta^.responderAttributes.defaultMembershipGroup.
			<<Tue, Aug 3, 1999 at 12:39:52 PM by PBS
				<<Added optional pta parameter.
				<<Since member names are often repeated, added a local table to cache the names while building the page, to avoid unnecessary calls out.
			<<10/30/99; 1:12:22 PM by PBS
				<<headerColor is a new optional parameter for specifying the color of the header at the top of a discussion group messages list. If not specified, the default is black, which is current behavior.
				<<headerTextColor is a new optional parameter for specifying the color of the text inside the header. If not specified, the default is the parameter in bgColor.
				<<In both cases, default behavior applies if you don't specify the parameter.
			<<04/12/00; 1:01:38 PM by JES
				<<Localized column headers and table header using mainResponder.getString
			<<05/30/00; 5:22:03 PM by PBS
				<<cssPrefix is a new optional parameter. If supplied, then CSS classes are added to the tables, rows, cells, and font tags.
			<<05/31/00; 3:50:03 PM by PBS
				<<Typo fix: there was a colspan=6 when there are only 5 columns.
			<<06/01/00; 9:04:38 PM by JES
				<<merged CSS code with localization code
	
	if pta == nil {
		pta = html.getPageTableAddress ()};
	
	local (adrData = mainResponder.discuss.openRoot (pta));
	local (adrCal = @adrData^.calendar);
	local (adrMsgs = @adrData^.messages);
	local (htmlText = "", indentLevel = 0);
	local (adrDay, i, ct);
	local (membershipGroup = pta^.responderAttributes.defaultMembershipGroup);
	local (msgReaderUrl = pta^.responderAttributes.urls^.discussMsgReader);
	local (flCss = (cssPrefix != "")); //if true, emit CSS classes, otherwise don't
	
	local (nameTable);
	new (tableType, @nameTable);
	
	on add (s) {
		htmlText = htmlText + string.filledString ("\t", indentLevel) + s + "\r"};
	
	<<on td (s, align="")
		<<add ("<td nowrap " + align + " valign=\"middle\"><font size=\"-1\">  " + s + "  </font></td>")
	on td (s, align="", class="", height="") {
		local (fontClass = "");
		if (flCss) and (class != "") {
			class = cssPrefix + class;
			fontClass = " class=\"" + class + "Font\"";
			class = " class=\"" + class + "\""};
		if height != "" {
			height = " height=\"" + height + "\""};
		if align != "" {
			align = " " + align};
		add ("<td nowrap" + align + " valign=\"middle\"" + class + height + "><font size=\"-1\"" + fontClass + ">  " + s + "  </font></td>")};
	
	on shortenString (s, maxLen=35) {
		<<if sizeOf (s) <= maxLen
			<<return (s)
		return (string.mid (s, 1, maxLen - 3) + "...")};
	
	try { //get the address of this day in the calendar structure for this discussion group.
		adrDay = mainResponder.calendar.getDayAddress (adrCal, d, flCreate:false);
		ct = sizeOf (adrDay^)}
	else {
		ct = 0}; //no messages yet, shortcut building of message listing
	
	<<add ("<table cellpadding=\"0\" cellspacing=\"1\">"); indentLevel++
	bundle { //start the table
		if flCss {
			add ("<table cellpadding=\"0\" cellspacing=\"1\" class=\"" + cssPrefix + "Table\">"); indentLevel++}
		else {
			add ("<table cellpadding=\"0\" cellspacing=\"1\">"); indentLevel++}};
	
	<<bundle //add the date on a black background
		<<add ("<tr><td height=\"10\"><td> </td></tr>") //blank spacer row
		<<add ("<tr bgcolor=\"" + headerColor + "\">"); indentLevel++ //PBS 10/30/99: variable header color, black by default
		<<if headerTextColor == nil //PBS 10/30/99: the header text color may also be specified
			<<headerTextColor = bgColor
		<<add ("<td height=\"24\" width=\"" + tableWidth + "\" colspan=\"6\"><font color=\"" + headerTextColor + "\" size=\"-0\"> <b> " + mainResponder.localization.longDateString (d, pta) + " </b></font></td>") // 4/13/00 JES: localized the date
		<<add ("</tr>"); indentLevel--
	bundle { //add the date on a black background
		if flCss { //header row
			add ("<tr bgcolor=\"" + headerColor + "\" class=\"" + cssPrefix + "SeparatorRow\">"); indentLevel++} //PBS 10/30/99: variable header color, black by default
		else {
			add ("<tr bgcolor=\"" + headerColor + "\">"); indentLevel++}; //PBS 10/30/99: variable header color, black by default
		
		if headerTextColor == nil { //PBS 10/30/99: the header text color may also be specified
			headerTextColor = bgColor};
		
		if flCss { //header cell -- 06/01/00 JES: localized date string in new code
			add ("<td height=\"24\" width=\"" + tableWidth + "\" colspan=\"5\" class=\"" + cssPrefix + "SeparatorCell\"><font color=\"" + headerTextColor + "\" size=\"-0\" class=\"" + cssPrefix + "SeparatorFont\"> <b> " + mainResponder.localization.longDateString (d, pta) + " </b></font></td>")} //PBS 05/31/00: 5 columns, not 6
		else {
			add ("<td height=\"24\" width=\"" + tableWidth + "\" colspan=\"5\"><font color=\"" + headerTextColor + "\" size=\"-0\"> <b> " + mainResponder.localization.longDateString (d, pta) + " </b></font></td>")}; //PBS 05/31/00: 5 columns, not 6
		
		add ("</tr>"); indentLevel--};
	
	bundle { //add column titles
		<<bundle // 06/01/00 JES: old code
			<<add ("<tr bgcolor=\"" + otherColor + "\">"); indentLevel++
			<<add ("<td height=\"28\"></td>") //a dummy table cell to establish row height
		if flCss { //titles row
			add ("<tr bgcolor=\"" + otherColor + "\" class=\"" + cssPrefix + "TitleRow\">"); indentLevel++}
		else {
			add ("<tr bgcolor=\"" + otherColor + "\">"); indentLevel++};
		
		<<4/13/00; 3:53:31 PM by JES -- localized column headers
		td ("<b>" + mainResponder.getString ("listHeaders.shortNum") + "</b>", align:"align=\"center\"", class:"MessageLinkTitle", height:28);
		td ("<b>" + mainResponder.getString ("listHeaders.posted") + "</b>", align:"align=\"center\"", class:"PostedTitle");
		td ("<b>" + mainResponder.getString ("listHeaders.ct") + "</b>", align:"align=\"center\"", class:"ReadsTitle");
		td ("<b>" + mainResponder.getString ("listHeaders.author") + "</b>", class:"AuthorTitle");
		td ("<b>" + mainResponder.getString ("listHeaders.subject") + "</b>", class:"SubjectTitle");
		
		add ("</tr>"); indentLevel--};
	
	for i = ct downTo 1 { //loop through messages in reverse-chronological order
		local (adrItem, memberName);
		adrItem = @adrMsgs^.[nameOf (adrDay^ [i])];
		
		bundle { //was this message deleted? If so, skip it.
			if defined (adrItem^.flDeleted) {
				<<The flDeleted flag may not exist: it's necessary to test for existence before testing whether it's true or false.
				if adrItem^.flDeleted {
					continue}}};
		
		bundle { //message row
			if flCss {
				add ("<tr bgcolor=\"" + otherColor + "\" class=\"" + cssPrefix + "MessageRow\">"); indentLevel++}
			else {
				add ("<tr bgcolor=\"" + otherColor + "\">"); indentLevel++}};
		
		bundle { //add the message number, it's the link
			local (url = msgReaderUrl + adrItem^.msgNum);
			td ("<a href=\"" + url + "\">" + adrItem^.msgNum + "</a>", align:"align=\"center\"", class:"MessageLink", height:28)};
		
		bundle { //add post time and read count.
			td (mainResponder.localization.shortTimeString (adrItem^.postTime), align:"align=\"center\"", class:"Posted"); // 4/13/00 by JES: localized postTime
			td (adrItem^.ctReads, align:"align=\"right\"", class:"CountReads")};
		
		bundle { //get the name of the member who posted this message.
			if defined (nameTable.[adrItem^.member]) { //cache member names in a local table, since repetitions are likely
				memberName = nameTable.[adrItem^.member]}
			else {
				memberName = mainResponder.members.getMemberName (membershipGroup, adrItem^.member);
				nameTable.[adrItem^.member] = memberName}};
		
		bundle { //add the name of the member who posted this message.
			if sizeOf (memberName) > 20 {
				td (shortenString (memberName, 20), class:"Author")}
			else {
				td (memberName, class:"Author")}};
		
		bundle { //add the subject of the message.
			if sizeOf (adrItem^.subject) > 40 {
				td (shortenString (adrItem^.subject, 40), class:"Subject")}
			else {
				td (adrItem^.subject, class:"Subject")}};
		
		add ("</tr>"); indentLevel--;
		};
		<<bundle  //code to implement caching (deactivated)
			<<if false //defined (adritem^.htmlcache)
				<<local (oldindentlevel = indentlevel)
				<<indentlevel = 0
				<<add (adritem^.htmlcache)
				<<indentlevel = oldindentlevel
			<<else
				<<on shortenstring (s, maxlen=35)
					<<if sizeof (s) <= maxlen
						<<return (s)
					<<return (string.mid (s, 1, maxlen - 3) + "...")
				<<local (ixhtmltext = sizeof (htmltext))
				<<add ("<tr bgcolor=\"" + othercolor + "\">"); indentlevel++
				<<add ("<td height=\"28\"></td>") //a dummy table cell to establish row height
				<<bundle //add the message number, it's the link
					<<local (url = pta^.responderAttributes.urls^.discussMsgReader + adritem^.msgnum)
					<<td ("<a href=\"" + url + "\">" + adritem^.msgnum + "</a>", align:"align=\"center\"")
				<<td (date.timeString (adritem^.posttime, includeSeconds:false), align:"align=\"center\"")
				<<td (adritem^.ctreads, align:"align=\"right\"")
				<<local (membername = mainResponder.members.getMemberName (membershipGroup, adritem^.member))
				<<td (shortenstring (membername, 20))
				<<td (shortenstring (adritem^.subject, 40))
				<<add ("</tr>"); indentlevel--
				<<
				<<adritem^.htmlcache = string.delete (htmltext, 1, ixhtmltext)
				<<adritem^.htmlcache = string.delete (adritem^.htmlcache, sizeof (adritem^.htmlcache), 1)
	
	add ("</table>"); indentLevel--;
	
	return (htmlText)}



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.