コード例 #1
0
        private PhotoInstance?GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType[] photoTypes)
        {
            IEnumerator <photo> phEn = ni.photos.GetEnumerator();

            if (!phEn.MoveNext())
            {
                return(null);
            }

            PhotoInstance phIns = new PhotoInstance();
            bool          found = false;
            photo         ph    = phEn.Current;
            IEnumerator <photo.Instance> phIEn = ph.Instances.GetEnumerator();

            while (phIEn.MoveNext())
            {
                foreach (enumeratedTypes.enumPhotoInstanceType phType in photoTypes)
                {
                    if (phIEn.Current.type == phType)
                    {
                        phIns.Width  = phIEn.Current.width;
                        phIns.Height = phIEn.Current.height;
                        phIns.Url    = phIEn.Current.url;
                        phIns.Type   = phIEn.Current.type;
                        phIns.Type   = phType;

                        string cleanedUrl = phIns.Url;
                        if (cleanedUrl.IndexOf('?') >= 0)
                        {
                            cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?'));
                        }

                        string phTypeSlug = Slugify(phType);
                        phIns.DestinationFileName = Slugify(ni.headline) + (phTypeSlug == "" ? "" : "-" + phTypeSlug) + Path.GetExtension(cleanedUrl);

                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    phIns.AltText     = phEn.Current.htmlAlt;
                    phIns.Caption     = phEn.Current.caption;
                    phIns.Id          = phEn.Current.id;
                    phIns.Orientation = phEn.Current.orientation;

                    break;
                }
            }

            if (!found)
            {
                return(null);
            }
            return(phIns);
        }
コード例 #2
0
        private PhotoInstance?GetPhotoInstance(AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle article, AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotosClient photos, AdferoVideoDotNet.AdferoPhotos.AdferoPhotoClient photoClient, string scaleAxis, int scale)
        {
            PhotoInstance?inst = null;

            AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotoList photoList = photos.ListForArticle(article.Id, 0, 100);
            if (photoList.TotalCount > 0)
            {
                AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhoto apho = photos.Get(photoList.Items[0].Id);
                int photoId = apho.SourcePhotoId;
                AdferoVideoDotNet.AdferoPhotos.Photos.AdferoPhoto pho = photoClient.Photos().GetScaleLocationUrl(photoId, scaleAxis, scale);
                string photoUrl     = pho.LocationUri;
                string photoCaption = photos.Get(photoList.Items[0].Id).Fields["caption"];

                enumeratedTypes.enumPhotoOrientation ori = enumeratedTypes.enumPhotoOrientation.Landscape;
                if (scaleAxis == AdferoVideoDotNet.AdferoPhotos.Photos.AdferoScaleAxis.Y)
                {
                    ori = enumeratedTypes.enumPhotoOrientation.Portrait;
                }

                string cleanedUrl = photoUrl;
                if (cleanedUrl.IndexOf('?') >= 0)
                {
                    cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?'));
                }

                inst = new PhotoInstance()
                {
                    AltText             = photoCaption,
                    Caption             = photoCaption,
                    DestinationFileName = Slugify(article.Fields["title"]) + "-" + scale + Path.GetExtension(cleanedUrl),
                    Height      = 0,
                    Id          = apho.Id,
                    Orientation = ori,
                    Type        = enumeratedTypes.enumPhotoInstanceType.Custom,
                    Url         = photoUrl,
                    Width       = 0
                };
            }

            return(inst);
        }
コード例 #3
0
        private string AppendImageToContent(PhotoInstance photoInstance, string virtualPath, string content, string cssClass, string imageLink, bool useCaption)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("<div class=\"{0}\">", cssClass));
            if (!string.IsNullOrEmpty(imageLink))
            {
                sb.Append(string.Format("<a href=\"{0}\">", imageLink));
            }
            sb.Append(string.Format("<img src=\"{0}\" alt=\"{1}\" />", virtualPath, photoInstance.AltText));
            if (!string.IsNullOrEmpty(imageLink))
            {
                sb.Append("</a>");
            }
            if (useCaption)
            {
                sb.Append(string.Format("<span class=\"caption\">{0}</span>", photoInstance.Caption));
            }
            sb.Append("</div>");
            sb.Append(content);

            return(sb.ToString());
        }
コード例 #4
0
 private string AppendImageToContent(PhotoInstance photoInstance, string virtualPath, string content, string cssClass)
 {
     return(AppendImageToContent(photoInstance, virtualPath, content, cssClass, "", false));
 }
コード例 #5
0
        private void ImportPhotos(Post p, PhotoInstance? thumbnail, PhotoInstance? fullSizePhoto)
        {
            if (thumbnail != null || fullSizePhoto != null)
            {
                string thumbnailPath = string.Empty;
                string fullSizePhotoPath = string.Empty;
                int photoImportCount = 0;

                string physicalPicsPath = HttpContext.Current.Server.MapPath(Path.Combine(Blog.CurrentInstance.VirtualPath, "pics"));
                string fullSizePhysicalPath = string.Empty;
                string thumbnailPhysicalPath = string.Empty;
                string webrootUri = global::BlogEngine.Core.Blog.CurrentInstance.AbsoluteWebRoot.ToString();
                string webrootAuthorityUri = global::BlogEngine.Core.Blog.CurrentInstance.AbsoluteWebRootAuthority.ToString();
                string picsUri = webrootUri.Substring(webrootUri.IndexOf(webrootAuthorityUri) + webrootAuthorityUri.Length) + "pics/";

                if (fullSizePhoto != null && ImportPhoto(fullSizePhoto, physicalPicsPath, out fullSizePhysicalPath, out fullSizePhotoPath))
                {
                    photoImportCount++;
                    p.Content = AppendImageToContent(fullSizePhoto.Value, picsUri + fullSizePhotoPath, p.Content, "article-img-frame", "", true);
                }

                if (thumbnail != null && ImportPhoto(thumbnail, physicalPicsPath, out thumbnailPhysicalPath, out thumbnailPath))
                {
                    photoImportCount++;
                    p.Description = AppendImageToContent(thumbnail.Value, picsUri + thumbnailPath, p.Description, "article-thumbnail-frame");
                }

                if (photoImportCount > 0)
                    Log(string.Format("Imported {0} photo{1}.", photoImportCount, (photoImportCount != 1 ? "s" : "")), LogLevel.Info);
                else
                    Log("Warning: could not import any photos.", LogLevel.Warning);
            }
        }
