예제 #1
0
        static IHtmlControl GetUserRedoPanel(SiteState state, LightObject user)
        {
            return(new HPanel(
                       Decor.PropertyEdit("editUserName", "Ваше имя (*):", user.Get(UserType.FirstName)),
                       Decor.PropertyEdit("editUserEmail", "Email (*):", user.Get(UserType.Email)),
                       Decor.PropertyEdit("editUserCountry", "Страна:", user.Get(BasketballUserType.Country)),
                       Decor.PropertyEdit("editUserCity", "Город:", user.Get(BasketballUserType.City)),
                       Decor.PropertyEdit("editUserInterests", "Интересы:", user.Get(BasketballUserType.Interests)),
                       Decor.PropertyEdit("editUserAboutMe", "О себе:", user.Get(BasketballUserType.AboutMe)),
                       Decor.PropertyEdit("editUserCommunity", "На basketball.ru с:", user.Get(BasketballUserType.CommunityMember)),
                       Decor.Button("Сохранить")
                       .Event("user_edit_save", "userContainer",
                              delegate(JsonData json)
            {
                string name = json.GetText("editUserName");
                string email = json.GetText("editUserEmail");
                string country = json.GetText("editUserCountry");
                string city = json.GetText("editUserCity");
                string interests = json.GetText("editUserInterests");
                string aboutMe = json.GetText("editUserAboutMe");
                string community = json.GetText("editUserCommunity");

                WebOperation operation = state.Operation;

                if (!operation.Validate(email, "Не задана электронная почта"))
                {
                    return;
                }
                if (!operation.Validate(!email.Contains("@"), "Некорректный адрес электронной почты"))
                {
                    return;
                }
                if (!operation.Validate(name, "Не задано имя"))
                {
                    return;
                }

                LightObject editUser = DataBox.LoadObject(context.UserConnection, UserType.User, user.Id);

                editUser.Set(UserType.FirstName, name);
                editUser.Set(UserType.Email, email);
                editUser.Set(BasketballUserType.Country, country);
                editUser.Set(BasketballUserType.City, city);
                editUser.Set(BasketballUserType.Interests, interests);
                editUser.Set(BasketballUserType.AboutMe, aboutMe);
                editUser.Set(BasketballUserType.CommunityMember, community);

                editUser.Set(ObjectType.ActTill, DateTime.UtcNow);

                editUser.Box.Update();

                context.UserStorage.Update();

                state.BlockHint = "";
            }
                              )
                       ).EditContainer("userContainer"));
        }
예제 #2
0
        static IHtmlControl GetAdminPanel(LightObject user)
        {
            bool isModerator = user.Get(BasketballUserType.IsModerator);

            return(new HPanel(
                       Decor.Button(isModerator ? "Лишить прав модератора" : "Сделать модератором")
                       .Event("moderator_rights", "", delegate
            {
                LightObject editUser = DataBox.LoadObject(context.UserConnection, UserType.User, user.Id);
                editUser.Set(BasketballUserType.IsModerator, !isModerator);
                editUser.Box.Update();

                context.UserStorage.Update();
            }
                              )
                       ));
        }
예제 #3
0
        static IHtmlControl GetModeratorPanel(LightObject user)
        {
            return(new HPanel(
                       Decor.PropertyEdit("editBannedUntil", "Заблокировать до (например, 22.12.2018)",
                                          user.Get(BasketballUserType.BannedUntil)?.ToString("dd.MM.yyyy")
                                          ),
                       Decor.PropertyEdit("editNotRedactorUntil", "Запретить добавление новостей до",
                                          user.Get(BasketballUserType.NotRedactorUntil)?.ToString("dd.MM.yyyy")
                                          ),
                       Decor.Button("Сохранить").Event("user_rights_save", "moderatorEdit",
                                                       delegate(JsonData json)
            {
                string bannedUntilStr = json.GetText("editBannedUntil");
                string notRedactorUntilStr = json.GetText("editNotRedactorUntil");

                LightObject editUser = DataBox.LoadObject(context.UserConnection, UserType.User, user.Id);

                DateTime bannedUntil;
                if (DateTime.TryParse(bannedUntilStr, out bannedUntil))
                {
                    editUser.Set(BasketballUserType.BannedUntil, bannedUntil);
                }
                else
                {
                    editUser.Set(BasketballUserType.BannedUntil, null);
                }

                DateTime notRedactorUntil;
                if (DateTime.TryParse(notRedactorUntilStr, out notRedactorUntil))
                {
                    editUser.Set(BasketballUserType.NotRedactorUntil, notRedactorUntil);
                }
                else
                {
                    editUser.Set(BasketballUserType.NotRedactorUntil, null);
                }

                editUser.Box.Update();
                context.UserStorage.Update();
            }
                                                       )
                       ).EditContainer("moderatorEdit").MarginTop(10));
        }
