Tuesday, March 29, 2011 at 1:07 AM.

river2Suite.subscribeFeed

on subscribeFeed (url, adrname=nil, adruser=nil) {
	<<Changes
		<<3/24/11; 12:38:47 PM by DW
			<<Add optional adruser param to be passed to subscribeList.
		<<12/27/09; 10:10:57 AM by DW
			<<Set adrdata^.stats.cloudPipeClient.flFeedsDirty true on subscribe.
		<<9/16/09; 10:37:20 AM by DW
			<<Add optional adrname parameter, returns the name of the thing you subscribed to.
		<<9/16/09; 8:16:52 AM by DW
			<<Try to get the items from the feed before calling the read-feed routine. 
		<<9/7/09; 12:25:51 PM by DW
			<<After subscribing, renew subscriptions, in case the feed you're subscribed to is cloud-enabled.
		<<9/1/09; 11:49:26 AM by DW
			<<If it's an OPML file, delegate to the list-subscribing code.
		<<8/16/09; 7:03:39 PM by DW
			<<For feeds that are subscribed "naturally" and not from a reading list, we set adrdata^.prefs.flNonListSubscribe true, so they will not be deleted when all lists that reference them are unsubbed. It's *very* important that this routine not be called to subscribe to a feed from a mail list. Note that such feeds could be referenced from a reading list.
		<<8/11/09; 1:15:54 PM by DW
			<<Tweak log message.
		<<6/16/09; 1:36:33 PM by DW
			<<Created. 
	local (adrdata = river2Suite.init (), now = clock.now (), startticks = clock.ticks ());
	
	if defined (adrdata^.feeds.[url]) {
		scriptError ("Dude. You're already subscribed to that feed.")};
	
	bundle { //if it's an OPML file, delegate 9/1/09 by DW
		local (s = tcp.httpreadurl (url), xstruct, flopml = false);
		xml.compile (s, @xstruct);
		try {
			xml.getaddress (@xstruct, "opml");
			flopml = true};
		if flopml {
			return (river2Suite.subscribeList (url, adrname, adruser))}};
	
	bundle { //if we can't get the feed items, can't subscribe, 9/16/09 by DW
		local (items, feedinfo);
		new (tabletype, @feedinfo);
		xml.rss.getFeedItems (url, @items, @feedinfo);
		if adrname != nil {
			adrname^ = feedinfo.title}};
	
	try {
		river2Suite.readFeed (url);
		local (adrfeed = river2suite.initfeed (url));
		adrfeed^.stats.whenSubscribed = now;
		adrdata^.prefs.flNonListSubscribe = true; //8/16/09 by DW
		if adrdata^.prefs.flRequestCloudNotify { //9/7/09 by DW
			thread.callscript (@river2Suite.renewSubscriptions, {})};
		adrdata^.stats.cloudPipeClient.flFeedsDirty = true; //12/27/09 by DW
		log2.add (river2Info.name, "Subscribe", "<a href=\"" + url + "\">" + adrfeed^.feedinfo.title + "</a>.", startticks)}
	else {
		local (s = tryerror);
		local (adrfeed = river2suite.initfeed (url));
		log2.add (river2Info.name, "Subscribe", "Error subscribing to \"" + url + "\": " + s, startticks);
		delete (adrfeed);
		scripterror (s)}};
bundle { //test code
	local (url = "http://newsriver.org/podcastReadingList.opml");
	url = "http://static.newsriver.org/afp/texn.xml";
	url = "http://newsriver.org/podcastReadingList.opml";
	subscribeFeed (url);
	}
	<<if dialog.ask ("URL?", @config.river2.prefs.lastFeedUrl)
		<<subscribeFeed (config.river2.prefs.lastFeedUrl)



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.