Exemplo n.º 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");
        }
Exemplo n.º 2
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;
            // }
        }
Exemplo n.º 3
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());
     }
 }
Exemplo n.º 4
0
        /// <summary>S
        /// 获取文档的地址
        /// </summary>
        /// <param name="flags"></param>
        /// <param name="categoryTag"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual string GetArchiveUrl(string location, string flags, CategoryDto category, string id)
        {
            if (location == "" || location == null)
            {
                if (String.IsNullOrEmpty(flags) || (flags.IndexOf("p:'1'") == -1))
                {
                    return this.FormatUrl(UrlRulePageKeys.Archive, category.UriPath, id);
                }
                return this.FormatUrl(UrlRulePageKeys.SinglePage, id);
            }

            //如果定义了跳转地址
            if (Regex.IsMatch(location, "^http(s?)://", RegexOptions.IgnoreCase))
            {
                return location;
            }
            //todo:在添加的页面正则判断
            //if (archive.Location.StartsWith("/")) 
            //    throw new Exception("URL不能以\"/\"开头!");
            return String.Concat(AtNet.Cms.Cms.Context.SiteDomain, "/", location);
        }
Exemplo n.º 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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
        public virtual string GetCategory(CategoryDto category, int pageIndex, params object[] args)
        {
            string tplID = this.GetCategoryTemplateId(category);


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

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

            bool _isFirstPage = pageIndex == 1;

            string title;
            if (pageIndex == 1)
            {
                if (!String.IsNullOrEmpty(category.PageTitle))
                {
                    title = category.PageTitle;
                }
                else
                {
                    title = String.Format("{0}_{1}", category.Name, site.SeoTitle);
                }
            }
            else
            {
                switch (site.Language)
                {
                    case Languages.Zh_CN:
                        title = String.Format("- 第" + pageIndex.ToString() + "页");
                        break;
                    default:
                    case Languages.En_US:
                        title = String.Format("- page " + pageIndex.ToString());
                        break;
                }

                title = String.Format("{0}{1}_{2}", category.Name, title, site.SeoTitle);
            }

            //解析模板
            return PageUtility.Require(tplID, page =>
            {
                page.AddVariable("site", site);
                page.AddVariable("page", new PageVariable
                            {
                                Title = title,
                                SubTitle = site.SeoTitle,
                                Keywords = category.Keywords,
                                Description = category.Description,
                                PageIndex = pageIndex
                            });
                page.AddVariable("category", category);
                page.AddVariable("module", new Module { ID = category.ModuleId });
            });
        }