Exemplo n.º 1
0
        /// <summary>
        /// Creates the link button.
        /// </summary>
        /// <param name="addText">if set to <c>true</c> adds text.</param>
        /// <param name="baseUrl">The base URL.</param>
        /// <param name="linkText">The link text.</param>
        /// <param name="tooltipText">The tooltip text.</param>
        /// <param name="cssClass">The CSS class.</param>
        /// <returns>
        /// CreateLinkButton Html
        /// </returns>
        private static string CreateLinkButton(bool addText, string baseUrl, string linkText, string tooltipText, string cssClass)
        {
            var shareUrl    = string.Empty;
            var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;

            var title = string.Empty;

            if (currentNode != null && currentNode.Url != null)
            {
                shareUrl = RouteHelper.GetAbsoluteUrl(currentNode.Url);
                title    = currentNode.Title;
            }

            var url         = string.Format(System.Globalization.CultureInfo.InvariantCulture, baseUrl, Uri.EscapeUriString(shareUrl), Uri.EscapeUriString(title));
            var clickScript = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"window.open('{0}', '{1}','toolbar=no,width=550,height=550'); return false", url, linkText);

            var text = string.Empty;

            if (addText)
            {
                text = linkText;
            }

            var htmlString = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"<a onclick=""{0}"" title=""{1}""><span class=""{3}""></span>{2}</a>", clickScript, tooltipText, text, cssClass);

            return(htmlString);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Facebook button.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="showCount">if set to <c>true</c> shows count.</param>
        /// <param name="isLarge">if set to <c>true</c> is large.</param>
        /// <param name="addText">if set to <c>true</c> [add text].</param>
        /// <returns>FacebookButton Html</returns>
        public static System.Web.Mvc.MvcHtmlString FacebookButton(this System.Web.Mvc.HtmlHelper helper, bool showCount, bool isLarge, bool addText)
        {
            var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;

            var shareUrl    = string.Empty;
            var siteMapNode = SiteMapBase.GetCurrentProvider().CurrentNode;

            if (currentNode != null && currentNode.Url != null && siteMapNode != null)
            {
                shareUrl = RouteHelper.GetAbsoluteUrl(siteMapNode.Url);
            }

            string buttonTypeAttribute;

            if (showCount)
            {
                buttonTypeAttribute = "data-type='button_count'";
            }
            else if (isLarge || addText)
            {
                buttonTypeAttribute = "data-type='button'";
            }
            else
            {
                buttonTypeAttribute = "data-type='icon'";
            }

            var htmlString = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"<div class='fb-share-button' data-href='{0}' {1}></div>", shareUrl, buttonTypeAttribute);

            var scriptString = @"<div id='fb-root'></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];  if (d.getElementById(id)) return;  js = d.createElement(s); js.id = id;  js.src = '//connect.facebook.net/en_EN/all.js#xfbml=1';  fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>";

            return(new System.Web.Mvc.MvcHtmlString(htmlString + scriptString));
        }
Exemplo n.º 3
0
        /// <summary>
        /// LinkedIn button
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="showCount">if set to <c>true</c> shows count.</param>
        /// <returns>
        /// LinkedInButton Html
        /// </returns>
        public static System.Web.Mvc.MvcHtmlString LinkedInButton(this System.Web.Mvc.HtmlHelper helper, bool showCount)
        {
            var shareUrl    = string.Empty;
            var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;

            if (currentNode != null && currentNode.Url != null)
            {
                shareUrl = RouteHelper.GetAbsoluteUrl(currentNode.Url);
            }

            var countAttribute = string.Empty;

            if (showCount)
            {
                countAttribute = "data-counter='right'";
            }

            var scriptString = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                @"<script src='//platform.linkedin.com/in.js' type='text/javascript'>lang: en_US</script><script type='IN/Share' data-url='{0}' {1}></script>",
                shareUrl,
                countAttribute);

            return(new System.Web.Mvc.MvcHtmlString(scriptString));
        }
