Exemple #1
0
        public static IHtmlString SubmissionUrl(this FrontUrlHelper frontUrl, string submissionName, object routeValues)
        {
            var routes = RouteValuesHelper.GetRouteValues(routeValues);

            routes["SubmissionName"] = submissionName;
            return(frontUrl.WrapperUrl(frontUrl.Url.Action("Submit", "Submission", routes)));
        }
Exemple #2
0
        public static IHtmlString ViewUrl(this FrontUrlHelper frontUrl, string viewName, object values)
        {
            RouteValueDictionary routeValues = RouteValuesHelper.GetRouteValues(values);

            routeValues["ViewName"] = viewName;
            return(frontUrl.WrapperUrl(frontUrl.Url.Action("ViewEntry", "Page", routeValues)));
        }
Exemple #3
0
        public static Route ToMvcRoute(this PageRoute pageRoute)
        {
            var routePath   = GetRouteUrl(pageRoute);
            var routeValues = RouteValuesHelper.GetRouteValues(pageRoute.Defaults);

            routeValues = MergeEmptyRouteValues(pageRoute, routeValues);
            var mvcRoute = new Route(routePath, routeValues, null);

            return(mvcRoute);
        }
Exemple #4
0
        internal IHtmlString GeneratePageUrl(UrlHelper urlHelper, Site site, Page page, object values, FrontRequestChannel channel)
        {
            RouteValueDictionary routeValues = RouteValuesHelper.GetRouteValues(values);

            if (page == null)
            {
                return(new HtmlString(""));
            }
            var route = page.Routes == null ? null : page.Routes.FirstOrDefault();
            //if (route != null && !string.IsNullOrEmpty(route.ExternalUrl))
            //{
            //    return new HtmlString(route.ExternalUrl);
            //}

            var pageRoute = route.ToMvcRoute();

            routeValues = RouteValuesHelper.MergeRouteValues(pageRoute.Defaults, routeValues);

            var routeVirtualPath = pageRoute.GetVirtualPath(urlHelper.RequestContext, routeValues);

            if (routeVirtualPath == null)
            {
                Kooboo.Common.Logging.Logger.LoggerInstance.Warn(string.Format("Invalid page URL route. Page:{0}", page.AbsoluteName));
            }
            //string contentUrl = routeVirtualPath.VirtualPath;//don't decode the url. why??
            //if do not decode the url, the route values contains Chinese character will cause bad request.
            string contentUrl = HttpUtility.UrlDecode(routeVirtualPath.VirtualPath);
            string pageUrl    = contentUrl;

            if (!string.IsNullOrEmpty(contentUrl) || (string.IsNullOrEmpty(pageUrl) && !page.IsDefault))
            {
                pageUrl = Kooboo.Common.Web.UrlUtility.Combine(page.GetVirtualPath(route), contentUrl);
            }
            if (string.IsNullOrEmpty(pageUrl))
            {
                pageUrl = urlHelper.Content("~/");
            }
            else
            {
                pageUrl = HttpUtility.UrlDecode(
                    urlHelper.RouteUrl("Page", new { PageUrl = new HtmlString(pageUrl) }));
            }
            var url = this.WrapperUrl(pageUrl, page.RequireHttps);

            return(url);
        }
        public static IHtmlString ViewLink(this IFrontHtmlHelper frontHtmlHelper, object linkText, string viewName, object routeValues, object htmlAttributes)
        {
            var htmlValues = RouteValuesHelper.GetRouteValues(htmlAttributes);

            string url = frontHtmlHelper.Page_Context.FrontUrl.ViewUrl(viewName, routeValues).ToString();


            TagBuilder builder = new TagBuilder("a")
            {
                InnerHtml = linkText != null?HttpUtility.HtmlEncode(linkText) : string.Empty
            };

            builder.MergeAttributes <string, object>(htmlValues);
            builder.MergeAttribute("href", url);
            var html = new HtmlString(builder.ToString(TagRenderMode.Normal));

            return(html);
        }
Exemple #6
0
        //Optional parameter does not support NVelocity
        public static IHtmlString Pager(this IFrontHtmlHelper frontHtml, object model, object routeValues, PagerOptions options, object htmlAttributes)
        {
            options = options ?? new PagerOptions();

            //if ((model is DataRulePagedList))
            //{
            //    options.PageIndexParameterName = ((DataRulePagedList)model).PageIndexParameterName;
            //}

            var pagedList = (IPagedList)model;

            var builder = new CmsPagerBuilder
                          (
                frontHtml,
                pagedList,
                options,
                RouteValuesHelper.GetRouteValues(routeValues),
                RouteValuesHelper.GetRouteValues(htmlAttributes)
                          );

            return(new HtmlString(builder.RenderPager().ToString()));
        }
        public static IHtmlString PageLink(this IFrontHtmlHelper frontHtml, object linkText, string urlKey, object routeValues, object htmlAttributes)
        {
            var  htmlValues = RouteValuesHelper.GetRouteValues(htmlAttributes);
            Page page;

            string url = frontHtml.Page_Context.FrontUrl.PageUrl(urlKey, routeValues, out page).ToString();

            var innerHtml = "";

            if (linkText == null)
            {
                innerHtml = page.GetLinkText();
            }
            else
            {
                innerHtml = HttpUtility.HtmlEncode(linkText);
            }
            TagBuilder builder = new TagBuilder("a")
            {
                InnerHtml = innerHtml
            };

            builder.MergeAttributes <string, object>(htmlValues);
            builder.MergeAttribute("href", url);
            //if (page != null && page.Route != null)
            //{
            //    builder.MergeAttribute("target", page.Route.LinkTarget.ToString());
            //}
            var html = new HtmlString(builder.ToString(TagRenderMode.Normal));

#if Page_Trace
            stopwatch.Stop();
            HttpContext.Current.Response.Write(string.Format("PageLink,{0}.</br>", stopwatch.Elapsed));
#endif
            return(html);
        }