1<?php
2//////////////////////////////////////////////////////////////
3//   phpThumb() by James Heinrich <info@silisoftware.com>   //
4//        available at http://phpthumb.sourceforge.net      //
5//         and/or https://github.com/JamesHeinrich/phpThumb //
6//////////////////////////////////////////////////////////////
7//                                                          //
8// phpThumb.demo.showpic.php                                //
9// James Heinrich <info@silisoftware.com>                   //
10// 23 Feb 2004                                              //
11//                                                          //
12// This code is useful for popup pictures (e.g. thumbnails  //
13// you want to show larger, such as a larger version of a   //
14// product photo for example) but you don't know the image  //
15// dimensions before popping up. This script displays the   //
16// image with no window border, and resizes the window to   //
17// the size it needs to be (usually better to spawn it      //
18// large (600x400 for example) and let it auto-resize it    //
19// smaller), and if the image is larger than 90% of the     //
20// current screen area the window respawns itself with      //
21// scrollbars.                                              //
22//                                                          //
23// Usage:                                                   //
24// window.open('showpic.php?src=big.jpg&title=Big+picture', //
25//   'popupwindowname',                                     //
26//   'width=600,height=400,menubar=no,toolbar=no')          //
27//                                                          //
28// See demo linked from http://phpthumb.sourceforge.net    ///
29//////////////////////////////////////////////////////////////
30die('For security reasons, this demo is disabled by default. Please comment out line '.__LINE__.' in '.basename(__FILE__));
31
32$phpThumbLocation = '../phpThumb.php';
33require_once '../phpThumb.config.php';
34
35echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
36echo '<html><head>';
37if (isset($_GET['title'])) {
38	echo '<title>'.htmlentities($_GET['title']).'</title>';
39	unset($_GET['title']);
40} else {
41	echo '<title>'.htmlentities('phpThumb :: popup window resizing demo').'</title>';
42}
43?>
44
45<script type="text/javascript">
46<!--
47// http://www.xs4all.nl/~ppk/js/winprop.html
48function CrossBrowserResizeInnerWindowTo(newWidth, newHeight) {
49	if (self.innerWidth) {
50		frameWidth  = self.innerWidth;
51		frameHeight = self.innerHeight;
52	} else if (document.documentElement && document.documentElement.clientWidth) {
53		frameWidth  = document.documentElement.clientWidth;
54		frameHeight = document.documentElement.clientHeight;
55	} else if (document.body) {
56		frameWidth  = document.body.clientWidth;
57		frameHeight = document.body.clientHeight;
58	} else {
59		return false;
60	}
61	if (document.layers) {
62		newWidth  -= (parent.outerWidth - parent.innerWidth);
63		newHeight -= (parent.outerHeight - parent.innerHeight);
64	}
65
66	// original code:
67	//parent.window.resizeTo(newWidth, newHeight);
68	// fixed code: James Heinrich, 20 Feb 2004
69	parent.window.resizeBy(newWidth - frameWidth, newHeight - frameHeight);
70
71	return true;
72}
73// -->
74</script>
75
76<script type="text/javascript" src="javascript_api.js"></script>
77
78<?php
79$allowedGETparameters = array('src','new','w','h','wp','hp','wl','hl','ws','hs','f','q','sx','sy','sw','sh','zc','bc','bg','bgt','fltr','xto','ra','ar','aoe','far','iar','maxb','hash','md5s','sfn','dpi','sia');
80
81$additionalparameters = array();
82foreach ($_GET as $key => $value) {
83	if (!in_array($key, $allowedGETparameters)) {
84		continue;
85	}
86	if (is_array($value)) {
87		if ($key != 'fltr') {
88			continue;
89		}
90		foreach ($value as $key2 => $value2) {
91			@$additionalparameters[$key][] = preg_replace('#[^A-Za-z0-9\\. _:/]#', '', $value2);
92		}
93	} else {
94		if ($key == 'src') {
95			// allow as passed
96			$additionalparameters[$key] = $value;
97		} else {
98			$additionalparameters[$key] = preg_replace('#[^A-Za-z0-9\\. _:/]#', '', $value);
99		}
100	}
101}
102$imagesrc = phpThumbURL($additionalparameters, $phpThumbLocation);
103
104echo '<script type="text/javascript">';
105echo 'var ns4;'."\n";
106echo 'var op5;'."\n";
107echo 'function setBrowserWindowSizeToImage() {'."\n";
108echo 	'if (!document.getElementById("imageimg")) { return false; }'."\n";
109echo	'sniffBrowsers();'."\n";
110echo 	'var imageW = getImageWidth("imageimg");'."\n";
111echo 	'var imageH = getImageHeight("imageimg");'."\n";
112		// check for maximum dimensions to allow no-scrollbar window
113echo 	'if (((screen.width * 1.1) > imageW) || ((screen.height * 1.1) > imageH)) {'."\n";
114			// screen is large enough to fit whole picture on screen with 10% margin
115echo 		'CrossBrowserResizeInnerWindowTo(imageW, imageH);'."\n";
116echo 	'} else {'."\n";
117			// image is too large for screen: add scrollbars by putting the image inside an IFRAME
118echo 		'document.getElementById("showpicspan").innerHTML = "<iframe width=\"100%\" height=\"100%\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" scrolling=\"on\" src=\"'.$imagesrc.'\">Your browser does not support the IFRAME tag. Please use one that does (Chrome, Firefox, etc).<br><img src=\"'.$imagesrc.'\"><\/iframe>";'."\n";
119echo 	'}'."\n";
120echo '}';
121echo '</script>';
122
123echo '</head><body style="margin: 0;" onLoad="setBrowserWindowSizeToImage();"><div id="showpicspan">';
124
125if (!empty($_GET['src'])) {
126
127	echo '<script type="text/javascript">';
128	echo 'document.writeln(\'<img src="'.$imagesrc.'" border="0" id="imageimg" hspace="0" hspace="0" style="padding: 0px; margin: 0px;">\');';
129	echo '</script>';
130
131} else {
132
133	echo '<pre>';
134	echo 'Usage:<br><br><b>'.basename(__FILE__).'?src=<i>filename</i>&amp;title=<i>Picture+Title</i></b>';
135	echo '</pre>';
136
137}
138
139?></div></body>
140</html>