Exemple #1
0
        public string Post([FromBody] string articleNumber)
        {
            var    options  = new LinkUrlOptions();
            string mediaUrl = LinkManager.GetDynamicUrl(_articleUtil.GetArticleItemByNumber(articleNumber), options);

            return(mediaUrl);
        }
Exemple #2
0
 public void GetDynamicUrlCallsCallsBaseProviderIfCurrentNotSet(
     SwitchingLinkProvider sut,
     Item item,
     LinkUrlOptions options)
 {
     sut.GetDynamicUrl(item, options).Should().NotBeEmpty();
 }
        /// <summary>
        /// Detect if the item is a known token type and, if so, append the token identifyer
        /// </summary>
        public override string GetDynamicUrl(Item item, LinkUrlOptions options)
        {
            string dynamicUrl = base.GetDynamicUrl(item, options);

            if (TokenConfig.Processors.Any(x => x.TokenTemplates.Contains(item.TemplateID)))
            {
                dynamicUrl += TOKEN_IDENTIFIER;
            }

            return(dynamicUrl);
        }
Exemple #4
0
 public void GetDynamicUrlCallsCurrentProvider(
     SwitchingLinkProvider sut,
     [Substitute] LinkProvider current,
     Item item,
     LinkUrlOptions options)
 {
     using (new Switcher <LinkProvider>(current))
     {
         sut.GetDynamicUrl(item, options).Should().BeSameAs(current.GetDynamicUrl(item, options));
     }
 }
Exemple #5
0
 public override string GetDynamicUrl(Item item, LinkUrlOptions options)
 {
     if (this.StorefrontContext.IsStorefrontSite && this.IsCommerceCategoryItem(item))
     {
         var categoryItemUrl = item.GetCommerceItemUrl();
         if (!string.IsNullOrWhiteSpace(categoryItemUrl))
         {
             return(categoryItemUrl);
         }
     }
     return(base.GetDynamicUrl(item, options));
 }
