给dtcms增加模板自动生成功能

给dtcms增加模板自动生成功能

2023年7月3日发(作者:)

给dtcms增加模板⾃动⽣成功能作为的使⽤者你是不是像我⼀样,也在不停的修改模板之后要点击⽣成模板浪费了很多开发模板的时间?那就跟我⼀起给增加⼀个开发者模式,当模板修改完成之后,直接刷新页⾯就能看到效果,⽽不再重复的⽣成模板,⽣成模板了!1,增加开发者模式控制选项,和开发是所⽤的模板 所需要修改的内容有 Model层 sys_ 增加两个字段 private int _develop = 0; private string _tempName = "main"; public int develop { get { return _develop; } set { _develop = value; } } public string tempName { get { return _tempName; } set { _tempName = value; } }2, admin/settings/sys_增加页⾯显⽰

开启开发模式
*当选择开发模式时,请求访问链接⾃动⽣成当前请求页的模板!免去开发时要点击⽣成模板,使⽤此模式最好关闭伪静态
模板名称
*当选择开发模式时,所使⽤的模板的⽂件夹名称
3, admin/settings/sys_ 增加以下红⾊部分代码 #region 赋值操作================================= private void ShowInfo() { nfig bll = new nfig(); nfig model = nfig(); = e; = ; = pany; = ress; = ; = ; = l; = d; = h; = agepath; edValue = ng(); = extension; d = p == 1; = me; if (status == 1)--------------------------------------------------------------------------- /// /// 保存配置信息 /// protected void btnSubmit_Click(object sender, EventArgs e) { ChkAdminLevel("sys_config", ng()); //检查权限 nfig bll = new nfig(); nfig model = nfig(); try { e = ; = ; pany = ; ress = ; = ; = ; l = ; d = ; h = ; agepath = ; status = nt(edValue, 0); extension = ; p = d == true ? 1 : 0; me = ;

4, 增加以下红⾊部分代码///

/// DTcms的HttpModule类 /// public class HttpModule : odule { protected internal nfig siteConfig = new nfig().loadConfig(); /// /// 实现接⼝的Init⽅法 /// /// public void Init(HttpApplication context) { equest += new EventHandler(ReUrl_BeginRequest); } /// /// 实现接⼝的Dispose⽅法 /// public void Dispose() { } #region 页⾯请求事件处理=================================== /// /// 页⾯请求事件处理 /// /// 事件的源 /// 包含事件数据的 EventArgs private void ReUrl_BeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; nfig siteConfig = new nfig().loadConfig(); //获得站点配置信息 string requestPath = r(); //获得当前页⾯(含⽬录) //如果虚拟⽬录(不含安装⽬录)与站点根⽬录名相同则不需要重写 if (IsDirExist(_SITE_DIRECTORY, h, h, requestPath)) { return; } string requestDomain = r(); //获得当前域名(含端⼝号) string sitePath = GetSitePath(h, requestPath, requestDomain); //获取当前站点⽬录 string requestPage = CutStringPath(h, sitePath, requestPath); //截取除安装、站点⽬录部分 //是否开启开发模式 if (p == 1) { string tempName=me; MarkTemplates(sitePath, tempName, requestPage); } //检查⽹站重写状态0表⽰不开启重写、1开启重写、2⽣成静态 if (status == 0) { #region 站点不开启重写处理⽅法=========================== //遍历URL字典,匹配URL页⾯部分 foreach (_rewrite model in s().Urls) { //查找到与页⾯部分匹配的节点 if ( == ing(dexOf("/") + 1)) { //如果该页⾯属于插件页则映射到插件⽬录,否则映射到站点⽬录 if ( == ORY_REWRITE_PLUGIN) { ePath(("{0}{1}/{2}{3}", h, ORY_REWRITE_ASPX, ORY_REWRITE_PLUGIN,requestPage)); return; } else { ePath(("{0}{1}/{2}{3}", h, ORY_REWRITE_ASPX, sitePath, requestPage)); return; } } } #endregion } else { #region 站点开启重写或静态处理⽅法======================= //遍历URL字典 foreach (_rewrite model in s().Urls) { //如果没有重写表达式则不需要重写 if (_rewrite_ == 0 && Extension(, extension) == ing(dexOf("/") + 1)) { //如果该页⾯属于插件页则映射到插件⽬录,否则映射到站点⽬录 if ( == ORY_REWRITE_PLUGIN) { ePath(("{0}{1}/{2}/{3}", h, ORY_REWRITE_ASPX, ORY_REWRITE_PLUGIN,)); return; } else { ePath(("{0}{1}/{2}/{3}", h, ORY_REWRITE_ASPX, sitePath, )); return; } } //遍历URL字典的⼦节点 foreach (_rewrite_item item in _rewrite_items) { string newPattern = Extension(n, extension); //替换扩展名 //如果与URL节点匹配则重写 if (h(requestPage, ("^/{0}$", newPattern), | Case) || ( == "" && h(requestPage, ("^/{0}$", n), |Case))) { //如果开启⽣成静态、不是移动站点且是频道页或⾸页,则映射重写到HTML⽬录 if (status == 2 && !eDomains().ns(sitePath) &&

