Tuesday, August 18, 2009 at 7:34 PM.

newsRiverSuite.viewNewsItemsPda

on viewNewsItemsPda (adrcallback=nil) {
	<<Changes
		<<8/17/08; 10:46:32 AM by DW
			<<Converted to use newsRiverSuite.imageRef instead of the one in dotOpml.root.
		<<5/19/08; 12:05:10 PM by DW
			<<Allow callbacks to be addresses of a script.
		<<8/20/06; 7:42:14 AM by DW
			<<Added a callback, takes one param, the address of a story; if the callback returns true, we include the story in the view. 
		<<8/19/06; 5:42:12 PM by DW
			<<Eliminate duplicate items. Esp useful in the nytimesriver application.
	local (pta = html.getpagetableaddress ());
	<<pta^.title = "Home"
	local (globeimg, xmlimg, searchimg, checkmarkimg, mediaimg, commentimg, postbuttonimg, permalinkimg);
	bundle { //precalc img refs
		globeimg = newsRiverSuite.imageRef ("newsRiver/qbullet/remote");
		xmlimg = newsRiverSuite.imageRef ("newsRiver/icons/xml");
		searchimg = newsRiverSuite.imageRef ("newsRiver/qbullet/search");
		checkmarkimg = newsRiverSuite.imageRef ("newsRiver/icons/checkmark");
		postbuttonimg = newsRiverSuite.imageRef ("newsRiver/icons/post");
		mediaimg = newsRiverSuite.imageRef ("newsRiver/qbullet/sound");
		commentimg = newsRiverSuite.imageRef ("newsRiver/icons/pencil");
		permalinkimg = newsRiverSuite.imageRef ("newsRiver/icons/itemPermalink")};
	on decodeEntities (s) {
		s = string.replaceAll (s, "\r\n", "\r");
		s = string.replaceAll (s, "\n", "\r");
		return (newsRiverSuite.decodeEntities (s, flNeuterJavaScript:false))};
	local (htmltext = "", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + (string.filledstring ("\t", indentlevel) + s + "\r\n");};
	local (adrdata = newsRiverSuite.init ());
	local (urlstable); new (tabletype, @urlstable);
	local (ctStoriesToList = adrdata^.newsRiver.ctStoriesOnNewsPage);
	local (adrtable = @adrdata^.stories, sizetable = sizeof (adrtable^), i, ctstories = 0, lastchanneltitle = "");
	for i = sizetable downto 1 {
		local (adritem = @adrdata^.stories [i]);
		bundle { //check with callback, if defined
			if adrcallback != nil {
				try {
					if not adrcallback^ (adritem) {
						continue}}}};
		bundle { //skip duplicate stories
			if adrdata^.newsRiver.flEliminateDuplicateStories {
				if newsRiverSuite.eliminateDuplicates (adritem, @urlstable) {
					continue}}};
			<<old code
				<<An interesting story here...
					<<You might think that a guid or a permalink would be the same even if the story appeared in different departments, but apparently not.
					<<What to do? Well, headline writers tend to be creative, but they don't come up with different headlines when a story appears in more than one feed, so I tried using that as the guid, it worked. 
					<<Now if two headline writers for different pubs use exactly the same headline, we'll have a problem...
					<<8/23/06; 6:34:45 AM by DW
				<<local (guid = "")
				<<if defined (adritem^.data.title)
					<<guid = adritem^.data.title
				<<else
					<<if defined (adritem^.permalink)
						<<guid = adritem^.permalink
					<<else
						<<if defined (adritem^.guid)
							<<guid = adritem^.guid
				<<if sizeof (guid) > 0
					<<local (adr = @urlstable.[guid])
					<<if defined (adr^) //duplicate
						<<adr^++
						<<continue
					<<adr^ = 1
				<<if defined (adritem^.url)
					<<if (adritem^.url beginswith "http://www.nytimes.com") or (adritem^.url beginswith "http://newsrss.bbc.co.uk") or (adritem^.url contains "http://news.com.com")
						<<local (s = adritem^.storytext, ix)
						<<ix = string.patternmatch ('"', s)
						<<s = string.delete (s, 1, ix) //pop off everything before the first url
						<<ix = string.patternmatch ('"', s)
						<<s = string.mid (s, 1, ix-1)
						<<local (adr = @urlstable.[s])
						<<if defined (adr^) //duplicate
							<<adr^++
							<<continue
						<<adr^ = 1
		bundle { //skip missing or empty stories
			if not defined (adritem^.storyText) { //skip this story -- this can happen if the scan is interrupted
				continue};
			if (string.trimWhiteSpace (searchEngine.stripMarkup (adrItem^.storyText)) == "") and (not (string.lower (adrItem^.storyText) contains "<img ")) { //PBS 02/12/01: skip empty stories
				continue}};
		local (adrservice = @adrdata^.services.[adritem^.url]);
		if not defined (adrservice^) {
			continue};
		ctstories++;
		if ctstories > ctStoriesToList {
			break};
		if adritem^.channeltitle != lastchanneltitle { //display channel title
			local (globe = "");
			try { //link the globe to the HTML rendering of the channel
				with adrservice^.compilation {
					local (desc = searchengine.stripmarkup (channeldescription));
					globe = "<a href=\"" + channellink + "\" title=\"" + newsRiverSuite.translateToEntities (desc) + "\">" + globeimg + "</a>"; //PBS 02/12/01: fix bug where quotes and carets in a channel description would mess up rendering -- an example was Dave Winer: Two-Way Web, which has a description of You're soaking in it! ";->"
					add ("<b>" + decodeEntities (adrItem^.channelTitle) + ", " + date.timestring (adritem^.time, false) + ".</b>")}};
			lastchanneltitle = adritem^.channeltitle};
		local (enclosure = "");
		bundle { //if it has an enclosure add a media link
			if defined (adritem^.enclosure) {
				if not defined (adritem^.enclosure.error) {
					local (url);
					if defined (adritem^.enclosure.f) {
						url = html.getfileurl (adritem^.enclosure.f)}
					else {
						url = adritem^.enclosure.url};
					enclosure = " <a href=\"" + url + "\">" + "<img src=\"http://www.scripting.com/gifs/QBullets/qbullets/sound.gif\" width=\"10\" height=\"11\" border=\"0\" alt=\"enclosure\">" + "</a>"}}};
		bundle { //add story
			local (s = adritem^.storytext);
			bundle { //callbacks, 8/12/06 by DW
				local (adrscript);
				for adrscript in @adrdata^.newsRiver.callbacks.pdaStoryTextProcess {
					try {
						while typeof (adrscript^) == addresstype { //5/19/08; 12:05:01 PM by DW
							adrscript = adrscript^};
						s = adrscript^ (s, adritem)}}};
			add ("<p>" + s + enclosure + "</p>")}};
	scratchpad.urlstable = urlstable;
	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.