Ejemplo n.º 1
0
        public virtual string GetPageLink(Item contextItem, ID fieldID)
        {
            var item = this.GetAccountsSettingsItem(contextItem);

            if (item == null)
            {
                throw new Exception("Page with accounts settings isn't specified");
            }

            InternalLinkField link = item.Fields[fieldID];

            if (link.TargetItem == null)
            {
                throw new Exception($"{link.InnerField.Name} link isn't set");
            }

            if (Sitecore.Context.Item.InFxm())
            {
                UrlOptions options = LinkManager.GetDefaultUrlOptions();
                options.SiteResolving          = true;
                options.AlwaysIncludeServerUrl = true;
                return(link.TargetItem.Url(options));
            }
            else
            {
                return(link.TargetItem.Url());
            }
        }
Ejemplo n.º 2
0
        public void CreateUrlOptions_SetsOptionsOnDefaultOptions(
            SitecoreInfoUrlOptions options,
            bool addAspx,
            bool includeServer,
            bool encodeNames,
            bool shorten,
            bool siteResolving,
            bool displayName
            )
        {
            //Arrange

            var defaultOptions = new UrlOptions();

            defaultOptions.AddAspxExtension       = false;
            defaultOptions.AlwaysIncludeServerUrl = false;
            defaultOptions.EncodeNames            = false;
            defaultOptions.ShortenUrls            = false;
            defaultOptions.SiteResolving          = false;
            defaultOptions.UseDisplayName         = false;
            var urlOptionsResolver = new UrlOptionsResolver();


            //Act
            urlOptionsResolver.CreateUrlOptions(options, defaultOptions);

            //Assert
            Assert.AreEqual(addAspx, defaultOptions.AddAspxExtension);
            Assert.AreEqual(includeServer, defaultOptions.AlwaysIncludeServerUrl);
            Assert.AreEqual(encodeNames, defaultOptions.EncodeNames);
            Assert.AreEqual(shorten, defaultOptions.ShortenUrls);
            Assert.AreEqual(siteResolving, defaultOptions.SiteResolving);
            Assert.AreEqual(displayName, defaultOptions.UseDisplayName);
        }
Ejemplo n.º 3
0
        public static string GetAuthorViewUrl(string authorName, BlogSettings settingsItem)
        {
            UrlOptions option = new UrlOptions();

            option.AddAspxExtension = false;
            return(String.Format("{0}/{1}/{2}", LinkManager.GetItemUrl(settingsItem.AuthorViewPage, option), XBSettings.XBAuthorViewQS, authorName));
        }
Ejemplo n.º 4
0
 public UrlLookup(
     UrlOptions urlOptions,
     IUrlMaps urlMaps)
 {
     _urlOptions = urlOptions;
     _urlMaps    = urlMaps;
 }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static string GetUrl(Item item, string fieldName, UrlOptions urlOptions, MediaUrlOptions mediaUrlOptions)
        {
            string url = String.Empty;

            LinkField linkField = item.Fields[fieldName];

            if (linkField != null)
            {
                if (linkField.IsMediaLink)
                {
                    MediaItem media = new MediaItem(linkField.TargetItem);
                    url = Sitecore.StringUtil.EnsurePrefix('/', null != mediaUrlOptions ? MediaManager.GetMediaUrl(media, mediaUrlOptions) : MediaManager.GetMediaUrl(media));
                }
                else if (linkField.IsInternal)
                {
                    Item targetItem = linkField.TargetItem;

                    if (targetItem != null)
                    {
                        url = null != urlOptions?Sitecore.Links.LinkManager.GetItemUrl(linkField.TargetItem, urlOptions) : Sitecore.Links.LinkManager.GetItemUrl(linkField.TargetItem);
                    }
                    else
                    {
                        url = linkField.Url;
                    }
                }
            }

            return(url);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks the url string for authentication violations.
        /// </summary>
        /// <param name="url">The url to check.</param>
        /// <param name="options">The options to consider. Ignored.</param>
        /// <returns>True if it meets the authorization standards, false otherwise.</returns>
        private static CheckOutput CheckAuth(string url, UrlOptions options)
        {
            var output = new CheckOutput();
            var authIndex = url.IndexOf("@", StringComparison.InvariantCultureIgnoreCase);
            output.NewUrl = url;
            if (authIndex > -1)
            {
                var authValue = url.Substring(0, authIndex);
                var colonIndex = authValue.IndexOf(":", StringComparison.InvariantCultureIgnoreCase);
                if (colonIndex > -1)
                {
                    var user = authValue.Substring(0, colonIndex);
                    var pass = authValue.Substring(colonIndex + 1);
                    output.IsValid = !string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pass);
                }
                else
                {
                    output.IsValid = true;
                }
            }
            else
            {
                output.IsValid = true;
            }

            return output;
        }
        /// <summary>Gets the (friendly) URL of an item.</summary>
        /// <param name="item">The item.</param>
        /// <param name="options">The options.</param>
        /// <returns>The item URL.</returns>
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            Assert.ArgumentNotNull(item, nameof(item));
            Assert.ArgumentNotNull(options, nameof(options));

            var site = options.Site;

            if (site == null)
            {
                item.GetSite();
            }

            if (options.LanguageEmbedding == LanguageEmbedding.Always)
            {
                if (options.Language.CultureInfo.IetfLanguageTag == site.Language)
                {
                    options.LanguageEmbedding = LanguageEmbedding.Never;
                }
            }

            var url = CreateLinkBuilder(options).GetItemUrl(item);

            if (options.LowercaseUrls)
            {
                url = url.ToLowerInvariant();
            }

            return(url);
        }
        private static string GetFieldsJson(Item item, string contextSite)
        {
            var sb = new StringBuilder();

            sb.Append("{");
            var fieldDescriptors = new List <string>();
            var urlOptions       = new UrlOptions();

            urlOptions.AlwaysIncludeServerUrl = false;
            if (!string.IsNullOrEmpty(contextSite))
            {
                urlOptions.Site = SiteContext.GetSite(contextSite);
            }

            var url = LinkManager.GetItemUrl(item, urlOptions);

            url = url.Replace(" ", "%20");
            url = Settings.GetSetting("Sitecore.Flow.Actions.ServerUrl") + url;
            fieldDescriptors.Add($" \"ItemUrl\" : \"{url}\" ");

            foreach (Field field in item.Fields)
            {
                if (field.Name.StartsWith("__"))
                {
                    continue;
                }

                fieldDescriptors.Add($" \"{field.Name}\" : \"{HttpUtility.JavaScriptStringEncode(field.Value)}\" ");
            }

            sb.Append(fieldDescriptors.Aggregate((i, j) => i + "," + j));
            sb.Append("}");
            return(sb.ToString());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates the URL options.
        /// </summary>
        /// <param name="urlOptions">The URL options.</param>
        /// <returns>UrlOptions.</returns>
        public virtual UrlOptions CreateUrlOptions(SitecoreInfoUrlOptions urlOptions)
        {
            //We can test this because it throws an error due to config being missing
            UrlOptions defaultUrl = UrlOptions.DefaultOptions;

            return(CreateUrlOptions(urlOptions, defaultUrl));
        }
Ejemplo n.º 10
0
        public void Process(DeferredRegistrationArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNullOrEmpty(args.EncryptedToken, "args.EncryptedToken");
            Assert.ArgumentNotNullOrEmpty(args.UserData.FirstName, "args.UserData.FirstName");
            Assert.ArgumentNotNullOrEmpty(args.UserData.LastName, "args.UserData.LastName");
            Assert.ArgumentNotNull(args.MailMessage, "args.MailMessage");
            Assert.ArgumentNotNullOrEmpty(args.MailMessage.Body, "args.MailMessage.Body");

            var processActivationLinkPageId = Settings.GetSetting("DeferredRegistration.PageToProcessActivationLink");

            Assert.ArgumentNotNullOrEmpty(processActivationLinkPageId, "processActivationLinkPageId");

            var processActivationLinkPageItem = Sitecore.Context.Database.GetItem(processActivationLinkPageId);

            Assert.ArgumentNotNull(processActivationLinkPageItem, "processActivationLinkPageItem");

            var urlOptions = new UrlOptions
            {
                AlwaysIncludeServerUrl = true,
                LanguageEmbedding      = LanguageEmbedding.Never
            };
            var deferredRegistrationPageUrl = LinkManager.GetItemUrl(processActivationLinkPageItem, urlOptions);

            var activationLink = WebUtil.AddQueryString(deferredRegistrationPageUrl, "hash", args.EncryptedToken);

            args.MailMessage.Body = args.MailMessage.Body.Replace("{activation-link}", activationLink);
            args.MailMessage.Body = args.MailMessage.Body.Replace("{name}", args.UserData.FirstName);
        }
Ejemplo n.º 11
0
        public object ComputeFieldValue(IIndexable indexable)
        {
            Item item = (Item)(indexable as SitecoreIndexableItem);

            if (item == null)
            {
                return((object)null);
            }

            if (item.Paths.IsMediaItem)
            {
                return((object)MediaManager.GetMediaUrl((MediaItem)item));
            }

            UrlOptions defaultUrlOptions = LinkManager.GetDefaultUrlOptions();

            defaultUrlOptions.Site = Sitecore.Configuration.Factory.GetSite("ilightsingapore2019");
            defaultUrlOptions.AlwaysIncludeServerUrl = false;
            defaultUrlOptions.LanguageEmbedding      = LanguageEmbedding.Never;


            string url = LinkManager.GetItemUrl(item, defaultUrlOptions);

            //hack: last minute fix, not the best thing to do
            if (url.ToLower().StartsWith("://" + defaultUrlOptions.Site.HostName))
            {
                url = url.ToLower().Replace("://" + defaultUrlOptions.Site.HostName, "");
            }

            return(url);
        }
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            var datedLinkProvider = new DatedLinkProvider(new TagRepository(new DataContext()));
            Func <Item, UrlOptions, string> defaultUrlGenerator = base.GetItemUrl;

            return(datedLinkProvider.GetItemUrl(item, options, defaultUrlGenerator).FirstOrLazy(() => defaultUrlGenerator(item, options)));
        }
