Beispiel #1
0
        private void refreshTodayStats(ForumApp forum)
        {
            if (time.IsNextDay(forum.TodayTime) == false)
            {
                return;
            }

            int all = forum.TodayTopicCount + forum.TodayPostCount;

            if (all > forum.PeakPostCount)
            {
                forum.PeakPostCount = all;
            }

            forum.YestodayPostCount = forum.TodayTopicCount + forum.TodayPostCount;

            forum.TodayPostCount  = 0;
            forum.TodayTopicCount = 0;
            forum.TodayVisitCount = 0;
            forum.TodayTime       = DateTime.Now;

            forum.update();

            ForumBoard.updateBatch("set TodayTopics=0, TodayPosts=0", "AppId=" + forum.Id);
        }
        public override void UpdateCache(MvcContext ctx)
        {
            IMember owner = Site.Instance;

            IApp forum = ctx.app.obj as IApp;

            // 1) ForumIndexCache
            if (forum != null)
            {
                String forumUrl = alink.ToApp(forum, ctx);
                base.updateAllUrl(forumUrl, ctx);
            }

            // 2) SiteLayoutCache
            else
            {
                List <ForumApp> siteForums = ForumApp.find("OwnerId=" + owner.Id + " and OwnerType=:otype")
                                             .set("otype", owner.GetType().FullName)
                                             .list();
                foreach (ForumApp app in siteForums)
                {
                    String forumUrl = alink.ToApp(app, ctx);
                    base.updateAllUrl(forumUrl, ctx);
                }
            }
        }
Beispiel #3
0
        public void CreateAppAndMenu(Group group, MvcContext ctx)
        {
            // 添加程序
            IMemberApp forumApp = appService.Add((User)ctx.viewer.obj, group, lang.get("groupBoard"), 1, AccessStatus.Public);

            // 论坛
            ForumApp app = forumService.GetById(forumApp.AppOid);

            ForumPermission.AddOwnerAdminPermission(app);

            // 添加一个论坛板块
            ForumBoard board = new ForumBoard();

            board.Name     = lang.get("groupBoard");
            board.ParentId = 0;
            board.AppId    = forumApp.AppOid;

            board.Creator    = (User)ctx.viewer.obj;
            board.CreatorUrl = ctx.viewer.obj.Url;

            board.OwnerId   = group.Id;
            board.OwnerUrl  = group.Url;
            board.OwnerType = typeof(Group).FullName;
            board.Ip        = ctx.Ip;

            board.Security = app.Security;

            db.insert(board);

            // 添加menuUrl
            String forumUrl = UrlConverter.clearUrl(board, ctx);

            menuService.AddMenuByApp(forumApp, forumApp.Name, "default", forumUrl);
        }
Beispiel #4
0
        private void updateCount(ForumTopic topic, User user, IApp app)
        {
            ForumBoard fb = boardService.GetById(topic.ForumBoard.Id, topic.OwnerId, topic.OwnerType);

            fb.TodayPosts++;
            fb.Topics = boardService.CountTopic(fb.Id);

            LastUpdateInfo info = new LastUpdateInfo();

            info.PostId    = topic.Id;
            info.PostType  = typeof(ForumTopic).Name;
            info.PostTitle = topic.Title;

            info.CreatorName = user.Name;
            info.CreatorUrl  = user.Url;
            info.UpdateTime  = DateTime.Now;

            fb.LastUpdateInfo = info;

            fb.Updated = info.UpdateTime;

            boardService.Update(fb);
            ForumApp forum = app as ForumApp;

            forum.TopicCount = forum.CountTopic();
            forum.TodayTopicCount++;
            forum.LastUpdateMemberName = user.Name;
            forum.LastUpdateMemberUrl  = user.Url;
            forum.LastUpdatePostTitle  = topic.Title;
            forum.LastUpdateTime       = topic.Created;
            forumService.Update(forum);

            userService.AddPostCount(user);
        }