Exemple #6
0
        /// <summary>Handles a click on the OK button.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The arguments.</param>
        /// <remarks>
        /// When the user clicks OK, the dialog is closed by calling
        /// the <see cref="M:Sitecore.Web.UI.Sheer.ClientResponse.CloseWindow">CloseWindow</see> method.
        /// </remarks>
        protected override void OnOK(object sender, EventArgs args)
        {
            Assert.ArgumentNotNull(sender, ExtensionMethods.nameof(() => sender));
            Assert.ArgumentNotNull((object)args, ExtensionMethods.nameof(() => args));
            string displayName;
            string text;

            if (this.Tabs.Active == 0 || this.Tabs.Active == 2)
            {
                Item selectionItem = this.InternalLinkTreeview.GetSelectionItem();
                if (selectionItem == null)
                {
                    SheerResponse.Alert("Select an item.");
                    return;
                }
                displayName = selectionItem.DisplayName;
                if (selectionItem.Paths.IsMediaItem)
                {
                    text = this.GetMediaUrl(selectionItem);
                }
                else
                {
                    if (!selectionItem.Paths.IsContentItem)
                    {
                        SheerResponse.Alert("Select either a content item or a media item.");
                        return;
                    }
                    LinkUrlOptions options = new LinkUrlOptions();
                    text = LinkManager.GetDynamicUrl(selectionItem, options);
                }
            }
            else
            {
                MediaItem selectionItem = (MediaItem)this.MediaTreeview.GetSelectionItem();
                if (selectionItem == null)
                {
                    SheerResponse.Alert("Select a media item.");
                    return;
                }
                displayName = selectionItem.DisplayName;
                text        = this.GetMediaUrl((Item)selectionItem);
            }
            if (this.Mode == "webedit")
            {
                SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(text));
                base.OnOK(sender, args);
            }
            else
            {
                SheerResponse.Eval("TinyMCEEditor.InsertLink.scClose(" + StringUtil.EscapeJavascriptString(text) + "," + StringUtil.EscapeJavascriptString(displayName) + ")");
            }
        }
        /// <summary>
        /// This method returns the dynamicly generated URL based on the item type.
        /// </summary>
        /// <param name="item">The item</param>
        /// <param name="options">The options</param>
        /// <returns>The dynamically built URL</returns>
        public override string GetDynamicUrl(Item item, LinkUrlOptions options)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(options, "options");

            var url      = string.Empty;
            var itemType = item.ItemType();

            bool productCatalogLinkRequired = Sitecore.Web.WebUtil.GetRawUrl().IndexOf(ProductItemResolver.NavigationItemName, System.StringComparison.OrdinalIgnoreCase) >= 0;

            if (productCatalogLinkRequired)
            {
                url = CatalogUrlManager.BuildProductCatalogLink(item);
            }
            else if (this.UseShopLinks)
            {
                if (itemType == StorefrontConstants.ItemTypes.Product)
                {
                    url = CatalogUrlManager.BuildProductShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName, true);
                }
                else if (itemType == StorefrontConstants.ItemTypes.Category)
                {
                    url = CatalogUrlManager.BuildCategoryShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
                else if (itemType == StorefrontConstants.ItemTypes.Variant)
                {
                    url = CatalogUrlManager.BuildVariantShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName, true);
                }
            }
            else
            {
                if (itemType == StorefrontConstants.ItemTypes.Product)
                {
                    url = CatalogUrlManager.BuildProductLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
                else if (itemType == StorefrontConstants.ItemTypes.Category)
                {
                    url = CatalogUrlManager.BuildCategoryLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
            }

            if (string.IsNullOrEmpty(url))
            {
                url = base.GetDynamicUrl(item, options);
            }

            return(url);
        }
Exemple #8
0
        public JsonResult <string> Get(string path)
        {
            if (path == null)
            {
                return(null);
            }
            var options = new LinkUrlOptions();
            var item    = _sitecoreService.GetItem <Item>(path);

            if (item == null)
            {
                return(null);
            }
            string mediaUrl = LinkManager.GetDynamicUrl(item, options);

            return(Json(mediaUrl));
        }
        /// <summary>
        /// This method returns the dynamicly generated URL based on the item type.
        /// </summary>
        /// <param name="item">The item</param>
        /// <param name="options">The options</param>
        /// <returns>The dynamically built URL</returns>
        public override string GetDynamicUrl(Item item, LinkUrlOptions options)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(options, "options");

            var url           = string.Empty;
            var searchManager = CommerceTypeLoader.CreateInstance <ICommerceSearchManager>();

            if (this.UseShopLinks)
            {
                if (searchManager.IsItemProduct(item))
                {
                    url = CatalogUrlManager.BuildProductShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName, true);
                }
                else if (searchManager.IsItemCategory(item))
                {
                    url = CatalogUrlManager.BuildCategoryShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
                else if (this.UseShopLinks && searchManager.IsItemVariant(item))
                {
                    url = CatalogUrlManager.BuildVariantShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName, true);
                }
            }
            else
            {
                if (searchManager.IsItemProduct(item))
                {
                    url = CatalogUrlManager.BuildProductLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
                else if (searchManager.IsItemCategory(item))
                {
                    url = CatalogUrlManager.BuildCategoryLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
            }

            if (string.IsNullOrEmpty(url))
            {
                url = base.GetDynamicUrl(item, options);
            }

            return(url);
        }
Exemple #10
0
        public override string GetDynamicUrl(Item item, LinkUrlOptions options)
        {
            Assert.ArgumentNotNull(item, nameof(item));
            Assert.ArgumentNotNull(options, nameof(options));

            var urlService = DependencyResolver.Current.GetService <CatalogUrlService>();

            //TODO: Incorporate the url options in the catalog URL building
            if (Context.PageMode.IsExperienceEditor)
            {
                return(urlService.GetProductCatalogUrl(item));
            }

            var url = UseShopLinks ? urlService.BuildShopUrl(item, IncludeCatalog, IncludeFriendlyName) : urlService.BuildUrl(item, IncludeCatalog, IncludeFriendlyName);

            if (string.IsNullOrEmpty(url))
            {
                url = base.GetDynamicUrl(item, options);
            }

            return(url);
        }
        protected override void OnOK(object sender, EventArgs args)
        {
            if (Tabs.Active == 2)
            {
                Item   selectionItem = TokenTreeview.GetSelectionItem();
                string displayName   = selectionItem.DisplayName;

                LinkUrlOptions options     = new LinkUrlOptions();
                string         dynamicLink = LinkManager.GetDynamicUrl(selectionItem, options);

                string response = String.Format(
                    "scClose({0},{1})",
                    StringUtil.EscapeJavascriptString(dynamicLink),
                    StringUtil.EscapeJavascriptString(displayName));

                SheerResponse.Eval(response);
            }
            else
            {
                base.OnOK(sender, args);
            }
        }
 private bool GetSelectedUrl(out string url, out string displayName)
 {
     url         = null;
     displayName = null;
     if (Tabs.Active == 0 || Tabs.Active == 2)
     {
         var selectedItem = InternalLinkTreeview.GetSelectionItem();
         if (selectedItem == null)
         {
             return(false);
         }
         displayName = selectedItem.GetUIDisplayName();
         if (selectedItem.Paths.IsMediaItem)
         {
             url = GetMediaUrl(selectedItem);
         }
         else
         {
             if (!IsValidContentOrProductItem(selectedItem))
             {
                 return(false);
             }
             var options = new LinkUrlOptions();
             url = LinkManager.GetDynamicUrl(selectedItem, options);
         }
     }
     else
     {
         MediaItem item = MediaTreeview.GetSelectionItem();
         if (item == null)
         {
             return(false);
         }
         displayName = item.DisplayName;
         url         = GetMediaUrl(item);
     }
     return(true);
 }
 public void GetDynamicUrlCallsCurrentProvider(SwitchingLinkProvider sut, [Substitute] LinkProvider current, Item item, LinkUrlOptions options)
 {
   using (new Switcher<LinkProvider>(current))
   {
     sut.GetDynamicUrl(item, options).Should().BeSameAs(current.GetDynamicUrl(item, options));
   }
 }
        public override string GetDynamicUrl(Item item, LinkUrlOptions options)
        {
            var current = this.CurrentProvider;

            return(current != null?current.GetDynamicUrl(item, options) : base.GetDynamicUrl(item, options));
        }
 public string GetDynamicUrl(Item item, LinkUrlOptions options)
 {
     return LinkManager.GetDynamicUrl(item, options);
 }
Exemple #16
0
        protected override void OnOK(object sender, EventArgs args)
        {
            string mediaUrl;
            string displayName;

            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");
            string linkedId = string.Empty;
            string goalId   = string.Empty;

            //verify goal has been selected
            Item goalItem = rootItemDataContext.GetFolder();

            if (goalItem == null || goalItem.ID.ToString() == AnalyticsReference.System_MarketingCenter_Goals.Guid)
            {
                //reset to null to avoid setting the goal item to the goal folder
                goalItem = null;
            }

            if (this.Tabs.Active == 0)
            {
                Item selectionItem = this.InternalLinkTreeview.GetSelectionItem();
                if (selectionItem == null)
                {
                    SheerResponse.Alert("Select an item.", new string[0]);
                    return;
                }

                //use variant mapping functionality
                MultiVariantProcessor processor = new MultiVariantProcessor();
                if (processor.IsVariantTemplate(selectionItem.TemplateID.ToString()))
                {
                    SheerResponse.Alert("Select an non variant item.", new string[0]);
                    return;
                }

                displayName = selectionItem.DisplayName;
                if (selectionItem.Paths.IsMediaItem)
                {
                    mediaUrl = GetMediaUrl(selectionItem);
                }
                else
                {
                    if (!selectionItem.Paths.IsContentItem)
                    {
                        SheerResponse.Alert("Select either a content item or a media item.", new string[0]);
                        return;
                    }
                    LinkUrlOptions options = new LinkUrlOptions();
                    mediaUrl = LinkManager.GetDynamicUrl(selectionItem, options);
                    linkedId = selectionItem.ID.ToString();
                }
            }
            else
            {
                MediaItem item2 = this.MediaTreeview.GetSelectionItem();
                if (item2 == null)
                {
                    SheerResponse.Alert("Select a media item.", new string[0]);
                    return;
                }

                //use variant mapping functionality
                MultiVariantProcessor processor = new MultiVariantProcessor();
                if (processor.IsVariantTemplate(item2.InnerItem.TemplateID.ToString()))
                {
                    SheerResponse.Alert("Select an non variant item.", new string[0]);
                    return;
                }

                displayName = item2.DisplayName;
                mediaUrl    = GetMediaUrl((Item)item2);
                linkedId    = item2.ID.ToString();
            }
            if (this.Mode == "webedit")
            {
                SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(mediaUrl));
                base.OnOK(sender, args);
            }
            else
            {
                string url = StringUtil.EscapeJavascriptString(mediaUrl);

                if (goalItem.IsNotNull())
                {
                    goalId = goalItem.ID.ToString();
                }

                //put querystring on for only content items, media items will be picked up within a javascript event.
                if (this.Tabs.Active == 0)
                {
                    //set default parameter key
                    string parameterKey = "sc_trk";

                    //check configuration file for parameter key
                    if (!string.IsNullOrEmpty(Sitecore.Configuration.Settings.GetSetting("Analytics.EventQueryStringKey")))
                    {
                        parameterKey = Sitecore.Configuration.Settings.GetSetting("Analytics.EventQueryStringKey");
                    }

                    //if there is a goal, assign a querystring parameter
                    //no check for existing parameters, this is because it will come across as link.aspx?_id=3D98F330EBA94EAA97C63F0D0FE1D5D8?sc_trk=SomeGoal
                    //and when the field renderer processes this it will convert it as /research?sc_trk=SomeGoal
                    string goalName = string.Empty;
                    if (goalItem.IsNotNull() && !string.IsNullOrEmpty(goalItem.Name))
                    {
                        goalName = string.Format("?{1}={0}", goalItem.Name, parameterKey);
                    }

                    url = StringUtil.EscapeJavascriptString(string.Format("{0}{1}", mediaUrl, goalName));
                }

                SheerResponse.Eval("scClose(" + url + "," + StringUtil.EscapeJavascriptString(displayName) + ",'" + linkedId + "','" + goalId + "')");
            }
        }
 public string GetDynamicUrl(Item item, LinkUrlOptions options)
 {
     return(LinkManager.GetDynamicUrl(item, options));
 }
 public override string GetDynamicUrl(Item item, LinkUrlOptions options)
 {
     return(this.Provider.GetDynamicUrl(item, options));
 }
 public override string GetDynamicUrl(Item item, LinkUrlOptions options)
 {
   var current = this.CurrentProvider;
   return current != null ? current.GetDynamicUrl(item, options) : base.GetDynamicUrl(item, options);
 }
        /// <summary>
        /// This method returns the dynamicly generated URL based on the item type.
        /// </summary>
        /// <param name="item">The item</param>
        /// <param name="options">The options</param>
        /// <returns>The dynamically built URL</returns>
        public override string GetDynamicUrl(Item item, LinkUrlOptions options)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(options, "options");

            var url = string.Empty;
            var searchManager = CommerceTypeLoader.CreateInstance<ICommerceSearchManager>();
            if (this.UseShopLinks)
            {
                if (searchManager.IsItemProduct(item))
                {
                    url = CatalogUrlManager.BuildProductShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName, true);
                }
                else if (searchManager.IsItemCategory(item))
                {
                    url = CatalogUrlManager.BuildCategoryShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
                else if (this.UseShopLinks && searchManager.IsItemVariant(item))
                {
                    url = CatalogUrlManager.BuildVariantShopLink(item, this.IncludeCatalog, this.IncludeFriendlyName, true);
                }
            }
            else
            {
                if (searchManager.IsItemProduct(item))
                {
                    url = CatalogUrlManager.BuildProductLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
                else if (searchManager.IsItemCategory(item))
                {
                    url = CatalogUrlManager.BuildCategoryLink(item, this.IncludeCatalog, this.IncludeFriendlyName);
                }
            }

            if (string.IsNullOrEmpty(url))
            {
                url = base.GetDynamicUrl(item, options);
            }

            return url;
        }
		/// <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)
		{
			string url = null;
			Assert.ArgumentNotNull(item, "item");
			Assert.ArgumentNotNull(options, "options");

			if (Context.Site != null && (Context.PageMode.IsPreview || Context.PageMode.IsPageEditor))
			{
				var dynamicOptions = new LinkUrlOptions { Site = Context.Site.Name, Language = item.Language };

				var sharedContentSetting = SharedContentLinkProviderConfiguration.Settings.Rules[item.TemplateName];
				if (sharedContentSetting != null)
				{
					// Make sure we load Shared Content Items for editing in the context of their parent site
					var siteName = PathUtility.GetFirstFolderFromPath(item.Paths.FullPath, sharedContentSetting.PathToSiteFolder);

					if (!string.IsNullOrEmpty(siteName))
					{
						dynamicOptions.Site = siteName;
					}
				}

				url = this.GetDynamicUrl(item, dynamicOptions);
			}

			if (url == null)
			{
				var builder = new SharedContentLinkBuilder(options);
				url = builder.GetItemUrl(item);
				if (this.LowercaseUrls)
				{
					url = url.ToLowerInvariant();
				}
			}

			return url;
		}
		/// <summary>
		/// Gets the dynamic URL for an item.
		/// </summary>
		/// <param name="item">The item to create an URL to.</param>
		/// <param name="options">The options.</param>
		/// <returns>The dynamic URL.</returns>
		public override string GetDynamicUrl(Item item, LinkUrlOptions options)
		{
			Assert.ArgumentNotNull(item, "item");
			Assert.ArgumentNotNull(options, "options");
			var builder = new StringBuilder();

			// Get the hostname for the site
			var siteInfo = Factory.GetSiteInfo(options.Site);

			if (siteInfo != null)
			{
				if (!string.IsNullOrEmpty(siteInfo.TargetHostName))
				{
					builder.Append("http://");
					builder.Append(siteInfo.TargetHostName);
				}
			}

			var queryStringSeparator = HttpUtility.HtmlDecode(Settings.Links.QueryStringSeparator);
			builder.Append("/~/link.aspx?_id" + '=' + item.ID.ToShortID());
			if (options.Language != null)
			{
				builder.Append(queryStringSeparator + "_lang" + "=" + options.Language.Name);
			}

			if (!string.IsNullOrEmpty(options.Site))
			{
				builder.Append(queryStringSeparator + "_site" + "=" + options.Site);
			}

			builder.Append(queryStringSeparator + "_z=z");

			return builder.ToString();
		}
        protected override void OnOK(object sender, EventArgs args)
        {
            string mediaUrl;
            string displayName;
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");
            string linkedId = string.Empty;
            string goalId = string.Empty;

            //verify goal has been selected
            Item goalItem = rootItemDataContext.GetFolder();
            if (goalItem == null || goalItem.ID.ToString() == AnalyticsReference.System_MarketingCenter_Goals.Guid)
            {
                //reset to null to avoid setting the goal item to the goal folder
                goalItem = null;
            }

            if (this.Tabs.Active == 0)
            {
                Item selectionItem = this.InternalLinkTreeview.GetSelectionItem();
                if (selectionItem == null)
                {
                    SheerResponse.Alert("Select an item.", new string[0]);
                    return;
                }

                //use variant mapping functionality
                MultiVariantProcessor processor = new MultiVariantProcessor();
                if (processor.IsVariantTemplate(selectionItem.TemplateID.ToString()))
                {
                    SheerResponse.Alert("Select an non variant item.", new string[0]);
                    return;
                }

                displayName = selectionItem.DisplayName;
                if (selectionItem.Paths.IsMediaItem)
                {
                    mediaUrl = GetMediaUrl(selectionItem);
                }
                else
                {
                    if (!selectionItem.Paths.IsContentItem)
                    {
                        SheerResponse.Alert("Select either a content item or a media item.", new string[0]);
                        return;
                    }
                    LinkUrlOptions options = new LinkUrlOptions();
                    mediaUrl = LinkManager.GetDynamicUrl(selectionItem, options);
                    linkedId = selectionItem.ID.ToString();
                }
            }
            else
            {
                MediaItem item2 = this.MediaTreeview.GetSelectionItem();
                if (item2 == null)
                {
                    SheerResponse.Alert("Select a media item.", new string[0]);
                    return;
                }

                //use variant mapping functionality
                MultiVariantProcessor processor = new MultiVariantProcessor();
                if (processor.IsVariantTemplate(item2.InnerItem.TemplateID.ToString()))
                {
                    SheerResponse.Alert("Select an non variant item.", new string[0]);
                    return;
                }

                displayName = item2.DisplayName;
                mediaUrl = GetMediaUrl((Item)item2);
                linkedId = item2.ID.ToString();
            }
            if (this.Mode == "webedit")
            {
                SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(mediaUrl));
                base.OnOK(sender, args);
            }
            else
            {
                string url = StringUtil.EscapeJavascriptString(mediaUrl);

                if (goalItem.IsNotNull())
                {
                    goalId = goalItem.ID.ToString();
                }

                //put querystring on for only content items, media items will be picked up within a javascript event.
                if (this.Tabs.Active == 0)
                {
                    //set default parameter key
                    string parameterKey = "sc_trk";

                    //check configuration file for parameter key
                    if (!string.IsNullOrEmpty(Sitecore.Configuration.Settings.GetSetting("Analytics.EventQueryStringKey")))
                    {
                        parameterKey = Sitecore.Configuration.Settings.GetSetting("Analytics.EventQueryStringKey");
                    }

                    //if there is a goal, assign a querystring parameter
                    //no check for existing parameters, this is because it will come across as link.aspx?_id=3D98F330EBA94EAA97C63F0D0FE1D5D8?sc_trk=SomeGoal
                    //and when the field renderer processes this it will convert it as /research?sc_trk=SomeGoal
                    string goalName = string.Empty;
                    if (goalItem.IsNotNull() && !string.IsNullOrEmpty(goalItem["Name"]))
                    {
                        goalName = string.Format("?{1}={0}", goalItem["Name"], parameterKey);
                    }

                    url = StringUtil.EscapeJavascriptString(string.Format("{0}{1}", mediaUrl, goalName));
                }

                SheerResponse.Eval("scClose(" + url + "," + StringUtil.EscapeJavascriptString(displayName) + ",'" + linkedId + "','" + goalId + "')");
            }
        }
 public void GetDynamicUrlCallsCallsBaseProviderIfCurrentNotSet(SwitchingLinkProvider sut, Item item, LinkUrlOptions options)
 {
   sut.GetDynamicUrl(item, options).Should().NotBeEmpty();
 }