//查找匹配的URL private string get_url_rewrite(int channel_id, string call_index, int id) { if (channel_id == 0) { return(string.Empty); } string querystring = id.ToString(); string channel_name = new BLL.channel().GetChannelName(channel_id); if (string.IsNullOrEmpty(channel_name)) { return(string.Empty); } if (!string.IsNullOrEmpty(call_index)) { querystring = call_index; } BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(channel_name, "detail"); if (model != null) { return(linkurl(model.name, querystring)); } return(string.Empty); }
private bool DoAdd() { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = new Model.url_rewrite(); model.name = txtName.Text.Trim(); model.type = ddlType.SelectedValue; model.channel = ddlChannel.SelectedValue; model.page = txtPage.Text.Trim(); model.inherit = txtInherit.Text.Trim(); model.templet = txtTemplet.Text.Trim(); //添加URL重写节点 List <Model.url_rewrite_item> items = new List <Model.url_rewrite_item>(); string[] itemPathArr = Request.Form.GetValues("itemPath"); string[] itemPatternArr = Request.Form.GetValues("itemPattern"); string[] itemQuerystringArr = Request.Form.GetValues("itemQuerystring"); if (itemPathArr != null && itemPatternArr != null && itemQuerystringArr != null) { for (int i = 0; i < itemPathArr.Length; i++) { items.Add(new Model.url_rewrite_item { path = itemPathArr[i], pattern = itemPatternArr[i], querystring = itemQuerystringArr[i] }); } } model.url_rewrite_items = items; if (bll.Add(model)) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加URL配置信息:" + model.name); //记录日志 return(true); } return(false); }
/// <summary> /// 生成全部模板 /// </summary> private void MarkTemplates(string buildPath, string skinName) { //取得ASP目录下的所有文件 string fullDirPath = Utils.GetMapPath(string.Format("{0}aspx/{1}/", siteConfig.webpath, buildPath)); DirectoryInfo dirFile = new DirectoryInfo(fullDirPath); //获得URL配置列表 BLL.url_rewrite bll = new BLL.url_rewrite(); List <Model.url_rewrite> ls = bll.GetList(""); //删除不属于URL映射表里的文件,防止冗余 if (Directory.Exists(fullDirPath)) { foreach (FileInfo file in dirFile.GetFiles()) { //检查文件 Model.url_rewrite modelt = ls.Find(p => p.page.ToLower() == file.Name.ToLower()); if (modelt == null) { file.Delete(); } } } //遍历URL配置列表 foreach (Model.url_rewrite modelt in ls) { //如果URL配置对应的模板文件存在则生成 string fullPath = Utils.GetMapPath(string.Format("{0}templates/{1}/{2}", siteConfig.webpath, skinName, modelt.templet)); if (File.Exists(fullPath)) { PageTemplate.GetTemplate(siteConfig.webpath, "templates", skinName, modelt.templet, modelt.page, modelt.inherit, buildPath, 1); } } }
private bool DoAdd() { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = new Model.url_rewrite(); model.name = txtName.Text.Trim(); model.type = ddlType.SelectedValue; model.channel = ddlChannel.SelectedValue; model.page = txtPage.Text.Trim(); model.inherit = txtInherit.Text.Trim(); model.templet = txtTemplet.Text.Trim(); //添加URL重写节点 List<Model.url_rewrite_item> items = new List<Model.url_rewrite_item>(); string[] itemPathArr = Request.Form.GetValues("itemPath"); string[] itemPatternArr = Request.Form.GetValues("itemPattern"); string[] itemQuerystringArr = Request.Form.GetValues("itemQuerystring"); if (itemPathArr != null && itemPatternArr != null && itemQuerystringArr != null) { for (int i = 0; i < itemPathArr.Length; i++) { items.Add(new Model.url_rewrite_item { path = itemPathArr[i], pattern = itemPatternArr[i], querystring = itemQuerystringArr[i] }); } } model.url_rewrite_items = items; if (bll.Add(model)) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加URL配置信息:" + model.name); //记录日志 return true; } return false; }
/// <summary> /// 修改节点 /// </summary> public bool Edit(Model.url_rewrite model) { string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == model.name.ToLower()) { xe.Attributes["path"].Value = model.path; xe.Attributes["pattern"].Value = model.pattern; xe.Attributes["page"].Value = model.page; xe.Attributes["querystring"].Value = model.querystring; xe.Attributes["templet"].Value = model.templet; xe.Attributes["channel"].Value = model.channel.ToString(); xe.Attributes["type"].Value = model.type; xe.Attributes["inherit"].Value = model.inherit; doc.Save(filePath); return(true); } } } return(false); }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.url_rewrite GetInfo(string attrValue) { Model.url_rewrite model = new Model.url_rewrite(); string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower()) { model.name = xe.Attributes["name"].Value; model.path = xe.Attributes["path"].Value; model.pattern = xe.Attributes["pattern"].Value; model.page = xe.Attributes["page"].Value; model.querystring = xe.Attributes["querystring"].Value; model.templet = xe.Attributes["templet"].Value; model.channel = xe.Attributes["channel"].Value; model.type = xe.Attributes["type"].Value; model.inherit = xe.Attributes["inherit"].Value; return(model); } } } return(null); }
/// <summary> /// 增加节点 /// </summary> public bool Add(Model.url_rewrite model) { try { string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlElement xe = doc.CreateElement("rewrite"); xe.SetAttribute("name", model.name); xe.SetAttribute("path", model.path); xe.SetAttribute("pattern", model.pattern); xe.SetAttribute("page", model.page); xe.SetAttribute("querystring", model.querystring); xe.SetAttribute("templet", model.templet); xe.SetAttribute("channel", model.channel.ToString()); xe.SetAttribute("type", model.type); xe.SetAttribute("inherit", model.inherit); xn.AppendChild(xe); doc.Save(filePath); return(true); } catch { return(false); } }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.url_rewrite GetInfo(string attrValue) { Model.url_rewrite model = new Model.url_rewrite(); string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower()) { model.name = xe.Attributes["name"].Value; model.path = xe.Attributes["path"].Value; model.pattern = xe.Attributes["pattern"].Value; model.page = xe.Attributes["page"].Value; model.querystring = xe.Attributes["querystring"].Value; model.templet = xe.Attributes["templet"].Value; model.channel = xe.Attributes["channel"].Value; model.type = xe.Attributes["type"].Value; model.inherit = xe.Attributes["inherit"].Value; return model; } } } return null; }
//查找匹配的URL private string get_url_rewrite(string channel_id, int id) { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(channel_id, "detail"); if (model != null) { return(linkurl(model.name, id)); } return(""); }
private bool DoAdd() { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = new Model.url_rewrite(); model.name = txtName.Text.Trim(); model.type = ddlType.SelectedValue; model.channel = ddlChannel.SelectedValue; model.page = txtPage.Text.Trim(); if (!model.page.EndsWith(".aspx")) { model.page += ".aspx"; } model.cache = rblCache.SelectedValue; model.cachepath = txtCachePath.Text.Trim(); model.inherit = txtInherit.Text.Trim(); if (!model.inherit.StartsWith("DTcms.Web.UI.Page.")) { model.inherit = "DTcms.Web.UI.Page." + model.inherit; } model.templet = txtTemplet.Text.Trim(); if (!model.templet.EndsWith(".html")) { model.templet += ".html"; } if (!string.IsNullOrEmpty(txtPageSize.Text.Trim())) { model.pagesize = txtPageSize.Text.Trim(); } //添加URL重写节点 List <Model.url_rewrite_item> items = new List <Model.url_rewrite_item>(); string[] itemPathArr = Request.Form.GetValues("itemPath"); string[] itemPatternArr = Request.Form.GetValues("itemPattern"); string[] itemQuerystringArr = Request.Form.GetValues("itemQuerystring"); if (itemPathArr != null && itemPatternArr != null && itemQuerystringArr != null) { for (int i = 0; i < itemPathArr.Length; i++) { items.Add(new Model.url_rewrite_item { path = itemPathArr[i], pattern = itemPatternArr[i], querystring = itemQuerystringArr[i] }); } } model.url_rewrite_items = items; if (bll.Add(model)) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加URL配置信息:" + model.name); //记录日志 return(true); } return(false); }
/// <summary> /// 返回URL重写统一链接地址 /// </summary> public string linkurl(string _key, params object[] _params) { Hashtable ht = new BLL.url_rewrite().GetList(); //获得URL配置列表 Model.url_rewrite model = ht[_key] as Model.url_rewrite; //查找指定的URL配置节点 //如果不存在该节点则返回空字符串 if (model == null) { return(string.Empty); } return(linkurl(model, _params)); }
private bool DoAdd() { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = new Model.url_rewrite(); model.name = txtName.Text.Trim(); model.path = txtPath.Text.Trim(); model.pattern = txtPattern.Text.Trim(); model.page = txtPage.Text.Trim(); model.querystring = txtQueryString.Text.Trim(); model.templet = txtTemplet.Text.Trim(); model.channel = txtChannel.Text.Trim(); model.type = ddlType.SelectedValue; model.inherit = txtInherit.Text.Trim(); return bll.Add(model); }
private bool DoEdit(string _urlName) { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(_urlName); model.name = txtName.Text.Trim(); model.path = txtPath.Text.Trim(); model.pattern = txtPattern.Text.Trim(); model.page = txtPage.Text.Trim(); model.querystring = txtQueryString.Text.Trim(); model.templet = txtTemplet.Text.Trim(); model.channel = txtChannel.Text.Trim(); model.type = ddlType.SelectedValue; model.inherit = txtInherit.Text.Trim(); return(bll.Edit(model)); }
private void ShowInfo(string _urlName) { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(_urlName); txtName.Text = model.name; txtName.ReadOnly = true; txtPath.Text = model.path; txtPattern.Text = model.pattern; txtPage.Text = model.page; txtQueryString.Text = model.querystring; txtTemplet.Text = model.templet; txtChannel.Text = model.channel; ddlType.SelectedValue = model.type; txtInherit.Text = model.inherit; }
private void ShowInfo(string _urlName) { BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(_urlName); txtName.Text = model.name; txtName.ReadOnly = true; ddlType.SelectedValue = model.type; ddlChannel.SelectedValue = model.channel; txtPage.Text = model.page; txtInherit.Text = model.inherit; txtTemplet.Text = model.templet; //绑定URL配置列表 rptList.DataSource = model.url_rewrite_items; rptList.DataBind(); }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.url_rewrite GetInfo(string channel, string type) { Hashtable ht = GetList(); foreach (DictionaryEntry item in ht) { Model.url_rewrite model = item.Value as Model.url_rewrite; if (model != null) { if (model.channel == channel && model.type == type) { return(model); } } } return(null); }
/// <summary> /// 查找匹配的URL /// </summary> /// <param name="channel_id">频道ID</param> /// <param name="call_index">调用名</param> /// <param name="id">ID</param> /// <returns></returns> public string get_url_rewrite(int channel_id, string type, int id) { string channel_name = new BLL.site_channel().GetChannelName(channel_id); string querystring = id.ToString(); if (string.IsNullOrEmpty(channel_name)) { return(string.Empty); } BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(channel_name, type); if (model != null) { return(new BaseController().linkurl(model.name, querystring)); } return(string.Empty); }
/// <summary> /// 查找匹配的URL /// </summary> /// <param name="channel_id">频道ID</param> /// <param name="call_index">调用名</param> /// <param name="id">ID</param> /// <returns></returns> public string get_url_rewrite(string channel_name, string type, string call_index, int id) { string querystring = id.ToString(); if (string.IsNullOrEmpty(channel_name)) { return(string.Empty); } if (!string.IsNullOrEmpty(call_index)) { querystring = call_index; } BLL.url_rewrite bll = new BLL.url_rewrite(); Model.url_rewrite model = bll.GetInfo(channel_name, type); if (model != null) { return(new BaseController().linkurl(model.name, querystring)); } return(string.Empty); }
/// <summary> /// 返回URL重写统一链接地址 /// </summary> public string linkurl(string _key, params object[] _params) { Hashtable ht = new BLL.url_rewrite().GetList(); Model.url_rewrite model = ht[_key] as Model.url_rewrite; if (model == null) { return(""); } try { string _result = string.Empty; string _rewriteurl = string.Format(model.path, _params); switch (config.staticstatus) { case 1: //URL重写 _result = config.webpath + _rewriteurl; break; case 2: //全静态 _rewriteurl = _rewriteurl.Substring(0, _rewriteurl.LastIndexOf(".") + 1); _result = config.webpath + DTKeys.DIRECTORY_REWRITE_HTML + "/" + _rewriteurl + config.staticextension; break; default: //不开启 string _originalurl = model.page; if (!string.IsNullOrEmpty(model.querystring)) { _originalurl = model.page + "?" + Regex.Replace(_rewriteurl, model.pattern, model.querystring, RegexOptions.None | RegexOptions.IgnoreCase); } _result = config.webpath + _originalurl; break; } return(_result); } catch { return(""); } }
/// <summary> /// 生成全部範本 /// </summary> private void MarkTemplates(string skinName) { //取得ASP目錄下的所有檔 DirectoryInfo dirFile = new DirectoryInfo(Utils.GetMapPath(siteConfig.webpath + "aspx/")); //獲得URL映射列表 BLL.url_rewrite bll = new BLL.url_rewrite(); List <Model.url_rewrite> ls = bll.GetList(""); //刪除不屬於URL映射表裡的檔,防止冗餘 foreach (FileInfo file in dirFile.GetFiles()) { //檢查檔 Model.url_rewrite model2 = ls.Find(p => p.page.ToLower() == file.Name.ToLower()); if (model2 == null) { file.Delete(); } } //遍歷網站目錄的templates資料夾下的範本檔 DirectoryInfo dirInfo = new DirectoryInfo(Utils.GetMapPath(siteConfig.webpath + @"templates/" + skinName)); foreach (FileInfo file in dirInfo.GetFiles()) { if (!file.Name.StartsWith("_") && file.Name.EndsWith(".html")) { //查找相對應的繼承類名 foreach (Model.url_rewrite model in ls) { if (file.Name.ToLower() == model.templet && !string.IsNullOrEmpty(model.inherit)) { //檢查頻道ID int channelId = Utils.StrToInt(model.channel, 0); //生成範本檔 PageTemplate.GetTemplate(siteConfig.webpath, "templates", skinName, model.templet, model.page, model.inherit, channelId, 1); } } } } }
/// <summary> /// 生成全部模板 /// </summary> private void MarkTemplates(string skinName) { //取得ASP目录下的所有文件 DirectoryInfo dirFile = new DirectoryInfo(Utils.GetMapPath(siteConfig.webpath + "aspx/")); //获得URL映射列表 BLL.url_rewrite bll = new BLL.url_rewrite(); List <Model.url_rewrite> ls = bll.GetList(""); //删除不属于URL映射表里的文件,防止冗余 foreach (FileInfo file in dirFile.GetFiles()) { //检查文件 Model.url_rewrite model2 = ls.Find(p => p.page.ToLower() == file.Name.ToLower()); if (model2 == null) { file.Delete(); } } //遍历站点目录的templates文件夹下的模板文件 DirectoryInfo dirInfo = new DirectoryInfo(Utils.GetMapPath(siteConfig.webpath + @"templates/" + skinName)); foreach (FileInfo file in dirInfo.GetFiles()) { if (!file.Name.StartsWith("_") && file.Name.EndsWith(".html")) { //查找相对应的继承类名 foreach (Model.url_rewrite model in ls) { if (file.Name.ToLower() == model.templet && !string.IsNullOrEmpty(model.inherit)) { //检查频道ID int channelId = Utils.StrToInt(model.channel, 0); //生成模板文件 PageTemplate.GetTemplate(siteConfig.webpath, "templates", skinName, model.templet, model.page, model.inherit, channelId, 1); } } } } }
private bool DoAdd() { Model.channel model = new Model.channel(); BLL.channel bll = new BLL.channel(); model.category_id = Utils.StrToInt(ddlCategoryId.SelectedValue, 0); model.name = txtName.Text.Trim(); model.title = txtTitle.Text.Trim(); if (cbIsAlbums.Checked == true) { model.is_albums = 1; } if (cbIsAttach.Checked == true) { model.is_attach = 1; } if (cbIsGroupPrice.Checked == true) { model.is_group_price = 1; } model.page_size = Utils.StrToInt(txtPageSize.Text.Trim(), 10); model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); //添加频道扩展字段 List <Model.channel_field> ls = new List <Model.channel_field>(); for (int i = 0; i < cblAttributeField.Items.Count; i++) { if (cblAttributeField.Items[i].Selected) { ls.Add(new Model.channel_field { field_id = Utils.StrToInt(cblAttributeField.Items[i].Value, 0) }); } } model.channel_fields = ls; if (bll.Add(model) < 1) { return(false); } #region 保存URL配置 BLL.url_rewrite urlBll = new BLL.url_rewrite(); urlBll.Remove("channel", model.name); //先删除 string[] itemTypeArr = Request.Form.GetValues("item_type"); string[] itemNameArr = Request.Form.GetValues("item_name"); string[] itemPageArr = Request.Form.GetValues("item_page"); string[] itemTempletArr = Request.Form.GetValues("item_templet"); string[] itemRewriteArr = Request.Form.GetValues("item_rewrite"); if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemRewriteArr != null) { if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length) && (itemTempletArr.Length == itemRewriteArr.Length)) { for (int i = 0; i < itemTypeArr.Length; i++) { Model.url_rewrite urlModel = new Model.url_rewrite(); urlModel.name = itemNameArr[i].Trim(); urlModel.type = itemTypeArr[i].Trim(); urlModel.page = itemPageArr[i].Trim(); urlModel.inherit = GetInherit(urlModel.type); urlModel.templet = itemTempletArr[i].Trim(); urlModel.channel = model.name; List <Model.url_rewrite_item> itemLs = new List <Model.url_rewrite_item>(); string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串 for (int j = 0; j < urlRewriteArr.Length; j++) { string[] urlItemArr = urlRewriteArr[j].Split(','); if (urlItemArr.Length == 3) { itemLs.Add(new Model.url_rewrite_item { path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2] }); } } urlModel.url_rewrite_items = itemLs; urlBll.Add(urlModel); } } } #endregion AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加频道" + model.title); //记录日志 return(true); }
/// <summary> /// 返回URL重写统一链接地址(2017-08-14) /// </summary> public string linkurl(Model.url_rewrite model, params object[] _params) { string requestDomain = System.Web.HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号 string requestPath = System.Web.HttpContext.Current.Request.RawUrl.ToLower(); //当前的URL地址 string linkStartString = GetLinkStartString(requestPath, requestDomain); //链接前缀 //如果URL字典表达式不需要重写则直接返回 if (model.url_rewrite_items.Count == 0) { //检查网站重写状态 if (config.staticstatus > 0) { if (_params.Length > 0) { return(linkStartString + GetUrlExtension(model.page, config.staticextension) + string.Format("{0}", _params)); } else { return(linkStartString + GetUrlExtension(model.page, config.staticextension)); } } else { if (_params.Length > 0) { return(linkStartString + model.page + string.Format("{0}", _params)); } else { return(linkStartString + model.page); } } } if (model.url_rewrite_items.Count == 1 && _params.Length > 0) { Model.url_rewrite_item item = model.url_rewrite_items[0]; if (string.IsNullOrEmpty(item.querystring)) { //检查网站重写状态 if (config.staticstatus > 0) { return(linkStartString + GetUrlExtension(item.path, config.staticextension) + string.Format("{0}", _params)); } else { return(linkStartString + item.path + string.Format("{0}", _params)); } } } //否则检查该URL配置节点下的子节点 foreach (Model.url_rewrite_item item in model.url_rewrite_items) { //如果参数个数匹配 if (IsUrlMatch(item, _params)) { //检查网站重写状态 if (config.staticstatus > 0) { return(linkStartString + string.Format(GetUrlExtension(item.path, config.staticextension), _params)); } else { string queryString = Regex.Replace(string.Format(item.path, _params), item.pattern, item.querystring, RegexOptions.None | RegexOptions.IgnoreCase); if (queryString.Length > 0) { queryString = "?" + queryString; } return(linkStartString + model.page + queryString); } } } return(string.Empty); }
private bool DoEdit(int _id) { BLL.channel bll = new BLL.channel(); Model.channel model = bll.GetModel(_id); string old_name = model.name; model.site_id = Utils.StrToInt(ddlSiteId.SelectedValue, 0); model.name = txtName.Text.Trim(); model.title = txtTitle.Text.Trim(); model.is_albums = 0; model.is_attach = 0; model.is_spec = 0; if (cbIsAlbums.Checked == true) { model.is_albums = 1; } if (cbIsAttach.Checked == true) { model.is_attach = 1; } if (cbIsSpec.Checked == true) { model.is_spec = 1; } model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); //添加频道扩展字段 List<Model.channel_field> ls = new List<Model.channel_field>(); for (int i = 0; i < cblAttributeField.Items.Count; i++) { if (cblAttributeField.Items[i].Selected) { string[] fieldIdArr = cblAttributeField.Items[i].Value.Split(','); //分解出ID值 ls.Add(new Model.channel_field { channel_id = model.id, field_id = Utils.StrToInt(fieldIdArr[1], 0) }); } } model.channel_fields = ls; if (!bll.Update(model)) { return false; } #region 保存URL配置 BLL.url_rewrite urlBll = new BLL.url_rewrite(); urlBll.Remove("channel", old_name); //先删除旧的 string[] itemTypeArr = Request.Form.GetValues("item_type"); string[] itemNameArr = Request.Form.GetValues("item_name"); string[] itemPageArr = Request.Form.GetValues("item_page"); string[] itemTempletArr = Request.Form.GetValues("item_templet"); string[] itemPageSizeArr = Request.Form.GetValues("item_pagesize"); string[] itemRewriteArr = Request.Form.GetValues("item_rewrite"); if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemPageSizeArr != null && itemRewriteArr != null) { if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length) && (itemTempletArr.Length == itemPageSizeArr.Length) && (itemPageSizeArr.Length == itemRewriteArr.Length)) { for (int i = 0; i < itemTypeArr.Length; i++) { Model.url_rewrite urlModel = new Model.url_rewrite(); urlModel.name = itemNameArr[i].Trim(); urlModel.type = itemTypeArr[i].Trim(); urlModel.page = itemPageArr[i].Trim(); urlModel.inherit = GetInherit(urlModel.type); urlModel.templet = itemTempletArr[i].Trim(); if (Utils.StrToInt(itemPageSizeArr[i].Trim(), 0) > 0) { urlModel.pagesize = itemPageSizeArr[i].Trim(); } urlModel.channel = model.name; List<Model.url_rewrite_item> itemLs = new List<Model.url_rewrite_item>(); string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串 for (int j = 0; j < urlRewriteArr.Length; j++) { string[] urlItemArr = urlRewriteArr[j].Split(','); if (urlItemArr.Length == 3) { itemLs.Add(new Model.url_rewrite_item { path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2] }); } } urlModel.url_rewrite_items = itemLs; urlBll.Add(urlModel); } } } #endregion AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改频道" + model.title); //记录日志 return true; }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.url_rewrite GetInfo(string attrValue) { Model.url_rewrite model = new Model.url_rewrite(); string filePath = Utils.GetXmlMapPath(MXKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower()) { if (xe.Attributes["name"] != null) model.name = xe.Attributes["name"].Value; if (xe.Attributes["type"] != null) model.type = xe.Attributes["type"].Value; if (xe.Attributes["page"] != null) model.page = xe.Attributes["page"].Value; if (xe.Attributes["inherit"] != null) model.inherit = xe.Attributes["inherit"].Value; if (xe.Attributes["templet"] != null) model.templet = xe.Attributes["templet"].Value; if (xe.Attributes["channel"] != null) model.channel = xe.Attributes["channel"].Value; //再次遍历子节点 List<Model.url_rewrite_item> lsItems = new List<Model.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.url_rewrite_item item = new Model.url_rewrite_item(); if (xe1.Attributes["path"] != null) item.path = xe1.Attributes["path"].Value; if (xe1.Attributes["pattern"] != null) item.pattern = xe1.Attributes["pattern"].Value; if (xe1.Attributes["querystring"] != null) item.querystring = xe1.Attributes["querystring"].Value; lsItems.Add(item); } } model.url_rewrite_items = lsItems; return model; } } } return null; }
/// <summary> /// 取得URL配制列表 /// </summary> public List<Model.url_rewrite> GetList(string channel) { List<Model.url_rewrite> ls = new List<Model.url_rewrite>(); string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); foreach (XmlElement xe in xn.ChildNodes) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite") { if (xe.Attributes["name"] != null) { if (!string.IsNullOrEmpty(channel)) { if (channel.ToLower() == xe.Attributes["channel"].Value.ToLower()) { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) model.name = xe.Attributes["name"].Value; if (xe.Attributes["path"] != null) model.path = xe.Attributes["path"].Value; if (xe.Attributes["pattern"] != null) model.pattern = xe.Attributes["pattern"].Value; if (xe.Attributes["page"] != null) model.page = xe.Attributes["page"].Value; if (xe.Attributes["querystring"] != null) model.querystring = xe.Attributes["querystring"].Value; if (xe.Attributes["templet"] != null) model.templet = xe.Attributes["templet"].Value; if (xe.Attributes["channel"] != null) model.channel = xe.Attributes["channel"].Value; if (xe.Attributes["type"] != null) model.type = xe.Attributes["type"].Value; if (xe.Attributes["inherit"] != null) model.inherit = xe.Attributes["inherit"].Value; ls.Add(model); } } else { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) model.name = xe.Attributes["name"].Value; if (xe.Attributes["path"] != null) model.path = xe.Attributes["path"].Value; if (xe.Attributes["pattern"] != null) model.pattern = xe.Attributes["pattern"].Value; if (xe.Attributes["page"] != null) model.page = xe.Attributes["page"].Value; if (xe.Attributes["querystring"] != null) model.querystring = xe.Attributes["querystring"].Value; if (xe.Attributes["templet"] != null) model.templet = xe.Attributes["templet"].Value; if (xe.Attributes["channel"] != null) model.channel = xe.Attributes["channel"].Value; if (xe.Attributes["type"] != null) model.type = xe.Attributes["type"].Value; if (xe.Attributes["inherit"] != null) model.inherit = xe.Attributes["inherit"].Value; ls.Add(model); } } } } return ls; }
/// <summary> /// 修改节点 /// </summary> public bool Edit(Model.url_rewrite model) { return(dal.Edit(model)); }
/// <summary> /// 修改节点 /// </summary> public bool Edit(Model.url_rewrite model) { string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == model.name.ToLower()) { if (!string.IsNullOrEmpty(model.type)) { xe.SetAttribute("type", model.type); } else if (xe.Attributes["type"] != null) { xe.Attributes["type"].RemoveAll(); } if (!string.IsNullOrEmpty(model.page)) { xe.SetAttribute("page", model.page); } else if (xe.Attributes["page"] != null) { xe.Attributes["page"].RemoveAll(); } if (!string.IsNullOrEmpty(model.inherit)) { xe.SetAttribute("inherit", model.inherit); } else if (xe.Attributes["inherit"] != null) { xe.Attributes["inherit"].RemoveAll(); } if (!string.IsNullOrEmpty(model.templet)) { xe.SetAttribute("templet", model.templet); } else if (xe.Attributes["templet"] != null) { xe.Attributes["templet"].RemoveAll(); } if (!string.IsNullOrEmpty(model.channel)) { xe.SetAttribute("channel", model.channel); } else if (xe.Attributes["channel"] != null) { xe.Attributes["channel"].RemoveAll(); } if (!string.IsNullOrEmpty(model.pagesize)) { xe.SetAttribute("pagesize", model.pagesize); } else if (xe.Attributes["pagesize"] != null) { xe.Attributes["pagesize"].RemoveAll(); } //移除所有的子节点重新添加 XmlNodeList itemXnList = xe.ChildNodes; foreach (XmlElement itemXe in itemXnList) { for (int i = itemXnList.Count - 1; i >= 0; i--) { XmlElement xe2 = (XmlElement)itemXnList.Item(i); xe.RemoveChild(xe2); } } //创建子节点 foreach (Model.url_rewrite_item modelt in model.url_rewrite_items) { XmlElement xeItem = doc.CreateElement("item"); if (!string.IsNullOrEmpty(modelt.path)) { xeItem.SetAttribute("path", modelt.path); } if (!string.IsNullOrEmpty(modelt.pattern)) { xeItem.SetAttribute("pattern", modelt.pattern); } if (!string.IsNullOrEmpty(modelt.querystring)) { xeItem.SetAttribute("querystring", modelt.querystring); } xe.AppendChild(xeItem); } doc.Save(filePath); return(true); } } } return(false); }
/// <summary> /// 取得URL配制列表 /// </summary> public List <Model.url_rewrite> GetList(string channel) { List <Model.url_rewrite> ls = new List <Model.url_rewrite>(); string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); foreach (XmlElement xe in xn.ChildNodes) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite") { if (xe.Attributes["name"] != null) { if (!string.IsNullOrEmpty(channel)) { if (xe.Attributes["channel"] != null && channel.ToLower() == xe.Attributes["channel"].Value.ToLower()) { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) { model.name = xe.Attributes["name"].Value; } if (xe.Attributes["type"] != null) { model.type = xe.Attributes["type"].Value; } if (xe.Attributes["page"] != null) { model.page = xe.Attributes["page"].Value; } if (xe.Attributes["inherit"] != null) { model.inherit = xe.Attributes["inherit"].Value; } if (xe.Attributes["templet"] != null) { model.templet = xe.Attributes["templet"].Value; } if (xe.Attributes["channel"] != null) { model.channel = xe.Attributes["channel"].Value; } if (xe.Attributes["pagesize"] != null) { model.pagesize = xe.Attributes["pagesize"].Value; } //再次遍历子节点 StringBuilder urlRewriteString = new StringBuilder(); List <Model.url_rewrite_item> lsItems = new List <Model.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.url_rewrite_item item = new Model.url_rewrite_item(); if (xe1.Attributes["path"] != null) { item.path = xe1.Attributes["path"].Value; } if (xe1.Attributes["pattern"] != null) { item.pattern = xe1.Attributes["pattern"].Value; } if (xe1.Attributes["querystring"] != null) { item.querystring = xe1.Attributes["querystring"].Value; } urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串 lsItems.Add(item); } } model.url_rewrite_str = Utils.DelLastChar(urlRewriteString.ToString(), "&"); model.url_rewrite_items = lsItems; ls.Add(model); } } else { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) { model.name = xe.Attributes["name"].Value; } if (xe.Attributes["type"] != null) { model.type = xe.Attributes["type"].Value; } if (xe.Attributes["page"] != null) { model.page = xe.Attributes["page"].Value; } if (xe.Attributes["inherit"] != null) { model.inherit = xe.Attributes["inherit"].Value; } if (xe.Attributes["templet"] != null) { model.templet = xe.Attributes["templet"].Value; } if (xe.Attributes["channel"] != null) { model.channel = xe.Attributes["channel"].Value; } if (xe.Attributes["pagesize"] != null) { model.pagesize = xe.Attributes["pagesize"].Value; } //再次遍历子节点 StringBuilder urlRewriteString = new StringBuilder(); List <Model.url_rewrite_item> lsItems = new List <Model.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.url_rewrite_item item = new Model.url_rewrite_item(); if (xe1.Attributes["path"] != null) { item.path = xe1.Attributes["path"].Value; } if (xe1.Attributes["pattern"] != null) { item.pattern = xe1.Attributes["pattern"].Value; } if (xe1.Attributes["querystring"] != null) { item.querystring = xe1.Attributes["querystring"].Value; } urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串 lsItems.Add(item); } } model.url_rewrite_str = Utils.DelLastChar(urlRewriteString.ToString(), "&"); model.url_rewrite_items = lsItems; ls.Add(model); } } } } return(ls); }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.url_rewrite GetInfo(string attrValue) { Model.url_rewrite model = new Model.url_rewrite(); string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower()) { if (xe.Attributes["name"] != null) { model.name = xe.Attributes["name"].Value; } if (xe.Attributes["type"] != null) { model.type = xe.Attributes["type"].Value; } if (xe.Attributes["page"] != null) { model.page = xe.Attributes["page"].Value; } if (xe.Attributes["inherit"] != null) { model.inherit = xe.Attributes["inherit"].Value; } if (xe.Attributes["templet"] != null) { model.templet = xe.Attributes["templet"].Value; } if (xe.Attributes["channel"] != null) { model.channel = xe.Attributes["channel"].Value; } if (xe.Attributes["pagesize"] != null) { model.pagesize = xe.Attributes["pagesize"].Value; } //再次遍历子节点 List <Model.url_rewrite_item> lsItems = new List <Model.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.url_rewrite_item item = new Model.url_rewrite_item(); if (xe1.Attributes["path"] != null) { item.path = xe1.Attributes["path"].Value; } if (xe1.Attributes["pattern"] != null) { item.pattern = xe1.Attributes["pattern"].Value; } if (xe1.Attributes["querystring"] != null) { item.querystring = xe1.Attributes["querystring"].Value; } lsItems.Add(item); } } model.url_rewrite_items = lsItems; return(model); } } } return(null); }
/// <summary> /// 增加节点 /// </summary> public bool Add(Model.url_rewrite model) { try { string filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlElement xe = doc.CreateElement("rewrite"); if (!string.IsNullOrEmpty(model.name)) { xe.SetAttribute("name", model.name); } if (!string.IsNullOrEmpty(model.type)) { xe.SetAttribute("type", model.type); } if (!string.IsNullOrEmpty(model.page)) { xe.SetAttribute("page", model.page); } if (!string.IsNullOrEmpty(model.inherit)) { xe.SetAttribute("inherit", model.inherit); } if (!string.IsNullOrEmpty(model.templet)) { xe.SetAttribute("templet", model.templet); } if (!string.IsNullOrEmpty(model.channel)) { xe.SetAttribute("channel", model.channel); } if (!string.IsNullOrEmpty(model.pagesize)) { xe.SetAttribute("pagesize", model.pagesize); } XmlNode newXn = xn.AppendChild(xe); //创建子节点 foreach (Model.url_rewrite_item modelt in model.url_rewrite_items) { XmlElement xeItem = doc.CreateElement("item"); if (!string.IsNullOrEmpty(modelt.path)) { xeItem.SetAttribute("path", modelt.path); } if (!string.IsNullOrEmpty(modelt.pattern)) { xeItem.SetAttribute("pattern", modelt.pattern); } if (!string.IsNullOrEmpty(modelt.querystring)) { xeItem.SetAttribute("querystring", modelt.querystring); } newXn.AppendChild(xeItem); } doc.Save(filePath); return(true); } catch { return(false); } }
/// <summary> /// 取得URL配制列表 /// </summary> public List <Model.url_rewrite> GetList(string channel) { List <Model.url_rewrite> ls = new List <Model.url_rewrite>(); string filePath = HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); foreach (XmlElement xe in xn.ChildNodes) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite") { if (xe.Attributes["name"] != null) { if (!string.IsNullOrEmpty(channel)) { if (channel.ToLower() == xe.Attributes["channel"].Value.ToLower()) { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) { model.name = xe.Attributes["name"].Value; } if (xe.Attributes["path"] != null) { model.path = xe.Attributes["path"].Value; } if (xe.Attributes["pattern"] != null) { model.pattern = xe.Attributes["pattern"].Value; } if (xe.Attributes["page"] != null) { model.page = xe.Attributes["page"].Value; } if (xe.Attributes["querystring"] != null) { model.querystring = xe.Attributes["querystring"].Value; } if (xe.Attributes["templet"] != null) { model.templet = xe.Attributes["templet"].Value; } if (xe.Attributes["channel"] != null) { model.channel = xe.Attributes["channel"].Value; } if (xe.Attributes["type"] != null) { model.type = xe.Attributes["type"].Value; } if (xe.Attributes["inherit"] != null) { model.inherit = xe.Attributes["inherit"].Value; } ls.Add(model); } } else { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) { model.name = xe.Attributes["name"].Value; } if (xe.Attributes["path"] != null) { model.path = xe.Attributes["path"].Value; } if (xe.Attributes["pattern"] != null) { model.pattern = xe.Attributes["pattern"].Value; } if (xe.Attributes["page"] != null) { model.page = xe.Attributes["page"].Value; } if (xe.Attributes["querystring"] != null) { model.querystring = xe.Attributes["querystring"].Value; } if (xe.Attributes["templet"] != null) { model.templet = xe.Attributes["templet"].Value; } if (xe.Attributes["channel"] != null) { model.channel = xe.Attributes["channel"].Value; } if (xe.Attributes["type"] != null) { model.type = xe.Attributes["type"].Value; } if (xe.Attributes["inherit"] != null) { model.inherit = xe.Attributes["inherit"].Value; } ls.Add(model); } } } } return(ls); }
/// <summary> /// 增加节点 /// </summary> public bool Add(Model.url_rewrite model) { return(dal.Add(model)); }
/// <summary> /// 取得URL配制列表 /// </summary> public List<Model.url_rewrite> GetList(string channel) { List<Model.url_rewrite> ls = new List<Model.url_rewrite>(); string filePath = Utils.GetXmlMapPath(MXKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); foreach (XmlElement xe in xn.ChildNodes) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite") { if (xe.Attributes["name"] != null) { if (!string.IsNullOrEmpty(channel)) { if (xe.Attributes["channel"] != null && channel.ToLower() == xe.Attributes["channel"].Value.ToLower()) { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) model.name = xe.Attributes["name"].Value; if (xe.Attributes["type"] != null) model.type = xe.Attributes["type"].Value; if (xe.Attributes["page"] != null) model.page = xe.Attributes["page"].Value; if (xe.Attributes["inherit"] != null) model.inherit = xe.Attributes["inherit"].Value; if (xe.Attributes["templet"] != null) model.templet = xe.Attributes["templet"].Value; if (xe.Attributes["channel"] != null) model.channel = xe.Attributes["channel"].Value; //再次遍历子节点 StringBuilder urlRewriteString = new StringBuilder(); List<Model.url_rewrite_item> lsItems = new List<Model.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.url_rewrite_item item = new Model.url_rewrite_item(); if (xe1.Attributes["path"] != null) item.path = xe1.Attributes["path"].Value; if (xe1.Attributes["pattern"] != null) item.pattern = xe1.Attributes["pattern"].Value; if (xe1.Attributes["querystring"] != null) item.querystring = xe1.Attributes["querystring"].Value; urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串 lsItems.Add(item); } } model.url_rewrite_str = Utils.DelLastChar(urlRewriteString.ToString(), "&"); model.url_rewrite_items = lsItems; ls.Add(model); } } else { Model.url_rewrite model = new Model.url_rewrite(); if (xe.Attributes["name"] != null) model.name = xe.Attributes["name"].Value; if (xe.Attributes["type"] != null) model.type = xe.Attributes["type"].Value; if (xe.Attributes["page"] != null) model.page = xe.Attributes["page"].Value; if (xe.Attributes["inherit"] != null) model.inherit = xe.Attributes["inherit"].Value; if (xe.Attributes["templet"] != null) model.templet = xe.Attributes["templet"].Value; if (xe.Attributes["channel"] != null) model.channel = xe.Attributes["channel"].Value; //再次遍历子节点 StringBuilder urlRewriteString = new StringBuilder(); List<Model.url_rewrite_item> lsItems = new List<Model.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.url_rewrite_item item = new Model.url_rewrite_item(); if (xe1.Attributes["path"] != null) item.path = xe1.Attributes["path"].Value; if (xe1.Attributes["pattern"] != null) item.pattern = xe1.Attributes["pattern"].Value; if (xe1.Attributes["querystring"] != null) item.querystring = xe1.Attributes["querystring"].Value; urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串 lsItems.Add(item); } } model.url_rewrite_str = Utils.DelLastChar(urlRewriteString.ToString(), "&"); model.url_rewrite_items = lsItems; ls.Add(model); } } } } return ls; }
/// <summary> /// 返回URL重写统一链接地址 /// </summary> public string linkurl(string _key, params object[] _params) { Hashtable ht = new BLL.url_rewrite().GetList(); //获得URL配置列表 Model.url_rewrite model = ht[_key] as Model.url_rewrite; //查找指定的URL配置节点 //如果不存在该节点则返回空字符串 if (model == null) { return(string.Empty); } string requestDomain = HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号 string requestFirstPath = GetFirstPath(); //获得二级目录(不含站点安装目录) string linkStartString = string.Empty; //链接前缀 //检查是否与绑定的域名或者与默认频道分类的目录匹配 if (SiteDomains.GetSiteDomains().CategoryDirs.ContainsValue(requestDomain)) { linkStartString = "/"; } else if (requestFirstPath == string.Empty || requestFirstPath == SiteDomains.GetSiteDomains().DefaultPath) { linkStartString = config.webpath; } else { linkStartString = config.webpath + requestFirstPath + "/"; } //如果URL字典表达式不需要重写则直接返回 if (model.url_rewrite_items.Count == 0) { //检查网站重写状态 if (config.staticstatus > 0) { if (_params.Length > 0) { return(linkStartString + GetUrlExtension(model.page, config.staticextension) + string.Format("{0}", _params)); } else { return(linkStartString + GetUrlExtension(model.page, config.staticextension)); } } else { if (_params.Length > 0) { return(linkStartString + model.page + string.Format("{0}", _params)); } else { return(linkStartString + model.page); } } } //否则检查该URL配置节点下的子节点 foreach (Model.url_rewrite_item item in model.url_rewrite_items) { //如果参数个数匹配 if (IsUrlMatch(item, _params)) { //检查网站重写状态 if (config.staticstatus > 0) { return(linkStartString + string.Format(GetUrlExtension(item.path, config.staticextension), _params)); } else { string queryString = Regex.Replace(string.Format(item.path, _params), item.pattern, item.querystring, RegexOptions.None | RegexOptions.IgnoreCase); if (queryString.Length > 0) { queryString = "?" + queryString; } return(linkStartString + model.page + queryString); } } } return(string.Empty); }
/// <summary> /// 修改节点 /// </summary> public bool Edit(Model.url_rewrite model) { string filePath = HotoUtils.GetXmlMapPath(HotoKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == model.name.ToLower()) { if (!string.IsNullOrEmpty(model.path)) { xe.SetAttribute("path", model.path); } else if (xe.Attributes["path"] != null) { xe.Attributes["path"].RemoveAll(); } if (!string.IsNullOrEmpty(model.pattern)) { xe.SetAttribute("pattern", model.pattern); } else if (xe.Attributes["pattern"] != null) { xe.Attributes["pattern"].RemoveAll(); } if (!string.IsNullOrEmpty(model.page)) { xe.SetAttribute("page", model.page); } else if (xe.Attributes["page"] != null) { xe.Attributes["page"].RemoveAll(); } if (!string.IsNullOrEmpty(model.querystring)) { xe.SetAttribute("querystring", model.querystring); } else if (xe.Attributes["querystring"] != null) { xe.Attributes["querystring"].RemoveAll(); } if (!string.IsNullOrEmpty(model.templet)) { xe.SetAttribute("templet", model.templet); } else if (xe.Attributes["templet"] != null) { xe.Attributes["templet"].RemoveAll(); } if (!string.IsNullOrEmpty(model.channel)) { xe.SetAttribute("channel", model.channel); } else if (xe.Attributes["channel"] != null) { xe.Attributes["channel"].RemoveAll(); } if (!string.IsNullOrEmpty(model.type)) { xe.SetAttribute("type", model.type); } else if (xe.Attributes["type"] != null) { xe.Attributes["type"].RemoveAll(); } if (!string.IsNullOrEmpty(model.inherit)) { xe.SetAttribute("inherit", model.inherit); } else if (xe.Attributes["inherit"] != null) { xe.Attributes["inherit"].RemoveAll(); } doc.Save(filePath); return(true); } } } return(false); }
private bool DoEdit(int _id) { BLL.site_channel bll = new BLL.site_channel(); Model.site_channel model = bll.GetModel(_id); string old_name = model.name; model.site_id = Utils.StrToInt(ddlSiteId.SelectedValue, 0); model.name = txtName.Text.Trim(); model.title = txtTitle.Text.Trim(); model.is_lock = 0; model.is_comment = 0; model.is_albums = 0; model.is_attach = 0; model.is_spec = 0; if (cbIsLock.Checked == false) { model.is_lock = 1; } if (cbIsComment.Checked == true) { model.is_comment = 1; } if (cbIsAlbums.Checked == true) { model.is_albums = 1; } if (cbIsAttach.Checked == true) { model.is_attach = 1; } if (cbIsSpec.Checked == true) { model.is_spec = 1; } model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); //添加频道扩展字段 List <Model.site_channel_field> ls = new List <Model.site_channel_field>(); for (int i = 0; i < cblAttributeField.Items.Count; i++) { if (cblAttributeField.Items[i].Selected) { string[] fieldIdArr = cblAttributeField.Items[i].Value.Split(','); //分解出ID值 ls.Add(new Model.site_channel_field { channel_id = model.id, field_id = Utils.StrToInt(fieldIdArr[1], 0) }); } } model.channel_fields = ls; if (!bll.Update(model)) { return(false); } #region 保存URL配置 BLL.url_rewrite urlBll = new BLL.url_rewrite(); urlBll.Remove("channel", old_name); //先删除旧的 string[] itemTypeArr = Request.Form.GetValues("item_type"); string[] itemNameArr = Request.Form.GetValues("item_name"); string[] itemPageArr = Request.Form.GetValues("item_page"); string[] itemTempletArr = Request.Form.GetValues("item_templet"); string[] itemPageSizeArr = Request.Form.GetValues("item_pagesize"); string[] itemRewriteArr = Request.Form.GetValues("item_rewrite"); if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemPageSizeArr != null && itemRewriteArr != null) { if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length) && (itemTempletArr.Length == itemPageSizeArr.Length) && (itemPageSizeArr.Length == itemRewriteArr.Length)) { for (int i = 0; i < itemTypeArr.Length; i++) { Model.url_rewrite urlModel = new Model.url_rewrite(); urlModel.name = itemNameArr[i].Trim(); urlModel.type = itemTypeArr[i].Trim(); urlModel.page = itemPageArr[i].Trim(); urlModel.inherit = GetInherit(urlModel.type); urlModel.templet = itemTempletArr[i].Trim(); if (Utils.StrToInt(itemPageSizeArr[i].Trim(), 0) > 0) { urlModel.pagesize = itemPageSizeArr[i].Trim(); } urlModel.channel = model.name; List <Model.url_rewrite_item> itemLs = new List <Model.url_rewrite_item>(); string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串 for (int j = 0; j < urlRewriteArr.Length; j++) { string[] urlItemArr = urlRewriteArr[j].Split(','); if (urlItemArr.Length == 3) { itemLs.Add(new Model.url_rewrite_item { path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2] }); } } urlModel.url_rewrite_items = itemLs; urlBll.Add(urlModel); } } } #endregion AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改频道" + model.title); //记录日志 return(true); }
private bool DoAdd() { Model.channel model = new Model.channel(); BLL.channel bll = new BLL.channel(); model.category_id = Utils.StrToInt(ddlCategoryId.SelectedValue, 0); model.name = txtName.Text.Trim(); model.title = txtTitle.Text.Trim(); if (cbIsAlbums.Checked == true) { model.is_albums = 1; } if (cbIsAttach.Checked == true) { model.is_attach = 1; } if (cbIsGroupPrice.Checked == true) { model.is_group_price = 1; } model.page_size = Utils.StrToInt(txtPageSize.Text.Trim(), 10); model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); //添加频道扩展字段 List<Model.channel_field> ls = new List<Model.channel_field>(); for (int i = 0; i < cblAttributeField.Items.Count; i++) { if (cblAttributeField.Items[i].Selected) { ls.Add(new Model.channel_field { field_id = Utils.StrToInt(cblAttributeField.Items[i].Value, 0) }); } } model.channel_fields = ls; if (bll.Add(model) < 1) { return false; } #region 保存URL配置 BLL.url_rewrite urlBll = new BLL.url_rewrite(); urlBll.Remove("channel", model.name); //先删除 string[] itemTypeArr = Request.Form.GetValues("item_type"); string[] itemNameArr = Request.Form.GetValues("item_name"); string[] itemPageArr = Request.Form.GetValues("item_page"); string[] itemTempletArr = Request.Form.GetValues("item_templet"); string[] itemRewriteArr = Request.Form.GetValues("item_rewrite"); if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemRewriteArr != null) { if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length) && (itemTempletArr.Length == itemRewriteArr.Length)) { for (int i = 0; i < itemTypeArr.Length; i++) { Model.url_rewrite urlModel = new Model.url_rewrite(); urlModel.name = itemNameArr[i].Trim(); urlModel.type = itemTypeArr[i].Trim(); urlModel.page = itemPageArr[i].Trim(); urlModel.inherit = GetInherit(urlModel.type); urlModel.templet = itemTempletArr[i].Trim(); urlModel.channel = model.name; List<Model.url_rewrite_item> itemLs = new List<Model.url_rewrite_item>(); string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串 for (int j = 0; j < urlRewriteArr.Length; j++) { string[] urlItemArr = urlRewriteArr[j].Split(','); if (urlItemArr.Length == 3) { itemLs.Add(new Model.url_rewrite_item { path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2] }); } } urlModel.url_rewrite_items = itemLs; urlBll.Add(urlModel); } } } #endregion AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加频道" + model.title); //记录日志 return true; }