Beispiel #5
0
        public virtual void SetOnlineUser(ForumApp forum)
        {
            List <OnlineUser> results     = new List <OnlineUser>();
            List <OnlineUser> onlineUsers = OnlineService.GetAll();// Online.Instance.OnlineUsers;
            int memberCount = 0;

            foreach (OnlineUser info in onlineUsers)
            {
                if (this.isInCurrentForum(info, forum))
                {
                    results.Add(info);
                    if (info.UserId > 0)
                    {
                        memberCount++;
                    }
                }
            }

            if (results.Count > forum.OnlinePeakCount)
            {
                forum.OnlinePeakCount = results.Count;
                forum.OnlinePeakTime  = DateTime.Now;
                db.update(forum, new string[] { "OnlinePeakCount", "OnlinePeakTime" });
            }
            forum.OnlineUser        = results;
            forum.OnlineMemberCount = memberCount;
        }
Beispiel #6
0
        public virtual void StickyMoveDown(ForumApp forum, int topicId)
        {
            String json = StickyTopic.MoveDown(forum.StickyTopic, topicId);

            forum.StickyTopic = json;
            db.update(forum, "StickyTopic");
        }
Beispiel #7
0
        public void SaveGlobalStickySort()
        {
            int    topicId = ctx.PostInt("id");
            String cmd     = ctx.Post("cmd");

            ForumApp app = ctx.app.obj as ForumApp;

            PermissionUtil.Check(this, app);

            if (cmd == "up")
            {
                forumService.StickyMoveUp(app, topicId);
                echoRedirect("ok");
            }
            else if (cmd == "down")
            {
                forumService.StickyMoveDown(app, topicId);
                echoRedirect("ok");
            }
            else
            {
                errors.Add(lang("exUnknowCmd"));
                echoError();
            }
        }
Beispiel #8
0
        public void TopList()
        {
            ForumApp app = ctx.app.obj as ForumApp;

            set("recentTopicLink", to(new RecentController().Topic));
            set("recentPostLink", to(new RecentController().Post));
            set("recentHotLink", to(new RecentController().Replies));
            set("recentPickedImgLink", to(new RecentController().ImgTopic));

            ForumSetting s = app.GetSettingsObj();

            List <ForumPickedImg> pickedImg = db.find <ForumPickedImg>("AppId=" + ctx.app.Id).list(s.HomeImgCount);

            bindImgs(pickedImg);

            //List<ForumTopic> newPosts = topicService.GetByApp( ctx.app.Id, s.HomeListCount );
            //bindTopics( newPosts, "topic" );

            //List<ForumTopic> hots = topicService.GetByAppAndReplies( ctx.app.Id, s.HomeListCount, s.HomeHotDays );
            //bindTopics( hots, "hot" );

            //List<ForumPost> posts = postService.GetRecentByApp( ctx.app.Id, s.HomeListCount );
            //bindPosts( posts, "post" );

            List <ForumTopic> newPosts = topicService.GetByApp(ctx.app.Id, 30);
            List <MergedData> results  = pickService.GetAll(newPosts, ctx.app.Id);

            bindCustomList(results);
        }
Beispiel #9
0
        public override void Layout()
        {
            ForumApp app = ctx.app.obj as ForumApp;

            set("adminUrl", to(new Admin.ForumController().Index));
            set("appUrl", to(new ForumController().Index));

            set("adminCheckUrl", t2(new wojilu.Web.Controller.SecurityController().CanAppAdmin, app.Id) + "?appType=" + typeof(ForumApp).FullName);

            // 当前app/module所有页面,所属的首页
            ctx.SetItem("_moduleUrl", to(new ForumController().Index));

            set("noticeLink", to(new Admin.ForumController().Notice));
            set("forumBoardList", to(new Admin.ForumController().Index));
            set("dataCombine", to(new Admin.ForumController().DataCombine));
            set("security", to(new Admin.SecurityController().Setting));
            set("forumLog", to(new Admin.SecurityController().Log));
            set("addFriend", to(new Admin.ForumLinkController().New));
            set("friendList", to(new Admin.ForumLinkController().List));
            set("recyclebin", to(new Admin.ForumController().TopicTrash));

            set("settings", to(new Admin.SettingController().Index));

            set("pickedImg", to(new Admin.PickedImgController().Index));
        }
