2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
2006-07-06 18:37:34 +00:00
|
|
|
/**
|
|
|
|
|
* Shows a thumbnail or a full size screenshot.
|
|
|
|
|
*
|
|
|
|
|
* Mandatory parameters:
|
|
|
|
|
* - iId, image identifier
|
|
|
|
|
*
|
|
|
|
|
* Optional parameters:
|
|
|
|
|
* - bThumbnail, "true" if we want to see a thumbnail, "false" otherwise
|
|
|
|
|
* - sREQUEST_METHOD
|
|
|
|
|
*
|
|
|
|
|
* TODO:
|
|
|
|
|
* - rename and document sREQUEST_METHOD
|
|
|
|
|
* - replace iId with iScreenshotId
|
|
|
|
|
* - replace require_once with require after checking that it doesn't break anything
|
|
|
|
|
*/
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2006-07-06 18:37:34 +00:00
|
|
|
// application environment
|
2004-03-15 16:22:00 +00:00
|
|
|
include("path.php");
|
2006-07-06 18:37:34 +00:00
|
|
|
require(BASE."include/incl.php");
|
|
|
|
|
require_once(BASE."include/screenshot.php");
|
2005-07-31 03:35:44 +00:00
|
|
|
|
2006-06-17 06:10:10 +00:00
|
|
|
$aClean = array(); //array of filtered user input
|
|
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
$aClean['iId'] = makeSafe($_REQUEST['iId']);
|
|
|
|
|
$aClean['sREQUEST_METHOD'] = makeSafe($_REQUEST['sREQUEST_METHOD']);
|
|
|
|
|
$aClean['bThumbnail'] = makeSafe($_REQUEST['bThumbnail']);
|
2006-06-17 06:10:10 +00:00
|
|
|
|
2006-07-06 18:37:34 +00:00
|
|
|
// an image doesn't have a link, so a cookie makes no sense
|
2005-07-31 03:35:44 +00:00
|
|
|
header("Set-Cookie: ");
|
|
|
|
|
header("Pragma: ");
|
|
|
|
|
|
2006-07-06 18:37:34 +00:00
|
|
|
// is the user supposed to be viewing this image ?
|
2006-07-06 17:27:54 +00:00
|
|
|
if(!$_SESSION['current']->canViewImage($aClean['iId']))
|
2006-06-29 16:13:35 +00:00
|
|
|
util_show_error_page("Insufficient privileges.");
|
2005-08-05 22:07:41 +00:00
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
if ($aClean['sREQUEST_METHOD']='HEAD')
|
2005-07-31 03:35:44 +00:00
|
|
|
{
|
|
|
|
|
/* WARNING! optimization of logic in include/screenshots.php */
|
2006-07-06 17:27:54 +00:00
|
|
|
if (sscanf($aClean['iId'],"%d", &$iId) < 1)
|
2006-06-29 16:13:35 +00:00
|
|
|
util_show_error_page("Bad parameter");
|
2006-07-06 17:59:52 +00:00
|
|
|
|
2006-06-27 19:16:27 +00:00
|
|
|
$hResult = query_parameters("SELECT id, url FROM appData
|
|
|
|
|
WHERE id = '?'
|
|
|
|
|
AND type = 'image' LIMIT 1", $iId);
|
2005-07-31 04:23:06 +00:00
|
|
|
$fImage = 0;
|
|
|
|
|
if($hResult)
|
|
|
|
|
{
|
|
|
|
|
$oRow = mysql_fetch_object($hResult);
|
|
|
|
|
|
|
|
|
|
/* we need to use the url field from appData, this is the name of the file */
|
|
|
|
|
/* in the filesystem */
|
2005-07-31 04:35:18 +00:00
|
|
|
$fImage = fopen(appdb_fullpath("data/screenshots/".$oRow->url), "rb");
|
2005-07-31 04:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if the query failed or if we didn't find the image, we should */
|
|
|
|
|
/* report a 404 to the browser */
|
|
|
|
|
if(!$hResult || !$fImage)
|
2005-07-31 03:35:44 +00:00
|
|
|
{
|
|
|
|
|
header("404 No such image");
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
$fstat_val = fstat($fImage);
|
|
|
|
|
$iModTime = $fstat_val['mtime'];
|
|
|
|
|
$sMagic = fread($fImage,8);
|
|
|
|
|
fclose($fImage); /* don't leave the fopened image open */
|
|
|
|
|
/* identify what kind of image this is, if we can't identify it */
|
|
|
|
|
/* we should report that its a bad image */
|
|
|
|
|
if (strcmp("\x89PNG\r\n\x1A\n",$sMagic)==0)
|
|
|
|
|
{
|
|
|
|
|
header("Content-Type: image/png");
|
|
|
|
|
} else if (preg_match("^\xD8\xFF^",$sMagic)) {
|
|
|
|
|
header("Content-Type: image/jpeg");
|
|
|
|
|
} else {
|
|
|
|
|
header("500 Bad image format");
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
header("Cache-Control: public");
|
|
|
|
|
header("Expires: ");
|
|
|
|
|
header("Last-Modified: ".fHttpDate($iModTime));
|
|
|
|
|
}
|
2006-07-06 17:27:54 +00:00
|
|
|
$oScreenshot = new Screenshot($aClean['iId']);
|
2005-07-31 03:35:44 +00:00
|
|
|
|
|
|
|
|
/* at this point, we know that .../screenshots/$id and
|
|
|
|
|
* .../screenshots/thumbnails/$id both exist as normally
|
|
|
|
|
* they would both be created at the same time. */
|
2006-07-06 17:27:54 +00:00
|
|
|
$fstat_val = stat(appdb_fullpath("data/screenshots/".$aClean['iId']));
|
2005-07-31 03:35:44 +00:00
|
|
|
$iModTime = $fstat_val['mtime'];
|
|
|
|
|
|
|
|
|
|
header("Cache-Control: public");
|
|
|
|
|
header("Expires: ");
|
|
|
|
|
|
|
|
|
|
/* if the browser is asking if the file was modified since a particular date */
|
|
|
|
|
/* and the date is the same that the file was modified, then we can report */
|
|
|
|
|
/* that the file wasn't modified, the browser can used the cached image */
|
|
|
|
|
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
|
|
|
|
|
$iModTime == pHttpDate($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
|
|
|
|
{
|
|
|
|
|
header("HTTP/1.0 304 Not Modified");
|
|
|
|
|
exit;
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
2005-07-31 03:35:44 +00:00
|
|
|
|
|
|
|
|
header("Last-Modified: ".fHttpDate($iModTime));
|
|
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
if(!$aClean['bThumbnail'])
|
2005-01-27 15:42:53 +00:00
|
|
|
$oScreenshot->oScreenshotImage->output_to_browser(1);
|
2004-03-25 16:23:42 +00:00
|
|
|
else
|
2005-01-27 15:42:53 +00:00
|
|
|
$oScreenshot->oThumbnailImage->output_to_browser(1);
|
2006-06-17 06:10:10 +00:00
|
|
|
?>
|