Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
        private void CalculateReferencesForPublish()
        {
            //calculate references in the html content
            string postContents = _editingContext.BlogPost.Contents;

            HtmlReferenceFixer.FixReferences(postContents, new ReferenceFixer(AddHtmlReference));
        }
Ejemplo n.º 4
0
        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();
        }
            public void UploadFilesBeforePublish()
            {
                // create a file uploader
                using (BlogFileUploader fileUploader = BlogFileUploader.CreateFileUploader(_blog, _publishingContext.EditingContext.ServerSupportingFileDirectory))
                {
                    // connect to the file uploader
                    fileUploader.Connect();

                    // upload the files and fixup references within the contents of the blog post
                    string htmlContents = _publishingContext.EditingContext.BlogPost.Contents;

                    _referenceFixer = new BlogPostReferenceFixer(htmlContents, _publishingContext);
                    _referenceFixer.Parse();

                    string fixedHtml = HtmlReferenceFixer.FixLocalFileReferences(htmlContents, _referenceFixer.GetFileUploadReferenceFixer(fileUploader));
                    _publishingContext.EditingContext.BlogPost.Contents = fixedHtml;
                }
            }
Ejemplo n.º 6
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);
                    }
                }
            }
        }
 public string[] GetSupportingFilesInPost(string postContents)
 {
     _supportingFileScratchList.Clear();
     HtmlReferenceFixer.FixLocalFileReferences(postContents, new ReferenceFixer(EnumerateLocalFileReference));
     return((string[])_supportingFileScratchList.ToArray(typeof(string)));
 }