Ejemplo n.º 1
0
        /// <summary>
        /// 获取文档的模板ID
        /// </summary>
        /// <param name="category"></param>
        /// <param name="archive"></param>
        /// <returns></returns>
        public virtual string GetArchiveTemplateID(ArchiveDto archive)
        {
            ////获取模板ID
            //string tplID = null;
            //Module m = CmsLogic.Module.GetModule(archive.Category.ModuleID);
            //if (m != null)
            //{
            //    TemplateBind tb = CmsLogic.TemplateBind.GetArchiveTemplateBind(archive.ID, archive.Category.ID);
            //    if (tb != null)
            //    {
            //        string id = this.GetTemplateID(tb.TplPath);
            //        if (id != null)
            //        {
            //            tplID = "/" + id;
            //        }
            //    }
            //}

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

            if (archive.TemplatePath!=null)
            {
                return "/" + this.GetTemplateID(archive.TemplatePath);
            }
            //设置默认的模板
            return this.FormatTemplatePath("archive");
        }
Ejemplo n.º 2
0
        public int SaveArchive(int siteId, ArchiveDto archiveDto)
        {

            IContentContainer ic = this._contentRep.GetContent(siteId);
            IArchive archive;

            if (archiveDto.Id <= 0)
            {
                archive = ic.CreateArchive(-1, archiveDto.StrId, archiveDto.Category.ID, archiveDto.Title);
            }
            else
            {
                archive = ic.GetArchiveById(archiveDto.Id);

                //修改栏目
                if (archiveDto.Category.ID != archive.Category.ID)
                {
                    ISite site = this._siteRep.GetSiteById(siteId);
                    archive.Category = site.GetCategory(archiveDto.Category.ID);
                }
            }


            archive.LastModifyDate = DateTime.Now;
            archive.Content = archiveDto.Content;
            archive.Alias = archiveDto.Alias;
            archive.Author = archiveDto.Author;
            archive.Flags = archiveDto.Flags;
            archive.Outline = archiveDto.Outline;
            archive.Source = archiveDto.Source;
            archive.Tags = archiveDto.Tags;
            archive.Thumbnail = archiveDto.Thumbnail;
            archive.Title = archiveDto.Title;
            archive.ExtendValues = archiveDto.ExtendValues;

            //只更新自己的模板
            if (archiveDto.IsSelfTemplate
                || (archive.ID == -1 && !String.IsNullOrEmpty(archiveDto.TemplatePath))
                )
            {
                archive.UpdateTemplateBind(archiveDto.TemplatePath);
            }

            return archive.Save();
        }
