示例#1
0
    /// <summary>
    /// Get product Image by Image path
    /// </summary>
    /// <param name="imagepath"></param>
    /// <returns></returns>
    public string GetProductImage(object imagepath)
    {
        string returnValue = string.Empty;

        try
        {
            if (ProductType == (int)ProductsType.PreBuy)
            {
                string folderName = SettingsKeyInfoProvider.GetValue(CurrentSite.SiteName + ".KDA_ImagesFolderName");
                folderName = !string.IsNullOrEmpty(folderName) ? folderName.Replace(" ", "") : "CampaignProducts";
                if (imagepath != null && folderName != null)
                {
                    returnValue = MediaFileURLProvider.GetMediaFileAbsoluteUrl(CurrentSiteName, folderName, ValidationHelper.GetString(imagepath, string.Empty));
                }
            }
            else
            {
                string folderName = SettingsKeyInfoProvider.GetValue(CurrentSite.SiteName + ".KDA_InventoryProductImageFolderName");
                folderName = !string.IsNullOrEmpty(folderName) ? folderName.Replace(" ", "") : "InventoryProducts";
                if (imagepath != null && folderName != null)
                {
                    returnValue = MediaFileURLProvider.GetMediaFileAbsoluteUrl(CurrentSiteName, folderName, ValidationHelper.GetString(imagepath, string.Empty));
                }
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Get Product Image", "GetProductImage", ex, CurrentSite.SiteID, ex.Message);
        }
        return(string.IsNullOrEmpty(returnValue) ? SettingsKeyInfoProvider.GetValue($@"{CurrentSiteName}.KDA_ProductsPlaceHolderImage") : returnValue);
    }
示例#2
0
        public ActionResult Index()
        {
            var properties = GetProperties();
            IEnumerable <Picture> pictures = new List <Picture>();

            switch (properties.Type)
            {
            case Type.Attachments:
                pictures = this.GetPage().Attachments.ToList().Where(a => a.AttachmentImageWidth > 0).Select(a => new Picture
                {
                    Url       = CMS.DocumentEngine.AttachmentURLProvider.GetAttachmentUrl(a.AttachmentName, this.GetPage().NodeAliasPath),
                    AltText   = a.AttachmentTitle,
                    Thumbnail = $"{AttachmentURLProvider.GetAttachmentUrl(a.AttachmentName, this.GetPage().NodeAliasPath)}?maxsidesize=128"
                });
                break;

            case Type.MediaLibraryFolder:
                /*var library = MediaLibraryInfoProvider.GetMediaLibraryInfo(properties.MediaLibraryFolder, this.GetPage().NodeSiteName);
                 * if (string.IsNullOrEmpty(properties.MediaLibraryFolder))
                 * {
                 *  properties.MediaLibraryFolder = "%";
                 * }
                 * var files = MediaFileInfoProvider.GetMediaFiles($"{nameof(MediaFileInfo.FileLibraryID)}={library.LibraryID} AND {nameof(MediaFileInfo.FilePath)} LIKE '{properties.MediaLibrarySubfolder}%'");
                 * pictures = files.ToList().Select(f => new Picture
                 * {
                 *  Url = MediaLibraryHelper.GetMediaFileUrl(f.FileGUID, this.GetPage().NodeSiteName),
                 *  AltText = f.FileTitle,
                 *  Thumbnail = $"{MediaFileURLProvider.GetMediaFileAbsoluteUrl(this.GetPage().NodeSiteName, f.FileGUID, f.FileName)}?maxsidesize=120"
                 * });*/
                if (properties.MediaFiles != null)
                {
                    pictures = properties.MediaFiles.Select(m => new Picture
                    {
                        Url       = MediaLibraryHelper.GetMediaFileUrl(m.FileGuid, this.GetPage().NodeSiteName),
                        AltText   = MediaFileInfoProvider.GetMediaFileInfo(m.FileGuid, this.GetPage().NodeSiteName).FileTitle,
                        Thumbnail = $"{MediaFileURLProvider.GetMediaFileAbsoluteUrl(this.GetPage().NodeSiteName, m.FileGuid, MediaFileInfoProvider.GetMediaFileInfo(m.FileGuid, this.GetPage().NodeSiteName).FileName)}?maxsidesize=128"
                    });
                }
                break;

            case Type.External:
                pictures = properties.External.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Select(f => new Picture
                {
                    Url       = f,
                    AltText   = f,
                    Thumbnail = f
                });
                break;
            }

            var viewModel = new ViewModel
            {
                Pictures = pictures
            };

            return(PartialView("Widgets/_LightboxGallery", viewModel));
        }
示例#3
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    public void ReloadData(bool forceReload)
    {
        if (binded && !forceReload)
        {
            return;
        }

        if (mData != null)
        {
            MediaFileInfo mfi         = new MediaFileInfo(mData);
            SiteInfo      currentSite = SiteContext.CurrentSite;

            SiteInfo si = mfi.FileSiteID == currentSite.SiteID ? currentSite : SiteInfo.Provider.Get(mfi.FileSiteID);
            if (si != null)
            {
                if (DisplayActiveContent)
                {
                    string url = "";

                    // Complete URL only for other site than current
                    bool completeUrl = (si.SiteID != currentSite.SiteID);

                    if (UseSecureLinks)
                    {
                        string fileName = AttachmentHelper.GetFullFileName(mfi.FileName, mfi.FileExtension);

                        url = completeUrl
                            ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, fileName)
                            : MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, fileName);
                    }
                    else
                    {
                        MediaLibraryInfo li = MediaLibraryInfo.Provider.Get(mfi.FileLibraryID);
                        if (li != null)
                        {
                            url = completeUrl
                                ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, li.LibraryFolder, mfi.FilePath)
                                : MediaFileURLProvider.GetMediaFileUrl(si.SiteName, li.LibraryFolder, mfi.FilePath);
                        }
                    }

                    url = UrlResolver.ResolveUrl(url);

                    if (ImageHelper.IsImage(mfi.FileExtension) && File.Exists(MediaFileInfoProvider.GetMediaFilePath(mfi.FileLibraryID, mfi.FilePath)))
                    {
                        // Get new dimensions
                        int[] newDims = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, mfi.FileImageWidth, mfi.FileImageHeight);

                        // If dimensions changed use secure link
                        if ((newDims[0] != mfi.FileImageWidth) || (newDims[1] != mfi.FileImageHeight))
                        {
                            string fileName = AttachmentHelper.GetFullFileName(mfi.FileName, mfi.FileExtension);

                            url = completeUrl
                                ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, fileName)
                                : MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, fileName);

                            url = UrlResolver.ResolveUrl(url);
                        }
                        else
                        {
                            // Use width and height from properties in case dimensions are bigger than original
                            newDims[0] = Width;
                            newDims[1] = Height;
                        }

                        // Initialize image parameters
                        ImageParameters imgParams = new ImageParameters();
                        imgParams.Alt    = mfi.FileDescription;
                        imgParams.Width  = newDims[0];
                        imgParams.Height = newDims[1];
                        imgParams.Url    = url;

                        ltlOutput.Text = MediaHelper.GetImage(imgParams);
                    }
                    else if (MediaHelper.IsAudioVideo(mfi.FileExtension))
                    {
                        // Initialize audio/video parameters
                        AudioVideoParameters audioVideoParams = new AudioVideoParameters();

                        audioVideoParams.SiteName  = SiteContext.CurrentSiteName;
                        audioVideoParams.Url       = url;
                        audioVideoParams.Width     = Width;
                        audioVideoParams.Height    = Height;
                        audioVideoParams.Extension = mfi.FileExtension;

                        ltlOutput.Text = MediaHelper.GetAudioVideo(audioVideoParams);
                    }
                    else
                    {
                        ltlOutput.Text = ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page);
                    }
                }
                else
                {
                    ltlOutput.Text = ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page);
                }
            }
        }
        binded = true;
    }
    /// <summary>
    /// Returns URL of the media item according site settings.
    /// </summary>
    /// <param name="fileInfo">File info object</param>
    /// <param name="site">Information on site file belongs to</param>
    /// <param name="fileGuid">GUID of the file URL is generated for</param>
    /// <param name="fileName">Name of the file URL is generated for</param>
    /// <param name="fileExtension">Extension of the file URL is generated for</param>
    /// <param name="filePath">Media file path of the file URL is generated for</param>
    /// <param name="isPreview">Indicates whether the file URL is generated for preview</param>
    /// <param name="height">Specifies height of the image</param>
    /// <param name="width">Specifies width of the image</param>
    /// <param name="maxSideSize">Maximum dimension for images displayed for thumbnails view</param>
    public string GetItemUrl(MediaFileInfo fileInfo, SiteInfo site, Guid fileGuid, string fileName, string fileExtension, string filePath, bool isPreview, int height, int width, int maxSideSize)
    {
        string mediaFileUrl;
        bool   resize = (maxSideSize > 0);

        fileName = AttachmentHelper.GetFullFileName(fileName, fileExtension);

        bool generateAbsoluteURL = Config?.UseFullURL ?? false;

        generateAbsoluteURL = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseMediaFileAbsoluteURLs"], generateAbsoluteURL);
        bool isDifferentSite = false;

        if (generateAbsoluteURL || (isDifferentSite = IsLibrarySiteDifferentThanCurrentSite()))
        {
            if (site.SiteIsContentOnly && isDifferentSite)
            {
                mediaFileUrl = UsePermanentUrls ? MediaFileURLProvider.GetMediaFileUrl(fileGuid, fileName) : MediaFileURLProvider.GetMediaFileUrl(site.SiteName, LibraryInfo.LibraryFolder, filePath);
                mediaFileUrl = URLHelper.CombinePath(mediaFileUrl, '/', site.SitePresentationURL, null);
            }
            else if (UsePermanentUrls || resize || isPreview)  // If permanent URLs should be generated
            {
                // URL in format 'http://domainame/getmedia/123456-25245-45454-45455-5455555545/testfile.gif'
                mediaFileUrl = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, fileGuid, fileName);
            }
            else
            {
                // URL in format 'http://domainame/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif'
                mediaFileUrl = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, LibraryInfo.LibraryFolder, filePath);
            }
        }
        else
        {
            if (UsePermanentUrls || resize || isPreview)
            {
                // URL in format '/cms/getmedia/123456-25245-45454-45455-5455555545/testfile.gif'
                mediaFileUrl = MediaFileURLProvider.GetMediaFileUrl(fileGuid, fileName);
            }
            else
            {
                if (fileInfo != null)
                {
                    mediaFileUrl = MediaFileURLProvider.GetMediaFileUrl(fileInfo, SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder);
                }
                else
                {
                    // URL in format '/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif'
                    mediaFileUrl = MediaFileURLProvider.GetMediaFileUrl(SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder, filePath);
                }
            }
        }

        // If image dimensions are specified
        if (resize)
        {
            mediaFileUrl = URLHelper.AddParameterToUrl(mediaFileUrl, "maxsidesize", maxSideSize.ToString());
        }
        if (height > 0)
        {
            mediaFileUrl = URLHelper.AddParameterToUrl(mediaFileUrl, "height", height.ToString());
        }
        if (width > 0)
        {
            mediaFileUrl = URLHelper.AddParameterToUrl(mediaFileUrl, "width", width.ToString());
        }

        // Media selector should returns non-resolved URL in all cases
        bool isMediaSelector = (OutputFormat == OutputFormatEnum.URL) && (SelectableContent == SelectableContentEnum.OnlyMedia);

        return((isMediaSelector || ((Config != null) && Config.ContentUseRelativeUrl)) ? mediaFileUrl : UrlResolver.ResolveUrl(mediaFileUrl));
    }
    /// <summary>
    /// Returns URL of the media item according site settings.
    /// </summary>
    /// <param name="site">Information on site file belongs to</param>
    /// <param name="fileGuid">GUID of the file URL is generated for</param>
    /// <param name="fileName">Name of the file URL is generated for</param>
    /// <param name="filePath">Media file path of the file URL is generated for</param>
    /// <param name="isPreview">Indicates whether the file URL is generated for preview</param>
    /// <param name="maxSideSize">Maximum dimension for images displayed for tile and thumbnails view</param>
    public string GetItemUrl(MediaFileInfo fileInfo, SiteInfo site, Guid fileGuid, string fileName, string fileExtension, string filePath, bool isPreview, int height, int width, int maxSideSize)
    {
        string result = "";
        bool   resize = (maxSideSize > 0);

        fileName = UsePermanentUrls ? AttachmentHelper.GetFullFileName(fileName, fileExtension) : fileName;

        bool generateFullURL = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseMediaFileAbsoluteURLs"], false);

        if ((Config != null) && (Config.UseFullURL || generateFullURL || (CMSContext.CurrentSiteID != LibraryInfo.LibrarySiteID) || (CMSContext.CurrentSiteID != GetCurrentSiteId())))
        {
            // If permanent URLs should be generated
            if (UsePermanentUrls || resize || isPreview)
            {
                // URL in format 'http://domainame/getmedia/123456-25245-45454-45455-5455555545/testfile.gif'
                result = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, fileGuid, fileName);
            }
            else
            {
                // URL in format 'http://domainame/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif'
                result = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, LibraryInfo.LibraryFolder, filePath);
            }
        }
        else
        {
            if (UsePermanentUrls || resize || isPreview)
            {
                // URL in format '/cms/getmedia/123456-25245-45454-45455-5455555545/testfile.gif'
                result = MediaFileURLProvider.GetMediaFileUrl(fileGuid, fileName);
            }
            else
            {
                if (fileInfo != null)
                {
                    result = MediaFileURLProvider.GetMediaFileUrl(fileInfo, CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder);
                }
                else
                {
                    // URL in format '/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif'
                    result = MediaFileURLProvider.GetMediaFileUrl(CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder, filePath);
                }
            }
        }

        // If image dimensions are specified
        if (resize)
        {
            result = URLHelper.AddParameterToUrl(result, "maxsidesize", maxSideSize.ToString());
        }
        if (height > 0)
        {
            result = URLHelper.AddParameterToUrl(result, "height", height.ToString());
        }
        if (width > 0)
        {
            result = URLHelper.AddParameterToUrl(result, "width", width.ToString());
        }

        // Media selctor should returns non-resolved URL in all cases
        bool isMediaSelector = (OutputFormat == OutputFormatEnum.URL) && (SelectableContent == SelectableContentEnum.OnlyMedia);

        return(isMediaSelector ? result : URLHelper.ResolveUrl(result, true, false));
    }
