Esempio n. 1
0
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            if (source == null)
            {
                return(new UrlPicker());
            }
            string input = source.ToString();

            if (!DetectIsJson(input))
            {
                return(input);
            }
            try
            {
                UrlPicker     urlPicker     = JsonConvert.DeserializeObject <UrlPicker>(input);
                UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                if (urlPicker.TypeData.ContentId.HasValue)
                {
                    urlPicker.TypeData.Content = umbracoHelper.TypedContent(urlPicker.TypeData.ContentId);
                }
                if (urlPicker.TypeData.MediaId.HasValue)
                {
                    urlPicker.TypeData.Media = umbracoHelper.TypedMedia(urlPicker.TypeData.MediaId);
                }
                switch (urlPicker.Type)
                {
                case UrlPicker.UrlPickerTypes.Content:
                    if (urlPicker.TypeData.Content != null)
                    {
                        urlPicker.Url  = urlPicker.TypeData.Content.Url;
                        urlPicker.Name = string.IsNullOrWhiteSpace(urlPicker.Meta.Title) ? urlPicker.TypeData.Content.Name : urlPicker.Meta.Title;
                        break;
                    }
                    break;

                case UrlPicker.UrlPickerTypes.Media:
                    if (urlPicker.TypeData.Media != null)
                    {
                        urlPicker.Url  = urlPicker.TypeData.Media.Url;
                        urlPicker.Name = string.IsNullOrWhiteSpace(urlPicker.Meta.Title) ? urlPicker.TypeData.Media.Name : urlPicker.Meta.Title;
                        break;
                    }
                    break;

                default:
                    urlPicker.Url  = urlPicker.TypeData.Url;
                    urlPicker.Name = string.IsNullOrWhiteSpace(urlPicker.Meta.Title) ? urlPicker.TypeData.Url : urlPicker.Meta.Title;
                    break;
                }
                return((object)urlPicker);
            }
            catch (Exception ex)
            {
                LogHelper.Error <UrlPickerValueConverter>(ex.Message, ex);
                return((object)new UrlPicker());
            }
        }
Esempio n. 2
0
        public static LinkInfo GetSingleUrlFromUrlPicker(UrlPicker link)
        {
            LinkInfo linkInfo = null;

            if (link != null && link.Url != null)
            {
                if (link.Type == UrlPicker.UrlPickerTypes.Media)
                {
                    linkInfo          = new LinkInfo();
                    linkInfo.LinkType = UrlPicker.UrlPickerTypes.Media;

                    linkInfo.LinkUmbracoNode = link.TypeData.Media;

                    linkInfo.LinkURL = link.Url;

                    if (link.Meta.NewWindow)
                    {
                        linkInfo.LinkTitle  = " title=\"" + umbraco.library.GetDictionaryItem("USN New Window Title Tag") + "\" ";
                        linkInfo.LinkTarget = "target=\"blank\"";
                        linkInfo.LinkIcon   = "<i class=\"fa fa-external-link after\"></i>";
                    }

                    if (link.Meta.Title == String.Empty)
                    {
                        linkInfo.LinkCaption = link.TypeData.Media.Name;
                    }
                    else
                    {
                        linkInfo.LinkCaption = link.Meta.Title;
                    }
                }
                else if (link.Type == UrlPicker.UrlPickerTypes.Content)
                {
                    linkInfo = new LinkInfo();

                    linkInfo.LinkUmbracoNode = link.TypeData.Content;
                    linkInfo.LinkType        = UrlPicker.UrlPickerTypes.Content;

                    linkInfo.LinkURL = link.Url;

                    if (link.Meta.NewWindow)
                    {
                        linkInfo.LinkTitle  = " title=\"" + umbraco.library.GetDictionaryItem("USN New Window Title Tag") + "\" ";
                        linkInfo.LinkTarget = "target=\"blank\"";
                        linkInfo.LinkIcon   = "<i class=\"fa fa-external-link after\"></i>";
                    }

                    if (link.Meta.Title == String.Empty)
                    {
                        linkInfo.LinkCaption = link.TypeData.Content.Name;
                    }
                    else
                    {
                        linkInfo.LinkCaption = link.Meta.Title;
                    }

                    //Document types ending _AN should be linked to anchor position on page.
                    if (link.TypeData.Content.DocumentTypeAlias.IndexOf("_AN", StringComparison.Ordinal) != -1)
                    {
                        var    pageComponentsNode = link.TypeData.Content.Parent;
                        var    parentNode         = pageComponentsNode.Parent;
                        string anchor             = "#pos_" + link.TypeData.Content.Id.ToString();
                        linkInfo.LinkURL = parentNode.Url + anchor;
                    }
                }
                else if (link.Type == UrlPicker.UrlPickerTypes.Url)
                {
                    linkInfo = new LinkInfo
                    {
                        LinkUmbracoNode = null,
                        LinkType        = UrlPicker.UrlPickerTypes.Url,
                        LinkURL         = link.Url
                    };



                    if (link.Meta.NewWindow)
                    {
                        linkInfo.LinkTitle  = " title=\"" + umbraco.library.GetDictionaryItem("USN New Window Title Tag") + "\" ";
                        linkInfo.LinkTarget = "target=\"blank\"";
                        linkInfo.LinkIcon   = "<i class=\"fa fa-external-link after\"></i>";
                    }

                    if (link.Meta.Title == string.Empty)
                    {
                        linkInfo.LinkCaption = link.Url;
                    }
                    else
                    {
                        linkInfo.LinkCaption = link.Meta.Title;
                    }
                }
            }

            return(linkInfo);
        }