Beispiel #1
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));
        }
Beispiel #2
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)
        {
            UserDto 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,
                    PublisherId = user.Id,
                    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);
        }
Beispiel #3
0
        private DataPackFunc GetDataPackHandler(int categoryId)
        {
            int    publisherId;
            string flag;
            bool   isAutoTag;
            bool   removeLink;
            bool   dlPic;

            publisherId = UserState.Administrator.Current.Id;

            flag = ArchiveFlag.GetFlagString(
                false,
                false,
                request.Form["visible"] == "on",
                false,
                null);

            isAutoTag  = request.Form["autotag"] == "on";
            removeLink = request.Form["removelink"] == "on";
            dlPic      = request.Form["dlpic"] == "on";
            string   domain = null;
            HttpTags _tags  = this.GetTags(siteId);

            return(data =>
            {
                string content = data["content"];
                string thumbnail = data["thumbnail"] ?? (data["image"] ?? "");
                bool thumbIsNull = String.IsNullOrEmpty(thumbnail);

                if (domain == null)
                {
                    Match m = Regex.Match(data.ReferenceUrl, "((http|https)://[^/]+)/(.+?)"
                                          , RegexOptions.IgnoreCase);
                    domain = m.Groups[1].Value;
                }

                //替换src
                content = srcRegex.Replace(content, "$1" + domain + "/");
                if (!thumbIsNull && thumbnail[0] == '/')
                {
                    thumbnail = domain + thumbnail;
                }

                //移除链接
                if (removeLink)
                {
                    content = linkRegex.Replace(content, "$1");
                }

                //远程下载
                if (dlPic)
                {
                    content = AutoUpload(content);
                    if (!thumbIsNull)
                    {
                        thumbnail = downloadThumbnail(thumbnail);
                    }
                }


                //自动替换Tags
                if (isAutoTag)
                {
                    // content = _tags.Tags.RemoveAutoTags(content);
                    content = _tags.Tags.ReplaceSingleTag(content);
                }

                this.CreateNewArchive(categoryId, content, thumbnail, publisherId, flag, data);
            });
        }
Beispiel #4
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);
        }