mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-29 11:23:54 +01:00
let browser cache images
This commit is contained in:
parent
e2c8bb4425
commit
819fdea809
@ -681,7 +681,7 @@ class addressbook_bo extends addressbook_so
|
||||
$data[$name] = egw_time::server2user($data[$name], $date_format);
|
||||
}
|
||||
}
|
||||
$data['photo'] = $this->photo_src($data['id'],$data['jpegphoto']);
|
||||
$data['photo'] = $this->photo_src($data['id'],$data['jpegphoto'],'',$data['etag']);
|
||||
|
||||
// set freebusy_uri for accounts
|
||||
if (!$data['freebusy_uri'] && !$data['owner'] && $data['account_id'] && !is_object($GLOBALS['egw_setup']))
|
||||
@ -701,14 +701,18 @@ class addressbook_bo extends addressbook_so
|
||||
* @param int $id contact_id
|
||||
* @param boolean $jpeg=false jpeg exists or not
|
||||
* @param string $default='' image-name to use if !$jpeg, eg. 'template'
|
||||
* @param string $etag=null etag to set in url to allow caching with Expires header
|
||||
* @return string/array
|
||||
*/
|
||||
function photo_src($id,$jpeg,$default='')
|
||||
function photo_src($id,$jpeg,$default='',$etag=null)
|
||||
{
|
||||
error_log(__METHOD__."($id, ..., etag=$etag) ". function_backtrace());
|
||||
return $jpeg ? array(
|
||||
'menuaction' => 'addressbook.addressbook_ui.photo',
|
||||
'contact_id' => $id,
|
||||
) : $default;
|
||||
)+(isset($etag) ? array(
|
||||
'etag' => $etag,
|
||||
) : array()) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1982,7 +1982,7 @@ window.egw_LAB.wait(function() {
|
||||
// Enable history
|
||||
$this->setup_history($content, $sel_options);
|
||||
|
||||
$content['photo'] = $this->photo_src($content['id'],$content['jpegphoto'],'photo');
|
||||
$content['photo'] = $this->photo_src($content['id'],$content['jpegphoto'],'photo',$content['etag']);
|
||||
|
||||
if ($content['private']) $content['owner'] .= 'p';
|
||||
|
||||
@ -2392,12 +2392,29 @@ window.egw_LAB.wait(function() {
|
||||
{
|
||||
egw::redirect(common::image('addressbook','photo'));
|
||||
}
|
||||
// use an etag over the image mapp
|
||||
$etag = '"'.$contact['id'].':'.$contact['etag'].'"';
|
||||
if (!ob_get_contents())
|
||||
{
|
||||
header('Content-type: image/jpeg');
|
||||
header('Content-length: '.(extension_loaded(mbstring) ? mb_strlen($contact['jpegphoto'],'ascii') : strlen($contact['jpegphoto'])));
|
||||
header('ETag: '.$etag);
|
||||
// if etag parameter given in url, we can allow browser to cache picture via an Expires header
|
||||
// different url with different etag parameter will force a reload
|
||||
if (isset($_GET['etag']))
|
||||
{
|
||||
egw_session::cache_control(30*86400); // cache for 30 days
|
||||
}
|
||||
// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
|
||||
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag)
|
||||
{
|
||||
header("HTTP/1.1 304 Not Modified");
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Content-length: '.bytes($contact['jpegphoto']));
|
||||
echo $contact['jpegphoto'];
|
||||
exit;
|
||||
}
|
||||
common::egw_exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user