Beispiel #1
0
        /// <summary>
        /// 生成链接标签
        /// </summary>
        /// <param name="htmlHelper">被扩展的HtmlHelper实例</param>
        /// <param name="text">链接文本</param>
        /// <param name="url">链接地址</param>
        /// <param name="title">链接提示文字(必填)</param>
        /// <param name="htmlAttributes">链接的其他属性集合</param>
        /// <param name="navigateTarget">头衔图片链接的Target</param>
        /// <returns></returns>
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string text, string url, string title, object htmlAttributes = null, HyperLinkTarget navigateTarget = HyperLinkTarget._self)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(MvcHtmlString.Empty);
            }

            //if (string.IsNullOrEmpty(title))
            //{
            //    throw new ExceptionFacade("参数名称title不能为空");
            //}

            if (string.IsNullOrEmpty(url))
            {
                url = "javascript:void(0)";
            }

            TagBuilder builder = new TagBuilder("a");

            builder.MergeAttribute("href", url);
            builder.SetInnerText(text);
            builder.MergeAttribute("title", title);
            if (navigateTarget != HyperLinkTarget._self)
            {
                builder.MergeAttribute("target", navigateTarget.ToString());
            }
            if (htmlAttributes != null)
            {
                builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            }
            return(MvcHtmlString.Create(builder.ToString()));
        }
Beispiel #2
0
        /// <summary>
        ///     生成链接标签
        /// </summary>
        /// <param name="htmlHelper">被扩展的HtmlHelper实例</param>
        /// <param name="text">链接文本(必填)</param>
        /// <param name="url">链接地址</param>
        /// <param name="title">链接提示文字(不填则默认与text相同)</param>
        /// <param name="isLayer">是否是弹层</param>
        /// <param name="htmlAttributes">链接的其他属性集合</param>
        /// <param name="navigateTarget">头衔图片链接的Target</param>
        /// <returns></returns>
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string text, string url, string title,
            bool isLayer = false, object htmlAttributes = null, HyperLinkTarget navigateTarget = HyperLinkTarget._self)
        {
            if (string.IsNullOrEmpty(text))
                return MvcHtmlString.Empty;

            if (string.IsNullOrEmpty(url))
                url = "javascript:void(0)";

            if (string.IsNullOrEmpty(title))
                title = text;

            var builder = new TagBuilder("a");
            if (isLayer)
            {
                builder.MergeAttribute("href", "javascript:void(0)");
                builder.MergeAttribute("data-href", url);
                builder.MergeAttribute("plugin", "layer");
            }
            else
            {
                builder.MergeAttribute("href", url);
            }
            builder.SetInnerText(text);
            builder.MergeAttribute("title", title);
            if (navigateTarget != HyperLinkTarget._self)
                builder.MergeAttribute("target", navigateTarget.ToString());
            if (htmlAttributes != null)
                builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            return MvcHtmlString.Create(builder.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// 生成链接标签
        /// </summary>
        /// <param name="htmlHelper">被扩展的HtmlHelper实例</param>
        /// <param name="text">链接文本</param>
        /// <param name="url">链接地址</param>
        /// <param name="title">链接提示文字(必填)</param>
        /// <param name="htmlAttributes">链接的其他属性集合</param>
        /// <param name="navigateTarget">头衔图片链接的Target</param>
        /// <returns></returns>
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string text, string url, string title, object htmlAttributes = null, HyperLinkTarget navigateTarget = HyperLinkTarget._self)
        {
            if (string.IsNullOrEmpty(text))
                return MvcHtmlString.Empty;

            //if (string.IsNullOrEmpty(title))
            //{
            //    throw new ExceptionFacade("参数名称title不能为空");
            //}

            if (string.IsNullOrEmpty(url))
            {
                url = "javascript:void(0)";
            }

            TagBuilder builder = new TagBuilder("a");
            builder.MergeAttribute("href", url);
            builder.SetInnerText(text);
            builder.MergeAttribute("title", title);
            if (navigateTarget != HyperLinkTarget._self)
                builder.MergeAttribute("target", navigateTarget.ToString());
            if (htmlAttributes != null)
                builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            return MvcHtmlString.Create(builder.ToString());
        }
        /// <summary>
        /// 根据文件类型显示缩略图
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="fileName">文件名称</param>
        /// <param name="thumbnailSize">缩略图大小</param>
        /// <param name="navigateUrl">缩略图链接地址</param>
        /// <param name="navigateTarget">链接目标</param>
        /// <returns></returns>
        public static MvcHtmlString ContentTypeThumbnail(this HtmlHelper htmlHelper, string fileName, ContentTypeThumbnailSize thumbnailSize, string navigateUrl = null, HyperLinkTarget navigateTarget = HyperLinkTarget._self)
        {
            string fileExtension = Path.GetExtension(fileName);
            string thumbnail = GetContentTypeThumbnail(fileExtension, thumbnailSize);
            if (!string.IsNullOrEmpty(navigateUrl))
            {
                TagBuilder a = new TagBuilder("a");
                a.MergeAttribute("href", navigateUrl);

                if (navigateTarget != HyperLinkTarget._self)
                    a.MergeAttribute("target", navigateTarget.ToString());

                a.InnerHtml = thumbnail;
                return MvcHtmlString.Create(a.ToString());
            }
            else
                return MvcHtmlString.Create(thumbnail);
        }
Beispiel #5
0
        /// <summary>
        ///     生成链接标签
        /// </summary>
        /// <param name="htmlHelper">被扩展的HtmlHelper实例</param>
        /// <param name="text">链接文本(必填)</param>
        /// <param name="url">链接地址</param>
        /// <param name="title">链接提示文字(不填则默认与text相同)</param>
        /// <param name="isLayer">是否是弹层</param>
        /// <param name="htmlAttributes">链接的其他属性集合</param>
        /// <param name="navigateTarget">头衔图片链接的Target</param>
        /// <returns></returns>
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string text, string url, string title,
                                         bool isLayer = false, object htmlAttributes = null, HyperLinkTarget navigateTarget = HyperLinkTarget._self)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(MvcHtmlString.Empty);
            }

            if (string.IsNullOrEmpty(url))
            {
                url = "javascript:void(0)";
            }

            if (string.IsNullOrEmpty(title))
            {
                title = text;
            }

            var builder = new TagBuilder("a");

            if (isLayer)
            {
                builder.MergeAttribute("href", "javascript:void(0)");
                builder.MergeAttribute("data-href", url);
                builder.MergeAttribute("plugin", "layer");
            }
            else
            {
                builder.MergeAttribute("href", url);
            }
            builder.SetInnerText(text);
            builder.MergeAttribute("title", title);
            if (navigateTarget != HyperLinkTarget._self)
            {
                builder.MergeAttribute("target", navigateTarget.ToString());
            }
            if (htmlAttributes != null)
            {
                builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            }
            return(MvcHtmlString.Create(builder.ToString()));
        }
        /// <summary>
        /// 根据文件类型显示缩略图
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="fileName">文件名称</param>
        /// <param name="thumbnailSize">缩略图大小</param>
        /// <param name="navigateUrl">缩略图链接地址</param>
        /// <param name="navigateTarget">链接目标</param>
        /// <returns></returns>
        public static MvcHtmlString ContentTypeThumbnail(this HtmlHelper htmlHelper, string fileName, ContentTypeThumbnailSize thumbnailSize, string navigateUrl = null, HyperLinkTarget navigateTarget = HyperLinkTarget._self)
        {
            string fileExtension = Path.GetExtension(fileName);
            string thumbnail     = GetContentTypeThumbnail(fileExtension, thumbnailSize);

            if (!string.IsNullOrEmpty(navigateUrl))
            {
                TagBuilder a = new TagBuilder("a");
                a.MergeAttribute("href", navigateUrl);

                if (navigateTarget != HyperLinkTarget._self)
                {
                    a.MergeAttribute("target", navigateTarget.ToString());
                }

                a.InnerHtml = thumbnail;
                return(MvcHtmlString.Create(a.ToString()));
            }
            else
            {
                return(MvcHtmlString.Create(thumbnail));
            }
        }