Ejemplo n.º 13
0
        private static string GetSiteMapTree(Item node)
        {
            if (node == null)
            {
                return("");
            }

            UrlOptions         options  = GetOptions();
            IEnumerable <Item> children = node.Children.Where(x => !string.IsNullOrEmpty(x.Name));
            StringBuilder      sb       = new StringBuilder("");

            if (children == null || !children.Any())
            {
                return("");
            }

            sb.Append("<ul>");

            foreach (var child in children)
            {
                if (ShowNode(child.Fields[SiteMapFields.ShowInHTMLSiteMap]))
                {
                    sb.Append(NodeWithMarkup(GetTitle(child), Sitecore.Links.LinkManager.GetItemUrl(child, options)));
                }

                if (HasContentChildren(child))
                {
                    sb.Append(GetSiteMapTree(child));
                }
            }

            sb.Append("</ul>");

            return(sb.ToString());
        }
        public virtual UrlOptions CreateUrlOptions(SitecoreInfoUrlOptions urlOptions, UrlOptions defaultOptions)
        {
            if (urlOptions == 0) return defaultOptions;

            Func<SitecoreInfoUrlOptions, bool> flagCheck =
                option => (urlOptions & option) == option;


            //check for any default overrides
            defaultOptions.AddAspxExtension = flagCheck(SitecoreInfoUrlOptions.AddAspxExtension) || defaultOptions.AddAspxExtension;
            defaultOptions.AlwaysIncludeServerUrl = flagCheck(SitecoreInfoUrlOptions.AlwaysIncludeServerUrl) || defaultOptions.AlwaysIncludeServerUrl;
            defaultOptions.EncodeNames = flagCheck(SitecoreInfoUrlOptions.EncodeNames) || defaultOptions.EncodeNames;
            defaultOptions.ShortenUrls = flagCheck(SitecoreInfoUrlOptions.ShortenUrls) || defaultOptions.ShortenUrls;
            defaultOptions.SiteResolving = flagCheck(SitecoreInfoUrlOptions.SiteResolving) || defaultOptions.SiteResolving;
            defaultOptions.UseDisplayName = flagCheck(SitecoreInfoUrlOptions.UseUseDisplayName) || defaultOptions.UseDisplayName;


            if (flagCheck(SitecoreInfoUrlOptions.LanguageEmbeddingAlways))
                defaultOptions.LanguageEmbedding = LanguageEmbedding.Always;
            else if (flagCheck(SitecoreInfoUrlOptions.LanguageEmbeddingAsNeeded))
                defaultOptions.LanguageEmbedding = LanguageEmbedding.AsNeeded;
            else if (flagCheck(SitecoreInfoUrlOptions.LanguageEmbeddingNever))
                defaultOptions.LanguageEmbedding = LanguageEmbedding.Never;

            if (flagCheck(SitecoreInfoUrlOptions.LanguageLocationFilePath))
                defaultOptions.LanguageLocation = LanguageLocation.FilePath;
            else if (flagCheck(SitecoreInfoUrlOptions.LanguageLocationQueryString))
                defaultOptions.LanguageLocation = LanguageLocation.QueryString;

            return defaultOptions;

        }
