private Boolean checkCreatorPermission( ForumTopic topic ) {
     if (topic.Creator.Id != ctx.viewer.Id) {
         echoText( alang( "exRewardSelfOnly" ) );
         return false;
     }
     return true;
 }
        private static Boolean isTopicFound( List<StickyTopic> stickyList, ForumTopic ft ) {

            foreach (StickyTopic t in stickyList) {
                if (t.Id == ft.Id) return true;
            }
            return false;
        }
 private Boolean boardError( ForumTopic topic ) {
     if (ctx.GetLong( "boardId" ) != topic.ForumBoard.Id) {
         echoRedirect( lang( "exNoPermission" ) + ": borad id error" );
         return true;
     }
     return false;
 }
        public virtual Result Buy( int buyerId, int creatorId, ForumTopic topic )
        {
            Result result = new Result();
            if (userIncomeService.HasEnoughKeyIncome( buyerId, topic.Price ) == false) {
                result.Add( String.Format( alang.get( typeof( ForumApp ), "exIncome" ), KeyCurrency.Instance.Name ) );
                return result;
            }

            // 日志:买方减少收入
            UserIncomeLog log = new UserIncomeLog();
            log.UserId = buyerId;
            log.CurrencyId = KeyCurrency.Instance.Id;
            log.Income = -topic.Price;
            log.DataId = topic.Id;
            log.ActionId = actionId;
            db.insert( log );

            // 日志:卖方增加收入
            UserIncomeLog log2 = new UserIncomeLog();
            log2.UserId = creatorId;
            log2.CurrencyId = KeyCurrency.Instance.Id;
            log2.Income = topic.Price;
            log2.DataId = topic.Id;
            log2.ActionId = actionId;
            db.insert( log2 );

            userIncomeService.AddKeyIncome( buyerId, -topic.Price );
            userIncomeService.AddKeyIncome( creatorId, topic.Price );

            return result;
        }
