public void Page_Load(object sender, EventArgs e) { if (IsForbidden) { return; } if (Page.IsPostBack) { return; } VerifyAdministratorPermissions(ConfigManager.SettingsPermissions.Site); InfoMessage($@"本页面只显示部分免费模板,更多站点模板请访问官网:<a href=""{OnlineTemplateManager.UrlHome}"" target=""_blank"">{OnlineTemplateManager.UrlHome}</a>"); List <Dictionary <string, string> > list; if (OnlineTemplateManager.TryGetOnlineTemplates(out list)) { RptContents.DataSource = list; RptContents.ItemDataBound += RptContents_ItemDataBound; RptContents.DataBind(); } else { FailMessage($"在线模板获取失败:页面地址{OnlineTemplateManager.UrlHome}无法访问!"); } }
public NameValueCollection CreateSiteByOnlineTemplateName(int siteId, bool isImportContents, bool isImportTableStyles, string onlineTemplateName, string onlineTemplateUrl, string userKeyPrefix, string administratorName) { var cacheTotalCountKey = userKeyPrefix + CacheTotalCount; var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount; var cacheMessageKey = userKeyPrefix + CacheMessage; CacheUtils.Insert(cacheTotalCountKey, "4"); //存储需要的页面总数 CacheUtils.Insert(cacheCurrentCountKey, "0"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息 //返回“运行结果”、“错误信息”及“执行JS脚本”的字符串数组 NameValueCollection retval; try { CacheUtils.Insert(cacheCurrentCountKey, "1"); CacheUtils.Insert(cacheMessageKey, "开始下载模板压缩包,可能需要几分钟,请耐心等待..."); var filePath = PathUtility.GetSiteTemplatesPath($"T_{onlineTemplateName}.zip"); FileUtils.DeleteFileIfExists(filePath); //var downloadUrl = OnlineTemplateManager.GetDownloadUrl(onlineTemplateName); var downloadUrl = OnlineTemplateManager.GetDownloadUrlByUrl(onlineTemplateUrl); WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath); CacheUtils.Insert(cacheCurrentCountKey, "2"); CacheUtils.Insert(cacheMessageKey, "模板压缩包下载成功,开始解压缩,可能需要几分钟,请耐心等待..."); var siteTemplateDir = $"T_{onlineTemplateName}"; var directoryPath = PathUtility.GetSiteTemplatesPath(siteTemplateDir); DirectoryUtils.DeleteDirectoryIfExists(directoryPath); ZipUtils.ExtractZip(filePath, directoryPath); CacheUtils.Insert(cacheCurrentCountKey, "3"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "模板压缩包解压成功,正在导入数据..."); //存储消息 SiteTemplateManager.Instance.ImportSiteTemplateToEmptySite(siteId, siteTemplateDir, isImportContents, isImportTableStyles, administratorName); CreateManager.CreateByAll(siteId); CacheUtils.Insert(cacheCurrentCountKey, "4"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "创建成功!"); //存储消息 var siteInfo = SiteManager.GetSiteInfo(siteId); retval = AjaxManager.GetWaitingTaskNameValueCollection($"站点 <strong>{siteInfo.SiteName}<strong> 创建成功!", string.Empty, $"top.location.href='{PageUtils.GetMainUrl(siteId)}';"); } catch (Exception ex) { retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty); LogUtils.AddErrorLog(ex); } CacheUtils.Remove(cacheTotalCountKey); //取消存储需要的页面总数 CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数 CacheUtils.Remove(cacheMessageKey); //取消存储消息 CacheUtils.ClearAll(); return(retval); }
private void RptContents_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType != ListItemType.AlternatingItem && e.Item.ItemType != ListItemType.Item) { return; } var dict = (Dictionary <string, string>)e.Item.DataItem; var title = dict["title"]; var description = dict["description"]; var author = dict["author"]; var source = dict["source"]; var lastEditDate = dict["lastEditDate"]; var ltlTitle = (Literal)e.Item.FindControl("ltlTitle"); var ltlDescription = (Literal)e.Item.FindControl("ltlDescription"); var ltlAuthor = (Literal)e.Item.FindControl("ltlAuthor"); var ltlLastEditDate = (Literal)e.Item.FindControl("ltlLastEditDate"); var ltlPreviewUrl = (Literal)e.Item.FindControl("ltlPreviewUrl"); var ltlCreateUrl = (Literal)e.Item.FindControl("ltlCreateUrl"); var templateUrl = OnlineTemplateManager.GetTemplateUrl(title); ltlTitle.Text = $@"<a href=""{templateUrl}"" target=""_blank"">{title}</a>"; ltlDescription.Text = description; ltlAuthor.Text = author; if (!string.IsNullOrEmpty(source) && PageUtils.IsProtocolUrl(source)) { ltlAuthor.Text = $@"<a href=""{source}"" target=""_blank"">{ltlAuthor.Text}</a>"; } ltlLastEditDate.Text = lastEditDate; ltlPreviewUrl.Text = $@"<a href=""{templateUrl}"" target=""_blank"">模板详情</a>"; var urlAdd = PageSiteAdd.GetRedirectUrl(string.Empty, title); ltlCreateUrl.Text = $@"<a href=""{urlAdd}"">创建站点</a>"; //if (_directoryNameLowerList.Contains($"T_{title}".ToLower().Trim())) //{ // ltlDownloadUrl.Text = "已下载"; //} //else //{ // var downloadUrl = OnlineTemplateManager.GetDownloadUrl(title); // ltlCreateUrl.Text = // $@"<a href=""javascript:;"" onclick=""{Cms.ModalProgressBar.GetOpenWindowStringWithSiteTemplateDownload($"{downloadUrl}")}"">下载并导入</a>"; //} }
private void RptOnlineTemplates_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType != ListItemType.AlternatingItem && e.Item.ItemType != ListItemType.Item) { return; } var dict = (Dictionary <string, string>)e.Item.DataItem; var title = dict["title"]; var description = dict["description"]; var author = dict["author"]; var source = dict["source"]; var lastEditDate = dict["lastEditDate"]; var ltlChoose = (Literal)e.Item.FindControl("ltlChoose"); var ltlTitle = (Literal)e.Item.FindControl("ltlTitle"); var ltlDescription = (Literal)e.Item.FindControl("ltlDescription"); var ltlAuthor = (Literal)e.Item.FindControl("ltlAuthor"); var ltlLastEditDate = (Literal)e.Item.FindControl("ltlLastEditDate"); var ltlPreviewUrl = (Literal)e.Item.FindControl("ltlPreviewUrl"); ltlChoose.Text = $@"<input type=""radio"" name=""choose"" id=""choose_{title}"" onClick=""document.getElementById('{HihOnlineTemplateName.ClientID}').value=this.value;"" {(HihOnlineTemplateName.Value == title ? "checked" : string.Empty)} value=""{title}"" /><label for=""choose_{title}"" class=""m-l-10"">选中</label>"; var templateUrl = OnlineTemplateManager.GetTemplateUrl(title); ltlTitle.Text = $@"<a href=""{templateUrl}"" target=""_blank"">{title}</a>"; ltlDescription.Text = description; ltlAuthor.Text = author; if (!string.IsNullOrEmpty(source) && PageUtils.IsProtocolUrl(source)) { ltlAuthor.Text = $@"<a href=""{source}"" target=""_blank"">{ltlAuthor.Text}</a>"; } ltlLastEditDate.Text = lastEditDate; ltlPreviewUrl.Text = $@"<a href=""{templateUrl}"" target=""_blank"">模板详情</a>"; }
public void BtnNext_Click(object sender, EventArgs e) { if (PhSource.Visible) { HideAll(); if (IsSiteTemplate) { var siteTemplates = SiteTemplateManager.Instance.GetSiteTemplateSortedList(); RptSiteTemplates.DataSource = siteTemplates.Values; RptSiteTemplates.ItemDataBound += RptSiteTemplates_ItemDataBound; RptSiteTemplates.DataBind(); ShowSiteTemplates(); } else if (IsOnlineTemplate) { List <Dictionary <string, string> > list; if (OnlineTemplateManager.TryGetOnlineTemplates(out list)) { RptOnlineTemplates.DataSource = list; RptOnlineTemplates.ItemDataBound += RptOnlineTemplates_ItemDataBound; RptOnlineTemplates.DataBind(); ShowOnlineTemplates(); } else { FailMessage($"在线模板获取失败:页面地址{OnlineTemplateManager.UrlHome}无法访问!"); ShowSource(); } } else { LtlSource.Text = "创建空站点(不使用站点模板)"; ShowSubmit(); } } else if (PhSiteTemplates.Visible) { HideAll(); var siteTemplateDir = HihSiteTemplateDir.Value; if (string.IsNullOrEmpty(siteTemplateDir)) { FailMessage("请选择需要使用的站点模板"); ShowSiteTemplates(); return; } LtlSource.Text = $"使用本地站点模板创建站点({siteTemplateDir})"; ShowSubmit(); } else if (PhOnlineTemplates.Visible) { HideAll(); var onlineTemplateName = HihOnlineTemplateName.Value; if (string.IsNullOrEmpty(onlineTemplateName)) { FailMessage("请选择需要使用的在线站点模板"); ShowOnlineTemplates(); return; } LtlSource.Text = $@"使用在线站点模板创建站点(<a href=""{OnlineTemplateManager.GetTemplateUrl(onlineTemplateName)}"" target=""_blank"">{onlineTemplateName}</a>)"; ShowSubmit(); } }
public async Task <ActionResult <IntResult> > Submit([FromBody] SubmitRequest request) { if (!await _authManager.HasAppPermissionsAsync(Types.AppPermissions.SettingsSitesAdd)) { return(Unauthorized()); } if (!request.Root) { if (_pathManager.IsSystemDirectory(request.SiteDir)) { return(this.Error("文件夹名称不能为系统文件夹名称,请更改文件夹名称!")); } if (!DirectoryUtils.IsDirectoryNameCompliant(request.SiteDir)) { return(this.Error("文件夹名称不符合系统要求,请更改文件夹名称!")); } var sitePath = await _pathManager.GetSitePathAsync(request.ParentId); var directories = DirectoryUtils.GetDirectoryNames(sitePath); if (ListUtils.ContainsIgnoreCase(directories, request.SiteDir)) { return(this.Error("已存在相同的文件夹,请更改文件夹名称!")); } var list = await _siteRepository.GetSiteDirsAsync(request.ParentId); if (ListUtils.ContainsIgnoreCase(list, request.SiteDir)) { return(this.Error("已存在相同的站点文件夹,请更改文件夹名称!")); } } var channelInfo = new Channel(); channelInfo.ChannelName = channelInfo.IndexName = "首页"; channelInfo.ParentId = 0; channelInfo.ContentModelPluginId = string.Empty; var tableName = string.Empty; if (StringUtils.EqualsIgnoreCase(request.SiteType, Types.SiteTypes.Web) || StringUtils.EqualsIgnoreCase(request.SiteType, Types.SiteTypes.Wx)) { if (request.TableRule == TableRule.Choose) { tableName = request.TableChoose; } else if (request.TableRule == TableRule.HandWrite) { tableName = request.TableHandWrite; if (!await _settingsManager.Database.IsTableExistsAsync(tableName)) { await _contentRepository.CreateContentTableAsync(tableName, _contentRepository.GetTableColumns(tableName)); } else { await _settingsManager.Database.AlterTableAsync(tableName, _contentRepository.GetTableColumns(tableName)); } } } var adminId = _authManager.AdminId; var siteId = await _siteRepository.InsertSiteAsync(_pathManager, channelInfo, new Site { SiteName = request.SiteName, SiteType = request.SiteType, SiteDir = request.SiteDir, TableName = tableName, ParentId = request.ParentId, Root = request.Root }, adminId); if (string.IsNullOrEmpty(tableName)) { tableName = await _contentRepository.CreateNewContentTableAsync(); await _siteRepository.UpdateTableNameAsync(siteId, tableName); } if (await _authManager.IsSiteAdminAsync() && !await _authManager.IsSuperAdminAsync()) { var siteIdList = await _authManager.GetSiteIdsAsync() ?? new List <int>(); siteIdList.Add(siteId); var adminInfo = await _administratorRepository.GetByUserIdAsync(adminId); await _administratorRepository.UpdateSiteIdsAsync(adminInfo, siteIdList); } var caching = new CacheUtils(_cacheManager); var site = await _siteRepository.GetAsync(siteId); caching.SetProcess(request.Guid, "任务初始化..."); if (request.CreateType == "local") { var manager = new SiteTemplateManager(_pathManager, _databaseManager, caching); await manager.ImportSiteTemplateToEmptySiteAsync(site, request.CreateTemplateId, request.IsImportContents, request.IsImportTableStyles, adminId, request.Guid); caching.SetProcess(request.Guid, "生成站点页面..."); await _createManager.CreateByAllAsync(site.Id); caching.SetProcess(request.Guid, "清除系统缓存..."); _cacheManager.Clear(); } else if (request.CreateType == "cloud") { caching.SetProcess(request.Guid, "开始下载模板压缩包,可能需要几分钟,请耐心等待..."); var filePath = _pathManager.GetSiteTemplatesPath($"T_{request.CreateTemplateId}.zip"); FileUtils.DeleteFileIfExists(filePath); var downloadUrl = OnlineTemplateManager.GetDownloadUrl(request.CreateTemplateId); WebClientUtils.Download(downloadUrl, filePath); caching.SetProcess(request.Guid, "模板压缩包下载成功,开始解压缩,可能需要几分钟,请耐心等待..."); var siteTemplateDir = $"T_{request.CreateTemplateId}"; var directoryPath = _pathManager.GetSiteTemplatesPath(siteTemplateDir); DirectoryUtils.DeleteDirectoryIfExists(directoryPath); _pathManager.ExtractZip(filePath, directoryPath); caching.SetProcess(request.Guid, "模板压缩包解压成功,正在导入数据..."); var manager = new SiteTemplateManager(_pathManager, _databaseManager, caching); await manager.ImportSiteTemplateToEmptySiteAsync(site, siteTemplateDir, request.IsImportContents, request.IsImportTableStyles, adminId, request.Guid); caching.SetProcess(request.Guid, "生成站点页面..."); await _createManager.CreateByAllAsync(site.Id); caching.SetProcess(request.Guid, "清除系统缓存..."); _cacheManager.Clear(); } return(new IntResult { Value = siteId }); }