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

system.verbs.builtins.xml.rss.getHtmlRendering

on getHtmlRendering (adrservice, boxTitle=nil, width=125, frameColor="#000000", titleBarTextColor="#000000", titleBarColor="#ADD8E6", boxFillColor="#FFFFFF", timeZone="PST", maxItems=infinity, timeZoneOffsetHours=0) {
	<<Changes:
		<<10/21/01; 9:35:58 PM by DW
			<<All items have bullets, even if they don't have sources.
		<<05/07/01; 8:17:37 PM by JES
			<<New optional parameter, timeZoneOffsetHours, used for adjusting time display, according to a Manila site's time zone pref setting. Bug fix: display the time if the channel was updated in the last 24 hours. Formerly, the update time was displayed as a date, even if it had been updated one minute ago, at 12:00 AM.
		<<3/28/01; 2:18:17 PM by PBS
			<<Added alt attributes to img tags, for proper HTML.
		<<02/09/01; 6:50:57 PM by PBS
			<<New optional maxItems parameter, defaults to infinity (current behavior), allows the caller to specify the maximum number of news items that appear in the HTML rendering.
		<<1/6/2001; 2:45:19 PM by DW
			<<In the box title, replace all spaces with non-breaking spaces.
		<<1/6/2001; 2:41:15 PM by DW
			<<Use a different bullet, one that displays well on a non-white background.
		<<01/04/01; 5:38:13 PM by JES
			<<Changed the width attribute for the inner-most td tags to 100%, since IE for Windows wasn't respecting the absolute width attribute.
		<<1/4/2001; 3:49:55 PM by JES
			<<Fixed HTML validation error, and problem with width specification.
		<<1/4/2001; 8:19:02 AM by DW
			<<More tweaks to formatting w/o box.
		<<1/2/2001; 1:31:26 PM by DW
			<<Minor tweaks to formatting w/o box.
		<<1/2/01; 12:22:56 PM by DW
			<<If width is infinity, don't do the box.
	local (flbox = width != infinity);
	local (adrtable = @adrservice^.compilation);
	on neuter (s) {
		s = string.replaceall (s, "{", "{"); //neuter macros
		s = string.replaceall (s, "'", "'");
		return (s)};
	local (htmltext = "\r\n", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledString ("\t", indentlevel) + s + "\r\n"};
	
	if boxTitle == nil {
		boxTitle = neuter (adrtable^.channelTitle)};
	boxTitle = string.replaceAll (boxTitle, " ", " ");
	add ("<!-- RSS-to-HTML rendering done by UserLand on " + date.netstandardstring (clock.now ()) + " -->");
	if flbox {
		add ("<table width=\"" + width + "\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\">"); indentlevel++;
		add ("<tr bgcolor=\"" + framecolor + "\">"); indentlevel++;
		add ("<td width=\"" + width + "\">"); indentlevel++;
		add ("<table width=\"" + width + "\" cellspacing=\"0\" cellpadding=\"7\" border=\"0\">"); indentlevel++};
	local (timeString);
	bundle { //add title bar row
		bundle { //set timestring
			local (day, month, year, hour, minute, second);
			local (yesterday = date.yesterday (clock.now ()) + (timeZoneOffsetHours * 3600));
			local (timeLastChange = adrservice^.timeLastChange + (timeZoneOffsetHours * 3600));
			date.get (timeLastChange, @day, @month, @year, @hour, @minute, @second);
			
			if timeLastChange > yesterday { //only show time
				minute = string.padwithzeros (minute, 2);
				if hour == 0 {
					timeString = "12:" + minute + "AM"}
				else {
					if hour < 12 {
						timeString = hour + ":" + minute + "AM"}
					else {
						if hour == 12 {
							timeString = hour + ":" + minute + "PM"}
						else {
							timeString = (hour - 12) + ":" + minute + "PM"}}};
				timestring = timeString + " " + timeZone}
			else {
				timeString = month + "/" + day + "/" + year}};
		if flbox {
			add ("<tr bgcolor=\"" + titleBarColor + "\">"); indentlevel++;
			add ("<td width=\"" + width + "\" height=\"22\" nowrap><a href=\"" + adrtable^.channelLink + "\"><b><font color=\"" + titleBarTextColor + "\">" + boxTitle + "</font></b></a></td><td> </td><td nowrap align=\"right\"><font color=\"" + titleBarTextColor + "\" size=\"-1\">" + "" + timeString + "</font></td>");
			add ("</tr>"); indentlevel--}};
	bundle { //add one-pixel row in the frame color
		if flbox {
			add ("<tr bgcolor=\"" + frameColor + "\"><td width=\"" + width + "\" height=\"1\"></td></tr>")}};
	bundle { //add the body
		local (imageLink = "");
		if defined (adrtable^.imagelink) { //the image is optional
			imageLink = "<a href=\"" + adrtable^.imagelink + "\"><img src=\"" + adrtable^.imageurl + "\" border=\"0\" align=\"right\" vspace=\"3\" alt=\"\"></a>"}; //PBS 03/28/01: alt tag required
		if flbox {
			add ("<tr bgcolor=\"" + boxFillColor + "\">"); indentlevel++;
			add ("<td width=\"100%\" colspan=\"3\">"); indentlevel++}
		else {
			add ("<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\">"); indentlevel++};
			<<add ("<tr><td></td><td><font size=\"-1\">XML</font></td></tr>")
		bundle { //generate the news items
			local (storyLink, i, ct = 0);
			if sizeof (imagelink) > 0 {
				add (imagelink)};
			for i = sizeof (adrtable^.items) downto 1 {
				local (adritem = @adrtable^.items [i], bullet = "");
				bundle { //set bullet
					local (align = "");
					if flbox {
						align = " hspace=\"10\" vspace=\"2\" align=\"left\""};
					if defined (adritem^.sourceChannelTitle) {
						bullet = "<a href=\"" + adritem^.sourceChannelUrl + "\" title=\"Source: " + adritem^.sourceChannelTitle + "\"><img src=\"http://www.scripting.com/images/bullet.gif\" height=\"10\" width=\"5\"" + align + " border=\"0\" alt=\"Source: " + adrItem^.sourceChannelTitle + "\"></a>"} //PBS 03/28/01: add alt tag -- it's the name of the source
						<<http://static.userland.com/shortcuts/images/qbullets/text.gif
					else {
						bullet = "<img src=\"http://www.scripting.com/images/bullet.gif\" height=\"10\" width=\"5\"" + align + " border=\"0\" alt=\"Bullet\">"}};
				if flbox {
					add (bullet + neuter (adritem^.title) + "<br><br>")}
				else {
					add ("<tr>"); indentlevel++;
					add ("<td valign=\"top\"><center>" + bullet + "</center></td>");
					add ("<td>" + neuter (adritem^.title) + "</td>");
					add ("</tr>"); indentlevel--;
					add ("<tr height=\"8\"><td colspan=\"2\"></td></tr>")};
				ct++;
				if ct == maxItems { //PBS 02/08/01: respect maxItems parameter
					break}}};
		if not flbox {
			add ("<tr height=\"8\"><td colspan=\"2\"></td></tr>");
			add ("<tr><td colspan=\"2\"><font size=\"-1\"><i>Source: <a href=\"" + adrservice^.xmlurl + "\" title=\"Click on this link to see the XML version of the '" + boxTitle + "' channel.\">" + boxTitle + "</a>; Updated: " + timeString + ".</i></font></td></tr>");
			add ("</table>"); indentlevel--};
		if defined (adrtable^.textInputTitle) { //add the textinput form
			add ("<form name=\"my.userland.com textinput\" action=\"" + adrtable^.textInputLink + "\" method=\"GET\"><font size=\"-0\">"); indentlevel++;
			add ("<b>" + adrtable^.textInputDescription + "</b>:<br>");
			add ("<input type=\"text\" name=\"" + adrtable^.textInputName + "\" size=\"20\" maxlength=\"100\" value=\"\">");
			add ("<input type=\"submit\" value=\"" + neuter (adrtable^.textInputTitle) + "\">");
			add ("</form></font>"); indentlevel--};
		if flbox {
			add ("</td>"); indentlevel--;
			add ("</tr>"); indentlevel--}};
	if flbox {
		add ("</table>"); indentlevel--;
		add ("</td>"); indentlevel--;
		add ("</tr>"); indentlevel--;
		add ("</table>"); indentlevel--};
	adrservice^.htmlRendering = htmltext;
	<<scratchpad.service = adrservice^
	return (htmltext)}
<<bundle //test code
	<<webbrowser.displaytext (getHtmlRendering (@scratchpad.service, width:300))



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.