Ejemplo n.º 15
0
        /// <summary>
        /// Checks the url string for path violations.
        /// </summary>
        /// <param name="url">The url to check.</param>
        /// <param name="options">The options to consider. Ignored.</param>
        /// <returns>True if it meets the path standards, false otherwise.</returns>
        private static CheckOutput CheckPath(string url, UrlOptions options)
        {
            var output    = new CheckOutput();
            var pathIndex = url.IndexOf("/", StringComparison.InvariantCultureIgnoreCase);

            if (pathIndex > -1)
            {
                var queryStringValue = url.Substring(pathIndex + 1);
                output.NewUrl = url.Substring(0, pathIndex);
                if (string.IsNullOrEmpty(queryStringValue))
                {
                    output.IsValid = true;
                }
                else
                {
                    output.IsValid = !queryStringValue.Contains(" ");
                }
            }
            else
            {
                output.NewUrl  = url;
                output.IsValid = true;
            }

            return(output);
        }
 private ActionResult RedirectToHomepage()
 {
     var urloptions = new UrlOptions { AddAspxExtension = false, LanguageEmbedding = LanguageEmbedding.Never };
     var startItem = Context.Database.GetItem(Context.Site.ContentStartPath);
     var url = LinkManager.GetItemUrl(startItem, urloptions);
     return RedirectToRoute(MvcSettings.SitecoreRouteName, new { pathInfo = url.TrimStart('/') });
 }