예제 #4
0
        static IHtmlControl GetModeratorPanel(SiteState state,
                                              LightObject currentUser, TopicStorage topic, DateTime localTime)
        {
            bool isModerator = currentUser != null && currentUser.Get(BasketballUserType.IsModerator);

            if (!state.EditMode && !state.ModeratorMode)
            {
                return(null);
            }

            return(new HPanel(
                       new HTextEdit("newsDate", localTime.ToString(Decor.timeFormat))
                       .Width(100).MarginRight(10).FontFamily("Tahoma").FontSize(12),
                       Decor.Button("Изменить дату").Event("news_date_modify", "newsAdminContainer",
                                                           delegate(JsonData json)
            {
                string dateStr = json.GetText("newsDate");

                WebOperation operation = state.Operation;

                if (!operation.Validate(dateStr, "Дата не задана"))
                {
                    return;
                }
                DateTime editDate;
                if (!operation.Validate(!DateTime.TryParse(dateStr, out editDate), "Неверный формат даты"))
                {
                    return;
                }

                LightObject editNews = DataBox.LoadObject(context.FabricConnection, NewsType.News, topic.TopicId);
                editNews.Set(ObjectType.ActFrom, editDate.ToUniversalTime());
                editNews.Set(ObjectType.ActTill, DateTime.UtcNow);

                editNews.Box.Update();

                context.UpdateNews();
                context.NewsStorages.ForTopic(topic.TopicId).UpdateTopic();
            }
                                                           )
                       ).EditContainer("newsAdminContainer"));
        }
예제 #5
0
        static IHtmlControl GetTopicRedoPanel(SiteState state,
                                              LightObject currentUser, LightSection forumSection, TopicStorage topic)
        {
            string blockHint = string.Format("topic_edit_{0}", topic.TopicId);

            IHtmlControl redoPanel = null;

            if (state.BlockHint == blockHint)
            {
                redoPanel = new HPanel(
                    new HPanel(
                        Decor.Button("Удалить тему").Event("delete_topic", "", delegate
                {
                    int messageCount = topic.MessageLink.AllRows.Length;
                    if (!state.Operation.Validate(messageCount > 1, "Тема с комментариями не может быть удалена"))
                    {
                        return;
                    }

                    MessageHlp.DeleteTopicMessages(context.ForumConnection, topic.Topic.Id);
                    BasketballHlp.DeleteTopic(context.FabricConnection, topic.TopicId);

                    topic.UpdateTopic();
                    topic.UpdateMessages();
                    context.UpdateLastComments(true);
                    context.Forum.ForSection(forumSection.Id).Update();

                    state.RedirectUrl = "/";
                }
                                                           )
                        ).Align(false),
                    Decor.PropertyEdit("editTopicTitle", "Заголовок темы", topic.Topic.Get(TopicType.Title)),
                    Decor.Button("Переименовать тему")
                    .Event("save_topic_edit", "editTopicData",
                           delegate(JsonData json)
                {
                    string title = json.GetText("editTopicTitle");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }

                    LightObject editTopic = DataBox.LoadObject(context.FabricConnection, TopicType.Topic, topic.TopicId);
                    editTopic.SetWithoutCheck(TopicType.Title, title);

                    editTopic.Box.Update();

                    context.Forum.ForSection(forumSection.Id).Update();
                    topic.UpdateTopic();

                    state.BlockHint = "";
                },
                           topic.TopicId
                           )
                    ).EditContainer("editTopicData")
                            .Padding(5, 10).MarginTop(5).Background(Decor.pageBackground);
            }

            return(new HPanel(
                       Decor.Button("Редактировать")
                       .Event("topic_edit", "", delegate
            {
                state.SetBlockHint(blockHint);
            }
                              ),
                       redoPanel
                       ).MarginTop(5).MarginBottom(10));
        }
