--- qdig-20051005cnj.php	Wed Oct  5 18:04:03 2005
+++ qdig-20051203cnj.php	Sat Dec  3 22:13:15 2005
@@ -37,9 +37,9 @@
 | Version 2 along with this program; if not, visit GNU's Home Page
 | http://www.gnu.org/
 +----------------------------------------------------------------------+
-CVS: $Id: qdig.php,v 1.19 2005/10/05 22:02:00 matt Exp $#
+CVS: $Id: qdig.php,v 1.21 2005/12/04 00:22:39 matt Exp $#
 */#
-$qdig_version = '20051005cnj [based on 20050509]';
+$qdig_version = '20051203cnj [based on 20050509]';
 $mtime = microtime();
 $mtime = explode(' ', $mtime);
 $start_time = $mtime[1] + $mtime[0];
@@ -217,8 +217,8 @@
 $exif_camera['padding'] = '3px';
 $exif_camera['above'] = TRUE;	// Place camera line above the image, not below.
 $exif_verbose['enable'] = TRUE;	// Show verbose EXtendedInFormation on the side
-$exif_verbose['min_width'] = 300;	/// XXX these need to change
-$exif_verbose['padding'] = '3px';
+//$exif_verbose['min_width'] = 300;	/// XXX these need to change
+//$exif_verbose['padding'] = '3px';
 $exif_verbose['above'] = FALSE;	// Plase verbose above image, not below
 $exif_verbose_ignore[] = 'EXIF.MakerNote';	// Ignore these fields
 $exif_verbose_ignore[] = 'THUMBNAIL'; 	// or an entire section
@@ -227,6 +227,7 @@
 $exif_verbose_ignore[] = 'EXIF.ComponentsConfiguration';
 $exif_verbose_ignore[] = 'IFD0'; 		// We're ignoring everything.
 $exif_verbose_ignore[] = 'EXIF'; 		// We're ignoring everything.
+$exif_verbose_ignore[] = 'MAKERNOTE'; 		// We're ignoring everything.
 $exif_verbose_show[]	= 'EXIF.ISOSpeedRatings';	// Allow these back in
 $exif_verbose_show[]	= 'EXIF.FNumber';	
 //$exif_verbose_show[]	= 'COMPUTED.ApertureFNumber';	
@@ -249,6 +250,7 @@
 $exif_verbose_show[]	= 'FILE.MimeType';
 $exif_verbose_show[]	= 'COMPUTED.Height';
 $exif_verbose_show[]	= 'COMPUTED.Width';
+$exif_columns	=	2;	// How many elements to display across (verbose)
 
 
 // Settings for making the displayed image an active link
@@ -356,6 +358,7 @@
 * To use the one that isn't the default, set the default one to FALSE.
 */
 $convert_magick = TRUE;  // Use Image Magick, if available, to convert images.
+$convert_magick_force = TRUE;  // Use Image Magick, even in safe_mode (add to safe_mode_exec_dir! path)
 $convert_cmd    = '/usr/local/bin/convert';  // Full pathname to `convert'.
 // Example $convert_cmd for Win32 users:
 //$convert_cmd    = '"C:\\Program Files\\ImageMagick-5.5.3-Q16\\convert.exe"';
@@ -1095,7 +1098,7 @@
 /**
 * Generate thumbnail images for images that do not have thumbnails yet.
 */
-function createThumbs($cnvrt_thmb)
+function createThumbs($cnvrt_thmb, $bCallHook = false)
 {
 	global $platform, $pwd, $imgs, $convert_magick, $cnvrt_path, $convert_cmd,
 		$convert_GD, $thmbs_ena, $convert_writable, $caption_path,
@@ -1127,6 +1130,11 @@
 				|| ! file_exists($caption_file))
 			{
 				touch($caption_file);
+				$caption="";
+			} 
+			else 
+			{
+				$caption=file_get_contents($caption_file);
 			}
 		}
 		$orig_img   = $pwd.'/'.$img_file;
@@ -1191,6 +1199,9 @@
 					.$img_file.$using.".\n"
 					."  </small>\n  <br />\n";
 			}