Ejemplo n.º 17
0
        private string GetItemUrl(Item item, Site site, Language language)
        {
            UrlOptions defaultOptions = UrlOptions.DefaultOptions;

            defaultOptions.SiteResolving          = Settings.Rendering.SiteResolving;
            defaultOptions.Site                   = SiteContext.GetSite(site.Name);
            defaultOptions.AlwaysIncludeServerUrl = false;
            defaultOptions.LanguageEmbedding      = LanguageEmbedding.Always;
            if (language != null)
            {
                defaultOptions.Language = language;
            }
            string itemUrl         = LinkManager.GetItemUrl(item, defaultOptions);
            string serverUrlBySite = SitemapManagerConfiguration.GetServerUrlBySite(site.Name);

            if (serverUrlBySite.Contains("http://"))
            {
                serverUrlBySite = serverUrlBySite.Substring("http://".Length);
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(serverUrlBySite))
            {
                if (!(itemUrl.Contains("://") || itemUrl.Contains("http")))
                {
                    stringBuilder.Append("http://");
                    stringBuilder.Append(serverUrlBySite);
                    stringBuilder.Append(itemUrl);
                }
                else
                {
                    if (itemUrl.StartsWith("http"))
                    {
                        itemUrl = itemUrl.Remove(0, 4);
                    }
                    stringBuilder.Append("http://");
                    stringBuilder.Append(serverUrlBySite);
                    if (itemUrl.IndexOf("/", 3) > 0)
                    {
                        stringBuilder.Append(itemUrl.Substring(itemUrl.IndexOf("/", 3)));
                    }
                }
            }
            else if (!string.IsNullOrEmpty(site.Properties["hostname"]))
            {
                stringBuilder.Append("http://");
                stringBuilder.Append(site.Properties["hostname"]);
                stringBuilder.Append(itemUrl);
            }
            else if (!itemUrl.Contains("://") || itemUrl.Contains("http"))
            {
                stringBuilder.Append(WebUtil.GetFullUrl(itemUrl));
            }
            else
            {
                stringBuilder.Append("http://");
                stringBuilder.Append(itemUrl);
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            footer = Sitecore.Context.Database.GetItem(footerItemPath);

            //Main Menu items
            List<PageSummaryItem> items = footer.Mainlinks.ListItems.ConvertAll(x => new PageSummaryItem(x));
            System.Text.StringBuilder markupBuilder = new System.Text.StringBuilder();
            int childcounter = 0;
            foreach (PageSummaryItem child in items)
            {
                if (!string.IsNullOrEmpty(child.NavigationTitle.Text))
                {
                    markupBuilder.AppendFormat(@"<li{2}><a href=""{0}"">{1}</a></li>", child.Url, child.NavigationTitle.Rendered, childcounter == 0 ? @" class=""first""" : "");
                    childcounter++;
                }
            }

            if (markupBuilder.Length > 0)
            {
                markupBuilder.Insert(0, "<ul>");
                markupBuilder.Insert(0, "<nav>");
                markupBuilder.AppendFormat(@"<li><a href=""{0}"" class=""external"" target=""_blank"">{1}</a></li>", Settings.CareersLink, Translate.Text("Careers"));
                markupBuilder.Append("</ul>");
                markupBuilder.Append("</nav>");
                markup = markupBuilder.ToString();
            }

            //Submenu items
            List<PageSummaryItem> subitems = footer.Sublinks.ListItems.ConvertAll(x => new PageSummaryItem(x));
            System.Text.StringBuilder markupBuilderSub = new System.Text.StringBuilder();
            childcounter = 0;
            //Set Link to Mobile Site -if we are using a Mobile device.

            if (SitecoreHelper.GetDeviceFromCookie().Equals(Settings.MobileDevice, StringComparison.OrdinalIgnoreCase))
            {
                string startPath = Sitecore.Context.Site.StartPath.ToString();
                var homeItem = Sitecore.Context.Database.GetItem(startPath);
                var options = new UrlOptions { AlwaysIncludeServerUrl = true, AddAspxExtension = false, LanguageEmbedding = LanguageEmbedding.Never };
                var homeUrl = LinkManager.GetItemUrl(homeItem, options);

                //Set return to main site link
                markupBuilderSub.AppendFormat(@"<li><a href=""{0}"">{1}</a></li>", homeUrl + "?sc_device=mobile&persisted=true", Translate.Text("Mobile Site"));
                childcounter++;
            }

            foreach (PageSummaryItem child in subitems)
            {
                if (!string.IsNullOrEmpty(child.NavigationTitle.Text))
                {
                    string url = Sitecore.Links.LinkManager.GetItemUrl(child.InnerItem);
                    markupBuilderSub.AppendFormat(@"<li><a href=""{0}"">{1}</a></li>", url, child.NavigationTitle.Rendered);
                    childcounter++;
                }
            }

            if (markupBuilderSub.Length > 0)
            {
                subMenuMarkup = markupBuilderSub.ToString();
            }
        }
        public void Process(DoLogoutPipelineArgs args)
        {
            if (args != null && WsFederatedSiteInfo.FastIsFederatedCheck(Context.Site))
            {
                Item       startItem  = Context.Database.GetItem(Context.Site.StartPath);
                UrlOptions urlOptions = UrlOptions.DefaultOptions;
                urlOptions.AlwaysIncludeServerUrl = true;

                args.OwinAuthenticationProperties              = new AuthenticationProperties();
                args.OwinAuthenticationProperties.RedirectUri  = LinkManager.GetItemUrl(startItem, urlOptions);
                args.OwinAuthenticationProperties.AllowRefresh = false;
            }
            else if (args != null && OpenIdConnectSiteInfo.FastUsesOpenIdConnectCheck(Context.Site))
            {
                OpenIdConnectSiteInfo site = new OpenIdConnectSiteInfo(Context.Site);

                args.OwinAuthenticationProperties              = new AuthenticationProperties();
                args.OwinAuthenticationProperties.RedirectUri  = site.PostlogoutRedirectUri;
                args.OwinAuthenticationProperties.AllowRefresh = false;
            }
            else
            {
                // No OWIN imlementation found, continue process
            }
        }
Ejemplo n.º 20
0
        public static UrlOptions CheckOverrideLanguageEmbedding(UrlOptions urlOptions)
        {
            var thisSite = Sitecore.Context.Site;

            if (urlOptions.Site != null)
            {
                thisSite = urlOptions.Site;
            }

            if (!String.IsNullOrEmpty(thisSite.SiteInfo.Properties["languageEmbedding"]))
            {
                if (thisSite.SiteInfo.Properties["languageEmbedding"].ToLower() == "never")
                {
                    urlOptions.LanguageEmbedding = LanguageEmbedding.Never;
                }
                else if (thisSite.SiteInfo.Properties["languageEmbedding"].ToLower() == "always")
                {
                    urlOptions.LanguageEmbedding = LanguageEmbedding.Always;
                }
                else if (thisSite.SiteInfo.Properties["languageEmbedding"].ToLower() == "asneeded")
                {
                    urlOptions.LanguageEmbedding = LanguageEmbedding.AsNeeded;
                }
            }

            return(urlOptions);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="items"></param>
        /// <param name="command"></param>
        /// <param name="schedule"></param>
        public void SetXmLsitemap(Item[] items, CommandItem command, ScheduleItem schedule)
        {
            if (ConfigurationHelper.IsAuthoringServer())
            {
                try
                {
                    XmlDocument    xmlDoc         = new XmlDocument();
                    XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

                    XmlElement rootNode = xmlDoc.CreateElement("urlset");
                    rootNode.SetAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
                    xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
                    xmlDoc.AppendChild(rootNode);

                    //we will take only approved items / pages
                    string     databaseName  = "web";
                    string     startItemPath = ConfigurationHelper.GetSitecoreSetting("rootPath");
                    Database   database      = Factory.GetDatabase(databaseName);
                    UrlOptions urlOptions    = UrlOptions.DefaultOptions;
                    urlOptions.AlwaysIncludeServerUrl = false;

                    Item item = database.GetItem(startItemPath);
                    AddUrlEntry(item, xmlDoc, rootNode, urlOptions);
                    xmlDoc.Save(System.Web.Hosting.HostingEnvironment.MapPath("/sitemap.xml"));
                }
                catch (Exception ex)
                {
                    Log.Error("Error at sitemap xml handler.", ex, this);
                }
            }
        }
Ejemplo n.º 22
0
    /// <summary>
    /// Convenience method to access the optional URL to the Sitecore item
    /// Note: can handle null item (returns null)
    /// </summary>
    /// <param name="item">Item to get the URL for</param>
    /// <param name="urlOptions">Set UrlOptions to get desired URL</param>
    /// <returns>Item's URL, or null if passed item null</returns>
    public static string GetItemUrl(this Item item, UrlOptions urlOptions)
    {
        Assert.ArgumentNotNull(item, "item");
        Assert.ArgumentNotNull(urlOptions, "urlOptions");

        return(LinkManager.GetItemUrl(item, urlOptions));
    }
Ejemplo n.º 23
0
        /// <summary>
        /// Checks the url string for authentication violations.
        /// </summary>
        /// <param name="url">The url to check.</param>
        /// <param name="options">The options to consider. Ignored.</param>
        /// <returns>True if it meets the authorization standards, false otherwise.</returns>
        private static CheckOutput CheckAuth(string url, UrlOptions options)
        {
            var output    = new CheckOutput();
            var authIndex = url.IndexOf("@", StringComparison.InvariantCultureIgnoreCase);

            output.NewUrl = url;
            if (authIndex > -1)
            {
                var authValue  = url.Substring(0, authIndex);
                var colonIndex = authValue.IndexOf(":", StringComparison.InvariantCultureIgnoreCase);
                if (colonIndex > -1)
                {
                    var user = authValue.Substring(0, colonIndex);
                    var pass = authValue.Substring(colonIndex + 1);
                    output.IsValid = !string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pass);
                }
                else
                {
                    output.IsValid = true;
                }
            }
            else
            {
                output.IsValid = true;
            }

            return(output);
        }
        public object ComputeFieldValue(IIndexable indexable)
        {
            Item item = (Item)(indexable as SitecoreIndexableItem);

            if (item == null)
            {
                return(null);
            }
            if (item.Paths.IsMediaItem)
            {
                return(MediaManager.GetMediaUrl(item));
            }
            UrlOptions defaultUrlOptions = LinkManager.GetDefaultUrlOptions();

            //defaultUrlOptions.LanguageEmbedding= LanguageEmbedding.Never;
            defaultUrlOptions.SiteResolving = Settings.Rendering.SiteResolving;

            var link       = LinkManager.GetItemUrl(item, defaultUrlOptions);
            var noProtocol = link.Replace("://", String.Empty);
            var siteName   = noProtocol.Split('/');

            var processedLink = noProtocol.Replace(siteName[0], String.Empty);

            return(processedLink);
        }
Ejemplo n.º 25
0
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            // call the base implementation for non-bucketed items
            if (!BucketManager.IsItemContainedWithinBucket(item))
            {
                return(base.GetItemUrl(item, options));
            }

            var bucketItem = item.GetParentBucketItemOrParent();

            // is this item a bucket?
            if (bucketItem == null || !bucketItem.IsABucket())
            {
                return(base.GetItemUrl(item, options));
            }

            var bucketUrl = base.GetItemUrl(bucketItem, options);

            if (options.AddAspxExtension)
            {
                bucketUrl = bucketUrl.Replace(".aspx", string.Empty);
            }

            var name = item.Name;

            if (options.EncodeNames)
            {
                name = MainUtil.EncodePath(item.Name, '/');
            }

            bucketUrl = FileUtil.MakePath(bucketUrl, name);

            // reutrn url as bucket-name/item-name
            return(bucketUrl + (options.AddAspxExtension ? ".aspx" : string.Empty));
        }
