Esempio n. 1
0
        public ContentBlockModel(string providerName, string content, bool enableSocialSharing, Guid sharedContentId, Type containerType)
        {
            this.ContainerType       = containerType;
            this.ProviderName        = providerName;
            this.EnableSocialSharing = enableSocialSharing;
            this.SharedContentID     = sharedContentId;

            content = this.GetContentHtmlValue(content);

            this.Content = LinkParser.ResolveLinks(
                content,
                DynamicLinksParser.GetContentUrl,
                null,
                SystemManager.IsInlineEditingMode);
        }
        public ListModel(string items)
        {
            this.Items = new List <ListItem>();

            if (!String.IsNullOrEmpty(items))
            {
                this.Items.AddRange(ServiceStack.Text.JsonSerializer.DeserializeFromString <List <ListItem> >(items));

                //Resolve the links
                foreach (var i in this.Items)
                {
                    i.Content = LinkParser.ResolveLinks(i.Content, DynamicLinksParser.GetContentUrl, null, false);
                }
            }
        }
        public ContentBlockModel(string providerName, string content, Guid sharedContentId, Type containerType, string wrapperCssClass)
        {
            this.ContainerType   = containerType;
            this.ProviderName    = providerName;
            this.SharedContentID = sharedContentId;
            this.WrapperCssClass = wrapperCssClass;

            content = this.GetContentHtmlValue(content);

            this.Content = LinkParser.ResolveLinks(
                content,
                DynamicLinksParser.GetContentUrl,
                null,
                SystemManager.IsInlineEditingMode);
        }
Esempio n. 4
0
        public static IHtmlString Raw(this HtmlHelper helper, object html, RawContentResolveType resolveType, string imageViewPath = "/Views/Image/Image.Inline.cshtml", string documentViewPath = "/Views/Document/DocumentLink.Inline.cshtml")
        {
            var content = html.ToString();

            switch (resolveType)
            {
            case RawContentResolveType.Default:
                content = LinkParser.ResolveLinks(html.ToString(), DynamicLinksParser.GetContentUrl, null, false);
                break;

            case RawContentResolveType.Enhanced:
                content = SFSHtml.EnhanceRaw(html.ToString(), imageViewPath, documentViewPath);
                break;
            }

            return(new System.Web.Mvc.MvcHtmlString(content));
        }
Esempio n. 5
0
        private static string EnhanceRaw(string html, string imageViewPath, string documentViewPath)
        {
            //Resolve [OpenAccess provider style links first]
            html = LinkParser.ResolveLinks(html, DynamicLinksParser.GetContentUrl, null, false);

            if (html.Contains(_mediaItemPrefix))
            {
                try
                {
                    var doc = new HtmlDocument();
                    doc.LoadHtml(html);

                    //Parse images
                    var images = doc.DocumentNode.SelectNodes("//img[contains(@src, '" + _mediaItemPrefix + "')]");

                    if (images != null)
                    {
                        foreach (var node in images)
                        {
                            //Find the id
                            var imageRef = new SfImageLink(node.GetAttributeValue("src", "#"), node.GetAttributeValue("title", ""), node.GetAttributeValue("alt", ""));

                            if (imageRef.FoundDataItem())
                            {
                                if (SystemManager.CurrentHttpContext != null)
                                {
                                    var markup  = SFSHtml.GetRazorViewAsString(new ImageController(), imageRef.DataItem, imageViewPath);
                                    var newNode = HtmlNode.CreateNode(markup);

                                    //Reapply all the attributes that were on the original node
                                    foreach (var attribute in node.Attributes.Where(x => x.Name != "src" && x.Name != "title" && x.Name != "alt"))
                                    {
                                        if (newNode.Attributes[attribute.Name] != null)
                                        {
                                            //Merge
                                            var newNodeValue = newNode.GetAttributeValue(attribute.Name, "");
                                            newNode.SetAttributeValue(attribute.Name, newNodeValue + " " + attribute.Value);
                                        }
                                        else
                                        {
                                            //Just add
                                            newNode.SetAttributeValue(attribute.Name, attribute.Value);
                                        }
                                    }

                                    node.ParentNode.ReplaceChild(newNode, node);
                                }
                            }
                        }
                    }

                    //Parse documents
                    var documents = doc.DocumentNode.SelectNodes("//a[contains(@href, '" + _mediaItemPrefix + "')]");
                    if (documents != null)
                    {
                        foreach (var node in documents)
                        {
                            var src = node.GetAttributeValue("href", "#");

                            if (src.Contains("?{0}".Arrange(_mediaItemPrefix)) && src != "#")
                            {
                                //Find the id
                                var docRef = new SfDocLink(src);

                                if (docRef.FoundDataItem())
                                {
                                    var markup  = SFSHtml.GetRazorViewAsString(new DocumentController(), docRef.DataItem, documentViewPath);
                                    var newNode = HtmlNode.CreateNode(markup);


                                    //Reapply all the attributes that were on the original node
                                    foreach (var attribute in node.Attributes.Where(x => x.Name != "src" && x.Name != "href" && x.Name != "title" && x.Name != "alt"))
                                    {
                                        if (newNode.Attributes[attribute.Name] != null)
                                        {
                                            //Merge
                                            var newNodeValue = newNode.GetAttributeValue(attribute.Name, "");
                                            newNode.SetAttributeValue(attribute.Name, newNodeValue + " " + attribute.Value);
                                        }
                                        else
                                        {
                                            //Just add
                                            newNode.SetAttributeValue(attribute.Name, attribute.Value);
                                        }
                                    }

                                    node.ParentNode.ReplaceChild(newNode, node);
                                }
                            }
                        }
                    }

                    //Parse pages

                    /*
                     * var pages = doc.DocumentNode.SelectNodes("//a[starts-with(@href, '/')]);
                     * if (pages != null)
                     * {
                     *  foreach (var node in pages)
                     *  {
                     *      //TODO
                     *  }
                     * }
                     */

                    return(doc.DocumentNode.OuterHtml);
                }
                catch (Exception ex)
                {
                    Telerik.Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Write(ex);
                    //Problem, just show something
                    return(html);
                }
            }
            else
            {
                //No version
                return(html);
            }
        }
Esempio n. 6
0
        public static IHtmlString Raw(object html)
        {
            var content = LinkParser.ResolveLinks(html.ToString(), DynamicLinksParser.GetContentUrl, null, false);

            return(new System.Web.Mvc.MvcHtmlString(content));
        }