📄 picture.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using CommunityServer.Components;
namespace CommunityServer.Galleries.Components
{
/// <summary>
/// This class contains the properties that describe a Picture. It inherits from the base class <see cref="Post"/>.
/// </summary>
public class Picture : Post, IThread, IComparable
{
#region Custom Properties
/// <summary>
/// This property defines the width of the image
/// </summary>
public int Width
{
get
{
string val = GetExtendedAttribute( "Width" );
if(val != string.Empty)
return int.Parse(val);
else
return 0;
}
set { SetExtendedAttribute( "Width", value.ToString() ); }
}
/// <summary>
/// This property defines the height of the image
/// </summary>
public int Height
{
get
{
string val = GetExtendedAttribute( "Height" );
if(val != string.Empty)
return int.Parse(val);
else
return 0;
}
set { SetExtendedAttribute( "Height", value.ToString() ); }
}
/// <summary>
/// This property defines the ContentType for the image, such as "image/jpeg" or "image/gif".
/// </summary>
public string ContentType
{
get { return GetExtendedAttribute( "ContentType" ); }
set { SetExtendedAttribute( "ContentType", value); }
}
public int ImageSize
{
get
{
string val = GetExtendedAttribute( "ImageSize" );
if(val != string.Empty)
return int.Parse(val);
else
return 0;
}
set { SetExtendedAttribute( "ImageSize", value.ToString() ); }
}
public bool EnableComments
{
get
{
string val = GetExtendedAttribute( "EnableComments" );
if(val != string.Empty)
return bool.Parse(val);
else
return Galleries.GetGallery(this.SectionID).EnableComments;
}
set { SetExtendedAttribute( "EnableComments", value.ToString() ); }
}
public bool EnableExif
{
get
{
string val = GetExtendedAttribute( "EnableExif" );
if(val != string.Empty)
return bool.Parse(val);
else
return Galleries.GetGallery(this.SectionID).EnableExif;
}
set { SetExtendedAttribute( "EnableExif", value.ToString() ); }
}
public bool EnableRatings
{
get
{
string val = GetExtendedAttribute( "EnableRatings" );
if(val != string.Empty)
return bool.Parse(val);
else
return Galleries.GetGallery(this.SectionID).EnableRatings;
}
set { SetExtendedAttribute( "EnableRatings", value.ToString() ); }
}
#endregion
#region CompareTo
// *********************************************************************
// CompareTo
//
/// <summary>
/// All forums have a SortOrder property. CompareTo compares on SortOrder
/// to sort the forums appropriately.
/// </summary>
// ********************************************************************/
public int CompareTo(object value)
{
if(value == null) return 1;
return this.SortOrder.CompareTo( ((Picture)value).SortOrder );
}
#endregion
#region Static Properties
/// <summary>
/// This static method gets the location of the picture cache directory, mapped on the local filesystem.
/// </summary>
/// <returns>string</returns>
public static string CacheDirectory()
{
return CSContext.Current.Context.Server.MapPath(GalleryUrls.Instance().PictureCache);
}
public static string CacheFilename(int sectionID, int pictureID, GalleryImageType imageType, int width, int height)
{
switch(imageType)
{
case GalleryImageType.Thumbnail:
return CacheDirectory() + System.IO.Path.DirectorySeparatorChar + CSContext.Current.SiteSettings.SettingsID + "." + sectionID + "." + pictureID + ".thumb.jpg";
case GalleryImageType.SecondaryThumbnail:
return CacheDirectory() + System.IO.Path.DirectorySeparatorChar + CSContext.Current.SiteSettings.SettingsID + "." + sectionID + "." + pictureID + ".secondarythumb.jpg";
default:
return CacheFilename(sectionID, pictureID, width, height);
}
}
/// <summary>
/// This static method gets the filename and location of a cached picture with the specified width and height
/// setting on the local filesystem.
/// </summary>
/// <param name="sectionID">The SectionID of the <see cref="Gallery"/> the picture belongs to</param>
/// <param name="pictureID">The PictureID of the <see cref="Picture"/> the scaled image is of</param>
/// <param name="width">The width of the scaled image</param>
/// <param name="height">The heigh of the scaled image</param>
/// <returns>string</returns>
public static string CacheFilename(int sectionID, int pictureID, int width, int height)
{
return CacheDirectory() + System.IO.Path.DirectorySeparatorChar + CSContext.Current.SiteSettings.SettingsID + "." + sectionID + "." + pictureID + "." + width + "x" + height + ".jpg";
}
#endregion
#region Post Implementation
private Gallery _gallery = null;
public override Section Section
{
get
{
if(_gallery == null)
_gallery = Galleries.GetGallery(this.SectionID);
return _gallery;
}
set
{
_gallery = value as Gallery;
}
}
#endregion
#region IThread Privates
string mostRecentAuthor = ""; // Most recent post author
int mostRecentAuthorID = 0;
int mostRecentPostID = 0; // Most recent post id
int authorID = 0;
int ratingSum = 0;
int totalRatings = 0;
#endregion
#region IThread Public Properties
public int RatingSum
{
get
{
return ratingSum;
}
set
{
ratingSum = value;
}
}
public int TotalRatings
{
get
{
return totalRatings;
}
set
{
totalRatings = value;
}
}
public double ThreadRating
{
get
{
if (TotalRatings == 0)
return 0;
return ( (double) RatingSum / (double) TotalRatings );
}
}
ThreadStatus status = ThreadStatus.NotSet;
public ThreadStatus Status
{
get { return status; }
set { status = value; }
}
public int AuthorID
{
get
{
return authorID;
}
set
{
authorID = value;
}
}
// *********************************************************************
//
// IsPopular
//
/// <summary>
/// If thread has activity in the last 2 days and > 20 replies
/// </summary>
//
// ********************************************************************/
public bool IsPopular
{
get
{
if ((ThreadDate < DateTime.Now.AddDays(CSContext.Current.SiteSettings.PopularPostLevelDays)) && ( (Replies > CSContext.Current.SiteSettings.PopularPostLevelPosts) || (Views > CSContext.Current.SiteSettings.PopularPostLevelViews) ))
return true;
return false;
}
}
// *********************************************************************
//
// IsAnnouncement
//
/// <summary>
/// If post is locked and post date > 2 years
/// </summary>
//
// ********************************************************************/
public bool IsAnnouncement
{
get
{
if ((StickyDate > DateTime.Now.AddYears(2)) && (IsLocked))
return true;
else
return false;
}
}
bool isSticky = false;
public bool IsSticky
{
get
{
return isSticky;
}
set
{
isSticky = value;
}
}
DateTime stickyDate = DateTime.Now.AddYears(-25);
public DateTime StickyDate
{
get
{
return stickyDate;
}
set
{
stickyDate = value;
}
}
// *********************************************************************
//
// MostRecentPostAuthor
//
/// <summary>
/// The author of the most recent post in the thread.
/// </summary>
//
// ********************************************************************/
public string MostRecentPostAuthor
{
get
{
return mostRecentAuthor;
}
set
{
mostRecentAuthor = value;
}
}
public int MostRecentPostAuthorID
{
get
{
return mostRecentAuthorID;
}
set
{
mostRecentAuthorID = value;
}
}
public string PreviewBody
{
get
{
return Transforms.StripForPreview(base.Body);
}
}
// *********************************************************************
//
// MostRecentPostID
//
/// <summary>
/// The post id of the most recent post in the thread.
/// </summary>
//
// ********************************************************************/
public int MostRecentPostID
{
get
{
return mostRecentPostID;
}
set
{
mostRecentPostID = value;
}
}
#endregion
private int settingsID = -1;
public int SettingsID
{
get { return settingsID; }
set { settingsID = value; }
}
public bool IsPicture
{
get
{
string val = GetExtendedAttribute( "IsPicture" );
if(val != string.Empty)
return bool.Parse(val);
else
return true;
}
set { SetExtendedAttribute("IsPicture", value.ToString()); }
}
private PostAttachment pictureData = null;
public PostAttachment PictureData
{
get
{
if(pictureData == null)
pictureData = Pictures.GetPictureData(PostID);
return pictureData;
}
set { pictureData = value; }
}
private string[] categories;
/// <summary>
/// list of categories this post was made to
/// </summary>
public string[] Categories
{
get{return categories;}
set{categories = value;}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -