private void GetPluginConfigData(HttpContext context) { string pluginid = context.Request.Form["id"]; string type = context.Request.Form["type"]; string fn = context.Request.Form["fn"]; XmlDocument xmlDoc = new XmlDocument(); Dukey.Model.WebConfig mysite = BLL.WebConfig.instance.GetModelByCache();//网站配置信息 string path = context.Server.MapPath("~/template/" + mysite.folder + "/theme.xml"); xmlDoc.Load(path); //加载XML文档 XmlNode paras = xmlDoc.SelectSingleNode("//config/page[@url='" + fn + "']/plugins/plugin[@id='" + pluginid + "' and @type='" + type + "']/paras"); if (paras != null) { context.Response.Write(paras.InnerText); } }
public static string SelectPlugins(string originstr, string type, string fn)//选择插件 { try { Dukey.Model.WebConfig mysite = BLL.WebConfig.instance.GetModelByCache();//网站配置信息 string path = HttpContext.Current.Server.MapPath("~/template/" + mysite.folder + "/" + fn + ".html"); string htmlstr = Common.FileHelper.ReadFile(path, "utf-8"); string tempid = type + "" + DateTime.Now.ToString("fff"); htmlstr = htmlstr.Replace("edit=\"" + originstr + "\"", "edit=\"" + type + "." + tempid + "\""); htmlstr = htmlstr.Replace("<!--" + originstr + "-->", "{$plugin." + type + "." + tempid + "}"); //MatchCollection mc = Regex.Matches(htmlstr, @"(?<=<div[^>]*>)[\s\S]*?(?=</div>)", RegexOptions.IgnoreCase); //htmlstr = htmlstr.Replace("edit=\"" + type + "." + pluginid + "\"", "edit=\"placeholder-" + DateTime.Now.ToString("fff") + "\""); Common.FileHelper.WriteFile(path, htmlstr, "utf-8"); return("ok"); } catch (Exception ex) { return(ex.Message); } }
private void PluginDelete(HttpContext context) { string pluginid = context.Request.Form["id"]; string type = context.Request.Form["type"]; string fn = context.Request.Form["fn"]; try { Dukey.Model.WebConfig mysite = BLL.WebConfig.instance.GetModelByCache();//网站配置信息 //删除插件配置 string xmlpath = context.Server.MapPath("~/template/" + mysite.folder + "/theme.xml"); XMLHelper.DeleteXmlNodeByXPath(xmlpath, "//config/page[@url='" + fn + "']/plugins/plugin[@id='" + pluginid + "' and @type='" + type + "']"); //删除模板包中的标签等 string path = context.Server.MapPath("~/template/" + mysite.folder + "/" + fn + ".html"); string htmlstr = Common.FileHelper.ReadFile(path, "utf-8"); string tempstr = "placeholder-" + DateTime.Now.ToString("fff"); htmlstr = htmlstr.Replace("{$plugin." + type + "." + pluginid + "}", "<!--" + tempstr + "-->"); htmlstr = htmlstr.Replace("edit=\"" + type + "." + pluginid + "\"", "edit=\"" + tempstr + "\""); Common.FileHelper.WriteFile(path, htmlstr, "utf-8"); context.Response.Write("ok"); } catch (Exception ex) { context.Response.Write(ex.Message); } }
private void PluginConfig(HttpContext context) { string str = "<![CDATA[\n" + context.Request.Form["datastr"] + "]]>\n"; string pluginid = context.Request.Form["id"]; string type = context.Request.Form["type"]; string parasstr = "<![CDATA[" + context.Request.Form["paras"] + "]]>"; string fn = context.Request.Form["fn"]; Dukey.Model.WebConfig mysite = BLL.WebConfig.instance.GetModelByCache();//网站配置信息 if (!File.Exists(context.Server.MapPath("~/template/" + mysite.folder + "/theme.xml"))) { using (StreamWriter sw = File.CreateText(context.Server.MapPath("~/template/" + mysite.folder + "/theme.xml"))) { sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sw.WriteLine("<config>"); sw.WriteLine(string.Format("<page url=\"{0}\">", fn)); sw.WriteLine("<plugins>"); sw.WriteLine(string.Format("<plugin id=\"{0}\" type=\"{1}\">", pluginid, type)); sw.WriteLine(string.Format("<paras>{0}</paras>", parasstr)); sw.WriteLine("<content>"); sw.WriteLine(str); sw.WriteLine("</content>"); sw.WriteLine("</plugin>"); sw.WriteLine("</plugins>"); sw.WriteLine("</page>"); sw.WriteLine("</config>"); } } else { string path = context.Server.MapPath("~/template/" + mysite.folder + "/theme.xml"); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); //加载XML文档 XmlNode root = xmlDoc.SelectSingleNode("//config"); if (root == null) { root = xmlDoc.CreateNode("element", "config", ""); xmlDoc.AppendChild(root); } XmlNode page = xmlDoc.SelectSingleNode("//config/page[@url='" + fn + "']"); if (page == null) { page = xmlDoc.CreateNode("element", "page", ""); XmlAttribute xmlAttribute = xmlDoc.CreateAttribute("url"); xmlAttribute.Value = fn; page.Attributes.Append(xmlAttribute); root.AppendChild(page); } XmlNode plugins = xmlDoc.SelectSingleNode("//config/page[@url='" + fn + "']/plugins"); if (plugins == null) { plugins = xmlDoc.CreateNode("element", "plugins", ""); page.AppendChild(plugins); } XmlNode plugin = xmlDoc.SelectSingleNode("//config/page[@url='" + fn + "']/plugins/plugin[@id='" + pluginid + "' and @type='" + type + "']"); if (plugin == null) { plugin = xmlDoc.CreateNode("element", "plugin", ""); XmlAttribute att1 = xmlDoc.CreateAttribute("id"); att1.Value = pluginid; XmlAttribute att2 = xmlDoc.CreateAttribute("type"); att2.Value = type; plugin.Attributes.Append(att1); plugin.Attributes.Append(att2); plugins.AppendChild(plugin); } XmlNode paras = xmlDoc.SelectSingleNode("//config/page[@url='" + fn + "']/plugins/plugin[@id='" + pluginid + "' and @type='" + type + "']/paras"); if (paras == null) { paras = xmlDoc.CreateNode("element", "paras", ""); plugin.AppendChild(paras); } paras.InnerXml = parasstr; XmlNode content = xmlDoc.SelectSingleNode("//config/page[@url='" + fn + "']/plugins/plugin[@id='" + pluginid + "' and @type='" + type + "']/content"); if (content == null) { content = xmlDoc.CreateNode("element", "content", ""); plugin.AppendChild(content); } content.InnerXml = str; xmlDoc.Save(path); context.Response.Write("ok"); } catch (Exception ex) { context.Response.Write(ex.Message); } } }