Ejemplo n.º 26
0
        protected string GetItemUrl(Item detailItem, Item targetItem, UrlOptions urlOptions, WildcardItemUrlArgs args)
        {
            var friendlyUrl = GetFriendlyUrl(targetItem);

            return(args.BaseAction(detailItem, urlOptions)
                   .Replace(Constants.Wildcard.UrlToken, friendlyUrl)
                   .Replace(Constants.Wildcard.Node, friendlyUrl));
        }
        public string GetItemUrl(Item item, string siteName)
        {
            SiteContext site = SiteContext.GetSite(siteName);

            UrlOptions urlOptions = new UrlOptions { Site = site, LanguageEmbedding = LanguageEmbedding.Always };

            return "http://" + site.HostName + LinkManager.GetItemUrl(item, urlOptions);
        }
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            var productPageItem = item.Database.GetItem("{}");
            var baseUrl         = LinkManager.GetItemUrl(item, options);
            var productCode     = item["Product code"];

            return($"{baseUrl}?={productCode}");
        }
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            var url = base.GetItemUrl(item, options);
            if (!string.IsNullOrEmpty(url))
                return url.ToLower();

            return url;
        }
Ejemplo n.º 30
0
        public static string GetAuthorUrl(string authorName, Item currentItem)
        {
            Item       blogHome = General.DataManager.GetBlogHomeItem(currentItem);
            UrlOptions option   = new UrlOptions();

            option.AddAspxExtension = false;
            return(String.Format("{0}/{1}/{2}", LinkManager.GetItemUrl(blogHome, option), XBSettings.XBAuthorQS, authorName));
        }
Ejemplo n.º 31
0
 public BaseController(IHostingEnvironment hostingEnvironment, IOptions <UrlOptions> urlOptions, IOptions <ButterCmsOptions> siteOptions, ButterCMSClient client, IMemoryCache cache)
 {
     HostingEnvironment = hostingEnvironment;
     SiteOptions        = siteOptions.Value;
     Client             = client;
     Cache      = cache;
     UrlOptions = urlOptions.Value;
 }
        //TODO:
        //Consolidate the two below methods into a single method which sets Aspx extension based on 'ishomeitem" boolean
        private static UrlOptions GetItemUrlOptions(SiteContext siteContext)
        {
            UrlOptions urlOptions = UrlOptions.DefaultOptions;

            urlOptions.AlwaysIncludeServerUrl = true;
            urlOptions.Site = siteContext;
            return(urlOptions);
        }
        public static object GetItemInfo(SitecoreInfoType infoType, Item item, UrlOptions urlOptions)
        {
            if (urlOptions == null)
            {
                urlOptions = new UrlOptions();
            }

            switch (infoType)
            {
            case SitecoreInfoType.ContentPath:
                return(item.Paths.ContentPath);

            case SitecoreInfoType.DisplayName:
                return(item.DisplayName);

            case SitecoreInfoType.FullPath:
                return(item.Paths.FullPath);

            case SitecoreInfoType.Name:
                return(item.Name);

            case SitecoreInfoType.Key:
                return(item.Key);

            case SitecoreInfoType.MediaUrl:
                global::Sitecore.Data.Items.MediaItem media = new global::Sitecore.Data.Items.MediaItem(item);
                return(global::Sitecore.Resources.Media.MediaManager.GetMediaUrl(media));

                break;

            case SitecoreInfoType.Path:
                return(item.Paths.Path);

            case SitecoreInfoType.TemplateId:
                return(item.TemplateID.Guid);

            case SitecoreInfoType.TemplateName:
                return(item.TemplateName);

            case SitecoreInfoType.Url:
                return(LinkManager.GetItemUrl(item, urlOptions));

            case SitecoreInfoType.FullUrl:
                return(LinkManager.GetItemUrl(item, new UrlOptions()
                {
                    AlwaysIncludeServerUrl = true
                }));

            case SitecoreInfoType.Version:
                return(item.Version.Number);

            case SitecoreInfoType.Language:
                return(item.Language);

            default:
                throw new NotSupportedException("Value {0} not supported".Formatted(infoType.ToString()));
            }
        }
Ejemplo n.º 34
0
        public static string Url(this Item item, UrlOptions options = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(options != null?LinkManager.GetItemUrl(item, options) : LinkManager.GetItemUrl(item));
        }
        private static UrlOptions GetHomeUrlOptions(SiteContext siteContext)
        {
            UrlOptions urlOptions = UrlOptions.DefaultOptions;

            urlOptions.AlwaysIncludeServerUrl = true;
            urlOptions.AddAspxExtension       = false;
            urlOptions.Site = siteContext;
            return(urlOptions);
        }
Ejemplo n.º 36
0
        protected void Page_Load(object sender, EventArgs e)
        {
            settingsItem = XBlogHelper.General.DataManager.GetBlogSettingsItem(DataSourceItem != null ? DataSourceItem : Sitecore.Context.Item);

            Item blogHome = XBlogHelper.General.DataManager.GetBlogHomeItem(DataSourceItem != null ? DataSourceItem : Sitecore.Context.Item);
            UrlOptions option = new UrlOptions();
            option.AddAspxExtension = false;
            searchUrl = String.Format("{0}/{1}/", LinkManager.GetItemUrl(blogHome, option), XBSettings.XBSearchQS);
        }
		public string GetItemUrl(Item item, UrlOptions options)
		{
			if (item == null)
			{
				return string.Empty;
			}

			return LinkManager.GetItemUrl(item, options);
		}
Ejemplo n.º 38
0
        public static string GetUrl(this Item item, UrlOptions options = null)
        {
            if (options != null)
            {
                return(LinkManager.GetItemUrl(item, options));
            }

            return(LinkManager.GetItemUrl(item));
        }
Ejemplo n.º 39
0
        public static string Url(this Item item, UrlOptions options = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return options != null ? LinkManager.GetItemUrl(item, options) : LinkManager.GetItemUrl(item);
        }
