示例#1
0
        public string GetCategorySitemapHtml(int siteId, string catPath, string split, string linkFormat)
        {
            ISite     site     = this.repo.GetSiteById(siteId);
            ICategory category = site.GetCategoryByPath(catPath);

            if (linkFormat.EndsWith("/"))
            {
                linkFormat = linkFormat.Substring(0, linkFormat.Length - 1);
            }
            StringBuilder sb     = new StringBuilder();
            int           tmpInt = 0;
            String        html   = "";

            while (category != null)
            {
                sb.Append("<a class=\"l").Append((tmpInt + 1).ToString()).Append("\" href=\"");
                if (!String.IsNullOrEmpty(category.Get().Location))
                {
                    if (category.Get().Location.IndexOf("//", StringComparison.Ordinal) != -1)
                    {
                        sb.Append(category.Get().Location);
                    }
                    else
                    {
                        if (category.Get().Location.StartsWith("/"))
                        {
                            category.Get().Location = category.Get().Location.Substring(1);
                        }
                        string path = String.Format(linkFormat, category.Get().Location);
                        sb.Append(path);
                    }
                }
                else
                {
                    sb.Append(String.Format(linkFormat, category.Get().Path)).Append("/");
                }
                sb.Append("\"");

                //栏目的上一级添加不追踪特性
                if (++tmpInt > 1)
                {
                    sb.Append(" rel=\"nofollow\"");
                }
                sb.Append(">").Append(category.Get().Name).Append("</a>");

                //添加分隔符
                if (tmpInt > 1)
                {
                    sb.Append(split);
                }

                html = sb.ToString() + html;
                sb.Remove(0, sb.Length);

                category = category.Parent;
            }
            return(html);
        }
示例#2
0
        public CategoryDto GetCategory(int siteId, string catPath)
        {
            // 如果以"/"开头,则去掉
            if (!String.IsNullOrEmpty(catPath) && catPath[0] == '/')
            {
                catPath = catPath.Substring(1);
            }
            ISite site = this.repo.GetSiteById(siteId);

            return(CategoryDto.ConvertFrom(site.GetCategoryByPath(catPath)));
        }
示例#3
0
        public void TestGetCategory()
        {
            ISite     ist = this.siteRepo.GetSiteById(siteId);
            ICategory ic  = ist.GetCategoryByPath("root/cat1");

            if (ic == null)
            {
                Assert.Fail("no such category");
            }
            Console.WriteLine(this.Stringfy(ic.Get()));
        }
示例#4
0
        public bool CheckCategoryTagAvailable(int siteId, int categoryId, string categoryTag)
        {
            ISite     site     = this.repo.GetSiteById(siteId);
            ICategory category = site.GetCategoryByPath(categoryTag);

            if (category == null)
            {
                return(true);
            }
            //
            //            if (categoryId <= 0)
            //            {
            //                return false;
            //            }
            return(category.GetDomainId() == categoryId);
        }
示例#5
0
        public void SaveCategory()
        {
            ISite             ist = this.siteRepo.GetSiteById(siteId);
            CmsCategoryEntity cat = new CmsCategoryEntity
            {
                SiteId   = siteId,
                Name     = "一级分类",
                ParentId = 0,
                Tag      = "cat1",
                Location = "http://baidu.com",
            };
            ICategory ic = ist.GetCategoryByPath("cat1");

            if (ic == null)
            {
                ic = this.repo.CreateCategory(cat);
            }
            Error err = ic.Set(cat);

            if (err == null)
            {
                TemplateBind[] arr = new TemplateBind[2];
                arr[0] = new TemplateBind(0, TemplateBindType.CategoryArchiveTemplate, "default/archive_1");
                arr[1] = new TemplateBind(0, TemplateBindType.CategoryTemplate, "default/category_1");
                err    = ic.SetTemplates(arr);
                if (err == null)
                {
                    err = ic.Save();
                }
            }
            if (err != null)
            {
                Assert.Fail(err.Message);
            }
            else
            {
                this.Println(this.Stringfy(ic.Get()));
                this.Println(this.Stringfy(ist.GetCategoryTreeWithRootNode()));
                cat.Name += "*";
                ic.Set(cat);
                ic.Save();
                this.Println(this.Stringfy(ist.GetCategoryTreeWithRootNode()));
            }
        }
示例#6
0
        public CategoryDto GetCategory(int siteId, string catPath)
        {
            ISite site = this.repo.GetSiteById(siteId);

            return(CategoryDto.ConvertFrom(site.GetCategoryByPath(catPath)));
        }