// Do Not Cache this RH
request.element.isStatic = 0;
csAuthMode = false;
if ( StructKeyExists(request,"renderstate") AND StructKeyExists(request.renderstate,"rendermode") AND ListFindNoCase("author,edit",request.renderstate.rendermode) )
csAuthMode = true;
blogDataArray = attributes.elementInfo.elementData.propertyValues;
itmCntr = 0;
// Config Values
// - Set the Link, Page and Subsite Defualts
baseLinkURL = ""; // Link to the Display page for the RSS feed Data
rootSiteURL = "http://" & CGI.HTTP_HOST;
// Get the feed Page ID from the current page
feedPageID = request.page.ID;
feedPageURL = Application.PTBlog2.csData.getCSPageURL(feedPageID);
// Set the base Page and Subsite defaults... to handle it if nothing is passed in
basePageURL = "";
baseSubsiteID = request.subsite.id;
baseSubsiteURL = request.subsiteCache[request.subsite.id].url;
// Build the site URL is the server is secure
if ( CGI.SERVER_PORT IS "443" )
rootSiteURL = "https://" & CGI.HTTP_HOST;
if ( structKeyExists(request.params,"pgid") AND IsNumeric(request.params.pgid) ) {
basePageURL = Application.Blog2.csData.getCSPageURL(request.params.pgid);
} else if ( structKeyExists(request.params,"ssid") AND IsNumeric(request.params.ssid) ) {
// If a pageID is not passed in, use the index page of the current subsite (set above) or a subsite ID that is passed in
// If a Subsite ID is passed in, use this for the subsite id
baseSubsiteID = request.params.ssid;
baseSubsiteURL = request.subsiteCache[baseSubsiteID].url;
}
// TODO: Add this to the CS Filter
recentPostDaysFilter = 90;
if (structKeyExists(request.params,"days") AND IsNumeric(request.params.days) AND request.params.days NEQ 0 )
recentPostDaysFilter = request.params.days;
recentPostDescriptionWordsLimit = 25;
if (structKeyExists(request.params,"words") AND IsNumeric(request.params.words) AND request.params.words NEQ 0 )
recentPostDescriptionWordsLimit = request.params.words;
showElementData = false;
if (structKeyExists(request.params,"elementdata") AND IsBoolean(request.params.elementdata) )
showElementData = request.params.elementdata;
showRSSdata = false;
if (structKeyExists(request.params,"rssdata") AND IsBoolean(request.params.rssdata) )
showRSSdata = request.params.rssdata;
outputRSS = false;
if ( !showRSSdata AND !showElementData AND StructKeyExists(request.params,"rss") AND IsBoolean(request.params.rss) AND request.params.rss EQ 1 )
outputRSS = true;
if ( showElementData )
Application.ptBlog2.utils.doDump(blogDataArray,"blogDataArray",0);
// Create the LinkURL fromt the basePageURL
if ( LEN(TRIM(basePageURL)) )
baseLinkURL = rootSiteURL & basePageURL;
else
baseLinkURL = rootSiteURL & baseSubsiteURL; // use the index page as the URL the base subsite
// Build the RSS feed struct
rssStruct = StructNew();
// The "link" is URL page the RSS feed references, not the URL of the FEED itself
// - This URL was built from location of the CS Page using this RH or from the subsite or pageID that was passed in
rssStruct.link = baseLinkURL;
rssStruct.title = "Recent Blog Posts"; // TODO: Add to configuration render handler Meta data
rssStruct.description = "RSS Feed for Recent Blog Posts"; // TODO: Add to configuration render handler Meta data
rssStruct.pubDate = Now();
rssStruct.version = "rss_2.0";
rssStruct.item = ArrayNew(1);
// Loop of Posts2 element data
for (itm=1;itm LTE ArrayLen(blogDataArray); itm=itm+1) {
//Application.ptBlog2.utils.doDump(blogDataArray[itm].values.blogID,"blogID",0);
// Get the meta data about the BLOG that this Blog Post is coming from
blogData = Application.ptBlog2.blogDAO.getBlog(blogDataArray[itm].values.blogID);
//Application.ptBlog2.utils.doDump(blogData,"blogData",0);
// Make sure the Blog is ACTIVE
if ( IsStruct(blogData) AND StructKeyExists(blogData,"active") AND blogData.active EQ true ) {
// Set 'baseLinkURL' adn the Default URL for each item
FormattedPostURL = baseLinkURL;
// Set the PageID for the Blog Post
postPageID = blogDataArray[itm].values.postPageID;
// If a PostPageID is available for the Post, get the Page URL from the pageid
if ( LEN(TRIM(postPageID)) AND IsNumeric(postPageID) )
FormattedPostURL = rootSiteURL & application.ptBlog2.CSData.getCSPageURL(pageID=blogDataArray[itm].values.postPageID);
// Formatted RSS Post Date
FormattedDatePosted = createDate(year(blogDataArray[itm].values.datePosted), month(blogDataArray[itm].values.datePosted), day(blogDataArray[itm].values.datePosted));
// Filter By Recent Posts
if ( DateCompare(FormattedDatePosted,DateAdd("d",-(recentPostDaysFilter),Now())) EQ 1) {
itmCntr = itmCntr + 1;
// Formatted RSS Title
FormattedTitle = application.ptBlog2.data.EscapeExtendedChars(Trim(blogDataArray[itm].values.title));
// Format RSS Description
FormattedDesciption = blogDataArray[itm].values.slug;
if ( LEN(TRIM(FormattedDesciption)) EQ 0 )
FormattedDesciption = blogDataArray[itm].values.content;
// Strip out Images from inside the blog post content block
FormattedDesciption = REReplace(FormattedDesciption,"]*>","","All");
// Escape Extended Characters
FormattedDesciption = application.ptBlog2.data.EscapeExtendedChars(FormattedDesciption);
//FormattedDesciption = Server.CommonSpot.UDF.data.ToHTML(FormattedDesciption);
//FormattedDesciption = Server.CommonSpot.UDF.data.FromHTML(FormattedDesciption);
// Strip HTML
FormattedDesciption = ReReplace(FormattedDesciption, "<[^>]*>", "", "all");
// Trim the number of words
FormattedDesciption = application.ptBlog2.data.trimStringByWordCount(FormattedDesciption,recentPostDescriptionWordsLimit,0);
// Make XML Safe (converts some characters to HTML entities )
// TODO: DO NOT USE... this logic needs some work before using this function
// FormattedDesciption = xmlFormat(FormattedDesciption);
// Build Feed ITEM substruct
rssStruct.item[itmCntr] = StructNew();
rssStruct.item[itmCntr].title = xmlFormat(FormattedTitle); // "2"
rssStruct.item[itmCntr].pubDate = FormattedDatePosted;
rssStruct.item[itmCntr].description = StructNew();
rssStruct.item[itmCntr].description.value = FormattedDesciption;
rssStruct.item[itmCntr].guid.isPermaLink = "YES";
rssStruct.item[itmCntr].guid.value = TRIM(FormattedPostURL);
rssStruct.item[itmCntr].link = TRIM(FormattedPostURL);
rssStruct.item[itmCntr].category = ArrayNew(1);
// extract the tags from the a comma-delimited list and assign to RSS categories
if ( structKeyExists(blogDataArray[itm].values, "tags") ) {
tagNameList = blogDataArray[itm].values.tags;
for (c=1;c LTE ListLen(tagNameList,","); c=c+1) {
rssStruct.item[itmCntr].category[c] = StructNew();
rssStruct.item[itmCntr].category[c].value = Trim(ListGetAt(tagNameList,c,","));
}
}
// retrieve the tag names for the tags
// IMPORTANT: This Requires ptTags App
/* if (structKeyExists(blogDataArray[itm].values, "tags") and LEN(TRIM(blogDataArray[itm].values.tags)) ) {
tagNameList = application.ptTags.tagsService.tagNameListByIDs(blogDataArray[itm].values.tags);
//Build Category Sub-Substruct for TAGS
for (cat=1;cat LTE ListLen(tagNameList,"^"); cat=cat+1) {
rssStruct.item[itmCntr].category[cat] = StructNew();
rssStruct.item[itmCntr].category[cat].value = ListGetAt(tagNameList,cat,"^");
}
} */
}
}
}
if ( showRSSdata )
Application.ptBlog2.utils.doDump(rssStruct,"rssStruct",0);