Ejemplo n.º 40
0
        public static string AddAndGetShortUrl(this Item item, UrlOptions options)
        {
            if (item == null)
            {
                Log.Fatal("ShortUrlManager: AddAndGetShortUrl failed. Item was null", new object());
                return null;
            }

            return item.ReadShortUrl() ?? item.AddShortUrl(options);
        }
 public override string GetItemUrl(Item item, UrlOptions options)
 {
     if (!item.TemplateID.Equals(Templates.Event.ID))
     {
         return base.GetItemUrl(item, options);
     }
     else
     {
         return $"{Sitecore.Context.Site.HostName}/Events/{item.Name}";
     }
 }
        public override string GetItemUrl(Data.Items.Item item, UrlOptions options)
        {
            if (item != null)
            {
                return BucketManager.IsItemContainedWithinBucket(item, Context.Database)
                           ? item.ShortUrl()
                           : base.GetItemUrl(item, options);
            }

            return string.Empty;
        }
Ejemplo n.º 43
0
        public static string Url(this Item item, UrlOptions options = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (options != null)
                return LinkManager.GetItemUrl(item, options);
            return !item.Paths.IsMediaItem ? LinkManager.GetItemUrl(item) : MediaManager.GetMediaUrl(item);
        }
Ejemplo n.º 44
0
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(options, "options");

            if (options.ShortenUrls)
            {
                return item.AddAndGetShortUrl(options) ?? base.GetItemUrl(item, options);
            }

            return base.GetItemUrl(item, options);
        }
Ejemplo n.º 45
0
        public static string ResolveShortUrl(this Item item, UrlOptions options)
        {
            if (item == null)
            {
                Log.Fatal("ShortUrlManager: cannot resolve short url. Item was null", new object());
                return null;
            }

            var args = new ResolveShortUrlArgs(item, options);
            CorePipeline.Run("resolveShortUrl", args);
            return args.ResolvedUrl;
        }
Ejemplo n.º 46
0
 private static string GetItemUrlByLanguage(Sitecore.Globalization.Language language)
 {
   using (new LanguageSwitcher(language))
   {
     var options = new UrlOptions
     {
       AlwaysIncludeServerUrl = true,
       LanguageEmbedding = LanguageEmbedding.Always,
       LowercaseUrls = true
     };
     var url = LinkManager.GetItemUrl(Context.Item, options);
     return StringUtil.EnsurePostfix('/', url).ToLower();
   }
 }
        protected virtual string GetMostSuitableRootItemUrl(WildcardRouteItem routeItem, UrlOptions options)
        {
            var url = string.Empty;

            var rootItems = routeItem.WildcardItems;
            var currentSiteItem = rootItems.FirstOrDefault(x => x.Paths.FullPath.StartsWith(Context.Site.RootPath, StringComparison.InvariantCultureIgnoreCase));

            if (currentSiteItem != null)
            {
                return base.GetItemUrl(currentSiteItem, options);
            }

            return url;
        }
		/// <summary>
		/// The expand.
		/// </summary>
		/// <param name="text">The text.</param><param name="urlOptions">The url options.</param>
		public override void Expand(ref string text, UrlOptions urlOptions)
		{
			Assert.ArgumentNotNull(text, "text");
			Assert.ArgumentNotNull(urlOptions, "urlOptions");

			var builder = new StringBuilder();
			var startIndex = 0;
			string prefix;
			var mediaPrefix = this.FindMediaPrefix(text, 0, out prefix);
			while (mediaPrefix >= 0 && text.Length >= mediaPrefix + prefix.Length + 32)
			{
				string id = text.Substring(mediaPrefix + prefix.Length, 32);
				if (!ShortID.IsShortID(id))
				{
					mediaPrefix = this.FindMediaPrefix(text, mediaPrefix + 1, out prefix);
				}
				else
				{
					MediaItem mediaItem = null;
					if (Context.Database != null)
					{
						mediaItem = Context.Database.GetItem(new ID(id));
					}

					if (mediaItem == null)
					{
						mediaPrefix = this.FindMediaPrefix(text, mediaPrefix + 1, out prefix);
					}
					else
					{
						MediaUrlOptions empty = MediaUrlOptions.Empty;
						empty.IncludeExtension = text.Substring(mediaPrefix + prefix.Length + 32 + 1, "ashx".Length) == "ashx";
						string mediaUrl = MediaManager.GetMediaUrl(mediaItem, empty);
						builder.Append(text.Substring(startIndex, mediaPrefix - startIndex));
						builder.Append(mediaUrl);
						startIndex = mediaPrefix + prefix.Length + 32;
						if (empty.IncludeExtension)
						{
							startIndex += "ashx".Length + 1;
						}

						mediaPrefix = this.FindMediaPrefix(text, startIndex, out prefix);
					}
				}
			}

			builder.Append(text.Substring(startIndex));
			text = builder.ToString();
		}
Ejemplo n.º 49
0
        private void LoadBlogPost()
        {
            //Context item - gets Blog Post infomration
            BlogPost blogPost = Sitecore.Context.Item.CreateAs<BlogPost>();
            scTitle.Item = Sitecore.Context.Item;
            scBody.Item = Sitecore.Context.Item;
            dateBlogPostPublishDate.Item = Sitecore.Context.Item;

            UrlOptions option = new UrlOptions();
            option.AlwaysIncludeServerUrl = true;
            //currentUrl = HttpUtility.UrlEncode(LinkManager.GetItemUrl(blogPost.InnerItem, option));
            currentUrl = LinkManager.GetItemUrl(blogPost.InnerItem, option);
            title = HttpUtility.UrlEncode(blogPost.Title);

            if (settingsItem.IncludeEmailOnBlogPost)
                pnlEmail.Visible = true;
            if (settingsItem.IncludeFacebookOnBlogPost)
                pnlFacebook.Visible = true;
            if (settingsItem.IncludeGooglePlusOnBlogPost)
                pnlGooglePlus.Visible = true;
            if (settingsItem.IncludeLinkedinOnBlogPost)
                pnlLinkedin.Visible = true;
            if (settingsItem.IncludeTwitterOnBlogPost)
                pnlTwitter.Visible = true;

            if (dateBlogPostPublishDate != null)
            {
                dateBlogPostPublishDate.Field = BlogPost.BlogPostPublishDateFieldId;
                dateBlogPostPublishDate.Format = settingsItem.BlogPostDateFormat;
            }

            if (blogPost.Authors.Any())
            {
                List<Sitecore.Data.ID> authorIds = new List<Sitecore.Data.ID>();
                foreach (Author a in blogPost.Authors)
                {
                    authorIds.Add(a.ItemId);
                }

                List<Author> authors = AuthorManager.GetAuthorsForBlogPost(authorIds);

                litAuthor.Text = authors[0].FullName;
            }

            litCategories.Text = CategoryManager.GetCommaSeperatedCategoryList(blogPost);

            litTags.Text = TagManager.GetCommaSeperatedTagList(blogPost);
        }
