Example #1
0
        public static IHtmlControl GetNewsView(SiteState state, LightObject currentUser, TopicStorage topic,
                                               out string description)
        {
            LightObject news = topic.Topic;

            description = BasketballHlp.GetDescriptionForNews(news);

            DateTime    localTime   = (news.Get(ObjectType.ActFrom) ?? DateTime.UtcNow).ToLocalTime();
            int         publisherId = news.Get(NewsType.PublisherId);
            LightObject publisher   = context.UserStorage.FindUser(publisherId);

            IHtmlControl editPanel = null;

            if (currentUser != null && (currentUser.Id == publisherId || currentUser.Get(BasketballUserType.IsModerator)))
            {
                editPanel = ViewNewsHlp.GetNewsEditPanel(state, topic);
            }

            IHtmlControl moderatorPanel = GetModeratorPanel(state, currentUser, topic, localTime);

            return(new HPanel(
                       Decor.Title(news.Get(NewsType.Title)),
                       new HLabel(localTime.ToString(Decor.timeFormat)).Block().FontBold(),
                       new HTextView(news.Get(NewsType.Text)).PositionRelative().Overflow("hidden"),
                       new HPanel(
                           new HLabel("Добавил:").MarginRight(5),
                           new HLink(UrlHlp.ShopUrl("user", publisherId), publisher?.Get(UserType.Login))
                           ),
                       new HLink(news.Get(NewsType.OriginUrl), news.Get(NewsType.OriginName)),
                       ViewTagHlp.GetViewTagsPanel(context.Tags.TagBox, topic.Topic),
                       editPanel,
                       moderatorPanel,
                       ViewCommentHlp.GetCommentsPanel(context.MessageConnection, state, currentUser, topic, topic.MessageLink.AllRows)
                       ));
        }
Example #2
0
 public static IHtmlControl GetMainView(SiteState state, LightObject currentUser)
 {
     return(new HPanel(
                ViewNewsHlp.GetActualNewsBlock(state, currentUser),
                ViewArticleHlp.GetActualArticleBlock(state, currentUser)
                ).PaddingLeft(15)
            .MediaSmartfon(new HStyle().PaddingLeft(5)));
 }
Example #3
0
        public static IHtmlControl GetArticleView(SiteState state, LightObject currentUser, TopicStorage topic)
        {
            if (topic == null || topic.Topic == null)
            {
                return(null);
            }

            LightObject article = topic.Topic;

            DateTime    localTime   = (article.Get(ObjectType.ActFrom) ?? DateTime.UtcNow).ToLocalTime();
            int         publisherId = article.Get(NewsType.PublisherId);
            LightObject publisher   = context.UserStorage.FindUser(publisherId);

            IHtmlControl editPanel = null;

            if (currentUser != null && (currentUser.Id == publisherId || currentUser.Get(BasketballUserType.IsModerator)))
            {
                editPanel = ViewArticleHlp.GetArticleEditPanel(state, topic);
            }

            string author       = article.Get(ArticleType.Author);
            int    commentCount = topic.MessageLink.AllRows.Length;
            string articleUrl   = UrlHlp.ShopUrl("article", article.Id);

            return(new HPanel(
                       Decor.Title(article.Get(NewsType.Title)),
                       new HPanel(
                           new HLabel(string.Format("{0},", author)).FontBold().MarginRight(5).Hide(StringHlp.IsEmpty(author)),
                           new HLabel(article.Get(ArticleType.OriginName))
                           .FontBold().MarginRight(5),
                           new HLabel(string.Format("| {0}", localTime.ToString("dd MMMM yyyy")))
                           ).FontSize("90%"),
                       new HPanel(
                           new HLabel("Комментарии:").Color(Decor.minorColor),
                           ViewNewsHlp.GetCommentElement(commentCount, articleUrl)
                           ).FontSize("90%"),
                       //new HLabel(localTime.ToString(Decor.timeFormat)).Block().FontBold(),
                       new HTextView(article.Get(NewsType.Text)),
                       new HLabel("Автор:").MarginRight(5).Hide(StringHlp.IsEmpty(author)),
                       new HLabel(author).FontBold().MarginRight(5).Hide(StringHlp.IsEmpty(author)),
                       new HLabel("|").MarginRight(5).Hide(StringHlp.IsEmpty(author)),
                       new HLink(article.Get(NewsType.OriginUrl), article.Get(NewsType.OriginName)),
                       new HPanel(
                           new HLabel("Добавил:").MarginRight(5),
                           new HLink(UrlHlp.ShopUrl("user", publisherId), publisher?.Get(UserType.Login))
                           ).MarginTop(5),
                       editPanel,
                       ViewCommentHlp.GetCommentsPanel(context.MessageConnection, state, currentUser, topic, topic.MessageLink.AllRows)
                       ));
        }