Beispiel #10
0
        public void Index()
        {
            target(Save);
            ForumApp app = ctx.app.obj as ForumApp;

            bindSettings(app.GetSettingsObj());
        }
Beispiel #11
0
        public override int GetImgCount()
        {
            ForumApp     app = ctx.app.obj as ForumApp;
            ForumSetting s   = app.GetSettingsObj();

            return(s.HomeImgCount);
        }
Beispiel #12
0
        public virtual void Index()
        {
            set("forumPath", "");
            set("topicTypeName", alang("normalTopic"));

            this.fb         = ctx.GetItem("forumBoard") as ForumBoard;
            this.boardsPath = ctx.GetItem("pathBoards") as List <ForumBoard>;
            long id = fb.Id;

            IList   adminCmds = SecurityHelper.GetTopicAdminCmds((User)ctx.viewer.obj, fb, ctx);
            Boolean isAdmin   = (adminCmds.Count > 0);

            ForumApp          app              = ctx.app.obj as ForumApp;
            int               page             = ctx.route.page;
            List <ForumTopic> globalStickyList = page <= 1 ? forumService.GetStickyTopics(app) : null;
            List <ForumTopic> stickyList       = topicService.getMergedStickyList(globalStickyList, id, page);

            int    categoryId = cvt.ToInt(ctx.GetItem("forumCategory"));
            String sort       = ctx.GetItem("forumSort") as String;
            String time       = ctx.GetItem("forumRecentTime") as String;
            DataPage <ForumTopic> topicList  = topicService.FindTopicPage(id, getPageSize(ctx.app.obj), categoryId, sort, time);
            List <ForumCategory>  categories = categoryService.GetByBoard(id);

            bindAll(id, stickyList, topicList, categories, isAdmin);
        }
Beispiel #13
0
        //private static String getTimeStr() {
        //    String elapsed = string.Format( "<div>Processed in {0} seconds, {1} queries</div>",
        //        (WebStopwatch.Stop().ElapsedMilliseconds / 1000.0).ToString( "0.0000" ),
        //        DbContext.getSqlCount()
        //    );

        //    String copyright = "<div>Powered by <a href=\"http://www.wojilu.com\" target=\"_blank\">我记录1.6</a></div>";

        //    String timeStr = copyright + elapsed;
        //    return timeStr;
        //}

        //----------------------------------------------- 有针对性的缓存TODO ------------------------------------------------------

        //private void addPageToCache( MvcEventArgs e, String output ) {
        //    if (shouldCachePage.Contains( e.ctx.url.PathAndQuery )) {
        //        CachedPageList[e.ctx.url.PathAndQuery] = output;
        //    }
        //}

        //private static List<String> shouldCachePage = getShouldCachePages();

        // TODO 1)统计访问量前100位主要页面 2)自定义添加的页面
        //private static List<String> getShouldCachePages() {

        //    List<String> list = new List<String>();

        //    List<String> menuPage = getMenuPages( list );
        //    List<String> mainPages = getMainPages( menuPage );
        //    List<String> forumPages = getForumPages( mainPages );

        //    return menuPage;
        //}

        // 【portal页面通知】
        //  1)每个聚合区块都和service相关,即和domain model相关
        //  2)给ORM增加 interceptor ,一旦插入或者更新或者删除,即更新相关页面的缓存
        //    a)根据domain获取service,以及serviceId
        //    b)查找所有相关portal的appId,得到页面url,然后移除此页面的缓存
        // ——仍然是粗粒度的

        // 【论坛页面通知】
        // 每次发帖、删帖、修改,都获取board,然后更新论坛首页,board页面,topicShow和postShow页面
        // 修改积分单位、用户信息
        // 【论坛登录的区别】针对登录用户和游客进行各自缓存
        private static List <string> getForumPages(List <string> list)
        {
            // 获取网站的所有论坛
            List <ForumApp> forums = ForumApp.find("OwnerType=:otype").set("otype", typeof(Site).FullName).list();

            // 获取所有版块页面
            foreach (ForumApp app in forums)
            {
                List <ForumBoard> boards = ForumBoard.find("AppId=" + app.Id).list();

                foreach (ForumBoard bd in boards)
                {
                    String url = alink.ToAppData(bd);
                    if (list.Contains(url) == false)
                    {
                        list.Add(url);
                    }

                    // 获取前5页的列表页
                    for (int i = 2; i < 6; i++)
                    {
                        String pagedUrl = getListPage(url, i);
                        if (list.Contains(pagedUrl) == false)
                        {
                            list.Add(pagedUrl);
                        }
                    }
                }
            }

            return(list);
        }