Ejemplo n.º 50
0
        /// <summary>
        /// A server control that outputs a Canonical URL tag such as <link rel="canonical" href="hostname.com/foo/bar" />
        /// </summary>
        /// <param name="output"></param>
        /// <param name="UseDisplayName">Defaults to false</param>
        /// <param name="AlwaysIncludeServerUrl">Defaults to true</param>
        /// <param name="LanguageEmbedding">Defaults to LanguageEmbedding.Never</param>
        /// <param name="SiteResolving">Defaults to true</param>
        /// Usage: <pxl:CanonicalUrl runat="server" AlwaysIncludeServerUrl="True" SiteResolving="" LanguageEmbedding="Never" UseDisplayName="True" />
        protected override void DoRender(HtmlTextWriter output)
        {
            Assert.ArgumentNotNull(output, "output");
            var options = new UrlOptions
                {
                    AlwaysIncludeServerUrl = AlwaysIncludeServerUrl,
                    LanguageEmbedding = LanguageEmbedding,
                    SiteResolving = SiteResolving,
                    UseDisplayName = UseDisplayName
                };

            output.Write("<link rel=\"canonical\" href=\"{0}\" />",
                (Sitecore.Context.Item == null
                             ? String.Empty
                             : LinkManager.GetItemUrl(Sitecore.Context.Item, options)));
        }
Ejemplo n.º 51
0
        public static string AddShortUrl(this Item item, UrlOptions options)
        {
            if (item != null && item.Parent != null && item.Parent.IsABucketFolder())
            {
                try
                {
                    string shortUrl = item.ResolveShortUrl(options);

                    if (string.IsNullOrEmpty(shortUrl))
                    {
                        return null;
                    }

                    if (options.EncodeNames)
                    {
                        shortUrl = MainUtil.EncodePath(shortUrl, '/');
                    }

                    if (options.LowercaseUrls)
                    {
                        shortUrl = shortUrl.ToLowerInvariant();
                    }

                    if (!shortUrl.EndsWith(".aspx") && options.AddAspxExtension)
                    {
                        shortUrl += ".aspx";
                    }

                    ShortUrlTable.RemoveID(Prefix, item.ID);
                    ShortUrlTable.Add(Prefix, shortUrl, item.ID);
                    return shortUrl;
                }
                catch (Exception exception)
                {
                    Log.Fatal(
                        string.Format("Short Url Manager: cannot add short url for item {0} {1} {2}", item.Uri,
                            exception.Message,
                            exception.StackTrace), new object());
                    return null;
                }
            }

            return null;
        }
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            var route = WildcardManager.Current.GetWildcardRouteForLinkProvider(item, Context.Site);

            if (route == null || route.WildcardItemIds.Any(x => x == item.ID))
            {
                return base.GetItemUrl(item, options);
            }

            var url = base.GetItemUrl(item, options);
            var routeUrl = this.GetMostSuitableRootItemUrl(route, options);

            if (string.IsNullOrEmpty(routeUrl))
            {
                return url;
            }

            return this.ReplaceUrlTokens(routeUrl, item, route, options);
        }
Ejemplo n.º 53
0
        /// <summary>
        /// Returns the url for a specified item and a specific device.  UrlOptions will be used
        /// if they are provided, but are not required.  If successful, a url for the item will be
        /// returned.  If not successfully, an empty string will be returned.
        /// </summary>
        /// <param name="item">The item to get the url for.</param>
        /// <param name="device">[optional] The device for the url.</param>
        /// <param name="urlOptions">[optional] The url parameters for the url.</param>
        /// <returns>The url to the item provided.</returns>
        public static string GetDeviceUrlForItem(Item item, DeviceItem device, UrlOptions urlOptions)
        {
            //if an item was not provided then just return empty string
            if (item == null)
            {
                return string.Empty;
            }

            //get our item url depending on if url options were provided or not
            string itemUrl = string.Empty;
            if (urlOptions != null)
            {
                itemUrl = LinkManager.GetItemUrl(item, urlOptions);
            }
            else
            {
                itemUrl = LinkManager.GetItemUrl(item);
            }

            //if our item url is null or empty then just return empty string
            if (string.IsNullOrEmpty(itemUrl))
            {
                return string.Empty;
            }

            //get our device url parameter
            string deviceUrlParam = string.Empty;
            if (device != null)
            {
                deviceUrlParam = device.QueryString;
            }

            //if we don't have a device url parameter then return our item url
            //this could be the default device, which does not have a url parameter.
            if (string.IsNullOrEmpty(deviceUrlParam))
            {
                return itemUrl;
            }

            //return our item url with the device url parameter attached
            return string.Concat(itemUrl, "?", deviceUrlParam);
        }
        public static object GetItemInfo(SitecoreInfoType infoType, Item item, global::Sitecore.Links.UrlOptions urlOptions)
        {
            
            if (urlOptions == null) urlOptions = new UrlOptions();

            if(urlOptions.Language == null)
                urlOptions.Language = item.Language;

            switch (infoType)
            {
                case SitecoreInfoType.ContentPath:
                    return item.Paths.ContentPath;
                case SitecoreInfoType.DisplayName:
                    return item.DisplayName;
                case SitecoreInfoType.FullPath:
                    return item.Paths.FullPath;
                case SitecoreInfoType.Name:
                    return item.Name;
                case SitecoreInfoType.Key:
                    return item.Key;
                case SitecoreInfoType.MediaUrl:
                    global::Sitecore.Data.Items.MediaItem media = new global::Sitecore.Data.Items.MediaItem(item);
                    return global::Sitecore.Resources.Media.MediaManager.GetMediaUrl(media);
                    break;
                case SitecoreInfoType.Path:
                    return item.Paths.Path;
                case SitecoreInfoType.TemplateId:
                    return item.TemplateID.Guid;
                case SitecoreInfoType.TemplateName:
                    return item.TemplateName;
                case SitecoreInfoType.Url:
                    return LinkManager.GetItemUrl(item, urlOptions);
                case SitecoreInfoType.FullUrl:
                    return LinkManager.GetItemUrl(item, new UrlOptions() { AlwaysIncludeServerUrl = true });
                case SitecoreInfoType.Version:
                    return item.Version.Number;
                case SitecoreInfoType.Language:
                    return item.Language;
                default:
                    throw new NotSupportedException("Value {0} not supported".Formatted(infoType.ToString()));
            }
        }
        private readonly UrlOptions _urlOptions = UrlOptions.RequireProtocol; //Default to require protocol

        #endregion Fields

        #region Constructors

        public UrlAttribute(UrlOptions urlOptions = UrlOptions.RequireProtocol)
            : base(DataType.Text)
        {
            _urlOptions = urlOptions;

            switch (urlOptions)
            {
                case UrlOptions.RequireProtocol:
                    _regex = @"^" + BaseProtocolExpression + BaseUrlExpression + @"$";
                    break;
                case UrlOptions.OptionalProtocol:
                    _regex = @"^(" + BaseProtocolExpression + @")?" + BaseUrlExpression + @"$";
                    break;
                case UrlOptions.DisallowProtocol:
                    _regex = @"^" + BaseUrlExpression + @"$";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("urlOptions");
            }
        }
        private readonly UrlOptions _urlOptions = UrlOptions.RequireProtocol; //Default to require protocol

        #endregion Fields

        #region Constructors

        public UrlTextboxAttribute(UrlOptions urlOptions = UrlOptions.RequireProtocol)
            : base(DataType.Url)
        {
            _urlOptions = urlOptions;

            switch (urlOptions)
            {
                case UrlOptions.RequireProtocol:
                    _regex = @"^(https?|ftp):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$";
                    break;
                case UrlOptions.OptionalProtocol:
                    _regex = @"^((https?|ftp):\/\/)?(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$";
                    break;
                case UrlOptions.DisallowProtocol:
                    _regex = @"^(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-fA-F]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("urlOptions");
            }
        }
