*** include/general.php	2008-08-25 10:51:40.000000000 +0200
--- include/general.php	2008-08-25 15:12:18.000000000 +0200
***************
*** 42,48 ****
  		$scramblepath=substr(md5($ref . "_" . $scramble_key),0,15);
  		}
  	
! 	if ($extension=="") {$extension="jpg";}
  	$folder="filestore/";
  	#if (!file_exists(dirname(__FILE__) . $folder)) {mkdir(dirname(__FILE__) . $folder,0777);}
  	
--- 42,48 ----
  		$scramblepath=substr(md5($ref . "_" . $scramble_key),0,15);
  		}
  	
! 	if (($extension=="") || ($size !="")) {$extension="jpg";}
  	$folder="filestore/";
  	#if (!file_exists(dirname(__FILE__) . $folder)) {mkdir(dirname(__FILE__) . $folder,0777);}
  	
***************
*** 266,301 ****
  	# Returns a table of available image sizes for resource $ref.
  	# The original image file assumes the name of the 'nearest size (up)' in the table
  
  	# loop through all image sizes
  	$sizes=sql_query("select * from preview_size order by width desc");
- 	$return=array();
- 	$outputfirst=false;$lastname="";$lastpreview=0;
  	for ($n=0;$n<count($sizes);$n++)