Beispiel #5
0
        public virtual Result Buy( int buyerId, int creatorId, ForumTopic topic )
        {
            if (topic == null) throw new ArgumentNullException( "ForumBuyLogService.Buy" );

            Result result = new Result();
            if (topic.Price <= 0) {
                result.Add( "topic.price <=0" );
                return result;
            }

            if (incomeService.HasEnoughKeyIncome( buyerId, topic.Price ) == false) {
                result.Add( String.Format( alang.get( typeof( ForumApp ), "exIncome" ), KeyCurrency.Instance.Name ) );
                return result;
            }

            // 购买日志
            ForumBuyLog log = new ForumBuyLog();
            log.UserId = buyerId;
            log.TopicId = topic.Id;
            log.insert();

            String msg = string.Format( "访问需要购买的帖子 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
            incomeService.AddKeyIncome( buyerId, -topic.Price, msg );

            String msg2 = string.Format( "销售帖子 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
            incomeService.AddKeyIncome( creatorId, topic.Price, msg2 );

            return result;
        }
 private void setCategory( ForumTopic topic, ForumBoard board ) {
     List<ForumCategory> categories = categoryService.GetByBoard( board.Id );
     if (categories.Count > 0) {
         categories.Insert( 0, new ForumCategory( 0, alang( "plsSelectCategory" ) ) );
         long categoryId = topic.Category == null ? 0 : topic.Category.Id;
         set( "post.Category", Html.DropList( categories, "CategoryId", "Name", "Id", categoryId ) );
     }
     else {
         set( "post.Category", string.Empty );
     }
 }
        private static void updatePost( ForumTopic post ) {

            if (post.OwnerType != typeof( Site ).FullName) return;

            IMember owner = Site.Instance;
            int appId = post.AppId;

            IndexViewCacher.Update( owner, appId );
            BoardViewCacher.Update( owner, appId, post.ForumBoard.Id, 1 );
            RecentViewCacher.Update( owner, appId, "Topic" );

        }
Beispiel #8
0
        public void CreateByTemp( String ids, ForumTopic topic )
        {
            int[] arrIds = cvt.ToIntArray( ids );
            if (arrIds.Length == 0) return;

            ForumTopicService topicService = new ForumTopicService();

            ForumPost post = topicService.GetPostByTopic( topic.Id );

            int attachmentCount = 0;
            foreach (int id in arrIds) {

                AttachmentTemp _temp = AttachmentTemp.findById( id );
                if (_temp == null) continue;

                Attachment a = new Attachment();

                a.AppId = _temp.AppId;
                a.Guid = _temp.Guid;

                a.FileSize = _temp.FileSize;
                a.Type = _temp.Type;
                a.Name = _temp.Name;

                a.Description = _temp.Description;
                a.ReadPermission = _temp.ReadPermission;
                a.Price = _temp.Price;

                a.TopicId = topic.Id;
                a.PostId = post.Id;

                a.OwnerId = topic.OwnerId;
                a.OwnerType = topic.OwnerType;
                a.OwnerUrl = topic.OwnerUrl;
                a.Creator = topic.Creator;
                a.CreatorUrl = topic.CreatorUrl;

                a.insert();

                _temp.delete();

                attachmentCount++;

            }

            if (attachmentCount > 0) {
                String msg = string.Format( "上传附件 <a href=\"{0}\">{1}</a>,获得奖励", alink.ToAppData( topic ), topic.Title );
                incomeService.AddIncome( topic.Creator, UserAction.Forum_AddAttachment.Id, msg );
            }

            topicService.UpdateAttachments( topic, attachmentCount );
        }
        public void CreateByTemp( String ids, ForumTopic topic )
        {
            int[] arrIds = cvt.ToIntArray( ids );
            if (arrIds.Length == 0) return;

            ForumTopicService topicService = new ForumTopicService();

            ForumPost post = topicService.GetPostByTopic( topic.Id );

            int attachmentCount = 0;
            foreach (int id in arrIds) {

                AttachmentTemp at = AttachmentTemp.findById( id );
                if (at == null) continue;

                Attachment a = new Attachment();

                a.AppId = at.AppId;
                a.Guid = at.Guid;

                a.FileSize = at.FileSize;
                a.Type = at.Type;
                a.Name = at.Name;

                a.Description = at.Description;
                a.ReadPermission = at.ReadPermission;
                a.Price = at.Price;

                a.TopicId = topic.Id;
                a.PostId = post.Id;

                a.OwnerId = topic.OwnerId;
                a.OwnerType = topic.OwnerType;
                a.OwnerUrl = topic.OwnerUrl;
                a.Creator = topic.Creator;
                a.CreatorUrl = topic.CreatorUrl;

                a.insert();

                at.delete();

                attachmentCount++;

            }

            topicService.UpdateAttachments( topic, attachmentCount );
        }
    //adds a new post to db
    public bool addPost(string postTitle, string firstComment, string username)
    {
        ForumDAO dataLayer = new ForumDAO();
        ForumTopic topic = new ForumTopic();
        topic.createdBy = username;
        topic.createdOnDate = DateTime.Now;
        topic.title = postTitle;
        int topicID = dataLayer.createNewTopic(topic);

        Comment comment = new Comment();
        comment.comment = firstComment;
        comment.username = username;
        comment.createdOnDate = DateTime.Now;
        comment.forumTopic = topicID;
        bool success = dataLayer.addComment(comment);

        return success;
    }
    /**
     * this mehtod load all fourm topics
     * */
    public List<ForumTopic> getAllTopics()
    {
        List<ForumTopic> topics = new List<ForumTopic>();
        String database = System.Configuration.ConfigurationManager.ConnectionStrings["programaholics_anonymous_databaseConnectionString"].ConnectionString;
        using (OleDbConnection sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + database))
        {
            try
            {

                String query = "SELECT * FROM [forum_topic] ORDER BY [createdOnDate]";
                OleDbDataAdapter adapter = new OleDbDataAdapter(query, sqlConn);
                ForumTopicDataSet ds = new ForumTopicDataSet();
                adapter.Fill(ds, "forum_topic");
                DataTable table = ds.Tables["forum_topic"];

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    ForumTopic topic = new ForumTopic();
                    DataRow currentRow = table.Rows[i];
                    topic.ID = Convert.ToInt32(currentRow["ID"]);
                    topic.title = currentRow["title"].ToString();
                    topic.createdBy = currentRow["createdBy"].ToString();
                    topic.createdOnDate = DateTime.Parse(currentRow["createdOnDate"].ToString());

                    topics.Add(topic);
                }

            }
            catch (OleDbException ex)
            {

            }
            finally
            {
                sqlConn.Close();

            }
            return topics;
        }
    }
        private void bindTopicOne( IBlock block, ForumTopic topic ) {

            String typeImg = string.Empty;
            if (strUtil.HasText( topic.TypeName )) {
                typeImg = string.Format( "<img src='{0}apps/forum/{1}.gif'>", sys.Path.Skin, topic.TypeName );
            }

            block.Set( "p.Id", topic.Id );
            block.Set( "p.TypeImg", typeImg );
            block.Set( "p.TitleStyle", topic.TitleStyle );
            block.Set( "p.Titile", topic.Title );
            block.Set( "p.Author", topic.Creator.Name );

            block.Set( "p.Url", Link.To( topic.OwnerType, topic.OwnerUrl, new TopicController().Show, topic.Id, topic.AppId ) );

            block.Set( "p.Created", topic.Created );
            block.Set( "p.ReplyCount", topic.Replies );
            block.Set( "p.Hits", topic.Hits.ToString() );

            String attachments = topic.Attachments > 0 ? "<img src='" + sys.Path.Img + "attachment.gif'/>" : "";
            block.Set( "p.Attachments", attachments );

            block.Next();
        }
 private String getRewardInfo( ForumTopic topic, String rewardInfo ) {
     if (topic.RewardAvailable == 0) {
         rewardInfo = "(" + alang( "resolved" ) + ")";
     }
     else {
         rewardInfo = string.Format( "({0}{1})", topic.Reward, KeyCurrency.Instance.Unit );
     }
     if (DateTime.Now.Subtract( topic.Created ).Days >= ForumConfig.Instance.QuestionExpiryDay) {
     }
     return rewardInfo;
 }
 private Boolean checkIsLockPrivate( ForumTopic topic ) {
     if (topic.IsLocked == 1) {
         echoRedirect( alang( "exLockTip" ) );
         return false;
     }
     return true;
 }
Beispiel #15
0
 private void forwardToPre( ForumTopic topic )
 {
     ForumTopic next = topicService.GetNext( topic );
     if (next == null) {
         echoRedirect( alang( "exLastTopic" ) );
     }
     else {
         redirect( Show, next.Id );
     }
 }
    private int SaveTopic( ForumTopic item )
    {
        int rowsAffected = 0;
        try
        {
            Session["CurrentObject"] = item.Save();
            rowsAffected = 1;
        }
        catch ( Csla.Validation.ValidationException ex )
        {
            System.Text.StringBuilder message = new System.Text.StringBuilder();
            message.AppendFormat( "{0}<br/>", ex.Message );
            if ( item.BrokenRulesCollection.Count == 1 )
                message.AppendFormat( "* {0}: {1}", item.BrokenRulesCollection[0].Property, item.BrokenRulesCollection[0].Description );
            else
                foreach ( Csla.Validation.BrokenRule rule in item.BrokenRulesCollection )
                    message.AppendFormat( "* {0}: {1}<br/>", rule.Property, rule.Description );

            PostError.Visible = true;
            PostError.Text = message.ToString();
            rowsAffected = 0;
        }
        catch ( Csla.DataPortalException ex )
        {
            PostError.Visible = true;
            PostError.Text = ex.BusinessException.Message;
            rowsAffected = 0;
        }
        catch ( Exception ex )
        {
            PostError.Visible = true;
            PostError.Text = ex.Message;
            rowsAffected = 0;
        }
        return rowsAffected;
    }
