Exemplo n.º 1
0
        /// <summary>
        /// 删除文章。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LinkButtonDelete_Click(object sender, CommandEventArgs e)
        {
            int articleId;
            if(int.TryParse(e.CommandName, out articleId) == false)
            {
                MessageBox("错误提示", "文章编号必须为整数");
                return;
            }

            // 添加操作日志
            DataManager.LogManager logManager = new DataManager.LogManager();
            int iExecuteNonQuery = 0;

            Wis.Website.DataManager.ArticleManager articleManager = new Wis.Website.DataManager.ArticleManager();
            Wis.Website.DataManager.Article article = articleManager.GetArticle(articleId);
            #warning 删除与该文章相关的图片、视频、软件

            // 重新生成静态页面和关联页面
            DataManager.ReleaseManager releaseManager = new DataManager.ReleaseManager();
            switch (article.Category.ArticleType)
            {
                case 1://ArticleType.Normal:
                    iExecuteNonQuery = articleManager.Remove(article.ArticleGuid);
                    logManager.AddNew(Guid.NewGuid(), Guid.Empty, "删除新闻", article.ArticleGuid, article.Title, System.DateTime.Now);
                    releaseManager.ReleasingRemovedArticle(article);
                    break;
                case 2://ArticleType.Photo:
                    ArticlePhotoManager articlePhotoManager = new ArticlePhotoManager();
                    ArticlePhoto articlePhoto = articlePhotoManager.GetArticlePhoto(article.ArticleGuid);
                    iExecuteNonQuery = articleManager.Remove(articlePhoto.ArticleGuid);
                    logManager.AddNew(Guid.NewGuid(), Guid.Empty, "删除新闻", articlePhoto.ArticleGuid, articlePhoto.Title, System.DateTime.Now);
                    releaseManager.ReleasingRemovedPhotoArticle(articlePhoto);
                    break;
                case 3://ArticleType.Video:
                    VideoArticleManager videoArticleManager = new VideoArticleManager();
                    VideoArticle videoArticle = videoArticleManager.GetVideoArticle(article.ArticleGuid);
                    iExecuteNonQuery = articleManager.Remove(videoArticle.Article.ArticleGuid);
                    logManager.AddNew(Guid.NewGuid(), Guid.Empty, "删除新闻", videoArticle.Article.ArticleGuid, videoArticle.Article.Title, System.DateTime.Now);
                    releaseManager.ReleasingRemovedVideoArticle(videoArticle);
                    break;
                //case ArticleType.Soft:
                //    releaseManager.ReleasingRemovedSoftArticle(article);
                //    break;
                //case ArticleType.Link:
                //    releaseManager.ReleasingRemovedLinkArticle(article);
                //    break;
            }

            if (iExecuteNonQuery > 0)
            {
                Warning.InnerHtml = "删除成功!";
            }
            else
            {
                Warning.InnerHtml = "删除失败!";
            }

            // 重新绑定新闻列表
            BindRepeater();
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            // TODO:同一IP在指定的时间内浏览网页不做统计
            // 获取文章的编号
            string requestArticleId = RequestManager.Request("ArticleId");

            // 文章编号是否为数字
            int articleId;
            if (int.TryParse(requestArticleId, out articleId) == false)
            {
                // 提示失败
                return;
            }

            // 文章是否存在
            ArticleManager articleManager = new ArticleManager();
            Article article = articleManager.GetArticle(articleId);
            if (string.IsNullOrEmpty(article.Title))
            {
                // 提示失败
                return;
            }

            // 更新Article的浏览数
            articleManager.UpdateArticleHits(article.ArticleGuid);

            // 输出浏览数
            context.Response.Write((article.Hits + 1).ToString());
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            // 1 验证验证码
            if (context.Session[CommentVerifyHttpHandler.ConstCommentVerify] == null)
            {
                return;
            }
            string commentVerify1 = context.Session[CommentVerifyHttpHandler.ConstCommentVerify].ToString();
            string commentVerify2 = context.Request[CommentVerifyHttpHandler.ConstCommentVerify];
            if (string.IsNullOrEmpty(commentVerify1) || string.IsNullOrEmpty(commentVerify2))
            {
                return;
            }
            if (commentVerify1.ToUpper() != commentVerify2.ToUpper())
            {
                return;
            }

            // 验证评论数据,两者不能同时为空
            string title = RequestManager.Request("Title");
            string contentHtml = RequestManager.Request("ContentHtml");
            if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(contentHtml))
            {
                return;
            }

            // 评论标题和内过滤Html脚本
            // TODO:过滤内嵌Script脚本、样式
            title = Regex.Replace(title, "<[^>]*>", "");
            contentHtml = Regex.Replace(contentHtml, "<[^>]*>", "");

            // 2 验证评论数据
            // 获取文章的编号
            if (context.Request.UrlReferrer == null)
            {
                return;
            }

            string rawUrl = context.Request.UrlReferrer.AbsoluteUri;
            int charIndex = rawUrl.LastIndexOf('/');
            if (charIndex == -1)
            {
                return;
            }

            // http://localhost:3419/Web/2/2-13/38.htm
            rawUrl = rawUrl.Substring(charIndex + 1); // 38.htm
            charIndex = rawUrl.IndexOf('.');
            if (charIndex == -1)
            {
                return;
            }
            string requestArticleId = rawUrl.Substring(0, charIndex); // RequestManager.Request("ArticleId");

            // 文章编号是否为数字
            int articleId;
            if (int.TryParse(requestArticleId, out articleId) == false)
            {
                // 提示失败
                return;
            }

            // 文章是否存在
            ArticleManager articleManager = new ArticleManager();
            Article article = articleManager.GetArticle(articleId);
            if (string.IsNullOrEmpty(article.Title))
            {
                // 提示失败
                return;
            }

            // 构造评论实体类
            Comment comment = new Comment();

            // 获得实体类
            // TODO:如果前台支持用户注册和登录,获取用户的昵称(唯一不重复)
            comment.Commentator = string.Empty;

            comment.CommentGuid = Guid.NewGuid();
            //comment.CommentId
            comment.ContentHtml = contentHtml;
            comment.DateCreated = DateTime.Now;
            comment.IPAddress = RequestManager.GetClientIP();
            comment.Original = string.Empty;
            comment.SubmissionGuid = article.ArticleGuid;
            comment.Title = title;

            CommentManager commentManager = new CommentManager();
            commentManager.AddNew(comment);

            // TODO:事务处理
            // 更新Article的评论数
            articleManager.UpdateArticleComments(article.ArticleGuid);

            // 清空评论验证码
            context.Session[CommentVerifyHttpHandler.ConstCommentVerify] = null;

            // 输出评论数
            //context.Response.Write((articlePhoto.Comments + 1).ToString());
            // 重新生成 Article
            ReleaseManager releaseManager = new ReleaseManager();
            switch (article.Category.ArticleType)
            {
                case 1://ArticleType.Normal:
                    releaseManager.ReleasingArticleItem(article);
                    break;
                case 2://ArticleType.Photo:
                    ArticlePhotoManager articlePhotoManager = new ArticlePhotoManager();
                    ArticlePhoto articlePhoto = articlePhotoManager.GetArticlePhoto(article.ArticleGuid);
                    releaseManager.ReleasingPhotoArticleItem(articlePhoto);
                    break;
                case 3://ArticleType.Video:
                    VideoArticleManager videoArticleManager = new VideoArticleManager();
                    VideoArticle videoArticle = videoArticleManager.GetVideoArticle(article.ArticleGuid);
                    releaseManager.ReleasingVideoArticleItem(videoArticle);
                    break;
                //case ArticleType.Soft:
                //    releaseManager.ReleasingSoftArticleItem(article);
                //    break;
                //case ArticleType.Link:
                //    releaseManager.ReleasingLinkArticleItem(article);
                //    break;
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // 获取文章信息
            string requestArticleGuid = Request.QueryString["ArticleGuid"];
            //requestArticleGuid = "ceb3f055-a529-468b-a073-c21e542527d5";
            if (string.IsNullOrEmpty(requestArticleGuid) || !Wis.Toolkit.Validator.IsGuid(requestArticleGuid))
            {
                Warning.InnerHtml = "不正确的文章编号,请<a href='ArticleSelectCategory.aspx'>点击这里</a>重新操作";
                return;
            }
            this.ArticleGuid = new Guid(requestArticleGuid);

            if (article == null)
            {
                if (articleManager == null) articleManager = new Wis.Website.DataManager.ArticleManager();
                article = articleManager.GetArticleByArticleGuid(this.ArticleGuid);
            }

            if (releaseManager == null)
            {
                releaseManager = new DataManager.ReleaseManager();
                List<Release> releases = releaseManager.GetReleasesByCategoryGuid(article.Category.CategoryGuid);
                List<Release> relatedReleases = releaseManager.GetRelatedReleases(article.Category.CategoryGuid);
                foreach(Release release in relatedReleases)
                {
                    releases.Add(release);
                }

                RepeaterReleaseList.DataSource = releases;
                RepeaterReleaseList.DataBind();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 绑定新闻列表。
        /// </summary>
        private void BindRepeater()
        {
            // 获取 PageIndex
            int pageIndex;
            string requestPageIndex = Request.QueryString["PageIndex"];
            if (int.TryParse(requestPageIndex, out pageIndex) == false)
                pageIndex = 1;

            string keywords = (Request.QueryString["Keywords"] == null) ? string.Empty : Request.QueryString["Keywords"].Trim();

            // 获取新闻
            Wis.Website.DataManager.ArticleManager articleManager = new Wis.Website.DataManager.ArticleManager();
            List<Wis.Website.DataManager.Article> articles = Wis.Website.DataManager.ArticleManager.GetArticlesByKeywords(keywords, categoryGuid, pageIndex, this.PageSize);

            MiniPager1.RecordCount = articleManager.CountArticlesByKeywords(keywords, categoryGuid);
            MiniPager1.PageIndex = pageIndex;
            MiniPager1.PageSize = this.PageSize;
            string pattern = @"PageIndex=\d+$";
            if (Regex.IsMatch(Request.RawUrl, pattern))
            {
                MiniPager1.UrlPattern = Regex.Replace(Request.RawUrl, pattern, "PageIndex={0}");
            }
            else
            {
                if (Request.RawUrl.IndexOf("?") == -1)
                    MiniPager1.UrlPattern = Request.RawUrl + "?PageIndex={0}";
                else
                    MiniPager1.UrlPattern = Request.RawUrl + "&PageIndex={0}";
            }

            RepeaterArticleList.DataSource = articles;
            RepeaterArticleList.DataBind();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 发布文章。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LinkButtonRelease_Click(object sender, CommandEventArgs e)
        {
            int articleId;
            if (int.TryParse(e.CommandName, out articleId) == false)
            {
                MessageBox("错误提示", "文章编号必须为整数");
                return;
            }
            Wis.Website.DataManager.ArticleManager articleManager = new Wis.Website.DataManager.ArticleManager();
            Wis.Website.DataManager.Article article = articleManager.GetArticle(articleId);

            // 重新生成静态页面和关联页面
            DataManager.ReleaseManager releaseManager = new DataManager.ReleaseManager();
            switch (article.Category.ArticleType)
            {
                case 1://ArticleType.Normal:
                    releaseManager.ReleasingArticle(article);
                    break;
                case 2://ArticleType.Photo:
                    ArticlePhotoManager articlePhotoManager = new ArticlePhotoManager();
                    ArticlePhoto articlePhoto = articlePhotoManager.GetArticlePhoto(article.ArticleGuid);
                    releaseManager.ReleasingPhotoArticle(articlePhoto);
                    break;
                case 3://ArticleType.Video:
                    VideoArticleManager videoArticleManager = new VideoArticleManager();
                    VideoArticle videoArticle = videoArticleManager.GetVideoArticle(article.ArticleGuid);
                    releaseManager.ReleasingVideoArticle(videoArticle);
                    break;
                //case ArticleType.Soft:
                //    releaseManager.ReleasingRemovedSoftArticle(article);
                //    break;
                //case ArticleType.Link:
                //    releaseManager.ReleasingRemovedLinkArticle(article);
                //    break;
            }

            MessageBox("操作提示", "发布成功!");
            //MessageBox("操作提示", "发布失败!");

            // 添加操作日志
            DataManager.LogManager logManager = new DataManager.LogManager();
            logManager.AddNew(Guid.NewGuid(), Guid.Empty, "发布新闻", article.ArticleGuid, article.Title, System.DateTime.Now);
        }
Exemplo n.º 7
0
        protected void ImageButtonNext_Click(object sender, ImageClickEventArgs e)
        {
            // 添加内容,下一步
            if (string.IsNullOrEmpty(category.CategoryName))
            {
                Warning.InnerHtml = "未读取到分类信息,请<a href='ArticleSelectCategory.aspx'>返回</a>选择分类";
                return;
            }

            // 2 判断并校验表单中各录入项的值
            Wis.Website.DataManager.Article article = new Wis.Website.DataManager.Article();

            // TODO:事务处理
            //articleManager.BeginTransaction();

            // 2.1 标题
            // TODO:注入式处理
            article.Title = RequestManager.Request("Title");
            // 2.1.1 判断标题为空
            if (string.IsNullOrEmpty(article.Title))
            {
                Warning.InnerHtml = "标题不能为空";
                return;
            }
            // 2.1.3 判断标题是否包含全角空格符
            if (article.Title.IndexOf(" ") != -1)
            {
                Warning.InnerHtml = "标题不能包含全角空格符";
                return;
            }
            // 2.1.3 判断标题长度
            // TODO:验表单中各录入项的值的长度判断,如果内容过长,数据库会截断或抛异常
            // 可以参考:http://www.china-aspx.com/ShowArticle.aspx?ArticleID=181
            if (article.Title.Length > 128)
            {
                Warning.InnerHtml = string.Format("标题最大长度为128个字符,当前为 {0} 个字符", article.Title.Length);
                return;
            }
            // 2.1.4 判断标题是否重复
            Wis.Website.DataManager.ArticleManager articleManager = new Wis.Website.DataManager.ArticleManager();
            int count = articleManager.CountArticlesByTitle(article.Title);
            if (count > 0)
            {
                Warning.InnerHtml = "标题不能重复";
                return;
            }

            // TODO:过滤非法字符和脏字词语
            //if (ArticleManager.HasBannedWord(articlePhoto.Title) || ArticleManager.HasBannedWord(articlePhoto.ContentHtml))
            //{
            //    Warning.InnerHtml = "对不起, 您提交的内容包含不良信息, 因此无法提交, 请返回修改!";
            //    return;
            //}

            // 3 录入内容
            article.ArticleGuid = Guid.NewGuid();
            // TODO:Author 注入式处理
            article.Author = Author.Value.Replace("'", "\"");
            article.Category = category;
            article.Comments = 0;
            // TODO:ContentHtml 注入式处理
            article.ContentHtml = ContentHtml.Text;
            article.DateCreated = System.DateTime.Now;
            article.Editor = Guid.Empty; // TODO: 当前登录用户
            article.Hits = 0;
            // TODO:MetaDesc 注入式处理
            article.MetaDesc = MetaDesc.Value.Replace("'", "\"");
            // TODO:MetaKeywords 注入式处理
            article.MetaKeywords = MetaKeywords.Value.Replace("'", "\"");
            // TODO:Original 注入式处理
            article.Original = Original.Value.Replace("'", "\"");
            article.Rank = 0;
            // TODO:SubTitle 注入式处理
            article.SubTitle = SubTitle.Value;
            // TODO:Summary 注入式处理
            article.Summary = Summary.Value;
            // TODO:TitleColor 注入式处理
            article.TitleColor = TitleColor.Value;
            article.Votes = 0;

            // articlePhoto 入库
            article.ArticleId = articleManager.AddNew(article);

            // 4 添加主题
            string requestTags = RequestManager.Request("Tags"); // 获取主题
            TagManager tagManager = new TagManager();
            tagManager.AddNew(article.ArticleGuid, requestTags);

            // 5 添加操作日志
            // TODO:完善,保存操作的对象
            DataManager.LogManager logManager = new DataManager.LogManager();
            logManager.AddNew(Guid.NewGuid(), Guid.Empty, "添加新闻", article.ArticleGuid, article.Title, System.DateTime.Now);

            // 6 下一步
            // TODO:创建 ArticleType 表,扩展文章类型
            switch (category.ArticleType)
            {
                case 1: // 普通新闻
                    Response.Redirect("ArticleRelease.aspx?ArticleGuid=" + article.ArticleGuid);
                    break;
                case 2:// 图片新闻
                    Response.Redirect("ArticleAddPhoto.aspx?ArticleGuid=" + article.ArticleGuid);
                    break;
                case 3:// 视频新闻
                    Response.Redirect("ArticleAddVideo.aspx?ArticleGuid=" + article.ArticleGuid);
                    break;
                case 4:// 软件
                    Response.Redirect("ArticleAddSoft.aspx?ArticleGuid=" + article.ArticleGuid);
                    break;
                default:
                    Response.Redirect("ArticleRelease.aspx?ArticleGuid=" + article.ArticleGuid);
                    break;
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// 发布被引用的页面,比如首页某个栏目引用了该分类,专题引用了改分类,把关联的发布页面重新生成
 /// </summary>
 /// <param name="categoryGuid"></param>
 public void ReleasingRelatedReleases(Guid relatedGuid)
 {
     CategoryManager categoryManager = new CategoryManager();
     List<Release> relatedReleases = GetRelatedReleases(relatedGuid);
     foreach (Release relatedRelease in relatedReleases)
     {
         switch (relatedRelease.Template.TemplateType)
         {
             case TemplateType.Index:
                 ReleasingIndex(relatedRelease);
                 break;
             case TemplateType.ArticleItem: // 发布对应分类下的所有文章
                 ArticleManager articleManager = new ArticleManager();
                 List<Article> relatedArticles = articleManager.GetArticlesByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Article relatedArticle in relatedArticles)
                 {
                     ReleasingArticleItem(relatedArticle, relatedRelease);
                 }
                 break;
             case TemplateType.ArticleList: // 发布对应分类下的所有列表页
                 List<Category> relatedArticleListCategories = categoryManager.GetCategorysByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Category relatedCategory in relatedArticleListCategories)
                 {
                     ReleasingArticleList(relatedCategory, relatedRelease);
                 }
                 break;
             case TemplateType.ArticleIndex: // 发布对应分类下的所有索引页
                 List<Category> relatedArticleIndexCategories = categoryManager.GetCategorysByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Category relatedCategory in relatedArticleIndexCategories)
                 {
                     ReleasingArticleIndex(relatedCategory, relatedRelease);
                 }
                 break;
             case TemplateType.Page: // 发布对应的单页
                 PageManager pageManager = new PageManager();
                 List<Page> relatedPages = pageManager.GetPagesByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Page relatedPage in relatedPages)
                 {
                     ReleasingPage(relatedPage, relatedRelease);
                 }
                 break;
             case TemplateType.PhotoArticleItem: // 发布对应分类下的图片新闻
                 ArticlePhotoManager photoArticleManager = new ArticlePhotoManager();
                 List<ArticlePhoto> photoArticles = photoArticleManager.GetPhotoArticlesByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (ArticlePhoto photoArticle in photoArticles)
                 {
                     ReleasingPhotoArticleItem(photoArticle, relatedRelease);
                 }
                 break;
             case TemplateType.PhotoArticleList: // 发布对应分类下的列表页
                 List<Category> relatedPhotoArticleListCategories = categoryManager.GetCategorysByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Category relatedCategory in relatedPhotoArticleListCategories)
                 {
                     ReleasingPhotoArticleList(relatedCategory, relatedRelease);
                 }
                 break;
             case TemplateType.SpecialList: // 发布专题列表页
                 SpecialManager specialManager = new SpecialManager();
                 List<Special> relatedSpecials = specialManager.GetSpecialsByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Special relatedSpecial in relatedSpecials)
                 {
                     ReleasingSpecial(relatedSpecial, relatedRelease);
                 }
                 break;
             case TemplateType.VideoArticleItem: // 发布对应分类下的所有视频文章详细页
                 VideoArticleManager videoArticleManager = new VideoArticleManager();
                 List<VideoArticle> relatedVideoArticles = videoArticleManager.GetVideoArticlesByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (VideoArticle relatedVideoArticle in relatedVideoArticles)
                 {
                     ReleasingVideoArticleItem(relatedVideoArticle, relatedRelease);
                 }
                 break;
             case TemplateType.VideoArticleList: // 发布对应分类下的所有视频列表页
                 List<Category> relatedVideoArticleListCategories = categoryManager.GetCategorysByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Category relatedCategory in relatedVideoArticleListCategories)
                 {
                     ReleasingVideoArticleList(relatedCategory, relatedRelease);
                 }
                 break;
             case TemplateType.VideoArticleIndex: // 发布对应分类下的所有视频索引页
                 List<Category> relatedVideoArticleIndexCategories = categoryManager.GetCategorysByReleaseGuid(relatedRelease.ReleaseGuid);
                 foreach (Category relatedCategory in relatedVideoArticleIndexCategories)
                 {
                     ReleasingVideoArticleIndex(relatedCategory, relatedRelease);
                 }
                 break;
         }
     }
 }