/// <summary> /// /// </summary> /// <param name="workerIndent"></param> public PluginPackAttribute(string workerIndent) { this.WorkIndent = workerIndent; bool isChanged = false; var dirPath = String.Concat( AppDomain.CurrentDomain.BaseDirectory, PluginConfig.PLUGIN_DIRECTORY, workerIndent, "/"); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath).Create(); } settings = new SettingFile(string.Concat(dirPath, "plugin.config")); if (!settings.Contains(PluginSettingKeys.State)) { settings.Set(PluginSettingKeys.State, "Normal"); isChanged = true; } if (!settings.Contains(PluginSettingKeys.OverrideUrlIndent)) { settings.Set(PluginSettingKeys.OverrideUrlIndent, ""); isChanged = true; } if (isChanged) { settings.Flush(); } }
/// <summary> /// 获取指定日期的数据 /// </summary> /// <param name="date"></param> /// <returns></returns> public static string GetData(DateTime date) { string key = String.Format("{0:yyyyMMdd}", date); if (trafficFile.Contains(key)) { return(trafficFile[key]); } else { trafficFile.Add(key, defaultJson); trafficFile.Flush(); } //try //{ // trafficFile["ips"] = String.Empty; //} //catch //{ // trafficFile.Append("ips", String.Empty); //} return(defaultJson); }
/// <summary> /// 获取处理JSON数据 /// </summary> /// <param name="action"></param> /// <returns></returns> private string GethandleJson(string action) { if (handleConfigFile.Contains(action)) { return(handleConfigFile[action]); } return(String.Empty); }
public string Get(string key) { if (_sf.Contains(key)) { return(_sf.Get(key)); } return(string.Empty); }
private static int GetInt(SettingFile s, string key) { if (!s.Contains(key)) { return(0); } int.TryParse(s[key], out var value); return(value); }
public IDictionary <string, string> GetNameDictionary() { SettingFile sf = new SettingFile(String.Format("{0}templates/{1}/tpl.conf", Cms.PyhicPath, this._tplDirName)); String json; if (!sf.Contains("TPL_NAMES") || String.IsNullOrEmpty((json = sf.Get("TPL_NAMES")))) { return(new Dictionary <string, string>()); } return(JsonConvert.DeserializeObject <Dictionary <String, String> >(json)); }
/// <summary> /// 获取模板 /// </summary> /// <returns></returns> public static IDictionary <string, string> GetTemplates() { IDictionary <string, string> dict = new Dictionary <string, string>(); var tplRootPath = $"{EnvUtil.GetBaseDirectory()}/templates/"; var dir = new DirectoryInfo(tplRootPath); var dirs = dir.GetDirectories(); var tpls = new string[dirs.Length]; if (dir.Exists) { var i = -1; foreach (var d in dirs) { if ((d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { tpls[++i] = d.Name; } } } SettingFile sf; string tplConfigFile, tplName; foreach (var key in tpls) { tplName = key; tplConfigFile = string.Format("{0}{1}/tpl.conf", tplRootPath, key); if (File.Exists(tplConfigFile)) { sf = new SettingFile(tplConfigFile); if (sf.Contains("name")) { tplName = sf["name"]; } //if (sf.Contains("thumbnail")) //{ // tplThumbnail = sf["thumbnail"]; //} } if (!string.IsNullOrEmpty(key)) { dict.Add(key, tplName); } } return(dict); }
/// <summary> /// 获取模板 /// </summary> /// <returns></returns> public static IDictionary <string, string> GetTemplates() { IDictionary <string, string> dict = new Dictionary <string, string>(); string[] tpls; string tplRootPath = String.Format("{0}templates/", AppDomain.CurrentDomain.BaseDirectory); DirectoryInfo dir = new DirectoryInfo(tplRootPath); DirectoryInfo[] dirs = dir.GetDirectories(); tpls = new string[dirs.Length]; if (dir.Exists) { int i = -1; foreach (DirectoryInfo d in dirs) { if ((d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { tpls[++i] = d.Name; } } } SettingFile sf; string tplConfigFile, tplName; foreach (string key in tpls) { tplName = key; tplConfigFile = String.Format("{0}{1}/tpl.conf", tplRootPath, key); if (global::System.IO.File.Exists(tplConfigFile)) { sf = new SettingFile(tplConfigFile); if (sf.Contains("name")) { tplName = sf["name"]; } //if (sf.Contains("thumbnail")) //{ // tplThumbnail = sf["thumbnail"]; //} } if (!String.IsNullOrEmpty(key)) { dict.Add(key, tplName); } } return(dict); }
public void SchoolIndex(string area) { if (file.Contains(area)) { string html = PageUtility.Require("/default/school", new { name = file[area], area = area }); base.Render(html); } else { base.Category(area); } }
internal static void LoadRelatedIndent() { string relatedConf = String.Format("{0}{1}related_indent.conf", Cms.PyhicPath, CmsVariables.SITE_CONF_PATH); bool isExists = File.Exists(relatedConf); SettingFile sf = new SettingFile(relatedConf); var isModify = false; var isLoaded = false; IDictionary <int, RelateIndent> relatedIndents = ServiceCall.Instance.ContentService.GetRelatedIndents(); IDictionary <int, RelateIndent> newIndents = new Dictionary <int, RelateIndent>(relatedIndents.Count); String key; String value; foreach (var relatedIndent in relatedIndents) { key = relatedIndent.Key.ToString(); if (isExists && sf.Contains(key)) { value = sf.Get(key); isLoaded = true; } else { value = relatedIndent.Value.ToString(); sf.Set(key, value); isModify = true; } newIndents.Add(relatedIndent.Key, new RelateIndent(value)); } if (isModify) { sf.Flush(); } if (isLoaded) { ServiceCall.Instance.ContentService.SetRelatedIndents(newIndents); } }
//[AcceptVerbs("POST")] public string Verify(string domain, string key, string token) { //activatorFile.Append("YmIyNDAwMGI3YmEyZGMwZTgxZWI2OGQxYzk3MWU4NWI=", "{domain:'temp.j6.cc',start:'*',end='*'}"); try { if (activatorFile.Contains(key)) { JsonAnalyzer ja = new JsonAnalyzer(activatorFile[key]); string endDate = ja.GetValue("end"); //如果结束时间为不限 if (endDate == "*") { return(GethandleJson("ok")); } //判断结束时间是否已过,未过则返回"ok"; DateTime _endDate; DateTime.TryParse(endDate, out _endDate); if (_endDate > DateTime.Now) { return(GethandleJson("ok")); } } } catch { //如果控制端出现任何异常,则默认全部通过 return(GethandleJson("ok")); } // // 不存在Key或者已过有效期 // 返回值 // go:返回数据但不调用Response.End() // end:返回数据调用Response.End() // 其他数据则默认通过且存入缓存 return(GethandleJson("end")); }
/// <summary> /// 加载配置文件 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>返回加载消息,如成功返回空</returns> internal static string Load(string filePath) { cmsConfigFile = filePath; //从配置文件中加载 SettingFile sf = new SettingFile(cmsConfigFile); Settings.loaded = true; bool settingChanged = false; //try // { Settings.License_NAME = sf.Contains("license_name") ? sf["license_name"] : "评估用户"; Settings.License_KEY = sf.Contains("license_key") ? sf["license_key"] : String.Empty; Settings.SYS_AUTOWWW = sf.Contains("sys_autowww") ? sf["sys_autowww"] == "true" : false; //自动WWW #region 读取模板选项 Settings.TPL_UseFullPath = sf.Contains("tpl_usefullpath") ? sf["tpl_usefullpath"] == "true" : true; Settings.TPL_UseCompress = sf.Contains("tpl_usecompress") ? sf["tpl_usecompress"] == "true" : false; #endregion Settings.DB_TYPE = sf["db_type"]; Settings.DB_CONN = sf["db_conn"]; Settings.DB_PREFIX = sf["db_prefix"]; Settings.MM_AVATAR_PATH = sf["mm_avatar_path"]; /**************** 优化项 ******************/ Settings.Opti_Debug = WebConfig.IsDebug(); //缓存项 if (sf.Contains("opti_IndexCacheSeconds")) { int.TryParse(sf["opti_IndexCacheSeconds"], out Settings.Opti_IndexCacheSeconds); } if (sf.Contains("opti_ClientCacheSeconds")) { int.TryParse(sf["opti_ClientCacheSeconds"], out Settings.Opti_ClientCacheSeconds); } if (sf.Contains("Opti_GC_Collect_Interval")) { int.TryParse(sf["Opti_GC_Collect_Interval"], out Settings.Opti_GC_Collect_Interval); } /**************** 静态服务器 ******************/ if (sf.Contains("server_static")) { Settings.SERVER_STATIC = sf["server_static"]; if (Settings.SERVER_STATIC.Length == 0) { Settings.SERVER_STATIC = Server._defaultStaticServer; } } else { sf.Append("server_static", Server._defaultStaticServer); Settings.SERVER_STATIC = Server._defaultStaticServer; settingChanged = true; } if (sf.Contains("server_static_enabled")) { Settings.SERVER_STATIC_ENABLED = sf["server_static_enabled"] == "true"; } else { sf.Append("server_static_enabled", "false"); settingChanged = true; } if (sf.Contains("sys_admin_tag")) { Settings.SYS_ADMIN_TAG = sf["sys_admin_tag"]; } else { sf.Append("sys_admin_tag", Settings.SYS_ADMIN_TAG); settingChanged = true; } if (settingChanged) { sf.Flush(); } return(string.Empty); /* * } * catch (Exception ex) * { * const string strtpl = "配置文件不正确,请检查!位置:{0}。{1}"; * string _file = filePath.Replace("/", "\\").Replace("\\\\", "\\"); * * return string.Format(strtpl, _file, * ex.GetType() == typeof(ArgumentOutOfRangeException) ? "此错误可能因为缺少系统所需的配置而引发。" : * string.Empty * ); * }*/ }
/// <summary> /// 更新资料 /// </summary> /// <param name="prefix"></param> public static void Update(string prefix) { SettingFile sf = new SettingFile(cmsConfigFile); switch (prefix) { case "sys": sf["license_name"] = Settings.License_NAME; sf["license_key"] = Settings.License_KEY; sf["server_static_enabled"] = Settings.SERVER_STATIC_ENABLED?"true":"false"; sf["server_static"] = Settings.SERVER_STATIC; sf["sys_admin_tag"] = Settings.SYS_ADMIN_TAG; //301跳转 if (!sf.Contains("sys_autowww")) { sf.Append("sys_autowww", Settings.SYS_AUTOWWW ? "true" : "false"); } else { sf["sys_autowww"] = Settings.SYS_AUTOWWW ? "true" : "false"; } //虚拟路径 //if (!sf.Contains("sys_virthpath")) //{ // sf.Append("sys_virthpath", Settings.SYS_VIRTHPATH); //} //else //{ // sf["sys_virthpath"] = Settings.SYS_VIRTHPATH; //} break; case "db": sf["db_prefix"] = Settings.DB_PREFIX; break; case "tpl": //压缩代码 if (!sf.Contains("tpl_usecompress")) { sf.Append("tpl_usecompress", Settings.TPL_UseCompress ? "true" : "false"); } else { sf["tpl_usecompress"] = Settings.TPL_UseCompress ? "true" : "false"; } //使用完整路径 if (!sf.Contains("tpl_usefullpath")) { sf.Append("tpl_usefullpath", Settings.TPL_UseFullPath ? "true" : "false"); } else { sf["tpl_usefullpath"] = Settings.TPL_UseFullPath ? "true" : "false"; } Cms.Template.Register(); break; //优化 case "opti": WebConfig.SetDebug(Settings.Opti_Debug); //缓存项 if (!sf.Contains("opti_IndexCacheSeconds")) { sf.Append("opti_IndexCacheSeconds", Settings.Opti_IndexCacheSeconds.ToString()); } else { sf["opti_IndexCacheSeconds"] = Settings.Opti_IndexCacheSeconds.ToString(); } if (!sf.Contains("Opti_GC_Collect_Interval")) { sf.Append("Opti_GC_Collect_Interval", Settings.Opti_GC_Collect_Interval.ToString()); } else { sf["Opti_GC_Collect_Interval"] = Settings.Opti_GC_Collect_Interval.ToString(); } if (!sf.Contains("opti_ClientCacheSeconds")) { sf.Append("opti_ClientCacheSeconds", Settings.Opti_ClientCacheSeconds.ToString()); } else { sf["opti_ClientCacheSeconds"] = Settings.Opti_ClientCacheSeconds.ToString(); } break; } // //Version:兼容更新站点 // SiteDto site = Cms.Context.CurrentSite; if (site.SiteId > 0) { if (sf.Contains("idx_title")) { site.SeoTitle = sf["idx_title"]; sf.Remove("idx_title"); } if (sf.Contains("idx_keywords")) { site.SeoKeywords = sf["idx_keywords"]; sf.Remove("idx_keywords"); } if (sf.Contains("idx_description")) { site.SeoDescription = sf["idx_description"]; sf.Remove("idx_description"); } if (sf.Contains("sys_alias")) { sf.Remove("sys_alias"); } } if (sf.Contains("sys_name")) { if (sf.Contains("license_name")) { sf["license_name"] = sf["sys_name"]; sf["license_key"] = sf["sys_key"]; } else { sf.Append("license_name", sf["sys_name"]); sf.Append("license_key", sf["sys_key"]); } sf.Remove("sys_name"); sf.Remove("sys_key"); } sf.Flush(); }
public TemplateSetting(string tpl) { this.tplName = tpl; sf = new SettingFile(String.Format("{0}templates/{1}/tpl.conf", AppDomain.CurrentDomain.BaseDirectory, tpl)); #region 获取设置 if (sf.Contains("CFG_ShowError")) { this.cfg_showError = sf["CFG_ShowError"] == "true"; } if (sf.Contains("CFG_SitemapSplit")) { this.cfg_sitemapSplit = sf["CFG_SitemapSplit"]; } if (sf.Contains("CFG_ArchiveTagsFormat")) { this.cfg_ArchiveTagsFormat = sf["CFG_ArchiveTagsFormat"]; } if (sf.Contains("CFG_NavigatorLinkFormat")) { this.cfg_navigatorLinkFormat = sf["CFG_NavigatorLinkFormat"]; } if (sf.Contains("CFG_NavigatorChildFormat")) { this.cfg_navigatorChildFormat = sf["CFG_NavigatorChildFormat"]; } if (sf.Contains("CFG_FriendShowNum")) { int.TryParse(sf["CFG_FriendShowNum"], out this.cfg_friendShowNum); } if (sf.Contains("CFG_OutlineLength")) { int.TryParse(sf["CFG_OutlineLength"], out this.cfg_outlineLength); } if (sf.Contains("CFG_FriendLinkFormat")) { this.cfg_friendLinkFormat = sf["CFG_FriendLinkFormat"]; } if (sf.Contains("CFG_TrafficFormat")) { this.cfg_trafficFormat = sf["CFG_TrafficFormat"]; } if (sf.Contains("CFG_CommentEditorHtml")) { this.cfg_commentEditorHtml = sf["CFG_CommentEditorHtml"]; } if (sf.Contains("CFG_allowAmousComment")) { this.cfg_allowAmousComment = sf["CFG_allowAmousComment"] == "true"; } if (sf.Contains("CFG_ArchiveFormat")) { this.cfg_archiveFormat = sf["CFG_ArchiveFormat"]; } if (sf.Contains("CFG_PrevArchiveFormat")) { this.cfg_prevArchiveFormat = sf["CFG_PrevArchiveFormat"]; } if (sf.Contains("CFG_NextArchiveFormat")) { this.cfg_nextArchiveFormat = sf["CFG_NextArchiveFormat"]; } if (sf.Contains("CFG_ArchiveLinkFormat")) { this.cfg_archiveLinkFormat = sf["CFG_ArchiveLinkFormat"]; } if (sf.Contains("CFG_CategoryLinkFormat")) { this.cfg_categoryLinkFormat = sf["CFG_CategoryLinkFormat"]; } sf = null; #endregion }
public void Save() { SettingFile sf = new SettingFile(String.Format("{0}templates/{1}/tpl.conf", Cms.PyhicPath, this.tplName)); /**************** 模板设置 ****************/ if (sf.Contains("CFG_ShowErrror")) { sf["CFG_ShowErrror"] = this.CFG_ShowError?"true":"false"; } else { sf.Append("CFG_ShowErrror", this.CFG_ShowError?"true":"false"); } if (sf.Contains("CFG_SitemapSplit")) { sf["CFG_SitemapSplit"] = this.cfg_sitemapSplit; } else { sf.Append("CFG_SitemapSplit", this.cfg_sitemapSplit); } if (sf.Contains("CFG_ArchiveTagsFormat")) { sf["CFG_ArchiveTagsFormat"] = this.cfg_ArchiveTagsFormat; } else { sf.Append("CFG_ArchiveTagsFormat", this.cfg_ArchiveTagsFormat); } if (sf.Contains("CFG_NavigatorLinkFormat")) { sf["CFG_NavigatorLinkFormat"] = this.cfg_navigatorLinkFormat; } else { sf.Append("CFG_NavigatorLinkFormat", this.cfg_navigatorLinkFormat); } if (sf.Contains("CFG_NavigatorChildFormat")) { sf["CFG_NavigatorChildFormat"] = this.cfg_navigatorChildFormat; } else { sf.Append("CFG_NavigatorChildFormat", this.cfg_navigatorChildFormat); } if (sf.Contains("CFG_FriendShowNum")) { sf["CFG_FriendShowNum"] = this.cfg_friendShowNum.ToString(); } else { sf.Append("CFG_FriendShowNum", this.cfg_friendShowNum.ToString()); } if (sf.Contains("CFG_FriendLinkFormat")) { sf["CFG_FriendLinkFormat"] = this.cfg_friendLinkFormat; } else { sf.Append("CFG_FriendLinkFormat", this.cfg_friendLinkFormat); } if (sf.Contains("CFG_TrafficFormat")) { sf["CFG_TrafficFormat"] = this.cfg_trafficFormat; } else { sf.Append("CFG_TrafficFormat", this.cfg_trafficFormat); } if (sf.Contains("CFG_CommentEditorHtml")) { sf["CFG_CommentEditorHtml"] = this.cfg_commentEditorHtml; } else { sf.Append("CFG_CommentEditorHtml", this.cfg_commentEditorHtml); } if (sf.Contains("CFG_allowAmousComment")) { sf["CFG_allowAmousComment"] = this.cfg_allowAmousComment ? "true" : "false"; } else { sf.Append("CFG_allowAmousComment", this.cfg_allowAmousComment ? "true" : "false"); } if (sf.Contains("CFG_OutlineLength")) { sf["CFG_OutlineLength"] = this.cfg_outlineLength.ToString(); } else { sf.Append("CFG_OutlineLength", this.cfg_outlineLength.ToString()); } if (sf.Contains("CFG_ArchiveFormat")) { sf["CFG_ArchiveFormat"] = this.cfg_archiveFormat; } else { sf.Append("CFG_ArchiveFormat", this.cfg_archiveFormat); } if (sf.Contains("CFG_ArchiveLinkFormat")) { sf["CFG_ArchiveLinkFormat"] = this.cfg_archiveLinkFormat; } else { sf.Append("CFG_ArchiveLinkFormat", this.cfg_archiveLinkFormat); } if (sf.Contains("CFG_PrevArchiveFormat")) { sf["CFG_PrevArchiveFormat"] = this.cfg_prevArchiveFormat; } else { sf.Append("CFG_PrevArchiveFormat", this.cfg_prevArchiveFormat); } if (sf.Contains("CFG_NextArchiveFormat")) { sf["CFG_NextArchiveFormat"] = this.cfg_nextArchiveFormat; } else { sf.Append("CFG_NextArchiveFormat", this.cfg_nextArchiveFormat); } if (sf.Contains("CFG_CategoryLinkFormat")) { sf["CFG_CategoryLinkFormat"] = this.cfg_categoryLinkFormat; } else { sf.Append("CFG_CategoryLinkFormat", this.cfg_categoryLinkFormat); } sf.Flush(); }
public TemplateSetting(String tplName, String confPath) { this._tplDirName = tplName; this.tplName = tplName; sf = new SettingFile(confPath); if (sf.Contains("TPL_NAME")) { this.tplName = sf.Get("TPL_NAME"); } #region 获取设置 if (sf.Contains("CFG_ShowError")) { this._cfgShowError = sf["CFG_ShowError"] == "true"; } if (sf.Contains("CFG_EnabledMobiPage")) { this._cfgEnabledMobiPage = sf["CFG_EnabledMobiPage"] == "true"; } if (sf.Contains("CFG_SitemapSplit")) { this._cfgSitemapSplit = sf["CFG_SitemapSplit"]; } if (sf.Contains("CFG_ArchiveTagsFormat")) { this._cfgArchiveTagsFormat = sf["CFG_ArchiveTagsFormat"]; } if (sf.Contains("CFG_NavigatorLinkFormat")) { this._cfgNavigatorLinkFormat = sf["CFG_NavigatorLinkFormat"]; } if (sf.Contains("CFG_NavigatorChildFormat")) { this._cfgNavigatorChildFormat = sf["CFG_NavigatorChildFormat"]; } if (sf.Contains("CFG_FriendShowNum")) { int.TryParse(sf["CFG_FriendShowNum"], out this._cfgFriendShowNum); } if (sf.Contains("CFG_OutlineLength")) { int.TryParse(sf["CFG_OutlineLength"], out this._cfgOutlineLength); } if (sf.Contains("CFG_FriendLinkFormat")) { this._cfgFriendLinkFormat = sf["CFG_FriendLinkFormat"]; } if (sf.Contains("CFG_TrafficFormat")) { this._cfgTrafficFormat = sf["CFG_TrafficFormat"]; } if (sf.Contains("CFG_CommentEditorHtml")) { this._cfgCommentEditorHtml = sf["CFG_CommentEditorHtml"]; } if (sf.Contains("CFG_allowAmousComment")) { this._cfgAllowAmousComment = sf["CFG_allowAmousComment"] == "true"; } if (sf.Contains("CFG_ArchiveFormat")) { this._cfgArchiveFormat = sf["CFG_ArchiveFormat"]; } if (sf.Contains("CFG_PrevArchiveFormat")) { this._cfgPrevArchiveFormat = sf["CFG_PrevArchiveFormat"]; } if (sf.Contains("CFG_NextArchiveFormat")) { this._cfgNextArchiveFormat = sf["CFG_NextArchiveFormat"]; } if (sf.Contains("CFG_ArchiveLinkFormat")) { this._cfgArchiveLinkFormat = sf["CFG_ArchiveLinkFormat"]; } if (sf.Contains("CFG_CategoryLinkFormat")) { this._cfgCategoryLinkFormat = sf["CFG_CategoryLinkFormat"]; } sf = null; #endregion }
/// <summary> /// 模板列表 /// </summary> public void Templates_GET() { if (UserState.Administrator.Current.Group != UserGroups.Master) return; string curTemplate = base.CurrentSite.Tpl; string tplRootPath=String.Format("{0}templates/",AppDomain.CurrentDomain.BaseDirectory); string[] tplList = new string[0]; DirectoryInfo dir = new DirectoryInfo(tplRootPath); if (dir.Exists) { DirectoryInfo[] dirs = dir.GetDirectories(); tplList = new string[dirs.Length]; int i = -1; foreach (DirectoryInfo d in dirs) { tplList[++i] = d.Name; } } SettingFile sf; string currentName="", currentThumbnail="", tplConfigFile, tplName, tplDescrpt, tplThumbnail; StringBuilder sb = new StringBuilder(); foreach (string tpl in tplList) { tplName = tpl; tplThumbnail = null; tplDescrpt = null; tplConfigFile = String.Format("{0}{1}/tpl.conf", tplRootPath, tpl); if (global::System.IO.File.Exists(tplConfigFile)) { sf = new SettingFile(tplConfigFile); if (sf.Contains("name")) { tplName = sf["name"]; } if (sf.Contains("thumbnail")) { tplThumbnail = sf["thumbnail"]; } if (sf.Contains("descript")) { tplDescrpt = sf["descript"]; } } if (String.Compare(tpl, curTemplate , false) != 0) { sb.Append("<li><p><a href=\"javascript:;\">"); if (tplThumbnail != null) { sb.Append("<img src=\"").Append(tplThumbnail).Append("\" alt=\"点击切换模板\" class=\"shot ").Append(tpl).Append("\"/>"); } else { sb.Append("<span title=\"点击切换模板\" class=\"shot ").Append(tpl).Append(" thumbnail\">无缩略图</span>"); } sb.Append("</a></p><p><a href=\"javascript:;\" class=\"t\">") .Append(tplName).Append("</a></p><p><a class=\"btn edit\" href=\"tpl:") .Append(tpl).Append("\">编辑</a> <a class=\"btn down\" href=\"tpl:") .Append(tpl).Append("\">下载</a></p>") .Append("<p class=\"hidden\">").Append(tplDescrpt).Append("</p>") .Append("</li>"); } else { currentName = String.IsNullOrEmpty(tplName) ? curTemplate : tplName; if (tplThumbnail != null) { currentThumbnail="<img src=\""+tplThumbnail+"\" alt=\"点击切换模板\" class=\"shot1 "+tpl+"\"/>"; } else { currentThumbnail="<span class=\"shot1 "+tpl+" thumbnail\">无缩略图</span>"; } } } base.RenderTemplate(ResourceMap.GetPageContent(ManagementPage.Template_Manager), new { list=sb.ToString(), current = curTemplate, currentName=currentName, currentThumbnail=currentThumbnail }); }
/// <summary> /// 加载配置文件 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>返回加载消息,如成功返回空</returns> private static void Load(string filePath) { cmsConfFile = filePath; //从配置文件中加载 SettingFile sf = new SettingFile(cmsConfFile); Settings.loaded = true; bool settingChanged = false; //try // { Settings.LICENSE_NAME = sf.Contains("license_name") ? sf["license_name"] : "评估用户"; Settings.LICENSE_KEY = sf.Contains("license_key") ? sf["license_key"] : String.Empty; Settings.SYS_WWW_RD = GetInt(sf, "sys_www_rd"); Settings.SYS_FORCE_HTTPS = CheckTrueValue(sf, "sys_force_https"); Settings.SYS_USE_UPLOAD_RAW_NAME = CheckTrueValue(sf, "sys_use_upload_raw_path"); #region 读取模板选项 Settings.TPL_FULL_URL_PATH = !sf.Contains("tpl_full_url_path") || sf["tpl_full_url_path"] == "true"; Settings.TPL_USE_COMPRESS = sf.Contains("tpl_use_compress") && sf["tpl_use_compress"] == "true"; Settings.TPL_USE_CACHE = !sf.Contains("tpl_use_cache") || sf["tpl_use_cache"] == "true"; #endregion Settings.DB_TYPE = sf["db_type"]; Settings.DB_CONN = sf["db_conn"]; Settings.DB_PREFIX = sf["db_prefix"]; Settings.MM_AVATAR_PATH = sf["mm_avatar_path"]; /**************** 优化项 ******************/ Settings.OPTI_DEBUG_MODE = WebConfig.IsDebug(); //缓存项 if (sf.Contains("perm_index_cache_second")) { Int32.TryParse(sf["perm_index_cache_second"], out Settings.PERM_INDEX_CACHE_SECOND); } if (sf.Contains("opti_client_cache_seconds")) { Int32.TryParse(sf["opti_client_cache_seconds"], out Settings.Opti_ClientCacheSeconds); } if (sf.Contains("opti_gc_collect_interval")) { Int32.TryParse(sf["opti_gc_collect_interval"], out Settings.opti_gc_collect_interval); } /**************** 静态服务器 ******************/ if (sf.Contains("server_static")) { Settings.SERVER_STATIC = sf["server_static"]; if (Settings.SERVER_STATIC.Length == 0) { Settings.SERVER_STATIC = Server.DefaultStaticServer; } } else { sf.Set("server_static", Server.DefaultStaticServer); Settings.SERVER_STATIC = Server.DefaultStaticServer; settingChanged = true; } if (sf.Contains("server_upgrade")) { Settings.SERVER_UPGRADE = sf["server_upgrade"]; if (Settings.SERVER_UPGRADE.Length == 0) { Settings.SERVER_UPGRADE = Server.DefaultUpgradeServer; } } else { sf.Set("server_upgrade", Server.DefaultUpgradeServer); Settings.SERVER_UPGRADE = Server.DefaultUpgradeServer; settingChanged = true; } if (sf.Contains("server_static_enabled")) { Settings.SERVER_STATIC_ENABLED = sf["server_static_enabled"] == "true"; } else { sf.Set("server_static_enabled", "false"); settingChanged = true; } if (sf.Contains("sys_encode_conf")) { Settings.SYS_ENCODE_CONF_FILE = sf["sys_encode_conf"] == "true"; } else { sf.Set("sys_encode_conf", Settings.SYS_ENCODE_CONF_FILE ? "true" : "false"); settingChanged = true; } if (sf.Contains("sql_profile_trace")) { Settings.SQL_PROFILE_TRACE = sf["sql_profile_trace"] == "true"; } else { sf.Set("sql_profile_trace", Settings.SQL_PROFILE_TRACE ? "true" : "false"); settingChanged = true; } if (sf.Contains("sys_admin_tag")) { Settings.SYS_ADMIN_TAG = sf["sys_admin_tag"]; } else { sf.Set("sys_admin_tag", Settings.SYS_ADMIN_TAG); settingChanged = true; } if (sf.Contains("sys_site_map_path")) { Settings.SYS_SITE_MAP_PATH = sf["sys_site_map_path"]; } else { sf.Set("sys_site_map_path", ""); settingChanged = true; } if (settingChanged) { sf.Flush(); } }
public TemplateSetting(string tpl) { this.tplName = tpl; sf = new SettingFile(String.Format("{0}templates/{1}/tpl.conf", AppDomain.CurrentDomain.BaseDirectory, tpl)); #region 获取设置 if(sf.Contains("CFG_ShowError")) { this.cfg_showError = sf["CFG_ShowError"]=="true"; } if (sf.Contains("CFG_SitemapSplit")) { this.cfg_sitemapSplit = sf["CFG_SitemapSplit"]; } if (sf.Contains("CFG_ArchiveTagsFormat")) { this.cfg_ArchiveTagsFormat = sf["CFG_ArchiveTagsFormat"]; } if (sf.Contains("CFG_NavigatorLinkFormat")) { this.cfg_navigatorLinkFormat = sf["CFG_NavigatorLinkFormat"]; } if (sf.Contains("CFG_NavigatorChildFormat")) { this.cfg_navigatorChildFormat= sf["CFG_NavigatorChildFormat"]; } if (sf.Contains("CFG_FriendShowNum")) { int.TryParse(sf["CFG_FriendShowNum"], out this.cfg_friendShowNum); } if (sf.Contains("CFG_OutlineLength")) { int.TryParse(sf["CFG_OutlineLength"], out this.cfg_outlineLength); } if (sf.Contains("CFG_FriendLinkFormat")) { this.cfg_friendLinkFormat= sf["CFG_FriendLinkFormat"]; } if (sf.Contains("CFG_TrafficFormat")) { this.cfg_trafficFormat = sf["CFG_TrafficFormat"]; } if (sf.Contains("CFG_CommentEditorHtml")) { this.cfg_commentEditorHtml = sf["CFG_CommentEditorHtml"]; } if (sf.Contains("CFG_allowAmousComment")) { this.cfg_allowAmousComment= sf["CFG_allowAmousComment"] == "true"; } if (sf.Contains("CFG_ArchiveFormat")) { this.cfg_archiveFormat = sf["CFG_ArchiveFormat"]; } if (sf.Contains("CFG_PrevArchiveFormat")) { this.cfg_prevArchiveFormat= sf["CFG_PrevArchiveFormat"]; } if (sf.Contains("CFG_NextArchiveFormat")) { this.cfg_nextArchiveFormat = sf["CFG_NextArchiveFormat"]; } if (sf.Contains("CFG_ArchiveLinkFormat")) { this.cfg_archiveLinkFormat= sf["CFG_ArchiveLinkFormat"]; } if (sf.Contains("CFG_CategoryLinkFormat")) { this.cfg_categoryLinkFormat = sf["CFG_CategoryLinkFormat"]; } sf = null; #endregion }
/// <summary> /// 更新资料 /// </summary> /// <param name="prefix"></param> public static void Update(string prefix) { SettingFile sf = new SettingFile(cmsConfigFile); switch (prefix) { case "sys": sf["license_name"] = Settings.License_NAME; sf["license_key"] = Settings.License_KEY; sf["server_static_enabled"]=Settings.SERVER_STATIC_ENABLED?"true":"false"; sf["server_static"] = Settings.SERVER_STATIC; sf["sys_admin_tag"] = Settings.SYS_ADMIN_TAG; //301跳转 if (!sf.Contains("sys_autowww")) { sf.Append("sys_autowww", Settings.SYS_AUTOWWW ? "true" : "false"); } else { sf["sys_autowww"] = Settings.SYS_AUTOWWW ? "true" : "false"; } //虚拟路径 //if (!sf.Contains("sys_virthpath")) //{ // sf.Append("sys_virthpath", Settings.SYS_VIRTHPATH); //} //else //{ // sf["sys_virthpath"] = Settings.SYS_VIRTHPATH; //} break; case "db": sf["db_prefix"] = Settings.DB_PREFIX; break; case "tpl": //压缩代码 if (!sf.Contains("tpl_usecompress")) { sf.Append("tpl_usecompress", Settings.TPL_UseCompress ? "true" : "false"); } else { sf["tpl_usecompress"] = Settings.TPL_UseCompress ? "true" : "false"; } //使用完整路径 if (!sf.Contains("tpl_usefullpath")) { sf.Append("tpl_usefullpath", Settings.TPL_UseFullPath ? "true" : "false"); } else { sf["tpl_usefullpath"] = Settings.TPL_UseFullPath ? "true" : "false"; } Cms.Template.Register(); break; //优化 case "opti": WebConfig.SetDebug(Settings.Opti_Debug); //缓存项 if (!sf.Contains("opti_IndexCacheSeconds")) { sf.Append("opti_IndexCacheSeconds", Settings.Opti_IndexCacheSeconds.ToString()); } else { sf["opti_IndexCacheSeconds"] = Settings.Opti_IndexCacheSeconds.ToString(); } if (!sf.Contains("Opti_GC_Collect_Interval")) { sf.Append("Opti_GC_Collect_Interval", Settings.Opti_GC_Collect_Interval.ToString()); } else { sf["Opti_GC_Collect_Interval"] = Settings.Opti_GC_Collect_Interval.ToString(); } if (!sf.Contains("opti_ClientCacheSeconds")) { sf.Append("opti_ClientCacheSeconds", Settings.Opti_ClientCacheSeconds.ToString()); } else { sf["opti_ClientCacheSeconds"] = Settings.Opti_ClientCacheSeconds.ToString(); } break; } // //Version:兼容更新站点 // SiteDto site = Cms.Context.CurrentSite; if (site.SiteId>0) { if (sf.Contains("idx_title")) { site.SeoTitle = sf["idx_title"]; sf.Remove("idx_title"); } if (sf.Contains("idx_keywords")) { site.SeoKeywords = sf["idx_keywords"]; sf.Remove("idx_keywords"); } if (sf.Contains("idx_description")) { site.SeoDescription = sf["idx_description"]; sf.Remove("idx_description"); } if (sf.Contains("sys_alias")) { sf.Remove("sys_alias"); } } if (sf.Contains("sys_name")) { if(sf.Contains("license_name")) { sf["license_name"] = sf["sys_name"]; sf["license_key"] = sf["sys_key"]; } else { sf.Append("license_name", sf["sys_name"]); sf.Append("license_key",sf["sys_key"]); } sf.Remove("sys_name"); sf.Remove("sys_key"); } sf.Flush(); }
/// <summary> /// 加载配置文件 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>返回加载消息,如成功返回空</returns> internal static string Load(string filePath) { cmsConfigFile = filePath; //从配置文件中加载 SettingFile sf = new SettingFile(cmsConfigFile); Settings.loaded = true; bool settingChanged=false; //try // { Settings.License_NAME = sf.Contains("license_name") ? sf["license_name"] : "评估用户"; Settings.License_KEY = sf.Contains("license_key") ? sf["license_key"] : String.Empty; Settings.SYS_AUTOWWW = sf.Contains("sys_autowww") ? sf["sys_autowww"] == "true" : false; //自动WWW #region 读取模板选项 Settings.TPL_UseFullPath = sf.Contains("tpl_usefullpath") ? sf["tpl_usefullpath"] == "true" : true; Settings.TPL_UseCompress = sf.Contains("tpl_usecompress") ? sf["tpl_usecompress"] == "true" : false; #endregion Settings.DB_TYPE = sf["db_type"]; Settings.DB_CONN = sf["db_conn"]; Settings.DB_PREFIX = sf["db_prefix"]; Settings.MM_AVATAR_PATH = sf["mm_avatar_path"]; /**************** 优化项 ******************/ Settings.Opti_Debug = WebConfig.IsDebug(); //缓存项 if (sf.Contains("opti_IndexCacheSeconds")) { int.TryParse(sf["opti_IndexCacheSeconds"], out Settings.Opti_IndexCacheSeconds); } if (sf.Contains("opti_ClientCacheSeconds")) { int.TryParse(sf["opti_ClientCacheSeconds"], out Settings.Opti_ClientCacheSeconds); } if (sf.Contains("Opti_GC_Collect_Interval")) { int.TryParse(sf["Opti_GC_Collect_Interval"], out Settings.Opti_GC_Collect_Interval); } /**************** 静态服务器 ******************/ if(sf.Contains("server_static")) { Settings.SERVER_STATIC=sf["server_static"]; if(Settings.SERVER_STATIC.Length==0) { Settings.SERVER_STATIC=Server._defaultStaticServer; } } else { sf.Append("server_static",Server._defaultStaticServer); Settings.SERVER_STATIC=Server._defaultStaticServer; settingChanged=true; } if(sf.Contains("server_static_enabled")) { Settings.SERVER_STATIC_ENABLED=sf["server_static_enabled"]=="true"; } else { sf.Append("server_static_enabled","false"); settingChanged=true; } if(sf.Contains("sys_admin_tag")) { Settings.SYS_ADMIN_TAG=sf["sys_admin_tag"]; } else { sf.Append("sys_admin_tag",Settings.SYS_ADMIN_TAG); settingChanged=true; } if(settingChanged)sf.Flush(); return string.Empty; /* } catch (Exception ex) { const string strtpl = "配置文件不正确,请检查!位置:{0}。{1}"; string _file = filePath.Replace("/", "\\").Replace("\\\\", "\\"); return string.Format(strtpl, _file, ex.GetType() == typeof(ArgumentOutOfRangeException) ? "此错误可能因为缺少系统所需的配置而引发。" : string.Empty ); }*/ }
public PluginPackAttribute(string workerIndent) { this.WorkIndent = workerIndent; bool isChanged = false; var dirPath = String.Concat( AppDomain.CurrentDomain.BaseDirectory, PluginConfig.PLUGIN_DIRECTORY, workerIndent, "/"); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath).Create(); } settings = new SettingFile(string.Concat(dirPath, "plugin.config")); if (!settings.Contains("state")) { settings.Append("state", "Normal"); isChanged = true; } if (!settings.Contains("override.url.indent")) { settings.Append("override.url.indent", ""); isChanged = true; } if (isChanged) { settings.Flush(); } }
/// <summary> /// 获取模板 /// </summary> /// <returns></returns> public static IDictionary<string, string> GetTemplates() { IDictionary<string, string> dict = new Dictionary<string, string>(); string[] tpls; string tplRootPath = String.Format("{0}templates/", AppDomain.CurrentDomain.BaseDirectory); DirectoryInfo dir = new DirectoryInfo(tplRootPath); DirectoryInfo[] dirs=dir.GetDirectories(); tpls = new string[dirs.Length]; if (dir.Exists) { int i = -1; foreach (DirectoryInfo d in dirs) { if ((d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { tpls[++i] = d.Name; } } } SettingFile sf; string tplConfigFile, tplName; foreach (string key in tpls) { tplName = key; tplConfigFile = String.Format("{0}{1}/tpl.conf", tplRootPath, key); if (global::System.IO.File.Exists(tplConfigFile)) { sf = new SettingFile(tplConfigFile); if (sf.Contains("name")) { tplName = sf["name"]; } //if (sf.Contains("thumbnail")) //{ // tplThumbnail = sf["thumbnail"]; //} } if (!String.IsNullOrEmpty(key)) { dict.Add(key, tplName); } } return dict; }
/// <summary> /// 判断设置项的值是否为真 /// </summary> /// <param name="sf"></param> /// <param name="key"></param> /// <returns></returns> private static bool CheckTrueValue(SettingFile sf, string key) { return(sf.Contains(key) && sf.Get(key) == "true"); }
/// <summary> /// 模板列表 /// </summary> public void Templates_GET() { if (!UserState.Administrator.Current.IsMaster) { return; } string curTemplate = base.CurrentSite.Tpl; string tplRootPath = String.Format("{0}templates/", AppDomain.CurrentDomain.BaseDirectory); string[] tplList = new string[0]; DirectoryInfo dir = new DirectoryInfo(tplRootPath); if (dir.Exists) { DirectoryInfo[] dirs = dir.GetDirectories(); tplList = new string[dirs.Length]; int i = -1; foreach (DirectoryInfo d in dirs) { tplList[++i] = d.Name; } } SettingFile sf; string currentName = "", currentThumbnail = "", tplConfigFile, tplName, tplDescrpt, tplThumbnail; StringBuilder sb = new StringBuilder(); foreach (string tpl in tplList) { tplName = tpl; tplThumbnail = null; tplDescrpt = null; tplConfigFile = String.Format("{0}{1}/tpl.conf", tplRootPath, tpl); if (File.Exists(tplConfigFile)) { sf = new SettingFile(tplConfigFile); if (sf.Contains("name")) { tplName = sf["name"]; } if (sf.Contains("thumbnail")) { tplThumbnail = sf["thumbnail"]; } if (sf.Contains("descript")) { tplDescrpt = sf["descript"]; } } if (String.CompareOrdinal(tpl, curTemplate) != 0) { sb.Append("<li><p><a href=\"javascript:;\">"); if (tplThumbnail != null) { sb.Append("<img src=\"").Append(tplThumbnail).Append("\" alt=\"点击切换模板\" class=\"shot ").Append(tpl).Append("\"/>"); } else { sb.Append("<span title=\"点击切换模板\" class=\"shot ").Append(tpl).Append(" thumbnail\">无缩略图</span>"); } sb.Append("</a></p><p><a href=\"javascript:;\" class=\"t\">") .Append(tplName).Append("</a></p><p><a class=\"btn edit\" href=\"tpl:") .Append(tpl).Append("\">编辑</a> <a class=\"btn down\" href=\"tpl:") .Append(tpl).Append("\">下载</a></p>") .Append("<p class=\"hidden\">").Append(tplDescrpt).Append("</p>") .Append("</li>"); } else { currentName = String.IsNullOrEmpty(tplName) ? curTemplate : tplName; if (tplThumbnail != null) { currentThumbnail = "<img src=\"" + tplThumbnail + "\" alt=\"点击切换模板\" class=\"shot1 " + tpl + "\"/>"; } else { currentThumbnail = "<span class=\"shot1 " + tpl + " thumbnail\">无缩略图</span>"; } } } base.RenderTemplate(ResourceMap.GetPageContent(ManagementPage.Template_Manager), new { list = sb.ToString(), current = curTemplate, currentName = currentName, currentThumbnail = currentThumbnail }); }
public void Save() { SettingFile sf = new SettingFile(String.Format("{0}templates/{1}/tpl.conf",Cms.PyhicPath,this.tplName)); /**************** 模板设置 ****************/ if (sf.Contains("CFG_ShowErrror")) { sf["CFG_ShowErrror"] = this.CFG_ShowError?"true":"false"; } else { sf.Append("CFG_ShowErrror", this.CFG_ShowError?"true":"false"); } if (sf.Contains("CFG_SitemapSplit")) { sf["CFG_SitemapSplit"] = this.cfg_sitemapSplit; } else { sf.Append("CFG_SitemapSplit", this.cfg_sitemapSplit); } if (sf.Contains("CFG_ArchiveTagsFormat")) { sf["CFG_ArchiveTagsFormat"] = this.cfg_ArchiveTagsFormat; } else { sf.Append("CFG_ArchiveTagsFormat", this.cfg_ArchiveTagsFormat); } if (sf.Contains("CFG_NavigatorLinkFormat")) { sf["CFG_NavigatorLinkFormat"] = this.cfg_navigatorLinkFormat; } else { sf.Append("CFG_NavigatorLinkFormat", this.cfg_navigatorLinkFormat); } if (sf.Contains("CFG_NavigatorChildFormat")) { sf["CFG_NavigatorChildFormat"] = this.cfg_navigatorChildFormat; } else { sf.Append("CFG_NavigatorChildFormat", this.cfg_navigatorChildFormat); } if (sf.Contains("CFG_FriendShowNum")) { sf["CFG_FriendShowNum"] = this.cfg_friendShowNum.ToString(); } else { sf.Append("CFG_FriendShowNum", this.cfg_friendShowNum.ToString()); } if (sf.Contains("CFG_FriendLinkFormat")) { sf["CFG_FriendLinkFormat"] = this.cfg_friendLinkFormat; } else { sf.Append("CFG_FriendLinkFormat", this.cfg_friendLinkFormat); } if (sf.Contains("CFG_TrafficFormat")) { sf["CFG_TrafficFormat"] = this.cfg_trafficFormat; } else { sf.Append("CFG_TrafficFormat", this.cfg_trafficFormat); } if (sf.Contains("CFG_CommentEditorHtml")) { sf["CFG_CommentEditorHtml"] = this.cfg_commentEditorHtml; } else { sf.Append("CFG_CommentEditorHtml", this.cfg_commentEditorHtml); } if (sf.Contains("CFG_allowAmousComment")) { sf["CFG_allowAmousComment"] = this.cfg_allowAmousComment ? "true" : "false"; } else { sf.Append("CFG_allowAmousComment", this.cfg_allowAmousComment ? "true" : "false"); } if (sf.Contains("CFG_OutlineLength")) { sf["CFG_OutlineLength"] = this.cfg_outlineLength.ToString(); } else { sf.Append("CFG_OutlineLength", this.cfg_outlineLength.ToString()); } if (sf.Contains("CFG_ArchiveFormat")) { sf["CFG_ArchiveFormat"] = this.cfg_archiveFormat; } else { sf.Append("CFG_ArchiveFormat", this.cfg_archiveFormat); } if (sf.Contains("CFG_ArchiveLinkFormat")) { sf["CFG_ArchiveLinkFormat"] =this.cfg_archiveLinkFormat; } else { sf.Append("CFG_ArchiveLinkFormat", this.cfg_archiveLinkFormat); } if (sf.Contains("CFG_PrevArchiveFormat")) { sf["CFG_PrevArchiveFormat"] = this.cfg_prevArchiveFormat; } else { sf.Append("CFG_PrevArchiveFormat", this.cfg_prevArchiveFormat); } if (sf.Contains("CFG_NextArchiveFormat")) { sf["CFG_NextArchiveFormat"] = this.cfg_nextArchiveFormat; } else { sf.Append("CFG_NextArchiveFormat", this.cfg_nextArchiveFormat); } if (sf.Contains("CFG_CategoryLinkFormat")) { sf["CFG_CategoryLinkFormat"] = this.cfg_categoryLinkFormat; } else { sf.Append("CFG_CategoryLinkFormat", this.cfg_categoryLinkFormat); } sf.Flush(); }