Example #1
0
        /// <summary>
        /// Gets the requested page node.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">This resolver hasn’t been invoked with the proper route handler.</exception>
        private PageSiteNode GetRequestedPageNode()
        {
            var httpContext    = SystemManager.CurrentHttpContext;
            var requestContext = httpContext.Request.RequestContext;
            var node           = (PageSiteNode)requestContext.RouteData.DataTokens["SiteMapNode"];

            if (node == null)
            {
                throw new ArgumentException("This resolver hasn’t been invoked with the proper route handler.");
            }

            return(RouteHelper.GetFirstPageDataNode(node, true));
        }
Example #2
0
        /// <summary>
        /// Gets the requested page node.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">This resolver hasn’t been invoked with the proper route handler.</exception>
        private static PageSiteNode GetRequestedPageNode()
        {
            var httpContext    = SystemManager.CurrentHttpContext;
            var requestContext = httpContext.Request.RequestContext;
            var node           = requestContext.RouteData.DataTokens["SiteMapNode"] as PageSiteNode;

            if (node != null)
            {
                return(RouteHelper.GetFirstPageDataNode(node, true));
            }
            else
            {
                return(null);
            }
        }
        public string RenderFlatTaxaAsLink(BlogPost post, string taxonomyFieldName)
        {
            var baseUrl         = string.Empty;
            var currentProvider = SiteMapBase.GetCurrentProvider();

            if (currentProvider == null || currentProvider != null && currentProvider.CurrentNode == null)
            {
                return(string.Empty);
            }
            else
            {
                var currentNode = currentProvider.CurrentNode as PageSiteNode;
                if (currentNode == null)
                {
                    baseUrl = currentProvider.CurrentNode.Url;
                }
                else
                {
                    var firstPageDataNode = RouteHelper.GetFirstPageDataNode(currentNode, true);
                    if (!currentNode.IsGroupPage || !(firstPageDataNode.Url != currentProvider.CurrentNode.Url))
                    {
                        baseUrl = currentProvider.CurrentNode.Url;
                    }
                    else
                    {
                        baseUrl = firstPageDataNode.Url;
                    }
                }
            }

            var tagList = "";
            var tags    = post.GetValue <TrackedList <Guid> >(taxonomyFieldName);

            if (tags != null && tags.Count() > 0)
            {
                tagList = " | ";
                var taxManager = TaxonomyManager.GetManager();
                foreach (var tag in tags)
                {
                    var t    = taxManager.GetTaxon <FlatTaxon>(tag);
                    var url  = string.Format("{0}/-in-{1}/{2}/{3}", VirtualPathUtility.ToAbsolute(baseUrl), t.Taxonomy.Name, t.Taxonomy.Name, t.UrlName);
                    var link = string.Format("<a class='tag' href='{0}'><span>{1}</span></a>", url, t.Title).ToString();
                    tagList += link;
                }
            }

            return(tagList);
        }
        /// <summary>
        /// Returns if the inline editin section should be rendered.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <returns></returns>
        public static bool ShouldRenderInlineEditing(this HtmlHelper htmlHelper)
        {
            var shouldRender = false;

            if (!SitefinityContext.IsBackend && ControlExtensions.InlineEditingIsEnabled() && !SystemManager.CurrentHttpContext.Request.IsAjaxRequest())
            {
                const string SiteMapNodeKey = "ServedPageNode";

                if (HttpContext.Current != null && HttpContext.Current.Items != null && HttpContext.Current.Items.Contains(SiteMapNodeKey))
                {
                    var pageSiteNode = HttpContext.Current.Items[SiteMapNodeKey] as PageSiteNode;
                    if (pageSiteNode != null)
                    {
                        var firstPageDataNode = RouteHelper.GetFirstPageDataNode(pageSiteNode, true);
                        if (firstPageDataNode != null && firstPageDataNode.Framework == Pages.Model.PageTemplateFramework.Mvc)
                        {
                            shouldRender = true;
                        }
                    }
                }
            }

            return(shouldRender);
        }
Example #5
0
        /// <summary>
        /// Builds the full url for a particular taxon filter
        /// Override this method  to change the pattern of the url
        /// </summary>
        /// <param name="taxonRelativeUrl">The taxon relative URL.</param>
        /// <returns></returns>
        protected virtual string BuildUrl(string taxonRelativeUrl)
        {
            var url = this.BaseUrl;

            if (string.IsNullOrEmpty(url))
            {
                var siteMap = SiteMapBase.GetCurrentProvider();
                if (siteMap == null || (siteMap != null && siteMap.CurrentNode == null))
                {
                    return(string.Empty);
                }

                var psn = siteMap.CurrentNode as PageSiteNode;
                if (psn != null)
                {
                    // Check if the page is a Group page and if yes take its first child page and emit an URL that has embedded the URL of the first child
                    var temp = RouteHelper.GetFirstPageDataNode(psn, true);
                    if (psn.NodeType == NodeType.Group && temp.Url != siteMap.CurrentNode.Url)
                    {
                        url = temp.Url;
                    }
                    else
                    {
                        var getUrlMethod = psn.GetType().GetMethod("GetUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                        url = getUrlMethod.Invoke(psn, new object[] { true, true }) as string;
                    }
                }
                else
                {
                    url = siteMap.CurrentNode.Url;
                }
            }
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("BaseUrl property could not be resolved.");
            }

            if (string.IsNullOrEmpty(this.FieldName))
            {
                throw new ArgumentNullException("FieldName property could not be resolved.");
            }

            url = RouteHelper.ResolveUrl(url, UrlResolveOptions.Absolute);

            if (this.UrlEvaluationMode == Pages.Model.UrlEvaluationMode.UrlPath)
            {
                // Pages that are migrated from 3.7 have extensions (.aspx), which are unnecessary when we have segments after the page url.
                var    getCurrentNodeExtensionMethod = typeof(PageHelper).GetMethod("GetCurrentNodeExtension", BindingFlags.NonPublic | BindingFlags.Static);
                string extension = getCurrentNodeExtensionMethod.Invoke(null, null) as string;

                if (!extension.IsNullOrEmpty() && url.EndsWith(extension))
                {
                    url = url.Substring(0, url.LastIndexOf(extension));
                }
            }

            var evaluator         = new TaxonomyEvaluator();
            var taxonBuildOptions = TaxonBuildOptions.None;

            if (this.Taxonomy is Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxonomy)
            {
                taxonBuildOptions = TaxonBuildOptions.Hierarchical;
            }
            else if (this.Taxonomy is Telerik.Sitefinity.Taxonomies.Model.FlatTaxonomy)
            {
                taxonBuildOptions = TaxonBuildOptions.Flat;
            }

            var rootTaxonomy    = this.Taxonomy.RootTaxonomy ?? this.Taxonomy;
            var evaluatedResult = evaluator.BuildUrl(rootTaxonomy.Name, taxonRelativeUrl, this.FieldName, taxonBuildOptions, this.UrlEvaluationMode, this.UrlKeyPrefix);

            return(string.Concat(url, evaluatedResult));
        }