Exemple #1
0
        /// <summary>
        /// 获取栏目的模板ID
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public virtual string GetCategoryTemplateID(CategoryDto category)
        {
            //Module m = CmsLogic.Module.GetModule(category.ModuleID);
            //if (m != null)
            //{ //}

            if (category.CategoryTemplate!=null)
            {
                return "/"+this.GetTemplateID(category.CategoryTemplate);
            }
            //设置默认的模板
            return this.FormatTemplatePath("category");
        }
Exemple #2
0
        public static CategoryDto ConvertFrom(ICategory category)
        {
            if (category == null) return default(CategoryDto);
            //int moduleId = category.ModuleID;
            CategoryDto dto = new CategoryDto
            {
                ID = category.ID,
                Keywords = category.Keywords,
                Description = category.Description,
                Tag = category.Tag,
                Icon = category.Icon,
                Name = category.Name,
                PageTitle = category.PageTitle,
                OrderIndex = category.OrderIndex,
                ModuleID = category.ModuleID,
                Location = category.Location,
                ExtendFields = category.ExtendFields,
                SiteId = category.Site.ID,
                UriPath = category.UriPath,
                Lft = category.Lft,
                Rgt = category.Rgt
                //ModuleID = moduleId
            };
            //dto.CloneData(category);



            foreach (ITemplateBind tplBind in category.Templates)
            {
                switch (tplBind.BindType)
                {
                    case TemplateBindType.CategoryTemplate:
                        dto.CategoryTemplate = tplBind.TplPath;
                        break;
                    case TemplateBindType.CategoryArchiveTemplate:
                        dto.CategoryArchiveTemplate = tplBind.TplPath;
                        break;
                }
            }

            return dto;
        }
Exemple #3
0
        public int SaveCategory(int siteId, int parentLft, CategoryDto category)
        {
            ISite site = this._resp.GetSiteById(siteId);
            ICategory ic = site.GetCategoryByLft(category.Lft);
            if (ic == null) ic = _categoryRep.CreateCategory(-1, site);
            //ic.CloneData(category);
            ic.ID = category.ID;
            ic.Keywords = category.Keywords;
            ic.Description = category.Description;
            ic.Tag = category.Tag;
            ic.Icon = category.Icon;
            ic.Name = category.Name;
            ic.PageTitle = category.PageTitle;
            ic.OrderIndex = category.OrderIndex;
            ic.ModuleID = category.ModuleID;
            ic.Location = category.Location;

            bool isExistCategoryBind = false;
            bool isExistArchiveBind = false;

            #region 模板绑定

            foreach (ITemplateBind tempBind in ic.Templates)
            {
                if (tempBind.BindType == TemplateBindType.CategoryTemplate)
                {
                    isExistCategoryBind = true;
                    tempBind.TplPath = category.CategoryTemplate;
                }
                else if (tempBind.BindType == TemplateBindType.CategoryArchiveTemplate)
                {
                    isExistArchiveBind = true;
                    tempBind.TplPath = category.CategoryArchiveTemplate;
                }
            }

            //栏目模板
            if (!isExistCategoryBind && !String.IsNullOrEmpty(category.CategoryTemplate))
            {
                ITemplateBind bind = this._tempRep.CreateTemplateBind(-1,
                        TemplateBindType.CategoryTemplate,
                        category.CategoryTemplate);

                bind.BindRefrenceId = ic.ID;
                ic.Templates.Add(bind);
            }

            //栏目文档模板
            if (!isExistArchiveBind && !String.IsNullOrEmpty(category.CategoryArchiveTemplate))
            {
                ITemplateBind bind = this._tempRep.CreateTemplateBind(-1,
                        TemplateBindType.CategoryArchiveTemplate,
                        category.CategoryArchiveTemplate);

                bind.BindRefrenceId = ic.ID;

                ic.Templates.Add(bind);
            }
            #endregion

            #region 扩展属性

            if (category.ExtendFields != null)
            {
                ic.ExtendFields = category.ExtendFields;
            }

            #endregion

            if (parentLft >= 0) ic.Parent = site.GetCategoryByLft(parentLft);
            return ic.Save();
        }
