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

system.verbs.builtins.radio.hotlist.main

on main () {
	<<Changes:
		<<1/6/02; 3:46:25 AM by JES
			<<Added table css classes.
		<<11/28/01; 11:08:16 PM by JES
			<<Set pta^.title to the localized title.
		<<11/13/01; 5:48:11 PM by DW
			<<Prepared for localization.
		<<11/9/01; 10:34:03 PM by DW
			<<Rewrite.
		<<10/20/01; 12:16:27 AM by JES
			<<Set adraggregatordata^.settings.flSubscriptionsChanged to true, after unsubscribing from a channel. Causes mySubscriptions.opml to be re-written.
		<<8/12/01; 4:22:32 PM by JES
			<<Fixed a typo when checking to see if the cache needs clearing: if defined, not if defind. (Duh.)
		<<8/8/01; 10:23:21 PM by JES
			<<Ported to builtins.radio.
		<<3/4/01; 6:15:58 PM by JES
			<<Toss the homepage cache when unsubscribing from a channel.
		<<2/25/01; 2:24:50 PM by JES
			<<If rendering for a remote browser, delete the remote stories cache, not the local machine cache, when subscribing to a new channel.
		<<2/25/01; 1:37:10 PM by PBS
			<<Set up a second cache for when it's not the same machine.
		<<2/25/01; 1:26:29 PM by JES
			<<Toss the homepage cache after reading a newly subscribed channel.
		<<2/25/01; 1:07:46 PM by JES
			<<When subscribing to new channels, read the channel right away. Stories appear on the homepage, and the channel appears on the Subscriptions page.
		<<2/24/01; 5:10:36 PM by PBS
			<<Terminology: channels, not sources.
			<<Help link next to the description.
		<<2/23/01; 10:25:03 PM by PBS
			<<When subscribing or unsubscribing, set the flag so that mySubscriptions.opml gets rebuilt.
		<<2/20/01; 5:10:58 PM by PBS
			<<No need to call myUserLandSuite.unTaint here, as data is untainted when it enters the system.
		<<2/15/01; 3:12:26 PM by PBS
			<<Fixed a typo in the text at the top of the page. Prevented macros from being executed.
		<<2/12/01; 5:13:48 PM by PBS
			<<XML buttons get link titles, consistent with other pages.
		<<2/8/01; 7:41:08 AM by DW
			<<Some sources don't have descriptions, so don't fail if you encounter one.
		<<2/4/01; 3:11:19 PM by DW
			<<Wrapped in a procedure to facilitate debugging.
		<<1/24/01; 7:23:42 AM by DW
			<<Oops, when I added the caching I didn't allow for POSTs, which must not be cached.
		<<1/23/01; 2:12:28 PM by DW
			<<Added "Last update" string at top of page.
			<<Cache the rendering.
	local (flUseCache = false); //set true when not debugging
	local (pta = html.getpagetableaddress ());
	pta^.title = radio.string.getlocalizedstring ("hotlist.title");
	<<scratchpad.params = pta^; edit (@scratchpad.params) //debugging
	local (adrdata = radio.hotlist.init ());
	local (adraggregatordata = xml.aggregator.init ());
	
	local (xmlimg = radio.images.systemImageRef ("icons/xml", flFileUrl:pta^.radioResponder.flSameMachine));
	local (htmltext = "", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
	
	bundle { //if it's been more than 24 hours since we loaded the hotlist data, reload it
		if  adrdata^.prefs.dateLastRead <= date.yesterday (clock.now ()) {
			radio.hotlist.reload ()}};
	
	local (adrincache);
	bundle { //set adrincache
		if pta^.radioResponder.flSameMachine {
			adrincache = @adrdata^.cache.main}
		else {
			adrincache = @adrdata^.cache.mainRemote}};
	bundle { //use the cache if you can
		if (pta^.method == "GET") and defined (adrincache^) and flUseCache {
			return (string (adrincache^))}};
	if pta^.method == "POST" {
		local (adrargs = @pta^.radioResponder.postArgs);
		<<scratchpad.args = adrargs^; edit (@scratchpad.args)
		try {delete (@adrargs^.subscribe)};
		
		bundle { //subscribe to checked channels that we aren't subscribed to
			local (adrarg, adrhotlistservice, adrservice);
			for adrarg in adrargs {
				adrhotlistservice = @adrdata^.top100 [number (nameof (adrarg^))];
				adrservice = @adraggregatordata^.services.[adrhotlistservice^.xmlUrl];
				if not defined (adrservice^) { //not subscribed
					local (errorstring);
					xml.aggregator.subscribeService (adrhotlistservice^.xmlUrl, @errorstring)}}};
		bundle { //unsubscribe from unchecked channels that we are subscribed to
			local (i, adrhotlistservice, adrservice);
			for i = 1 to sizeof (adrdata^.top100) {
				if not defined (adrargs^.[string.padwithzeros (i, 3)]) {
					adrhotlistservice = @adrdata^.top100 [i];
					adrservice = @adraggregatordata^.services.[adrhotlistservice^.xmlUrl];
					if defined (adrservice^) { //the user is subscribed to this channel
						xml.aggregator.unsubscribeService (adrhotlistservice^.xmlUrl)}}}}};
	
	add ("<form method=\"POST\">"); indentlevel++;
	
	bundle { //add the Subscribe button
		add ("<table align=\"right\" cellspacing=\"0\" cellpadding=\"7\"><tr><td valign=\"top\">  <input type=\"submit\" name=\"subscribe\" value=\"" + radio.string.getlocalizedstring ("hotlist.subscribeButton") + "\"></td></tr></table>")};
	bundle { //add the Description, Last Update text and Help icon
		pta^.title = radio.string.getlocalizedstring ("hotlist.title");
		add (radio.string.getlocalizedstring ("hotlist.intro"));
		add ("<i>" + radio.string.getlocalizedstring ("hotlist.lastUpdate") + ": " + radio.string.getDateString (adrdata^.prefs.dateLastRead) + ".</i> " + radio.userinterface.helplink ("The Hotlist page") + "<p>")};
	
	add ("<table class=\"dwsFrameTable\" cellspacing=\"0\" cellpadding=\"0\"><tr bgcolor=\"" + radio.data.htmlColors.framecolor + "\"><td>"); indentlevel++;
	add ("<table class=\"dwsTable\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">"); indentlevel++;
	local (adr, ct = 0);
	for adr in @adrdata^.top100 {
		ct++;
		add ("<tr bgcolor=\"" + radio.data.htmlColors.cellbgcolor + "\">"); indentlevel++;
		bundle { //add checkbox
			local (name = number (nameof (adrpost^)));
			local (checkboxval = "xxx ");
			if defined (adraggregatordata^.services.[adr^.xmlUrl]) {
				checkboxval = checkboxval + "checked"};
			add ("<td class=\"dwsTableCell\" valign=\"top\"><input type=\"checkbox\" name=\"" + string.padwithzeros (ct, 3) + "\" value=" + checkboxval + "></td>")};
		add ("<td class=\"dwsTableCell\" align=\"right\" valign=\"top\"><font size=\"-1\">" + ct + "</font></td>");
		add ("<td class=\"dwsTableCell\" valign=\"top\"><a href=\"" + adr^.htmlUrl + "\">" + adr^.title + "</a></td>");
		local (description = "");
		if defined (adr^.description) {
			description = adr^.description};
		add ("<td class=\"dwsTableCell\" valign=\"top\">" + description + "</td>");
		add ("<td class=\"dwsTableCell\" align=\"right\" valign=\"top\"><font size=\"-1\">" + adr^.ctSubscribers + "</font></td>");
		add ("<td class=\"dwsTableCell\" valign=\"top\"><a href=\"" + adr^.xmlUrl + "\" title=\"" + radio.data.strings.xmltooltip + "\">" + xmlimg + "</a></td>");
		add ("</tr>"); indentlevel--};
	add ("</table>"); indentlevel--;
	add ("</td></tr></table>"); indentlevel--;
	
	add ("</form>"); indentlevel--;
	adrincache^ = htmltext;
	return (htmlText)}
<<bundle //test code
	<<html.setPageTableAddress (@scratchpad.params)
	<<main ()
	<<html.deletePageTableAddress ()



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.