+			if($bCallHook===true) {
+				$str .= genthmHook($pwd, $img_file, $cnvrtd_img, $caption);
+			}
 		}
 	}
 	if (isset($str)) { return $str; }
@@ -1916,7 +1927,7 @@
 	$num_imgs = count($imgs);
 	if (isset($imgs) && $num_imgs > 1) {
 		$str = " <!-- thumbnail-image links -->\n";
-		$str .= " <div align=\"center\" style=\"padding-top:2px; white-space:nowrap\">\n";
+		$str .= " <div align=\"center\" style=\"padding-top:2px; white-space:nowrap\" class=\"qdig-thumbrow\">\n";
 		// prepare wrap data
 		$thumbs_width = 0;
 		$thumbs_wrap  = 0;
@@ -2431,10 +2442,16 @@
 	}
 	if(''!=$exif_data['EXIF']['ISOSpeedRatings']) 
 		$str.= "ISO-{$exif_data['EXIF']['ISOSpeedRatings']}, " ;
-	if(''!=$exif_data['COMPUTED']['ApertureFNumber']) 
-		$str.=	$exif_data['COMPUTED']['ApertureFNumber'] . ',' ;
+	if(''!=$exif_data['COMPUTED']['ApertureFNumber']) {
+		$str.=	$exif_data['COMPUTED']['ApertureFNumber'].',' ;
+	}
 	if(''!=$exif_data['EXIF']['ExposureTime']) 
 		$str.=	$exif_data['EXIF']['ExposureTime'] . ',' ;
+	if(''!=$exif_data['EXIF']['FocalLength']) {
+		$t =	$exif_data['EXIF']['FocalLength'];
+		$t = explode('/', $t);
+		$str .= ' ' . ($t[0] / $t[1]) . 'mm ';
+	}
 	if(''!=$exif_data['EXIF']['FocalLengthIn35mmFilm']) 
 		$str.=	"{$exif_data['EXIF']['FocalLengthIn35mmFilm']}mm equiv. ";
 	if(''!=$exif_data['IFD0']['DateTime']) 
