📄 sectionutility.cs
字号:
{
return GetInheritedSectionString( (int)drowSection[ "section_id" ], "section_pageStyle", dstSections );
}
//*********************************************************************
//
// GetInheritedWebBoxes Method
//
// Calculates the inherited Web boxes for a section.
//
//*********************************************************************
private static string[] GetInheritedWebBoxes(SectionInfo objSectionInfo, SectionCollection objSectionCollection)
{
while (objSectionInfo.ParentSectionID != -1)
{
objSectionInfo = objSectionCollection.GetSectionByID(objSectionInfo.ParentSectionID);
if (objSectionInfo.WebBoxes != null)
return objSectionInfo.WebBoxes;
}
return null;
}
//*********************************************************************
//
// GetInheritedWebServiceBoxes Method
//
// Calculates the inherited Web boxes for a section.
//
//*********************************************************************
private static string[] GetInheritedWebServiceBoxes(SectionInfo objSectionInfo, SectionCollection objSectionCollection)
{
while (objSectionInfo.ParentSectionID != -1)
{
objSectionInfo = objSectionCollection.GetSectionByID(objSectionInfo.ParentSectionID);
if (objSectionInfo.WebServiceBoxes != null)
return objSectionInfo.WebServiceBoxes;
}
return null;
}
//SMR - Enh - Begin: Add inherit web box display mode
public static int GetInheritedSectionWebBoxDisplayMode(SectionInfo objSectionInfo, SectionCollection objSectionCollection)
{
while (objSectionInfo.ParentSectionID != -1)
{
objSectionInfo = objSectionCollection.GetSectionByID(objSectionInfo.ParentSectionID);
if (!objSectionInfo.IsWebBoxesInherited)
{
break;
}
}
return objSectionInfo.WebBoxDisplayMode;
}
public static int GetInheritedSectionWebServiceBoxDisplayMode(SectionInfo objSectionInfo, SectionCollection objSectionCollection)
{
while (objSectionInfo.ParentSectionID != -1)
{
objSectionInfo = objSectionCollection.GetSectionByID(objSectionInfo.ParentSectionID);
if (!objSectionInfo.IsWebServiceBoxesInherited)
{
break;
}
}
return objSectionInfo.WebServiceBoxDisplayMode;
}
//SMR - Enh - End: Add inherit web box display mod
//*********************************************************************
//
// GetInheritedSectionString Method
//
// Support method for calculating inherited section properties.
//
//*********************************************************************
private static string GetInheritedSectionString(int intSectionID, string strColName, DataSet dstSections)
{
DataRow[] drowMatches;
string strMatchString;
strMatchString = "section_id=" + intSectionID.ToString();
drowMatches = dstSections.Tables[0].Select( strMatchString );
while ( ((string)drowMatches[0][strColName]).Trim()==String.Empty && (int)drowMatches[0]["section_parentID"]!=-1)
{
strMatchString = "section_id=" + drowMatches[0]["section_parentID"].ToString();
drowMatches = dstSections.Tables[0].Select( strMatchString );
}
return (string)drowMatches[0][strColName];
}
//*********************************************************************
//
// CalculateTransformations Method
//
// Precooks transformations for this section.
//
//*********************************************************************
public static string CalculateTransformations(DataRow drowSection, DataSet dstSections)
{
string transformations;
string trans;
StringBuilder builder = new StringBuilder();
// Check for inheritance
if ((bool)drowSection["section_inheritTransformations"])
transformations = GetInheritedTransformations( (int)drowSection[ "section_id" ], dstSections );
else
transformations = (string)drowSection["section_transformations"];
// Trim and split transformations
transformations = transformations.Trim();
string[] splitTrans = Regex.Split(transformations, "\n");
// Parse the transformations
foreach (string line in splitTrans)
{
trans = line;
if (trans.ToLower().StartsWith("from:"))
{
trans = trans.Remove(0, 5).Trim();
trans = Regex.Escape(trans);
trans = trans.Replace("<CONTENTS>", @"((.|\n)*?)");
trans = trans.Replace("<WORDBOUNDARY>", @"\b");
// SMR - Enh - Begin: Uniform Translation.
// Moved these conditionally to the CommunityGlobals.ApplyTransformations();
// trans = trans.Replace("<", "<");
// trans = trans.Replace(">", ">");
// trans = trans.Replace("\"", """);
// SMR - Enh - End: Uniform Translation.
}
if (trans.ToLower().StartsWith("to:"))
{
trans = trans.Remove(0, 3).Trim();
trans = trans.Replace("<CONTENTS>", "$1");
trans = trans.Replace( "~/", CommunityGlobals.AppPath + "/Communities/Common/Images/");
}
builder.AppendFormat("{0}\n", trans);
}
return builder.ToString();
}
//*********************************************************************
//
// GetInheritedTransformations Method
//
// Calculates the inherited transformations for a section.
//
//*********************************************************************
public static string GetInheritedTransformations(int intSectionID, DataSet dstSections)
{
DataRow[] drowMatches;
string matchString;
matchString = "section_id=" + intSectionID.ToString();
drowMatches = dstSections.Tables[0].Select( matchString );
while ( ((bool)drowMatches[0]["section_inheritTransformations"]) && (int)drowMatches[0]["section_parentID"]!=-1)
{
matchString = "section_id=" + drowMatches[0]["section_parentID"].ToString();
drowMatches = dstSections.Tables[0].Select( matchString );
}
return (string)drowMatches[0]["section_transformations"];
}
//*********************************************************************
//
// GetSectionInfoFromPath Method
//
// Returns section information based on the path to a section.
//
//*********************************************************************
public static SectionInfo GetSectionInfoFromPath(string requestBasePath)
{
SectionCollection sectionCollection = GetAllEnabledSections();
return sectionCollection[requestBasePath + "default.aspx"];
}
//*********************************************************************
//
// GetDefaultSectionInfo Method
//
// Returns section information for the default (home) section.
//
//*********************************************************************
public static SectionInfo GetDefaultSectionInfo()
{
return GetAllEnabledSections().DefaultSection;
}
//*********************************************************************
//
// DefaultSectionID Property
//
// Returns the ID of the default (home) section.
//
//*********************************************************************
public static int DefaultSectionID
{
get { return GetDefaultSectionInfo().ID; }
}
//*********************************************************************
//
// GetSectionInfoFromDB Method
//
// Gets section information by doing a database lookup.
//
//*********************************************************************
public static SectionInfo GetSectionInfoFromDB(int sectionID)
{
SqlDataAdapter dadSections = new SqlDataAdapter( "Community_SectionsGetSectionInfo", CommunityGlobals.ConnectionString );
dadSections.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSections.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSections.SelectCommand.Parameters.Add( "@sectionID", sectionID );
SqlDataAdapter dadSectionSecurity = new SqlDataAdapter( "Community_SectionsGetSectionRoles", CommunityGlobals.ConnectionString );
dadSectionSecurity.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSectionSecurity.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSectionSecurity.SelectCommand.Parameters.Add( "@sectionID", sectionID );
SqlDataAdapter dadSectionWebBoxes = new SqlDataAdapter( "Community_SectionsGetSectionWebBoxes", CommunityGlobals.ConnectionString );
dadSectionWebBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSectionWebBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSectionWebBoxes.SelectCommand.Parameters.Add( "@sectionID", sectionID );
SqlDataAdapter dadSectionWebServiceBoxes = new SqlDataAdapter( "Community_SectionsGetSectionWebServiceBoxes", CommunityGlobals.ConnectionString );
dadSectionWebServiceBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
dadSectionWebServiceBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
dadSectionWebServiceBoxes.SelectCommand.Parameters.Add( "@sectionID", sectionID );
DataSet dstSections = new DataSet();
dadSections.Fill( dstSections, "Sections" );
dadSectionSecurity.Fill( dstSections, "Security" );
dadSectionWebBoxes.Fill( dstSections, "WebBoxes" );
dadSectionWebServiceBoxes.Fill( dstSections, "WebServiceBoxes" );
if (dstSections.Tables[0].Rows.Count > 0)
{
dstSections.Tables[0].Columns.Add("section_path");
dstSections.Tables[0].Rows[0]["section_path"] = "";
return new SectionInfo( dstSections.Tables["Sections"].Rows[0], dstSections.Tables["Security"].Select(), dstSections.Tables["WebBoxes"].Select(), dstSections.Tables["WebServiceBoxes"].Select() );
}
else
return null;
}
//*********************************************************************
//
// GetSectionNameFromID Method
//
// Returns the section name given the section ID.
//
//*********************************************************************
public static string GetSectionNameFromID(int sectionID)
{
SectionInfo objSectionInfo = GetAllEnabledSections().GetSectionByID(sectionID);
return objSectionInfo.Name;
}
//*********************************************************************
//
// GetSectionPath Method
//
// Returns the path for a section with a particular ID.
//
//*********************************************************************
public static string GetSectionPath(int sectionID)
{
SectionInfo objSectionInfo = GetAllEnabledSections().GetSectionByID(sectionID);
return objSectionInfo.Path;
}
//*********************************************************************
//
// GetSectionInfo Method
//
// Returns section information given a section ID.
//
//*********************************************************************
public static SectionInfo GetSectionInfo(int sectionID)
{
SectionInfo objSectionInfo = GetAllEnabledSections().GetSectionByID(sectionID);
return objSectionInfo;
}
//*********************************************************************
//
// MayModerate Method
//
// Determines whether a particular user can moderate a particular
// section.
//
//*********************************************************************
public static bool MayModerate(UserInfo userInfo, int sectionID)
{
SectionInfo sectionInfo = GetSectionInfo(sectionID);
// If moderation disabled, it passes
if (!sectionInfo.EnableModeration)
return true;
if (CheckAuthenticatedPermission(sectionInfo.ModerateRoles))
return true;
else
return false;
}
//*********************************************************************
//
// GetAuthenticatedPermission Method
//
// Support method for determining a user's permissions for a
// section.
//
//*********************************************************************
private static bool CheckAuthenticatedPermission(string[] sectionRoles)
{
// If Everyone has permission, return true
if (Array.IndexOf( sectionRoles, "Community-Everyone" ) != -1)
return true;
// If Authenticated has permission, return true
if (Array.IndexOf( sectionRoles, "Community-Authenticated" ) != -1)
return true;
// Otherwise, check each role
foreach (string role in sectionRoles)
if (HttpContext.Current.User.IsInRole(role))
return true;
// Nope, doesn't have permissions
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -