public ActionResult ForwardMicroblog(string forwardBody)
        {
            if (!ValidateContentLength(forwardBody))
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "内容超出字数限制!") }));
            }

            bool isBanned = ModelState.HasBannedWord();

            forwardBody = Tunynet.Utilities.WebUtility.HtmlEncode(forwardBody);
            if (isBanned)
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "内容中包含非法词语!") }));
            }

            bool isCommnet         = Request.Form.GetBool("isCommnet", false);
            bool isCommentOriginal = Request.Form.GetBool("isCommentOriginal", false);

            IUser currentUser = UserContext.CurrentUser;

            MicroblogEntity microblog = MicroblogEntity.New();

            microblog.Body                 = string.IsNullOrEmpty(forwardBody) ? "转发微博" : forwardBody;
            microblog.Author               = currentUser.DisplayName;
            microblog.UserId               = currentUser.UserId;
            microblog.OwnerId              = currentUser.UserId;
            microblog.TenantTypeId         = TenantTypeIds.Instance().User();
            microblog.ForwardedMicroblogId = Request.Form.Get <long>("forwardedMicroblogId", 0);
            microblog.OriginalMicroblogId  = Request.Form.Get <long>("originalMicroblogId", 0);

            if (!authorizer.Microblog_Create(microblog.TenantTypeId, microblog.OwnerId))
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "您没有权限进行转发!") }));
            }

            long toUserId         = Request.Form.Get <long>("toUserId", 0);
            long toOriginalUserId = Request.Form.Get <long>("toOriginalUserId", 0);
            //reply:已修改
            long microblogId = 0;
            bool isSuccess   = microblogService.Forward(microblog, isCommnet, isCommentOriginal, toUserId, toOriginalUserId, out microblogId);

            if (isSuccess)
            {
                string url = SiteUrls.Instance()._Microblog(microblogId);
                return(Json(new { Url = url, MessageData = new StatusMessageData(StatusMessageType.Success, "转发成功!") }));
            }
            else
            {
                return(Json(new { MessageData = new StatusMessageData(StatusMessageType.Error, "转发失败!") }));
            }
        }
        public ActionResult Create(string spaceKey, string microblogBody, string tenantTypeId = null, long ownerId = 0, string imageUrl = null)
        {
            if (string.IsNullOrEmpty(microblogBody))
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容不能为空!" }));
            }
            if (!ValidateContentLength(microblogBody))
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容不能超过140个字!" }));
            }

            //当前用户登录
            IUser currentUser = UserContext.CurrentUser;

            bool            isBanned = ModelState.HasBannedWord();
            MicroblogEntity entity   = MicroblogEntity.New();

            entity.Author       = currentUser.DisplayName;
            entity.Body         = Tunynet.Utilities.WebUtility.HtmlEncode(microblogBody);
            entity.PostWay      = PostWay.Web;
            entity.TenantTypeId = !string.IsNullOrEmpty(tenantTypeId) ? tenantTypeId : TenantTypeIds.Instance().User();
            entity.UserId       = currentUser.UserId;
            entity.OwnerId      = ownerId > 0 ? ownerId : currentUser.UserId;

            if (!authorizer.Microblog_Create(entity.TenantTypeId, entity.OwnerId))
            {
                return(HttpNotFound());
            }

            //判断是否当前有,图片附件
            HttpCookie cookie = Request.Cookies["microblog_PhotoExists"];

            if (cookie != null && cookie.Value.Trim().ToLower().Equals("true"))
            {
                entity.HasPhoto = true;
                cookie.Value    = "";
                Response.Cookies.Set(cookie);
            }

            if (!string.IsNullOrEmpty(imageUrl))
            {
                //by zhaoyx:获取到的图片地址如果带有“-”字符的话,会被ModelBinder屏蔽掉,导致图片无法加载
                imageUrl        = Request["imageUrl"];
                entity.HasPhoto = true;
            }

            bool isSuccess = false;

            if (!isBanned)
            {
                isSuccess = microblogService.Create(entity) > 0;
            }

            //by zhengw:
            if (isSuccess)
            {
                //处理imageUrl
                if (!string.IsNullOrEmpty(imageUrl))
                {
                    DownloadRemoteImage(imageUrl, entity.MicroblogId);
                }

                //同步微博
                var accountBindingService = new AccountBindingService();
                foreach (var accountType in accountBindingService.GetAccountTypes(true, true))
                {
                    bool isSync = Request.Form.GetBool("sync_" + accountType.AccountTypeKey, false);
                    if (isSync)
                    {
                        var account = accountBindingService.GetAccountBinding(currentUser.UserId, accountType.AccountTypeKey);
                        if (account != null)
                        {
                            var thirdAccountGetter = ThirdAccountGetterFactory.GetThirdAccountGetter(accountType.AccountTypeKey);
                            if (entity.HasPhoto)
                            {
                                byte[] bytes       = null;
                                var    attachments = attachmentService.GetsByAssociateId(entity.MicroblogId);
                                string fileName    = null;
                                if (attachments.Count() > 0)
                                {
                                    var            attachment    = attachments.First();
                                    IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();
                                    IStoreFile     storeFile     = storeProvider.GetResizedImage(attachment.GetRelativePath(), attachment.FileName, new Size(405, 600), Tunynet.Imaging.ResizeMethod.KeepAspectRatio);
                                    using (Stream stream = storeFile.OpenReadStream())
                                    {
                                        bytes = StreamToBytes(stream);
                                        stream.Dispose();
                                        stream.Close();
                                    }
                                    fileName = attachment.FriendlyFileName;
                                }
                                thirdAccountGetter.CreatePhotoMicroBlog(account.AccessToken, microblogBody, bytes, fileName, account.Identification);
                            }
                            else
                            {
                                thirdAccountGetter.CreateMicroBlog(account.AccessToken, microblogBody, account.Identification);
                            }
                        }
                    }
                }
                if ((int)entity.AuditStatus > (int)(new AuditService().GetPubliclyAuditStatus(MicroblogConfig.Instance().ApplicationId)))
                {
                    return(Json(new { MessageType = StatusMessageType.Success, MessageContent = "发布成功", id = entity.MicroblogId }));
                }
                else
                {
                    return(Json(new { MessageType = StatusMessageType.Hint, MessageContent = "尚未通过审核,请耐心等待", id = entity.MicroblogId }));
                }
            }

            if (isBanned)
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "内容中有非法词语!" }));
            }
            else
            {
                return(Json(new { MessageType = StatusMessageType.Error, MessageContent = "创建失败请联系管理员!" }));
            }
        }