( > 0 || r() == "")) //频道页 { ePath(h + ORY_REWRITE_HTML + "/" + sitePath + Extension(requestPage, extension, true)); return; } else if ( == ORY_REWRITE_PLUGIN) //插件页 { string queryString = e(requestPage, ("/{0}", newPattern), tring, | Case); ePath(("{0}{1}/{2}/{3}",

h, ORY_REWRITE_ASPX, ORY_REWRITE_PLUGIN,), , queryString); return; } else //其它 { string queryString = e(requestPage, ("/{0}", newPattern), tring, | Case); ePath(("{0}{1}/{2}/{3}", h, ORY_REWRITE_ASPX, sitePath, ), , queryString); return; } } } } #endregion } } #endregion #region 辅助⽅法(私有)===================================== ///

/// 获取URL的虚拟⽬录(除安装⽬录) /// /// ⽹站安装⽬录 /// 当前页⾯,包含⽬录 /// String private string GetFirstPath(string webPath, string requestPath) { if (With(webPath)) { string tempStr = ing(); if (f("/") > 0) { return ing(0, f("/")).ToLower(); } } return ; } /// /// 获取当前域名包含的站点⽬录 /// /// 获取的域名(含端⼝号) /// String private string GetCurrDomainPath(string requestDomain) { //当前域名是否存在于站点⽬录列表 if (eDomains().nsValue(requestDomain)) { return eDomains().Domains[requestDomain]; } return ; } /// /// 获取当前页⾯包含的站点⽬录 /// /// ⽹站安装⽬录 /// 获取的页⾯,包含⽬录 /// String private string GetCurrPagePath(string webPath, string requestPath) { //获取URL的虚拟⽬录(除安装⽬录) string requestFirstPath = GetFirstPath(webPath, requestPath); if (requestFirstPath != && eDomains().nsKey(requestFirstPath)) { return requestFirstPath; } return ; } /// /// 获取站点的⽬录 /// /// ⽹站安装⽬录 /// 获取的页⾯,包含⽬录 /// 获取的域名(含端⼝号) /// String private string GetSitePath(string webPath, string requestPath, string requestDomain) { //获取当前域名包含的站点⽬录 string domainPath = GetCurrDomainPath(requestDomain); if (domainPath != ) { return domainPath; } // 获取当前页⾯包含的站点⽬录 string pagePath = GetCurrPagePath(webPath, requestPath); if (pagePath != ) { return pagePath; } return eDomains().DefaultPath; } /// /// 遍历指定路径⽬录,如果缓存存在则直接返回 /// /// 缓存KEY /// 指定路径 /// ArrayList private ArrayList GetSiteDirs(string cacheKey, string dirPath) { ArrayList _cache = (cacheKey); //从续存中取 if (_cache == null) { _cache = new ArrayList(); DirectoryInfo dirInfo = new DirectoryInfo(Path(dirPath)); foreach (DirectoryInfo dir in ectories()) { _(r()); } (cacheKey, _cache, 2); //存⼊续存,弹性2分钟 } return _cache; } /// /// 遍历指定路径的⼦⽬录,检查是否匹配 /// /// 缓存KEY /// ⽹站安装⽬录,以“/”结尾 /// 指定的路径,以“/”结尾 /// 获取的URL全路径 /// 布尔值 private bool IsDirExist(string cacheKey, string webPath, string dirPath, string requestPath) { ArrayList list = GetSiteDirs(cacheKey, dirPath); //取得所有⽬录 string requestFirstPath = ; //获得当前页⾯除站点安装⽬录的虚拟⽬录名称 string tempStr = ; //临时变量 if (With(webPath)) { tempStr = ing(); if (f("/") > 0) { requestFirstPath = ing(0, f("/")); } } if ( > 0 && ns(r())) { return true; } return false; } /// /// 截取安装⽬录和站点⽬录部分 /// /// 站点安装⽬录 /// 站点⽬录 /// 当前页⾯路径 /// String private string CutStringPath(string webPath, string sitePath, string requestPath) { if (With(webPath)) { requestPath = ing(); } sitePath += "/"; if (With(sitePath)) { requestPath = ing(); } return "/" + requestPath; } #endregion #region ⽣成模板============================= /// /// ⽣成模板 /// private void MarkTemplates(string buildPath, string skinName,string requestPage) { //取得ASP⽬录下的所有⽂件 string fullDirPath = Path(("{0}aspx/{1}/", h, buildPath)); //获得URL配置列表 _rewrite bll = new _rewrite(); List<_rewrite> ls = t(""); DirectoryInfo dirFile = new DirectoryInfo(fullDirPath); //删除不属于URL映射表⾥的⽂件,防⽌冗余 if ((fullDirPath)) { foreach (FileInfo file in es()) { //检查⽂件 //_rewrite modelt = (p => r() == r()); //if (modelt == null) //{ (); //} } } //遍历URL配置列表 foreach (_rewrite modelt in ls) { //如果URL配置对应的模板⽂件存在则⽣成 string fullPath = Path(("{0}templates/{1}/{2}", h, skinName, t)); if ((fullPath)&& ns(e(".html",".aspx"))) { plate(h, "templates", skinName, t, , t,buildPath, l, ze, 1); } } } #endregion }ok 试试修改模板刷新页⾯看看是否能够⾃动⽣成模板了

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688384706a130038.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信