|
CS 2.1 support for unpublished photos |
|
So I have a very cool gallery mod, I am about to release, but it relies on a late add feature to CS 2.1, unpublished posts. I took the idea from blogs, and added support for unpublishing posts, and while the control panel mechanics are there and work just fine (you can make an un published photo, or take a published photo and unpublish it) several of the UI controls, or more specifically "thread queries" weren't updated to only display published content. I have since checked in a fix for this which will be released with the next CS 2.1 service pack (sp3), but want to outline the changes for those with the SDK who might want this change sooner than later...
The fix involves adding a property to the thread query argument in 6 files, and a tweak to the get random post function; the changes are as follows. (line numbers are approximate)
/Galleries/Controls/Aggregate/AggregatePortalPictureScroller.cs (line 380)
public override void DataBind()
{
[...]
query.ApplicationPostType = GalleryPostType.Image;
query.PublishedFilter = GalleryPostPublishedFilter.Published;
ArrayList pictures = GalleryPosts.GetPictures(query, true, true).Threads;
[...]
}
/Galleries/Controls/PictureDetails.cs (line 108, and line 144)
private
void BindData()
{
[...]
query.SectionID = CurrentGallery.SectionID;
query.PublishedFilter =
GalleryPostPublishedFilter.Published;
PostSet ps = GalleryPosts.GetPostSet(query);
[...]
pagerQuery.IncludePageIndex = true;
//Only load published photos into the pager
pagerQuery.PublishedFilter = GalleryPostPublishedFilter.Published;
//For CS 1.2 we are dropping the option to let the user sort
[...]
}
/Galleries/Controls/Slideshow.cs (line 120)
protected override void CreateChildControls()
{
[...]
query.ApplicationPostType = GalleryPostType.Image;
query.PublishedFilter =
GalleryPostPublishedFilter.Published;
pictures =
GalleryPosts.GetPictures(query).Threads;
[...]
}
/Galleries/Components/TrackBackHandler.cs (line 206)
private static bool IsNewTrackBack(GalleryPost post, string trackbackUrl)
{
[...]
query.ReturnFullThread = true;
query.PublishedFilter =
GalleryPostPublishedFilter.Published;
PostSet ps = GalleryPosts.GetPostSet(query) ;
[...]
}
/Galleries/GalleryPosts.cs (line 256 a new GetRandomPicture method and line 290)
public static GalleryPost GetRandomPicture(int galleryID, int categoryID)
{
CSContext cSContext = CSContext.Current;
string cacheKey = "RandomPicture-Gallery:" + galleryID + "-Category:" + categoryID;
int postID = -1;
if (!cSContext.Items.Contains(cacheKey))
{
//Get random post does not support moderated posts, so use a thread query
//postID = GalleryDataProvider.Instance().GetRandomPostID(galleryID, categoryID);
GalleryThreadQuery query = new GalleryThreadQuery();
query.SectionID = galleryID;
query.PageIndex = 0;
query.PageSize = 999999;
query.ApplicationPostType = GalleryPostType.Image;
query.PublishedFilter = GalleryPostPublishedFilter.Published;
if (categoryID > 0)
query.CategoryID = categoryID;
ArrayList threads = GalleryPosts.GetPictures(query).Threads;
if(threads != null && threads.Count > 0)
{
Random r = new Random();
int i = r.Next(0, threads.Count-1);
GalleryPost post = (GalleryPost) threads
;
cSContext.Items.Add(cacheKey, post.PostID);
return post;
}
}
else
postID = (int)cSContext.Items[cacheKey];
if (postID == -1)
return null;
else
return GetPicture(postID);
}
public static GalleryPost GetFirstPicture(int galleryID, int categoryID)
{
[...]
query.SortOrder = g.ThreadSortOrder;
query.PublishedFilter =
GalleryPostPublishedFilter.Published;
ThreadSet ts = GalleryPosts.GetPictures(query);
[...]
}
/Galleries/Components/Syndication/GalleryRssHandler.cs (line 115)
protected override CachedFeed BuildFeed()
{
[...]
query.PageSize = GalleryConfig.RssDefaultThreadsPerFeed;
query.PublishedFilter = GalleryPostPublishedFilter.Published;
if (Tags != null && Tags.Length > 0)
[...]
}
/Galleries/Components/Syndication/GalleryCommentRssHandler.cs (line 45)
protected override CachedFeed BuildFeed()
{
[...]
query.PageSize = GalleryConfig.RssDefaultThreadsPerFeed;
query.PublishedFilter =
GalleryPostPublishedFilter.Published;
PostSet ps = GalleryPosts.GetPostSet(query) ;
[...]
}