Beispiel #14
0
        public override IPageList GetPage()
        {
            ForumApp     app = ctx.app.obj as ForumApp;
            ForumSetting s   = app.GetSettingsObj();

            return(ndb.findPage(typeof(ForumPickedImg), "AppId=" + ctx.app.Id, s.HomeImgCount));
        }
Beispiel #15
0
        public void GlobalSticky()
        {
            int      id  = ctx.GetInt("boardId");
            ForumApp app = ctx.app.obj as ForumApp;

            adminPrivate(id);
            set("ActionLink", to(new TopicSaveController().GlobalSticky) + "?boardId=" + id + "&ids=" + ids);
        }
Beispiel #16
0
        public virtual void Headline()
        {
            target(SaveNotice);

            ForumApp forum = ctx.app.obj as ForumApp;

            set("Notice", forum.Notice);
        }
Beispiel #17
0
        public void Init(MvcContext ctx, String appName, String fUrl)
        {
            ForumApp forum = createFirstForum(ctx, appName);

            updateSettings(forum);

            base.AddMenu(ctx, appName, alink.ToApp(forum), fUrl);
        }
Beispiel #18
0
        public virtual void Setting()
        {
            target(SavePermissionAll);
            set("lnkApplyAll", to(ApplyAll));
            ForumApp f = ctx.app.obj as ForumApp;

            bindRoleActions(f);
        }
Beispiel #19
0
        public void Notice()
        {
            target(SaveNotice);

            ForumApp forum = ctx.app.obj as ForumApp;

            editor("Notice", forum.Notice, "380px");
        }
        public override void Layout()
        {
            ForumApp app = ctx.app.obj as ForumApp;

            set("adminUrl", to(new Admin.ForumController().Index));
            set("appUrl", to(new ForumController().Index));

            set("adminCheckUrl", t2(new wojilu.Web.Controller.SecurityController().CanAppAdmin, app.Id) + "?appType=" + typeof(ForumApp).FullName);
        }
        private static void updatePost( ForumApp app )
        {
            if (app.OwnerType != typeof( Site ).FullName) return;

            IMember owner = Site.Instance;

            //LayoutViewCacher.Update( owner, appId );
            IndexViewCacher.Update( owner, app.Id );
        }
Beispiel #22
0
        public void Move()
        {
            int      id  = ctx.GetInt("boardId");
            ForumApp app = ctx.app.obj as ForumApp;

            set("ActionLink", to(new TopicSaveController().Move) + "?boardId=" + id + "&ids=" + ids);
            set("ActionName", getActionName());
            set("dropForums", getTree().DropList("targetForum", 0));
        }