Exemple #4
0
        public virtual string GetCategory(CategoryDto category, int pageIndex, params object[] args)
        {
            string tplID = this.GetCategoryTemplateID(category);


            //
            //todo:  /news/news/news/时候仍然能访问
            //

            //用于当前的模板共享数据
            Cms.Context.Items["category.tag"] = category.Tag;
            Cms.Context.Items["module.id"] = category.ModuleID;
            Cms.Context.Items["page.index"] = pageIndex;

            bool _isFirstPage = pageIndex == 1;

            //解析模板
            return PageUtility.Require(tplID, page =>
            {
                page.AddVariable("site", site);
                page.AddVariable("page", new PageVariable
                            {
                                Title = _isFirstPage && !String.IsNullOrEmpty(category.PageTitle) ?
                                    category.PageTitle
                                    : String.Format("{0}{1}_{2}", category.Name, _isFirstPage ? "" : "(第" + pageIndex.ToString() + "页)", site.SeoTitle),
                                SubTitle = site.SeoTitle,
                                Keywords = category.Keywords,
                                Description = category.Description,
                                PageIndex = pageIndex
                            });
                page.AddVariable("category", category);
                page.AddVariable("module", new Module { ID = category.ModuleID });
            });
        }
Exemple #5
0
        private static CategoryDto InitCategoryDtoFromHttpPost(NameValueCollection form, CategoryDto category)
        {
            //form.BindToEntity(category);
            category.Keywords = form["Keywords"];
            category.PageTitle = form["PageTitle"];
            category.Tag = form["Tag"];
            category.Name = form["Name"];
            category.OrderIndex = int.Parse(form["OrderIndex"]);
            category.Description = form["Description"];
            category.Location = form["Location"];
            category.Icon = form["Icon"];

            if (!String.IsNullOrEmpty(category.Keywords))
            {
                category.Keywords = Regex.Replace(category.Keywords, ",|\\s|\\|", ",");
            }

            //设置模板
            string categoryTplPath = form["CategoryTemplate"],
                        archiveTplPath = form["CategoryArchiveTemplate"];


            //如果设置了栏目视图路径,则保存
            category.CategoryTemplate = categoryTplPath;

            //如果设置了文档视图路径,则保存
            category.CategoryArchiveTemplate = archiveTplPath;

            return category;
        }
Exemple #6
0
        protected void CategoryTree_Iterator(CategoryDto category, StringBuilder sb, CategoryResultTreeHandler handler, bool isRoot)
        {
            /*if (category.IsSign)
            {
                category.IsSign = false;
                return;
            }
            else
            {*/
            if (!isRoot)
            {
                sb.Append("<li><a href=\"")
                    //
                    //TODO:
                    //
                    //.Append(this.GetCategoryUrl(category, 1)).Append("\" tag=\"")
                    .Append(category.Tag).Append("\" lft=\"").Append(category.Lft.ToString()).Append("\">")
                    .Append(category.Name).Append("</a>");
            }

            IList<CategoryDto> childs = new List<CategoryDto>(ServiceCall.Instance.SiteService.GetCategories(
                this.siteId,
                category.Lft,
                category.Rgt,
                CategoryContainerOption.NextLevel));


            if (childs.Count != 0)
            {
                sb.Append("<ul>");

                foreach (CategoryDto c in childs)
                {
                    if (isRoot || handler(category))
                    {
                        CategoryTree_Iterator(c, sb, handler, false);
                    }
                }
                sb.Append("</ul>");
            }

            if (!isRoot)
            {
                sb.Append("</li>");
            }

            //category.IsSign = true;
            // }
        }
Exemple #7
0
 /// <summary>
 /// 获取栏目的地址
 /// </summary>
 /// <param name="category"></param>
 /// <param name="pageIndex"></param>
 /// <returns></returns>
 public virtual string GetCategoryUrl(CategoryDto category, int pageIndex)
 {
     if (pageIndex < 2)
     {
         return this.FormatUrl(UrlRulePageKeys.Category, category.UriPath);
     }
     else
     {
         return this.FormatUrl(UrlRulePageKeys.CategoryPager, category.UriPath, pageIndex.ToString());
     }
 }
Exemple #8
0
 /// <summary>
 /// 获取文档的地址
 /// </summary>
 /// <param name="flags"></param>
 /// <param name="categoryTag"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public virtual string GetArchiveUrl(string flags, CategoryDto category, string id)
 {
     //if (category == null)
     //{
     //    Archive archive = CmsLogic.Archive.Get(id);
     //   category = CmsLogic.Category.Get(a => a.ID == archive.Cid);
     //}
     if (String.IsNullOrEmpty(flags) || (flags.IndexOf("p:'1'") == -1))
     {
         return this.FormatUrl(UrlRulePageKeys.Archive, category.UriPath, id);
     }
     return this.FormatUrl(UrlRulePageKeys.SinglePage, id);
 }