@@ -2449,7 +2466,8 @@
 */
 function exifVerboseBlock($exif_data, $exif_verbose)
 {
-	global $exif_verbose_ignore, $exif_verbose_show;
+	global $exif_verbose_ignore, $exif_verbose_show,
+		$exif_columns;
 	if($exif_data==FALSE) return "";
 	$str = " <div title='{$caption['lang ExifVerbose']}'"
 		." class='qdig-exifverbose'"
@@ -2457,23 +2475,57 @@
 		." padding:{$exif_verbose['padding']};"
 		." text-align:{$exif_verbose['txt_align']};'>\n";
 	$str.="\t<table width='100%'>\n";
+	$col_space=0;
+	$col_total_space=$col_space*($exif_columns-1);
+	$col_width=floor((100-$col_total_space)/($exif_columns*2));
 	foreach($exif_data as $key => $section) {
 		foreach($section as $name => $val) {
-			if(stristr($key.'.'.$name, 'undefined')!==FALSE) {
-				continue;
+			if(!is_array($val)) {
+				$val=array($val);
 			}
-			if(//!isset($exif_verbose_ignore) ||
-			   in_array($key.'.'.$name, $exif_verbose_show) 
-				|| ! (	in_array(
-						$key.'.'.$name, 
-						$exif_verbose_ignore)  ||
-				 	in_array(
-						$key,
-						$exif_verbose_ignore) ) ) {
-				$str .= "\t\t<tr><td>$name</td><td>$val</td></tr>\n";
-			} 
+			foreach($val as $ak => $av) {
+				$full_key = $key.'.'.$name;
+				if(sizeof($val)>1) {
+					$full_key .= '.' .$ak;
+					$desc_name = $name . '.' . $ak;
+				} else {
+					$desc_name = $name; 
+				}
+				if(stristr($key.'.'.$name, 'undefined')!==FALSE) {
+					continue;
+				}
+				if(//!isset($exif_verbose_ignore) ||
+				   in_array($full_key, $exif_verbose_show) 
+					|| ! (	in_array(
+							$full_key,
+							$exif_verbose_ignore)  ||
+						in_array(
+							$key . '.' . $name,
+							$exif_verbose_ignore)  ||
+						in_array(
+							$key,
+							$exif_verbose_ignore) ) ) {
+					$exif_entry[] = "<td width='{$col_width}%' class='qdig-exifname'>${desc_name}</td><td width='{$col_width}%' class='qdig-exifvalue'>${av}</td>";
+				} 
+			}
+		}
+	}
+	$ee_cnt=0; 
+	foreach($exif_entry as $ee) {
+		if(++$ee_cnt==1){
+			$str .= "\t\t<tr width='100%'>";
+		} else if($col_space){
+			$str .= "<td width='{$col_space}%'>&nbsp;</td>";
+		}
+		$str .= $ee;
+		if($exif_columns==$ee_cnt) {
+			$str .= "</tr>\n";
+			$ee_cnt=0;
 		}
 	}
+	if($ee_cnt) {
+			$str .= "</tr>\n";
+	}
 	$str.= "\t</table>\n";
 	$str.= "</div>";
 	return $str;
@@ -2741,7 +2793,7 @@
 		}
 		$str = <<<EOT
 \n <!-- gallery navigation -->
- <div align="center" style="padding-top:$pad_top;">
+ <div align="center" style="padding-top:$pad_top;" class="qdig-nav">
   <table summary="{$nav_lnk['Gallery Navigation']}"
    width="{$nav['width']}" cellpadding="1" cellspacing="0">
    <tr>\n
@@ -2841,6 +2893,25 @@
 } // End navHook()
 
 /**
+* Calls external functions to hook into when new thumbs generated.
+*
+* Returns a string containing the concatenated output of all 
+* functions in $genthm_hook[].
+*/
+function genthmHook($qif, $qwd, $thm, $caption)
+{
+	global $genthm_hook;
+	if(!is_array($genthm_hook)) return "";
+	$str="";
+	foreach($genthm_hook as $f) {
+		if(function_exists($f)) {
+			$str .= ' ' . call_user_func($f, $qif, $qwd, $thm, $caption);
+		}
+	}
+	return $str;
+} // End genthmHook()
+
+/**
 * Produce a Gallery Footer Row table.
 *
 * Includes Site Link, Copyright, and Quig Home link.
@@ -2894,7 +2965,7 @@
 	{
 		$str = <<<EOT
 \n <!-- table footer row of image dispaly area -->
- $tag<div align="center" style="padding-top:{$footer['pad_top']};">
+ $tag<div align="center" style="padding-top:{$footer['pad_top']};" class="qdig-footer">
   <table summary="{$footer['summary_txt']}"
    width="100%" cellpadding="1" cellspacing="0">
    <tr>\n
@@ -3496,7 +3567,7 @@
 if ($convert_GD == TRUE && ! $convert_GD_ver = gdVersion()) {
 	$convert_GD = FALSE;
 }
-if ($convert_magick == TRUE
+if ($convert_magick == TRUE && $convert_magick_force != TRUE
 	&& ($safe_mode == TRUE || ! @is_file($convert_cmd)))
 {
 	$convert_magick = FALSE;
@@ -3753,7 +3824,7 @@
 	# Reset the image 'list' to just this one
 	$imgs = array($reqd_image['file']);
 	$cnvrt_thmb['single'] = TRUE;
-	$thumbs_msg = createThumbs($cnvrt_thmb);
+	$thumbs_msg = createThumbs($cnvrt_thmb, false);
 
 	$name = $cnvrt_path.'/'.$cnvrt_thmb['prefix'].$imgs[0];
 
@@ -3802,9 +3873,10 @@
 /**
 * Create thumbnail image(s) if necessary.
 */
-if ($thumbs['onfly'] == FALSE) {
-	$thumbs_msg = createThumbs($cnvrt_thmb);
-	$thumbs_msg = createThumbs($cnvrt_thmb_rv);
+if ($thumbs['onfly'] == FALSE &&
+   !(isset($GLOBALS['no_qdig_body']) &&  $GLOBALS['no_qdig_body'])) {
+	$thumbs_msg = createThumbs($cnvrt_thmb, fale);
+	$thumbs_msg = createThumbs($cnvrt_thmb_rv, true);
 }
 
 /**