Example #4
0
        public static IHtmlControl[] GetArticleItems(SiteState state, IEnumerable <LightObject> articleList)
        {
            List <IHtmlControl> items = new List <IHtmlControl>();

            foreach (LightObject article in articleList)
            {
                DateTime localTime = (article.Get(ObjectType.ActFrom) ?? DateTime.UtcNow).ToLocalTime();

                int    commentCount = context.ArticleStorages.ForTopic(article.Id).MessageLink.AllRows.Length;
                string articleUrl   = UrlHlp.ShopUrl("article", article.Id);
                string imageUrl     = UrlHlp.ImageUrl(article.Id, false);
                string author       = article.Get(ArticleType.Author);

                string annotationWithLink = string.Format(
                    "{0} <a href='{1}'><img src='/images/full.gif'></img></a>",
                    article.Get(ArticleType.Annotation), articleUrl
                    );

                items.Add(
                    new HPanel(
                        new HPanel(
                            new HLink(articleUrl,
                                      article.Get(NewsType.Title)
                                      ).FontSize("14.4px").FontBold(),
                            ViewNewsHlp.GetCommentElement(commentCount, articleUrl)
                            ).FontSize("90%"),
                        new HXPanel(
                            new HPanel(
                                new HPanel().InlineBlock().Size(Decor.ArticleThumbWidth, Decor.ArticleThumbHeight)
                                .Background(imageUrl, "no-repeat", "center").CssAttribute("background-size", "100%")
                                .MarginTop(2).MarginBottom(5)
                                ),
                            new HPanel(
                                new HPanel(
                                    new HLabel(string.Format("{0},", author)).MarginRight(5).Hide(StringHlp.IsEmpty(author)),
                                    new HLabel(article.Get(ArticleType.OriginName)),
                                    new HLabel("//").MarginLeft(5).MarginRight(5),
                                    new HLabel(localTime.ToString("dd MMMM yyyy"))
                                    ).FontSize("90%").MarginBottom(7).MarginTop(2),
                                new HTextView(
                                    annotationWithLink
                                    )
                                ).PaddingLeft(20)
                            )
                        ).Padding(1).BorderBottom("1px solid #e0dede").MarginBottom(5)
                    );
            }

            return(items.ToArray());
        }
Example #5
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);
        }
Example #6
0
        public static IHtmlControl GetActualNewsBlock(SiteState state, LightObject currentUser)
        {
            IHtmlControl[] items = ViewNewsHlp.GetNewsItems(state, context.ActualNews);

            HPanel editBlock = null;
            string editHint  = "news_add";

            if (state.BlockHint == editHint)
            {
                if (state.Tag == null)
                {
                    state.Tag = new List <string>();
                }

                string unsaveText = BasketballHlp.AddCommentFromCookie();

                editBlock = new HPanel(
                    Decor.PropertyEdit("newsTitle", "Заголовок новости"),
                    new HPanel(
                        HtmlHlp.CKEditorCreate("newsText", unsaveText, "300px", true)
                        ),
                    ViewTagHlp.GetEditTagsPanel(state, context.Tags.TagBox, state.Tag as List <string>, true),
                    Decor.PropertyEdit("newsOriginName", "Источник"),
                    Decor.PropertyEdit("newsOriginUrl", "Ссылка"),
                    Decor.Button("Добавить новость").MarginTop(10) //.CKEditorOnUpdateAll()
                    .OnClick(string.Format("CK_updateAll(); {0}", BasketballHlp.AddCommentToCookieScript("newsText")))
                    .Event("save_news_add", "addNewsData",
                           delegate(JsonData json)
                {
                    string title      = json.GetText("newsTitle");
                    string text       = json.GetText("newsText");
                    string originName = json.GetText("newsOriginName");
                    string originUrl  = json.GetText("newsOriginUrl");

                    WebOperation operation = state.Operation;

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

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

                    ParentBox editBox = new ParentBox(context.FabricConnection, "1=0");

                    int addNewsId        = editBox.CreateObject(NewsType.News, NewsType.Title.CreateXmlIds(title), DateTime.UtcNow);
                    LightParent editNews = new LightParent(editBox, addNewsId);

                    editNews.Set(NewsType.PublisherId, currentUser.Id);
                    editNews.Set(NewsType.Text, text);
                    editNews.Set(NewsType.OriginName, originName);
                    editNews.Set(NewsType.OriginUrl, originUrl);

                    ViewTagHlp.SaveTags(context, state, editNews);

                    editBox.Update();

                    context.UpdateNews();

                    state.BlockHint = "";
                    state.Tag       = null;

                    BasketballHlp.ResetAddComment();
                }
                           )
                    ).EditContainer("addNewsData").Padding(5, 10).MarginTop(10).Background(Decor.pageBackground);
            }

            IHtmlControl addButton = null;

            if (currentUser != null && !BasketballHlp.NoRedactor(currentUser))
            {
                addButton = Decor.Button("Добавить").MarginLeft(10)
                            .Event("news_add", "", delegate
                {
                    state.Tag = null;
                    state.SetBlockHint(editHint);
                }
                                   );
            }

            return(new HPanel(
                       Decor.Subtitle("Новости"),
                       new HPanel(
                           items.ToArray()
                           ),
                       new HPanel(
                           new HLink("/novosti",
                                     "Все новости",
                                     new HBefore().ContentIcon(5, 12).BackgroundImage(UrlHlp.ImageUrl("pointer.gif")).MarginRight(5).VAlign(-2)
                                     ).FontBold(),
                           addButton
                           ).MarginTop(15),
                       editBlock
                       ));
        }
Example #7
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));
        }