示例#6
0
    /// <summary>
    /// UniGrid external data bound.
    /// </summary>
    protected object GridOnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "update":
            PlaceHolder plcUpd = new PlaceHolder();
            plcUpd.ID = "plcUdateAction";

            // Dynamically load uploader control
            DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader;

            // Set uploader's properties
            if (dfuElem != null)
            {
                dfuElem.ID                = "dfuElem" + LibraryID;
                dfuElem.DisplayInline     = true;
                dfuElem.SourceType        = MediaSourceEnum.MediaLibraries;
                dfuElem.MediaFileID       = MediaFileID;
                dfuElem.LibraryID         = LibraryID;
                dfuElem.LibraryFolderPath = LibraryFolderPath;
                dfuElem.ParentElemID      = ClientID;
                dfuElem.IsMediaThumbnail  = IsMediaThumbnail;
                dfuElem.ShowIconMode      = true;
                dfuElem.InsertMode        = false;
                dfuElem.ForceLoad         = true;
                dfuElem.IsLiveSite        = IsLiveSite;
                // New settings added
                dfuElem.UploadMode        = MultifileUploaderModeEnum.DirectSingle;
                dfuElem.Height            = 16;
                dfuElem.Width             = 16;
                dfuElem.MaxNumberToUpload = 1;

                if (Enabled && EnableUpdate)
                {
                    dfuElem.Enabled = true;
                }
                else
                {
                    dfuElem.Enabled = false;
                }

                plcUpd.Controls.Add(dfuElem);
            }
            return(plcUpd);

        case "edit":
            // Get file extension
            if ((FileInfo != null) && (LibraryInfo != null))
            {
                var editButton = (CMSGridActionButton)sender;

                if (AuthenticationHelper.IsAuthenticated())
                {
                    string fileExt = (IsMediaThumbnail ? previewExt : FileInfo.FileExtension);

                    // If the file is not an image don't allow image editing
                    if (!ImageHelper.IsSupportedByImageEditor(fileExt) || !Enabled)
                    {
                        // Disable edit icon in case that attachment is not an image
                        editButton.Enabled = false;
                    }
                    else
                    {
                        string query = string.Format("?refresh=1&siteid={0}&MediaFileGUID={1}{2}", LibraryInfo.LibrarySiteID, FileInfo.FileGUID, (IsMediaThumbnail ? "&isPreview=1" : ""));
                        query = URLHelper.AddUrlParameter(query, "hash", QueryHelper.GetHash(query));
                        editButton.OnClientClick = "EditThumbnailImage('" + query + "'); return false;";
                    }
                    editButton.ToolTip = GetString("general.edit");
                }
                else
                {
                    editButton.Visible = false;
                }
            }
            break;

        case "delete":
            var deleteButton = (CMSGridActionButton)sender;

            if (!Enabled)
            {
                // Disable delete icon in case that editing is not allowed
                deleteButton.Enabled = false;
            }

            break;

        case "filename":
            if ((LibraryInfo != null) && (FileInfo != null))
            {
                string fileUrl  = "";
                string fileExt  = "";
                string fileName = "";

                // Get file extension
                if (IsMediaThumbnail)
                {
                    fileName = previewName;
                    fileExt  = previewExt;
                    fileUrl  = ResolveUrl("~/CMSPages/GetMediaFile.aspx?preview=1&fileguid=" + FileInfo.FileGUID);
                }
                else
                {
                    fileExt  = FileInfo.FileExtension;
                    fileName = FileInfo.FileName;
                    fileUrl  = MediaFileURLProvider.GetMediaFileAbsoluteUrl(FileInfo.FileGUID, AttachmentHelper.GetFullFileName(FileInfo.FileName, FileInfo.FileExtension));
                }
                fileUrl = URLHelper.UpdateParameterInUrl(fileUrl, "chset", Guid.NewGuid().ToString());

                string tooltip = null;
                string iconTag = UIHelper.GetFileIcon(Page, fileExt, tooltip: fileName);
                bool   isImage = ImageHelper.IsImage(fileExt);

                if (isImage)
                {
                    tooltip = "";

                    if (File.Exists(previewPath))
                    {
                        FileStream file = FileStream.New(previewPath, FileMode.Open, FileAccess.Read);
                        Image      img  = Image.FromStream(file);
                        file.Close();
                        if (img != null)
                        {
                            int[]  imgDims = ImageHelper.EnsureImageDimensions(0, 0, 150, img.Width, img.Height);
                            string setRTL  = (CultureHelper.IsUICultureRTL() ? ", LEFT, true" : "");
                            tooltip = "onmouseout=\"UnTip()\" onmouseover=\"Tip('<div style=\\'width:" + imgDims[0] + "px; text-align:center;\\'><img src=\\'" + URLHelper.AddParameterToUrl(fileUrl, "maxsidesize", "150") + "\\' alt=\\'" + fileName + "\\' /></div>'" + setRTL + ")\"";

                            // Dispose image
                            img.Dispose();
                        }
                    }
                }

                if (isImage)
                {
                    return("<a href=\"#\" onclick=\"javascript: window.open('" + fileUrl + "'); return false;\" class=\"cms-icon-link\"><span " + tooltip + ">" + iconTag + fileName + "</span></a>");
                }
                else
                {
                    return("<a href=\"" + fileUrl + "\" class=\"cms-icon-link\">" + iconTag + fileName + "</a>");
                }
            }

            return("");

        case "filesize":
            return(DataHelper.GetSizeString(ValidationHelper.GetLong(parameter, 0)));
        }

        return(parameter);
    }