Beispiel #17
0
        private void bindFormNew( ForumTopic topic, ForumPost lastPost, IBlock formBlock )
        {
            User user = ctx.viewer.obj as User;
            if (strUtil.HasText( user.Pic )) {
                formBlock.Set( "currentUser", "<img src=\"" + user.PicMedium + "\"/>" );
            }
            else {
                formBlock.Set( "currentUser", user.Name );
            }

            formBlock.Set( "post.ReplyActionUrl", Link.To( new Users.PostController().Create ) + "?boardId=" + topic.ForumBoard.Id );
            formBlock.Set( "post.ReplyTitle", "re:" + topic.Title );
            formBlock.Set( "post.TopicId", topic.Id );
            formBlock.Set( "post.ParentId", lastPost.Id );
            formBlock.Set( "forumBoard.Id", topic.ForumBoard.Id );

            Editor ed = Editor.NewOne( "Content", "", "150px", sys.Path.Editor, MvcConfig.Instance.JsVersion, Editor.ToolbarType.Basic );
            ed.AddUploadUrl( ctx );

            formBlock.Set( "Editor", ed );
            formBlock.Next();
        }
Beispiel #18
0
 private void forwardPreNext( ForumTopic topic )
 {
     if (ctx.url.Query.Equals( "?next" )) {
         forwardToPre( topic );
     }
     else if (ctx.url.Query.Equals( "?pre" )) {
         forwardToNext( topic );
     }
 }
        public virtual ForumTopicPageModel PrepareForumTopicPageModel(ForumTopic forumTopic, int page)
        {
            if (forumTopic == null)
            {
                throw new ArgumentNullException("forumTopic");
            }

            //load posts
            var posts = _forumService.GetAllPosts(forumTopic.Id, 0, string.Empty,
                                                  page - 1, _forumSettings.PostsPageSize);

            //prepare model
            var model = new ForumTopicPageModel();

            model.Id      = forumTopic.Id;
            model.Subject = forumTopic.Subject;
            model.SeName  = forumTopic.GetSeName();

            model.IsCustomerAllowedToEditTopic   = _forumService.IsCustomerAllowedToEditTopic(_workContext.CurrentCustomer, forumTopic);
            model.IsCustomerAllowedToDeleteTopic = _forumService.IsCustomerAllowedToDeleteTopic(_workContext.CurrentCustomer, forumTopic);
            model.IsCustomerAllowedToMoveTopic   = _forumService.IsCustomerAllowedToMoveTopic(_workContext.CurrentCustomer, forumTopic);
            model.IsCustomerAllowedToSubscribe   = _forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer);

            if (model.IsCustomerAllowedToSubscribe)
            {
                model.WatchTopicText = _localizationService.GetResource("Forum.WatchTopic");

                var forumTopicSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id, 0, forumTopic.Id, 0, 1).FirstOrDefault();
                if (forumTopicSubscription != null)
                {
                    model.WatchTopicText = _localizationService.GetResource("Forum.UnwatchTopic");
                }
            }
            model.PostsPageIndex    = posts.PageIndex;
            model.PostsPageSize     = posts.PageSize;
            model.PostsTotalRecords = posts.TotalCount;
            foreach (var post in posts)
            {
                var forumPostModel = new ForumPostModel
                {
                    Id               = post.Id,
                    ForumTopicId     = post.TopicId,
                    ForumTopicSeName = forumTopic.GetSeName(),
                    FormattedText    = post.FormatPostText(),
                    IsCurrentCustomerAllowedToEditPost   = _forumService.IsCustomerAllowedToEditPost(_workContext.CurrentCustomer, post),
                    IsCurrentCustomerAllowedToDeletePost = _forumService.IsCustomerAllowedToDeletePost(_workContext.CurrentCustomer, post),
                    CustomerId               = post.CustomerId,
                    AllowViewingProfiles     = _customerSettings.AllowViewingProfiles && !post.Customer.IsGuest(),
                    CustomerName             = post.Customer.FormatUserName(),
                    IsCustomerForumModerator = post.Customer.IsForumModerator(),
                    ShowCustomersPostCount   = _forumSettings.ShowCustomersPostCount,
                    ForumPostCount           = post.Customer.GetAttribute <int>(SystemCustomerAttributeNames.ForumPostCount),
                    ShowCustomersJoinDate    = _customerSettings.ShowCustomersJoinDate && !post.Customer.IsGuest(),
                    CustomerJoinDate         = post.Customer.CreatedOnUtc,
                    AllowPrivateMessages     = _forumSettings.AllowPrivateMessages && !post.Customer.IsGuest(),
                    SignaturesEnabled        = _forumSettings.SignaturesEnabled,
                    FormattedSignature       = post.Customer.GetAttribute <string>(SystemCustomerAttributeNames.Signature).FormatForumSignatureText(),
                };
                //created on string
                if (_forumSettings.RelativeDateTimeFormattingEnabled)
                {
                    forumPostModel.PostCreatedOnStr = post.CreatedOnUtc.RelativeFormat(true, "f");
                }
                else
                {
                    forumPostModel.PostCreatedOnStr =
                        _dateTimeHelper.ConvertToUserTime(post.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
                }
                //avatar
                if (_customerSettings.AllowCustomersToUploadAvatars)
                {
                    forumPostModel.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                        post.Customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mediaSettings.AvatarPictureSize,
                        _customerSettings.DefaultAvatarEnabled,
                        defaultPictureType: PictureType.Avatar);
                }
                //location
                forumPostModel.ShowCustomersLocation = _customerSettings.ShowCustomersLocation && !post.Customer.IsGuest();
                if (_customerSettings.ShowCustomersLocation)
                {
                    var countryId = post.Customer.GetAttribute <int>(SystemCustomerAttributeNames.CountryId);
                    var country   = _countryService.GetCountryById(countryId);
                    forumPostModel.CustomerLocation = country != null?country.GetLocalized(x => x.Name) : string.Empty;
                }

                //votes
                if (_forumSettings.AllowPostVoting)
                {
                    forumPostModel.AllowPostVoting = true;
                    forumPostModel.VoteCount       = post.VoteCount;
                    var postVote = _forumService.GetPostVote(post.Id, _workContext.CurrentCustomer);
                    if (postVote != null)
                    {
                        forumPostModel.VoteIsUp = postVote.IsUp;
                    }
                }

                // page number is needed for creating post link in _ForumPost partial view
                forumPostModel.CurrentTopicPage = page;
                model.ForumPostModels.Add(forumPostModel);
            }

            return(model);
        }
