📄 labeltransform.cs
字号:
{
return SiteConfig.SiteInfo.VirtualPath;
}
return SiteConfig.SiteInfo.SiteUrl;
case "adpath":
return (SiteConfig.SiteInfo.VirtualPath + SiteConfig.SiteOption.AdvertisementDir);
}
return ("[err:SiteConfig没有'" + labelName + "'这个内置方法]");
}
private static int GetSpecialPosition(string content, int beginPoint)
{
string pattern = "^(([^<]*>)[^<]{0,100})(?:<p|<img|<br|<li)*";
MatchCollection matchs = new Regex(pattern, RegexOptions.IgnoreCase).Matches(content, beginPoint);
if (matchs.Count > 0)
{
return (matchs[0].Length + beginPoint);
}
return beginPoint;
}
private static bool LogLabelTransformException(LabelInfo labelInfo)
{
if (labelInfo.Error >= 2)
{
ILog log = LogFactory.CreateLog();
LogInfo info = new LogInfo();
info.Category = LogCategory.Exception;
info.Priority = LogPriority.High;
info.Message = labelInfo.LabelContent.ToString();
info.ScriptName = HttpContext.Current.Request.RawUrl;
info.Source = "标签:\"" + labelInfo.OriginalData["id"] + "\"";
info.Timestamp = DateTime.Now;
info.Title = "标签:\"" + labelInfo.OriginalData["id"] + "\"引发异常";
info.UserIP = PEContext.Current.UserHostAddress;
info.UserName = "";
log.Add(info);
return true;
}
return false;
}
private static void ManualPage(ContentPageInfo contentPageInfo)
{
string pattern = @"\[NextPage(.*?)\]";
Regex regex = new Regex(pattern, RegexOptions.Compiled);
string format = "<select Name='PageSelect' id='PageSelect' onchange=javascript:window.location=(this.options[this.selectedIndex].value)>{0}</select>";
StringBuilder builder = new StringBuilder();
int num = 1;
foreach (Match match in regex.Matches(contentPageInfo.Content))
{
if (!string.IsNullOrEmpty(match.Groups[1].Value.Trim()))
{
builder.Append("<option ");
if (contentPageInfo.CurrentPage == num)
{
builder.Append(" selected=\"true\" ");
}
if (num == 1)
{
builder.Append(" value=\"" + contentPageInfo.PageName.Replace("_{$pageid/}", "") + "\"");
}
else
{
builder.Append(" value=\"" + contentPageInfo.PageName.Replace("{$pageid/}", num.ToString()) + "\"");
}
builder.Append(">");
builder.Append("第 " + num.ToString() + " 页:");
builder.Append(match.Groups[1].Value);
builder.Append("</option>");
}
num++;
}
if (builder.Length > 0)
{
format = "<p>" + string.Format(format, builder.ToString()) + "</p>";
}
else
{
format = string.Empty;
}
contentPageInfo.Content = regex.Replace(contentPageInfo.Content, "[NextPage]");
pattern = @"\[NextPage\]";
string[] strArray = new Regex(pattern, RegexOptions.Compiled).Split(contentPageInfo.Content);
if (contentPageInfo.CurrentPage <= strArray.Length)
{
if (string.IsNullOrEmpty(StringHelper.StripTags(strArray[0].Replace("\r\n", ""))))
{
contentPageInfo.PageNum = strArray.Length - 1;
contentPageInfo.Content = format + strArray[contentPageInfo.CurrentPage];
}
else
{
contentPageInfo.PageNum = strArray.Length;
contentPageInfo.Content = format + strArray[contentPageInfo.CurrentPage - 1];
}
}
}
private static LabelInfo SqlAttributesProc(LabelInfo labelInfo)
{
string str = labelInfo.LabelDefineData["LabelDataType"];
switch (str)
{
case "static":
labelInfo.LabelContent = new StringBuilder("static");
return labelInfo;
case "sql_syscommand":
labelInfo.TotalPub = dal.GetSqlCommand(labelInfo);
labelInfo.LabelContent = new StringBuilder("QueryLabel");
return labelInfo;
case "sql_sysquery":
return dal.GetSqlQuery(labelInfo);
case "sql_sysstoredcommand":
labelInfo.TotalPub = dal.GetStoreCommand(labelInfo);
labelInfo.LabelContent = new StringBuilder("QueryLabel");
return labelInfo;
case "sql_sysstoredquery":
return dal.GetStoreQuery(labelInfo);
case "sql_outquery":
return dal.GetOutSqlQuery(labelInfo);
case "xml_read":
return dal.GetXmlQuery(labelInfo);
case "ole_read":
return dal.GetOleQuery(labelInfo);
case "odbc_read":
return dal.GetOdbcQuery(labelInfo);
case "orc_read":
return dal.GetOracleQuery(labelInfo);
}
labelInfo.LabelContent = new StringBuilder("[err:错误的查询类型," + str + "]");
return labelInfo;
}
private static StringBuilder StaticLabelProc(LabelInfo labelInfo, StringBuilder labeltemplate)
{
string strA = (labelInfo.LabelDefineData["OutType"] == null) ? "" : labelInfo.LabelDefineData["OutType"].Trim();
if (string.Compare(strA, "txt", true) == 0)
{
StringBuilder builder = new StringBuilder(labeltemplate.ToString());
foreach (string str2 in labelInfo.AttributesData.AllKeys)
{
builder.Replace("<xsl:value-of select=\"$" + str2 + "\"/>", labelInfo.AttributesData[str2]);
}
return builder;
}
StringBuilder sb = new StringBuilder();
XmlDocument document = new XmlDocument();
document.LoadXml("<root>abc</root>");
XPathNavigator navigator = document.CreateNavigator();
XsltArgumentList arguments = new XsltArgumentList();
XslCompiledTransform cacheXslCompiledTransform = GetCacheXslCompiledTransform(labelInfo, labeltemplate.ToString());
if (cacheXslCompiledTransform == null)
{
return labelInfo.LabelContent;
}
foreach (string str3 in labelInfo.AttributesData.AllKeys)
{
arguments.AddParam(str3, "", labelInfo.AttributesData[str3]);
}
arguments.AddExtensionObject("labelproc", InsideStaticLabelObject);
try
{
cacheXslCompiledTransform.Transform((IXPathNavigable) navigator, arguments, (TextWriter) new StringWriter(sb));
}
catch (XsltException exception)
{
sb = new StringBuilder("[err:标签'" + labelInfo.OriginalData["id"] + "'模板转换错误,原因:" + exception.Message + "]");
}
return sb;
}
public static void TransContentPageLabel(ContentPageInfo contentPageInfo)
{
if (!string.IsNullOrEmpty(contentPageInfo.Content))
{
XmlDocument document = new XmlDocument();
string strA = string.Empty;
int num = 2;
try
{
document.LoadXml(contentPageInfo.Parameter);
XmlElement firstChild = (XmlElement) document.FirstChild;
strA = XmlManage.GetAttributesValue(firstChild, "mode");
num = DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "pagesize"), 2);
}
catch (XmlException)
{
throw new XmlException("内容分页标签解析错误!");
}
if (string.Compare(strA, "auto", true) == 0)
{
contentPageInfo.Content = contentPageInfo.Content.Replace("[NextPage]", string.Empty);
int length = contentPageInfo.Content.Length;
if ((num > 100) && (length > num))
{
contentPageInfo.PageNum = length / num;
if ((num * contentPageInfo.PageNum) < length)
{
contentPageInfo.PageNum++;
}
if (contentPageInfo.CurrentPage < 1)
{
contentPageInfo.CurrentPage = 1;
}
if (contentPageInfo.CurrentPage > contentPageInfo.PageNum)
{
contentPageInfo.CurrentPage = contentPageInfo.PageNum;
}
int beginPoint = 0;
if (contentPageInfo.CurrentPage == 1)
{
beginPoint = 1;
}
else
{
beginPoint = num * (contentPageInfo.CurrentPage - 1);
beginPoint = GetSpecialPosition(contentPageInfo.Content, beginPoint);
}
int specialPosition = 0;
if (contentPageInfo.CurrentPage == contentPageInfo.PageNum)
{
specialPosition = length;
}
else
{
specialPosition = num * contentPageInfo.CurrentPage;
if (specialPosition > length)
{
specialPosition = length;
}
else
{
specialPosition = GetSpecialPosition(contentPageInfo.Content, specialPosition);
}
}
if (specialPosition < beginPoint)
{
specialPosition = beginPoint;
}
contentPageInfo.Content = contentPageInfo.Content.Substring(beginPoint, specialPosition - beginPoint);
}
}
else if (string.Compare(strA, "manual", true) == 0)
{
ManualPage(contentPageInfo);
}
else
{
contentPageInfo.Content = contentPageInfo.Content.Replace("[NextPage]", string.Empty);
}
}
}
public static InsideStaticLabel InsideStaticLabelObject
{
get
{
InsideStaticLabel label = SiteCache.Get("CK_Label_LabelTransform_InsideStaticLabelObject") as InsideStaticLabel;
if (label == null)
{
label = new InsideStaticLabel();
SiteCache.Insert("CK_Label_LabelTransform_InsideStaticLabelObject", label, 0x4380);
}
return label;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -