/// <summary> /// 取得一个文件的内容 /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetSkinStr(string filename) { string str = ""; string path = "/theme/system/" + filename; str = HtmlEngine.ReadTxt(path); return(str); }
/// <summary> /// 生成插件页面 /// </summary> /// <param name="pgconf"></param> /// <param name="site"></param> /// <param name="type"></param> /// <param name="parentpath"></param> public static void CreatePluginPage(PluginConfig pgconf, string type, string parentpath) { string WebPath = Site.Instance.WebPath; string path = System.Web.HttpRuntime.AppDomainAppPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + type + "/page/" + parentpath; string filepath = WebPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + type + "/page/" + parentpath; string mediapath = "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + type; if (type == "admin") { if (!string.IsNullOrEmpty(RequestTool.GetConfigKey("SystemAdmin").Trim())) { path = System.Web.HttpRuntime.AppDomainAppPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + RequestTool.GetConfigKey("SystemAdmin").Trim() + "/page/" + parentpath; filepath = WebPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + RequestTool.GetConfigKey("SystemAdmin").Trim() + "/page/" + parentpath; mediapath = "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + RequestTool.GetConfigKey("SystemAdmin").Trim(); } } if (!Directory.Exists(path)) { return; } DirectoryInfo mydir = new DirectoryInfo(path); DirectoryInfo[] dirs = mydir.GetDirectories(); foreach (DirectoryInfo dir in dirs) { CreatePluginPage(pgconf, type, parentpath + "/" + dir.Name);//递归全部文件夹 } FileInfo[] files = mydir.GetFiles(); string content = ""; string pagename = ""; parentpath = parentpath.ToLower().Trim('/'); string createpath = type; if (type == "admin") { createpath = Site.Instance.AdminPath; } else if (type == "supplier") { createpath = Site.Instance.SupplierPath; } //parentpath = parentpath.Substring(type.Length, parentpath.Length - type.Length); if (!Directory.Exists(System.Web.HttpRuntime.AppDomainAppPath + "/" + createpath)) { Directory.CreateDirectory(System.Web.HttpRuntime.AppDomainAppPath + "/" + createpath); } foreach (FileInfo f in files) { pagename = f.Name.Replace(".html", ".aspx"); pagename = ThemeUrl.GetFullPath(WebPath + "/" + createpath + "/" + parentpath + "/" + pagename); content = HtmlEngine.ReadTxt(filepath + "/" + f.Name); CreatAdminAspx(pagename, content, type, mediapath); } }
/// <summary> /// /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetSkinStr(Lebi_Supplier_Skin skin) { string str = ""; string path = skin.Path.TrimEnd('/') + "/index.html"; path = ThemeUrl.GetFullPath(path); str = HtmlEngine.ReadTxt(path); return(str); }
/// <summary> /// /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetSkinStr(Lebi_AdminSkin skin) { string str = ""; string path = site.AdminPath + "/custom/skin/" + skin.Code + ".html"; path = ThemeUrl.GetFullPath(path); str = HtmlEngine.ReadTxt(path); return(str); }
/// <summary> /// /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetSkinStr(Lebi_Theme theme, Lebi_Theme_Skin skin) { string str = ""; string path = theme.Path_Files + "/" + skin.Path_Skin; path = ThemeUrl.GetFullPath(path); str = HtmlEngine.ReadTxt(path); return(str); }
/// <summary> /// 生成后台|供应商文件 /// </summary> /// <param name="type">admin或supplier或前台文件夹名</param> /// <param name="parentpath"></param> public static string CreateAdmin(string type, string parentpath) { string msg = ""; Site site = new Site(); string content = ""; string createpath = type; if (type == "admin") { createpath = site.AdminPath == "" ? "admin" : site.AdminPath; } else if (type == "supplier") { if (!Shop.LebiAPI.Service.Instanse.Check("plugin_gongyingshang")) { return(""); } createpath = site.SupplierPath == "" ? "supplier" : site.SupplierPath; } else if (type == "front") { createpath = "/"; } try { string path = ""; path = System.Web.HttpRuntime.AppDomainAppPath + "theme/system/systempage/" + type + "/page/" + parentpath; if (!Directory.Exists(path)) { return("模板目录不存在"); } DirectoryInfo mydir = new DirectoryInfo(path); DirectoryInfo[] dirs = mydir.GetDirectories(); foreach (DirectoryInfo dir in dirs) { CreateAdmin(type, parentpath + "/" + dir.Name); } FileInfo[] files = mydir.GetFiles(); foreach (FileInfo f in files) { content = HtmlEngine.ReadTxt("theme/system/systempage/" + type + "/page/" + parentpath + "/" + f.Name); CreatAdminAspx(createpath + parentpath + "/" + f.Name.Replace(".html", ".aspx"), content, type, ""); } //生成插件页面 List <PluginConfig> plgs = Event.GetPluginConfig(); foreach (PluginConfig plg in plgs) { CreateALLPluginPage(plg); } } catch (Exception ex) { } return(msg); }
/// <summary> /// 生成域名绑定规则 /// </summary> public static void CreateURLRewrite_shop() { HtmlEngine save = new HtmlEngine(); StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder(); string str = HtmlEngine.ReadTxt("httpd.ini"); string str1 = HtmlEngine.ReadTxt(".htaccess"); if (str == "") { sb.AppendLine("[ISAPI_Rewrite]"); } else { sb.AppendLine(HtmlEngine.ReadTxt("httpd.ini")); } if (str1 == "") { sb1.AppendLine("RewriteEngine On"); sb1.AppendLine("RewriteCompatibility2 On"); sb1.AppendLine("RepeatLimit 200"); sb1.AppendLine("RewriteBase"); } else { sb1.AppendLine(HtmlEngine.ReadTxt(".htaccess")); } List <Lebi_Supplier> models = B_Lebi_Supplier.GetList("Domain!=''", ""); if (models.Count == 0) { return; } //RewriteCond %{HTTP_HOST} ^www.shop0769.top$ //RewriteRule ^(.*)$ http://www.shop0769.com/shop/?id=11 Lebi_Site site = B_Lebi_Site.GetModel("1=1 order by Sort desc"); if (site != null) { foreach (Lebi_Supplier model in models) { //sb1.AppendLine(@"RewriteRule //" + model.Domain + "(.*)$ /shop/?id=" + model.id + " [NC,N]"); //sb.AppendLine(@"RewriteRule //" + model.Domain + "/(.*) /$1/shop/?id=" + model.id + " [N,I]"); sb.AppendLine(@"RewriteCond Host ^" + model.Domain + "$"); sb.AppendLine(@"RewriteRule (.*) " + ShopCache.GetBaseConfig().HTTPServer + "://" + site.Domain + "/shop/?id=" + model.id + "$ [N,I]"); sb1.AppendLine(@"RewriteCond %{HTTP_HOST} ^" + model.Domain + "$"); sb1.AppendLine(@"RewriteRule ^(.*)$ " + ShopCache.GetBaseConfig().HTTPServer + "://" + site.Domain + "/shop/?id=" + model.id + " [NC,N]"); } } save.CreateFile("httpd.ini", sb.ToString(), "ascii"); save.CreateFile(".htaccess", sb1.ToString(), "ascii"); }
/// <summary> /// 生成页面皮肤 /// 针对单个皮肤生成的情况 /// </summary> /// <returns></returns> public void CreateSkin() { string Msg = ""; int ThemeID = 0; int SkinID = 0; string Content = ""; string SkinPath = ""; //皮肤路径 string Path = ""; //输入Path要包含路径及文件名 SkinID = RequestTool.RequestInt("id", 0); Lebi_Theme_Skin skin = B_Lebi_Theme_Skin.GetModel(SkinID); Lebi_Theme theme; if (skin == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } ThemeID = skin.Theme_id; theme = B_Lebi_Theme.GetModel(ThemeID); SkinPath = theme.Path_Files + "/" + skin.Path_Skin; SkinPath = ThemeUrl.GetFullPath(SkinPath); Content = HtmlEngine.ReadTxt(SkinPath); List <Lebi_Language> langs = B_Lebi_Language.GetList("Theme_id=" + theme.id + "", ""); if (langs.Count == 0) { Response.Write("{\"msg\":\"" + Tag("请在站点语言设置中关联此模板") + "\"}"); return; } Site site = new Site(); foreach (Lebi_Language lang in langs) { if (lang.Theme_id != ThemeID) { continue; } Lebi_Site s = B_Lebi_Site.GetModel(lang.Site_id); if (s == null) { Path = lang.Path + "/" + skin.PageName; } else { Path = s.Path + lang.Path + "/" + skin.PageName; } Msg = Shop.Bussiness.Theme.CreatAspx(s, lang, theme, skin, Path, Content); } Response.Write("{\"msg\":\"" + Msg + "\"}"); }
/// <summary> /// 取得一个文件的内容 /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetSkinStr(string filename) { string str = ""; string path = "/" + filename; if (filename.ToLower().Contains("web.config")) { str = ""; } else { str = HtmlEngine.ReadTxt(path); } return(str); }
/// <summary> /// 取得一个文件内的备注 /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetRemark(string filename) { string str = ""; string path = "/theme/system/" + filename; str = HtmlEngine.ReadTxt(path); if (str.IndexOf("<!--") == 0) { str = RegexTool.GetRegValue(str, @"<!--(.*?)-->"); str = str.Trim() + "\r\n"; //str = str.Replace("\r\n",""); } else { str = ""; } return(str); }
/// <summary> /// /// </summary> /// <param name="theme"></param> /// <param name="skin"></param> /// <returns></returns> private string GetSkinStr(Lebi_AdminSkin skin) { string str = ""; string path = ""; if (!string.IsNullOrEmpty(RequestTool.GetConfigKey("SystemAdmin").Trim())) { path = site.AdminPath + "/custom/skin2/" + skin.Code + ".html"; } else { path = site.AdminPath + "/custom/skin/" + skin.Code + ".html"; } path = ThemeUrl.GetFullPath(path); str = HtmlEngine.ReadTxt(path); return(str); }
/// <summary> /// 获取模板页面内容 /// </summary> public void GetSkinContent() { if (!EX_Admin.Power("theme_edit", "编辑模板")) { AjaxNoPower(); return; } string filename = RequestTool.RequestString("filename"); string str = ""; string path = site.WebPath + "/theme/system/" + filename; path = path.ToLower().Replace(".aspx", ".html"); string FileName = HttpContext.Current.Server.MapPath(@"~/" + path); if (File.Exists(FileName)) { str = HtmlEngine.ReadTxt(path); } else { str = ""; } Response.Write(str); }
/// <summary> /// 执行代码替换 /// 在${...}$内 /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static string DoCodeConvert(string strIn, string type, string webpath, string mediapath) { strIn = DoLayout(strIn, type, webpath, mediapath); //====================================================== string[] PartArry = RegexTool.GetSimpleRegResultArray(strIn, @"({[Mm][Oo][Dd]:.*?})"); string partTag = ""; string partConten = ""; string partPara = ""; webpath = webpath.TrimEnd('/'); Lebi_Theme_Skin partskin = new Lebi_Theme_Skin(); foreach (string partStr in PartArry) { partTag = ""; partConten = ""; partPara = ""; if (partStr.Contains("(")) { partTag = RegexTool.GetRegValue(partStr, @"{[Mm][Oo][Dd]:(.*?)\(.*?}"); partPara = RegexTool.GetRegValue(partStr, @"{[Mm][Oo][Dd]:.*?\((.*?)\)}"); } else { partTag = RegexTool.GetRegValue(partStr, @"{[Mm][Oo][Dd]:(.*?)}"); } if (partTag != "") { //模块提取优先级 //1插件中的BLOCK文件夹 //2模板中的自定义设置 //3系统块 string[] plugins = ShopCache.GetBaseConfig().PluginUsed.ToLower().Split(','); foreach (string plugin in plugins) { partConten = HtmlEngine.ReadTxt(webpath + "/plugin/" + plugin + "/systempage/" + type + "/block/" + partTag + ".html"); if (partConten == "") { partConten = HtmlEngine.ReadTxt(webpath + "/plugin/" + plugin + "/block/" + partTag + ".html"); } if (partConten != "") { break; } } if (partConten == "") { partConten = HtmlEngine.ReadTxt(ThemeUrl.GetFullPath(webpath + "/system/" + type + "/block/" + partTag + ".html")); } if (partConten == "") { partConten = HtmlEngine.ReadTxt(ThemeUrl.GetFullPath(webpath + "/system/block/" + partTag + ".html")); } if (partConten != "") { partConten = "<!--MOD_start:" + partTag + "-->\r\n" + DoCodeConvert(partConten, type, webpath, "") + "<!--MOD_end:" + partTag + "-->\r\n"; strIn = RegexTool.ReplaceRegValue(strIn, @"{[Mm][Oo][Dd]:" + partTag + ".*?}", partConten); } } } //========================================================= string str = ""; Type t = typeof(ShopPage); string temp = ""; int[,] d = IndexFlagArry(strIn);//记录开始,结尾标记的数组 if (d.Length > 0) { int begin = 0; string[,] tempArry = new string[d.GetUpperBound(0) + 1, 2];//用于存放一个外层标记的临时数组 for (int i = 0; i < d.GetUpperBound(0); i++) { temp += RegexTool.GetSubString(strIn, begin, d[i, 0]) + "$$$" + i + "$$$";//挑选非标记部组合,将标记部分替换为$$$0$$$,$$$1$$$形式 begin = d[i, 1] + 2; tempArry[i, 0] = "$$$" + i + "$$$"; tempArry[i, 1] = RegexTool.GetSubString(strIn, d[i, 0] + 2, d[i, 1]);//截取不包含开始,结尾标记的块 } temp += RegexTool.GetSubString(strIn, begin, strIn.Length); str = temp;//str已经替除了全部的标记块 for (int i = 0; i < tempArry.GetUpperBound(0); i++) { temp = DoPart(tempArry[i, 1], type, webpath); str = str.Replace("$$$" + i + "$$$", temp); } } return(str); }
/// <summary> /// 载入布局文件 /// </summary> /// <param name="strIn"></param> /// <param name="theme"></param> /// <returns></returns> public static string DoLayout(string strIn, string type, string webpath, string mediapath) { string layout = RegexTool.GetRegValue(strIn, @"{[Ll][Aa][Yy][Oo][Uu][Tt]:(.*?)}"); string cs = RegexTool.GetRegValue(strIn, @"({[Cc][Ll][Aa][Ss][Ss]:.*?})"); if (layout == "") { return(cs + strIn); } string layoutpath = ""; string layoutContent = ""; if (mediapath != "") { layoutpath = webpath + mediapath + "/layout/" + layout + ".layout"; layoutpath = ThemeUrl.GetFullPath(layoutpath); layoutContent = HtmlEngine.ReadTxt(layoutpath); } if (layoutContent == "") { layoutpath = webpath + "/theme/system/systempage/" + type + "/layout/" + layout + ".layout"; layoutpath = ThemeUrl.GetFullPath(layoutpath); layoutContent = HtmlEngine.ReadTxt(layoutpath); } if (layoutContent == "") { layoutpath = webpath + "/theme/system/layout/" + layout + ".layout"; layoutpath = ThemeUrl.GetFullPath(layoutpath); layoutContent = HtmlEngine.ReadTxt(layoutpath); } if (layoutContent == "") { return(""); } string[] holderArray = RegexTool.GetSimpleRegResultArray(layoutContent, @"({[Hh][Oo][Ll][Dd][Ee][Rr]:.*?})"); foreach (string holder in holderArray) { string tag = RegexTool.GetRegValue(holder, @"{[Hh][Oo][Ll][Dd][Ee][Rr]:(.*?)}"); string regtag = ""; foreach (char t in tag) { regtag += "[" + t.ToString().ToUpper() + t.ToString().ToLower() + "]"; } string holdercontent = RegexTool.GetRegValue(strIn, @"<" + regtag + ">(.*?)</" + regtag + ">"); layoutContent = RegexTool.ReplaceRegValue(layoutContent, @"{[Hh][Oo][Ll][Dd][Ee][Rr]:" + tag + ".*?}", holdercontent); } //载入重写模块 string[] rewriteArray = RegexTool.GetSimpleRegResultArray(strIn, @"({[Rr][Ee][Ww][Rr][Ii][Tt][Ee]:.*?})"); foreach (string rewrite in rewriteArray) { string tag = RegexTool.GetRegValue(rewrite, @"{[Rr][Ee][Ww][Rr][Ii][Tt][Ee]:(.*?)}"); string from = ""; string to = ""; from = tag.Substring(0, tag.IndexOf(" ")); to = tag.Substring(tag.IndexOf(" ") + 1, tag.Length - from.Length - 1); string regfrom = ""; string regto = ""; foreach (char t in from) { regfrom += "[" + t.ToString().ToUpper() + t.ToString().ToLower() + "]"; } foreach (char t in to) { regto += "[" + t.ToString().ToUpper() + t.ToString().ToLower() + "]"; } string holdercontent = RegexTool.GetRegValue(strIn, @"<" + regto + ">(.*?)</" + regto + ">"); if (holdercontent == "") { holdercontent = "{MOD:" + to + "}"; } layoutContent = RegexTool.ReplaceRegValue(layoutContent, @"{[Mm][Oo][Dd]:" + regfrom + "}", holdercontent); } layoutContent = cs + layoutContent; return(layoutContent); }
/// <summary> /// 解压部署文件 /// </summary> public void Version_FileUpdate() { if (!EX_Admin.Power("version", "版本管理")) { AjaxNoPower(); return; } int id = RequestTool.RequestInt("id"); int IsUpdated = RequestTool.RequestInt("IsUpdated", 0); Lebi_Version model = B_Lebi_Version.GetModel(id); if (model == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } if (!Shop.LebiAPI.Service.Instanse.ISRightVersion(SYS, model)) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } //if (IsUpdated == 0) //{ if (model.Path_rar != "") { //文件解包+部署文件 string nistring = HtmlEngine.ReadTxt("/config/noupdate.txt"); UpDate.DecompressFile(model.Path_rar, "/", nistring); //执行更新程序 try { string url = "http://" + HttpContext.Current.Request.Url.Authority + "/update/update.aspx"; string res = HtmlEngine.CetHtml(url); if (res.Contains("OK")) { string ServerPath = System.Web.HttpContext.Current.Server.MapPath("~/"); string fileUrl = ServerPath + "/update/update.aspx"; if (File.Exists(fileUrl)) { File.Delete(fileUrl); } //fileUrl = ServerPath + "/update.aspx.cs"; //if (File.Exists(fileUrl)) //{ // File.Delete(fileUrl); //} } } catch { } //执行sql string sqlfile = WebPath + "/update/update.sql"; if (LB.DataAccess.DB.BaseUtilsInstance.DBType == "access") { sqlfile = WebPath + "/update/update_access.sql"; } //string sql = HtmlEngine.ReadTxt(sqlfile); //if (sql != null) //{ // if (sql != "") // Common.ExecuteSql(sql); //} string fileName = HttpContext.Current.Server.MapPath(@"~/" + sqlfile); if (File.Exists(fileName)) { using (FileStream fs = new FileStream(fileName, FileMode.Open)) { using (StreamReader reader = new StreamReader(fs, Encoding.UTF8)) { string text = string.Empty; while (!reader.EndOfStream) { try { text = reader.ReadLine(); if (text != "") { Common.ExecuteSql(text); } } catch { } } } } } } //} //if (model.IsTypeUpdate == 1) //{ // //更新type表 // Thread thread = new Thread(new ThreadStart(Shop.LebiAPI.Service.Instanse.UpdateType)); // thread.IsBackground = true; // thread.Start(); //} //if (model.IsDBStructUpdate == 1) //{ // //更新数据库结构 // Thread thread = new Thread(new ThreadStart(Shop.LebiAPI.Service.Instanse.UpdateDBBody)); // thread.IsBackground = true; // thread.Start(); //} //if (model.IsSystemMenuUpdate == 1) //{ // //更新系统菜单 // Thread thread = new Thread(new ThreadStart(Shop.LebiAPI.Service.Instanse.UpdateMenu)); // thread.IsBackground = true; // thread.Start(); //} //if (model.IsThemePageUpdate == 1) //{ // //更新系统页面 // Thread thread = new Thread(new ThreadStart(Shop.LebiAPI.Service.Instanse.UpdateThemePage)); // thread.IsBackground = true; // thread.Start(); //} //if (model.IsNodeUpdate == 1) //{ // //更新系统结点 // Thread thread = new Thread(new ThreadStart(Shop.LebiAPI.Service.Instanse.UpdateNode)); // thread.IsBackground = true; // thread.Start(); //} //if (model.IsSystemPageUpdate == 1) //{ // //更新系统页面 // Thread thread = new Thread(new ThreadStart(SystemTheme.CreateSystemPage)); // thread.IsBackground = true; // thread.Start(); //} //if (model.IsPageUpdate == 1) //{ // //更新所有前台页面 // Thread thread = new Thread(new ThreadStart(Shop.Bussiness.Theme.CreateThemeALL)); // thread.IsBackground = true; // thread.Start(); //} //更新版本号 BaseConfig cf = new BaseConfig(); cf.Version_Son = model.Version_Son.ToString(); cf.Version = model.Version.ToString(); B_BaseConfig bcf = new B_BaseConfig(); bcf.SaveConfig(cf); model.IsUpdate = 1; model.Time_Update = System.DateTime.Now; B_Lebi_Version.Update(model); //同步版本号 Shop.LebiAPI.Service.Instanse.UpdateVersionCode(); Response.Write("{\"msg\":\"OK\"}"); }