/// <summary> /// 加载ModulePref信息 /// </summary> /// <param name="filename">文件名</param> /// <returns></returns> public static ModulePref LoadModulePref(string filename) { XmlDocument xmlfile = LoadXmlFile(filename); if (xmlfile == null) { return(null); } XmlNode xmlnode = xmlfile.SelectSingleNode("/Module/ModulePrefs"); if (xmlnode == null) { return(null); } ModulePref module = new ModulePref(); module.Author = xmlnode.Attributes["author"] == null ? "" : xmlnode.Attributes["author"].Value; module.AuthorAffiliation = xmlnode.Attributes["author_affiliation"] == null ? "" : xmlnode.Attributes["author_affiliation"].Value; module.AuthorEmail = xmlnode.Attributes["author_email"] == null ? "" : xmlnode.Attributes["author_email"].Value; module.AuthorLocation = xmlnode.Attributes["author_location"] == null ? "" : xmlnode.Attributes["author_location"].Value; module.Category = xmlnode.Attributes["category"] == null ? "" : xmlnode.Attributes["category"].Value; module.Category2 = xmlnode.Attributes["category2"] == null ? "" : xmlnode.Attributes["category2"].Value; module.Description = xmlnode.Attributes["description"] == null ? "" : xmlnode.Attributes["description"].Value; module.RenderInline = xmlnode.Attributes["render_inline"] == null ? "" : xmlnode.Attributes["render_inline"].Value; module.Screenshot = xmlnode.Attributes["screenshot"] == null ? "" : xmlnode.Attributes["screenshot"].Value; module.Thumbnail = xmlnode.Attributes["thumbnail"] == null ? "" : xmlnode.Attributes["thumbnail"].Value; module.Title = xmlnode.Attributes["title"] == null ? "" : xmlnode.Attributes["title"].Value; module.TitleUrl = xmlnode.Attributes["title_url"] == null ? "" : xmlnode.Attributes["title_url"].Value; module.DirectoryTitle = xmlnode.Attributes["directory_title"] == null ? "" : xmlnode.Attributes["directory_title"].Value; module.Height = xmlnode.Attributes["height "] == null ? 200 : Utils.StrToInt(xmlnode.Attributes["height"].Value, 200); module.Width = xmlnode.Attributes["width"] == null ? 320 : Utils.StrToInt(xmlnode.Attributes["width"].Value, 320); module.Scaling = xmlnode.Attributes["scaling"] == null ? true : Utils.StrToBool(xmlnode.Attributes["scaling"].Value, true); module.Scrolling = xmlnode.Attributes["scrolling"] == null ? false : Utils.StrToBool(xmlnode.Attributes["scrolling"].Value, false); module.Singleton = xmlnode.Attributes["singleton"] == null ? true : Utils.StrToBool(xmlnode.Attributes["singleton"].Value, true); module.AuthorPhoto = xmlnode.Attributes["author_photo"] == null ? "" : xmlnode.Attributes["author_photo"].Value; module.AuthorAboutMe = xmlnode.Attributes["author_aboutme"] == null ? "" : xmlnode.Attributes["author_aboutme"].Value; module.AuthorLink = xmlnode.Attributes["author_link"] == null ? "" : xmlnode.Attributes["author_link"].Value; module.AuthorQuote = xmlnode.Attributes["author_quote"] == null ? "" : xmlnode.Attributes["author_quote"].Value; module.Controller = xmlnode.Attributes["controller"] == null ? "" : xmlnode.Attributes["controller"].Value; XmlNodeList xnl = xmlfile.SelectNodes("/Module/ModulePrefs/Require"); if (xnl.Count > 0) { module.Requires = new Discuz.Common.Generic.List <ModuleRequire>(); foreach (XmlNode xn in xnl) { module.Requires.Add(new ModuleRequire(xn.Attributes["feature"] == null ? "" : xn.Attributes["feature"].Value)); } } return(module); }
public ifr() { HttpContext.Current.Response.ContentType = "text/html"; // if (ForumUtils.IsCrossSitePost(DNTRequest.GetUrlReferrer(), DNTRequest.GetHost())) // return; // if (userid < 1) // return; string url = DNTRequest.GetQueryString("url"); int mid = DNTRequest.GetQueryInt("mid", 0); int uid = DNTRequest.GetQueryInt("uid", 0); ModuleInfo moduleinfo = Spaces.GetModuleById(mid, uid); if (moduleinfo == null) { return; } if (url != moduleinfo.ModuleUrl) { return; } UserPrefsSaved ups = new UserPrefsSaved(moduleinfo.UserPref); string path = BaseConfigs.GetForumPath + "space/modules/" + url; string modulefilepath = Utils.GetMapPath(path); ModulePref mp = ModuleXmlHelper.LoadModulePref(modulefilepath); ModuleContent mc = ModuleXmlHelper.LoadContent(modulefilepath); #if NET1 UserPrefCollection upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath); #else UserPrefCollection <UserPref> upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath); #endif StringBuilder registScript = new StringBuilder("<script type=\"text/javascript\">"); foreach (UserPref up in upc) { string userprefvalue = ups.GetValueByName(up.Name); userprefvalue = userprefvalue == string.Empty ? up.DefaultValue : userprefvalue; registScript.AppendFormat(PREF_SCRIPT_FORMAT, mid, up.Name, userprefvalue); } registScript.Append(ModuleXmlHelper.GetModuleRequireScript(mp, mc.Type == ModuleContentType.HtmlInline)); registScript.Append("</script>"); string html = string.Format(IFRAME_HTML, registScript.ToString(), mc.ContentHtml, BaseConfigs.GetForumPath); html = html.Replace("__MODULE_ID__", mid.ToString()).Replace("_IG_", "_DS_"); HttpContext.Current.Response.Write(html); HttpContext.Current.Response.End(); }
public static string GetModuleRequireScript(ModulePref modulePref, bool isInline) { Hashtable ht = new Hashtable(); ht.Add(FeatureType.SetTitle, SCRIPT_NO_SET_TITLE); ht.Add(FeatureType.Dynamic_Height, SCRIPT_NO_DYNAMIC_HEIGHT); if (modulePref.Requires != null) { foreach (ModuleRequire mr in modulePref.Requires) { string script = string.Empty; switch (mr.Feature) { case FeatureType.Analytics: break; case FeatureType.Drag: break; case FeatureType.Dynamic_Height: script = isInline ? SCRIPT_DYNAMIC_HEIGHT_INLINE : SCRIPT_DYNAMIC_HEIGHT; break; case FeatureType.Flash: break; case FeatureType.Grid: break; case FeatureType.MiniMessage: break; case FeatureType.SetPrefs: break; case FeatureType.SetTitle: if (isInline) { script = SCRIPT_SET_TITLE_INLINE; } else { script = SCRIPT_SET_TITLE; } break; case FeatureType.Tabs: break; } ht[mr.Feature] = script; } } StringBuilder sb = new StringBuilder(); foreach (DictionaryEntry de in ht) { sb.Append(de.Value.ToString()); } return(sb.ToString()); }
public static string GetModuleRequireScript(ModulePref modulePref, bool isInline) { Hashtable ht = new Hashtable(); ht.Add(FeatureType.SetTitle, SCRIPT_NO_SET_TITLE); ht.Add(FeatureType.Dynamic_Height, SCRIPT_NO_DYNAMIC_HEIGHT); if (modulePref.Requires != null) { foreach (ModuleRequire mr in modulePref.Requires) { string script = string.Empty; switch (mr.Feature) { case FeatureType.Analytics: break; case FeatureType.Drag: break; case FeatureType.Dynamic_Height: script = isInline ? SCRIPT_DYNAMIC_HEIGHT_INLINE : SCRIPT_DYNAMIC_HEIGHT; break; case FeatureType.Flash: break; case FeatureType.Grid: break; case FeatureType.MiniMessage: break; case FeatureType.SetPrefs: break; case FeatureType.SetTitle: if (isInline) script = SCRIPT_SET_TITLE_INLINE; else script = SCRIPT_SET_TITLE; break; case FeatureType.Tabs: break; } ht[mr.Feature] = script; } } StringBuilder sb = new StringBuilder(); foreach (DictionaryEntry de in ht) { sb.Append(de.Value.ToString()); } return sb.ToString(); }
/// <summary> /// 加载ModulePref信息 /// </summary> /// <param name="filename">文件名</param> /// <returns></returns> public static ModulePref LoadModulePref(string filename) { XmlDocument xmlfile = LoadXmlFile(filename); if (xmlfile == null) return null; XmlNode xmlnode = xmlfile.SelectSingleNode("/Module/ModulePrefs"); if (xmlnode == null) return null; ModulePref module = new ModulePref(); module.Author = xmlnode.Attributes["author"] == null ? "" : xmlnode.Attributes["author"].Value; module.AuthorAffiliation = xmlnode.Attributes["author_affiliation"] == null ? "" : xmlnode.Attributes["author_affiliation"].Value; module.AuthorEmail = xmlnode.Attributes["author_email"] == null ? "" : xmlnode.Attributes["author_email"].Value; module.AuthorLocation = xmlnode.Attributes["author_location"] == null ? "" : xmlnode.Attributes["author_location"].Value; module.Category = xmlnode.Attributes["category"]== null ? "" : xmlnode.Attributes["category"].Value; module.Category2 = xmlnode.Attributes["category2"] == null ? "" : xmlnode.Attributes["category2"].Value; module.Description = xmlnode.Attributes["description"] == null ? "" : xmlnode.Attributes["description"].Value; module.RenderInline = xmlnode.Attributes["render_inline"] == null ? "" : xmlnode.Attributes["render_inline"].Value; module.Screenshot = xmlnode.Attributes["screenshot"] == null ? "" : xmlnode.Attributes["screenshot"].Value; module.Thumbnail = xmlnode.Attributes["thumbnail"] == null ? "" : xmlnode.Attributes["thumbnail"].Value; module.Title = xmlnode.Attributes["title"] == null ? "" : xmlnode.Attributes["title"].Value; module.TitleUrl = xmlnode.Attributes["title_url"] == null ? "" : xmlnode.Attributes["title_url"].Value; module.DirectoryTitle = xmlnode.Attributes["directory_title"] == null ? "" : xmlnode.Attributes["directory_title"].Value; module.Height = xmlnode.Attributes["height "] == null ? 200 : Utils.StrToInt(xmlnode.Attributes["height"].Value, 200); module.Width = xmlnode.Attributes["width"] == null ? 320 : Utils.StrToInt(xmlnode.Attributes["width"].Value, 320); module.Scaling = xmlnode.Attributes["scaling"] == null ? true : Utils.StrToBool(xmlnode.Attributes["scaling"].Value, true); module.Scrolling = xmlnode.Attributes["scrolling"] == null ? false : Utils.StrToBool(xmlnode.Attributes["scrolling"].Value, false); module.Singleton = xmlnode.Attributes["singleton"] == null ? true : Utils.StrToBool(xmlnode.Attributes["singleton"].Value, true); module.AuthorPhoto = xmlnode.Attributes["author_photo"] == null ? "" : xmlnode.Attributes["author_photo"].Value; module.AuthorAboutMe = xmlnode.Attributes["author_aboutme"] == null ? "" : xmlnode.Attributes["author_aboutme"].Value; module.AuthorLink = xmlnode.Attributes["author_link"] == null ? "" : xmlnode.Attributes["author_link"].Value; module.AuthorQuote = xmlnode.Attributes["author_quote"] == null ? "" : xmlnode.Attributes["author_quote"].Value; module.Controller = xmlnode.Attributes["controller"] == null ? "" : xmlnode.Attributes["controller"].Value; XmlNodeList xnl = xmlfile.SelectNodes("/Module/ModulePrefs/Require"); if (xnl.Count > 0) { module.Requires = new Discuz.Common.Generic.List<ModuleRequire>(); foreach (XmlNode xn in xnl) { module.Requires.Add(new ModuleRequire(xn.Attributes["feature"] == null ? "" : xn.Attributes["feature"].Value)); } } return module; }
private void BindGridData() { DataTable dt = new DataTable(); dt.Columns.Add("moduledefname"); dt.Columns.Add("moduledefcatelog"); dt.Columns.Add("moduledeftype"); dt.Columns.Add("hadindb"); dt.Columns.Add("url"); dt.Columns.Add("modulestatus"); dt.Columns.Add("moduledefop"); DNTCache.GetCacheService().RemoveObject("/Space/ModuleDefList"); XmlDocument xml = new XmlDocument(); try { xml.Load(listfilename); } catch { base.RegisterStartupScript("", "<script>alert('缺少对列表文件的访问权限或者列表文件不存在');window.location.href='space_moduledefmanage.aspx';</script>"); return; } XmlNodeList xnl = xml.GetElementsByTagName("Gadget"); //枚举xml文件列表 string[] files = Directory.GetFiles(moduledefpath, "*.xml"); foreach (string file in files) { DataRow dr = dt.NewRow(); string moduleurl = Path.GetFileName(file); XmlNode node = HadInList(moduleurl, xnl); dr["url"] = moduleurl; //<a href="space_editmoduledef.aspx?url=<%#DataBinder.Eval(Container, "DataItem.url")%>">编辑</a> // <a runat="server" id="enablemoduledef" href="###" onclick="document.getElementById('url<%#DataBinder.Eval(Container, "DataItem.url").ToString()%>').checked=true;submitDeleteApply();">置为无效</a> if (node != null) { //已经在列表使用中的模块 dr["moduledefop"] = string.Format("<a href=\"space_editmoduledef.aspx?url={0}\">编辑</a> <a href=\"#\" onclick=\"document.getElementById('url{0}').checked=true;submitDeleteApply();\">置为无效</a>", moduleurl); if (moduleurl.StartsWith("builtin_")) { //内置模块 ModuleDefInfo mdi = SpaceProvider.GetModuleDefInfoByUrl(moduleurl); try { Activator.CreateInstance(Type.GetType(mdi.BussinessController, false, true)); dr["modulestatus"] = "<img title='模块可以正常工作' alt='模块可以正常工作' src='../images/state2.gif' />"; } catch { //本模块逻辑控制反射失败 dr["modulestatus"] = "<img title='模块当前无法正常工作' alt='模块当前无法正常工作' src='../images/state1.gif' />"; dr["moduledefop"] = string.Format("<a href=\"?mod=refresh&url={0}\">刷新</a> <a href=\"#\" onclick=\"document.getElementById('url{0}').checked=true;submitDeleteApply();\">置为无效</a>", moduleurl); } dr["moduledeftype"] = "内置模块"; } else { //外置模块 dr["modulestatus"] = "<img title='模块可以正常工作' alt='模块可以正常工作' src='../images/state2.gif' />"; dr["moduledeftype"] = "外置模块"; } dr["moduledefname"] = string.Format("{0}({1})", node.Attributes["name"].Value, node.Attributes["url"].Value); dr["moduledefcatelog"] = node.ParentNode.Attributes["name"].Value; dt.Rows.Add(dr); } else { //未被使用的模块 dr["modulestatus"] = "<img title='尚未启用的模块' alt='尚未启用的模块' src='../images/state3.gif' />"; ModulePref mp = ModuleXmlHelper.LoadModulePref(file); if (moduleurl.StartsWith("builtin_")) { dr["moduledeftype"] = "内置模块"; } else { dr["moduledeftype"] = "外置模块"; } if (mp != null) { dr["moduledefname"] = string.Format("{0}({1})", mp.Title.StartsWith("_") ? moduleurl : mp.Title, moduleurl); dr["moduledefcatelog"] = mp.Category == string.Empty ? "其他" : mp.Category; dr["moduledefop"] = string.Format(" <a runat=\"server\" href=\"###\" onclick=\"document.getElementById('url{0}').checked=true;submitAddApply();\">置为有效</a>", moduleurl); dt.Rows.Add(dr); } } } this.DataGrid1.TableHeaderName = "现有模块"; this.DataGrid1.AllowPaging = false; this.DataGrid1.AllowCustomPaging = false; this.DataGrid1.DataKeyField = "url"; this.DataGrid1.DataSource = dt; this.DataGrid1.DataBind(); }
protected void AddApply_Click(object sender, EventArgs e) { if (this.CheckCookie()) { string[] urllist = DNTRequest.GetString("url").Split(','); bool hasemptyvalue = false; XmlDocument xml = new XmlDocument(); try { xml.Load(listfilename); } catch { base.RegisterStartupScript("", "<script>alert('缺少对列表文件的访问权限或者列表文件不存在');window.location.href='space_moduledefmanage.aspx';</script>"); return; } XmlNodeList xnlGadgets = xml.GetElementsByTagName("Gadget"); BindGridData(); foreach (string url in urllist) { foreach (DataGridItem dgi in DataGrid1.Items) { if (dgi.ItemType == ListItemType.AlternatingItem || dgi.ItemType == ListItemType.Item) { if (url != DataGrid1.DataKeys[dgi.ItemIndex].ToString() || HadInList(url, xnlGadgets) != null) { continue; } string category = DataGrid1.Items[dgi.ItemIndex].Cells[3].Text; string modulename = DataGrid1.Items[dgi.ItemIndex].Cells[2].Text.Substring(0, DataGrid1.Items[dgi.ItemIndex].Cells[2].Text.LastIndexOf("("));; //DataGrid1.GetControlValue(dgi.ItemIndex, "moduledefname"); if (category == string.Empty || modulename == string.Empty) { hasemptyvalue = true; continue; } //分类节点如果不存在则创建 XmlNodeList xnl = xml.GetElementsByTagName("Category"); XmlNode categorynode = GetCategoryNode(category, xnl); if (categorynode == null) { categorynode = xml.CreateNode(XmlNodeType.Element, "Category", ""); XmlAttribute xa = xml.CreateAttribute("name"); xa.Value = category; categorynode.Attributes.Append(xa); xml.DocumentElement.AppendChild(categorynode); } //添加至列表文件 XmlNode node = xml.CreateNode(XmlNodeType.Element, "Gadget", ""); XmlAttribute xanode = xml.CreateAttribute("name"); xanode.Value = modulename; node.Attributes.Append(xanode); xanode = xml.CreateAttribute("url"); xanode.Value = url; node.Attributes.Append(xanode); categorynode.AppendChild(node); try { xml.Save(listfilename); } catch { base.RegisterStartupScript("", "<script>alert('缺少对列表文件的访问权限或者列表文件不存在');window.location.href='space_moduledefmanage.aspx';</script>"); return; } if (url.StartsWith("builtin_")) { //内置模块添加至数据库 ModulePref mp = ModuleXmlHelper.LoadModulePref(Utils.GetMapPath(BaseConfigs.GetForumPath + "space/modules/" + url)); if (mp != null) { ModuleDefInfo mdi = new ModuleDefInfo(); mdi.ModuleName = modulename; mdi.CacheTime = 0; mdi.BussinessController = mp.Controller; mdi.ConfigFile = url; SpaceProvider.AddModuleDefInfo(mdi); } } } } } if (hasemptyvalue) { base.RegisterStartupScript("", "<script>alert('模块名称或分类名称为空的模块未被添加');window.location.href='space_moduledefmanage.aspx';</script>"); } base.RegisterStartupScript("", "<script>window.location.href='space_moduledefmanage.aspx';</script>"); BindGridData(); } }