Exemple #1
0
        public string GetArchive(ArchiveDto archive)
        {
            #region 属性

            /*
             * //验证密码
             * PropertyBLL pbll = new PropertyBLL();
             * var a = pbll.GetProperty(category.ModuleID, "pwd");
             * if (a != null)
             * {
             *  var json = archive.GetPropertiesJson();
             *  string key = json.GetValue("pwd");
             *  if (!String.IsNullOrEmpty(key))
             *  {
             *      string requireKey = HttpContext.Current.Request.QueryString["pwd"];
             *      if (requireKey != key)
             *      {
             *          HttpContext.Current.Response.Write("<div style='margin:0 auto;padding:30px 0'>请输入密码:<input type='text'/><input type='button' value='提交' onclick=\"location.replace(location.href+'?pwd='+this.previousSibling.value)\"/></div>");
             *          HttpContext.Current.Response.End();
             *      }
             *
             *  }
             * }*/

            #endregion

            //获取模板ID
            var tplId    = GetArchiveTemplateId(archive);
            var category = archive.Category;

            //用于当前的模板共享数据
            Cms.Context.Items["archive.id"]    = archive.Id;
            Cms.Context.Items["category.path"] = category.Path;
            Cms.Context.Items["module.id"]     = category.ModuleId;


            //解析模板
            var html = PageUtility.Require(tplId,
                                           page =>
            {
                page.AddVariable("site", _site);

                var pageArchive = new PageArchive(archive);

                page.AddVariable("archive", pageArchive);

                page.AddVariable("category", category);
                page.AddVariable("module", new Module {
                    ID = category.ModuleId
                });


                page.AddVariable("page", new PageVariable
                {
                    Title       = $"{archive.Title}_{_site.Title}",
                    SubTitle    = _site.Title,
                    Keywords    = archive.Tags,
                    Description = pageArchive.Outline.Replace("\"", string.Empty)
                });
            });
            return(html);
        }
        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["category.path"] = category.Path;
            Cms.Context.Items["module.id"]     = category.ModuleId;
            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.Title);
                }
            }
            else
            {
                switch (_site.Language)
                {
                case Languages.Zh_CN:
                    title = String.Format("- 第" + pageIndex.ToString() + "页");
                    break;

                default:
                case Languages.En:
                    title = String.Format("- page " + pageIndex.ToString());
                    break;
                }

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

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