public override void Submit_OnClick(object sender, EventArgs e) { if (Page.IsPostBack && Page.IsValid) { if (_theTemplateType != ETemplateType.ChannelTemplate) { if (!CreatedFileFullName.Text.StartsWith("~") && !CreatedFileFullName.Text.StartsWith("@")) { CreatedFileFullName.Text = PageUtils.Combine("@", CreatedFileFullName.Text); } } else { CreatedFileFullName.Text = CreatedFileFullName.Text.TrimStart('~', '@'); CreatedFileFullName.Text = CreatedFileFullName.Text.Replace("/", string.Empty); } if (Body.GetQueryInt("TemplateID") > 0 && _isCopy == false) { var templateId = Body.GetQueryInt("TemplateID"); var templateInfo = TemplateManager.GetTemplateInfo(PublishmentSystemId, templateId); if (templateInfo.TemplateName != TemplateName.Text) { var templateNameArrayList = DataProvider.TemplateDao.GetTemplateNameArrayList(PublishmentSystemId, templateInfo.TemplateType); if (templateNameArrayList.IndexOf(TemplateName.Text) != -1) { FailMessage("模板修改失败,模板名称已存在!"); return; } } TemplateInfo previousTemplateInfo = null; var isChanged = false; if (PathUtils.RemoveExtension(templateInfo.RelatedFileName) != PathUtils.RemoveExtension(RelatedFileName.Text))//文件名改变 { var fileNameArrayList = DataProvider.TemplateDao.GetLowerRelatedFileNameArrayList(PublishmentSystemId, templateInfo.TemplateType); foreach (string fileName in fileNameArrayList) { var fileNameWithoutExtension = PathUtils.RemoveExtension(fileName); if (fileNameWithoutExtension == RelatedFileName.Text.ToLower()) { FailMessage("模板修改失败,模板文件已存在!"); return; } } isChanged = true; } if (GetTemplateFileExtension(templateInfo) != CreatedFileExtNameDropDownList.SelectedValue)//文件后缀改变 { isChanged = true; } if (isChanged) { previousTemplateInfo = new TemplateInfo(templateInfo.TemplateId, templateInfo.PublishmentSystemId, templateInfo.TemplateName, templateInfo.TemplateType, templateInfo.RelatedFileName, templateInfo.CreatedFileFullName, templateInfo.CreatedFileExtName, templateInfo.Charset, templateInfo.IsDefault); } templateInfo.TemplateName = TemplateName.Text; templateInfo.RelatedFileName = RelatedFileName.Text + CreatedFileExtNameDropDownList.SelectedValue; templateInfo.CreatedFileExtName = CreatedFileExtNameDropDownList.SelectedValue; templateInfo.CreatedFileFullName = CreatedFileFullName.Text + CreatedFileExtNameDropDownList.SelectedValue; templateInfo.Charset = ECharsetUtils.GetEnumType(Charset.SelectedValue); try { DataProvider.TemplateDao.Update(PublishmentSystemInfo, templateInfo, Content.Text, Body.AdministratorName); if (previousTemplateInfo != null) { FileUtils.DeleteFileIfExists(TemplateManager.GetTemplateFilePath(PublishmentSystemInfo, previousTemplateInfo)); } CreatePages(templateInfo); Body.AddSiteLog(PublishmentSystemId, $"修改{ETemplateTypeUtils.GetText(templateInfo.TemplateType)}", $"模板名称:{templateInfo.TemplateName}"); SuccessMessage("模板修改成功!"); } catch (Exception ex) { FailMessage(ex, "模板修改失败," + ex.Message); } } else { var templateNameArrayList = DataProvider.TemplateDao.GetTemplateNameArrayList(PublishmentSystemId, ETemplateTypeUtils.GetEnumType(TemplateType.Value)); if (templateNameArrayList.IndexOf(TemplateName.Text) != -1) { FailMessage("模板添加失败,模板名称已存在!"); return; } var fileNameArrayList = DataProvider.TemplateDao.GetLowerRelatedFileNameArrayList(PublishmentSystemId, ETemplateTypeUtils.GetEnumType(TemplateType.Value)); if (fileNameArrayList.IndexOf(RelatedFileName.Text.ToLower()) != -1) { FailMessage("模板添加失败,模板文件已存在!"); return; } var templateInfo = new TemplateInfo(); templateInfo.PublishmentSystemId = PublishmentSystemId; templateInfo.TemplateName = TemplateName.Text; templateInfo.TemplateType = ETemplateTypeUtils.GetEnumType(TemplateType.Value); templateInfo.RelatedFileName = RelatedFileName.Text + CreatedFileExtNameDropDownList.SelectedValue; templateInfo.CreatedFileExtName = CreatedFileExtNameDropDownList.SelectedValue; templateInfo.CreatedFileFullName = CreatedFileFullName.Text + CreatedFileExtNameDropDownList.SelectedValue; templateInfo.Charset = ECharsetUtils.GetEnumType(Charset.SelectedValue); templateInfo.IsDefault = false; try { templateInfo.TemplateId = DataProvider.TemplateDao.Insert(templateInfo, Content.Text, Body.AdministratorName); CreatePages(templateInfo); Body.AddSiteLog(PublishmentSystemId, $"添加{ETemplateTypeUtils.GetText(templateInfo.TemplateType)}", $"模板名称:{templateInfo.TemplateName}"); SuccessMessage("模板添加成功!"); AddWaitAndRedirectScript(PageTemplate.GetRedirectUrl(PublishmentSystemId)); } catch (Exception ex) { FailMessage(ex, "模板添加失败," + ex.Message); } } } }
private static string GetAnalysisValue(PageInfo pageInfo, int channelId, int contentId, string templateType, string type, string scope, bool isAverage, string style, int addNum, string since, string referrer) { var publishmentSystemInfo = pageInfo.PublishmentSystemInfo; if (publishmentSystemInfo == null) { return(string.Empty); } var html = string.Empty; var eStyle = publishmentSystemInfo.Additional.TrackerStyle; if (!string.IsNullOrEmpty(style)) { eStyle = ETrackerStyleUtils.GetEnumType(style); } if (string.IsNullOrEmpty(scope) || !StringUtils.EqualsIgnoreCase(scope, ScopeSite)) { scope = ScopePage; } var eTemplateType = ETemplateTypeUtils.GetEnumType(templateType); var accessNum = 0; var sinceDate = DateUtils.SqlMinValue; if (!string.IsNullOrEmpty(since)) { sinceDate = DateTime.Now.AddHours(-DateUtils.GetSinceHours(since)); } if (StringUtils.EqualsIgnoreCase(type, TypePageView)) { if (StringUtils.EqualsIgnoreCase(scope, ScopePage)) { accessNum = eTemplateType != ETemplateType.FileTemplate ? DataProvider.TrackingDao.GetTotalAccessNumByPageInfo(pageInfo.PublishmentSystemId, channelId, contentId, sinceDate) : DataProvider.TrackingDao.GetTotalAccessNumByPageUrl(pageInfo.PublishmentSystemId, referrer, sinceDate); } else { accessNum = DataProvider.TrackingDao.GetTotalAccessNum(pageInfo.PublishmentSystemId, sinceDate); accessNum = accessNum + publishmentSystemInfo.Additional.TrackerPageView; } if (isAverage) { var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, pageInfo.PublishmentSystemId); var timeSpan = new TimeSpan(DateTime.Now.Ticks - nodeInfo.AddDate.Ticks); if (!string.IsNullOrEmpty(since)) { timeSpan = new TimeSpan(DateTime.Now.Ticks - sinceDate.Ticks); } var trackerDays = (timeSpan.Days == 0) ? 1 : timeSpan.Days;//总统计天数 trackerDays = trackerDays + publishmentSystemInfo.Additional.TrackerDays; accessNum = Convert.ToInt32(Math.Round(Convert.ToDouble(accessNum / trackerDays))); } } else if (StringUtils.EqualsIgnoreCase(type, TypeUniqueVisitor)) { if (StringUtils.EqualsIgnoreCase(scope, ScopePage)) { accessNum = eTemplateType != ETemplateType.FileTemplate ? DataProvider.TrackingDao.GetTotalUniqueAccessNumByPageInfo(pageInfo.PublishmentSystemId, channelId, contentId, sinceDate) : DataProvider.TrackingDao.GetTotalUniqueAccessNumByPageUrl(pageInfo.PublishmentSystemId, referrer, sinceDate); } else { accessNum = DataProvider.TrackingDao.GetTotalUniqueAccessNum(pageInfo.PublishmentSystemId, sinceDate); accessNum = accessNum + publishmentSystemInfo.Additional.TrackerUniqueVisitor; } if (isAverage) { var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, pageInfo.PublishmentSystemId); var timeSpan = new TimeSpan(DateTime.Now.Ticks - nodeInfo.AddDate.Ticks); var trackerDays = (timeSpan.Days == 0) ? 1 : timeSpan.Days;//总统计天数 trackerDays = trackerDays + publishmentSystemInfo.Additional.TrackerDays; accessNum = Convert.ToInt32(Math.Round(Convert.ToDouble(accessNum / trackerDays))); } } else if (StringUtils.EqualsIgnoreCase(type, TypeCurrentVisitor)) { accessNum = DataProvider.TrackingDao.GetCurrentVisitorNum(pageInfo.PublishmentSystemId, publishmentSystemInfo.Additional.TrackerCurrentMinute); } accessNum = accessNum + addNum; if (accessNum == 0) { accessNum = 1; } if (eStyle != ETrackerStyle.None) { if (eStyle == ETrackerStyle.Number) { html = accessNum.ToString(); } else { var numString = accessNum.ToString(); var htmlBuilder = new StringBuilder(); string imgFolder = $"{SiteFilesAssets.GetUrl(pageInfo.ApiUrl, SiteFilesAssets.Tracker.DirectoryName)}/{ETrackerStyleUtils.GetValue(eStyle)}"; foreach (var t in numString) { string imgHtml = $"<img src='{imgFolder}/{t}.gif' align=absmiddle border=0>"; htmlBuilder.Append(imgHtml); } html = htmlBuilder.ToString(); } } return(html); }
public void ImportTemplates(bool overwrite, string administratorName) { if (!FileUtils.IsFileExists(_filePath)) { return; } var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(_filePath)); var fso = new FileSystemObject(_publishmentSystemId); foreach (AtomEntry entry in feed.Entries) { var templateName = AtomUtility.GetDcElementContent(entry.AdditionalElements, "TemplateName"); if (!string.IsNullOrEmpty(templateName)) { var templateInfo = new TemplateInfo { PublishmentSystemId = _publishmentSystemId, TemplateName = templateName, TemplateType = ETemplateTypeUtils.GetEnumType(AtomUtility.GetDcElementContent(entry.AdditionalElements, "TemplateType")), RelatedFileName = AtomUtility.GetDcElementContent(entry.AdditionalElements, "RelatedFileName"), CreatedFileFullName = AtomUtility.GetDcElementContent(entry.AdditionalElements, "CreatedFileFullName"), CreatedFileExtName = AtomUtility.GetDcElementContent(entry.AdditionalElements, "CreatedFileExtName"), Charset = ECharsetUtils.GetEnumType(AtomUtility.GetDcElementContent(entry.AdditionalElements, "Charset")), IsDefault = false }; var templateContent = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, "Content")); var srcTemplateInfo = TemplateManager.GetTemplateInfoByTemplateName(_publishmentSystemId, templateInfo.TemplateType, templateInfo.TemplateName); int templateId; if (srcTemplateInfo != null) { if (overwrite) { srcTemplateInfo.RelatedFileName = templateInfo.RelatedFileName; srcTemplateInfo.TemplateType = templateInfo.TemplateType; srcTemplateInfo.CreatedFileFullName = templateInfo.CreatedFileFullName; srcTemplateInfo.CreatedFileExtName = templateInfo.CreatedFileExtName; srcTemplateInfo.Charset = templateInfo.Charset; DataProvider.TemplateDao.Update(fso.PublishmentSystemInfo, srcTemplateInfo, templateContent, administratorName); templateId = srcTemplateInfo.TemplateId; } else { templateInfo.TemplateName = DataProvider.TemplateDao.GetImportTemplateName(_publishmentSystemId, templateInfo.TemplateName); templateId = DataProvider.TemplateDao.Insert(templateInfo, templateContent, administratorName); } } else { templateId = DataProvider.TemplateDao.Insert(templateInfo, templateContent, administratorName); } if (templateInfo.TemplateType == ETemplateType.FileTemplate) { fso.CreateFile(templateId); } } } }
public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } PageUtils.CheckRequestParameter("PublishmentSystemID"); TemplateInfo templateInfo = null; if (Body.GetQueryInt("TemplateID") > 0) { var templateId = Body.GetQueryInt("TemplateID"); _isCopy = Body.GetQueryBool("IsCopy"); templateInfo = TemplateManager.GetTemplateInfo(PublishmentSystemId, templateId); if (templateInfo != null) { _theTemplateType = templateInfo.TemplateType; } } else { _theTemplateType = ETemplateTypeUtils.GetEnumType(Request.QueryString["TemplateType"]); } TemplateTypeString = ETemplateTypeUtils.GetText(_theTemplateType); if (_theTemplateType == ETemplateType.IndexPageTemplate || _theTemplateType == ETemplateType.FileTemplate) { CreatedFileFullNameRow.Visible = true; } else { CreatedFileFullNameRow.Visible = false; } if (!IsPostBack) { var pageTitle = Body.GetQueryInt("TemplateID") > 0 ? "编辑模板" : "添加模板"; BreadCrumb(AppManager.Cms.LeftMenu.IdTemplate, pageTitle, AppManager.Cms.Permission.WebSite.Template); ltlPageTitle.Text = pageTitle; var isCodeMirror = PublishmentSystemInfo.Additional.ConfigTemplateIsCodeMirror; btnEditorType.Text = isCodeMirror ? "采用纯文本编辑模式" : "采用代码编辑模式"; phCodeMirror.Visible = isCodeMirror; EFileSystemTypeUtils.AddWebPageListItems(CreatedFileExtNameDropDownList); ECharsetUtils.AddListItems(Charset); if (Body.GetQueryInt("TemplateID") > 0) { if (templateInfo != null) { Content.Text = StlCacheManager.FileContent.GetTemplateContent(PublishmentSystemInfo, templateInfo); if (_isCopy) { TemplateName.Text = templateInfo.TemplateName + "_复件"; RelatedFileName.Text = PathUtils.RemoveExtension(templateInfo.RelatedFileName) + "_复件"; CreatedFileFullName.Text = PathUtils.RemoveExtension(templateInfo.CreatedFileFullName) + "_复件"; } else { TemplateName.Text = templateInfo.TemplateName; RelatedFileName.Text = PathUtils.RemoveExtension(templateInfo.RelatedFileName); CreatedFileFullName.Text = PathUtils.RemoveExtension(templateInfo.CreatedFileFullName); LtlCommands.Text += $@"<a href=""javascript:;"" class=""btn btn-info"" onclick=""{ModalProgressBar.GetOpenWindowStringWithCreateByTemplate(PublishmentSystemId, templateInfo.TemplateId)}"">生成页面</a><a href=""javascript:;"" class=""btn btn-info"" onclick=""{ModalTemplateRestore.GetOpenLayerString(PublishmentSystemId, templateInfo.TemplateId, string.Empty)}"">还原历史版本</a>"; if (Body.GetQueryInt("TemplateLogID") > 0) { var templateLogId = Body.GetQueryInt("TemplateLogID"); if (templateLogId > 0) { Content.Text = DataProvider.TemplateLogDao.GetTemplateContent(templateLogId); SuccessMessage("已导入历史版本的模板内容,点击确定保存模板"); } } } ControlUtils.SelectListItemsIgnoreCase(Charset, ECharsetUtils.GetValue(templateInfo.Charset)); ControlUtils.SelectListItems(CreatedFileExtNameDropDownList, GetTemplateFileExtension(templateInfo)); TemplateType.Value = ETemplateTypeUtils.GetValue(templateInfo.TemplateType); } } else { RelatedFileName.Text = "T_"; if (_theTemplateType == ETemplateType.ChannelTemplate) { CreatedFileFullName.Text = "index"; } else { CreatedFileFullName.Text = "@/"; } ControlUtils.SelectListItemsIgnoreCase(Charset, PublishmentSystemInfo.Additional.Charset); ControlUtils.SelectListItems(CreatedFileExtNameDropDownList, EFileSystemTypeUtils.GetValue(EFileSystemType.Html)); TemplateType.Value = Body.GetQueryString("TemplateType"); } } }
public TemplateInfo GetTemplateByTemplateId(int publishmentSystemId, ETemplateType type, string tId) { TemplateInfo info = null; var parms = new IDataParameter[] { GetParameter(ParmPublishmentSystemId, EDataType.Integer, publishmentSystemId), GetParameter(ParmTemplateType, EDataType.VarChar, 50, ETemplateTypeUtils.GetValue(type)), GetParameter(ParmTemplateId, EDataType.Integer, tId) }; using (var rdr = ExecuteReader(SqlSelectTemplateByTemplateid, parms)) { if (rdr.Read()) { var i = 0; info = new TemplateInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), ETemplateTypeUtils.GetEnumType(GetString(rdr, i++)), GetString(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), ECharsetUtils.GetEnumType(GetString(rdr, i++)), GetBool(rdr, i)); } rdr.Close(); } return(info); }
public Dictionary <int, TemplateInfo> GetTemplateInfoDictionaryByPublishmentSystemId(int publishmentSystemId) { var dictionary = new Dictionary <int, TemplateInfo>(); var parms = new IDataParameter[] { GetParameter(ParmPublishmentSystemId, EDataType.Integer, publishmentSystemId) }; using (var rdr = ExecuteReader(SqlSelectAllTemplateByPublishmentSystemId, parms)) { while (rdr.Read()) { var i = 0; var info = new TemplateInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), ETemplateTypeUtils.GetEnumType(GetString(rdr, i++)), GetString(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), ECharsetUtils.GetEnumType(GetString(rdr, i++)), GetBool(rdr, i)); dictionary.Add(info.TemplateId, info); } rdr.Close(); } return(dictionary); }
public ArrayList GetTemplateInfoArrayListByPublishmentSystemId(int publishmentSystemId) { var arraylist = new ArrayList(); var parms = new IDataParameter[] { GetParameter(ParmPublishmentSystemId, EDataType.Integer, publishmentSystemId) }; using (var rdr = ExecuteReader(SqlSelectAllTemplateByPublishmentSystemId, parms)) { while (rdr.Read()) { var i = 0; var info = new TemplateInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), ETemplateTypeUtils.GetEnumType(GetString(rdr, i++)), GetString(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), ECharsetUtils.GetEnumType(GetString(rdr, i++)), GetBool(rdr, i)); arraylist.Add(info); } rdr.Close(); } return(arraylist); }
public ArrayList GetTemplateInfoArrayListOfFile(int publishmentSystemId) { var arraylist = new ArrayList(); string sqlString = $"SELECT TemplateID, PublishmentSystemID, TemplateName, TemplateType, RelatedFileName, CreatedFileFullName, CreatedFileExtName, Charset, IsDefault FROM siteserver_Template WHERE PublishmentSystemID = {publishmentSystemId} AND TemplateType = '{ETemplateTypeUtils.GetValue(ETemplateType.FileTemplate)}' ORDER BY RelatedFileName"; using (var rdr = ExecuteReader(sqlString)) { while (rdr.Read()) { var i = 0; var info = new TemplateInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), ETemplateTypeUtils.GetEnumType(GetString(rdr, i++)), GetString(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), ECharsetUtils.GetEnumType(GetString(rdr, i++)), GetBool(rdr, i)); arraylist.Add(info); } rdr.Close(); } return(arraylist); }