Esempio n. 1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Gallery"/> class.
		/// </summary>
		public Gallery() {
			base.Load += Gallery_Load;
			myProperty = new GalleryProperty();
			Header = new Label();
			Pages = 0;
			Subdir = "";
		}
Esempio n. 2
0
		/// <summary>
		/// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
		/// </summary>
		/// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
		public void ProcessRequest( HttpContext context ) {
			HttpApplication applicationInstance = context.ApplicationInstance;
			HttpRequest request = context.Request;
			HttpResponse response = context.Response;

			hashkey = request["ID"];
			myProperty = (GalleryProperty)Gallery.PublicGalleryProperties[hashkey];

			if ( myProperty == null ) {
				response.Write( "please reload the gallery and click the image again" );
				response.End();
			}
			else {
				string path = request["imgURL"];
				path = path.Replace( "{plus}" , "+" );
				if ( request["imgURL"].Contains( ".." ) ) {
					throw new Exception( "inproper use of imgURL- Request Parameter" );
				}
				if ( Path.IsPathRooted( myProperty.RootDirectory ) ) {
					imageDirectory = myProperty.RootDirectory + @"\" + Path.GetDirectoryName( path );
					imageFile = Path.GetFileName( path );
					watermarkDirectory = myProperty.RootDirectory;
				}
				else {
					imageDirectory = Path.GetDirectoryName( context.Server.MapPath( myProperty.RootDirectory + "/" + path ) );
					imageFile = Path.GetFileName( context.Server.MapPath( path ) );
					watermarkDirectory = context.Server.MapPath( myProperty.RootDirectory );
				}

				switch ( request["preview"] ) {
					case "normal":
						response.Write( "<html><head><title>" + path + "</title>" );

						writeNavButtonScript( context );

						response.Write( "</head>" );
						response.Write( "<body style=\"TEXT-ALIGN: center; font-family:Verdana; font-size:13px;\" onload='enableButtons();'>" + Conversions.ToString( myProperty.PopupWidth ) +
									" x " + Conversions.ToString( myProperty.PopupHeight ) + " " );

						if ( myProperty.AllowOriginal ) {
							response.Write( "<a href=\"?preview=original&imgURL=" +
										HttpContext.Current.Server.UrlEncode( request["imgURL"] ) + "&ID=" + hashkey +
										"\">" + Gallery.translate( "Original" , myProperty.Language ) + "</a>&nbsp;" );
						}

						writeNavButtons( context );

						response.Write( "<br/><br/><img " + ClickToCloseAttr() + " src=\"?imgURL=" +
									HttpContext.Current.Server.UrlEncode( request["imgURL"] ) + "&size=preview&ID=" +
									hashkey + "\"/>" );
						response.Write( "<br>" + LicenceInfo() );

						if ( myProperty.EnableOrderForm ) {
							response.Write( "<br>" + OrderForm( request["imgURL"] ) );
						}

						response.Write( "</body></html>" );

						return;

					case "original":
						response.Write( "<html><head><title>" + request["imgURL"] + "</title>" );
						writeNavButtonScript( context );
						response.Write( "</head>" );
						response.Write( "<body style=\"TEXT-ALIGN: center\" onload='enableButtons()'><a href=\"?preview=normal&imgURL=" +
									HttpContext.Current.Server.UrlEncode( request["imgUrl"] ) + "&ID=" + hashkey +
									"\">" + Conversions.ToString( myProperty.PopupWidth ) + " x " +
									Conversions.ToString( myProperty.PopupHeight ) + "</a> " +
									Gallery.translate( "Original" , myProperty.Language ) + "&nbsp;" );
						writeNavButtons( context );
						response.Write( "<br/><br/><img " + ClickToCloseAttr() + " src=\"?imgURL=" +
									HttpContext.Current.Server.UrlEncode( request["imgURL"] ) + "&size=original&ID=" +
									hashkey + "\"/>" );
						response.Write( "<br>" + LicenceInfo() );
						if ( myProperty.EnableOrderForm ) {
							response.Write( "<br>" + OrderForm( request["imgURL"] ) );
						}
						response.Write( "</body></html>" );
						return;

					case "sendmail": {
							var client = new SmtpClient( myProperty.SMTPhost );
							var message = new MailMessage();
							Image image = GetThumb( myProperty.PopupWidth , myProperty.PopupHeight , false );
							var stream = new MemoryStream();
							image.Save( stream , ImageFormat.Jpeg );
							stream.Seek( 0L , SeekOrigin.Begin );
							try {
								message.From = new MailAddress( request["Email"] , request["Name"] );
							}
							catch ( Exception exception1 ) {
								ProjectData.SetProjectError( exception1 );
								Exception exception = exception1;
								message.From = new MailAddress( myProperty.SMTPrecipient , myProperty.ID );
								ProjectData.ClearProjectError();
							}
							var item = new Attachment( stream , Path.GetFileName( request["imgUrl"] ) , "image/jpg" );
							message.Attachments.Add( item );
							message.Subject = Gallery.translate( "Request from" , myProperty.Language ) + " " + myProperty.ID;
							message.To.Add( myProperty.SMTPrecipient );
							string str2 = "<table>";
							str2 = ( ( ( ( ( ( ( ( str2 + "<tr><td>" + Gallery.translate( "Name" , myProperty.Language ) + "</td>" ) +
									    "<td>" + request["Name"] + "</td></tr>" ) + "<tr><td>" +
									   Gallery.translate( "e-mail" , myProperty.Language ) + "</td>" ) + "<td>" +
									  request["Email"] + "</td></tr>" ) + "<tr><td>" +
									 Gallery.translate( "Image" , myProperty.Language ) + "</td>" ) + "<td>" +
									request["imgUrl"] + "</td></tr>" ) + "<tr><td>" +
								    Gallery.translate( "Message" , myProperty.Language ) + "</td>" ) + "<td>" +
								   request["Message"] + "</td></tr>" ) + "</table>";
							message.IsBodyHtml = true;
							message.Body = str2 + "<img src='cid:" + item.ContentId + "' width='" +
										Conversions.ToString( image.Width ) + "' height='" +
										Conversions.ToString( image.Height ) + "'/>";
							client.Credentials = new NetworkCredential( myProperty.SMTPuser , myProperty.SMTPpassword );
							client.Send( message );
							response.Write( "<h3>" +
										Gallery.translate(
										    "Thanks for your interest in that image! This E-Mail has been sent:" ,
										    myProperty.Language ) + "</h3><br>" );
							response.Write( str2 + "<img src='?size=preview&ID=" + hashkey + "&imgUrl=" +
										HttpContext.Current.Server.UrlEncode( request["imgURL"] ) + "' width='" +
										Conversions.ToString( image.Width ) + "' height='" +
										Conversions.ToString( image.Height ) + "'/>" );
							return;
						}
					//case "":{
					default: {
							bool caching = request["size"] == "";
							if ( request["size"] == "preview" ) {
								imageWidth = myProperty.PopupWidth;
								imageheight = myProperty.PopupHeight;
								if ( !myProperty.PopupScaling ) {
									imageWidth = 0;
									imageheight = 0;
								}
							}
							else if ( request["size"] == "original" ) {
								if ( !myProperty.AllowOriginal ) {
									return;
								}
								imageWidth = 0;
								imageheight = 0;
							}
							else {
								imageWidth = myProperty.ThumbWidth;
								imageheight = myProperty.ThumbHeight;
							}
							if ( File.Exists( imageDirectory + @"\" + imageFile ) ) {
								response.ContentType = "image/jpeg";
								response.Expires = 0xe10;
								response.AddHeader( "Content-Disposition" ,
											    "inline; filename=" + HttpContext.Current.Server.UrlEncode( imageFile ) );
								ImageCodecInfo[] imageEncoders = ImageCodecInfo.GetImageEncoders();
								var encoderParams = new EncoderParameters( 1 );
								encoderParams.Param[0] = new EncoderParameter( Encoder.Quality , 0x62L );
								GetThumb( imageWidth , imageheight , caching ).Save( response.OutputStream , imageEncoders[1] ,
																	   encoderParams );
							}
							else {
								response.ContentType = "text/html";
								response.Write( "<h3>" + Gallery.translate( "Image does not exist." , myProperty.Language ) +
											"<br>(" + path + ")<br>" + LicenceInfo() );
							}
							return;
						}
				}
			}
		}