! 		{
! 		$path=get_resource_path($ref,$sizes[$n]["id"],false,$extension);
  		if (file_exists($path) || (!$onlyifexists))
  			{
- 			if ($outputfirst==false)
- 				{
- 				# add the original image
- 				$path2=get_resource_path($ref,'',false,$extension);
- 				if (file_exists($path2))
- 					{
- 					$returnline=array();
- 					$returnline["name"]=$lastname;
- 					$returnline["allow_preview"]=$lastpreview;
- 					$returnline["allow_restricted"]=$lastrestricted;
- 					$returnline["path"]=$path2;
- 					$returnline["id"]="";
- 					if ((list($sw,$sh) = @getimagesize($path2))===false) {$sw=0;$sh=0;}
- 					if (($filesize=filesize($path2))===false) {$returnline["filesize"]="?";$returnline["filedown"]="?";}
- 					else {$returnline["filedown"]=ceil($filesize/50000) . " seconds @ broadband";$returnline["filesize"]=formatfilesize($filesize);}
- 					$returnline["width"]=$sw;			
- 					$returnline["height"]=$sh;
- 					$return[]=$returnline;
- 					$outputfirst=true;
- 					}
- 				}
  			if (($sizes[$n]["internal"]==0) || ($internal))
  				{
  				$returnline=array();
--- 266,298 ----
  	# Returns a table of available image sizes for resource $ref.
  	# The original image file assumes the name of the 'nearest size (up)' in the table
  
+ 	# add the original image
+ 	$return=array();
+ 	$lastname="";$lastpreview=0;$lastrestricted=0;
+ 	$path2=get_resource_path($ref,'',false,$extension);
+ 	if (file_exists($path2))
+ 	{
+ 		$returnline=array();
+ 		$returnline["name"]=$lastname;
+ 		$returnline["allow_preview"]=$lastpreview;
+ 		$returnline["allow_restricted"]=$lastrestricted;
+ 		$returnline["path"]=$path2;
+ 		$returnline["id"]="";
+ 		if ((list($sw,$sh) = @getimagesize($path2))===false) {$sw=0;$sh=0;}
+ 		if (($filesize=filesize($path2))===false) {$returnline["filesize"]="?";$returnline["filedown"]="?";}
+ 		else {$returnline["filedown"]=ceil($filesize/50000) . " seconds @ broadband";$returnline["filesize"]=formatfilesize($filesize);}
+ 		$returnline["width"]=$sw;			
+ 		$returnline["height"]=$sh;
+ 		$returnline["extension"]=$extension;
+ 		$return[]=$returnline;
+ 	}
  	# loop through all image sizes
  	$sizes=sql_query("select * from preview_size order by width desc");
  	for ($n=0;$n<count($sizes);$n++)
! 	{
! 		$path=get_resource_path($ref,$sizes[$n]["id"],false);
  		if (file_exists($path) || (!$onlyifexists))
  			{
  			if (($sizes[$n]["internal"]==0) || ($internal))
  				{
  				$returnline=array();
***************
*** 310,315 ****
--- 307,313 ----
  				$returnline["filesize"]=$filesize;			
  				$returnline["width"]=$sw;			
  				$returnline["height"]=$sh;
+ 				$returnline["extension"]='jpg';
  				$return[]=$returnline;
  				}
  			}
***************
*** 980,983 ****
  		
  	return "You are here: " . $bc;
  	}
! ?>
\ Kein Zeilenumbruch am Dateiende.
--- 978,981 ----
  		
  	return "You are here: " . $bc;
  	}
! ?>
*** include/image_processing.php	2008-08-25 11:20:23.000000000 +0200
--- include/image_processing.php	2008-08-26 08:26:46.000000000 +0200
***************
*** 228,242 ****
  	{
  	# Always create file checksum (all types)
  	generate_file_checksum($ref,$extension);
! 	if  (($extension=="jpg") || ($extension=="jpeg") || ($extension=="png") || ($extension=="gif"))
   
! 	# Create image previews for built-in supported file types only (JPEG, PNG, GIF)
  		{
  		# For resource $ref, (re)create the various preview sizes listed in the table preview_sizes
  		# Only create previews where the target size IS LESS THAN OR EQUAL TO the source size.
  		# Set thumbonly=true to (re)generate thumbnails only.
  		$file=get_resource_path($ref,"",false,$extension);	
! 		# fetch source image size, if we fail, exit this function (file not an image, or file not a valid jpg/png/gif).
  		if ((list($sw,$sh) = @getimagesize($file))===false) {return false;}
  		
  		$ps=sql_query("select * from preview_size" . (($thumbonly)?" where id='thm' or id='col'":""));
--- 228,242 ----
  	{
  	# Always create file checksum (all types)
  	generate_file_checksum($ref,$extension);
! 	if (preg_match('/^(tif[f]?|jp[e]?g|psd|eps)$/i', $extension))
   
! 	# Create image previews for selected file types (JPEG, TIFF, PSD, EPS)
  		{
  		# For resource $ref, (re)create the various preview sizes listed in the table preview_sizes
  		# Only create previews where the target size IS LESS THAN OR EQUAL TO the source size.
  		# Set thumbonly=true to (re)generate thumbnails only.
  		$file=get_resource_path($ref,"",false,$extension);	
! 		# fetch source image size, if we fail, exit this function (file not an image, or file not a valid jpg/png/gif). This somehow works even with TIFF and PSD!?
  		if ((list($sw,$sh) = @getimagesize($file))===false) {return false;}
  		
  		$ps=sql_query("select * from preview_size" . (($thumbonly)?" where id='thm' or id='col'":""));
***************
*** 255,268 ****
  
              # only create previews where the target size IS LESS THAN OR EQUAL TO the source size.
  			# or when producing a small thumbnail (to make sure we have that as a minimum
! 			if (($sw>$tw) || ($sh>$th) || ($id=="thm") || ($id=="col"))
  				{
  				# Calculate width and height.
  				if ($sw>$sh) {$ratio = ($tw / $sw);} # Landscape
  				else {$ratio = ($th / $sh);} # Portrait
  				$tw=floor($sw*$ratio);
  				$th=floor($sh*$ratio);
  
  				global $imagemagick_path,$imagemagick_preserve_profiles,$imagemagick_quality;
  				if (isset($imagemagick_path))
  					{
--- 255,275 ----
  
              # only create previews where the target size IS LESS THAN OR EQUAL TO the source size.
  			# or when producing a small thumbnail (to make sure we have that as a minimum
! 			if (($sw>$tw) || ($sh>$th) || ($id=="thm") || ($id=="col") || ($id=="hpr"))
  				{
  				# Calculate width and height.
  				if ($sw>$sh) {$ratio = ($tw / $sw);} # Landscape
  				else {$ratio = ($th / $sh);} # Portrait
+ 				if ($id=="hpr") {
+ 				  $ratio = min($ratio, 1);
+ 				}
  				$tw=floor($sw*$ratio);
  				$th=floor($sh*$ratio);
  
+ 				if (($ratio == 1) && (!preg_match('/^(tif[f]?|psd|eps)$/i', $extension))) {
+ 				  continue;
+ 				}
+ 
  				global $imagemagick_path,$imagemagick_preserve_profiles,$imagemagick_quality;
  				if (isset($imagemagick_path))
  					{
***************
*** 277,286 ****
                      if (!file_exists($command)) {exit("Could not find ImageMagick 'convert' utility.'");}	
          
  					# Preserve colour profiles? (omit for smaller sizes)   
! 					$profile="+profile icc +profile xmp +profile exif +profile iptc -colorspace RGB"; # By default, strip the colour profiles ('+' is remove the profile, confusingly)
  					if ($imagemagick_preserve_profiles && $id!="thm" && $id!="col" && $id!="pre" && $id!="scr") {$profile="";}
      
! 				    $command2 = $command . " \"$file\"[0] $profile -quality $imagemagick_quality -resize " . $tw . "x" . $th . " \"$path\""; 
                      $output=shell_exec($command2); 
  
  					if ($id=="thm")
--- 284,293 ----
                      if (!file_exists($command)) {exit("Could not find ImageMagick 'convert' utility.'");}	
          
  					# Preserve colour profiles? (omit for smaller sizes)   
! 					$profile="+profile \"*\" -colorspace RGB"; # By default, strip the colour profiles ('+' is remove the profile, confusingly)
  					if ($imagemagick_preserve_profiles && $id!="thm" && $id!="col" && $id!="pre" && $id!="scr") {$profile="";}
      
! 				    $command2 = $command . " \"$file\"[0] -flatten $profile -quality $imagemagick_quality -resize " . $tw . "x" . $th . " \"$path\""; 
                      $output=shell_exec($command2); 
  
  					if ($id=="thm")
*** view.php	2008-08-25 10:55:04.000000000 +0200
--- view.php	2008-08-25 11:21:27.000000000 +0200
***************
*** 171,177 ****
  </tr>
  <?
  $nodownloads=false;$counter=0;
! if (($resource["has_image"]==1) && (($resource["file_extension"]=="jpg") || ($resource["file_extension"]=="jpeg")))
  	{
  	# Work out if the user is allowed to download these images
  	$download=true;
--- 171,177 ----
  </tr>
  <?
  $nodownloads=false;$counter=0;
! if (($resource["has_image"]==1) && (preg_match('/^(tif[f]?|jp[e]?g|psd|eps)$/i', $resource["file_extension"])))
  	{
  	# Work out if the user is allowed to download these images
  	$download=true;
***************
*** 206,220 ****
  		if ($downloadthissize)
  			{
  			$counter++;
  			?>
  			<tr class="DownloadDBlend" id="DownloadBox<?=$n?>">
! 			<td><h2><?=i18n_get_translated($sizes[$n]["name"])?></h2>
  			<p><?=$sizes[$n]["width"]?> x <?=$sizes[$n]["height"]?> <?=$lang["pixels"]?> <? if ($mp>=1) { ?> (<?=$mp?> MP)<? } ?></p>
  			<p><?=$dpi_w?> cm x <?=$dpi_h?> cm @ 300dpi</p></td>
  			<td><?=$sizes[$n]["filesize"]?></td>
  			<!--<td><?=$sizes[$n]["filedown"]?></td>-->
  			<td class="DownloadButton HorizontalWhiteNav">
! 			<a href="terms.php?ref=<?=$ref?>&k=<?=$k?>&url=<?=urlencode("download_progress.php?ref=" . $ref . "&size=" . $sizes[$n]["id"] . "&ext=" . $resource["file_extension"] . "&k=" . $k)?>"><?=$lang["download"]?></a>
  			</td></tr>
  			<?
  			}
--- 206,221 ----
  		if ($downloadthissize)
  			{
  			$counter++;
+ 			$headline = ($n == 0) ? strtoupper($resource["file_extension"]) . " " . $lang["file"] : i18n_get_translated($sizes[$n]["name"]);
  			?>
  			<tr class="DownloadDBlend" id="DownloadBox<?=$n?>">
! 			<td><h2><?=$headline?></h2>
  			<p><?=$sizes[$n]["width"]?> x <?=$sizes[$n]["height"]?> <?=$lang["pixels"]?> <? if ($mp>=1) { ?> (<?=$mp?> MP)<? } ?></p>
  			<p><?=$dpi_w?> cm x <?=$dpi_h?> cm @ 300dpi</p></td>
  			<td><?=$sizes[$n]["filesize"]?></td>
  			<!--<td><?=$sizes[$n]["filedown"]?></td>-->
  			<td class="DownloadButton HorizontalWhiteNav">
! 			<a href="terms.php?ref=<?=$ref?>&k=<?=$k?>&url=<?=urlencode("download_progress.php?ref=" . $ref . "&size=" . $sizes[$n]["id"] . "&ext=" . $sizes[$n]["extension"] . "&k=" . $k)?>"><?=$lang["download"]?></a>
  			</td></tr>
  			<?
  			}
*** collection_download.php	2008-08-25 14:07:28.000000000 +0200
--- collection_download.php	2008-08-25 16:32:58.000000000 +0200
***************
*** 9,16 ****
  
  $collection=getvalescaped("collection","");
  $size=getvalescaped("size","");
  
! if ($size!="")
  	{
  	$path="";
  	$deletion_array=array();
--- 9,17 ----
  
  $collection=getvalescaped("collection","");
  $size=getvalescaped("size","");
+ $submitted=getvalescaped("submitted","");
  
! if ($submitted != "")
  	{
  	$path="";
  	$deletion_array=array();
***************
*** 60,67 ****
  					{
  					if(!is_dir("filestore/tmp")){mkdir("filestore/tmp",0777);}
  					# Retrieve the original file name (strip the path if it's present due to staticsync.php)
! 					$filename=get_resource_data($ref);$filename=$filename["file_path"];
! 					
  					if ($filename!="")
  						{
  						# Only perform the copy if an original filename is set.
--- 61,71 ----
  					{
  					if(!is_dir("filestore/tmp")){mkdir("filestore/tmp",0777);}
  					# Retrieve the original file name (strip the path if it's present due to staticsync.php)
! 					$filename=get_resource_data($ref);
! 					$filename=$ref.'_'.$filename["file_path"];
! 					preg_match('/\.[^\.]+$/', $p, $pext);
! 					$filename=preg_replace('/\.[^\.]+$/', $pext[0], $filename);
! 
  					if ($filename!="")
  						{
  						# Only perform the copy if an original filename is set.
***************
*** 122,133 ****
  <div class="Inline"><select name="size" class="shrtwidth" id="downloadsize">
  <?
  $sizes=get_all_image_sizes();
  for ($n=0;$n<count($sizes);$n++)
  	{
  	?><option value="<?=$sizes[$n]["id"]?>"><?=i18n_get_translated($sizes[$n]["name"])?></option><?
  	}
  ?></select></div>
! <div class="Inline"><input name="Submit" type="submit" value="&nbsp;&nbsp;<?=$lang["download"]?>&nbsp;&nbsp;" /></div>
  </div>
  <div class="clearerleft"> </div>
  </div>
--- 126,138 ----
  <div class="Inline"><select name="size" class="shrtwidth" id="downloadsize">
  <?
  $sizes=get_all_image_sizes();
+ $sizes[]=array("id" => "", "name" => "Originaldatei");
  for ($n=0;$n<count($sizes);$n++)
  	{
  	?><option value="<?=$sizes[$n]["id"]?>"><?=i18n_get_translated($sizes[$n]["name"])?></option><?
  	}
  ?></select></div>
! <div class="Inline"><input name="submitted" type="submit" value="&nbsp;&nbsp;<?=$lang["download"]?>&nbsp;&nbsp;" /></div>
  </div>
  <div class="clearerleft"> </div>
  </div>

