예제 #1
0
        private HtmlBlobSet GetHtmlBlobSet(string img)
        {
            string imageBlobIdText          = _stringUtilities.GetXmlAttributeValue(img, "data-image-blob-id");
            string previewImageBlobIdText   = _stringUtilities.GetXmlAttributeValue(img, "data-preview-image-blob-id");
            string thumbnailImageBlobIdText = _stringUtilities.GetXmlAttributeValue(img, "data-thumbnail-image-blob-id");

            if (imageBlobIdText == null || previewImageBlobIdText == null || thumbnailImageBlobIdText == null)
            {
                return(null);
            }

            long imageBlobId;
            long previewImageBlobId;
            long thumbnailImageBlobId;
            bool parsedImageBlobId          = long.TryParse(imageBlobIdText, out imageBlobId);
            bool parsedPreviewImageBlobId   = long.TryParse(previewImageBlobIdText, out previewImageBlobId);
            bool parsedThumbnailImageBlobId = long.TryParse(thumbnailImageBlobIdText, out thumbnailImageBlobId);

            if (!parsedImageBlobId || !parsedPreviewImageBlobId || !parsedThumbnailImageBlobId)
            {
                return(null);
            }

            return(new HtmlBlobSet
            {
                ImageBlobId = imageBlobId,
                PreviewImageBlobId = previewImageBlobId,
                ThumbnailImageBlobId = thumbnailImageBlobId
            });
        }
예제 #2
0
            public string EnsureCommittedUrl(string img)
            {
                // If we have an uncommitted URL, will have full set of data attributes
                string imageBlobIdText          = _stringUtilities.GetXmlAttributeValue(img, "data-image-blob-id");
                string previewImageBlobIdText   = _stringUtilities.GetXmlAttributeValue(img, "data-preview-image-blob-id");
                string thumbnailImageBlobIdText = _stringUtilities.GetXmlAttributeValue(img, "data-thumbnail-image-blob-id");

                if (imageBlobIdText == null || previewImageBlobIdText == null || thumbnailImageBlobIdText == null)
                {
                    return(img); // Make no changes if not uncommitted URL
                }
                // Get preview image blob identifier
                long previewImageBlobId;

                if (!long.TryParse(previewImageBlobIdText, out previewImageBlobId))
                {
                    return(img); // Make no changes if not uncommitted URL
                }
                // Make no changes if we can't find blob set identifier
                if (!_blobSetIdsByPreviewImageBlobId.ContainsKey(previewImageBlobId))
                {
                    return(img);
                }
                long blobSetId = _blobSetIdsByPreviewImageBlobId[previewImageBlobId];

                // Get width, height and alt attributes if specified
                string width  = _stringUtilities.GetXmlAttributeValue(img, "width");
                string height = _stringUtilities.GetXmlAttributeValue(img, "height");
                string alt    = _stringUtilities.GetXmlAttributeValue(img, "alt");

                // Get width, height and alt if not specified
                width  = width ?? _previewImagesByBlobSetId[blobSetId].Width.ToString();
                height = height ?? _previewImagesByBlobSetId[blobSetId].Height.ToString();
                alt    = alt ?? _previewImagesByBlobSetId[blobSetId].Name;

                // Finally, return new committed URL
                string newUrl = $"/elementtypes/c92ee4c4-b133-44cc-8322-640e99c334dc/elements/{_elementId}/blobsets/{blobSetId}/content";

                return($"<img src=\"{newUrl}\" width=\"{width}\" height=\"{height}\" alt=\"{alt}\" />");
            }