<?php
//////////////////////////////////////////////////////////////
///  phpThumb() by James Heinrich <info@silisoftware.com>   //
//        available at http://phpthumb.sourceforge.net     ///
//////////////////////////////////////////////////////////////
///                                                         //
// See: phpthumb.readme.txt for usage instructions          //
//                                                         ///
//////////////////////////////////////////////////////////////
//                                                          //
// phpThumb.demo.showpic.php                                //
// James Heinrich <info@silisoftware.com>                   //
// 23 Feb 2004                                              //
//                                                          //
// This code is useful for popup pictures (e.g. thumbnails  //
// you want to show larger, such as a larger version of a   //
// product photo for example) but you don't know the image  //
// dimensions before popping up. This script displays the   //
// image with no window border, and resizes the window to   //
// the size it needs to be (usually better to spawn it      //
// large (600x400 for example) and let it auto-resize it    //
// smaller), and if the image is larger than 90% of the     //
// current screen area the window respawns itself with      //
// scrollbars.                                              //
//                                                          //
// Usage:                                                   //
// window.open('showpic.php?src=big.jpg&title=Big+picture', //
//   'popupwindowname',                                     //
//   'width=600,height=400,menubar=no,toolbar=no')          //
//                                                          //
// See demo linked from http://phpthumb.sourceforge.net    ///
//////////////////////////////////////////////////////////////
//Added modofications to support Mambo 4.5x - Ryan Demmer 16/05/2005 (ryandemmer@gmail.com)
//Renamed to popupImage.php for backwards compatability with TinyMCE-EXP 1.25 beta4
//Supports simple (as in original showpic.php) and advanced popup.
define( '_VALID_MOS', 1 );
if(isset($_GET['alt'])) $img_title = $_GET['alt'];
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title><?php echo $img_title; ?></title>

	<script language="Javascript">
	<!--
	// http://www.xs4all.nl/~ppk/js/winprop.html
	function CrossBrowserResizeInnerWindowTo(newWidth, newHeight) {
		if (self.innerWidth) {
			frameWidth  = self.innerWidth;
			frameHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientWidth) {
			frameWidth  = document.documentElement.clientWidth;
			frameHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			frameWidth  = document.body.clientWidth;
			frameHeight = document.body.clientHeight;
		} else {
			return false;
		}
		if (document.layers) {
			newWidth  -= (parent.outerWidth - parent.innerWidth);
			newHeight -= (parent.outerHeight - parent.innerHeight);
		}
		// original code
		//parent.window.resizeTo(newWidth, newHeight);

		// fixed code: James Heinrich, 20 Feb 2004
		parent.window.resizeBy(newWidth - frameWidth, newHeight - frameHeight);

		return true;
	}
	// -->
	</script>
	<style type="text/css">
    body {
          font-family: Verdana, Helvetica, Arial, Sans-Serif;
          font: message-box;
        }
    </style>
</head>
<body style="margin: 0px;">
<?php
if(isset($_GET['img'])) $image_src = $_GET['img'];
if(isset($_GET['imgsize'])) $image_size = $_GET['imgsize'];

if (get_magic_quotes_gpc()) {
	$image_src = stripslashes($image_src);
}

if ($imgdata = @getimagesize($image_src)) {

	// this would be an excellent place to put some caching stuff to avoid re-scanning every picture every time

	// check for maximum dimensions to allow no-scrollbar window
	echo '<script language="Javascript">'."\n";
	echo 'if (((screen.width * 1.1) > '.$imgdata[0].') || ((screen.height * 1.1) > '.$imgdata[1].')) {'."\n";
	// screen is large enough to fit whole picture on screen with 10% margin
	echo 'document.writeln(\'<div align="center"><img onclick="window.close();" src="'.$image_src.'" title="'.$img_title.'" alt="'.$img_title.'" border="0" style="cursor: pointer;" /></div>\');';
    echo 'document.writeln(\'<div align="center"><strong>'.$img_title.'</strong></div>\');';
    echo 'document.writeln(\'<div align="center">'.$imgdata[0].' px x '.$imgdata[1].' px</div>\');';
    echo 'document.writeln(\'<div align="center">'.$image_size.'</div>\');';
    echo 'CrossBrowserResizeInnerWindowTo('.$imgdata[0].', '.$imgdata[1].'+80);'."\n";
	echo '} else {'."\n";
	// image is too large for screen: add scrollbars by putting the image inside an IFRAME
	echo 'document.writeln(\'<iframe width="100%" height="100%" marginheight="0" marginwidth="0" frameborder="0" scrolling="on" src="'.$image_src.'">Your browser does not support the IFRAME tag. Please use one that does (IE, Firefox, etc).<br><img src="'.$image_src.'"></iframe>\');';
	echo '}'."\n";
	echo '</script>';

} else {

	// cannot determine correct window size, or correct size too large: add scrollbars by putting the image inside an IFRAME
	echo '<iframe width="100%" height="100%" marginheight="0" marginwidth="0" frameborder="0" scrolling="on" src="'.$image_src.'"></iframe>';

}

?>
</body>
</html>