コード例 #6
0
        private bool ImportPhoto(PhotoInstance? photoInstance, string picsPath, out string physicalPhotoPath, out string photoPath)
        {
            string filename = photoInstance.Value.DestinationFileName;
            string physicalPath = Path.Combine(picsPath, filename);
            using (WebClient wc = new WebClient())
            {
                try
                {
                    wc.DownloadFile(photoInstance.Value.Url, physicalPath);
                }
                catch (Exception ex)
                {
                    Log(string.Format("Error: Could not import photo '{0}': {1}", photoInstance.Value.Url, ex.Message), LogLevel.Error);
                    physicalPhotoPath = string.Empty;
                    photoPath = string.Empty;
                    return false;
                }
            }

            physicalPhotoPath = physicalPath;
            photoPath = filename;
            return true;
        }
コード例 #7
0
        private PhotoInstance? GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType[] photoTypes)
        {
            IEnumerator<photo> phEn = ni.photos.GetEnumerator();
            if (!phEn.MoveNext())
                return null;

            PhotoInstance phIns = new PhotoInstance();
            bool found = false;
            photo ph = phEn.Current;
            IEnumerator<photo.Instance> phIEn = ph.Instances.GetEnumerator();
            while (phIEn.MoveNext())
            {
                foreach (enumeratedTypes.enumPhotoInstanceType phType in photoTypes)
                {
                    if (phIEn.Current.type == phType)
                    {
                        phIns.Width = phIEn.Current.width;
                        phIns.Height = phIEn.Current.height;
                        phIns.Url = phIEn.Current.url;
                        phIns.Type = phIEn.Current.type;
                        phIns.Type = phType;

                        string cleanedUrl = phIns.Url;
                        if (cleanedUrl.IndexOf('?') >= 0)
                            cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?'));

                        string phTypeSlug = Slugify(phType);
                        phIns.DestinationFileName = Slugify(ni.headline) + (phTypeSlug == "" ? "" : "-" + phTypeSlug) + Path.GetExtension(cleanedUrl);

                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    phIns.AltText = phEn.Current.htmlAlt;
                    phIns.Caption = phEn.Current.caption;
                    phIns.Id = phEn.Current.id;
                    phIns.Orientation = phEn.Current.orientation;

                    break;
                }
            }

            if (!found)
                return null;
            return phIns;
        }
コード例 #8
0
        private PhotoInstance? GetPhotoInstance(AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle article, AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotosClient photos, AdferoVideoDotNet.AdferoPhotos.AdferoPhotoClient photoClient, string scaleAxis, int scale)
        {
            PhotoInstance? inst = null;

            AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotoList photoList = photos.ListForArticle(article.Id, 0, 100);
            if (photoList.TotalCount > 0)
            {
                AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhoto apho = photos.Get(photoList.Items[0].Id);
                int photoId = apho.SourcePhotoId;
                AdferoVideoDotNet.AdferoPhotos.Photos.AdferoPhoto pho = photoClient.Photos().GetScaleLocationUrl(photoId, scaleAxis, scale);
                string photoUrl = pho.LocationUri;
                string photoCaption = photos.Get(photoList.Items[0].Id).Fields["caption"];

                enumeratedTypes.enumPhotoOrientation ori = enumeratedTypes.enumPhotoOrientation.Landscape;
                if (scaleAxis == AdferoVideoDotNet.AdferoPhotos.Photos.AdferoScaleAxis.Y)
                    ori = enumeratedTypes.enumPhotoOrientation.Portrait;

                string cleanedUrl = photoUrl;
                if (cleanedUrl.IndexOf('?') >= 0)
                    cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?'));

                inst = new PhotoInstance()
                {
                    AltText = photoCaption,
                    Caption = photoCaption,
                    DestinationFileName = Slugify(article.Fields["title"]) + "-" + scale + Path.GetExtension(cleanedUrl),
                    Height = 0,
                    Id = apho.Id,
                    Orientation = ori,
                    Type = enumeratedTypes.enumPhotoInstanceType.Custom,
                    Url = photoUrl,
                    Width = 0
                };
            }

            return inst;
        }
コード例 #9
0
 private string AppendImageToContent(PhotoInstance photoInstance, string virtualPath, string content, string cssClass)
 {
     return AppendImageToContent(photoInstance, virtualPath, content, cssClass, "", false);
 }
コード例 #10
0
        private string AppendImageToContent(PhotoInstance photoInstance, string virtualPath, string content, string cssClass, string imageLink, bool useCaption)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("<div class=\"{0}\">", cssClass));
            if (!string.IsNullOrEmpty(imageLink))
                sb.Append(string.Format("<a href=\"{0}\">", imageLink));
            sb.Append(string.Format("<img src=\"{0}\" alt=\"{1}\" />", virtualPath, photoInstance.AltText));
            if (!string.IsNullOrEmpty(imageLink))
                sb.Append("</a>");
            if (useCaption)
                sb.Append(string.Format("<span class=\"caption\">{0}</span>", photoInstance.Caption));
            sb.Append("</div>");
            sb.Append(content);

            return sb.ToString();
        }