예제 #1
0
        private Boolean InitPage(BlogArticle article)
        {
            Boolean loaded = false;

            try
            {
                article.RenderHead(HeadContent);
                article.RenderContent(ArticleContent);

                loaded = true;
            }
            catch
            {

            }

            return loaded;
        }
예제 #2
0
        public void Render(StringBuilder sb, IEnumerable menuItems, PageInfo page, BlogArticle article, MenuRenderingType direction)
        {
            if (direction != MenuRenderingType.None)
            {
                sb.AppendFormat("<div class='page-navigation-menu {0}'>", direction == MenuRenderingType.Horizontal ? "horizontal" : "vertical");

                Boolean isFirst = true;

                foreach (Object menuItem in menuItems)
                {
                    MenuInfo menu = null;

                    if (menuItem is String)
                    {
                        String menuItemName = menuItem as String;

                        if (String.IsNullOrEmpty(menuItemName))
                            continue;

                        menu = FindMenuByName(menuItemName);
                    }
                    else if (menuItem is MenuInfo)
                    {
                        menu = menuItem as MenuInfo;
                    }
                    else
                        throw new Exception(String.Format("Unknown type {0}.", menuItem.GetType().Name));

                    if (menu == null)
                        continue;

                    if (!isFirst)
                        sb.Append("<div class='menu-separator'>&nbsp;</div>");

                    menu.Render(sb, page, article, direction);

                    isFirst = false;
                }

                sb.Append("</div>");
            }
        }
예제 #3
0
        public void Render(HtmlTextWriter writer, IEnumerable menuItems, PageInfo page, BlogArticle article, MenuRenderingType direction)
        {
            StringBuilder sb = new StringBuilder();

            Render(sb, menuItems, page, article, direction);

            writer.Write(sb.ToString());
        }
예제 #4
0
        private static List<BlogArticle> ParseXml(out Int32 nextItemID)
        {
            nextItemID = 1;
            List<BlogArticle> data = null;
            XmlDocument doc = FileManager.GetXmlDocument(XmlPath);

            if (doc != null)
            {
                data = new List<BlogArticle>();

                XmlNode root = doc.GetElementsByTagName("blog")[0];

                foreach (XmlNode node in root.ChildNodes)
                {
                    switch (node.Name)
                    {
                        case "article":
                            BlogArticle article = new BlogArticle(node);
                            data.Add(article);

                            if (article.ID > nextItemID)
                                nextItemID = article.ID;

                            break;
                        default:
                            throw new NotImplementedException(String.Format("Unknown XML tag: {0}", node.Name));
                    }
                }

                if (data.Count > 0)
                    nextItemID++;

                data.Sort();
            }

            return data;
        }
예제 #5
0
        public Boolean IsDuplicate(BlogArticle article)
        {
            BlogArticle existsArticle = FindArticleByIndexName(article.IndexName);

            return article.IsNew && existsArticle != null || !article.IsNew && article.ID != existsArticle.ID;
        }
예제 #6
0
        public void AddArticle(BlogArticle article)
        {
            if (!article.IsNew)
                return;

            article.ID = _nextArticleID++;

            _articles.Add(article);
        }
예제 #7
0
        public static void SaveArticleHtmlFile(BlogArticle article, String content)
        {
            if (String.IsNullOrEmpty(article.FileName))
                article.FileName = GenerateArticleFileName(article.Date);

            String virtualPath = FileManager.GetArticleFileRelativePath(article.FileName);
            TryToDeleteFile(virtualPath);

            String physicalPath = Server.MapPath(virtualPath);
            File.WriteAllText(physicalPath, content, _defaultEncoding);
        }
예제 #8
0
        public void Render(StringBuilder sb, PageInfo page, BlogArticle article)
        {
            if (!IsVisible(page, article))
                return;

            Boolean isAdmin = HttpContext.Current.User.Identity.IsAuthenticated;

            String url =
                    isAdmin && !String.IsNullOrEmpty(AdminHref)
                        ? AdminHref
                        : Href;

            if (!String.IsNullOrEmpty(url))
            {
                if (url.IndexOf("{$id}") >= 0 || url.IndexOf("{$article_id}") >= 0)
                {
                    if (page != null)
                        url = url.Replace("{$id}", page.ID.ToString());

                    if (article != null)
                        url = url.Replace("{$article_id}", article.ID.ToString());
                }

                sb.AppendFormat("<a href='{0}'", url);

                if (!String.IsNullOrEmpty(Target))
                    sb.AppendFormat(" target='{0}'", Target);

                sb.AppendFormat(">{0}</a> ", isAdmin && !String.IsNullOrEmpty(AdminTitle) ? AdminTitle : Title);

                sb.Append(Text);
            }
            else
            {
                sb.Append(Title);
            }
        }
