<?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 );
include ("../../../../../configuration.php");
include ($mosConfig_absolute_path."/includes/database.php");
require_once ($mosConfig_absolute_path."/mambots/editors/mosce/jscripts/tiny_mce/mosce_config.php");
$database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
// Get the default stylesheet
$query = "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'";
$database->setQuery($query );
$cur_template = $database->loadResult();

if (empty($editor_im_popup_bgcolor)){
  $editor_im_popup_body = "<body>";
}else{
  $editor_im_popup_body = "<body style=\"background-color:#$editor_im_popup_bgcolor\">";
}
if (isset($_GET['mode'])){
  $_mode = $_GET['mode'];
}else{
  $_mode = $editor_im_popup_mode;
}
if ($_mode == 'basic') {
    if (isset($_GET['title'])) $img_title = $_GET['title'];
    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>
</head>
<body style="margin: 0px;">
<?php
if(isset($_GET['src'])) $image_src = $_GET['src'];
if(isset($_GET['img'])) $image_src = $_GET['img'];

if (strstr($image_src, 'http://') || strstr($image_src, 'https://')){ //Offsite link or full url
    $image_src = $image_src;
}else{
    $image_src = $mosConfig_live_site."/".$image_src;
}

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

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

    if (isset($_GET['imgwidth']) && $_GET['imgwidth'] != $imgdata[0]) {
        $imgwidth = $_GET['imgwidth'];
    }else{
        $imgwidth = $imgdata[0];
    }
    
    if (isset($_GET['imgheight']) && $_GET['imgheight'] != $imgdata[1]) {
        $imgheight = $_GET['imgheight'];
    }else{
        $imgheight = $imgdata[1];
    }
    // 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) > '.$imgwidth.') || ((screen.height * 1.1) > '.$imgheight.')) {'."\n";
	// screen is large enough to fit whole picture on screen with 10% margin
	echo 'document.writeln(\'<img onclick="window.close();" src="'.$image_src.'" border="0" alt="'.$img_title.'" title="'.$img_title.'" width="'.$imgwidth.'" height="'.$imgheight.'" style="cursor: pointer;" />\');';
	echo 'CrossBrowserResizeInnerWindowTo('.$imgwidth.', '.$imgheight.');'."\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>
<?php }else{
    //Remove host url for backwards compatability
    if(isset($_GET['img'])) $img_src = ereg_replace($mosConfig_live_site."/", '',($_GET['img']));
    if(isset($_GET['src'])) $img_src = ereg_replace($mosConfig_live_site."/", '',($_GET['src']));
    if(isset($_GET['alt'])) $img_alt = ($_GET['alt']);
    if(isset($_GET['title'])) $img_alt = ($_GET['title']);

    $imgdata = @getimagesize($mosConfig_live_site."/".$img_src);
    
    if (isset($_GET['imgwidth']) && $_GET['imgwidth'] != $imgdata[0]) {
        $imgwidth = $_GET['imgwidth'];
    }else{
        $imgwidth = $imgdata[0];
    }

    if (isset($_GET['imgheight']) && $_GET['imgheight'] != $imgdata[1]) {
        $imgheight = $_GET['imgheight'];
    }else{
        $imgheight = $imgdata[1];
    }
?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
            <title><?php if(isset($_GET['alt'])) ?></title>
            <link rel="stylesheet" href="<?php echo $mosConfig_live_site ?>/templates/<?php echo $cur_template ?>/css/template_css.css" type="text/css" />
            <script type="text/javascript">
            window.resizeTo(<?php echo $imgwidth+10; ?>, <?php echo $imgheight+100; ?>);
            window.focus;
            </script>
    </head>
        <?php echo $editor_im_popup_body; ?>
        <div align="center">
        <table border="0">
            <?php if ($editor_im_popup_title == 'true'){?>
            <tr>
        		<td class="contentheading" colspan="2"><?php echo $img_alt; ?></td>
        	</tr>
        	<?php }?>
        	<tr>
        		<td colspan="2"><img src="<?php echo $mosConfig_live_site; ?>/<?php echo $img_src; ?>" onClick="window.close();" style="cursor: pointer;" border="0" title="<?php echo $img_alt; ?>" alt="<?php echo $img_alt; ?>" width="<?php echo $imgwidth; ?>" height="<?php echo $imgheight; ?>" /></td>
        	</tr>
        	<tr>
                <td><div align="center"><a href="#" onClick="window.close();">Close</a></div></td>
                <?php if ($editor_im_popup_print == 'true'){?>
                <td><div align="center"><a href="javascript:;" onClick="window.print(); return false">Print</a></div></td>
                <?php }?>
            </tr>
        </table>
        </div>
    </body>
    </html>
<?php } ?>
