public string GetCategorySitemapHtml(int siteId, string categoryTag, string split, string linkFormat) { ISite site = this._resp.GetSiteById(siteId); int rootLft = site.RootCategory.Lft; ICategory category = site.GetCategoryByTag(categoryTag); if (linkFormat.EndsWith("/")) { linkFormat = linkFormat.Substring(0, linkFormat.Length - 1); } StringBuilder sb = new StringBuilder(); int tmpInt = 0; String html = ""; while (category != null && category.Lft != rootLft) { sb.Append("<a class=\"l").Append((tmpInt + 1).ToString()).Append("\" href=\""); if (!String.IsNullOrEmpty(category.Location)) { if (category.Location.IndexOf("//", StringComparison.Ordinal) != -1) { sb.Append(category.Location); } else { if (category.Location.StartsWith("/")) { category.Location = category.Location.Substring(1); } string path = String.Format(linkFormat, category.Location); sb.Append(path); } } else { sb.Append(String.Format(linkFormat, category.UriPath)).Append("/"); } sb.Append("\""); //栏目的上一级添加不追踪特性 if (++tmpInt > 1) { sb.Append(" rel=\"nofollow\""); } sb.Append(">").Append(category.Name).Append("</a>"); //添加分隔符 if (tmpInt > 1) { sb.Append(split); } html = sb.ToString() + html; sb.Remove(0, sb.Length); category = category.Parent; } return(html); }
public string GetCategorySitemapHtml(int siteId, string categoryTag, string split, string linkFormat) { string categoryPath = null; int rootLft; ICategory parentCategory; ISite site = this._resp.GetSiteById(siteId); ICategory category = site.GetCategoryByTag(categoryTag); if (category == null) { throw new Exception("栏目不存在"); } rootLft = site.RootCategory.Lft; string html = ""; StringBuilder sb = new StringBuilder(); int tmpInt = 0; while (category != null && category.Lft != rootLft) { sb.Remove(0, sb.Length); sb.Append("<a href=\"") .Append(String.Format(linkFormat, category.UriPath)) .Append("\""); //栏目的上一级添加不追踪特性 if (++tmpInt > 1) { sb.Append(" rel=\"nofollow\""); } sb.Append(">").Append(category.Name).Append("</a>"); //添加分隔符 if (tmpInt != 1) { sb.Append(split); } html = sb.ToString() + html; category = category.Parent; } //去掉双斜杠 // Regex reg = new Regex("\\b//"); // return reg.Replace(sb.ToString(), "/"); return(html); }
public bool CheckCategoryTagAvailable(int siteId, int categoryId, string categoryTag) { ISite site = this._resp.GetSiteById(siteId); ICategory category = site.GetCategoryByTag(categoryTag); if (category == null) { return(true); } // // if (categoryId <= 0) // { // return false; // } return(category.Id == categoryId); }
public bool CheckCategoryTagAvailable(int siteId, int categoryId, string categoryTag) { ISite site = this._resp.GetSiteById(siteId); ICategory category = site.GetCategoryByTag(categoryTag); bool categoryIsNull = category == null; if (categoryIsNull) { return(true); } if (categoryId <= 0) { return(categoryIsNull); } return(category.Id == categoryId); }
public CategoryDto GetCategory(int siteId, string categoryTag) { ISite site = this._resp.GetSiteById(siteId); return(CategoryDto.ConvertFrom(site.GetCategoryByTag(categoryTag))); }