Beispiel #20
0
        public virtual IActionResult TopicCreate(EditForumTopicModel model)
        {
            if (!_forumSettings.ForumsEnabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var forum = _forumService.GetForumById(model.ForumId);

            if (forum == null)
            {
                return(RedirectToRoute("Boards"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!_forumService.IsCustomerAllowedToCreateTopic(_workContext.CurrentCustomer, forum))
                    {
                        return(Challenge());
                    }

                    var subject          = model.Subject;
                    var maxSubjectLength = _forumSettings.TopicSubjectMaxLength;
                    if (maxSubjectLength > 0 && subject.Length > maxSubjectLength)
                    {
                        subject = subject.Substring(0, maxSubjectLength);
                    }

                    var text          = model.Text;
                    var maxPostLength = _forumSettings.PostMaxLength;
                    if (maxPostLength > 0 && text.Length > maxPostLength)
                    {
                        text = text.Substring(0, maxPostLength);
                    }

                    var topicType = ForumTopicType.Normal;

                    var ipAddress = _webHelper.GetCurrentIpAddress();

                    var nowUtc = DateTime.UtcNow;

                    if (_forumService.IsCustomerAllowedToSetTopicPriority(_workContext.CurrentCustomer))
                    {
                        topicType = (ForumTopicType)Enum.ToObject(typeof(ForumTopicType), model.TopicTypeId);
                    }

                    //forum topic
                    var forumTopic = new ForumTopic
                    {
                        ForumId      = forum.Id,
                        CustomerId   = _workContext.CurrentCustomer.Id,
                        TopicTypeId  = (int)topicType,
                        Subject      = subject,
                        CreatedOnUtc = nowUtc,
                        UpdatedOnUtc = nowUtc
                    };
                    _forumService.InsertTopic(forumTopic, true);

                    //forum post
                    var forumPost = new ForumPost
                    {
                        TopicId      = forumTopic.Id,
                        CustomerId   = _workContext.CurrentCustomer.Id,
                        Text         = text,
                        IPAddress    = ipAddress,
                        CreatedOnUtc = nowUtc,
                        UpdatedOnUtc = nowUtc
                    };
                    _forumService.InsertPost(forumPost, false);

                    //update forum topic
                    forumTopic.NumPosts           = 1;
                    forumTopic.LastPostId         = forumPost.Id;
                    forumTopic.LastPostCustomerId = forumPost.CustomerId;
                    forumTopic.LastPostTime       = forumPost.CreatedOnUtc;
                    forumTopic.UpdatedOnUtc       = nowUtc;
                    _forumService.UpdateTopic(forumTopic);

                    //subscription
                    if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
                    {
                        if (model.Subscribed)
                        {
                            var forumSubscription = new ForumSubscription
                            {
                                SubscriptionGuid = Guid.NewGuid(),
                                CustomerId       = _workContext.CurrentCustomer.Id,
                                TopicId          = forumTopic.Id,
                                CreatedOnUtc     = nowUtc
                            };

                            _forumService.InsertSubscription(forumSubscription);
                        }
                    }

                    return(RedirectToRoute("TopicSlug", new { id = forumTopic.Id, slug = _forumService.GetTopicSeName(forumTopic) }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            //redisplay form
            _forumModelFactory.PrepareTopicCreateModel(forum, model);
            return(View(model));
        }
Beispiel #21
0
 public virtual DataPage <ForumTopic> GetPickedByApp(int appId, int pageSize)
 {
     return(ForumTopic.findPage("AppId=" + appId + " and IsPicked=1 and " + TopicStatus.GetShowCondition(), pageSize));
 }
Beispiel #22
0
 public virtual List <ForumTopic> GetByAppAndReplies(int appId, int count)
 {
     return(ForumTopic.find("AppId=" + appId + " and " + TopicStatus.GetShowCondition() + " order by Replies desc, Id desc").list(count));
 }
Beispiel #23
0
 public virtual List <ForumTopic> GetByApp(int appId, int count)
 {
     return(ForumTopic.find("AppId=" + appId + " and " + TopicStatus.GetShowCondition()).list(count));
 }
Beispiel #24
0
        public virtual int GetBoardPage(int topicId, int boardId, int pageSize)
        {
            int count = ForumTopic.count("Id>=" + topicId + " and ForumBoardId=" + boardId + " and " + TopicStatus.GetShowCondition());

            return(getPage(count, pageSize));
        }
Beispiel #25
0
        //--------------------------------------------------------------------------------



        public virtual void UpdateAttachmentPermission(ForumTopic topic, int ischeck)
        {
            topic.IsAttachmentLogin = ischeck;
            topic.update("IsAttachmentLogin");
        }
        public void Can_save_and_load_forumpost()
        {
            var customer       = GetTestCustomer();
            var customerFromDb = SaveAndLoadEntity(customer);

            customerFromDb.ShouldNotBeNull();

            var forumGroup = new ForumGroup
            {
                Name         = "Forum Group 1",
                Description  = "Forum Group 1 Description",
                DisplayOrder = 1,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow
            };

            var forumGroupFromDb = SaveAndLoadEntity(forumGroup);

            forumGroupFromDb.ShouldNotBeNull();
            forumGroupFromDb.Name.ShouldEqual("Forum Group 1");
            forumGroupFromDb.Description.ShouldEqual("Forum Group 1 Description");
            forumGroupFromDb.DisplayOrder.ShouldEqual(1);

            var forum = new Forum
            {
                ForumGroup   = forumGroupFromDb,
                Name         = "Forum 1",
                Description  = "Forum 1 Description",
                ForumGroupId = forumGroupFromDb.Id,
                DisplayOrder = 10,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
                NumPosts     = 25,
                NumTopics    = 15
            };

            forumGroup.Forums.Add(forum);
            var forumFromDb = SaveAndLoadEntity(forum);

            forumFromDb.ShouldNotBeNull();
            forumFromDb.Name.ShouldEqual("Forum 1");
            forumFromDb.Description.ShouldEqual("Forum 1 Description");
            forumFromDb.DisplayOrder.ShouldEqual(10);
            forumFromDb.NumTopics.ShouldEqual(15);
            forumFromDb.NumPosts.ShouldEqual(25);
            forumFromDb.ForumGroupId.ShouldEqual(forumGroupFromDb.Id);

            var forumTopic = new ForumTopic
            {
                Subject      = "Forum Topic 1",
                ForumId      = forumFromDb.Id,
                TopicTypeId  = (int)ForumTopicType.Sticky,
                Views        = 123,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
                NumPosts     = 100,
                CustomerId   = customerFromDb.Id,
                Published    = true
            };

            var forumTopicFromDb = SaveAndLoadEntity(forumTopic);

            forumTopicFromDb.ShouldNotBeNull();
            forumTopicFromDb.Subject.ShouldEqual("Forum Topic 1");
            forumTopicFromDb.Views.ShouldEqual(123);
            forumTopicFromDb.NumPosts.ShouldEqual(100);
            forumTopicFromDb.TopicTypeId.ShouldEqual((int)ForumTopicType.Sticky);
            forumTopicFromDb.ForumId.ShouldEqual(forumFromDb.Id);

            var forumPost = new ForumPost
            {
                Text         = "Forum Post 1 Text",
                ForumTopic   = forumTopicFromDb,
                TopicId      = forumTopicFromDb.Id,
                IPAddress    = "127.0.0.1",
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
                CustomerId   = customerFromDb.Id,
                Published    = true
            };

            var forumPostFromDb = SaveAndLoadEntity(forumPost);

            forumPostFromDb.ShouldNotBeNull();
            forumPostFromDb.Text.ShouldEqual("Forum Post 1 Text");
            forumPostFromDb.IPAddress.ShouldEqual("127.0.0.1");
            forumPostFromDb.TopicId.ShouldEqual(forumTopicFromDb.Id);
        }
        public async Task AddForumTokens(LiquidObject liquidObject, Customer customer, Store store, Forum forum, ForumTopic forumTopic = null, ForumPost forumPost = null,
                                         int?friendlyForumTopicPageIndex = null, string appendedPostIdentifierAnchor = "")
        {
            var liquidForum = new LiquidForums(forum, forumTopic, forumPost, customer, store, friendlyForumTopicPageIndex, appendedPostIdentifierAnchor);

            liquidObject.Forums = liquidForum;

            await _mediator.EntityTokensAdded(forum, liquidForum, liquidObject);

            await _mediator.EntityTokensAdded(forumTopic, liquidForum, liquidObject);

            await _mediator.EntityTokensAdded(forumPost, liquidForum, liquidObject);
        }
Beispiel #28
0
        private void addNotificationToParentCreator( ForumTopic topic, ForumPost post )
        {
            User creator = post.Creator;
            if (post.ParentId <= 0) return;

            // 如果不清理缓存,则parent.Creator就是null(受制于ORM查询的关联深度只有2级)
            ForumPost parent = db.nocache.findById<ForumPost>( post.ParentId );
            if (parent == null) return;

            User parentUser = userService.GetById( parent.Creator.Id );
            if (parentUser == null) return;

            int parentReceiverId = parent.Creator.Id;
            parentReceiverId = parent.Creator.Id;
            int topicReceiverId = topic.Creator.Id;
            if (parentReceiverId == creator.Id || parentReceiverId == topicReceiverId) return;

            String msgToParent = "<a href=\"" + Link.ToMember( creator ) + "\">" + creator.Name + "</a> " + alang.get( typeof( ForumApp ), "replyYourPost" ) + " <a href=\"" + alink.ToAppData( post ) + "\">" + topic.Title + "</a>";
            notificationService.send( parentReceiverId, typeof( User ).FullName, msgToParent, NotificationType.Comment );
        }
        public void Can_save_and_load_forum_subscription_topic_subscribed()
        {
            var customer       = GetTestCustomer();
            var customerFromDb = SaveAndLoadEntity(customer);

            customerFromDb.ShouldNotBeNull();

            var forumGroup = new ForumGroup
            {
                Name         = "Forum Group 1",
                Description  = "Forum Group 1 Description",
                DisplayOrder = 1,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow
            };

            var forumGroupFromDb = SaveAndLoadEntity(forumGroup);

            forumGroupFromDb.ShouldNotBeNull();
            forumGroupFromDb.Name.ShouldEqual("Forum Group 1");
            forumGroupFromDb.Description.ShouldEqual("Forum Group 1 Description");
            forumGroupFromDb.DisplayOrder.ShouldEqual(1);

            var forum = new Forum
            {
                ForumGroup   = forumGroupFromDb,
                Name         = "Forum 1",
                Description  = "Forum 1 Description",
                ForumGroupId = forumGroupFromDb.Id,
                DisplayOrder = 10,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
                NumPosts     = 25,
                NumTopics    = 15
            };

            forumGroup.Forums.Add(forum);
            var forumFromDb = SaveAndLoadEntity(forum);

            forumFromDb.ShouldNotBeNull();
            forumFromDb.Name.ShouldEqual("Forum 1");
            forumFromDb.Description.ShouldEqual("Forum 1 Description");
            forumFromDb.DisplayOrder.ShouldEqual(10);
            forumFromDb.NumTopics.ShouldEqual(15);
            forumFromDb.NumPosts.ShouldEqual(25);
            forumFromDb.ForumGroupId.ShouldEqual(forumGroupFromDb.Id);

            var forumTopic = new ForumTopic
            {
                Subject      = "Forum Topic 1",
                Forum        = forumFromDb,
                ForumId      = forumFromDb.Id,
                TopicTypeId  = (int)ForumTopicType.Sticky,
                Views        = 123,
                CreatedOnUtc = DateTime.UtcNow,
                UpdatedOnUtc = DateTime.UtcNow,
                NumPosts     = 100,
                CustomerId   = customerFromDb.Id,
                Published    = true
            };

            var forumTopicFromDb = SaveAndLoadEntity(forumTopic);

            forumTopicFromDb.ShouldNotBeNull();
            forumTopicFromDb.Subject.ShouldEqual("Forum Topic 1");
            forumTopicFromDb.Views.ShouldEqual(123);
            forumTopicFromDb.NumPosts.ShouldEqual(100);
            forumTopicFromDb.TopicTypeId.ShouldEqual((int)ForumTopicType.Sticky);
            forumTopicFromDb.ForumId.ShouldEqual(forumFromDb.Id);

            var forumSubscription = new ForumSubscription
            {
                CreatedOnUtc     = DateTime.UtcNow,
                SubscriptionGuid = new Guid("11111111-2222-3333-4444-555555555555"),
                TopicId          = forumTopicFromDb.Id,
                CustomerId       = customerFromDb.Id,
            };

            var forumSubscriptionFromDb = SaveAndLoadEntity(forumSubscription);

            forumSubscriptionFromDb.ShouldNotBeNull();
            forumSubscriptionFromDb.SubscriptionGuid.ToString().ShouldEqual("11111111-2222-3333-4444-555555555555");
            forumSubscriptionFromDb.TopicId.ShouldEqual(forumTopicFromDb.Id);
            forumSubscriptionFromDb.ForumId.ShouldEqual(0);
        }
Beispiel #30
0
 //-----------------------------------------------------------------------------------------------
 private void bindForm( ForumTopic topic, ISecurity board, ForumPost lastPost )
 {
     IBlock formBlock = getBlock( "form" );
     //if (topic.IsLocked == 1) return;
     //ISecurityAction replyAction = ForumAction.Get( new PostController().ReplyPost, ctx.route.getRootNamespace() );
     //if (PermissionUtil.HasAction( (User)ctx.viewer.obj, board, replyAction, ctx ))
     bindFormNew( topic, lastPost, formBlock );
 }
Beispiel #31
0
 public virtual void SubstractTopicReward(ForumTopic topic, int postValue)
 {
     topic.RewardAvailable -= postValue;
     db.update(topic, "RewardAvailable");
 }
Beispiel #32
0
        private void bindPosts( int id, ForumTopic topic, ForumBoard board, int userId )
        {
            DataPage<ForumPost> list = postService.GetPageList( id, getPageSize( ctx.app.obj ), userId );

            ForumPost lastPost = getLastPost( list, topic.Id );

            List<Attachment> attachments = attachService.GetByTopic( list.Results );
            UserIncomeUtil.AddIncomeListToUser( list.Results );

            forwardPreNext( topic );

            WebUtils.pageTitle( this, topic.Title, board.Name );
            Page.Keywords = topic.Tag.TextString;

            List<ForumBoard> pathboards = getTree().GetPath( board.Id );
            set( "location", ForumLocationUtil.GetTopic( pathboards, topic, ctx ) );

            set( "newReplyUrl", Link.To( new Users.PostController().ReplyTopic, id ) + "?boardId=" + topic.ForumBoard.Id );
            set( "newTopicUrl", Link.To( new Users.TopicController().NewTopic ) + "?boardId=" + topic.ForumBoard.Id );

            ctx.SetItem( "forumTopic", topic );
            ctx.SetItem( "forumBoard", board );
            ctx.SetItem( "posts", list.Results );
            ctx.SetItem( "attachs", attachments );
            ctx.SetItem( "pageSize", getPageSize( ctx.app.obj ) );

            load( "postBlock", new PostBlockController().Show );

            bindForm( topic, board, lastPost );

            list.RecordCount++;

            String pager = list.PageCount > 1 ? list.PageBar : "";
            set( "page", pager );
        }
Beispiel #33
0
 private IMember getOwner( ForumTopic topic )
 {
     if (topic.OwnerType == typeof( Site ).FullName) return Site.Instance;
     return ndb.findById( Entity.GetType( topic.OwnerType ), topic.OwnerId ) as IMember;
 }
Beispiel #34
0
 private void forwardToNext( ForumTopic topic )
 {
     ForumTopic pre = topicService.GetPre( topic );
     if (pre == null) {
         echoRedirect( alang( "exFirstTopic" ) );
     }
     else {
         redirect( Show, pre.Id );
     }
 }
        public void Show()
        {
            List <ForumPost>  posts   = ctx.GetItem("posts") as List <ForumPost>;
            List <Attachment> attachs = ctx.GetItem("attachs") as List <Attachment>;
            int pageSize = cvt.ToInt(ctx.GetItem("pageSize"));

            this.board = ctx.GetItem("forumBoard") as ForumBoard;
            ForumTopic topic = ctx.GetItem("forumTopic") as ForumTopic;

            IBlock block = getBlock("posts");

            for (int i = 0; i < posts.Count; i++)
            {
                ForumPost data = posts[i];
                if (data.Creator == null)
                {
                    continue;
                }

                getPostTopic(data);

                block.Set("post.Id", data.Id);
                block.Set("post.MemberName", data.Creator.Name);
                block.Set("post.MemberUrl", Link.ToMember(data.Creator));

                String face = "";
                if (strUtil.HasText(data.Creator.Pic))
                {
                    face = string.Format("<img src=\"{0}\"/>", data.Creator.PicMedium);
                }

                block.Set("post.MemberFace", face);


                block.Set("post.MemberRank", getRankStr(data));
                block.Set("post.StarList", data.Creator.Rank.StarHtml);
                block.Set("post.IncomeList", data.Creator.IncomeInfo);
                block.Set("post.MemberTitle", getUserTitle(data));
                block.Set("post.MemberGender", data.Creator.GenderString);
                block.Set("post.MemberPostCount", data.Creator.PostCount);
                block.Set("post.MemberCreateTime", data.Creator.Created.ToShortDateString());
                block.Set("post.UserLastLogin", data.Creator.LastLoginTime.ToShortDateString());

                String signature = strUtil.HasText(data.Creator.Signature) ? "<div class=\"posC\">" + data.Creator.Signature + "</div>" : "";
                block.Set("post.UserSignature", signature);

                block.Set("post.OnlyOneMember", Link.To(new TopicController().Show, data.TopicId) + "?userId=" + data.Creator.Id);
                block.Set("post.FloorNo", getFloorNumber(pageSize, i));
                block.Set("post.Title", addRewardInfo(data, data.Title));

                block.Set("post.TitleText", data.Title);

                block.Set("post.Admin", getAdminString(data));
                block.Set("post.CreateTime", data.Created);

                List <Attachment> attachList = getAttachByPost(attachs, data.Id);

                if (data.ParentId == 0)
                {
                    bindTopicOne(block, data, attachList);
                }
                else
                {
                    bindPostOne(block, data, attachList);
                }

                block.Set("adForumPosts", AdItem.GetAdById(AdCategory.ForumPosts));


                block.Next();
            }

            set("moderatorJson", moderatorService.GetModeratorJson(board));
            set("creatorId", topic.Creator.Id);
            set("tagAction", to(new Edits.TagController().SaveTag, topic.Id));
        }
Beispiel #36
0
 private Boolean haveReadPermission( ForumTopic topic )
 {
     if (ctx.viewer.IsLogin == false) return false;
     if (ctx.viewer.Id == topic.Creator.Id) return true;
     int permission = incomeService.GetUserIncome( ctx.viewer.Id, Currency.ReadPermission().Id ).Income;
     return permission >= topic.ReadPermission;
 }
Beispiel #37
0
 public virtual void AddHits(ForumTopic topic)
 {
     //topic.Hits++;
     //db.update( topic, "Hits" );
     HitsJob.Add(topic);
 }
        private void bindTopicOne( IBlock block, ForumTopic topic ) {

            if (topic.ForumBoard == null) return;
            if (topic.Creator == null) return;

            String rewardInfo = string.Empty;
            if (topic.Reward > 0) rewardInfo = getRewardInfo( topic, rewardInfo );

            String lblCategory = string.Empty;
            if (topic.Category != null && topic.Category.Id > 0) {
                String lnkCategory = to( new BoardController().Category, topic.ForumBoard.Id ) + "?categoryId=" + topic.Category.Id;
                lblCategory = string.Format( "<a href='{0}'>[<span style=\"color:{2}\">{1}]</span></a>&nbsp;", lnkCategory, topic.Category.Name, topic.Category.NameColor );
            }

            String typeImg = string.Empty;
            if (strUtil.HasText( topic.TypeName )) {
                typeImg = string.Format( "<img src='{0}apps/forum/{1}.gif'>", sys.Path.Skin, topic.TypeName );
            }

            String priceInfo = string.Empty;
            if (topic.Price > 0) {
                priceInfo = alang( "price" ) + " :" + topic.Price + " ";
            }

            String permissionInfo = string.Empty;
            if (topic.ReadPermission > 0) {
                permissionInfo = alang( "readPermission" ) + ":" + topic.ReadPermission + "";
            }

            block.Set( "p.Id", topic.Id );
            block.Set( "p.Category", lblCategory );
            block.Set( "p.TypeImg", typeImg );
            block.Set( "p.Reward", rewardInfo );
            block.Set( "p.Price", priceInfo );
            block.Set( "p.ReadPermission", permissionInfo );
            block.Set( "p.TitleStyle", topic.TitleStyle );
            block.Set( "p.Titile", strUtil.CutString( topic.Title, 30 ) );
            block.Set( "p.Url", to( new TopicController().Show, topic.Id ) );

            block.Set( "p.BoardName", topic.ForumBoard.Name );
            block.Set( "p.BoardLink", alink.ToAppData(topic.ForumBoard) );


            block.Set( "p.MemberName", topic.Creator.Name );
            block.Set( "p.MemberUrl", toUser( topic.Creator ) );
            block.Set( "p.CreateTime", topic.Created );
            block.Set( "p.ReplyCount", topic.Replies );
            block.Set( "p.Hits", topic.Hits.ToString() );
            block.Set( "p.LastUpdate", topic.Replied.GetDateTimeFormats( 'g' )[0] );
            block.Set( "p.LastReplyUrl", toUser( topic.RepliedUserFriendUrl ) );
            block.Set( "p.LastReplyName", topic.RepliedUserName );

            String attachments = topic.Attachments > 0 ? "<img src='" + sys.Path.Img + "attachment.gif'/>" : "";
            block.Set( "p.Attachments", attachments );

            String statusImg;

            if (topic.IsLocked == 1)
                statusImg = sys.Path.Skin + "apps/forum/lock.gif";
            else if (topic.IsPicked == 1)
                statusImg = sys.Path.Skin + "apps/forum/pick.gif";
            else
                statusImg = sys.Path.Skin + "apps/forum/topic.gif";

            block.Set( "postStatusImage", statusImg );
            block.Next();
        }
Beispiel #39
0
 public virtual void UpdateReply(ForumTopic topic)
 {
     db.update(topic, new string[] { "Replies", "RepliedUserName", "RepliedUserFriendUrl", "Replied" });
 }
        private void bindRewardInfo( ForumTopic topic ) {

            List<ForumBoard> pathboards = getTree().GetPath( topic.ForumBoard.Id );
            set( "location", ForumLocationUtil.GetSetReward( pathboards, topic, ctx ) );

            int rewardAvailable = topic.RewardAvailable;

            set( "currency.Name", KeyCurrency.Instance.Name );
            set( "post.Reward", topic.Reward );
            set( "post.RewardSetted", topic.Reward - rewardAvailable );
            set( "post.RewardAvailable", rewardAvailable );

            String rewardInfo = string.Format( alang( "rewardInfo" ), (topic.Reward - rewardAvailable), rewardAvailable );
            set( "rewardInfo", rewardInfo );
        }
Beispiel #41
0
        public virtual void AddFeedInfo(ForumTopic data)
        {
            String msg = GetFeedMsg(data);

            microblogService.AddSimple(data.Creator, msg, typeof(ForumTopic).FullName, data.Id, data.Ip);
        }
Beispiel #42
0
 public virtual ForumTopic GetPre(ForumTopic topic)
 {
     return(db.find <ForumTopic>("Replied>:replied and " + getCondition(topic.ForumBoard.Id) + " order by Replied asc, Id asc")
            .set("replied", topic.Created)
            .first());
 }
Beispiel #43
0
 public virtual Result CreateTopic(ForumTopic topic, User user, IMember owner, IApp app)
 {
     populateData(topic, user, owner, app.Id);
     return(saveToDb(topic, user, app));
 }
 public virtual Boolean HasBuyed( int buyerId, ForumTopic topic )
 {
     return ( db.count<UserIncomeLog>( "DataId=" + topic.Id + " and UserId=" + buyerId + " and ActionId=" + actionId ) > 0);
 }
Beispiel #45
0
        //-------------------------------------------------------------------------------------------------
        private static ForumTopic getTopicBySticky( StickyTopic st, int ownerId, String ownerType, String ownerUrl )
        {
            ForumTopic topic = new ForumTopic();
            topic.Id = st.Id;
            topic.Title = st.Title;

            topic.Creator = new wojilu.Members.Users.Domain.User() { Name = st.CreatorName, Url = st.CreatorUrl };
            topic.CreatorUrl = st.CreatorUrl;
            topic.Created = cvt.ToTime( st.Created );

            topic.Replies = st.Replies;
            topic.Hits = st.Views;

            topic.Replied = cvt.ToTime( st.LastUpdated );
            topic.RepliedUserName = st.LastUserName;
            topic.RepliedUserFriendUrl = st.LastUserUrl;

            topic.OwnerId = ownerId;
            topic.OwnerType = ownerType;
            topic.OwnerUrl = ownerUrl;

            topic.IsGlobalSticky = true;

            return topic;
        }
Beispiel #46
0
        private void addNotificationToTopicCreator( ForumTopic topic, ForumPost post )
        {
            User creator = post.Creator;
            int topicReceiverId = topic.Creator.Id;

            if (topicReceiverId == creator.Id) return;

            String msg = "<a href=\"" + Link.ToMember( creator ) + "\">" + creator.Name + "</a> " + alang.get( typeof( ForumApp ), "replyYourPost" ) + " <a href=\"" + alink.ToAppData( post ) + "\">" + topic.Title + "</a>";
            notificationService.send( topicReceiverId, post.Creator.GetType().FullName, msg, NotificationType.Comment );
        }
        public virtual EditForumPostModel PreparePostCreateModel(ForumTopic forumTopic, int?quote, bool excludeProperties)
        {
            if (forumTopic == null)
            {
                throw new ArgumentNullException("forumTopic");
            }

            var forum = forumTopic.Forum;

            if (forum == null)
            {
                throw new ArgumentException("forum cannot be loaded");
            }

            var model = new EditForumPostModel
            {
                ForumTopicId                 = forumTopic.Id,
                IsEdit                       = false,
                ForumEditor                  = _forumSettings.ForumEditor,
                ForumName                    = forum.Name,
                ForumTopicSubject            = forumTopic.Subject,
                ForumTopicSeName             = forumTopic.GetSeName(),
                IsCustomerAllowedToSubscribe = _forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer)
            };

            if (!excludeProperties)
            {
                //subscription
                if (model.IsCustomerAllowedToSubscribe)
                {
                    var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id,
                                                                              0, forumTopic.Id, 0, 1).FirstOrDefault();
                    model.Subscribed = forumSubscription != null;
                }

                // Insert the quoted text
                string text = string.Empty;
                if (quote.HasValue)
                {
                    var quotePost = _forumService.GetPostById(quote.Value);
                    if (quotePost != null && quotePost.TopicId == forumTopic.Id)
                    {
                        var quotePostText = quotePost.Text;

                        switch (_forumSettings.ForumEditor)
                        {
                        case EditorType.SimpleTextBox:
                            text = String.Format("{0}:\n{1}\n", quotePost.Customer.FormatUserName(), quotePostText);
                            break;

                        case EditorType.BBCodeEditor:
                            text = String.Format("[quote={0}]{1}[/quote]", quotePost.Customer.FormatUserName(), BBCodeHelper.RemoveQuotes(quotePostText));
                            break;
                        }
                        model.Text = text;
                    }
                }
            }

            return(model);
        }
Beispiel #48
0
        private int getParentId( OpenComment comment, ForumTopic topic )
        {
            ForumPost post = postService.GetPostByTopic( topic.Id );

            // 获取topic对应的post的Id
            if (comment.ParentId == 0) {
                return post.Id;
            }
            else {

                CommentSync objSync = CommentSync.find( "CommentId=" + comment.ParentId ).first();
                if (objSync == null || objSync.Post == null) return post.Id;

                return objSync.Post.Id;

            }
        }
 private String addContentInfo(ForumTopic data, String content)
 {
     return(content + "<div class=\"extDataPanel\">" + ExtData.GetExtView(data.Id, typeof(ForumTopic).FullName, data.TypeName, ctx) + "</div>");
 }