Ejemplo n.º 3
0
        public virtual string GetArchive(ArchiveDto archive, params object[] 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 = this.GetArchiveTemplateID(archive);
            CategoryDto category = archive.Category;

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

            //解析模板
            string html = PageUtility.Require(tplID,

                                              page =>
                                              {

                                                  page.AddVariable("site",this.site);

                                                  PageArchive 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 = String.Format("{0}_{1}_{2}", archive.Title, category.Name, site.SeoTitle),
                                                      SubTitle = site.SeoTitle,
                                                      Keywords = archive.Tags,
                                                      Description = pageArchive.Outline.Replace("\"", String.Empty)
                                                  });

                                              });

            /*
            HttpRequest request = HttpContext.Current.Request;

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

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

            return html;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建新的文档
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private int CreateNewArchive(DataPack data)
        {
            bool visible = request.Form["visible"] == "on";
            int categoryID = int.Parse(request.Form["category"]);
            string author = UserState.Administrator.Current.UserName;

            //string[,] flags;
            string flags = ArchiveFlag.GetFlagString(false, false, visible, false, null);

            ArchiveDto archive = new ArchiveDto
            {
                Agree = 0,
                Disagree = 0,
                Category = new CategoryDto {ID = categoryID},
                Flags = flags,
                Author = author,
                Tags = String.Empty,
                Outline = String.Empty,
                Source = String.Empty,
                Title = data["title"],
                Content = ReplaceContent(data["content"]),
                CreateDate = DateTime.Now
            };

            return ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, archive);
        }
Ejemplo n.º 5
0
        private IEnumerable<ArchiveDto> GetArchiveEnumertor(IEnumerable<IArchive> archives)
        {
            IDictionary<int, CategoryDto> categories = new Dictionary<int, CategoryDto>();
            ArchiveDto archive;
            CategoryDto cateDto;
            int categoryId;
            foreach (IArchive ia in archives)
            {
                archive = new ArchiveDto
                {
                    StrId = ia.StrID,
                    Id = ia.ID,
                    Author = ia.Author,
                    Alias = ia.Alias,
                    Agree = ia.Agree,
                    Disagree = ia.Disagree,
                    Content = ia.Content,
                    CreateDate = ia.CreateDate,
                    // FirstImageUrl=ia.FirstImageUrl,
                    Flags = ia.Flags,
                    Tags = ia.Tags,
                    LastModifyDate = ia.LastModifyDate,
                    Source = ia.Source,
                    Thumbnail = ia.Thumbnail,
                    Title = ia.Title,
                    ViewCount = ia.ViewCount,
                    Outline = ia.Outline,
                    //TemplateBind=null,
                    ExtendValues = ia.ExtendValues
                };

                //archive = new ArchiveDto().CloneData(ia);
                //archive.ID = ia.ID;

                if (!categories.TryGetValue(categoryId = ia.Category.ID, out cateDto))
                {
                    cateDto = CategoryDto.ConvertFrom(ia.Category);
                    categories.Add(categoryId, cateDto);
                }
                archive.Category = cateDto;
                yield return archive;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 执行删除文章操作
 /// </summary>
 /// <param name="archive"></param>
 public static void DeleteArchive(ArchiveDto archive)
 {
     if (OnArchiveDeleted != null) OnArchiveDeleted(archive);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 创建新文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="post"></param>
        /// <param name="publish"></param>
        /// <returns></returns>
        public string newPost(string blogid, string username, string password, Post post, bool publish)
        {
            User user;
            if ((user = ValidUser(username, password)) != null)
            {
                int categoryId = 0;
                string categoryName = post.categories[0];

                //根据提交的栏目设置栏目ID
                if (post.categories.Length != 0)
                {
                    var category = ServiceCall.Instance.SiteService.GetCategoryByName(this.siteId, categoryName);
                    if (category.ID > 0) categoryId = category.ID;
                }

                //如果栏目ID仍然为0,则设置第一个栏目
                if (categoryId == 0)
                {
                    throw new Exception("请选择分类!");
                }

                string flag = ArchiveFlag.GetFlagString(false, false, publish, false, null);

                ArchiveDto dto = new ArchiveDto
                {
                    Title = post.title,
                    Author = username,
                    Outline = String.Empty,
                    Content = post.description,
                    CreateDate = post.dateCreated,
                    Source = post.source.name,
                    ViewCount = 1,
                    Flags = flag,
                    Tags = String.Empty
                };
                dto.Category = new CategoryDto { ID = categoryId };

                return ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, dto).ToString(); ;

                //执行监视服务
                /*
                try
                {
                    WatchService.PublishArchive(abll.GetArchiveByID(id));
                }
                catch { }
                 */
            }

            return null;
        }
Ejemplo n.º 8
0
 protected string Require(string idOrAlias)
 {
     ArchiveDto a = ServiceCall.Instance.ArchiveService.GetArchiveByIdOrAlias(this.siteId, idOrAlias);
     if (a.Id > 0) archive = a;
     return string.Empty;
 }