Exemplo n.º 4
0
        private string GetBaseUrl()
        {
            var url = this.BaseUrl;

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

                url = siteMap.CurrentNode.Url;
            }

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

            if (VirtualPathUtility.IsAppRelative(url))
            {
                url = VirtualPathUtility.ToAbsolute(url);
            }
            return(url);
        }
        public static string GetPageNodeUrl(Guid pageNodeId)
        {
            var nodeUrl         = string.Empty;
            var siteMapProvider = SiteMapBase.GetCurrentProvider();

            if (siteMapProvider != null && pageNodeId != Guid.Empty)
            {
                var  pageProvider     = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager().Provider;
                bool suppressedChecks = pageProvider.SuppressSecurityChecks;
                pageProvider.SuppressSecurityChecks = true;
                var node = siteMapProvider.FindSiteMapNodeFromKey(pageNodeId.ToString());
                pageProvider.SuppressSecurityChecks = suppressedChecks;

                if (node == null)
                {
                    throw new ArgumentException("Invalid details page specified: \"{0}\".".Arrange(pageNodeId));
                }

                var pageSiteNode = node as PageSiteNode;
                if (pageSiteNode != null)
                {
                    nodeUrl = pageSiteNode.UrlWithoutExtension;
                }
            }

            return(nodeUrl);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var provider = SiteMapBase.GetCurrentProvider() as SiteMapBase;
            var siteNode = provider.CurrentNode as PageSiteNode;

            if (siteNode != null)
            {
                var bodyClass = siteNode.GetCustomFieldValue("BodyClass").ToString();
                this.bodyTag.Attributes.Add("class", bodyClass);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the page by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="includeChildren">(Optional) if set to <c>true</c> [include children].</param>
        /// <param name="includeRelatedData">(Optional) true to include, false to exclude the related data.</param>
        /// <returns>
        /// The by identifier.
        /// </returns>
        public virtual PageModel GetById(Guid id, bool includeChildren = true, bool includeRelatedData = true)
        {
            if (id == Guid.Empty)
            {
                return(null);
            }

            var siteMapNodeById = SiteMapBase.GetCurrentProvider()
                                  .FindSiteMapNodeFromKey(id.ToString());

            return(_pageModelFactory.Create(siteMapNodeById, true, includeChildren, includeRelatedData));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the page by URL.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="includeChildren">(Optional) if set to <c>true</c> [include children].</param>
        /// <param name="includeRelatedData">(Optional) true to include, false to exclude the related data.</param>
        /// <returns>
        /// The by URL.
        /// </returns>
        public virtual PageModel GetByUrl(string value, bool includeChildren = true, bool includeRelatedData = true)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            var siteMapNodeByUrl = SiteMapBase.GetCurrentProvider()
                                   .FindSiteMapNode(_virtualPathUtility.ToAbsolute("~/" + value.TrimStart('~', '/')));

            return(_pageModelFactory.Create(siteMapNodeByUrl, true, includeChildren, includeRelatedData));
        }
        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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Twitter Button HTML
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="showCount">if set to <c>true</c> shows count.</param>
        /// <param name="isLarge">if set to <c>true</c> is large.</param>
        /// <param name="addText">if set to <c>true</c> adds text.</param>
        /// <param name="textToShare">The text to share.</param>
        /// <returns>
        /// TwitterButton Html
        /// </returns>
        public static System.Web.Mvc.MvcHtmlString TwitterButton(this System.Web.Mvc.HtmlHelper helper, bool showCount, bool isLarge, bool addText, string textToShare)
        {
            var shareUrl = string.Empty;

            var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;

            if (currentNode != null && currentNode.Url != null)
            {
                shareUrl = RouteHelper.GetAbsoluteUrl(currentNode.Url);
            }

            var countAttribute = "data-count='horizontal'";

            if (!showCount)
            {
                countAttribute = "data-count='none'";
            }

            var sizeAttribute = string.Empty;

            if (isLarge)
            {
                sizeAttribute = "data-size='large'";
            }

            var text = string.Empty;

            if (addText)
            {
                text = "Tweet";
            }

            var htmlString = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                @"<a href='https://twitter.com/share' title='Share on Twitter' class='twitter-share-button' data-url={0} data-text={1} {2} {3}>{4}</a>",
                shareUrl,
                textToShare,
                sizeAttribute,
                countAttribute,
                text);

            var scriptString = @"<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>";

            return(new System.Web.Mvc.MvcHtmlString(htmlString + scriptString));
        }
Exemplo n.º 11
0
        private static PageDataViewModel GetPage()
        {
            var siteMapProvider = SiteMapBase.GetCurrentProvider();

            if (siteMapProvider != null && siteMapProvider.CurrentNode != null)
            {
                var pm       = new PageManager();
                var pageNode = pm.GetPageNode(new Guid(siteMapProvider.CurrentNode.Key));
                var result   = new PageDataViewModel
                {
                    Title    = pageNode.Page.Title,
                    Keywords = pageNode.Page.Keywords
                };
                return(result);
            }

            return(new PageDataViewModel());
        }
        public static Dictionary <string, string> GetProductsContext(this HttpContextBase httpContext)
        {
            var contextDictionary = new Dictionary <string, string>();
            var smp        = SiteMapBase.GetCurrentProvider();
            var pageDataId = ((PageSiteNode)smp.CurrentNode).PageId;

            var mgr      = PageManager.GetManager();
            var pageData = mgr.GetPageDataList()
                           .Where(pd => pd.Id == pageDataId && pd.Status == ContentLifecycleStatus.Live && pd.Visible == true)
                           .FirstOrDefault();

            if (pageData != null)
            {
                pageData.LoadToContextDictionary <ProductsController>(x => x.CategoryIds, contextDictionary);
                pageData.LoadToContextDictionary <ProductsController>(x => x.ProductIds, contextDictionary);
            }

            return(contextDictionary);
        }
        public static string GetSitefinityActionUrl(string pageId, string actionName)
        {
            PageNode    pNode;
            PageManager manager = PageManager.GetManager();

            if (pageId == null)
            {
                pNode = manager.GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key));
            }
            else
            {
                pNode = manager.GetPageNode(new Guid(pageId));
            }

            Uri url = HttpContext.Current.Request.Url;


            return(String.Format("{0}{1}/{2}", ExtractBaseUrl().TrimEnd('/'), pNode.GetFullUrl().TrimStart('~'), actionName));
        }
        private string GetCurrentCulture()
        {
            var actualSiteMapNode   = SiteMapBase.GetActualCurrentNode();
            var localization        = new Dictionary <string, string>();
            var siteMapProvider     = SiteMapBase.GetCurrentProvider();
            var currentPageSiteNode = siteMapProvider.CurrentNode as PageSiteNode;

            if (actualSiteMapNode != null)
            {
                if (currentPageSiteNode != null)
                {
                    foreach (var availableLanguage in currentPageSiteNode.AvailableLanguages)
                    {
                        localization.Add(availableLanguage.Name, currentPageSiteNode.GetUrl(availableLanguage));
                    }
                }
            }

            return(JsonConvert.SerializeObject(localization, Formatting.Indented));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the linked page URL.
        /// </summary>
        /// <returns></returns>
        private string GetLinkedUrl(SfImage image)
        {
            string linkedUrl = null;

            if (this.UseAsLink && this.LinkedPageId != Guid.Empty)
            {
                var pageManager = PageManager.GetManager();
                var node        = pageManager.GetPageNode(this.LinkedPageId);
                if (node != null)
                {
                    var provider    = SiteMapBase.GetCurrentProvider();
                    var siteMapNode = provider.FindSiteMapNodeFromKey(node.Id.ToString());
                    linkedUrl = UrlPath.ResolveUrl(siteMapNode.Url, true);
                }
            }
            else if (this.UseAsLink && this.LinkedPageId == Guid.Empty)
            {
                linkedUrl = image.ResolveMediaUrl(true);
            }

            return(linkedUrl);
        }
Exemplo n.º 16
0
        public string GetLinkedUrl()
        {
            var linkTo = string.IsNullOrWhiteSpace(this.LinkTo) ? LinkToPage : this.LinkTo;

            if (linkTo == LinkToPage)
            {
                if (this.LinkedPageId == Guid.Empty)
                {
                    return(null);
                }

                var siteMap     = SiteMapBase.GetCurrentProvider();
                var siteMapNode = siteMap.FindSiteMapNodeFromKey(LinkedPageId.ToString()) as PageSiteNode;

                if (siteMapNode != null)
                {
                    string relativeUrl = siteMapNode.GetUrl(CultureInfo.CurrentUICulture, true);

                    return(UrlPath.ResolveUrl(relativeUrl, Config.Get <SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls));
                }
            }
            else if (linkTo == LinkToUrl)
            {
                if (!string.IsNullOrEmpty(this.LinkedUrl))
                {
                    return(this.LinkedUrl);
                }
            }
            else if (linkTo == LinkToAnchor)
            {
                if (!string.IsNullOrEmpty(this.LinkedAnchor))
                {
                    return(this.LinkedAnchor);
                }
            }

            return(null);
        }
Exemplo n.º 17
0
        private string GetUrlByPageNodeIdAlternative(Guid pageNodeId, CultureInfo lang, bool resolveAsAbsolutUrl)
        {
            var siteMap = SiteMapBase.GetCurrentProvider();

            var siteMapNode = siteMap.FindSiteMapNodeFromKey(pageNodeId.ToString()) as PageSiteNode;

            var url = String.Empty;

            if (siteMapNode != null)
            {
                url = siteMapNode.GetUrl(lang, false);

                var urlService = Telerik.Sitefinity.Abstractions.ObjectFactory.Resolve <Telerik.Sitefinity.Localization.UrlLocalizationStrategies.UrlLocalizationService>();
                url = urlService.ResolveUrl(url, lang);

                if (resolveAsAbsolutUrl)
                {
                    url = UrlPath.ResolveUrl(url, true, true);
                }
            }

            return(url);
        }
        private string GetUrlForLanguage(CultureInfo culture)
        {
            string url = null;

            if (this.MissingTranslationAction == NoTranslationAction.RedirectToPage)
            {
                ////If the current page has no translation in the current language, set the URL to the home page in this language
                if (this.usedLanguages.Contains(culture) == false)
                {
                    url = this.GetMissingLanguageUrl(culture);
                }
            }

            if (url == null)
            {
                var currentUiCulture = Telerik.Sitefinity.Services.SystemManager.CurrentContext.Culture;
                Telerik.Sitefinity.Services.SystemManager.CurrentContext.Culture = culture;
                try
                {
                    var siteNode = SiteMapBase.GetCurrentProvider().FindSiteMapNodeFromKey(this.node.Id.ToString());
                    if (siteNode != null)
                    {
                        url = siteNode.Url;
                    }
                    else
                    {
                        url = this.ResolveUrl("~/", culture);
                    }
                }
                finally
                {
                    Telerik.Sitefinity.Services.SystemManager.CurrentContext.Culture = currentUiCulture;
                }
            }

            return(url);
        }
        public static string GetCurrentPageNodeUrl()
        {
            var currentNodeUrl = string.Empty;
            var currentNode    = SiteMapBase.GetActualCurrentNode();

            if (currentNode != null)
            {
                currentNodeUrl = currentNode.UrlWithoutExtension;
            }
            else
            {
                var siteMapProvider = SiteMapBase.GetCurrentProvider();
                if (siteMapProvider.CurrentNode != null)
                {
                    var currentPageSiteNode = siteMapProvider.CurrentNode as PageSiteNode;
                    if (currentPageSiteNode != null)
                    {
                        currentNodeUrl = currentPageSiteNode.UrlWithoutExtension;
                    }
                }
            }

            return(currentNodeUrl);
        }
Exemplo n.º 20
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));
        }