From a7ed3e3f4bbe825f2928cf30f9dec006a0f0def9 Mon Sep 17 00:00:00 2001 From: starlying Date: Fri, 22 Mar 2019 14:48:29 +0800 Subject: [PATCH] downloads --- .../Cms/ModalContentAttributes.cs | 21 + .../Cms/PageContentAddAfter.cs | 30 +- .../Cms/PageTemplateReference.cs | 145 +++++++ .../Core/TextUtility.cs | 4 + .../SiteServer.BackgroundPages.csproj | 3 + SiteServer.CMS/Core/ContentUtility.cs | 6 + SiteServer.CMS/Core/InputParserUtility.cs | 109 ++--- .../ImportExport/Components/ContentIe.cs | 8 +- .../Model/Attributes/ContentAttribute.cs | 3 + SiteServer.CMS/Model/ContentInfo.cs | 6 + SiteServer.CMS/Provider/ContentDao.cs | 387 +++++++++--------- SiteServer.CMS/Provider/TemplateDao.cs | 8 +- .../StlParser/StlElement/StlContent.cs | 8 +- .../StlParser/StlElement/StlFile.cs | 99 ++++- .../Sys/SysStlActionsDownloadController.cs | 71 ++-- .../Controllers/V1/V1CaptchaController.cs | 60 +-- SiteServer.Web/SiteServer/Cms/create.cshtml | 18 +- .../Cms/modalContentAttributes.aspx | 16 +- .../SiteServer/Cms/pageTemplateReference.aspx | 40 ++ .../SiteServer/assets/menus/Site.config | 1 + 20 files changed, 701 insertions(+), 342 deletions(-) create mode 100644 SiteServer.BackgroundPages/Cms/PageTemplateReference.cs create mode 100644 SiteServer.Web/SiteServer/Cms/pageTemplateReference.aspx diff --git a/SiteServer.BackgroundPages/Cms/ModalContentAttributes.cs b/SiteServer.BackgroundPages/Cms/ModalContentAttributes.cs index dc5439c0c..26a8342f2 100644 --- a/SiteServer.BackgroundPages/Cms/ModalContentAttributes.cs +++ b/SiteServer.BackgroundPages/Cms/ModalContentAttributes.cs @@ -20,6 +20,7 @@ public class ModalContentAttributes : BasePageCms protected CheckBox CbIsTop; protected HtmlInputHidden HihType; protected TextBox TbHits; + protected TextBox TbDownloads; private ChannelInfo _channelInfo; private List _idList; @@ -91,6 +92,7 @@ public override void Submit_OnClick(object sender, EventArgs e) } break; + case "2": if (CbIsRecommend.Checked || CbIsHot.Checked || CbIsColor.Checked || CbIsTop.Checked) { @@ -125,6 +127,7 @@ public override void Submit_OnClick(object sender, EventArgs e) } break; + case "3": var hits = TranslateUtils.ToInt(TbHits.Text); @@ -140,6 +143,24 @@ public override void Submit_OnClick(object sender, EventArgs e) AuthRequest.AddSiteLog(SiteId, "设置内容点击量"); + isChanged = true; + break; + + case "4": + var downloads = TranslateUtils.ToInt(TbDownloads.Text); + + foreach (var contentId in _idList) + { + var contentInfo = ContentManager.GetContentInfo(SiteInfo, _channelInfo, contentId); + if (contentInfo != null) + { + contentInfo.Downloads = downloads; + DataProvider.ContentDao.Update(SiteInfo, _channelInfo, contentInfo); + } + } + + AuthRequest.AddSiteLog(SiteId, "设置内容下载量"); + isChanged = true; break; } diff --git a/SiteServer.BackgroundPages/Cms/PageContentAddAfter.cs b/SiteServer.BackgroundPages/Cms/PageContentAddAfter.cs index 83d9ac90f..dcbe8e60e 100644 --- a/SiteServer.BackgroundPages/Cms/PageContentAddAfter.cs +++ b/SiteServer.BackgroundPages/Cms/PageContentAddAfter.cs @@ -74,21 +74,25 @@ public void RblOperation_SelectedIndexChanged(object sender, EventArgs e) if (after == EContentAddAfter.ContinueAdd) { PageUtils.Redirect(WebUtils.GetContentAddAddUrl(SiteId, _channelInfo, AuthRequest.GetQueryString("ReturnUrl"))); + return; } - else if (after == EContentAddAfter.ManageContents) - { - PageUtils.Redirect(_returnUrl); - } - else if (after == EContentAddAfter.Contribute) - { - CrossSiteTransUtility.LoadSiteIdDropDownList(DdlSiteId, SiteInfo, _channelInfo.Id); - if (DdlSiteId.Items.Count > 0) - { - DdlSiteId_SelectedIndexChanged(sender, e); - } - PhSiteId.Visible = PhSubmit.Visible = true; - } + if (after == EContentAddAfter.ManageContents) + { + PageUtils.Redirect(_returnUrl); + return; + } + + if (after == EContentAddAfter.Contribute) + { + CrossSiteTransUtility.LoadSiteIdDropDownList(DdlSiteId, SiteInfo, _channelInfo.Id); + + if (DdlSiteId.Items.Count > 0) + { + DdlSiteId_SelectedIndexChanged(sender, e); + } + PhSiteId.Visible = PhSubmit.Visible = true; + } } public void DdlSiteId_SelectedIndexChanged(object sender, EventArgs e) diff --git a/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs b/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs new file mode 100644 index 000000000..abe9e266d --- /dev/null +++ b/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Specialized; +using System.Reflection; +using System.Text; +using System.Web.UI.WebControls; +using SiteServer.CMS.DataCache; +using SiteServer.CMS.StlParser.Model; +using SiteServer.Utils; + +namespace SiteServer.BackgroundPages.Cms +{ + public class PageTemplateReference : BasePageCms + { + public Literal LtlAll; + public PlaceHolder PhRefenreces; + public Literal LtlReferences; + + public static string GetRedirectUrl(int siteId, string elementName) + { + return PageUtils.GetCmsUrl(siteId, nameof(PageTemplateReference), new NameValueCollection + { + {"elementName", elementName} + }); + } + + private string _elementName = string.Empty; + + public void Page_Load(object sender, EventArgs e) + { + if (IsForbidden) return; + + PageUtils.CheckRequestParameter("siteId"); + + _elementName = AuthRequest.GetQueryString("elementName"); + + if (IsPostBack) return; + + VerifySitePermissions(ConfigManager.WebSitePermissions.Template); + + var elements = StlAll.Elements; + var allBuilder = new StringBuilder(); + foreach (var elementName in elements.Keys) + { + if (!elements.TryGetValue(elementName, out var elementType)) continue; + + var tagName = elementName.Substring(4); + var stlAttribute = (StlElementAttribute)Attribute.GetCustomAttribute(elementType, typeof(StlElementAttribute)); + + allBuilder.Append($@" + + + + {elementName} + + + {stlAttribute.Title} + https://docs.siteserver.cn/stl#/{tagName}/ +"); + } + + LtlAll.Text = $@" +
+
+
+ + + + + + + + + + {allBuilder} + +
标签说明参考
+
+
+
+"; + + if (!string.IsNullOrEmpty(_elementName)) + { + if (elements.TryGetValue(_elementName, out var elementType)) + { + var tagName = _elementName.Substring(4); + PhRefenreces.Visible = true; + + var attrBuilder = new StringBuilder(); + + var fields = elementType.GetFields(BindingFlags.Static | BindingFlags.NonPublic); + foreach (var field in fields) + { + var fieldName = field.Name.ToCamelCase(); + var attr = (StlAttributeAttribute)Attribute.GetCustomAttribute(field, typeof(StlAttributeAttribute)); + + if (attr != null) + { + attrBuilder.Append($@" + + {fieldName} + {attr.Title} + https://docs.siteserver.cn/stl#/{tagName}/attributes?id={fieldName} +"); + } + } + + var helpUrl = $"https://docs.siteserver.cn/stl#/{tagName}/"; + + var stlAttribute = (StlElementAttribute)Attribute.GetCustomAttribute(elementType, typeof(StlElementAttribute)); + + LtlReferences.Text = $@" +
+

+ <{_elementName}> {stlAttribute.Title} +

+

+ {stlAttribute.Description} + 详细使用说明 +

+
+
+
+ + + + + + + + + + {attrBuilder} + +
属性说明参考
+
+
+
+
+"; + } + } + } + } +} \ No newline at end of file diff --git a/SiteServer.BackgroundPages/Core/TextUtility.cs b/SiteServer.BackgroundPages/Core/TextUtility.cs index 9494849a8..96e19c137 100644 --- a/SiteServer.BackgroundPages/Core/TextUtility.cs +++ b/SiteServer.BackgroundPages/Core/TextUtility.cs @@ -108,6 +108,10 @@ private static string GetColumnValue(Dictionary nameValueCacheDi { value = DateUtils.GetDateAndTimeString(contentInfo.LastHitsDate); } + else if (StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, ContentAttribute.Downloads)) + { + value = contentInfo.Downloads.ToString(); + } else if (StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, ContentAttribute.IsTop) || StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, ContentAttribute.IsColor) || StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, ContentAttribute.IsHot) || StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, ContentAttribute.IsRecommend)) { value = StringUtils.GetTrueImageHtml(contentInfo.GetString(styleInfo.AttributeName)); diff --git a/SiteServer.BackgroundPages/SiteServer.BackgroundPages.csproj b/SiteServer.BackgroundPages/SiteServer.BackgroundPages.csproj index 82d0581b5..9e41a9b35 100644 --- a/SiteServer.BackgroundPages/SiteServer.BackgroundPages.csproj +++ b/SiteServer.BackgroundPages/SiteServer.BackgroundPages.csproj @@ -410,6 +410,9 @@ + + ASPXCodeBehind + diff --git a/SiteServer.CMS/Core/ContentUtility.cs b/SiteServer.CMS/Core/ContentUtility.cs index 19d4e357a..7c701aeb2 100644 --- a/SiteServer.CMS/Core/ContentUtility.cs +++ b/SiteServer.CMS/Core/ContentUtility.cs @@ -362,6 +362,12 @@ public static List GetAllTableStyleInfoList(List Taxis = taxis++ }, new TableStyleInfo + { + AttributeName = ContentAttribute.Downloads, + DisplayName = "下载量", + Taxis = taxis++ + }, + new TableStyleInfo { AttributeName = ContentAttribute.CheckUserName, DisplayName = "审核人", diff --git a/SiteServer.CMS/Core/InputParserUtility.cs b/SiteServer.CMS/Core/InputParserUtility.cs index 41fa53eae..b1ac9f86b 100644 --- a/SiteServer.CMS/Core/InputParserUtility.cs +++ b/SiteServer.CMS/Core/InputParserUtility.cs @@ -95,7 +95,7 @@ public static string GetContentByTableStyle(string content, string separator, Si } else if (inputType == InputType.File) { - parsedContent = GetFileHtmlWithoutCount(siteInfo, parsedContent, attributes, innerHtml, isStlEntity); + parsedContent = GetFileHtmlWithoutCount(siteInfo, parsedContent, attributes, innerHtml, isStlEntity, false, false); } return parsedContent; @@ -208,7 +208,7 @@ public static string GetContentByTableStyle(ContentInfo contentInfo, string sepa { if (no <= 1) { - parsedContent = GetFileHtmlWithoutCount(siteInfo, value, attributes, innerHtml, isStlEntity); + parsedContent = GetFileHtmlWithoutCount(siteInfo, value, attributes, innerHtml, isStlEntity, false, false); } else { @@ -221,7 +221,7 @@ public static string GetContentByTableStyle(ContentInfo contentInfo, string sepa { if (index == no) { - parsedContent = GetFileHtmlWithoutCount(siteInfo, extendValue, attributes, innerHtml, isStlEntity); + parsedContent = GetFileHtmlWithoutCount(siteInfo, extendValue, attributes, innerHtml, isStlEntity, false, false); break; } index++; @@ -239,13 +239,13 @@ public static string GetContentByTableStyle(ContentInfo contentInfo, string sepa public static string GetImageOrFlashHtml(SiteInfo siteInfo, string imageUrl, NameValueCollection attributes, bool isStlEntity) { - var retval = string.Empty; + var retVal = string.Empty; if (!string.IsNullOrEmpty(imageUrl)) { imageUrl = PageUtility.ParseNavigationUrl(siteInfo, imageUrl, false); if (isStlEntity) { - retval = imageUrl; + retVal = imageUrl; } else { @@ -254,7 +254,7 @@ public static string GetImageOrFlashHtml(SiteInfo siteInfo, string imageUrl, Nam var htmlImage = new HtmlImage(); ControlUtils.AddAttributesIfNotExists(htmlImage, attributes); htmlImage.Src = imageUrl; - retval = ControlUtils.GetControlRenderHtml(htmlImage); + retVal = ControlUtils.GetControlRenderHtml(htmlImage); } else { @@ -285,7 +285,7 @@ public static string GetImageOrFlashHtml(SiteInfo siteInfo, string imageUrl, Nam } } } - retval = $@" + retVal = $@" @@ -295,78 +295,95 @@ public static string GetImageOrFlashHtml(SiteInfo siteInfo, string imageUrl, Nam } } } - return retval; + return retVal; } public static string GetVideoHtml(SiteInfo siteInfo, string videoUrl, NameValueCollection attributes, bool isStlEntity) { - var retval = string.Empty; + var retVal = string.Empty; if (!string.IsNullOrEmpty(videoUrl)) { videoUrl = PageUtility.ParseNavigationUrl(siteInfo, videoUrl, false); if (isStlEntity) { - retval = videoUrl; + retVal = videoUrl; } else { - retval = $@" + retVal = $@" "; } } - return retval; + return retVal; } - public static string GetFileHtmlWithCount(SiteInfo siteInfo, int channelId, int contentId, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity) + public static string GetFileHtmlWithCount(SiteInfo siteInfo, int channelId, int contentId, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity, bool isLower, bool isUpper) { - var retval = string.Empty; - if (!string.IsNullOrEmpty(fileUrl)) + var retVal = string.Empty; + if (siteInfo == null) return retVal; + if (string.IsNullOrEmpty(fileUrl)) return retVal; + + if (isStlEntity) { - if (isStlEntity) + retVal = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, channelId, contentId, + fileUrl); + } + else + { + var stlAnchor = new HtmlAnchor(); + ControlUtils.AddAttributesIfNotExists(stlAnchor, attributes); + stlAnchor.HRef = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, channelId, + contentId, fileUrl); + stlAnchor.InnerHtml = string.IsNullOrEmpty(innerHtml) + ? PageUtils.GetFileNameFromUrl(fileUrl) + : innerHtml; + if (isLower) { - retval = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, channelId, contentId, fileUrl); + stlAnchor.InnerHtml = stlAnchor.InnerHtml.ToLower(); } - else + if (isUpper) { - var stlAnchor = new HtmlAnchor(); - ControlUtils.AddAttributesIfNotExists(stlAnchor, attributes); - stlAnchor.HRef = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, channelId, contentId, fileUrl); - stlAnchor.InnerHtml = string.IsNullOrEmpty(innerHtml) ? PageUtils.GetFileNameFromUrl(fileUrl) : innerHtml; - - retval = ControlUtils.GetControlRenderHtml(stlAnchor); + stlAnchor.InnerHtml = stlAnchor.InnerHtml.ToUpper(); } + + retVal = ControlUtils.GetControlRenderHtml(stlAnchor); } - return retval; + + return retVal; } - public static string GetFileHtmlWithoutCount(SiteInfo siteInfo, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity) + public static string GetFileHtmlWithoutCount(SiteInfo siteInfo, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity, bool isLower, bool isUpper) { - if (siteInfo != null) + var retVal = string.Empty; + if (siteInfo == null) return retVal; + if (string.IsNullOrEmpty(fileUrl)) return retVal; + + if (isStlEntity) { - var retval = string.Empty; - if (!string.IsNullOrEmpty(fileUrl)) - { - if (isStlEntity) - { - retval = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, fileUrl); - } - else - { - var stlAnchor = new HtmlAnchor(); - ControlUtils.AddAttributesIfNotExists(stlAnchor, attributes); - stlAnchor.HRef = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, fileUrl); - stlAnchor.InnerHtml = string.IsNullOrEmpty(innerHtml) ? PageUtils.GetFileNameFromUrl(fileUrl) : innerHtml; + retVal = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, fileUrl); + } + else + { + var stlAnchor = new HtmlAnchor(); + ControlUtils.AddAttributesIfNotExists(stlAnchor, attributes); + stlAnchor.HRef = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, fileUrl); + stlAnchor.InnerHtml = string.IsNullOrEmpty(innerHtml) ? PageUtils.GetFileNameFromUrl(fileUrl) : innerHtml; - retval = ControlUtils.GetControlRenderHtml(stlAnchor); - } + if (isLower) + { + stlAnchor.InnerHtml = stlAnchor.InnerHtml.ToLower(); } - return retval; + if (isUpper) + { + stlAnchor.InnerHtml = stlAnchor.InnerHtml.ToUpper(); + } + + retVal = ControlUtils.GetControlRenderHtml(stlAnchor); } - return string.Empty; - } - + return retVal; + } } } diff --git a/SiteServer.CMS/ImportExport/Components/ContentIe.cs b/SiteServer.CMS/ImportExport/Components/ContentIe.cs index fb224c993..58701362b 100644 --- a/SiteServer.CMS/ImportExport/Components/ContentIe.cs +++ b/SiteServer.CMS/ImportExport/Components/ContentIe.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; using Atom.Core; @@ -101,6 +100,7 @@ private void ImportContents(AtomEntryCollection entries, ChannelInfo channelInfo var hitsByWeek = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByWeek)); var hitsByMonth = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByMonth)); var lastHitsDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LastHitsDate); + var downloads = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Downloads)); var title = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Title); var isTop = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsTop)); var isRecommend = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsRecommend)); @@ -137,6 +137,7 @@ private void ImportContents(AtomEntryCollection entries, ChannelInfo channelInfo contentInfo.HitsByWeek = hitsByWeek; contentInfo.HitsByMonth = hitsByMonth; contentInfo.LastHitsDate = TranslateUtils.ToDateTime(lastHitsDate); + contentInfo.Downloads = downloads; contentInfo.Title = AtomUtility.Decrypt(title); contentInfo.IsTop = isTop; contentInfo.IsRecommend = isRecommend; @@ -219,6 +220,7 @@ private void ImportContents(AtomEntryCollection entries, ChannelInfo channelInfo var hitsByWeek = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByWeek)); var hitsByMonth = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.HitsByMonth)); var lastHitsDate = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.LastHitsDate); + var downloads = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Downloads)); var title = AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.Title); var isTop = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsTop)); var isRecommend = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, ContentAttribute.IsRecommend)); @@ -257,6 +259,7 @@ private void ImportContents(AtomEntryCollection entries, ChannelInfo channelInfo contentInfo.HitsByWeek = hitsByWeek; contentInfo.HitsByMonth = hitsByMonth; contentInfo.LastHitsDate = TranslateUtils.ToDateTime(lastHitsDate); + contentInfo.Downloads = downloads; contentInfo.Title = AtomUtility.Decrypt(title); contentInfo.IsTop = isTop; contentInfo.IsRecommend = isRecommend; @@ -415,6 +418,7 @@ public AtomEntry ExportContentInfo(ContentInfo contentInfo) AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.HitsByWeek, contentInfo.HitsByWeek.ToString()); AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.HitsByMonth, contentInfo.HitsByMonth.ToString()); AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.LastHitsDate, contentInfo.LastHitsDate.ToString(CultureInfo.InvariantCulture)); + AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.Downloads, contentInfo.Downloads.ToString()); AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.Title, AtomUtility.Encrypt(contentInfo.Title)); AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.IsTop, contentInfo.IsTop.ToString()); AtomUtility.AddDcElement(entry.AdditionalElements, ContentAttribute.IsRecommend, contentInfo.IsRecommend.ToString()); diff --git a/SiteServer.CMS/Model/Attributes/ContentAttribute.cs b/SiteServer.CMS/Model/Attributes/ContentAttribute.cs index 8acfa99a9..f298bdb71 100644 --- a/SiteServer.CMS/Model/Attributes/ContentAttribute.cs +++ b/SiteServer.CMS/Model/Attributes/ContentAttribute.cs @@ -25,6 +25,7 @@ public static class ContentAttribute public const string HitsByWeek = nameof(ContentInfo.HitsByWeek); public const string HitsByMonth = nameof(ContentInfo.HitsByMonth); public const string LastHitsDate = nameof(ContentInfo.LastHitsDate); + public const string Downloads = nameof(ContentInfo.Downloads); public const string SettingsXml = nameof(ContentInfo.SettingsXml); public const string Title = nameof(ContentInfo.Title); public const string IsTop = nameof(ContentInfo.IsTop); @@ -78,6 +79,7 @@ public static string GetExtendAttributeName(string attributeName) HitsByWeek, HitsByMonth, LastHitsDate, + Downloads, SettingsXml, Title, IsTop, @@ -110,6 +112,7 @@ public static string GetExtendAttributeName(string attributeName) HitsByWeek, HitsByMonth, LastHitsDate, + Downloads, SettingsXml, IsTop, IsRecommend, diff --git a/SiteServer.CMS/Model/ContentInfo.cs b/SiteServer.CMS/Model/ContentInfo.cs index 02d62bbbb..e6c607c7a 100644 --- a/SiteServer.CMS/Model/ContentInfo.cs +++ b/SiteServer.CMS/Model/ContentInfo.cs @@ -180,6 +180,12 @@ public DateTime LastHitsDate set => Set(ContentAttribute.LastHitsDate, value); } + public int Downloads + { + get => GetInt(ContentAttribute.Downloads); + set => Set(ContentAttribute.Downloads, value); + } + public string Title { get => GetString(ContentAttribute.Title); diff --git a/SiteServer.CMS/Provider/ContentDao.cs b/SiteServer.CMS/Provider/ContentDao.cs index a4ad3fa91..8a2d2a375 100644 --- a/SiteServer.CMS/Provider/ContentDao.cs +++ b/SiteServer.CMS/Provider/ContentDao.cs @@ -34,155 +34,160 @@ public static string GetContentTableName(int siteId) { new TableColumn { - AttributeName = nameof(ContentInfo.Id), + AttributeName = ContentAttribute.Id, DataType = DataType.Integer, IsIdentity = true, IsPrimaryKey = true }, new TableColumn { - AttributeName = nameof(ContentInfo.ChannelId), + AttributeName = ContentAttribute.ChannelId, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.SiteId), + AttributeName = ContentAttribute.SiteId, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.AddUserName), + AttributeName = ContentAttribute.AddUserName, DataType = DataType.VarChar, DataLength = 255, }, new TableColumn { - AttributeName = nameof(ContentInfo.LastEditUserName), + AttributeName = ContentAttribute.LastEditUserName, DataType = DataType.VarChar, DataLength = 255, }, new TableColumn { - AttributeName = nameof(ContentInfo.LastEditDate), + AttributeName = ContentAttribute.LastEditDate, DataType = DataType.DateTime }, new TableColumn { - AttributeName = nameof(ContentInfo.AdminId), + AttributeName = ContentAttribute.AdminId, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.UserId), + AttributeName = ContentAttribute.UserId, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.Taxis), + AttributeName = ContentAttribute.Taxis, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.GroupNameCollection), + AttributeName = ContentAttribute.GroupNameCollection, DataType = DataType.VarChar, DataLength = 255 }, new TableColumn { - AttributeName = nameof(ContentInfo.Tags), + AttributeName = ContentAttribute.Tags, DataType = DataType.VarChar, DataLength = 255 }, new TableColumn { - AttributeName = nameof(ContentInfo.SourceId), + AttributeName = ContentAttribute.SourceId, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.ReferenceId), + AttributeName = ContentAttribute.ReferenceId, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.IsChecked), + AttributeName = ContentAttribute.IsChecked, DataType = DataType.VarChar, DataLength = 18 }, new TableColumn { - AttributeName = nameof(ContentInfo.CheckedLevel), + AttributeName = ContentAttribute.CheckedLevel, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.Hits), + AttributeName = ContentAttribute.Hits, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.HitsByDay), + AttributeName = ContentAttribute.HitsByDay, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.HitsByWeek), + AttributeName = ContentAttribute.HitsByWeek, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.HitsByMonth), + AttributeName = ContentAttribute.HitsByMonth, DataType = DataType.Integer }, new TableColumn { - AttributeName = nameof(ContentInfo.LastHitsDate), + AttributeName = ContentAttribute.LastHitsDate, DataType = DataType.DateTime }, new TableColumn { - AttributeName = nameof(ContentInfo.SettingsXml), + AttributeName = nameof(ContentInfo.Downloads), + DataType = DataType.Integer + }, + new TableColumn + { + AttributeName = ContentAttribute.SettingsXml, DataType = DataType.Text }, new TableColumn { - AttributeName = nameof(ContentInfo.Title), + AttributeName = ContentAttribute.Title, DataType = DataType.VarChar, DataLength = 255 }, new TableColumn { - AttributeName = nameof(ContentInfo.IsTop), + AttributeName = ContentAttribute.IsTop, DataType = DataType.VarChar, DataLength = 18 }, new TableColumn { - AttributeName = nameof(ContentInfo.IsRecommend), + AttributeName = ContentAttribute.IsRecommend, DataType = DataType.VarChar, DataLength = 18 }, new TableColumn { - AttributeName = nameof(ContentInfo.IsHot), + AttributeName = ContentAttribute.IsHot, DataType = DataType.VarChar, DataLength = 18 }, new TableColumn { - AttributeName = nameof(ContentInfo.IsColor), + AttributeName = ContentAttribute.IsColor, DataType = DataType.VarChar, DataLength = 18 }, new TableColumn { - AttributeName = nameof(ContentInfo.LinkUrl), + AttributeName = ContentAttribute.LinkUrl, DataType = DataType.VarChar, DataLength = 200 }, new TableColumn { - AttributeName = nameof(ContentInfo.AddDate), + AttributeName = ContentAttribute.AddDate, DataType = DataType.DateTime } }; @@ -244,7 +249,7 @@ public List TableColumnsDefault } } - public void Update(string tableName, int chananelId, int contentId, string name, string value) + public void Update(string tableName, int channelId, int contentId, string name, string value) { var sqlString = $"UPDATE {tableName} SET {name} = @{name} WHERE Id = @Id"; @@ -257,7 +262,7 @@ public void Update(string tableName, int chananelId, int contentId, string name, connection.Execute(sqlString, parameters); } - ContentManager.RemoveCache(tableName, chananelId); + ContentManager.RemoveCache(tableName, channelId); } public void UpdateIsChecked(string tableName, int siteId, int channelId, List contentIdList, int translateChannelId, string userName, bool isChecked, int checkedLevel, string reasons) @@ -280,11 +285,11 @@ public void UpdateIsChecked(string tableName, int siteId, int channelId, List 0) { sqlString = - $"UPDATE {tableName} SET {nameof(ContentInfo.IsChecked)} = '{isChecked}', {nameof(ContentInfo.CheckedLevel)} = {checkedLevel}, {nameof(ContentInfo.SettingsXml)} = '{attributes}', {nameof(ContentInfo.ChannelId)} = {translateChannelId} WHERE {nameof(ContentInfo.Id)} = {contentId}"; + $"UPDATE {tableName} SET {ContentAttribute.IsChecked} = '{isChecked}', {ContentAttribute.CheckedLevel} = {checkedLevel}, {ContentAttribute.SettingsXml} = '{attributes}', {ContentAttribute.ChannelId} = {translateChannelId} WHERE {ContentAttribute.Id} = {contentId}"; } ExecuteNonQuery(sqlString); @@ -302,7 +307,7 @@ public void SetAutoPageContentToSite(SiteInfo siteInfo) if (!siteInfo.Additional.IsAutoPageInTextEditor) return; var sqlString = - $"SELECT Id, {nameof(ContentInfo.ChannelId)}, {nameof(ContentInfo.Content)} FROM {siteInfo.TableName} WHERE SiteId = {siteInfo.Id}"; + $"SELECT Id, {ContentAttribute.ChannelId}, {nameof(ContentInfo.Content)} FROM {siteInfo.TableName} WHERE SiteId = {siteInfo.Id}"; using (var rdr = ExecuteReader(sqlString)) { @@ -455,7 +460,7 @@ public void Delete(string tableName, int siteId, int channelId, int contentId) // var tableName = ChannelManager.GetTableName(siteInfo, channelId); // if (string.IsNullOrEmpty(tableName)) continue; - // ExecuteNonQuery(trans, $"DELETE FROM {tableName} WHERE SiteId = {siteInfo.Id} AND {nameof(ContentInfo.ChannelId)} = {channelId}"); + // ExecuteNonQuery(trans, $"DELETE FROM {tableName} WHERE SiteId = {siteInfo.Id} AND {ContentAttribute.ChannelId} = {channelId}"); // ContentManager.RemoveCache(tableName, channelId); // } @@ -490,7 +495,7 @@ private void DeleteReferenceContents(int siteId, int channelId, string tableName // DataProvider.ChannelDao.UpdateAdditional(channelInfo); // var sqlString = - // $"DELETE FROM {tableName} WHERE {nameof(ContentInfo.SiteId)} = @{nameof(ContentInfo.SiteId)} AND {nameof(ContentInfo.ChannelId)} = @{nameof(ContentInfo.ChannelId)} AND {nameof(ContentInfo.SourceId)} = @{nameof(ContentInfo.SourceId)}"; + // $"DELETE FROM {tableName} WHERE {ContentAttribute.SiteId} = @{ContentAttribute.SiteId} AND {ContentAttribute.ChannelId} = @{ContentAttribute.ChannelId} AND {ContentAttribute.SourceId} = @{ContentAttribute.SourceId}"; // using (var connection = GetConnection()) // { @@ -679,7 +684,7 @@ public int GetMaxTaxis(string tableName, int channelId, bool isTop) try { - var sqlString = $"SELECT {nameof(ContentInfo.ChannelId)}, {name} FROM {tableName} WHERE Id = {contentId}"; + var sqlString = $"SELECT {ContentAttribute.ChannelId}, {name} FROM {tableName} WHERE Id = {contentId}"; using (var conn = GetConnection()) { @@ -883,7 +888,7 @@ public int GetChannelId(string tableName, int contentId) //public int GetCount(string tableName, int channelId) //{ - // var sqlString = $"SELECT COUNT(*) FROM {tableName} WHERE {nameof(ContentInfo.ChannelId)} = {channelId} AND {nameof(ContentInfo.SourceId)} != {SourceManager.Preview}"; + // var sqlString = $"SELECT COUNT(*) FROM {tableName} WHERE {ContentAttribute.ChannelId} = {channelId} AND {ContentAttribute.SourceId} != {SourceManager.Preview}"; // return DataProvider.DatabaseDao.GetIntResult(sqlString); //} @@ -891,7 +896,7 @@ public int GetChannelId(string tableName, int contentId) public int GetSequence(string tableName, int channelId, int contentId) { var sqlString = - $"SELECT COUNT(*) FROM {tableName} WHERE {nameof(ContentInfo.ChannelId)} = {channelId} AND {nameof(ContentInfo.IsChecked)} = '{true}' AND Taxis < (SELECT Taxis FROM {tableName} WHERE Id = {contentId}) AND {nameof(ContentInfo.SourceId)} != {SourceManager.Preview}"; + $"SELECT COUNT(*) FROM {tableName} WHERE {ContentAttribute.ChannelId} = {channelId} AND {ContentAttribute.IsChecked} = '{true}' AND Taxis < (SELECT Taxis FROM {tableName} WHERE Id = {contentId}) AND {ContentAttribute.SourceId} != {SourceManager.Preview}"; return DataProvider.DatabaseDao.GetIntResult(sqlString) + 1; } @@ -1003,98 +1008,101 @@ private int InsertInner(string tableName, SiteInfo siteInfo, ChannelInfo channel var sqlString = $@" INSERT INTO {tableName} ( - {nameof(ContentInfo.ChannelId)}, - {nameof(ContentInfo.SiteId)}, - {nameof(ContentInfo.AddUserName)}, - {nameof(ContentInfo.LastEditUserName)}, - {nameof(ContentInfo.LastEditDate)}, - {nameof(ContentInfo.AdminId)}, - {nameof(ContentInfo.UserId)}, - {nameof(ContentInfo.Taxis)}, - {nameof(ContentInfo.GroupNameCollection)}, - {nameof(ContentInfo.Tags)}, - {nameof(ContentInfo.SourceId)}, - {nameof(ContentInfo.ReferenceId)}, - {nameof(ContentInfo.IsChecked)}, - {nameof(ContentInfo.CheckedLevel)}, - {nameof(ContentInfo.Hits)}, - {nameof(ContentInfo.HitsByDay)}, - {nameof(ContentInfo.HitsByWeek)}, - {nameof(ContentInfo.HitsByMonth)}, - {nameof(ContentInfo.LastHitsDate)}, - {nameof(ContentInfo.SettingsXml)}, - {nameof(ContentInfo.Title)}, - {nameof(ContentInfo.IsTop)}, - {nameof(ContentInfo.IsRecommend)}, - {nameof(ContentInfo.IsHot)}, - {nameof(ContentInfo.IsColor)}, - {nameof(ContentInfo.LinkUrl)}, - {nameof(ContentInfo.AddDate)} + {ContentAttribute.ChannelId}, + {ContentAttribute.SiteId}, + {ContentAttribute.AddUserName}, + {ContentAttribute.LastEditUserName}, + {ContentAttribute.LastEditDate}, + {ContentAttribute.AdminId}, + {ContentAttribute.UserId}, + {ContentAttribute.Taxis}, + {ContentAttribute.GroupNameCollection}, + {ContentAttribute.Tags}, + {ContentAttribute.SourceId}, + {ContentAttribute.ReferenceId}, + {ContentAttribute.IsChecked}, + {ContentAttribute.CheckedLevel}, + {ContentAttribute.Hits}, + {ContentAttribute.HitsByDay}, + {ContentAttribute.HitsByWeek}, + {ContentAttribute.HitsByMonth}, + {ContentAttribute.LastHitsDate}, + {ContentAttribute.Downloads}, + {ContentAttribute.SettingsXml}, + {ContentAttribute.Title}, + {ContentAttribute.IsTop}, + {ContentAttribute.IsRecommend}, + {ContentAttribute.IsHot}, + {ContentAttribute.IsColor}, + {ContentAttribute.LinkUrl}, + {ContentAttribute.AddDate} {names} ) VALUES ( - @{nameof(ContentInfo.ChannelId)}, - @{nameof(ContentInfo.SiteId)}, - @{nameof(ContentInfo.AddUserName)}, - @{nameof(ContentInfo.LastEditUserName)}, - @{nameof(ContentInfo.LastEditDate)}, - @{nameof(ContentInfo.AdminId)}, - @{nameof(ContentInfo.UserId)}, - @{nameof(ContentInfo.Taxis)}, - @{nameof(ContentInfo.GroupNameCollection)}, - @{nameof(ContentInfo.Tags)}, - @{nameof(ContentInfo.SourceId)}, - @{nameof(ContentInfo.ReferenceId)}, - @{nameof(ContentInfo.IsChecked)}, - @{nameof(ContentInfo.CheckedLevel)}, - @{nameof(ContentInfo.Hits)}, - @{nameof(ContentInfo.HitsByDay)}, - @{nameof(ContentInfo.HitsByWeek)}, - @{nameof(ContentInfo.HitsByMonth)}, - @{nameof(ContentInfo.LastHitsDate)}, - @{nameof(ContentInfo.SettingsXml)}, - @{nameof(ContentInfo.Title)}, - @{nameof(ContentInfo.IsTop)}, - @{nameof(ContentInfo.IsRecommend)}, - @{nameof(ContentInfo.IsHot)}, - @{nameof(ContentInfo.IsColor)}, - @{nameof(ContentInfo.LinkUrl)}, - @{nameof(ContentInfo.AddDate)} + @{ContentAttribute.ChannelId}, + @{ContentAttribute.SiteId}, + @{ContentAttribute.AddUserName}, + @{ContentAttribute.LastEditUserName}, + @{ContentAttribute.LastEditDate}, + @{ContentAttribute.AdminId}, + @{ContentAttribute.UserId}, + @{ContentAttribute.Taxis}, + @{ContentAttribute.GroupNameCollection}, + @{ContentAttribute.Tags}, + @{ContentAttribute.SourceId}, + @{ContentAttribute.ReferenceId}, + @{ContentAttribute.IsChecked}, + @{ContentAttribute.CheckedLevel}, + @{ContentAttribute.Hits}, + @{ContentAttribute.HitsByDay}, + @{ContentAttribute.HitsByWeek}, + @{ContentAttribute.HitsByMonth}, + @{ContentAttribute.LastHitsDate}, + @{ContentAttribute.Downloads}, + @{ContentAttribute.SettingsXml}, + @{ContentAttribute.Title}, + @{ContentAttribute.IsTop}, + @{ContentAttribute.IsRecommend}, + @{ContentAttribute.IsHot}, + @{ContentAttribute.IsColor}, + @{ContentAttribute.LinkUrl}, + @{ContentAttribute.AddDate} {values} )"; var parameters = new List { - GetParameter(nameof(ContentInfo.ChannelId), DataType.Integer, contentInfo.ChannelId), - GetParameter(nameof(ContentInfo.SiteId), DataType.Integer, contentInfo.SiteId), - GetParameter(nameof(ContentInfo.AddUserName), DataType.VarChar, 255, contentInfo.AddUserName), - GetParameter(nameof(ContentInfo.LastEditUserName), DataType.VarChar, 255, contentInfo.LastEditUserName), - GetParameter(nameof(ContentInfo.LastEditDate), DataType.DateTime, contentInfo.LastEditDate), - GetParameter(nameof(ContentInfo.AdminId), DataType.Integer, contentInfo.AdminId), - GetParameter(nameof(ContentInfo.UserId), DataType.Integer, contentInfo.UserId), - GetParameter(nameof(ContentInfo.Taxis), DataType.Integer, contentInfo.Taxis), - GetParameter(nameof(ContentInfo.GroupNameCollection), DataType.VarChar, 255, contentInfo.GroupNameCollection), - GetParameter(nameof(ContentInfo.Tags), DataType.VarChar, 255, contentInfo.Tags), - GetParameter(nameof(ContentInfo.SourceId), DataType.Integer, contentInfo.SourceId), - GetParameter(nameof(ContentInfo.ReferenceId), DataType.Integer, contentInfo.ReferenceId), - GetParameter(nameof(ContentInfo.IsChecked), DataType.VarChar, 18, contentInfo.IsChecked.ToString()), - GetParameter(nameof(ContentInfo.CheckedLevel), DataType.Integer, contentInfo.CheckedLevel), - GetParameter(nameof(ContentInfo.Hits), DataType.Integer, contentInfo.Hits), - GetParameter(nameof(ContentInfo.HitsByDay), DataType.Integer, contentInfo.HitsByDay), - GetParameter(nameof(ContentInfo.HitsByWeek), DataType.Integer, contentInfo.HitsByWeek), - GetParameter(nameof(ContentInfo.HitsByMonth), DataType.Integer, contentInfo.HitsByMonth), - GetParameter(nameof(ContentInfo.LastHitsDate), DataType.DateTime, contentInfo.LastHitsDate), - GetParameter(nameof(ContentInfo.SettingsXml), DataType.Text, contentInfo.ToString(excludeAttributesNames)), - GetParameter(nameof(ContentInfo.Title), DataType.VarChar, 255, contentInfo.Title), - GetParameter(nameof(ContentInfo.IsTop), DataType.VarChar, 18, contentInfo.IsTop.ToString()), - GetParameter(nameof(ContentInfo.IsRecommend), DataType.VarChar, 18, contentInfo.IsRecommend.ToString()), - GetParameter(nameof(ContentInfo.IsHot), DataType.VarChar, 18, contentInfo.IsHot.ToString()), - GetParameter(nameof(ContentInfo.IsColor), DataType.VarChar, 18, contentInfo.IsColor.ToString()), - GetParameter(nameof(ContentInfo.LinkUrl), DataType.VarChar, 200, contentInfo.LinkUrl), - GetParameter(nameof(ContentInfo.AddDate), DataType.DateTime, contentInfo.AddDate) + GetParameter(ContentAttribute.ChannelId, DataType.Integer, contentInfo.ChannelId), + GetParameter(ContentAttribute.SiteId, DataType.Integer, contentInfo.SiteId), + GetParameter(ContentAttribute.AddUserName, DataType.VarChar, 255, contentInfo.AddUserName), + GetParameter(ContentAttribute.LastEditUserName, DataType.VarChar, 255, contentInfo.LastEditUserName), + GetParameter(ContentAttribute.LastEditDate, DataType.DateTime, contentInfo.LastEditDate), + GetParameter(ContentAttribute.AdminId, DataType.Integer, contentInfo.AdminId), + GetParameter(ContentAttribute.UserId, DataType.Integer, contentInfo.UserId), + GetParameter(ContentAttribute.Taxis, DataType.Integer, contentInfo.Taxis), + GetParameter(ContentAttribute.GroupNameCollection, DataType.VarChar, 255, contentInfo.GroupNameCollection), + GetParameter(ContentAttribute.Tags, DataType.VarChar, 255, contentInfo.Tags), + GetParameter(ContentAttribute.SourceId, DataType.Integer, contentInfo.SourceId), + GetParameter(ContentAttribute.ReferenceId, DataType.Integer, contentInfo.ReferenceId), + GetParameter(ContentAttribute.IsChecked, DataType.VarChar, 18, contentInfo.IsChecked.ToString()), + GetParameter(ContentAttribute.CheckedLevel, DataType.Integer, contentInfo.CheckedLevel), + GetParameter(ContentAttribute.Hits, DataType.Integer, contentInfo.Hits), + GetParameter(ContentAttribute.HitsByDay, DataType.Integer, contentInfo.HitsByDay), + GetParameter(ContentAttribute.HitsByWeek, DataType.Integer, contentInfo.HitsByWeek), + GetParameter(ContentAttribute.HitsByMonth, DataType.Integer, contentInfo.HitsByMonth), + GetParameter(ContentAttribute.LastHitsDate, DataType.DateTime, contentInfo.LastHitsDate), + GetParameter(ContentAttribute.Downloads, DataType.Integer, contentInfo.Downloads), + GetParameter(ContentAttribute.SettingsXml, DataType.Text, contentInfo.ToString(excludeAttributesNames)), + GetParameter(ContentAttribute.Title, DataType.VarChar, 255, contentInfo.Title), + GetParameter(ContentAttribute.IsTop, DataType.VarChar, 18, contentInfo.IsTop.ToString()), + GetParameter(ContentAttribute.IsRecommend, DataType.VarChar, 18, contentInfo.IsRecommend.ToString()), + GetParameter(ContentAttribute.IsHot, DataType.VarChar, 18, contentInfo.IsHot.ToString()), + GetParameter(ContentAttribute.IsColor, DataType.VarChar, 18, contentInfo.IsColor.ToString()), + GetParameter(ContentAttribute.LinkUrl, DataType.VarChar, 200, contentInfo.LinkUrl), + GetParameter(ContentAttribute.AddDate, DataType.DateTime, contentInfo.AddDate) }; parameters.AddRange(paras); - contentInfo.Id = ExecuteNonQueryAndReturnId(tableName, nameof(ContentInfo.Id), sqlString, parameters.ToArray()); + contentInfo.Id = ExecuteNonQueryAndReturnId(tableName, ContentAttribute.Id, sqlString, parameters.ToArray()); ContentManager.InsertCache(siteInfo, channelInfo, contentInfo); @@ -1166,107 +1174,109 @@ public void Update(SiteInfo siteInfo, ChannelInfo channelInfo, ContentInfo conte var sqlString = $@" UPDATE {tableName} SET - {nameof(ContentInfo.ChannelId)} = @{nameof(ContentInfo.ChannelId)}, - {nameof(ContentInfo.SiteId)} = @{nameof(ContentInfo.SiteId)}, - {nameof(ContentInfo.AddUserName)} = @{nameof(ContentInfo.AddUserName)}, - {nameof(ContentInfo.LastEditUserName)} = @{nameof(ContentInfo.LastEditUserName)}, - {nameof(ContentInfo.LastEditDate)} = @{nameof(ContentInfo.LastEditDate)}, - {nameof(ContentInfo.AdminId)} = @{nameof(ContentInfo.AdminId)}, - {nameof(ContentInfo.UserId)} = @{nameof(ContentInfo.UserId)}, - {nameof(ContentInfo.Taxis)} = @{nameof(ContentInfo.Taxis)}, - {nameof(ContentInfo.GroupNameCollection)} = @{nameof(ContentInfo.GroupNameCollection)}, - {nameof(ContentInfo.Tags)} = @{nameof(ContentInfo.Tags)}, - {nameof(ContentInfo.SourceId)} = @{nameof(ContentInfo.SourceId)}, - {nameof(ContentInfo.ReferenceId)} = @{nameof(ContentInfo.ReferenceId)},"; + {ContentAttribute.ChannelId} = @{ContentAttribute.ChannelId}, + {ContentAttribute.SiteId} = @{ContentAttribute.SiteId}, + {ContentAttribute.AddUserName} = @{ContentAttribute.AddUserName}, + {ContentAttribute.LastEditUserName} = @{ContentAttribute.LastEditUserName}, + {ContentAttribute.LastEditDate} = @{ContentAttribute.LastEditDate}, + {ContentAttribute.AdminId} = @{ContentAttribute.AdminId}, + {ContentAttribute.UserId} = @{ContentAttribute.UserId}, + {ContentAttribute.Taxis} = @{ContentAttribute.Taxis}, + {ContentAttribute.GroupNameCollection} = @{ContentAttribute.GroupNameCollection}, + {ContentAttribute.Tags} = @{ContentAttribute.Tags}, + {ContentAttribute.SourceId} = @{ContentAttribute.SourceId}, + {ContentAttribute.ReferenceId} = @{ContentAttribute.ReferenceId},"; if (contentInfo.CheckedLevel != CheckManager.LevelInt.NotChange) { sqlString += $@" - {nameof(ContentInfo.IsChecked)} = @{nameof(ContentInfo.IsChecked)}, - {nameof(ContentInfo.CheckedLevel)} = @{nameof(ContentInfo.CheckedLevel)},"; + {ContentAttribute.IsChecked} = @{ContentAttribute.IsChecked}, + {ContentAttribute.CheckedLevel} = @{ContentAttribute.CheckedLevel},"; } sqlString += $@" - {nameof(ContentInfo.Hits)} = @{nameof(ContentInfo.Hits)}, - {nameof(ContentInfo.HitsByDay)} = @{nameof(ContentInfo.HitsByDay)}, - {nameof(ContentInfo.HitsByWeek)} = @{nameof(ContentInfo.HitsByWeek)}, - {nameof(ContentInfo.HitsByMonth)} = @{nameof(ContentInfo.HitsByMonth)}, - {nameof(ContentInfo.LastHitsDate)} = @{nameof(ContentInfo.LastHitsDate)}, - {nameof(ContentInfo.SettingsXml)} = @{nameof(ContentInfo.SettingsXml)}, - {nameof(ContentInfo.Title)} = @{nameof(ContentInfo.Title)}, - {nameof(ContentInfo.IsTop)} = @{nameof(ContentInfo.IsTop)}, - {nameof(ContentInfo.IsRecommend)} = @{nameof(ContentInfo.IsRecommend)}, - {nameof(ContentInfo.IsHot)} = @{nameof(ContentInfo.IsHot)}, - {nameof(ContentInfo.IsColor)} = @{nameof(ContentInfo.IsColor)}, - {nameof(ContentInfo.LinkUrl)} = @{nameof(ContentInfo.LinkUrl)}, - {nameof(ContentInfo.AddDate)} = @{nameof(ContentInfo.AddDate)} + {ContentAttribute.Hits} = @{ContentAttribute.Hits}, + {ContentAttribute.HitsByDay} = @{ContentAttribute.HitsByDay}, + {ContentAttribute.HitsByWeek} = @{ContentAttribute.HitsByWeek}, + {ContentAttribute.HitsByMonth} = @{ContentAttribute.HitsByMonth}, + {ContentAttribute.LastHitsDate} = @{ContentAttribute.LastHitsDate}, + {ContentAttribute.Downloads} = @{ContentAttribute.Downloads}, + {ContentAttribute.SettingsXml} = @{ContentAttribute.SettingsXml}, + {ContentAttribute.Title} = @{ContentAttribute.Title}, + {ContentAttribute.IsTop} = @{ContentAttribute.IsTop}, + {ContentAttribute.IsRecommend} = @{ContentAttribute.IsRecommend}, + {ContentAttribute.IsHot} = @{ContentAttribute.IsHot}, + {ContentAttribute.IsColor} = @{ContentAttribute.IsColor}, + {ContentAttribute.LinkUrl} = @{ContentAttribute.LinkUrl}, + {ContentAttribute.AddDate} = @{ContentAttribute.AddDate} {sets} -WHERE {nameof(ContentInfo.Id)} = @{nameof(ContentInfo.Id)}"; +WHERE {ContentAttribute.Id} = @{ContentAttribute.Id}"; var parameters = new List { - GetParameter(nameof(ContentInfo.ChannelId), DataType.Integer, channelInfo.Id), - GetParameter(nameof(ContentInfo.SiteId), DataType.Integer, siteInfo.Id), - GetParameter(nameof(ContentInfo.AddUserName), DataType.VarChar, 255, contentInfo.AddUserName), - GetParameter(nameof(ContentInfo.LastEditUserName), DataType.VarChar, 255, + GetParameter(ContentAttribute.ChannelId, DataType.Integer, channelInfo.Id), + GetParameter(ContentAttribute.SiteId, DataType.Integer, siteInfo.Id), + GetParameter(ContentAttribute.AddUserName, DataType.VarChar, 255, contentInfo.AddUserName), + GetParameter(ContentAttribute.LastEditUserName, DataType.VarChar, 255, contentInfo.LastEditUserName), - GetParameter(nameof(ContentInfo.LastEditDate), DataType.DateTime, contentInfo.LastEditDate), - GetParameter(nameof(ContentInfo.AdminId), DataType.Integer, + GetParameter(ContentAttribute.LastEditDate, DataType.DateTime, contentInfo.LastEditDate), + GetParameter(ContentAttribute.AdminId, DataType.Integer, contentInfo.AdminId), - GetParameter(nameof(ContentInfo.UserId), DataType.Integer, + GetParameter(ContentAttribute.UserId, DataType.Integer, contentInfo.UserId), - GetParameter(nameof(ContentInfo.Taxis), DataType.Integer, contentInfo.Taxis), - GetParameter(nameof(ContentInfo.GroupNameCollection), DataType.VarChar, 255, + GetParameter(ContentAttribute.Taxis, DataType.Integer, contentInfo.Taxis), + GetParameter(ContentAttribute.GroupNameCollection, DataType.VarChar, 255, contentInfo.GroupNameCollection), - GetParameter(nameof(ContentInfo.Tags), DataType.VarChar, 255, contentInfo.Tags), - GetParameter(nameof(ContentInfo.SourceId), DataType.Integer, contentInfo.SourceId), - GetParameter(nameof(ContentInfo.ReferenceId), DataType.Integer, contentInfo.ReferenceId), + GetParameter(ContentAttribute.Tags, DataType.VarChar, 255, contentInfo.Tags), + GetParameter(ContentAttribute.SourceId, DataType.Integer, contentInfo.SourceId), + GetParameter(ContentAttribute.ReferenceId, DataType.Integer, contentInfo.ReferenceId), }; if (contentInfo.CheckedLevel != CheckManager.LevelInt.NotChange) { - parameters.Add(GetParameter(nameof(ContentInfo.IsChecked), DataType.VarChar, 18, + parameters.Add(GetParameter(ContentAttribute.IsChecked, DataType.VarChar, 18, contentInfo.IsChecked.ToString())); - parameters.Add(GetParameter(nameof(ContentInfo.CheckedLevel), DataType.Integer, + parameters.Add(GetParameter(ContentAttribute.CheckedLevel, DataType.Integer, contentInfo.CheckedLevel)); } - parameters.Add(GetParameter(nameof(ContentInfo.Hits), DataType.Integer, contentInfo.Hits)); + parameters.Add(GetParameter(ContentAttribute.Hits, DataType.Integer, contentInfo.Hits)); parameters.Add( - GetParameter(nameof(ContentInfo.HitsByDay), DataType.Integer, contentInfo.HitsByDay)); + GetParameter(ContentAttribute.HitsByDay, DataType.Integer, contentInfo.HitsByDay)); parameters.Add( - GetParameter(nameof(ContentInfo.HitsByWeek), DataType.Integer, contentInfo.HitsByWeek)); + GetParameter(ContentAttribute.HitsByWeek, DataType.Integer, contentInfo.HitsByWeek)); parameters.Add( - GetParameter(nameof(ContentInfo.HitsByMonth), DataType.Integer, + GetParameter(ContentAttribute.HitsByMonth, DataType.Integer, contentInfo.HitsByMonth)); parameters.Add( - GetParameter(nameof(ContentInfo.LastHitsDate), DataType.DateTime, + GetParameter(ContentAttribute.LastHitsDate, DataType.DateTime, contentInfo.LastHitsDate)); + parameters.Add(GetParameter(ContentAttribute.Downloads, DataType.Integer, contentInfo.Downloads)); parameters.Add( - GetParameter(nameof(ContentInfo.SettingsXml), DataType.Text, + GetParameter(ContentAttribute.SettingsXml, DataType.Text, contentInfo.ToString(excludeAttributesNames))); parameters.Add( - GetParameter(nameof(ContentInfo.Title), DataType.VarChar, 255, + GetParameter(ContentAttribute.Title, DataType.VarChar, 255, contentInfo.Title)); parameters.Add( - GetParameter(nameof(ContentInfo.IsTop), DataType.VarChar, 18, + GetParameter(ContentAttribute.IsTop, DataType.VarChar, 18, contentInfo.IsTop.ToString())); parameters.Add( - GetParameter(nameof(ContentInfo.IsRecommend), DataType.VarChar, + GetParameter(ContentAttribute.IsRecommend, DataType.VarChar, 18, contentInfo.IsRecommend.ToString())); parameters.Add( - GetParameter(nameof(ContentInfo.IsHot), DataType.VarChar, 18, + GetParameter(ContentAttribute.IsHot, DataType.VarChar, 18, contentInfo.IsHot.ToString())); parameters.Add( - GetParameter(nameof(ContentInfo.IsColor), + GetParameter(ContentAttribute.IsColor, DataType.VarChar, 18, contentInfo.IsColor.ToString())); parameters.Add( - GetParameter(nameof(ContentInfo.LinkUrl), + GetParameter(ContentAttribute.LinkUrl, DataType.VarChar, 200, contentInfo.LinkUrl)); parameters.Add(GetParameter( - $"@{nameof(ContentInfo.AddDate)}", DataType.DateTime, + $"@{ContentAttribute.AddDate}", DataType.DateTime, contentInfo.AddDate)); parameters.AddRange(paras); - parameters.Add(GetParameter(nameof(ContentInfo.Id), DataType.Integer, contentInfo.Id)); + parameters.Add(GetParameter(ContentAttribute.Id, DataType.Integer, contentInfo.Id)); ExecuteNonQuery(sqlString, parameters.ToArray()); @@ -1350,7 +1360,7 @@ public List GetContentCountInfoList(string tableName) List list; var sqlString = - $@"SELECT {nameof(ContentInfo.SiteId)}, {nameof(ContentInfo.ChannelId)}, {nameof(ContentInfo.IsChecked)}, {nameof(ContentInfo.CheckedLevel)}, {nameof(ContentInfo.AdminId)}, COUNT(*) AS {nameof(ContentCountInfo.Count)} FROM {tableName} WHERE {nameof(ContentInfo.ChannelId)} > 0 AND {nameof(ContentInfo.SourceId)} != {SourceManager.Preview} GROUP BY {nameof(ContentInfo.SiteId)}, {nameof(ContentInfo.ChannelId)}, {nameof(ContentInfo.IsChecked)}, {nameof(ContentInfo.CheckedLevel)}, {nameof(ContentInfo.AdminId)}"; + $@"SELECT {ContentAttribute.SiteId}, {ContentAttribute.ChannelId}, {ContentAttribute.IsChecked}, {ContentAttribute.CheckedLevel}, {ContentAttribute.AdminId}, COUNT(*) AS {nameof(ContentCountInfo.Count)} FROM {tableName} WHERE {ContentAttribute.ChannelId} > 0 AND {ContentAttribute.SourceId} != {SourceManager.Preview} GROUP BY {ContentAttribute.SiteId}, {ContentAttribute.ChannelId}, {ContentAttribute.IsChecked}, {ContentAttribute.CheckedLevel}, {ContentAttribute.AdminId}"; using (var connection = GetConnection()) { @@ -1364,7 +1374,7 @@ public int GetCountCheckedImage(int siteId, int channelId) { var tableName = SiteManager.GetSiteInfo(siteId).TableName; var sqlString = - $"SELECT COUNT(*) FROM {tableName} WHERE {nameof(ContentInfo.ChannelId)} = {channelId} AND {nameof(ContentInfo.ImageUrl)} != '' AND {ContentAttribute.IsChecked} = '{true}' AND {nameof(ContentInfo.SourceId)} != {SourceManager.Preview}"; + $"SELECT COUNT(*) FROM {tableName} WHERE {ContentAttribute.ChannelId} = {channelId} AND {nameof(ContentInfo.ImageUrl)} != '' AND {ContentAttribute.IsChecked} = '{true}' AND {ContentAttribute.SourceId} != {SourceManager.Preview}"; return DataProvider.DatabaseDao.GetIntResult(sqlString); } @@ -1545,6 +1555,15 @@ private DataSet GetStlDataSourceByStartNum(string tableName, int startNum, int t return dataset; } + public void AddDownloads(string tableName, int channelId, int contentId) + { + var sqlString = + $"UPDATE {tableName} SET {Context.DatabaseApi.ToPlusSqlString(ContentAttribute.Downloads, 1)} WHERE Id = {contentId}"; + Context.DatabaseApi.ExecuteNonQuery(Context.ConnectionString, sqlString); + + ContentManager.RemoveCache(tableName, channelId); + } + private int GetTaxisToInsert(string tableName, int channelId, bool isTop) { int taxis; @@ -2552,17 +2571,17 @@ private string GetCreateContentTableSqlString(string tableName, List columnInfoLis //private string GetCacheWhereString(SiteInfo siteInfo, ChannelInfo channelInfo) //{ - // return $"WHERE {nameof(ContentInfo.SiteId)} = {siteInfo.Id} AND {nameof(ContentInfo.ChannelId)} = {channelInfo.Id} AND {nameof(ContentAttribute.SourceId)} != {SourceManager.Preview}"; + // return $"WHERE {ContentAttribute.SiteId} = {siteInfo.Id} AND {ContentAttribute.ChannelId} = {channelInfo.Id} AND {nameof(ContentAttribute.SourceId)} != {SourceManager.Preview}"; //} public string GetCacheWhereString(SiteInfo siteInfo, ChannelInfo channelInfo, int? onlyAdminId) { - var whereString = $"WHERE {nameof(ContentInfo.SiteId)} = {siteInfo.Id} AND {nameof(ContentInfo.ChannelId)} = {channelInfo.Id} AND {nameof(ContentAttribute.SourceId)} != {SourceManager.Preview}"; + var whereString = $"WHERE {ContentAttribute.SiteId} = {siteInfo.Id} AND {ContentAttribute.ChannelId} = {channelInfo.Id} AND {nameof(ContentAttribute.SourceId)} != {SourceManager.Preview}"; if (onlyAdminId.HasValue) { whereString += $" AND {nameof(ContentAttribute.AdminId)} = {onlyAdminId.Value}"; diff --git a/SiteServer.CMS/Provider/TemplateDao.cs b/SiteServer.CMS/Provider/TemplateDao.cs index 441aa57bb..d2732cc0b 100644 --- a/SiteServer.CMS/Provider/TemplateDao.cs +++ b/SiteServer.CMS/Provider/TemplateDao.cs @@ -258,19 +258,19 @@ public string GetImportTemplateName(int siteId, string templateName) { var dictionary = new Dictionary(); - var parms = new IDataParameter[] + var parameters = new IDataParameter[] { GetParameter(ParmSiteId, DataType.Integer, siteId) }; - using (var rdr = ExecuteReader(SqlSelectTemplateCount, parms)) + using (var rdr = ExecuteReader(SqlSelectTemplateCount, parameters)) { while (rdr.Read()) { var templateType = TemplateTypeUtils.GetEnumType(GetString(rdr, 0)); var count = GetInt(rdr, 1); - dictionary.Add(templateType, count); + dictionary[templateType] = count; } rdr.Close(); } @@ -487,7 +487,7 @@ public void CreateDefaultTemplateInfo(int siteId, string administratorName) { var i = 0; var info = new TemplateInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), TemplateTypeUtils.GetEnumType(GetString(rdr, i++)), GetString(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), ECharsetUtils.GetEnumType(GetString(rdr, i++)), GetBool(rdr, i)); - dictionary.Add(info.Id, info); + dictionary[info.Id] = info; } rdr.Close(); } diff --git a/SiteServer.CMS/StlParser/StlElement/StlContent.cs b/SiteServer.CMS/StlParser/StlElement/StlContent.cs index 65b3a7f3f..42a401e9c 100644 --- a/SiteServer.CMS/StlParser/StlElement/StlContent.cs +++ b/SiteServer.CMS/StlParser/StlElement/StlContent.cs @@ -457,7 +457,7 @@ private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, stri else { //第一条 - sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.GetString(BackgroundContentAttribute.FileUrl), contextInfo.Attributes, contextInfo.InnerHtml, false)); + sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.GetString(BackgroundContentAttribute.FileUrl), contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetString(extendAttributeName); @@ -465,7 +465,7 @@ private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, stri { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { - sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, extendValue, contextInfo.Attributes, contextInfo.InnerHtml, false)); + sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, extendValue, contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper)); } } @@ -511,7 +511,7 @@ private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, stri { if (num <= 1) { - parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.GetString(BackgroundContentAttribute.FileUrl), contextInfo.Attributes, contextInfo.InnerHtml, false); + parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.GetString(BackgroundContentAttribute.FileUrl), contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper); } else { @@ -524,7 +524,7 @@ private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, stri { if (index == num) { - parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, extendValue, contextInfo.Attributes, contextInfo.InnerHtml, false); + parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, extendValue, contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper); break; } index++; diff --git a/SiteServer.CMS/StlParser/StlElement/StlFile.cs b/SiteServer.CMS/StlParser/StlElement/StlFile.cs index ae18f72a5..9f261906d 100644 --- a/SiteServer.CMS/StlParser/StlElement/StlFile.cs +++ b/SiteServer.CMS/StlParser/StlElement/StlFile.cs @@ -23,12 +23,24 @@ public class StlFile [StlAttribute(Title = "需要下载的文件地址")] private const string Src = nameof(Src); - [StlAttribute(Title = "显示文件大小")] + [StlAttribute(Title = "仅显示文件名称")] + private const string IsFileName = nameof(IsFileName); + + [StlAttribute(Title = "仅显示文件类型")] + private const string IsFileType = nameof(IsFileType); + + [StlAttribute(Title = "仅显示文件大小")] private const string IsFileSize = nameof(IsFileSize); - [StlAttribute(Title = "是否记录文件下载次数")] + [StlAttribute(Title = "仅显示下载次数")] private const string IsCount = nameof(IsCount); + [StlAttribute(Title = "是否转换为小写")] + private const string IsLower = nameof(IsLower); + + [StlAttribute(Title = "是否转换为大写")] + private const string IsUpper = nameof(IsUpper); + [StlAttribute(Title = "显示在信息前的文字")] private const string LeftText = nameof(LeftText); @@ -40,8 +52,12 @@ public static string Parse(PageInfo pageInfo, ContextInfo contextInfo) var type = BackgroundContentAttribute.FileUrl; var no = 0; var src = string.Empty; - var isFilesize = false; - var isCount = true; + var isFileName = false; + var isFileType = false; + var isFileSize = false; + var isCount = false; + var isLower = false; + var isUpper = false; var leftText = string.Empty; var rightText = string.Empty; @@ -61,14 +77,30 @@ public static string Parse(PageInfo pageInfo, ContextInfo contextInfo) { src = value; } + else if (StringUtils.EqualsIgnoreCase(name, IsFileName)) + { + isFileName = TranslateUtils.ToBool(value); + } + else if (StringUtils.EqualsIgnoreCase(name, IsFileType)) + { + isFileType = TranslateUtils.ToBool(value); + } else if (StringUtils.EqualsIgnoreCase(name, IsFileSize)) { - isFilesize = TranslateUtils.ToBool(value); + isFileSize = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, IsCount)) { isCount = TranslateUtils.ToBool(value); } + else if (StringUtils.EqualsIgnoreCase(name, IsLower)) + { + isLower = TranslateUtils.ToBool(value); + } + else if (StringUtils.EqualsIgnoreCase(name, IsUpper)) + { + isUpper = TranslateUtils.ToBool(value); + } else if (StringUtils.EqualsIgnoreCase(name, LeftText)) { leftText = value; @@ -79,10 +111,10 @@ public static string Parse(PageInfo pageInfo, ContextInfo contextInfo) } } - return ParseImpl(pageInfo, contextInfo, type, no, src, isFilesize, isCount, leftText, rightText); + return ParseImpl(pageInfo, contextInfo, type, no, src, isFileName, isFileType, isFileSize, isCount, isLower, isUpper, leftText, rightText); } - private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string type, int no, string src, bool isFilesize, bool isCount, string leftText, string rightText) + private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string type, int no, string src, bool isFileName, bool isFileType, bool isFileSize, bool isCount, bool isLower, bool isUpper, string leftText, string rightText) { if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { @@ -142,23 +174,58 @@ private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, stri } } - var parsedContent = InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, contextInfo.Attributes, contextInfo.InnerHtml, contextInfo.IsStlEntity); + string parsedContent; - if (isFilesize) + if (isFileName) + { + parsedContent = PathUtils.RemoveExtension(PageUtils.GetFileNameFromUrl(fileUrl)); + if (isLower) + { + parsedContent = parsedContent.ToLower(); + } + if (isUpper) + { + parsedContent = parsedContent.ToUpper(); + } + } + else if (isFileType) + { + var filePath = PathUtility.MapPath(pageInfo.SiteInfo, fileUrl); + parsedContent = PathUtils.GetExtension(filePath).Trim('.'); + if (isLower) + { + parsedContent = parsedContent.ToLower(); + } + if (isUpper) + { + parsedContent = parsedContent.ToUpper(); + } + } + else if (isFileSize) { var filePath = PathUtility.MapPath(pageInfo.SiteInfo, fileUrl); - parsedContent += " (" + FileUtils.GetFileSizeByFilePath(filePath) + ")"; + parsedContent = FileUtils.GetFileSizeByFilePath(filePath); + } + else if (isCount) + { + parsedContent = (contextInfo.ContentInfo?.Downloads ?? 0).ToString(); } else { - if (isCount && contextInfo.ContentInfo != null) + var innerHtml = string.Empty; + if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { - parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contextInfo.ContentInfo.ChannelId, contextInfo.ContentInfo.Id, fileUrl, contextInfo.Attributes, contextInfo.InnerHtml, contextInfo.IsStlEntity); + var innerBuilder = new StringBuilder(contextInfo.InnerHtml); + StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); + innerHtml = innerBuilder.ToString(); } - else - { - parsedContent = InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, contextInfo.Attributes, contextInfo.InnerHtml, contextInfo.IsStlEntity); - } + + parsedContent = contextInfo.ContentInfo != null + ? InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contextInfo.ContentInfo.ChannelId, + contextInfo.ContentInfo.Id, fileUrl, contextInfo.Attributes, innerHtml, + contextInfo.IsStlEntity, isLower, isUpper) + : InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, contextInfo.Attributes, + innerHtml, contextInfo.IsStlEntity, isLower, isUpper); } if (!string.IsNullOrEmpty(parsedContent)) diff --git a/SiteServer.Web/Controllers/Sys/SysStlActionsDownloadController.cs b/SiteServer.Web/Controllers/Sys/SysStlActionsDownloadController.cs index 8f60b887d..dd10ee584 100644 --- a/SiteServer.Web/Controllers/Sys/SysStlActionsDownloadController.cs +++ b/SiteServer.Web/Controllers/Sys/SysStlActionsDownloadController.cs @@ -17,7 +17,6 @@ public class SysStlActionsDownloadController : ApiController [Route(ApiRouteActionsDownload.Route)] public void Main() { - var isSuccess = false; try { var request = new RequestImpl(); @@ -29,28 +28,26 @@ public void Main() if (PageUtils.IsProtocolUrl(fileUrl)) { - isSuccess = true; PageUtils.Redirect(fileUrl); + return; } - else + + var siteInfo = SiteManager.GetSiteInfo(siteId); + var filePath = PathUtility.MapPath(siteInfo, fileUrl); + var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath)); + if (EFileSystemTypeUtils.IsDownload(fileType)) { - var siteInfo = SiteManager.GetSiteInfo(siteId); - var filePath = PathUtility.MapPath(siteInfo, fileUrl); - var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath)); - if (EFileSystemTypeUtils.IsDownload(fileType)) - { - if (FileUtils.IsFileExists(filePath)) - { - isSuccess = true; - PageUtils.Download(HttpContext.Current.Response, filePath); - } - } - else + if (FileUtils.IsFileExists(filePath)) { - isSuccess = true; - PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false)); + PageUtils.Download(HttpContext.Current.Response, filePath); + return; } } + else + { + PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false)); + return; + } } else if (!string.IsNullOrEmpty(request.GetQueryString("filePath"))) { @@ -60,15 +57,15 @@ public void Main() { if (FileUtils.IsFileExists(filePath)) { - isSuccess = true; PageUtils.Download(HttpContext.Current.Response, filePath); + return; } } else { - isSuccess = true; var fileUrl = PageUtils.GetRootUrlByPhysicalPath(filePath); PageUtils.Redirect(PageUtils.ParseNavigationUrl(fileUrl)); + return; } } else if (!string.IsNullOrEmpty(request.GetQueryString("siteId")) && !string.IsNullOrEmpty(request.GetQueryString("channelId")) && !string.IsNullOrEmpty(request.GetQueryString("contentId")) && !string.IsNullOrEmpty(request.GetQueryString("fileUrl"))) @@ -81,31 +78,31 @@ public void Main() var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId); var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId); + DataProvider.ContentDao.AddDownloads(ChannelManager.GetTableName(siteInfo, channelInfo), channelId, contentId); + if (!string.IsNullOrEmpty(contentInfo?.GetString(BackgroundContentAttribute.FileUrl))) { if (PageUtils.IsProtocolUrl(fileUrl)) { - isSuccess = true; PageUtils.Redirect(fileUrl); + return; } - else + + var filePath = PathUtility.MapPath(siteInfo, fileUrl, true); + var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath)); + if (EFileSystemTypeUtils.IsDownload(fileType)) { - var filePath = PathUtility.MapPath(siteInfo, fileUrl, true); - var fileType = EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath)); - if (EFileSystemTypeUtils.IsDownload(fileType)) - { - if (FileUtils.IsFileExists(filePath)) - { - isSuccess = true; - PageUtils.Download(HttpContext.Current.Response, filePath); - } - } - else + if (FileUtils.IsFileExists(filePath)) { - isSuccess = true; - PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false)); + PageUtils.Download(HttpContext.Current.Response, filePath); + return; } } + else + { + PageUtils.Redirect(PageUtility.ParseNavigationUrl(siteInfo, fileUrl, false)); + return; + } } } } @@ -113,10 +110,8 @@ public void Main() { // ignored } - if (!isSuccess) - { - HttpContext.Current.Response.Write("下载失败,不存在此文件!"); - } + + HttpContext.Current.Response.Write("下载失败,不存在此文件!"); } } } diff --git a/SiteServer.Web/Controllers/V1/V1CaptchaController.cs b/SiteServer.Web/Controllers/V1/V1CaptchaController.cs index 5662a622b..eb36e14ca 100644 --- a/SiteServer.Web/Controllers/V1/V1CaptchaController.cs +++ b/SiteServer.Web/Controllers/V1/V1CaptchaController.cs @@ -42,40 +42,50 @@ public void Get(string name) response.AppendHeader("Pragma", "No-Cache"); //特别注意 response.ContentType = "image/png"; - var validateimage = new Bitmap(130, 53, PixelFormat.Format32bppRgb); + byte[] buffer; - var r = new Random(); - var colors = Colors[r.Next(0, 5)]; + using (var image = new Bitmap(130, 53, PixelFormat.Format32bppRgb)) + { + var r = new Random(); + var colors = Colors[r.Next(0, 5)]; - var g = Graphics.FromImage(validateimage); - g.FillRectangle(new SolidBrush(Color.FromArgb(240, 243, 248)), 0, 0, 200, 200); //矩形框 - g.DrawString(code, new Font(FontFamily.GenericSerif, 28, FontStyle.Bold | FontStyle.Italic), new SolidBrush(colors), new PointF(14, 3));//字体/颜色 + using (var g = Graphics.FromImage(image)) + { + g.FillRectangle(new SolidBrush(Color.FromArgb(240, 243, 248)), 0, 0, 200, 200); //矩形框 + g.DrawString(code, new Font(FontFamily.GenericSerif, 28, FontStyle.Bold | FontStyle.Italic), new SolidBrush(colors), new PointF(14, 3));//字体/颜色 - var random = new Random(); + var random = new Random(); - for (var i = 0; i < 25; i++) - { - var x1 = random.Next(validateimage.Width); - var x2 = random.Next(validateimage.Width); - var y1 = random.Next(validateimage.Height); - var y2 = random.Next(validateimage.Height); + for (var i = 0; i < 25; i++) + { + var x1 = random.Next(image.Width); + var x2 = random.Next(image.Width); + var y1 = random.Next(image.Height); + var y2 = random.Next(image.Height); - g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); - } + g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); + } - for (var i = 0; i < 100; i++) - { - var x = random.Next(validateimage.Width); - var y = random.Next(validateimage.Height); + for (var i = 0; i < 100; i++) + { + var x = random.Next(image.Width); + var y = random.Next(image.Height); - validateimage.SetPixel(x, y, Color.FromArgb(random.Next())); - } + image.SetPixel(x, y, Color.FromArgb(random.Next())); + } - g.Save(); - var ms = new MemoryStream(); - validateimage.Save(ms, ImageFormat.Png); + g.Save(); + } + + using (var ms = new MemoryStream()) + { + image.Save(ms, ImageFormat.Png); + buffer = ms.ToArray(); + } + } + response.ClearContent(); - response.BinaryWrite(ms.ToArray()); + response.BinaryWrite(buffer); response.End(); } diff --git a/SiteServer.Web/SiteServer/Cms/create.cshtml b/SiteServer.Web/SiteServer/Cms/create.cshtml index 9131f9d9b..fee348623 100644 --- a/SiteServer.Web/SiteServer/Cms/create.cshtml +++ b/SiteServer.Web/SiteServer/Cms/create.cshtml @@ -48,20 +48,20 @@
- -
@@ -79,4 +79,4 @@
@section Scripts{ - } \ No newline at end of file + } diff --git a/SiteServer.Web/SiteServer/Cms/modalContentAttributes.aspx b/SiteServer.Web/SiteServer/Cms/modalContentAttributes.aspx index 7a33b9933..9cd5a7597 100644 --- a/SiteServer.Web/SiteServer/Cms/modalContentAttributes.aspx +++ b/SiteServer.Web/SiteServer/Cms/modalContentAttributes.aspx @@ -73,6 +73,9 @@
  • 设置点击量
  • +
  • + 设置下载量 +
  • @@ -100,6 +103,17 @@ + +
    @@ -113,4 +127,4 @@ - \ No newline at end of file + diff --git a/SiteServer.Web/SiteServer/Cms/pageTemplateReference.aspx b/SiteServer.Web/SiteServer/Cms/pageTemplateReference.aspx new file mode 100644 index 000000000..c6e13343a --- /dev/null +++ b/SiteServer.Web/SiteServer/Cms/pageTemplateReference.aspx @@ -0,0 +1,40 @@ +<%@ Page Language="C#" Inherits="SiteServer.BackgroundPages.Cms.PageTemplateReference" enableviewstate="false"%> +<%@ Register TagPrefix="ctrl" Namespace="SiteServer.BackgroundPages.Controls" Assembly="SiteServer.BackgroundPages" %> + + + + + + + + + +
    + + + +
    +
    + +
    +
    +
    + +
    + +
    + STL语言参考 +
    +

    + STL语言为SiteServer模板语言(SiteServer Template Language)的缩写,是一种和HTML语言类似的服务器端语言。 + STL 语言参考手册 +

    + + + +
    + + + + + diff --git a/SiteServer.Web/SiteServer/assets/menus/Site.config b/SiteServer.Web/SiteServer/assets/menus/Site.config index e40a1813a..50bf6593e 100644 --- a/SiteServer.Web/SiteServer/assets/menus/Site.config +++ b/SiteServer.Web/SiteServer/assets/menus/Site.config @@ -22,6 +22,7 @@ +