예제 #1
0
        public TagStore(ObjectHeadBox tagBox)
        {
            this.TagBox = tagBox;

            foreach (int tagId in tagBox.AllObjectIds)
            {
                string tagName = TagType.DisplayName.Get(tagBox, tagId);
                if (StringHlp.IsEmpty(tagName))
                {
                    continue;
                }

                string tagKey = tagName.ToLower();
                TagIdByKey[tagKey] = tagId;
            }

            foreach (string key in TagIdByKey.Keys)
            {
                int tagId = TagIdByKey[key];

                string[] words = key.Split(new char[] { ' ', ',', '-' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string word in words)
                {
                    List <int> ids;
                    if (!tagIdsByWord.TryGetValue(word, out ids))
                    {
                        ids = new List <int>();
                        tagIdsByWord[word] = ids;
                    }
                    ids.Add(tagId);
                }
            }
        }
예제 #2
0
        public static List <string> GetTopicDisplayTags(ObjectHeadBox tagBox, LightParent topic)
        {
            LightHead[]   tags        = GetTopicTags(tagBox, topic);
            List <string> displayTags = new List <string>(tags.Length);

            foreach (LightHead tag in tags)
            {
                displayTags.Add(tag.Get(TagType.DisplayName));
            }
            return(displayTags);
        }
예제 #3
0
        static RowLink[] GetTagRows(ObjectHeadBox tagBox, int[] tagIds)
        {
            List <RowLink> tagRows = new List <RowLink>(tagIds.Length);

            foreach (int tagId in tagIds)
            {
                RowLink tagRow = tagBox.ObjectById.AnyRow(tagId);
                if (tagRow != null)
                {
                    tagRows.Add(tagRow);
                }
            }
            return(tagRows.ToArray());
        }
예제 #4
0
        public static LightHead[] GetTopicTags(ObjectHeadBox tagBox, LightParent topic)
        {
            int[]            tagIds = topic.AllChildIds(TopicType.TagLinks);
            List <LightHead> tags   = new List <LightHead>(tagIds.Length);

            foreach (int tagId in tagIds)
            {
                if (tagBox.ObjectById.Exist(tagId))
                {
                    tags.Add(new LightHead(tagBox, tagId));
                }
            }
            return(tags.ToArray());
        }
예제 #5
0
        public ForumSectionStorage(IDataLayer fabricConnection, int sectionId)
        {
            this.fabricConnection = fabricConnection;
            this.SectionId        = sectionId;

            this.topicsCache = new Cache <LightHead[], long>(
                delegate
            {
                ObjectHeadBox topicBox = new ObjectHeadBox(fabricConnection,
                                                           "obj_id in (Select child_id from light_link Where parent_id = @parentId and type_id = @linkTypeId) order by act_till desc",
                                                           new DbParameter("parentId", sectionId),
                                                           new DbParameter("linkTypeId", ForumSectionType.TopicLinks.Kind)
                                                           );

                return(ArrayHlp.Convert(topicBox.AllObjectIds, delegate(int topicId)
                                        { return new LightHead(topicBox, topicId); }
                                        ));
            },
                delegate { return(dataChangeTick); }
                );
        }
예제 #6
0
        public static IHtmlControl GetViewTagsPanel(ObjectHeadBox tagBox, LightParent topic)
        {
            List <IHtmlControl> elements = new List <IHtmlControl>();

            elements.Add(new HLabel("Теги:").FontBold().MarginRight(5));
            int[] tagIds = topic.AllChildIds(TopicType.TagLinks);

            RowLink[] tagRows = GetTagRows(tagBox, tagIds);

            //tagsDisplay = StringHlp.Join(", ", tagRows, delegate (RowLink row)
            //  { return TagType.DisplayName.Get(row); }
            //);

            foreach (RowLink tagRow in tagRows)
            {
                elements.Add(
                    new HLink(TagUrl(tagRow.Get(ObjectType.ObjectId), 0), TagType.DisplayName.Get(tagRow)).MarginRight(5)
                    );
            }

            return(new HPanel(
                       elements.ToArray()
                       ).MarginTop(10));
        }
예제 #7
0
        public static IHtmlControl GetEditTagsPanel(SiteState state,
                                                    ObjectHeadBox tagBox, List <string> tags, bool isAdd)
        {
            if (tags == null)
            {
                return(null);
            }

            List <IHtmlControl> tagElements = new List <IHtmlControl>();
            int i = -1;

            foreach (string tag in tags)
            {
                ++i;
                int index = i;
                tagElements.Add(
                    new HPanel(
                        new HLabel(tag),
                        new HButton("",
                                    std.BeforeAwesome(@"\f00d", 0)
                                    ).MarginLeft(5).Color(Decor.redColor).Title("удалить тег")
                        .Event("tag_remove", "", delegate
                {
                    if (index < tags.Count)
                    {
                        tags.RemoveAt(index);
                    }
                },
                               index
                               )
                        ).InlineBlock().MarginTop(5).MarginRight(5)
                    );
            }

            string addTagName = string.Format("addTag_{0}", state.OperationCounter);
            string onClick    = !isAdd ? ";" :
                                string.Format("CK_updateAll(); {0}", BasketballHlp.AddCommentToCookieScript("newsText"));

            return(new HPanel(
                       new HPanel(
                           tagElements.ToArray()
                           ).MarginBottom(5),
                       new HPanel(
                           new HTextEdit(addTagName).Width(400).MarginRight(5).MarginBottom(5)
                           .MediaSmartfon(new HStyle().Width("100%")),
                           Decor.Button("Добавить тэг").VAlign(-1).MarginBottom(5)
                           .OnClick(onClick)
                           .Event("tag_add", "addTagData",
                                  delegate(JsonData json)
            {
                string addTag = json.GetText(addTagName);
                if (StringHlp.IsEmpty(addTag))
                {
                    return;
                }

                if (tags.Contains(addTag))
                {
                    return;
                }

                string[] newTags = addTag.Split(',');
                foreach (string rawTag in newTags)
                {
                    string tag = rawTag.Trim();
                    if (!StringHlp.IsEmpty(tag))
                    {
                        tags.Add(tag);
                    }
                }

                state.OperationCounter++;
            })
                           ).EditContainer("addTagData")
                       ).MarginTop(5));
        }
예제 #8
0
        public static void SaveTags(BasketballContext context, SiteState state, LightParent editTopic)
        {
            List <string> tags = state.Tag as List <string>;

            if (tags == null)
            {
                return;
            }

            ObjectHeadBox editBox = null;
            List <int>    tagIds  = new List <int>();

            foreach (string tag in tags)
            {
                if (StringHlp.IsEmpty(tag))
                {
                    continue;
                }

                string tagKey = tag.ToLower();
                {
                    int tagId;
                    if (context.TagIdByKey.TryGetValue(tagKey, out tagId))
                    {
                        tagIds.Add(tagId);
                        continue;
                    }
                }

                string xmlIds = TagType.DisplayName.CreateXmlIds(tag);
                //RowLink tagRow = context.Tags.ObjectByXmlIds.AnyRow(xmlIds);
                //if (tagRow != null)
                //{
                //  tagIds.Add(tagRow.Get(ObjectType.ObjectId));
                //  continue;
                //}

                if (editBox == null)
                {
                    editBox = new ObjectHeadBox(context.FabricConnection, "1=0");
                }

                int?newTagId = editBox.CreateUniqueObject(TagType.Tag, xmlIds, null);
                if (newTagId == null)
                {
                    continue;
                }

                tagIds.Add(newTagId.Value);
            }

            if (editBox != null)
            {
                editBox.Update();
                context.UpdateTags();
            }

            for (int i = 0; i < tagIds.Count; ++i)
            {
                int tagId = tagIds[i];
                if (tagId != editTopic.GetChildId(TopicType.TagLinks, i))
                {
                    editTopic.SetChildId(TopicType.TagLinks, i, tagId);
                }
            }

            RowLink[] allTagRows = editTopic.AllChildRows(TopicType.TagLinks);
            for (int i = allTagRows.Length - 1; i >= tagIds.Count; --i)
            {
                editTopic.RemoveChildLink(TopicType.TagLinks, i);
            }
        }
예제 #9
0
        public BasketballContext(string rootPath,
                                 EditorSelector sectionEditorSelector, EditorSelector unitEditorSelector,
                                 IDataLayer userConnection, IDataLayer fabricConnection,
                                 IDataLayer messageConnection, IDataLayer forumConnection)
        {
            this.rootPath              = rootPath;
            this.imagesPath            = Path.Combine(RootPath, "Images");
            this.userConnection        = userConnection;
            this.fabricConnection      = fabricConnection;
            this.messageConnection     = messageConnection;
            this.forumConnection       = forumConnection;
            this.sectionEditorSelector = sectionEditorSelector;
            this.unitEditorSelector    = unitEditorSelector;

            this.userStorage     = new UserStorage(userConnection);
            this.NewsStorages    = new TopicStorageCache(fabricConnection, messageConnection, NewsType.News);
            this.ArticleStorages = new TopicStorageCache(fabricConnection, messageConnection, ArticleType.Article);
            this.Forum           = new ForumStorageCache(fabricConnection, forumConnection);

            string settingsPath = Path.Combine(rootPath, "SiteSettings.config");

            if (!File.Exists(settingsPath))
            {
                this.siteSettings = new SiteSettings();
            }
            else
            {
                this.siteSettings = XmlSerialization.Load <SiteSettings>(settingsPath);
            }

            this.pull = new TaskPull(
                new ThreadLabel[] { Labels.Service },
                TimeSpan.FromMinutes(15)
                );

            this.newsCache = new Cache <Tuple <ObjectHeadBox, LightHead[]>, long>(
                delegate
            {
                ObjectHeadBox newsBox = new ObjectHeadBox(fabricConnection,
                                                          string.Format("{0} order by act_from desc", DataCondition.ForTypes(NewsType.News))
                                                          );

                int[] allNewsIds = newsBox.AllObjectIds;

                List <LightHead> actualNews = new List <LightHead>();
                for (int i = 0; i < Math.Min(22, allNewsIds.Length); ++i)
                {
                    int newsId = allNewsIds[i];
                    actualNews.Add(new LightHead(newsBox, newsId));
                }

                return(_.Tuple(newsBox, actualNews.ToArray()));
            },
                delegate { return(newsChangeTick); }
                );

            this.articlesCache = new Cache <Tuple <ObjectBox, LightObject[]>, long>(
                delegate
            {
                ObjectBox articleBox = new ObjectBox(fabricConnection,
                                                     string.Format("{0} order by act_from desc", DataCondition.ForTypes(ArticleType.Article))
                                                     );

                int[] allArticleIds = articleBox.AllObjectIds;

                ObjectBox actualBox = new ObjectBox(FabricConnection,
                                                    string.Format("{0} order by act_from desc limit 5", DataCondition.ForTypes(ArticleType.Article))
                                                    );

                List <LightObject> actualArticles = new List <LightObject>();
                foreach (int articleId in actualBox.AllObjectIds)
                {
                    actualArticles.Add(new LightObject(actualBox, articleId));
                }

                return(_.Tuple(articleBox, actualArticles.ToArray()));
            },
                delegate { return(articleChangeTick); }
                );

            this.lightStoreCache = new Cache <IStore, long>(
                delegate
            {
                LightObject contacts = DataBox.LoadOrCreateObject(fabricConnection,
                                                                  ContactsType.Contacts, ContactsType.Kind.CreateXmlIds, "main");

                LightObject seo = DataBox.LoadOrCreateObject(fabricConnection,
                                                             SEOType.SEO, SEOType.Kind.CreateXmlIds, "main");

                SectionStorage sections = SectionStorage.Load(fabricConnection);

                WidgetStorage widgets = WidgetStorage.Load(fabricConnection, siteSettings.DisableScripts);

                RedirectStorage redirects = RedirectStorage.Load(fabricConnection);

                SiteStore store = new SiteStore(sections, null, widgets, redirects, contacts, seo);
                store.Links.AddLink("register", null);
                store.Links.AddLink("passwordreset", null);

                return(store);
            },
                delegate { return(dataChangeTick); }
                );

            this.lastPublicationCommentsCache = new Cache <RowLink[], long>(
                delegate
            {
                DataTable table = messageConnection.GetTable("",
                                                             "Select Distinct article_id From message order by create_time desc limit 10"
                                                             );

                List <RowLink> lastComments = new List <RowLink>(10);
                foreach (DataRow row in table.Rows)
                {
                    int topicId = ConvertHlp.ToInt(row[0]) ?? -1;

                    if (News.ObjectById.Exist(topicId))
                    {
                        TopicStorage topic  = NewsStorages.ForTopic(topicId);
                        RowLink lastMessage = _.Last(topic.MessageLink.AllRows);
                        if (lastMessage != null)
                        {
                            lastComments.Add(lastMessage);
                        }
                    }
                    else if (Articles.ObjectById.Exist(topicId))
                    {
                        TopicStorage topic  = ArticleStorages.ForTopic(topicId);
                        RowLink lastMessage = _.Last(topic.MessageLink.AllRows);
                        if (lastMessage != null)
                        {
                            lastComments.Add(lastMessage);
                        }
                    }
                }

                return(lastComments.ToArray());
            },
                delegate { return(publicationCommentChangeTick); }
                );

            this.lastForumCommentsCache = new Cache <RowLink[], long>(
                delegate
            {
                DataTable table = forumConnection.GetTable("",
                                                           "Select Distinct article_id From message order by create_time desc limit 7"
                                                           );

                List <RowLink> lastComments = new List <RowLink>(7);
                foreach (DataRow row in table.Rows)
                {
                    int topicId = ConvertHlp.ToInt(row[0]) ?? -1;

                    TopicStorage topic  = Forum.TopicsStorages.ForTopic(topicId);
                    RowLink lastMessage = _.Last(topic.MessageLink.AllRows);
                    if (lastMessage != null)
                    {
                        lastComments.Add(lastMessage);
                    }
                }

                return(lastComments.ToArray());
            },
                delegate { return(forumCommentChangeTick); }
                );

            this.tagsCache = new Cache <TagStore, long>(
                delegate
            {
                ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc");

                return(new TagStore(tagBox));
            },
                delegate { return(tagChangeTick); }
                );

            //this.tagsCache = new Cache<Tuple<ObjectHeadBox, Dictionary<string, int>>, long>(
            //  delegate
            //  {
            //    ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc");

            //    Dictionary<string, int> tagIdByKey = new Dictionary<string, int>();
            //    foreach (int tagId in tagBox.AllObjectIds)
            //    {
            //      string tagName = TagType.DisplayName.Get(tagBox, tagId);
            //      if (StringHlp.IsEmpty(tagName))
            //        continue;

            //      string tagKey = tagName.ToLower();
            //      tagIdByKey[tagKey] = tagId;
            //    }

            //    return _.Tuple(tagBox, tagIdByKey);
            //  },
            //  delegate { return tagChangeTick; }
            //);

            this.unreadDialogCache = new Cache <TableLink, long>(
                delegate
            {
                return(DialogueHlp.LoadUnreadLink(forumConnection));
            },
                delegate { return(unreadChangeTick); }
                );

            Pull.StartTask(Labels.Service,
                           SiteTasks.SitemapXmlChecker(this, rootPath,
                                                       delegate(LinkInfo[] sectionlinks)
            {
                List <LightLink> allLinks = new List <LightLink>();
                allLinks.AddRange(
                    ArrayHlp.Convert(sectionlinks, delegate(LinkInfo link)
                {
                    return(new LightLink(link.Directory, null));
                })
                    );

                foreach (int articleId in Articles.AllObjectIds)
                {
                    LightHead article = new LightHead(Articles, articleId);
                    allLinks.Add(
                        new LightLink(UrlHlp.ShopUrl("article", articleId),
                                      article.Get(ObjectType.ActTill) ?? article.Get(ObjectType.ActFrom)
                                      )
                        );
                }

                foreach (int newsId in News.AllObjectIds)
                {
                    LightHead news = new LightHead(News, newsId);
                    allLinks.Add(
                        new LightLink(UrlHlp.ShopUrl("news", newsId),
                                      news.Get(ObjectType.ActTill) ?? news.Get(ObjectType.ActFrom)
                                      )
                        );
                }

                //foreach (int tagId in Tags.AllObjectIds)
                //{
                //  LightHead tag = new LightHead(Tags, tagId);
                //  allLinks.Add(
                //    new LightLink(string.Format("/tags?tag={0}", tagId)
                //    )
                //  );
                //}

                return(allLinks.ToArray());
            }
                                                       )
                           );
        }