/***
''Name:'' GenRssPlugin
''Source:'' http://www.sourceforge.net/projects/ptw/
''Author:'' BramChen
''Type:'' Plugin
''Description:''  
* This plugin add a  "xml-stylesheet" processing into the rss file generated by TW.
* Resources used: 
** rssfeed.xsl
** rssfeed.css
** xsl.css
<<<
''Descriptions:''
* if 'config.options.txtGenRssTags is empty then the outputs limited to 'config.numRssItems' except tiddlers taged with 'excludeLists'.
* you can add the macro <<option txtGenRssTags>> to some configure tiddler, eg 'AdvancedOptions' for changing the tag list,
* and add <<option txtRssItems>> to change number of rsfeed item.
''Revision History:''
* v0.2.0 (Mar 30 2006)
** add a new feature that rssfeed limited to tiddlers taged with the tag list specified in 'config.options.txtGenRssTags'.
** add config.options.txtRssItems.
** if it's empty then the outputs limited to 'config.numRssItems' except tiddlers taged with 'excludeLists'.
** you can add the macro <<option txtGenRssTags>> to some configure tiddler, eg 'AdvancedOptions' for changing the tag list.
* v0.1.1 (Feb 04 2006)
** JSLint checked
v0.1.0 (Feb 1, 2006) 
* initial release
***/
// //''Code section:''
//{{{
version.extensions.genRss = {major: 0, minor: 2, revision: 0,
	date: new Date("Mar 30, 2006"),
	info: {
		type: "Macro",
		name: "GenRssPlugin",
		author: "BramChen",
		source: "http://sourceforge.net/project/showfiles.php?group_id=150646"
	}
};

window.generateRss_ori = window.generateRss;

config.options.txtGenRssTags = "";
config.options.txtRssItems = "20";

window.generateRss = function () {
	var rssTags = config.options.txtGenRssTags.readBracketedList();
	var numRssItems = config.options.txtRssItems;
	var s = [];
	var d = new Date();
	var u = store.getTiddlerText("SiteUrl",null);
	// Assemble the header
	s.push("<" + "?xml version=\"1.0\" encoding=\"utf-8\"?" + ">");
	s.push("<" + "?xml-stylesheet type=\"text/xsl\" href=\"rss/rssfeed.xsl\"?" +">");
	s.push("<" + "?xml-stylesheet type=\"text/css\" href=\"rss/rssfeed.css\"?" +">");
	s.push("<" + "rss version=\"2.0\">");
	s.push("<channel>");
	s.push("<title>" + wikifyPlain("SiteTitle").htmlEncode() + "</title>");
	if(u)
		s.push("<link>" + u.htmlEncode() + "</link>");
	s.push("<description>" + wikifyPlain("SiteSubtitle").htmlEncode() + "</description>");
	s.push("<language>en-us</language>");
	s.push("<copyright>Copyright " + d.getFullYear() + " " + config.options.txtUserName.htmlEncode() + "</copyright>");
	s.push("<pubDate>" + d.toGMTString() + "</pubDate>");
	s.push("<lastBuildDate>" + d.toGMTString() + "</lastBuildDate>");
	s.push("<docs>http://blogs.law.harvard.edu/tech/rss</docs>");
	s.push("<generator>TiddlyWiki " + version.major + "." + version.minor + "." + version.revision + "</generator>");
	// The body
	var tiddlers = store.getTiddlers("modified","excludeLists");
	var n = numRssItems > tiddlers.length ? 0 : tiddlers.length-numRssItems;
	for (var t=tiddlers.length-1; t>=n; t--){
		var f=(rssTags.length===0);
		for (var i = 0; i<rssTags.length; i++){
			if (tiddlers[t].tags.find(rssTags[i])!=null){f=true;break;}
		}
		if (f){s.push(tiddlers[t].saveToRss(u));}
	}
	// And footer
	s.push("</channel>");
	s.push("</rss>");
	// Save it all
	return s.join("\n");
};
//}}}