Exemple #1
0
        /// <summary>
        /// Iterates through the provided HTML and fixes up image URLs.
        /// </summary>
        /// <param name="html">The HTML to iterate through.</param>
        /// <param name="sourceUrl">The source URL that the HTML originated from.</param>
        /// <returns>The fixed up HTML.</returns>
        public string FixImageReferences(string html, string sourceUrl)
        {
            if (html == null)
            {
                throw new ArgumentNullException("html");
            }

            if (sourceUrl == null)
            {
                throw new ArgumentNullException("sourceUrl");
            }

            StringBuilder sb = new StringBuilder();

            using (StringWriter writer = new StringWriter(sb, CultureInfo.InvariantCulture))
            {
                if (HtmlHandler.IsSharedCanvasTempUrl(sourceUrl))
                {
                    HtmlReferenceFixer fixer = new HtmlReferenceFixer(html);
                    fixer.FixReferences(writer, _internalReferenceFixer, null);
                }
                else
                {
                    return(html);
                }
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Iterates through the provided HTML and fixes up image URLs.
        /// </summary>
        /// <param name="html">The HTML to iterate through.</param>
        /// <param name="sourceUrl">The source URL that the HTML originated from.</param>
        /// <returns>The fixed up HTML.</returns>
        public string FixImageReferences(string html, string sourceUrl)
        {
            if (html == null)
            {
                throw new ArgumentNullException("html");
            }

            if (sourceUrl == null)
            {
                throw new ArgumentNullException("sourceUrl");
            }

            StringBuilder sb = new StringBuilder();
            using (StringWriter writer = new StringWriter(sb, CultureInfo.InvariantCulture))
            {
                if (HtmlHandler.IsSharedCanvasTempUrl(sourceUrl))
                {
                    HtmlReferenceFixer fixer = new HtmlReferenceFixer(html);
                    fixer.FixReferences(writer, _internalReferenceFixer, null);
                }
                else
                {
                    return html;
                }
            }

            return sb.ToString();
        }
Exemple #3
0
        private void CalculateReferencesForPublish()
        {
            //calculate references in the html content
            string postContents = _editingContext.BlogPost.Contents;

            HtmlReferenceFixer.FixReferences(postContents, new ReferenceFixer(AddHtmlReference));
        }
        private static void ConvertImageReferencesToLocal(IBlogPostEditingContext editingContext)
        {
            ImageReferenceFixer refFixer = new ImageReferenceFixer(editingContext.ImageDataList, editingContext.BlogId);

            // Create a text writer that the new html will be written to
            TextWriter htmlWriter = new StringWriter(CultureInfo.InvariantCulture);
            // Check an html image fixer that will find references and rewrite them to new paths
            HtmlReferenceFixer referenceFixer = new HtmlReferenceFixer(editingContext.BlogPost.Contents);
            // We need to update the editing context when we change an image
            ContextImageReferenceFixer contextFixer = new ContextImageReferenceFixer(editingContext);

            // Do the fixing
            referenceFixer.FixReferences(htmlWriter, new ReferenceFixer(refFixer.FixImageReferences), contextFixer.ReferenceFixedCallback);
            // Write back the new html
            editingContext.BlogPost.Contents = htmlWriter.ToString();
        }
Exemple #5
0
        private void CalculateReferencesForSave()
        {
            //calculate references in the html content
            string postContents = _editingContext.BlogPost.Contents;

            HtmlReferenceFixer.FixReferences(postContents, new ReferenceFixer(AddHtmlReference));

            //calculate the images referenced by the HTML
            AddImageReferences(_editingContext.ImageDataList);

            //calculate files referenced by plugins
            foreach (BlogPostExtensionData extensionData in _editingContext.ExtensionDataList.CalculateReferencedExtensionData(postContents))
            {
                foreach (string fileId in extensionData.FileIds)
                {
                    ISupportingFile file = extensionData.GetSupportingFile(fileId);
                    if (file != null)
                    {
                        AddReference(file);
                    }
                }
            }
        }