⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 breadcrumb.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using CommunityServer.Components;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{
    
    public class BreadCrumb : Literal 
    {
        protected CSContext csContext = CSContext.Current;
        protected Queue crumbs = new Queue();
        protected HtmlAnchor anchor;

        #region Properties
		
        /// <summary>
        /// Controls whether or not the root element for the home is shown
        /// </summary>
        [
        System.ComponentModel.DefaultValue( false ),
        ]
        public virtual Boolean ShowHome 
        {
            get 
            {
                Object state = ViewState["ShowHome"];
                if ( state != null ) 
                {
                    return (Boolean)state;
                }
                return false;
            }
            set 
            {
                ViewState["ShowHome"] = value;
            }
        }

        /// <summary>
        ///  Determines whether or not links are hook-ed up.
        /// </summary>
        [
        System.ComponentModel.DefaultValue( true ),
        ]
        public virtual Boolean EnableLinks 
        {
            get 
            {
                Object state = ViewState["EnableLinks"];
                if ( state != null ) 
                {
                    return (Boolean)state;
                }
                return true;
            }
            set 
            {
                ViewState["EnableLinks"] = value;
            }
        }

        #endregion


        protected override void CreateChildControls() 
        {

            // Do we need to add the home link?
            //
            if (ShowHome) 
            {
                crumbs.Enqueue( GetAnchor(CSContext.Current.SiteSettings.SiteName, Globals.GetSiteUrls().ForumsHome) );
            }

            // Is a Forum Group ID specified?
            //
            if (csContext.ForumGroupID > 0)
                AddForumGroup(csContext.ForumGroupID);

            // Is a Forum ID specified?
            //
            if (csContext.ForumID > 0)
                AddForum(csContext.ForumID);

            // Is a PostID specified?
            //
            if (csContext.PostID > 0)
                AddPost(csContext.PostID);

            // We can't find anything useful on the query string
            // so we need to parse the actual URL
            //
            AddByRawURL(csContext.Context.Request.RawUrl);
        }

        protected void AddByRawURL(string url) 
        {
            string comparisonUrl;

            // Unanswered posts
            //
            if (url == Globals.GetSiteUrls().PostsUnanswered) 
            {
                crumbs.Enqueue( GetAnchor(ResourceManager.GetString("ViewUnansweredThreads_Title"), Globals.GetSiteUrls().PostsUnanswered ) );
                return;
            }

            // Not read posts
            //
            if (url == Globals.GetSiteUrls().PostsNotRead) {
                crumbs.Enqueue( GetAnchor(ResourceManager.GetString("ViewNotReadThreads_Title"), Globals.GetSiteUrls().PostsNotRead ) );
                return;
            }

            // Active posts
            //
            if (url == Globals.GetSiteUrls().PostsActive) 
            {
                crumbs.Enqueue( GetAnchor(ResourceManager.GetString("ViewActiveThreads_Title"), Globals.GetSiteUrls().PostsActive ) );
                return;
            }

            // Moderation
            //
            if (url == Globals.GetSiteUrls().Moderate) 
            {
                crumbs.Enqueue( GetAnchor(ResourceManager.GetString("BreadCrumb_Moderation"), Globals.GetSiteUrls().Moderate) );
                return;
            }

            // User Profile
            //
            comparisonUrl = Globals.GetSiteUrls().UserProfile(csContext.UserID);
            if ( url == comparisonUrl) 
            {
                crumbs.Enqueue( GetAnchor( string.Format(ResourceManager.GetString("BreadCrumb_UserProfile"), Users.GetUser(csContext.UserID, false, true).Username), Globals.GetSiteUrls().UserProfile(csContext.UserID)) );
                return;
            }

            // User Profile
            //
            if ( url == Globals.GetSiteUrls().UserEditProfile)
            {
                crumbs.Enqueue( GetAnchor(ResourceManager.GetString("BreadCrumb_EditUserProfile"), Globals.GetSiteUrls().UserEditProfile) );
                return;
            }

            // Search
            //
            if ( url.IndexOf(Globals.GetSiteUrls().Search) > -1) 
            {
                crumbs.Enqueue( GetAnchor(ResourceManager.GetString("BreadCrumb_Search"), Globals.GetSiteUrls().Search) );
                return;
            }
			
			// Who is online
			//
			if ( url == Globals.GetSiteUrls().WhoIsOnline) {
				crumbs.Enqueue( GetAnchor(ResourceManager.GetString("WhoIsOnline_Title"), Globals.GetSiteUrls().WhoIsOnline) );
				return;
			}

            // Private Messages
            //
            if ( url.ToLower().IndexOf(Globals.GetSiteUrls().UserPrivateMessages.ToLower()) > -1 ) 
            {
                crumbs.Enqueue( GetAnchor(CommunityServer.Components.ResourceManager.GetString("PrivateMessages_Title"), Globals.GetSiteUrls().UserPrivateMessages) );
                return;
            }

			// My Forums
			//
			if ( url == Globals.GetSiteUrls().UserMyForums ) 
			{
				crumbs.Enqueue( GetAnchor(CommunityServer.Components.ResourceManager.GetString("ViewMyForumsThreads_Title"), Globals.GetSiteUrls().UserMyForums) );
				return;
			}
        }

        protected void AddPost(int postID) 
        {

            // Get the Post
            //
            ForumPost p = Posts.GetPost(postID, csContext.User.UserID);

            // Get the forum
            //
            Forum f = (Forum) Forums.GetForum(p.SectionID);

			// If forum is null, it is probably a post from another application... just return to avoid null references
			if(f == null)
				return;

            // Add the forum group, only if not viewing Private Messages
            //
            if (f.SectionID > 0)
            {
                AddForumGroup(f.GroupID);

                // Recursivley add the forums
                //
                RecursivlyAddForums(f);
            } 
            else 
            {
                // We add an anchor to return to the Private Messages
                //
                crumbs.Enqueue( GetAnchor(CommunityServer.Components.ResourceManager.GetString("PrivateMessages_Title"), Globals.GetSiteUrls().UserPrivateMessages) );
            }


            // Finally add the post
            //
            crumbs.Enqueue( GetAnchor(p.Subject, Globals.GetSiteUrls().Post(p.PostID)) );

        }

        protected void RecursivlyAddForums(Forum f) 
        {

            // Recurse
            //
            if (f.ParentID > 0) 
            {
                Forum parent = Forums.GetForum(f.ParentID) as Forum;
                RecursivlyAddForums( parent );
            }

            // Next add forums
            //
            crumbs.Enqueue( GetAnchor(f.Name, ForumUrls.Instance().Forum(f.SectionID)) );

        }

        protected void AddForum(int forumID) 
        {

            // Get the forum
            //
            Forum f = Forums.GetForum(forumID, true, true) as Forum;
            User user = CSContext.Current.User;

            // Only add the forum group if the user is allowed to see it
            //
            try 
            {
                Permissions.AccessCheck(f, Permission.View, user );
                Permissions.AccessCheck(f, Permission.Read, user );

                // First add the forum group
                //
                AddForumGroup(f.GroupID);
            } 
            catch {}

            // Recursively add forums
            //
            RecursivlyAddForums(f);

        }

        protected virtual void AddForumGroup(int forumGroupID) 
        {

            // Get the forum group
            //
            Group f = ForumGroups.GetForumGroup(forumGroupID);

            crumbs.Enqueue( GetAnchor(f.Name, Globals.GetSiteUrls().ForumGroup(forumGroupID) ) );
        }

        protected Control GetAnchor(string innerText, string href) 
        {
            anchor = new HtmlAnchor();
            anchor.InnerHtml = innerText;
            anchor.Attributes["class"] = "lnk3";
            anchor.HRef = href;

            return anchor;
        }

        protected override void Render(HtmlTextWriter writer) 
        {

            while(crumbs.Count > 0) 
            {
                HtmlAnchor a = (HtmlAnchor) crumbs.Dequeue();

				// add title for hover over
				a.Title = a.InnerHtml;

				if ((crumbs.Count > 0) && (a.InnerHtml.Length > 15))
					a.InnerHtml = a.InnerHtml.Substring(0,15) + "...";

                a.RenderControl(writer);

                if (crumbs.Count > 0)
                    writer.Write(ResourceManager.GetString("BreadCrumb_Seperator"));

            }
            
        }

        

    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -