Ejemplo n.º 1
0
        public void UpdateContentVersion(int id, int versionId, [FromBody] SiteContentVersion version)
        {
            var content = _cmsService.GetSiteContent(new SiteContentRequest()
            {
                SiteContentID       = version.SiteContentID,
                IncludeProfileTypes = true,
                IncludeAffiliates   = true,
                IncludeVersions     = true
            });

            if (content == null)
            {
                throw new Exception("Invalid Site Content ID");
            }

            if (content.Versions.Any(v => v.VersionName.Equals(version.VersionName, StringComparison.InvariantCultureIgnoreCase) && v.SiteContentVersionID != version.SiteContentVersionID))
            {
                throw new Exception("A version with this name already exists");
            }

            content.Versions.Remove(version);
            content.Versions.Add(version);

            _cmsService.SaveSiteContent(ref content, CurrentUser.UserID);
        }
Ejemplo n.º 2
0
        public SiteContentVersion CreateContentVersion([FromBody] SiteContentVersion version)
        {
            var fetchContent = new Func <SiteContent>(() => _cmsService.GetSiteContent(new SiteContentRequest()
            {
                SiteContentID       = version.SiteContentID,
                IncludeProfileTypes = true,
                IncludeAffiliates   = true,
                IncludeVersions     = true
            }));

            var content = fetchContent();

            if (content == null)
            {
                throw new Exception("Invalid Site Content ID");
            }

            if (content.ContentType != ContentType.ContentPage)
            {
                throw new Exception("Only content page types can have versions");
            }

            if (content.Versions.Any(v => v.VersionName.Equals(version.VersionName, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new Exception("A version with this name already exists");
            }

            content.Versions.Add(version);

            _cmsService.SaveSiteContent(ref content, CurrentUser.UserID);

            return(fetchContent().Versions.First(v => v.VersionName == version.VersionName));
        }
Ejemplo n.º 3
0
        private static ParsedContent ParseContent(SiteContentVersion content, List <SiteContent> contents, int profileTypeId)
        {
            if (content == null || string.IsNullOrWhiteSpace(content.ContentText))
            {
                return(null);
            }

            var parsedContent = new ParsedContent()
            {
                Html    = string.Empty,
                Scripts = string.Empty,
                Styles  = string.Empty
            };

            var doc = new HtmlDocument();

            doc.LoadHtml(content.ContentText);

            foreach (var script in doc.DocumentNode.Descendants("script").ToArray())
            {
                parsedContent.Scripts += script.InnerHtml;
                script.Remove();
            }

            foreach (var style in doc.DocumentNode.Descendants("style").ToArray())
            {
                parsedContent.Styles += style.InnerHtml;
                style.Remove();
            }

            foreach (var link in doc.DocumentNode.Descendants("a").ToArray())
            {
                var href = link.GetAttributeValue("href", string.Empty);

                if (!string.IsNullOrEmpty(href))
                {
                    var linkContent = contents.FindByPermalinkOrUrl(href);

                    if (linkContent != null)
                    {
                        if (linkContent.ProfileTypes.Any() && linkContent.ProfileTypes.All(p => p.ProfileTypeID != profileTypeId))
                        {
                            link.Attributes["href"].Remove();
                            link.SetAttributeValue("class", "disabled");
                        }
                        else if (linkContent.ContentType == ContentType.File && linkContent.Site != null && linkContent.FileInfo != null)
                        {
                            link.SetAttributeValue("data-track", "true");
                            link.SetAttributeValue("data-label", linkContent.Site.SiteName);
                            link.SetAttributeValue("data-value", linkContent.FileInfo.Name);
                        }
                    }
                }
            }

            parsedContent.Html = doc.DocumentNode.InnerHtml;

            return(parsedContent);
        }