Beispiel #7
0
        /// <summary>
        /// 显示头像
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <param name="avatarSizeType">头像尺寸类别</param>
        /// <param name="link">链接到用户空间的地址</param>
        /// <param name="navigateTarget">链接类型</param>
        /// <param name="enableCachingInClient">是否允许在客户端缓存</param>
        /// <param name="htmlAttributes">html属性,例如:new RouteValueDictionary{{"Class","editor"},{"width","90%"}}</param>
        /// <returns></returns>
        public static MvcHtmlString ShowUserAvatar(this HtmlHelper htmlHelper, IUser user, string link, AvatarSizeType avatarSizeType = AvatarSizeType.Medium, HyperLinkTarget navigateTarget = HyperLinkTarget._blank, bool enableCachingInClient = true, RouteValueDictionary htmlAttributes = null, bool isShowUserCard = true, bool isShowTitle = false)
        {
            string avatarUrl = SiteUrls.Instance().UserAvatarUrl(user, avatarSizeType, enableCachingInClient);

            TagBuilder img = new TagBuilder("img");

            if (htmlAttributes != null)
            {
                img.MergeAttributes(htmlAttributes);
            }

            img.MergeAttribute("src", avatarUrl);
            if (user != null)
            {
                img.MergeAttribute("alt", user.DisplayName);
                if (isShowTitle)
                {
                    img.MergeAttribute("title", user.DisplayName);
                }
            }

            IUserProfileSettingsManager userProfileSettingsManager = DIContainer.Resolve <IUserProfileSettingsManager>();
            UserProfileSettings         userProfileSettings        = userProfileSettingsManager.GetUserProfileSettings();

            TagBuilder div = new TagBuilder("div");

            switch (avatarSizeType)
            {
            case AvatarSizeType.Big:
                img.MergeAttribute("width", userProfileSettings.AvatarWidth.ToString());
                div.AddCssClass("tn-avatar-big");
                break;

            case AvatarSizeType.Medium:
                img.MergeAttribute("width", userProfileSettings.MediumAvatarWidth.ToString());
                div.AddCssClass("tn-avatar-medium");
                break;

            case AvatarSizeType.Small:
                img.MergeAttribute("width", userProfileSettings.SmallAvatarWidth.ToString());
                div.AddCssClass("tn-avatar");
                break;

            case AvatarSizeType.Micro:
                img.MergeAttribute("width", userProfileSettings.MicroAvatarWidth.ToString());
                div.AddCssClass("tn-avatar-mini");
                break;
            }

            if (!string.IsNullOrEmpty(link) && user != null)
            {
                TagBuilder a = new TagBuilder("a");
                a.MergeAttribute("href", link);

                if (navigateTarget != HyperLinkTarget._self)
                {
                    a.MergeAttribute("target", navigateTarget.ToString());
                }

                if (isShowUserCard)
                {
                    a.MergeAttribute("plugin", "tipsyHoverCard");
                    a.MergeAttribute("data-user-card-url", SiteUrls.Instance()._UserCard(user.UserId));
                    a.MergeAttribute("outerclass", "tn-user-card");
                }

                a.InnerHtml   = img.ToString(TagRenderMode.SelfClosing);
                div.InnerHtml = a.ToString();
                return(new MvcHtmlString(div.ToString()));
            }
            else
            {
                div.InnerHtml = img.ToString(TagRenderMode.SelfClosing);
                return(new MvcHtmlString(div.ToString()));
            }
        }