Ejemplo n.º 9
0
        private ArchiveDto GetFormCopyedArchive(int siteId, NameValueCollection form, ArchiveDto archive, string alias)
        {
            string flag = ArchiveFlag.GetFlagString(
                form["IsSystem"] == "on",   //系统
                form["IsSpecial"] == "on",  //特殊
                form["IsNotVisible"] != "on",    //隐藏
                form["AsPage"] == "on",     //作为单页
                null);

            string content = form["Content"];

            //自动替换Tags
            if (form["autotag"] == "on")
            {
                //todo:顺序调换了下
                HttpTags _tags = this.GetTags(siteId);
                content = _tags.Tags.RemoveAutoTags(content);
                content = _tags.Tags.ReplaceSingleTag(content);
            }

            archive.LastModifyDate = DateTime.Now;
            archive.Title = form["Title"];
            archive.Source = form["Source"];
            archive.Outline = form["Outline"];
            archive.Alias = alias;
            archive.Flags = flag;
            archive.Tags = form["Tags"].Replace(",", ",");
            archive.Content = content;
            archive.Thumbnail = form["Thumbnail"];

            //分类
            int categoryID = int.Parse(form["categoryid"]);
            archive.Category = new CategoryDto { ID = categoryID };

            //检测图片是否为默认图片
            if (archive.Thumbnail == CmsVariables.FRAMEWORK_ARCHIVE_NoPhoto)
                archive.Thumbnail = String.Empty;

            archive.ExtendValues = new List<IExtendValue>();

            //=============== 更新扩展字段 ===================

            IExtendField field;
            string extendValue;
            foreach (string key in form.Keys)
            {
                if (key.StartsWith("extend_"))
                {
                    extendValue = form[key];
                    field = new ExtendField(int.Parse(key.Substring(7)), null);
                    archive.ExtendValues.Add(new ExtendValue(-1, field, extendValue));

                }
            }

            //更新模板设置
            archive.TemplatePath = form["TemplatePath"];
            if (archive.TemplatePath != String.Empty)
            {
                archive.IsSelfTemplate = true;
            }
            return archive;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 执行发布文档操作
 /// </summary>
 /// <param name="archive"></param>
 public static void PublishArchive(ArchiveDto archive)
 {
     if (OnArchivePublished != null)OnArchiveUpdated(archive);
 }
Ejemplo n.º 11
0
        protected void FormatArchive(StringBuilder sb, ArchiveDto archive, string format, IEnumerable<ArchiveDto> dt, int index)
        {
            string id = string.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias;

            //读取自定义扩展数据字段
            IDictionary<string, string> extendFields = null;

            sb.Append(tplengine.FieldTemplate(format,
                field =>
                {
                    switch (field)
                    {

                        case "title": return archive.Title;
                        case "title2": return !ArchiveFlag.GetFlag(archive.Flags, BuiltInArchiveFlags.IsSpecial) ?
                            archive.Title : "<span class=\"special\">" + archive.Title + "</span>";

                        case "author": return archive.Author;

                        //
                        //TODO:Archive应持有一个author
                        //
                        //case "authorname": return ArchiveUtility.GetAuthorName(dr["author"].ToString());
                        case "source": return archive.Source == "" ? "原创" : archive.Source;
                        case "outline": return ArchiveUtility.GetOutline(String.IsNullOrEmpty(archive.Outline) ? archive.Content : archive.Outline, this.TplSetting.CFG_OutlineLength);
                        case "initid": return archive.Id.ToString();
                        case "id": return id;      //用于链接的ID标识
                        case "tags": return archive.Tags;
                        case "replay": return CmsLogic.Comment.GetArchiveCommentsCount(archive.StrId).ToString();
                        case "count": return archive.ViewCount.ToString();

                        //时间
                        case "modifytime": return String.Format("{0:yyyy-MM-dd HH:mm:ss}", archive.LastModifyDate);
                        case "modifytime2": return String.Format("{0:yyyy-MM-dd}", archive.LastModifyDate);
                        case "createtime": return String.Format("{0:yyyy-MM-dd HH:mm:ss}", archive.CreateDate);
                        case "createtime2": return String.Format("{0:yyyy-MM-dd}", archive.CreateDate);

                        //栏目
                        // case "categoryid":
                        // case "cid": return archive.Category.ID.ToString();
                        case "categoryname":
                        case "cname": return archive.Category.Name;
                        case "categorytag":
                        case "ctag": return archive.Category.Tag;
                        case "curl": return this.GetCategoryUrl(archive.Category, 1);


                        //
                        //TODO:
                        //
                        //链接
                        case "url":
                            return GetArchiveUrl(archive.Flags, archive.Category, id);

                        //内容
                        case "content": return archive.Content;

                        //压缩过的内容
                        case "content2":
                            return Regex.Replace(archive.Content, "\\r|\\t|\\s\\s", String.Empty);

                        //图片元素
                        case "img":
                            string url = archive.Thumbnail;
                            return String.IsNullOrEmpty(url) ? "" : String.Format("<img class=\"thumb thumbnail\" src=\"{0}\" alt=\"{1}\"/>", url, archive.Title);

                        //缩略图
                        case "thumb": return this.GetThumbnailUrl(archive.FirstImageUrl);

                        case "thumbnail": return this.GetThumbnailUrl(archive.Thumbnail);

                        // 项目顺序类
                        case "class":
                            if (dt == null || index <= 0) return String.Empty;
                            if (index == dt.Count() - 1) return " class=\"last\"";
                            else if (index == 0) return " class=\"first\"";
                            return String.Concat(" class=\"item", index.ToString(), "\"");

                        //特性列表
                        case "prolist":
                            StringBuilder sb2 = new StringBuilder();
                            sb.Append("<ul class=\"extend_field_list\">");

                            foreach (IExtendValue f in archive.ExtendValues)
                            {
                                if (!String.IsNullOrEmpty(f.Value))
                                {
                                    sb.Append("<li class=\"extend_")
                                       .Append(f.Field.ToString()).Append("\"><span class=\"attrName\">")
                                        .Append(f.Field.Name).Append(":</span><span class=\"value\">")
                                        .Append(f.Value).Append("</span></li>");
                                }
                            }

                            sb2.Append("</ul>");
                            return sb2.ToString();

                        default:

                            //读取自定义长度大纲
                            const string matchPattern = "outline\\[(\\d+)\\]";
                            if (Regex.IsMatch(field, matchPattern))
                            {
                                int length = int.Parse(Regex.Match(field, matchPattern).Groups[1].Value);
                                return ArchiveUtility.GetOutline(String.IsNullOrEmpty(archive.Outline) ? archive.Content : archive.Outline, length);
                            }

                            //读取自定义属性
                            if (extendFields == null)
                            {
                                extendFields = new Dictionary<string, string>();
                                foreach (IExtendValue value in archive.ExtendValues)
                                {
                                    extendFields.Add(value.Field.Name, value.Value);
                                }
                            }
                            if (extendFields.ContainsKey(field))
                                return extendFields[field];
                            return "";
                    }
                }));

        }
Ejemplo n.º 12
0
 /// <summary>
 /// 执行文档查看操作
 /// </summary>
 /// <param name="archive"></param>
 public static void ViewArchive(ArchiveDto archive)
 {
     if (OnArchiveViewed != null) OnArchiveViewed(archive);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 执行文档更新操作
 /// </summary>
 /// <param name="archive"></param>
 public static void UpdateArchive(ArchiveDto archive)
 {
     if (OnArchiveUpdated != null) OnArchiveUpdated(archive);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 更新文档之前发生
 /// </summary>
 /// <param name="archive"></param>
 public static void PrevUpdateArchive(ArchiveDto archive)
 {
     if (OnPrevArchiveUpdate != null) OnPrevArchiveUpdate(archive);
 }
Ejemplo n.º 15
0
 public PageArchive(ArchiveDto archive)
 {
     this.Archive = archive;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// 转换文档传输对象
        /// </summary>
        /// <param name="archive">文档</param>
        /// <returns></returns>
        public static ArchiveDto ConvertFrom(IArchive archive,bool copyCategory,bool copyTemplate,bool copyExtend)
        {
            ArchiveDto dto = new ArchiveDto
            {
                Id = archive.ID,
                StrId = archive.StrID,
                Disagree = archive.Disagree,
                Agree = archive.Agree,
                LastModifyDate = archive.LastModifyDate,
                CreateDate = archive.CreateDate,
                Content = archive.Content,
                Alias = archive.Alias,
                Author = archive.Author,
                Flags = archive.Flags,
                Outline = archive.Outline,
                Source = archive.Source,
                Tags = archive.Tags,
                Thumbnail = archive.Thumbnail,
                Title = archive.Title,
                ViewCount = archive.ViewCount
            };

            if(copyCategory)
            {
                CategoryDto categoryDto = CategoryDto.ConvertFrom(archive.Category);
                categoryDto.ID = archive.Category.ID;
                dto.Category = categoryDto;
            }

            if(copyExtend)
            {
                dto.ExtendValues = archive.ExtendValues;
            }

            if (copyTemplate)
            {
                if (archive.Template != null)// && archive.Template.BindRefrenceId == archive.ID)
                {
                    dto.TemplatePath = archive.Template.TplPath;
                    dto.IsSelfTemplate = archive.Template.BindRefrenceId == archive.ID;
                }
            }
            return dto;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 创建新的文档
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private int CreateNewArchive(int categoryId, string content, string thumbnail, string author, string flag, DataPack data)
        {
            ArchiveDto archive = new ArchiveDto
            {
                Agree = 0,
                Disagree = 0,
                Category = new CategoryDto { Id = categoryId },
                Flags = flag,
                Author = author,
                Tags = String.Empty,
                Outline = String.Empty,
                Source = String.Empty,
                Title = data["title"],
                Content = content,
                LastModifyDate = DateTime.Now,
                CreateDate = DateTime.Now,
                Thumbnail = thumbnail
            };

            return ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, archive);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 删除文档前发生
 /// </summary>
 /// <param name="archive"></param>
 public static void PrevDeleteArchive(ArchiveDto archive)
 {
     if (OnPrevArchiveDelete != null) OnPrevArchiveDelete(archive);
 }