コード例 #1
0
ファイル: CommentHttpHandler.cs プロジェクト: htawab/wiscms
        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;
            }
        }
コード例 #2
0
ファイル: ArticleList.aspx.cs プロジェクト: htawab/wiscms
        /// <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);
        }
コード例 #3
0
ファイル: ArticleList.aspx.cs プロジェクト: htawab/wiscms
        /// <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();
        }
コード例 #4
0
ファイル: ReleaseManager.cs プロジェクト: htawab/wiscms
 /// <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;
         }
     }
 }