Example #1
0
        public void SetTemplatePath(string templatePath)
        {
            bool templateIsNull = String.IsNullOrEmpty(templatePath);

            if (this.Template != null)
            {
                //处理自身的模板
                if (this.Template.BindRefrenceId == this.GetAggregaterootId())
                {
                    if (templateIsNull)
                    {
                        this.Template.TplPath = null;
                    }
                    else
                    {
                        this.Template.TplPath = templatePath;
                    }
                    return;
                }
            }

            //为文档新建模板绑定
            if (!templateIsNull)
            {
                this.Template = this._templateRep.CreateTemplateBind(
                    -1,
                    TemplateBindType.ArchiveTemplate,
                    templatePath);
                this.Template.BindRefrenceId = this.GetAggregaterootId();
            }
        }
Example #2
0
        public override Error Save()
        {
            this._value.SiteId = this.Category.Get().SiteId;
            this.UpdateArchivePath();
            if (this._value.SortNumber <= 0)
            {
                int sortNum = this._archiveRep.GetMaxSortNumber(this.Category.Site().GetAggregaterootId());
                this._value.SortNumber = sortNum + 1;
            }
            this._archiveRep.SaveArchive(this.Get());


            if (this._templateBind != null)
            {
            }
            //保存文档绑定的模板
            if (this._templateBind != null)
            {
                if (this._templateBind != null)
                {
                    this._templateBind.BindRefrenceId = this.GetAggregaterootId();
                }
                this._templateRep.SaveTemplateBind(this.GetAggregaterootId(), this._templateBind);
                if (this._templateBind.TplPath == null)
                {
                    this._templateBind = null;
                }
            }

            //保存扩展属性
            this._extendRep.UpdateArchiveRelationExtendValues(this);

            //保存其他
            return(base.Save());
        }
Example #3
0
        public IEnumerable <TemplateBind> GetTemplateBindsForCategory(ICategory category)
        {
            TemplateBind bind = this.GetBind(TemplateBindType.CategoryTemplate, category.GetDomainId());

            if (bind != null)
            {
                yield return(bind);
            }
            bind = this.GetBind(TemplateBindType.CategoryArchiveTemplate, category.GetDomainId());
            if (bind != null)
            {
                yield return(bind);
            }
        }
Example #4
0
        public override string GetCategory(Category category, int pageIndex, params object[] args)
        {
            string    tplID = null;
            ModuleBLL mbll  = new ModuleBLL();
            Module    m     = mbll.GetModule(category.ModuleID);

            if (m != null)
            {
                TemplateBind tb = tbbll.GetCategoryTemplateBind(category.ID);
                if (tb != null)
                {
                    string id = this.GetTemplateID(tb.TplPath);
                    if (id != null)
                    {
                        tplID = "/" + id;
                    }
                }
            }

            //设置默认的模板
            if (String.IsNullOrEmpty(tplID))
            {
                tplID = this.FormatTemplatePath("category");
            }

            Category parentCategory = cbll.GetParent(category.Lft, category.Rgt);

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

            //解析模板
            return(MultLangPageUtility.Require(tplID, new
            {
                categoryName = category.Name,
                categoryTag = category.Tag,
                parentCategoryName = parentCategory == null ? "" : parentCategory.Name,
                parentCategoryTag = parentCategory == null ? "" : parentCategory.Tag,
                pageIndex = pageIndex,
                moduleId = category.ModuleID,
                pageTitle = pageIndex == 1 ? "" : "(第" + pageIndex + "页)",
                keywords = category.Keywords,
                description = category.Description
            }));
        }
Example #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()));
            }
        }
Example #6
0
 public int SaveTemplateBind(int refrenceId, TemplateBind templateBind)
 {
     tpldal.SetBind(templateBind.BindType, refrenceId, templateBind.TplPath);
     RepositoryDataCache.ClearTemplateBinds();
     return(templateBind.ID);
 }