Beispiel #23
0
        public virtual void UpdateSecurityAll(ForumApp forum)
        {
            String            str    = forum.Security;
            List <ForumBoard> boards = getBoardsByApp(forum.Id);

            foreach (ForumBoard bd in boards)
            {
                UpdateSecurity(bd, str);
            }
        }
Beispiel #24
0
        public void Notice()
        {
            redirect(new ForumPickController().Index);

            target(SaveNotice);

            ForumApp forum = ctx.app.obj as ForumApp;

            editor("Notice", forum.Notice, "380px");
        }
Beispiel #25
0
        private void updateSettings(ForumApp forum)
        {
            ForumSetting s = forum.GetSettingsObj();

            // 配置:隐藏头条新帖
            s.IsHideTop = 1;

            forum.Settings = Json.ToString(s);
            forum.update();
        }
Beispiel #26
0
        public void Move(int id)
        {
            ForumApp app = ctx.app.obj as ForumApp;

            PermissionUtil.Check(this, app);

            set("ActionLink", to(new AdminSaveController().Move, id) + "?ids=" + ids);
            set("ActionName", getActionName());
            set("dropForums", getTree().DropList("targetForum", 0));
        }
Beispiel #27
0
        public override void CheckPermission()
        {
            if (!checkRegisterTimeValid())
            {
                return;
            }

            ForumApp forum = ctx.app.obj as ForumApp;

            refreshTodayStats(forum);
        }
Beispiel #28
0
        public void SaveNotice()
        {
            String notice = ctx.PostHtml("Notice");

            ForumApp forum = ctx.app.obj as ForumApp;

            forum.Notice = notice;
            forum.update("Notice");

            echoRedirect(lang("opok"));
        }
Beispiel #29
0
        //-------------------------------------------------------------------------------------------------
        public static List<ForumTopic> GetForumTopic( String json, ForumApp app )
        {
            List<StickyTopic> stickyList = GetTopics( json );

            List<ForumTopic> results = new List<ForumTopic>();
            foreach (StickyTopic st in stickyList) {
                ForumTopic topic = getTopicBySticky( st, app.OwnerId, app.OwnerType, app.OwnerUrl );
                results.Add( topic );
            }

            return results;
        }
Beispiel #30
0
        private static void updatePost(ForumApp app)
        {
            if (app.OwnerType != typeof(Site).FullName)
            {
                return;
            }

            IMember owner = Site.Instance;

            //LayoutViewCacher.Update( owner, appId );
            IndexViewCacher.Update(owner, app.Id);
        }
Beispiel #31
0
        public void GlobalSticky(int id)
        {
            ForumApp app = ctx.app.obj as ForumApp;

            if (PermissionUtil.Check(this, app) == false)
            {
                return;
            }

            adminPrivate(id);
            set("ActionLink", to(new AdminSaveController().GlobalSticky, id) + "?ids=" + ids);
        }
        private void createBoardList( MvcContext ctx, ForumApp app )
        {
            ForumBoard category1 = createBoard( ctx, app, null, "新闻" );
            ForumBoard category2 = createBoard( ctx, app, null, "娱乐" );

            createBoard( ctx, app, category1, "国际新闻" );
            createBoard( ctx, app, category1, "国内新闻" );
            createBoard( ctx, app, category1, "科技新闻" );

            createBoard( ctx, app, category2, "电影" );
            createBoard( ctx, app, category2, "音乐" );
            createBoard( ctx, app, category2, "游戏" );
        }