Beispiel #8
0
        /// <summary>
        /// 显示头像
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <param name="avatarSizeType">头像尺寸类别</param>
        /// <param name="link">链接到用户空间的地址</param>
        /// <param name="navigateTarget">链接类型</param>
        /// <param name="enableCachingInClient">是否允许在客户端缓存</param>
        /// <param name="htmlAttributes">html属性,例如:new RouteValueDictionary{{"Class","editor"},{"width","90%"}}</param>
        /// <returns></returns>
        public static MvcHtmlString ShowUserAvatar(this HtmlHelper htmlHelper, IUser user, string link, AvatarSizeType avatarSizeType = AvatarSizeType.Medium, HyperLinkTarget navigateTarget = HyperLinkTarget._blank, bool enableCachingInClient = true, RouteValueDictionary htmlAttributes = null, bool isShowUserCard = true, bool isShowTitle = false)
        {
            string avatarUrl = SiteUrls.Instance().UserAvatarUrl(user, avatarSizeType, enableCachingInClient);

            TagBuilder img = new TagBuilder("img");
            if (htmlAttributes != null)
                img.MergeAttributes(htmlAttributes);

            img.MergeAttribute("src", avatarUrl);
            if (user != null)
            {
                img.MergeAttribute("alt", user.DisplayName);
                if (isShowTitle)
                {
                    img.MergeAttribute("title", user.DisplayName);
                }
            }

            ISettingsManager<UserProfileSettings> userProfileSettingsManager = DIContainer.Resolve<ISettingsManager<UserProfileSettings>>();
            UserProfileSettings userProfileSettings = userProfileSettingsManager.Get();

            TagBuilder div = new TagBuilder("div");
            switch (avatarSizeType)
            {
                case AvatarSizeType.Big:
                    img.MergeAttribute("width", userProfileSettings.AvatarWidth.ToString());
                    div.AddCssClass("tn-avatar-big");
                    break;
                case AvatarSizeType.Medium:
                    img.MergeAttribute("width", userProfileSettings.MediumAvatarWidth.ToString());
                    div.AddCssClass("tn-avatar-medium");
                    break;
                case AvatarSizeType.Small:
                    img.MergeAttribute("width", userProfileSettings.SmallAvatarWidth.ToString());
                    div.AddCssClass("tn-avatar");
                    break;
                case AvatarSizeType.Micro:
                    img.MergeAttribute("width", userProfileSettings.MicroAvatarWidth.ToString());
                    div.AddCssClass("tn-avatar-mini");
                    break;
            }

            if (!string.IsNullOrEmpty(link) && user != null)
            {
                TagBuilder a = new TagBuilder("a");
                a.MergeAttribute("href", link);

                if (navigateTarget != HyperLinkTarget._self)
                    a.MergeAttribute("target", navigateTarget.ToString());

                if (isShowUserCard)
                {
                    a.MergeAttribute("plugin", "tipsyHoverCard");
                    a.MergeAttribute("data-user-card-url", SiteUrls.Instance()._UserCard(user.UserId));
                    a.MergeAttribute("outerclass", "tn-user-card");
                }

                a.InnerHtml = img.ToString(TagRenderMode.SelfClosing);
                div.InnerHtml = a.ToString();
                return new MvcHtmlString(div.ToString());
            }
            else
            {
                div.InnerHtml = img.ToString(TagRenderMode.SelfClosing);
                return new MvcHtmlString(div.ToString());
            }
        }