Example #7
0
        public override string GetArchive(Category category, Archive archive, params object[] args)
        {
            // return base.GetArchive(category, archive, args);

            #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
            string    tplID = null;
            ModuleBLL mbll  = new ModuleBLL();
            Module    m     = mbll.GetModule(category.ModuleID);
            if (m != null)
            {
                TemplateBind tb = tbbll.GetArchiveTemplateBind(archive.ID, category.ID);
                if (tb != null)
                {
                    string id = this.GetTemplateID(tb.TplPath);
                    if (id != null)
                    {
                        tplID = "/" + id;
                    }
                }
            }

            //设置默认的模板
            if (String.IsNullOrEmpty(tplID))
            {
                tplID = this.FormatTemplatePath("archive");
            }

            string description = ArchiveUtility.GetOutline(archive, 200);



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


            //解析模板
            string html = MultLangPageUtility.Require(tplID,
                                                      new
            {
                id2          = string.IsNullOrEmpty(archive.Alias)?archive.ID:archive.Alias,
                id           = archive.ID,
                title        = archive.Title,
                categoryName = category.Name,
                categoryTag  = category.Tag,
                moduleId     = category.ModuleID,
                author       = archive.Author,
                content      = archive.Content,
                tags         = archive.Tags,
                keywords     = archive.Tags,
                description  = description.Replace("\"", String.Empty),
                outline      = description,
                count        = archive.ViewCount,
                source       = String.IsNullOrEmpty(archive.Source) ? "原创" : archive.Source,
                publishdate  = string.Format("{0:yyyy-MM-dd}", archive.CreateDate)
            });


            HttpRequest request = HttpContext.Current.Request;

            //如果包含查询,则加入标签
            if (!String.IsNullOrEmpty(request.Url.Query))
            {
                //将查询参数作为标签
                html = global::J6.Template.TemplateRegexUtility.Replace(html, a =>
                {
                    if (request[a.Groups[1].Value] != null)
                    {
                        return(request[a.Groups[1].Value]);
                    }
                    return(a.Value);
                });
            }

            //
            //TODO:模板被替换成空白
            //

            return(html);
        }
Example #8
0
        public void Edit_POST()
        {
            HttpRequest request = HttpContext.Current.Request;
            int         id      = int.Parse(request.Form["id"]);
            string      name    = request.Form["tplname"];

            //
            //TODO:加重名验证
            //

            bool result = CmsLogic.Module.UpdateModule(new Models.Module
            {
                ID   = id,
                Name = name
            });

            if (result)
            {
                string categoryTplPath = request.Form["categoryTplPath"],
                       archiveTplPath  = request.Form["archiveTplPath"];

                TemplateBind tb, tb2;

                tb  = CmsLogic.TemplateBind.GetBind(TemplateBindType.ModuleCategoryTemplate, id.ToString());
                tb2 = CmsLogic.TemplateBind.GetBind(TemplateBindType.ModuleArchiveTemplate, id.ToString());

                //如果设置了栏目视图路径,则保存
                if (!String.IsNullOrEmpty(categoryTplPath) || tb != null)
                {
                    if (tb == null)
                    {
                        tb = new TemplateBind
                        {
                            BindType = (int)TemplateBindType.ModuleCategoryTemplate,
                            BindID   = id.ToString()
                        };
                    }
                    tb.TplPath = categoryTplPath;
                    CmsLogic.TemplateBind.SetBind(tb);
                }

                //如果设置了文档视图路径,则保存
                if (!String.IsNullOrEmpty(archiveTplPath) || tb2 != null)
                {
                    if (tb2 == null)
                    {
                        tb2 = new TemplateBind
                        {
                            BindType = (int)TemplateBindType.ModuleArchiveTemplate,
                            BindID   = id.ToString()
                        };
                    }
                    tb2.TplPath = archiveTplPath;
                    CmsLogic.TemplateBind.SetBind(tb2);
                }
                base.RenderSuccess();
                return;
            }

            base.RenderError("");
        }