ViewPost.cs :  » Bloggers » SubText » Subtext » Web » UI » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » Subtext » Web » UI » Controls » ViewPost.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ninject;
using Subtext.Extensibility.Interfaces;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Data;
using Subtext.Framework.Security;
using Subtext.Framework.Services;
using Subtext.Framework.Tracking;
using Subtext.Infrastructure;
using Subtext.Web.Controls;
using Subtext.Web.Properties;

namespace Subtext.Web.UI.Controls{
    /// <summary>
    ///  Control used to view a single blog post.
    /// </summary>
    public partial class ViewPost : BaseControl
    {
        const string LinkToComments = "<a href=\"{0}#feedback\" title=\"View and Add Comments\">{1}{2}</a>";
        const string LinkToEnclosure = "<a href=\"{0}\" title = \"{1}\">{2}</a>{3}";

        /// <summary>
        /// Loads the entry specified by the URL.  If the user is an 
        /// admin and the skin supports it, will also display an edit 
        /// link that navigates to the admin section and allows the 
        /// admin to edit the post.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //Get the entry
            Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext);

            //if found
            if(entry != null)
            {
                BindCurrentEntryControls(entry, this);

                DisplayEditLink(entry);

                Bootstrapper.RequestContext = SubtextContext.RequestContext;
                var statistics = Bootstrapper.ServiceLocator.GetService<IStatisticsService>();
                statistics.RecordWebView(new EntryView {EntryId = entry.Id, BlogId = Blog.Id});

                //Set the page title
                Globals.SetTitle(entry.Title, Context);

                //Sent entry properties
                TitleUrl.Text = entry.Title;
                ControlHelper.SetTitleIfNone(TitleUrl, "Title of this entry.");
                TitleUrl.NavigateUrl = Url.EntryUrl(entry);
                Body.Text = entry.Body;
                if(PostDescription != null)
                {
                    PostDescription.Text = string.Format(CultureInfo.InvariantCulture, "{0} {1}",
                                                         entry.DateSyndicated.ToLongDateString(),
                                                         entry.DateSyndicated.ToShortTimeString());
                }
                Trace.Write("loading categories");
                if(Categories != null)
                {
                    Categories.LinkCategories = Links.GetLinkCategoriesByPostId(entry.Id);
                    Categories.DataBind();
                }

                if(date != null)
                {
                    string entryUrl = Url.EntryUrl(entry);
                    if(date.Attributes["Format"] != null)
                    {
                        date.Text = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{2}\">{1}</a>",
                                                  entryUrl, entry.DateSyndicated.ToString(date.Attributes["Format"]),
                                                  Resources.EntryList_PermanentLink);
                        date.Attributes.Remove("Format");
                    }
                    else
                    {
                        date.Text = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{2}\">{1}</a>",
                                                  entryUrl, entry.DateSyndicated.ToString("f"),
                                                  Resources.EntryList_PermanentLink);
                    }
                }

                if(commentCount != null)
                {
                    if(Blog.CommentsEnabled && entry.AllowComments)
                    {
                        string entryUrl = Url.EntryUrl(entry);
                        if(entry.FeedBackCount == 0)
                        {
                            commentCount.Text = string.Format(LinkToComments, entryUrl, Resources.EntryList_AddComment,
                                                              string.Empty);
                        }
                        else if(entry.FeedBackCount == 1)
                        {
                            commentCount.Text = string.Format(LinkToComments, entryUrl, Resources.EntryList_OneComment,
                                                              string.Empty);
                        }
                        else if(entry.FeedBackCount > 1)
                        {
                            commentCount.Text = string.Format(LinkToComments, entryUrl, entry.FeedBackCount,
                                                              Resources.EntryList_CommentsPlural);
                        }
                    }
                }

                BindEnclosure(entry);

                //Set Pingback/Trackback 
                if(PingBack == null)
                {
                    PingBack = Page.FindControl("pinbackLinkTag") as Literal;
                }

                if(PingBack != null)
                {
                    PingBack.Text = TrackHelpers.GetPingPackTag(Url);
                }

                if(TrackBack != null)
                {
                    TrackBack.Text = TrackHelpers.TrackBackTag(entry, Blog, Url);
                }
            }
            else
            {
                //No post? Deleted? Help :)
                Controls.Clear();
                Controls.Add(new LiteralControl(Resources.ViewPost_EntryNotFound));
            }
        }

        private void BindEnclosure(Entry entry)
        {
            if(Enclosure != null)
            {
                if(entry.Enclosure != null && entry.Enclosure.ShowWithPost)
                {
                    bool displaySize;
                    Boolean.TryParse(Enclosure.Attributes["DisplaySize"], out displaySize);

                    string sizeStr = "";
                    if(displaySize)
                    {
                        sizeStr = string.Format(" ({0})", entry.Enclosure.FormattedSize);
                    }
                    Enclosure.Text = string.Format(LinkToEnclosure, entry.Enclosure.Url, entry.Enclosure.Title,
                                                   entry.Enclosure.Title, sizeStr);
                }
            }
        }

        // If the user is an admin AND the the skin 
        // contains an edit Hyperlink control, this 
        // will display the edit control.
        private void DisplayEditLink(IIdentifiable entry)
        {
            if(editLink != null)
            {
                if(SecurityHelper.IsAdmin)
                {
                    editLink.Visible = true;
                    editLink.NavigateUrl = AdminUrl.PostsEdit(entry.Id);
                    ControlHelper.SetTitleIfNone(editLink, Resources.ViewPost_EditThisEntry);

                    if(String.IsNullOrEmpty(editLink.Text) && String.IsNullOrEmpty(editLink.ImageUrl))
                    {
                        //We'll slap on our little pencil icon.
                        editLink.ImageUrl = Url.EditIconUrl();
                    }
                }
                else
                {
                    editLink.Visible = false;
                }
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.