show_image.php 3.93 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6
// 
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9 10
// $Id$
  
redflo's avatar
 
redflo committed
11
if (!isset($_REQUEST["nocache"]))
12
	session_cache_limiter('private_no_expire');
13

14 15
//include_once ("tiki-setup_base.php");
include_once ("tiki-setup.php");
lphuberdeau's avatar
lphuberdeau committed
16
$imagegallib = TikiLib::lib('imagegal');
17

18 19 20
// show_image.php
// application to display an image from the database with 
// option to resize the image dynamically creating a thumbnail on the fly.
21
// If a gallery ID is specified gallery's representative image is displayed.
lrargerich's avatar
lrargerich committed
22
// you have to check if the user has permission to see this gallery
23
if ($prefs['feature_galleries'] != 'y') {
24 25 26 27
   header("HTTP/1.0 404 Not Found");
	die;
}

28 29
$id = 0;
if (isset($_REQUEST["name"])) {
30 31 32 33 34
	if (!empty($_REQUEST['galleryId'])) {
		$id=$imagegallib->get_imageid_byname($_REQUEST['name'], $_REQUEST['galleryId']);
	} else {
		$id = $imagegallib->get_imageid_byname($_REQUEST['name']);
	}
35 36
} elseif (isset($_REQUEST["id"])) {
	$id=$_REQUEST["id"];
37
} elseif (isset($_REQUEST["galleryId"])) {
38
	$id=$imagegallib->get_gallery_image($_REQUEST["galleryId"], 'default');
39 40 41
}

if (!$id) {
42
   header("HTTP/1.0 404 Not Found");
43 44 45
	die;
}

46
$galleryId = $imagegallib->get_gallery_from_image($id);
47
$galperms = Perms::get(array( 'type' => 'image gallery', 'object' => $galleryId ));
48

49
if ( ! $galperms->view_image_gallery ) {
50 51 52
    header("HTTP/1.0 404 Not Found");
    die;
}
53

54
$scalesize = 0;
55 56 57

if (isset($_REQUEST["thumb"])) {
	$itype = 't';
58 59 60 61 62 63 64
} elseif (isset($_REQUEST["scalesize"])) {
    if (is_numeric($_REQUEST["scalesize"]) && $_REQUEST["scalesize"] > 0) {
    	$itype = 's';
    	$scalesize = $_REQUEST["scalesize"];
    } else {
    	$itype = 'o';
    }
65
} else {
66 67 68 69 70 71
	$galdef = $imagegallib->get_gallery_default_scale($galleryId);
	if ($galdef =='o') {
    	$itype = 'o';
	} else {
    	$itype = 's';
    	$scalesize = $galdef;
72
	}
73
}
74

75
if ($imagegallib->get_etag($id, $itype, $scalesize)!==false) {
76 77 78 79

# Client-Side image cache (based on Etag Headers)
# Etag value is based on the md5 hash of the image. It should change everytime the image changes. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19

80
#if the client sends the HTTP_IF_NONE_MATCH header(because it received the etag for this image the first time he saw it) we check that the received etag is the same as the actual etag (this is, the image haven't changed) and if it's equal, we send the "Not modified" header(304)
81
  if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $imagegallib->etag) {
82 83 84 85 86
           header("HTTP/1.0 304 Not Modified");
	   exit();
  }
}

87
$imagegallib->get_image($id, $itype, $scalesize);
88
	
redflo's avatar
redflo committed
89
if (!isset($imagegallib->image)) {
90
	// cannot scale image. Get original
91
	$imagegallib->get_image($id, 'o');
redflo's avatar
redflo committed
92 93
}

94 95 96
// do not count if it is a thumbnail or parameter 'nocount' set
// 'nocount' is set by tiki-browse_image to avoid double counting
if ((!isset($_REQUEST["thumb"])) && (!isset($_REQUEST["nocount"]))) {
97
	$imagegallib->add_image_hit($id);
98
}
ohertel's avatar
ohertel committed
99

100
$type = $imagegallib->filetype;
redflo's avatar
redflo committed
101

102 103
// close the session for speedup
session_write_close();
104

105 106
header("Content-type: $type");
header("Etag: ".$imagegallib->etag);
107 108 109 110 111 112

//line commented out by teedog
//I noticed that the browser sometimes sends erroneous "Range:" headers when calling show_image.php
//which makes images fail to load.  It appears that commenting out the "Content-length:" header
//makes this problem go away.  From what I found through Google, "Content-length:" is mostly optional
//so commenting it out should not cause problems.
113
// note that the problem was not so mysterious : 912614
114
// header("Content-length: ".$imagegallib->filesize);
115

116
header("Content-Disposition: inline; filename=\"" . $imagegallib->filename.'"');
117
//if ($data["path"]) {
118
//  readfile($prefs['gal_use_dir'].$data["path"].$ter);
119 120 121
//} else {
echo $imagegallib->image;
//}