예제 #9
0
        public Boolean IsVisible(PageInfo page, BlogArticle article)
        {
            Boolean isVisible = (!AdminOnly || HttpContext.Current.User.Identity.IsAuthenticated)
                && (String.IsNullOrEmpty(Href) || (Href.IndexOf("{$id}") < 0 || page != null) && (Href.IndexOf("{$article_id}") < 0 || article != null));

            if (isVisible && !String.IsNullOrEmpty(VisibeForUrl))
            {
                String rawUrl = HttpContext.Current.Request.RawUrl;

                isVisible = Regex.IsMatch(rawUrl, VisibeForUrl, RegexOptions.IgnoreCase);
            }

            return isVisible;
        }
예제 #10
0
        private void InitEditor(BlogArticle article)
        {
            if (article != null)
            {
                Title.Text = article.Title;
                Date.SelectedDate = article.Date;
                IsVisible.Checked = article.IsVisible;
                ImageSrc.Text = article.ImageSource;
                HomeImageSrc.Text = article.HomePageImageSource;
                Description.Text = article.Description;
                MetaDescription.Text = article.MetaDescription;
                MetaKeywords.Text = article.MetaKeywords;
                FileName.Text = String.IsNullOrEmpty(article.FileName) ? null : article.FileName + ".html";
                ContentEditor.Content = FileManager.GetArticleContent(article.FileName);
                PageName.Text = article.Name;

                String url = LinkUtils.GetArticleUrl(article.IndexName);

                PageLink.NavigateUrl = url;
                PageLink.Text = LinkUtils.ResolveAbsoluteUrl(url);
                PageLinkField.Visible = true;
            }
            else
            {
                CloseEditor();
            }
        }
예제 #11
0
        private void RenderSectionVertical(StringBuilder sb, PageInfo page, BlogArticle article, MenuSectionInfo section)
        {
            String listClass = section.Bullet == VerticalMenuBulletType.Sun
                ? "sun-bullet-list"
                : section.Bullet == VerticalMenuBulletType.Triangle
                    ? "triangle-bullet-list"
                    : null;

            sb.AppendFormat("<div class='menu-list-container'><ul class='{0}'>", listClass);

            foreach (MenuItemInfo item in section.Items)
            {
                if (item.IsVisible(page, article))
                {
                    sb.Append("<li>");
                    item.Render(sb, page, article);
                    sb.Append("</li>");
                }
            }

            sb.Append("</ul></div>");
        }
예제 #12
0
        private void RenderSectionHorizontal(StringBuilder sb, PageInfo page, BlogArticle article, MenuSectionInfo section)
        {
            foreach (MenuItemInfo item in section.Items)
            {
                if (item.IsVisible(page, article))
                {
                    sb.AppendFormat(" {0} ", section.HorizontalSeparator);

                    item.Render(sb, page, article);
                }
            }

            sb.AppendFormat(" {0} ", section.HorizontalSeparator);
        }
예제 #13
0
        public void Render(StringBuilder sb, PageInfo page, BlogArticle article, MenuRenderingType direction)
        {
            foreach (MenuSectionInfo section in _sections)
            {
                if (section.ShowHeader && !String.IsNullOrEmpty(section.Title))
                    sb.AppendFormat("<div class='menu-section-title'>{0}</div>", section.Title);

                if (!section.IsHtml)
                {
                    if (direction == MenuRenderingType.Horizontal)
                        RenderSectionHorizontal(sb, page, article, section);
                    else if (direction == MenuRenderingType.Vertical)
                        RenderSectionVertical(sb, page, article, section);
                }
                else
                {
                    sb.AppendFormat("<div class='menu-list-container'>{0}</div>", section.InnerHtml);
                }
            }
        }