Example #3
0
        public ActionResult Comment(MicroblogCommentEditModel model)
        {
            string message = string.Empty;

            if (ModelState.HasBannedWord(out message))
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, message)));
            }

            IUser currentUser = UserContext.CurrentUser;
            long  userId      = microblogService.Get(model.CommentedObjectId).UserId;

            //被评论用户的隐私判断

            if (!privacyService.Validate(userId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().Comment()))
            {
                return(Json(new StatusMessageData(StatusMessageType.Hint, "该用户不允许你评论他的内容!")));
            }

            CommentService commentService = new CommentService();

            if (model.IsValidate)
            {
                Comment comment = model.AsComment();

                if (comment.ParentId != 0)
                {
                    Comment parentComment = commentService.Get(comment.ParentId);
                    if (parentComment != null)
                    {
                        comment.IsPrivate = parentComment.IsPrivate ? true : comment.IsPrivate;
                    }
                }

                if (commentService.Create(comment))
                {
                    if (model.CommentOriginalAuthor)
                    {
                        MicroblogEntity entity = microblogService.Get(comment.CommentedObjectId);


                        if (entity != null)
                        {
                            Comment originalAuthorComment = model.AsComment();
                            entity = entity.OriginalMicroblog;
                            if (entity != null)
                            {
                                originalAuthorComment.ToUserId          = entity.UserId;
                                originalAuthorComment.ToUserDisplayName = entity.User.DisplayName;
                                originalAuthorComment.CommentedObjectId = entity.MicroblogId;
                                commentService.Create(originalAuthorComment);
                            }
                        }
                    }
                    if (model.ForwardMicrobo)
                    {
                        MicroblogEntity microblogEntity = microblogService.Get(model.CommentedObjectId);
                        if (microblogEntity != null)
                        {
                            MicroblogEntity microblog = MicroblogEntity.New();
                            microblog.Body         = "转发微博";
                            microblog.Author       = currentUser.DisplayName;
                            microblog.UserId       = currentUser.UserId;
                            microblog.OwnerId      = currentUser.UserId;
                            microblog.TenantTypeId = TenantTypeIds.Instance().User();

                            microblog.ForwardedMicroblogId = microblogEntity.MicroblogId;
                            microblog.OriginalMicroblogId  = microblogEntity.OriginalMicroblogId > 0 ? microblogEntity.OriginalMicroblogId : microblog.ForwardedMicroblogId;

                            long toUserId = microblog.UserId;

                            MicroblogEntity entity           = microblogService.Get(microblog.OriginalMicroblogId);
                            long            toOriginalUserId = entity == null ? 0 : entity.UserId;

                            microblogService.Forward(microblog, false, false, toUserId, toOriginalUserId);
                        }
                    }
                    return(Json(new { commentid = comment.Id }));
                }
            }
            WebUtility.SetStatusCodeForError(Response);
            return(Json(new StatusMessageData(StatusMessageType.Error, "创建留言失败了!")));
        }