예제 #6
0
        public static IHtmlControl GetCenter(HttpContext httpContext, SiteState state,
                                             LightObject currentUser, string kind, int?id,
                                             out string title, out string description, out SchemaOrg schema, out bool wideContent)
        {
            title       = "";
            description = "";
            schema      = null;
            wideContent = false;

            SiteSettings settings = context.SiteSettings;

            switch (kind)
            {
            case "":
            {
                title       = store.SEO.Get(SEOType.MainTitle);
                description = store.SEO.Get(SEOType.MainDescription);
                LightSection main = store.Sections.FindMenu("main");
                return(ViewHlp.GetMainView(state, currentUser));
            }

            case "news":
            {
                if (!context.News.ObjectById.Exist(id))
                {
                    return(null);
                }
                TopicStorage topicStorage = context.NewsStorages.ForTopic(id ?? 0);
                LightKin     topic        = topicStorage.Topic;
                //string tagsDisplay;
                IHtmlControl view = ViewNewsHlp.GetNewsView(state, currentUser, topicStorage, out description);

                title = topic.Get(NewsType.Title);

                //string postfix = "";
                //if (!StringHlp.IsEmpty(tagsDisplay))
                //  postfix = ". ";
                //description = string.Format("{0}{1}Живое обсуждение баскетбольных событий на basketball.ru.com",
                //  tagsDisplay, postfix
                //);

                string logoUrl = settings.FullUrl("/images/logo.gif");
                schema = new SchemaOrg("NewsArticle", settings.FullUrl(UrlHlp.ShopUrl("news", id)),
                                       title, new string[] { logoUrl }, topic.Get(ObjectType.ActFrom), topic.Get(ObjectType.ActTill),
                                       topic.Get(TopicType.OriginName), settings.Organization,
                                       logoUrl, description
                                       );

                return(view);
            }

            case "article":
            {
                if (!context.Articles.ObjectById.Exist(id))
                {
                    return(null);
                }
                TopicStorage topicStorage = context.ArticleStorages.ForTopic(id ?? 0);
                LightKin     topic        = topicStorage.Topic;
                title       = topic.Get(ArticleType.Title);
                description = topic.Get(ArticleType.Annotation);

                string logoUrl = settings.FullUrl("/images/logo.gif");
                schema = new SchemaOrg("Article", settings.FullUrl(UrlHlp.ShopUrl("article", id)),
                                       title, new string[] { logoUrl }, topic.Get(ObjectType.ActFrom), topic.Get(ObjectType.ActTill),
                                       topic.Get(TopicType.OriginName), settings.Organization,
                                       logoUrl, description
                                       );
                wideContent = topic.Get(ArticleType.WideContent);
                return(ViewArticleHlp.GetArticleView(state, currentUser, topicStorage));
            }

            case "topic":
            {
                TopicStorage topic = context.Forum.TopicsStorages.ForTopic(id ?? 0);
                title = topic.Topic.Get(TopicType.Title);

                int pageNumber = 0;
                {
                    string pageArg      = httpContext.Get("page");
                    int    messageCount = topic.MessageLink.AllRows.Length;
                    if (pageArg == "last" && messageCount > 0)
                    {
                        pageNumber = BinaryHlp.RoundUp(messageCount, ViewForumHlp.forumMessageCountOnPage) - 1;
                    }
                    else
                    {
                        pageNumber = ConvertHlp.ToInt(pageArg) ?? 0;
                    }
                }

                return(ViewForumHlp.GetTopicView(state, currentUser, topic, pageNumber));
            }

            case "tags":
            {
                int?tagId      = httpContext.GetUInt("tag");
                int pageNumber = httpContext.GetUInt("page") ?? 0;
                return(ViewNewsHlp.GetTagView(state, currentUser, tagId, pageNumber, out title, out description));
            }

            case "search":
            {
                return(ViewNewsHlp.GetFoundTagListView(state, out title));
            }

            case "user":
            {
                LightObject user = context.UserStorage.FindUser(id ?? -1);
                if (user == null)
                {
                    return(null);
                }
                title = string.Format("{0} - Basketball.ru.com", user.Get(UserType.Login));
                return(ViewUserHlp.GetUserView(state, currentUser, user));
            }

            case "page":
            {
                LightSection section = store.Sections.FindSection(id);
                title       = FabricHlp.GetSeoTitle(section, section.Get(SectionType.Title));
                description = FabricHlp.GetSeoDescription(section, section.Get(SectionType.Annotation));

                int    pageNumber = httpContext.GetUInt("page") ?? 0;
                string designKind = section.Get(SectionType.DesignKind);
                switch (designKind)
                {
                case "news":
                {
                    int[] allNewsIds = context.News.AllObjectIds;
                    return(ViewNewsHlp.GetNewsListView(state, currentUser, pageNumber));
                }

                case "articles":
                    return(ViewArticleHlp.GetArticleListView(state, currentUser, pageNumber));

                case "forum":
                    return(ViewForumHlp.GetForumView(state, currentUser, section));

                case "forumSection":
                    return(ViewForumHlp.GetForumSectionView(state, currentUser, section));

                default:
                    return(null);
                }
            }

            case "dialog":
            {
                if (currentUser == null)
                {
                    return(null);
                }

                if (id == null)
                {
                    return(ViewDialogueHlp.GetDialogueView(state,
                                                           context.ForumConnection, context.UserStorage, currentUser, out title
                                                           ));
                }

                LightObject collocutor = context.UserStorage.FindUser(id.Value);
                if (collocutor == null)
                {
                    return(null);
                }

                return(ViewDialogueHlp.GetCorrespondenceView(state, context.ForumConnection,
                                                             currentUser, collocutor, out title
                                                             ));
            }

            case "passwordreset":
                title = "Восстановление пароля - basketball.ru.com";
                return(ViewHlp.GetRestorePasswordView(state));

            case "register":
                title = "Регистрация - basketball.ru.com";
                return(ViewHlp.GetRegisterView(state));

            case "confirmation":
            {
                title = "Подтверждение аккаунта";

                int?   userId = httpContext.GetUInt("id");
                string hash   = httpContext.Get("hash");

                if (userId == null)
                {
                    return(ViewUserHlp.GetMessageView(
                               "Вам выслано письмо с кодом активации. Чтобы завершить процедуру регистрации, пройдите по ссылке, указанной в письме, и учётная запись будет активирована. Если вы не получили письмо, то попробуйте войти на сайт со своим логином и паролем. Тогда письмо будет отправлено повторно."
                               ));
                }

                if (StringHlp.IsEmpty(hash))
                {
                    return(null);
                }

                LightObject user = context.UserStorage.FindUser(userId.Value);
                if (userId == null)
                {
                    return(null);
                }

                if (!user.Get(UserType.NotConfirmed))
                {
                    return(ViewUserHlp.GetMessageView("Пользователь успешно активирован"));
                }

                string login  = user.Get(UserType.Login);
                string etalon = UserHlp.CalcConfirmationCode(user.Id, login, "bbbin");
                if (hash?.ToLower() != etalon?.ToLower())
                {
                    return(ViewUserHlp.GetMessageView("Неверный хэш"));
                }

                LightObject editUser = DataBox.LoadObject(context.UserConnection, UserType.User, user.Id);
                editUser.Set(UserType.NotConfirmed, false);
                editUser.Box.Update();

                context.UserStorage.Update();

                string xmlLogin = UserType.Login.CreateXmlIds("", login);
                HttpContext.Current.SetUserAndCookie(xmlLogin);

                state.RedirectUrl = "/";

                return(new HPanel());
            }
            }

            return(null);
        }
