var itmCnt = 0;
var itm = 1;
var eventsData = arguments.eventsDataArray;
// Config Values
var rootSiteURL = "http://" & CGI.HTTP_HOST;
var viewParamName = application.ptCalendar.viewParamName;
var defaultDisplayView = application.ptCalendar.defaultView;
// Set the base Link, Page and Subsite Defaults
// - Get the feed Page ID and URL from the current page
var baseFeedPageID = request.page.ID;
var baseFeedPageURL = application.ptCalendar.csData.getCSPageURL(baseFeedPageID);
// - Get the feed Subsite ID and URL from the current page
var baseFeedSubsiteID = request.subsite.id;
var baseFeedSubsiteURL = request.subsiteCache[baseFeedSubsiteID].url;
// - Set the Base Feed URL
// -- Link to the Display page for the Main Content
var baseFeedLinkURL = "";
var eventDaysFilter = 30;
var eventDescriptionWordsLimit = 25;
var showFeedData = false;
var FeedDateTime = Now();
var rssStruct = StructNew();
var FormattedDate = "";
var FormattedDateTime = "";
var FormattedTitle = "";
var FormattedDesciption = "";
var FormattedContentLink = "";
var catTextStr = "";
var categoryArray = ArrayNew(1);
var c = 1;
var catCnt = 1;
var viewLinkData =StructNew();
var qParamDelimiter = "?";
var linkedFeedView = defaultDisplayView; // Set
var detailLink = "";
var dailyLink = "";
var weeklyListLink = "";
var weeklyGridLink = "";
var monthlyListLink = "";
var monthlyGridLink = "";
// 1) rootSiteURL - The URL of the root site
// 2) The URL for the Feed
// 3) The URL for the page where the user subscribed to the Feed
// 4) The URL for the links to the Content items
if (structKeyExists(arguments,"days") AND IsNumeric(arguments.days) AND arguments.days NEQ 0 )
eventDaysFilter = arguments.days;
if (structKeyExists(arguments,"words") AND IsNumeric(arguments.words) AND arguments.words NEQ 0 )
eventDescriptionWordsLimit = arguments.words;
if (structKeyExists(arguments,"renderFeedData") AND IsBoolean(arguments.renderFeedData) )
showFeedData = arguments.renderFeedData;
if ( LEN(TRIM(arguments.linkedPage)) EQ 0 AND LEN(TRIM(arguments.linkedSubsite)) EQ 0 ) {
arguments.linkedPage = baseFeedPageURL;
arguments.linkedSubsite = baseFeedSubsiteURL;
}
/*if ( IsNumeric(arguments.linkedPage) )
baseFeedLinkURL = application.ptCalendar.csData.getCSPageURL(arguments.linkedPage);
else
baseFeedLinkURL = arguments.linkedPage;*/
// Get the view link data structure
if ( application.ptCalendar.viewPageMode EQ "Single" ) {
if ( LEN(TRIM(arguments.linkedPage)) )
viewLinkData = application.ptCalendar.calRenderViewService.getCalViewPageStruct(pageURL=arguments.linkedPage);
else
viewLinkData = application.ptCalendar.calRenderViewService.getCalViewPageStruct();
// Reset the query param initial delimiter to &
qParamDelimiter = "&";
//baseFeedLinkURL = baseFeedLinkURL & "?" & viewParamName & "=" & linkedFeedView;
}
else {
if ( LEN(TRIM(arguments.linkedSubsite)) )
viewLinkData = application.ptCalendar.calPageMapDAO.getCalPageMapStruct(subsiteID=arguments.linkedSubsite);
else
viewLinkData = application.ptCalendar.calPageMapDAO.getCalPageMapStruct();
}
//application.ptCalendar.utils.doDump(baseFeedLinkURL,"baseFeedLinkURL",0);
//application.ptCalendar.utils.doDump(viewLinkData,"viewLinkData",0);
if( structKeyExists(viewLinkData, "detailPage") and len(trim(viewLinkData.detailPage)) )
detailLink = viewLinkData.detailPage;
if( structKeyExists(viewLinkData, "dailyPage") and len(trim(viewLinkData.dailyPage)) )
dailyLink = viewLinkData.dailyPage;
if( structKeyExists(viewLinkData, "weeklyListPage") and len(viewLinkData.weeklyListPage) )
weeklyListLink = viewLinkData.weeklyListPage;
if( structKeyExists(viewLinkData, "weeklyGridPage") and len(viewLinkData.weeklyGridPage) )
weeklyGridLink = viewLinkData.weeklyGridPage;
if( structKeyExists(viewLinkData, "monthlyListPage") and len(viewLinkData.monthlyListPage) )
monthlyListLink = viewLinkData.monthlyListPage;
if( structKeyExists(viewLinkData, "monthlyGridPage") and len(viewLinkData.monthlyGridPage) )
monthlyGridLink = viewLinkData.monthlyGridPage;
// Get the Full Calendar View Link
baseFeedLinkURL = monthlyGridLink;
defaultViewPageVar = application.ptcalendar.calRenderViewDAO.getCalendarDefaultViewPageVar();
if( structKeyExists(viewLinkData,defaultViewPageVar) and LEN(TRIM(viewLinkData[defaultViewPageVar])) )
baseFeedLinkURL = viewLinkData[defaultViewPageVar];
//application.ptCalendar.utils.doDump(baseFeedLinkURL,"baseFeedLinkURL",0);
// Build the site URL is the server is secure
if ( CGI.SERVER_PORT IS "443" )
rootSiteURL = "https://" & CGI.HTTP_HOST;
//application.ptCalendar.utils.doDump(rootSiteURL,"rootSiteURL",1);
// Create the LinkURL from the basePageURL
if ( LEN(TRIM(baseFeedLinkURL)) )
FeedPageURL = rootSiteURL & baseFeedLinkURL;
else
FeedPageURL = rootSiteURL & baseSubsiteURL; // use the index page (index.cfm) as the URL for FeedPageURL
FeedPageURL = server.commonspot.udf.html.unescape(FeedPageURL);
//application.ptCalendar.utils.doDump(FeedPageURL,"FeedPageURL",1);
// Build the RSS feed struct
rssStruct = StructNew();
rssStruct.title = arguments.feedTitle;
rssStruct.description = arguments.feedDescription;
rssStruct.pubDate = FeedDateTime;
rssStruct.version = "rss_2.0";
rssStruct.item = ArrayNew(1);
rssStruct.lastBuildDate = FeedDateTime;
// The "link" is URL page the RSS feed references, not the URL of the FEED itself
// - This URL is built from location of the CS Page using this RH or from the subsite or pageID that was passed in
rssStruct.link = FeedPageURL;
// Loop over events data
for ( itm=1; itm LTE ArrayLen(eventsData); itm=itm+1 ) {
// Build the event details link with URL params for the occurrence
// There may be many Event Records with the the same calEventID (recurring events or an event with multiple date times)
// - Each ocurrence of a recurring event gets a unique dtHashID
// - Each "date/time" record for an event gets a unique dateTimeID
linkParamsData = application.ptCalendar.calRenderService.buildEventDetailsLinksParams(eventDataStruct=eventsData[itm]);
eventDetailLink = application.ptCalendar.calRenderService.buildLinkParamURL(
linkURL=detailLink
,linkParamName=linkParamsData.UIDvarName
,linkParamValue=linkParamsData.UIDvalue
,urlParams=""
);
//application.ptCalendar.utils.doDump(eventDetailLink,"eventDetailLink (#itm#)",1);
//application.ptCalendar.utils.doDump(eventDetailLink,"eventDetailLink (#itm#)",1);
// Build a Unique Feed ID string
eventFeedID = linkParamsData.UIDstring;
//application.ptCalendar.utils.doDump(eventFeedID,"eventFeedID (#itm#)",1);
// Build the Formatted Link to the Content
FormattedContentLink = rootSiteURL & eventDetailLink;
FormattedContentLink = server.commonspot.udf.html.unescape(FormattedContentLink);
//application.ptCalendar.utils.doDump(FormattedContentLink,"FormattedContentLink (#itm#)",1);
// Build Formatted Feed item Date
FormattedDate = createDate(year(eventsData[itm].eventDate), month(eventsData[itm].eventDate), day(eventsData[itm].eventDate));
//application.ptCalendar.utils.doDump(FormattedDate,"FormattedDate (#itm#)",1);
// Filter By Recent Posts
if ( DateCompare(eventsData[itm].eventDate,DateAdd("d",-(eventDaysFilter),Now())) EQ 1) {
itmCnt = itmCnt + 1;
// Build Formatted Feed item Date/Time from the Event Date and the Event Start Time
if ( StructKeyExists(eventsData[itm],"AllDay") AND eventsData[itm].AllDay EQ 1 )
FormattedDateTime = createDateTime(year(eventsData[itm].eventDate), month(eventsData[itm].eventDate), day(eventsData[itm].eventDate),0,0,0);
else if ( StructKeyExists(eventsData[itm],"startTime") AND LEN(TRIM(eventsData[itm].startTime)) )
FormattedDateTime = createDateTime(year(eventsData[itm].eventDate), month(eventsData[itm].eventDate), day(eventsData[itm].eventDate),hour(eventsData[itm].startTime),minute(eventsData[itm].startTime),0);
//application.ptCalendar.utils.doDump(FormattedDateTime,"FormattedDateTime (#itm#)",1);
// Formatted RSS Title
FormattedTitle = Trim(eventsData[itm].title);
// Append the Recurrence info to the Title
if ( StructKeyExists(eventsData[itm],"dateTimeID") AND StructKeyExists(eventsData[itm],"dthashID") ) {
if ( LEN(TRIM(eventsData[itm].dateTimeID)) AND LEN(TRIM(eventsData[itm].dthashID)) )
FormattedTitle = FormattedTitle & " [R*]"; // [R*] Broken Recurrence
else if ( LEN(TRIM(eventsData[itm].dthashID)) AND LEN(TRIM(eventsData[itm].dateTimeID)) EQ 0 )
FormattedTitle = FormattedTitle & " [R]"; // [R] Recurrence
}
// Make XML Safe (converts some characters to HTML entities )
FormattedTitle = XMLFormat(FormattedTitle);
//application.ptCalendar.utils.doDump(FormattedTitle,"FormattedTitle (#itm#)",1);
// Format RSS Description
FormattedDesciption = Trim(eventsData[itm].description);
// Strip out Images from inside the calendar event description text block
FormattedDesciption = REReplace(FormattedDesciption,"]*>"," ","All");
// Strip HTML
FormattedDesciption = application.ptCalendar.data.stripHTMLtags(str=FormattedDesciption,replaceStr=" ");
// Trim the number of words
FormattedDesciption = application.ptCalendar.data.trimStringByWordCount(FormattedDesciption,eventDescriptionWordsLimit,0);
// Make XML Safe (converts some characters to HTML entities )
FormattedDesciption = XMLFormat(FormattedDesciption);
//application.ptCalendar.utils.doDump(FormattedDesciption,"FormattedDesciption (#itm#)",1);
// Build Feed ITEM substruct
rssStruct.item[itmCnt] = StructNew();
rssStruct.item[itmCnt].title = FormattedTitle;
rssStruct.item[itmCnt].pubDate = FormattedDateTime;
rssStruct.item[itmCnt].link = TRIM(FormattedContentLink);
rssStruct.item[itmCnt].description = StructNew();
rssStruct.item[itmCnt].description.value = FormattedDesciption;
rssStruct.item[itmCnt].guid.isPermaLink = "yes";
rssStruct.item[itmCnt].guid.value = TRIM(FormattedContentLink);
rssStruct.item[itmCnt].category = ArrayNew(1);
// convert the category ID to the Feed categories struct
if ( StructKeyExists(eventsData[itm],"Category") AND LEN(TRIM(eventsData[itm].Category)) ){
// Get Category Data based on Cat UUIDs --->
categoryArray = application.ptCalendar.calEventCategoriesDAO.getEventCategories(uniqueID=eventsData[itm].Category);
if ( ArrayLen(categoryArray) ) {
catCnt = 1;
for ( c=1; c LTE ArrayLen(categoryArray); c=c+1 ) {
if ( StructKeyExists(categoryArray[c],"values") AND StructKeyExists(categoryArray[c].values,"name") AND LEN(TRIM(categoryArray[c].values.name)) ) {
rssStruct.item[itmCnt].category[catCnt] = StructNew();
rssStruct.item[itmCnt].category[catCnt].value = categoryArray[c].values.name;
catCnt = catCnt + 1;
}
}
}
}
}
}
if ( showFeedData )
application.ptCalendar.utils.doDump(rssStruct,"rssStruct",0);
return rssStruct;
var rssStruct = arguments.rssEventStruct;
var rssXML = "";
#rssXML#
var retHTML = "";