Ejemplo n.º 57
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BlogSettings settingsItem = XBlogHelper.General.DataManager.GetBlogSettingsItem(DataSourceItem != null ? DataSourceItem : Sitecore.Context.Item);

            BlogPost blogPost = Sitecore.Context.Item.CreateAs<BlogPost>();

            UrlOptions options = new UrlOptions();
            options.AlwaysIncludeServerUrl = true;
            ogURL = LinkManager.GetItemUrl(blogPost.InnerItem, options);

            ogTitle = blogPost.Title;

            ogDescription = "";
            if (!String.IsNullOrEmpty(blogPost.Summary))
            {
                ogDescription = Regex.Replace(blogPost.Summary, "<.*?>", String.Empty);
            }
            else
            {
                ogDescription = Regex.Replace(XBlogHelper.Helpers.Helper.SafeSubstring(blogPost.Summary, settingsItem.DisplaySummaryLength), "<.*?>", String.Empty);
            }

            ogAuthorImage = "";
            if (blogPost.Authors.Any())
            {
                List<Sitecore.Data.ID> authorIds = new List<Sitecore.Data.ID>();
                foreach (Author a in blogPost.Authors)
                {
                    authorIds.Add(a.ItemId);
                }

                List<Author> authors = AuthorManager.GetAuthorsForBlogPost(authorIds);

                if (authors[0].ProfileImage != null && authors[0].ProfileImage.MediaItem != null && settingsItem.DisplayAuthorImage)
                {
                    MediaUrlOptions mediaOptions = new MediaUrlOptions();
                    mediaOptions.AlwaysIncludeServerUrl = true;
                    ogAuthorImage = MediaManager.GetMediaUrl(authors[0].ProfileImage.MediaItem, mediaOptions);
                }
            }
        }
        protected static void GetWebsiteScripts(GetMediaStreamPipelineArgs args, ID targetItemId)
        {
            string targetItemUrl;
            string site = string.IsNullOrEmpty(args.Options.CustomOptions["site"])
                              ? "website"
                              : args.Options.CustomOptions["site"];
            using (new SiteContextSwitcher(SiteContext.GetSite(site)))
            {
                var item = Sitecore.Context.Database.GetItem(targetItemId);
                if (item == null)
                {
                    return;
                }

                var options = new UrlOptions();
                options.LanguageEmbedding = LanguageEmbedding.Never;
                options.AlwaysIncludeServerUrl = true;
                targetItemUrl = LinkManager.GetItemUrl(item, options);
            }

            var fileName = string.Format("SplitShot_{0}.png", ID.NewID);
            string tempPath = HttpContext.Current.Server.MapPath("/temp");
            string serverPath = HttpContext.Current.Server.MapPath("/App_Data/SplitShot");
            string arguments = string.Format(" rasterize.js \"{0}\" {1}\\{2}", targetItemUrl, tempPath, fileName);
            var psi = new System.Diagnostics.ProcessStartInfo(string.Format("{0}\\phantomjs.exe", serverPath), arguments)
                          {
                              UseShellExecute = false,
                              RedirectStandardOutput = true,
                              RedirectStandardInput = true,
                              RedirectStandardError = true,
                              WorkingDirectory = serverPath
                          };

            var process = System.Diagnostics.Process.Start(psi);
            process.WaitForExit();

            var stream = new MemoryStream();
            AddFileToStream(stream, "/temp/" + fileName);

            args.OutputStream = new MediaStream(stream, "png", args.MediaData.MediaItem);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pItem"></param>
        /// <param name="pXmlDoc"></param>
        /// <param name="pRootNode"></param>
        /// <param name="pUrlOptions"></param>
        public void AddUrlEntry(
          Item pItem, XmlDocument pXmlDoc, XmlElement pRootNode, UrlOptions pUrlOptions)
        {
            if (pItem != null && pItem.Visualization != null && pItem.Visualization.Layout != null && pItem.Name != "*")
            {
                if (pItem["Hide From Navigation"] != "1")
                {
                    string url = "www.clariant.com" + UrlHelper.GetUrl(pItem);
                    url = url.Replace("sitecore/content/", "");
                    GenerateUrlEntry(pXmlDoc, pRootNode, url);
                }
            }

            if (pItem != null)
            {
                foreach (Item childItem in pItem.Children)
                {
                    AddUrlEntry(childItem, pXmlDoc, pRootNode, pUrlOptions);
                }
            }
        }
        protected virtual string ReplaceUrlTokens(string routeUrl, Item item, WildcardRouteItem routeItem, UrlOptions options)
        {
            var resultUrl = new List<string>();

            var tokenValues = this.GetTokenValues(item, routeItem, options);

            var urlPattern = routeUrl.Split(new[] { '/' });
            var tokenCounter = 0;
            foreach (var segment in urlPattern)
            {
                var resultSegment = segment;
                if (segment.ToLower() == WildcardTokenizedString)
                {
                    resultSegment = tokenValues[tokenCounter++];
                }

                resultUrl.Add(resultSegment);
            }

            return string.Join("/", resultUrl);
        }