예제 #7
0
        public static IHtmlControl GetAddPanel(BasketballContext context, SiteState state,
                                               LightObject user, LightObject collocutor, bool sendFromUserView)
        {
            if (user == null)
            {
                return(null);
            }

            if (user.Id == collocutor.Id)
            {
                return(null);
            }

            IHtmlControl editPanel = null;

            if (state.BlockHint == "messageAdd")
            {
                string commentValue = BasketballHlp.AddCommentFromCookie();

                editPanel = new HPanel(
                    new HTextArea("messageContent", commentValue).BoxSizing().Width("100%")
                    .Height("10em").MarginTop(5).MarginBottom(5),
                    Decor.Button("отправить")
                    .OnClick(BasketballHlp.AddCommentToCookieScript("messageContent"))
                    .Event("message_add_save", "messageData",
                           delegate(JsonData json)
                {
                    string content = json.GetText("messageContent");
                    if (StringHlp.IsEmpty(content))
                    {
                        return;
                    }

                    DialogueHlp.SendMessage(context, user.Id, collocutor.Id, content);

                    state.BlockHint = "";

                    BasketballHlp.ResetAddComment();

                    if (sendFromUserView)
                    {
                        state.Operation.Message = "Сообщение успешно отправлено";
                    }
                }
                           ),
                    new HElementControl(
                        h.Script(h.type("text/javascript"), "$('.messageContent').focus();"),
                        ""
                        )
                    ).EditContainer("messageData");
            }

            HButton moderatorButton = null;
            HPanel  moderatorPanel  = null;

            if (!sendFromUserView)
            {
                moderatorButton = new HButton("",
                                              std.BeforeAwesome(@"\f1e2", 0)
                                              ).PositionAbsolute().Right(5).Top(0)
                                  .Title("Модерирование личных сообщений").FontSize(14)
                                  .Color(state.BlockHint == correspondenceModeration ? Decor.redColor : Decor.disabledColor)
                                  .Event("correspondence_moderation_set", "", delegate
                {
                    state.SetBlockHint(correspondenceModeration);
                });

                if (state.BlockHint == correspondenceModeration)
                {
                    bool lockedCollocutor = user.Get(BasketballUserType.LockedUserIds, collocutor.Id);
                    moderatorPanel = new HPanel(
                        Decor.ButtonMidi(!lockedCollocutor ? "Заблокировать собеседника" : "Разблокировать собеседника")
                        .Event("collocutor_locked", "", delegate
                    {
                        LightObject editUser = DataBox.LoadObject(context.UserConnection, UserType.User, user.Id);
                        editUser.Set(BasketballUserType.LockedUserIds, collocutor.Id, !lockedCollocutor);
                        editUser.Box.Update();
                        context.UserStorage.Update();
                    }),
                        new HSpoiler(Decor.ButtonMidi("Удаление переписки").Block().FontBold(false),
                                     new HPanel(
                                         Decor.ButtonMidi("Удалить? (без подтверждения)")
                                         .MarginTop(5).MarginLeft(10)
                                         .Event("correspondence_delete", "", delegate
                    {
                        context.ForumConnection.GetScalar("",
                                                          "Delete From correspondence Where user_id = @userId and collocutor_id = @collocutorId",
                                                          new DbParameter("userId", user.Id), new DbParameter("collocutorId", collocutor.Id)
                                                          );

                        context.ForumConnection.GetScalar("",
                                                          "Delete From dialogue Where user_id = @userId and collocutor_id = @collocutorId",
                                                          new DbParameter("userId", user.Id), new DbParameter("collocutorId", collocutor.Id)
                                                          );

                        context.UpdateUnreadDialogs();
                    })
                                         )
                                     ).MarginTop(10)
                        ).MarginTop(10);
                }
            }

            bool locked = user.Get(BasketballUserType.LockedUserIds, collocutor.Id) ||
                          collocutor.Get(BasketballUserType.LockedUserIds, user.Id);

            return(new HPanel(
                       new HPanel(
                           Decor.ButtonMidi("Написать сообщение")
                           .Hide(locked)
                           .Event("message_add", "", delegate
            {
                state.SetBlockHint("messageAdd");
            }
                                  ),
                           new HLabel("Вы не можете отправить сообщение этому пользователю").Hide(!locked)
                           .MarginLeft(10).Color(Decor.subtitleColor),
                           moderatorButton
                           ).PositionRelative(),
                       editPanel,
                       moderatorPanel
                       ).MarginTop(10).MarginBottom(10));
        }
