var feedArray = ArrayNew(1);
var feedData = StructNew();
var feedPageInfo = StructNew();
var feedStream = ArrayNew(1);
var feedService = StructNew();
var postQty = arguments.maxPosts;
var userData = StructNew();
var dt = "";
var postID = "";
var buildOp = "";
var feedStreamData = {};
var appConfigStruct = application.ptSocialMedia.getAppConfig();
// Determine post filter operator from chosen mode from app configuration
if ( LEN(TRIM(arguments.filterType)) EQ 0 AND structKeyExists(appConfigStruct,"filterType") AND LEN(TRIM(appConfigStruct['filterType'])) )
arguments.filterType = appConfigStruct['filterType'];
// Get the basic info about the registered account
feedPageInfo = application.ptSocialMedia.instagramFeedsDAO.getInstagramPageInfo(feedID=feedID);
// Get the the instagram feeds from the registered account
feedStreamData = application.ptSocialMedia.instagramFeedsDAO.getInstagramFeed(feedID=feedID,maxPosts=maxPosts);
if ( StructKeyExists(feedStreamData,'data') )
feedStream = feedStreamData.data;
else
{
// 'data' key not returned from the instagramFeedsDAO.getInstagramFeed call
doErrorLogging("instagram","instagramFeedsService.buildInstagramFeedData",feedStreamData,'Unable to Build the Instagram Feed Data for FeedID: #arguments.FeedID#');
application.ptSocialMedia.utils.doDUMP(feedStreamData,"instagramFeedsService.buildInstagramFeedData",0);
return feedArray;
}
if ( arguments.showFeedDump )
{
application.ptSocialMedia.utils.doDUMP(feedPageInfo,"Instagram-feedPageInfo (#arguments.FeedID#)",0);
application.ptSocialMedia.utils.doDUMP(feedStream,"Instagram-feedStream (#arguments.FeedID#)",0);
}
//application.ptSocialMedia.utils.doDUMP(arguments,"arguments (#arguments.FeedID#)",0);
//application.ptSocialMedia.utils.doDUMP(feedStream,"buildInstagramFeedData (updated) - Instagram-feedStream (#arguments.FeedID#)",0);
// Make sure the feedStream data is an Array
if ( IsArray(feedStream) ) {
// feedStream Count LT maxPosts
if ( ArrayLen(feedStream) LT postQty )
postQty = ArrayLen(feedStream);
for ( var d=1; d LTE postQty; d++ ) {
PostID = "";
if ( StructKeyExists(feedStream[d],"id") )
PostID = feedStream[d].id;
if ( LEN(TRIM(PostID)) )
buildOp = true;
// Disabled - Add all posts to the cache
/* if (arguments.filtertype EQ "excluded")
// Do not Build a Feed Data Struct for Posts that are part of the Excluded Posts List
buildOp = ListFindNoCase(arguments.filteredPostIDs, PostID) NEQ 0;
else
// Build a Feed Data Struct for Posts that are part of the included Posts List
buildOp = ListFindNoCase(arguments.filteredPostIDs, PostID) EQ 0;
*/
if (buildOp)
{
// Build the empty feed data structure
feedData = Application.ptSocialMedia.feedController.buildFeedDataFormat();
// Fill in the feedData structure with the post info
// General Post Metadata
feedService = Application.ptSocialMedia.instagramFeedsDAO.getInstagramMetadata();
StructAppend(feedData, feedService, true);
// Feed ID
feedData.FeedID = arguments.FeedID;
// Feed Type
feedData.FeedType = "status update";
// Instagram Page Name (from Page Info Feed)
if (StructKeyExists(feedPageInfo, "name"))
feedData.FeedName = feedPageInfo.name;
// Published Dates
if (StructKeyExists(feedStream[d], "timestamp")) {
dt = Application.ptSocialMedia.date.ISOToDateTimeStruct(feedStream[d].timestamp);
feedData.PublishedDate = dt.ISO8601DateTime;
feedData.csFormattedPublishedDate = dt.csDateTime;
feedData.Content.Date = dt.ISO8601DateTime;
feedData.Content.CSFormattedDate = dt.csDateTime;
// Post Content
// Content Post ID (ID)
feedData.Content.PostID = PostID;
// Content Message (Message)
if (StructKeyExists(feedStream[d], "caption"))
feedData.Content.Message = feedStream[d].caption;
// Content Link (Link)
if (StructKeyExists(feedStream[d], "permalink") AND len(feedStream[d].permalink)) {
feedData.Content.Link = feedStream[d].permalink;
} else {
feedData.Content.Link = application.ptSocialMedia.instagramFeedsDAO.getInstagramPostURL(feedID,postID);
}
// Content Thumbnail (picture)
// The media_url is typically a static image but if the post contains a video then this field will link to a video.
// Check for the thumbnail URL first which usually exists when the media_url is a video. Otherwise...
/*if (StructKeyExists(feedStream[d], "thumbnail_url")) {
feedData.Content.Thumbnail = feedStream[d].thumbnail_url;
}
else if (StructKeyExists(feedStream[d], "media_url")) {
// Grab the thumbnail from media_url since the post only contains a static image.
feedData.Content.Thumbnail = feedStream[d].media_url;
}*/
if (StructKeyExists(feedStream[d], "media_url")) {
// Grab the thumbnail from media_url since the post only contains a static image.
feedData.Content.Thumbnail = feedStream[d].media_url;
}
// Content Icon (icon)
if (StructKeyExists(feedStream[d], "icon"))
feedData.Content.icon = feedStream[d].icon;
// FB Like and Twitter Tweet Buttons
if (LEN(TRIM(feedData.Content.Link))) {
feedData.FBLikeBtn.link = feedData.Content.Link;
feedData.TweetBtn.link = feedData.Content.Link;
} else if (LEN(TRIM(feedData.Source.Link))) {
feedData.FBLikeBtn.link = feedData.Source.Link;
feedData.TweetBtn.link = feedData.Source.Link;
} else {
feedData.FBLikeBtn.link = feedData.FEEDLINK;
feedData.TweetBtn.link = feedData.FEEDLINK;
}
// Twitter Tweet Text
if (LEN(TRIM(feedData.Content.Title)))
feedData.TweetBtn.message = Left(feedData.Content.Title, 120);
else if (LEN(TRIM(feedData.Content.message)))
feedData.TweetBtn.message = Left(feedData.Content.message, 120);
else if (LEN(TRIM(feedData.Content.description)))
feedData.TweetBtn.message = Left(feedData.Content.description, 120);
// Add feedData Data Struct to the feedArray Data Array
ArrayAppend(feedArray, feedData);
}
} // END - buildOp logic
} // END - loop
}
//application.ptSocialMedia.utils.doDUMP(feedArray,"buildInstagramFeedData (updated) - feedArray (#arguments.FeedID#)",0);
return feedArray;
var pName = "";
var paramPos = 0;
var feedPos = 0;
// Get the FB PAGE NAME from the submitted URL
pName = arguments.pageURL;
// 1) Strip any URL parameters
paramPos = FindNoCase("?",pName);
if ( paramPos )
pName = ListFirst(pName,"?");
// 2) remove the 'feed' Subfolder, if needed
feedPos = ListFindNoCase(pName,"feed","/");
if ( feedPos GT 0 )
pName = ListDeleteAt(pName,feedPos,"/");
// 3) get the last part of the URL, which should be the pageName
pName = ListLast(pName,"/");
return TRIM(pName);