File: D:/HostingSpaces/TDijk1/erp-apps.eu/wwwroot/CMSWebParts/Pux/Media/ImageEngine.ascx.cs
using CMS.Controls;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.PortalControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CMSWebParts_Pux_Media_ImageEngine : CMSAbstractWebPart
{
/// <summary>
/// Type rendered element (img, div, a) => string
/// </summary>
/// <value>img</value>
public string Type
{
get
{
return ValidationHelper.GetString(GetValue("Type"), "img");
}
set
{
SetValue("Type", value);
}
}
/// <summary>
/// Enable lazy load => bool
/// </summary>
/// <value>false</value>
public bool LazyLoad
{
get
{
return ValidationHelper.GetBoolean(GetValue("LazyLoad"), false);
}
set
{
SetValue("LazyLoad", value);
}
}
/// <summary>
/// Custom CSS class => string
/// </summary>
/// <value></value>
public string Css
{
get
{
return ValidationHelper.GetString(GetValue("Css"), "");
}
set
{
SetValue("Css", value);
}
}
/// <summary>
/// Alt for image => string
/// </summary>
/// <value></value>
public string Alt
{
get
{
return ValidationHelper.GetString(GetValue("Alt"), "");
}
set
{
SetValue("Alt", value);
}
}
/// <summary>
/// Src file for lazy load => string
/// </summary>
/// <value>data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==</value>
public string SrcLazyLoad
{
get
{
return ValidationHelper.GetString(GetValue("SrcLazyLoad"), "/" + CurrentSiteName + "/media/system/img/blank.gif");//"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==");
}
set
{
SetValue("SrcLazyLoad", value);
}
}
/// <summary>
/// Image src from media library or file system => string
/// </summary>
/// <value></value>
public string DataSrcLibrary
{
get
{
return ValidationHelper.GetString(GetValue("DataSrcLibrary"), "");
}
set
{
SetValue("DataSrcLibrary", value);
}
}
/// <summary>
/// Image src from file uplouad => Guid
/// </summary>
/// <value>Guid.Empty</value>
public Guid DataSrcFile
{
get
{
return ValidationHelper.GetGuid(GetValue("DataSrcFile"), Guid.Empty);
}
set
{
SetValue("DataSrcFile", value);
}
}
/// <summary>
/// Image src if DataSrcLibrary and DataSrcFile is empty
/// </summary>
/// <value>"/"+CurrentSiteName+"/media/system/img/empty.png"</value>
public string SrcEmpty
{
get
{
return ValidationHelper.GetString(GetValue("SrcEmpty"), "/"+CurrentSiteName+"/media/system/img/empty.png");
}
set
{
SetValue("SrcEmpty", value);
}
}
/// <summary>
/// Href attribute for type="a"
/// </summary>
/// <value></value>
public string Href
{
get
{
return ValidationHelper.GetString(GetValue("Href"), "");
}
set
{
SetValue("Href", value);
}
}
/// <summary>
/// maxsidesize for image
/// </summary>
/// <value>0</value>
public int Maxsidesize
{
get
{
return ValidationHelper.GetInteger(GetValue("Maxsidesize"), 0);
}
set
{
SetValue("Maxsidesize", value);
}
}
/// <summary>
/// width for image
/// </summary>
/// <value>0</value>
public int Width
{
get
{
return ValidationHelper.GetInteger(GetValue("Width"), 0);
}
set
{
SetValue("Width", value);
}
}
/// <summary>
/// height for image
/// </summary>
/// <value>0</value>
public int Height
{
get
{
return ValidationHelper.GetInteger(GetValue("Height"), 0);
}
set
{
SetValue("Height", value);
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
string imageFile = "";
imageFile = TransformationHelper.HelperObject.GetFileUrl(DataSrcFile, null);
string imageSrc = String.IsNullOrEmpty(DataSrcLibrary) ? (DataSrcFile == Guid.Empty) ? SrcEmpty : imageFile : DataSrcLibrary;
imageSrc = imageSrc.Replace("~", "").Replace("?ext=.jpg", "").Replace("?ext=.png", "") + GetImageSize(Maxsidesize, Width, Height);
if (LazyLoad && false)
{
Css += " b-lazy";
if (Type == "img")
{
litImage.Text = "<img class=\"" + Css + "\" src=\"" + SrcLazyLoad + "\" data-src=\"" + imageSrc + "\" alt=\"" + HTMLHelper.EncodeForHtmlAttribute(Alt) + "\" >";
litImageNoScript.Text = "<noscript><img src=\"" + imageSrc + "\" alt=\"" + HTMLHelper.EncodeForHtmlAttribute(Alt) + "\" /></noscript>";
}
else
{
if (Type == "a")
{
litImage.Text = "<a href=\"" + Href + "\" class=\"" + Css + "\" data-src=\"" + imageSrc + "\" ></a>";
litImageNoScript.Text = "<noscript><a href=\"" + Href + "\" class=\"" + CssClass + "\" style=\"background:url('" + imageSrc + "');\"></a></noscript>";
}
else
{
litImage.Text = "<div class=\"" + Css + "\" data-src=\"" + imageSrc + "\" ></div>";
litImageNoScript.Text = "<noscript><div class=\"" + CssClass + "\" style=\"background:url('" + imageSrc + "');\"></div></noscript>";
}
}
}
else
{
if (Type == "img")
{
litImage.Text = "<img class=\"" + Css + "\" src=\"" + imageSrc + "\" alt=\"" + HTMLHelper.EncodeForHtmlAttribute(Alt) + "\">";
}
else
{
if (Type == "a")
{
litImage.Text = "<a href=\"" + Href + "\" class=\"" + Css + "\" style=\"background:url('" + imageSrc + "');\" ></a>";
}
else
{
litImage.Text = "<div class=\"" + Css + "\" style=\"background:url('" + imageSrc + "');\"></div>";
}
}
}
}
public static string GetImageSize(int maxSideSize, int width, int height)
{
string imageSize = "";
if (maxSideSize > 0)
{
imageSize = "?maxsidesize=" + maxSideSize;
}
else if (width > 0)
{
imageSize = "?width=" + width;
}
else if (height > 0)
{
imageSize = "?height=" + height;
}
return imageSize;
}
}