Beispiel #33
0
        // 如果不是针对某个特定app的更新,则需要移除所有缓存
        private void removeAllForumCache(IMember owner)
        {
            List <ForumApp> siteForums = ForumApp.find("OwnerId=" + owner.Id + " and OwnerType=:otype")
                                         .set("otype", owner.GetType().FullName)
                                         .list();

            foreach (ForumApp app in siteForums)
            {
                String cacheKey = getCacheKey(owner, app.Id);

                CacheManager.GetApplicationCache().Remove(cacheKey);
            }
        }
        private ForumBoard createBoard( MvcContext ctx, ForumApp app, ForumBoard board, String name )
        {
            ForumBoard bd = new ForumBoard();
            bd.Name = name;
            bd.Description = name + " 的简介";

            if (board != null) {
                bd.ParentId = board.Id;
            }

            bd.AppId = app.Id;
            bd.Creator = ctx.viewer.obj as User;
            bd.CreatorUrl = bd.Creator.Url;
            setOwner( bd, app );
            bd.insert();

            return bd;
        }
Beispiel #35
0
        public virtual void SetOnlineUser( ForumApp forum ) {
            List<OnlineUser> results = new List<OnlineUser>();
            List<OnlineUser> onlineUsers = OnlineService.GetAll();// Online.Instance.OnlineUsers;
            int memberCount = 0;
            foreach (OnlineUser info in onlineUsers) {
                if (this.isInCurrentForum( info, forum )) {
                    results.Add( info );
                    if (info.UserId > 0) memberCount++;
                }
            }

            if (results.Count > forum.OnlinePeakCount) {
                forum.OnlinePeakCount = results.Count;
                forum.OnlinePeakTime = DateTime.Now;
                db.update( forum, new string[] { "OnlinePeakCount", "OnlinePeakTime" } );
            }
            forum.OnlineUser = results;
            forum.OnlineMemberCount = memberCount;
        }
        private void refreshTodayStats( ForumApp forum )
        {
            if (time.IsNextDay( forum.TodayTime ) == false) return;

            int all = forum.TodayTopicCount + forum.TodayPostCount;
            if (all > forum.PeakPostCount) {
                forum.PeakPostCount = all;
            }

            forum.YestodayPostCount = forum.TodayTopicCount + forum.TodayPostCount;

            forum.TodayPostCount = 0;
            forum.TodayTopicCount = 0;
            forum.TodayVisitCount = 0;
            forum.TodayTime = DateTime.Now;

            forum.update();

            ForumBoard.updateBatch( "set TodayTopics=0, TodayPosts=0", "AppId=" + forum.Id );
        }
 private void setOwner( ForumBoard bd, ForumApp app )
 {
     bd.OwnerId = app.OwnerId;
     bd.OwnerType = app.OwnerType;
     bd.OwnerUrl = app.OwnerUrl;
 }
Beispiel #38
0
        //-----------------------------------------------------------------------------------------------------------------------

        public virtual List<ForumTopic> GetStickyTopics( ForumApp forum ) {
            return StickyTopic.GetForumTopic( forum.StickyTopic, forum );
        }
        private void updateSettings( ForumApp forum )
        {
            ForumSetting s = forum.GetSettingsObj();
            // 配置:隐藏头条新帖
            s.IsHideTop = 1;

            forum.Settings = Json.ToString( s );
            forum.update();
        }
Beispiel #40
0
 public virtual void UpdateSecurity( ForumApp forum, String str ) {
     forum.Security = str;
     db.update( forum, "Security" );
 }
Beispiel #41
0
 public virtual void Update( ForumApp forum ) {
     db.update( forum );
 }
Beispiel #42
0
 // TODO 判断是否在当前论坛
 private Boolean isInCurrentForum( OnlineUser user, ForumApp forum ) {
     return true;
 }
Beispiel #43
0
 public virtual void UpdateSecurityAll( ForumApp forum )
 {
     String str = forum.Security;
     List<ForumBoard> boards = getBoardsByApp( forum.Id );
     foreach (ForumBoard bd in boards) {
         UpdateSecurity( bd, str );
     }
 }
Beispiel #44
0
 public virtual void StickyMoveDown(ForumApp forum, long topicId) {
     String json = StickyTopic.MoveDown( forum.StickyTopic, topicId );
     forum.StickyTopic = json;
     db.update( forum, "StickyTopic" );
 }