예제 #8
0
        static IHtmlControl GetArticleEditPanel(SiteState state, TopicStorage topic)
        {
            LightObject article = topic.Topic;

            string blockHint = string.Format("article_edit_{0}", article.Id);

            IHtmlControl redoPanel = null;

            if (state.BlockHint == blockHint)
            {
                IHtmlControl deletePanel = null;
                if (state.ModeratorMode)
                {
                    deletePanel = ViewNewsHlp.DeleteTopicPanel(state, topic);
                }

                redoPanel = new HPanel(
                    deletePanel,
                    new HPanel(
                        Decor.PropertyEdit("editArticleTitle", "Заголовок статьи", article.Get(NewsType.Title)),
                        new HPanel(
                            new HLabel("Аннотация").FontBold(),
                            new HTextArea("editArticleAnnotation", article.Get(NewsType.Annotation))
                            .Width("100%").Height("4em").MarginBottom(5)
                            ),
                        new HPanel(
                            new HInputCheck(
                                "editArticleWideContent", article.Get(ArticleType.WideContent),
                                new HAfter().Content("Таблицы шире колонки статьи").MarginLeft(18).MarginBottom(1)
                                ).NoWrap()
                            ).MarginBottom(5),
                        HtmlHlp.CKEditorCreate("editArticleText", article.Get(NewsType.Text), "300px", true),
                        Decor.PropertyEdit("editArticleAuthor", "Автор", article.Get(ArticleType.Author)),
                        Decor.PropertyEdit("editArticleOriginName", "Источник (без префикса http://)", article.Get(NewsType.OriginName)),
                        Decor.PropertyEdit("editArticleOriginUrl", "Ссылка (с префиксом http://)", article.Get(NewsType.OriginUrl)),
                        Decor.Button("Сохранить статью").CKEditorOnUpdateAll().MarginTop(10).MarginBottom(10)
                        .Event("save_article_edit", "editArticleData",
                               delegate(JsonData json)
                {
                    string title      = json.GetText("editArticleTitle");
                    string annotation = json.GetText("editArticleAnnotation");
                    bool wideContent  = json.GetBool("editArticleWideContent");
                    string text       = json.GetText("editArticleText");
                    string author     = json.GetText("editArticleAuthor");
                    string originName = json.GetText("editArticleOriginName");
                    string originUrl  = json.GetText("editArticleOriginUrl");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }

                    if (!operation.Validate(text, "Не задан текст"))
                    {
                        return;
                    }

                    LightObject editNews = DataBox.LoadObject(context.FabricConnection, ArticleType.Article, article.Id);

                    editNews.SetWithoutCheck(NewsType.Title, title);

                    editNews.Set(ArticleType.WideContent, wideContent);
                    editNews.Set(NewsType.Annotation, annotation);
                    editNews.Set(NewsType.Text, text);
                    editNews.Set(ArticleType.Author, author);
                    editNews.Set(NewsType.OriginName, originName);
                    editNews.Set(NewsType.OriginUrl, originUrl);

                    editNews.Set(ObjectType.ActTill, DateTime.UtcNow);

                    editNews.Box.Update();

                    context.UpdateArticles();
                    context.ArticleStorages.ForTopic(article.Id).UpdateTopic();

                    state.BlockHint = "";
                },
                               article.Id
                               )
                        ).EditContainer("editArticleData"),
                    new HPanel(
                        EditElementHlp.GetImageThumb(article.Id)
                        ),
                    new HPanel(
                        EditElementHlp.GetDescriptionImagesPanel(state.Option, article.Id)
                        )
                    ).Padding(5, 10).MarginTop(10).Background(Decor.pageBackground);
            }

            return(new HPanel(
                       Decor.Button("Редактировать")
                       .Event("article_edit", "", delegate
            {
                state.SetBlockHint(blockHint);
            }
                              ),
                       redoPanel
                       ).MarginTop(5));
        }