mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 15:33:23 +01:00
Introduces avatar.php and replaces all addressbook.photo urls accordingly
This commit is contained in:
parent
7c3fa06082
commit
2690ec5053
@ -3186,66 +3186,6 @@ window.egw_LAB.wait(function() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* download photo of the given ($_GET['contact_id'] or $_GET['account_id']) contact
|
||||
*/
|
||||
function photo()
|
||||
{
|
||||
ob_start();
|
||||
$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] :
|
||||
(isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0);
|
||||
|
||||
if (substr($contact_id,0,8) == 'account:')
|
||||
{
|
||||
$contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id,8),'person_id');
|
||||
}
|
||||
if (!($contact = $this->read($contact_id)) ||
|
||||
empty($contact['jpegphoto']) && // LDAP/AD (not updated SQL)
|
||||
!(($contact['files'] & Api\Contacts::FILES_BIT_PHOTO) && // new SQL in VFS
|
||||
($size = filesize($url=Api\Link::vfs_path('addressbook', $contact_id, Api\Contacts::FILES_PHOTO)))))
|
||||
{
|
||||
if (is_array($contact))
|
||||
{
|
||||
echo Api\avatar::lavatar(array(
|
||||
'id' => $contact['id'],
|
||||
'firstname' => $contact['n_given'],
|
||||
'lastname' => $contact['n_family'])
|
||||
);
|
||||
exit();
|
||||
}
|
||||
Egw::redirect(Api\Image::find('addressbook','photo'));
|
||||
}
|
||||
// use an etag over the image mapp
|
||||
$etag = '"'.$contact_id.':'.$contact['etag'].'"';
|
||||
if (!ob_get_contents())
|
||||
{
|
||||
header('Content-type: image/jpeg');
|
||||
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']))
|
||||
{
|
||||
Api\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");
|
||||
}
|
||||
elseif(!empty($contact['jpegphoto']))
|
||||
{
|
||||
header('Content-length: '.bytes($contact['jpegphoto']));
|
||||
echo $contact['jpegphoto'];
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Content-length: '.$size);
|
||||
readfile($url);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate contacts to or from LDAP (called by Admin >> Addressbook >> Site configuration (Admin only)
|
||||
*
|
||||
|
30
api/avatar.php
Normal file
30
api/avatar.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* API: loading user preferences and data
|
||||
*
|
||||
* Usage: /egroupware/api/user.php?user=123
|
||||
*
|
||||
* @link www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package api
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
*/
|
||||
|
||||
use EGroupware\Api;
|
||||
|
||||
// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression
|
||||
ini_set('zlib.output_compression', 0);
|
||||
|
||||
$GLOBALS['egw_info'] = array(
|
||||
'flags' => array(
|
||||
'currentapp' => 'api',
|
||||
'noheader' => true,
|
||||
'nocachecontrol' => true,
|
||||
)
|
||||
);
|
||||
|
||||
include '../header.inc.php';
|
||||
|
||||
$contacts = new Api\Contacts();
|
||||
|
||||
$contacts->photo();
|
@ -361,7 +361,7 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend(
|
||||
set_contact_id: function(_contact_id)
|
||||
{
|
||||
var params = {
|
||||
menuaction: 'addressbook.addressbook_ui.photo'
|
||||
id:''
|
||||
};
|
||||
var id = 'contact_id';
|
||||
|
||||
@ -383,7 +383,7 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend(
|
||||
params[id] = _contact_id;
|
||||
this.image.addClass('et2_avatar');
|
||||
|
||||
var url = egw.link('/index.php',params);
|
||||
var url = egw.link('/api/avatar.php',params);
|
||||
this.set_src(url);
|
||||
},
|
||||
|
||||
|
@ -759,17 +759,16 @@ class Contacts extends Contacts\Storage
|
||||
* @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
|
||||
* @return string
|
||||
*/
|
||||
function photo_src($id,$jpeg,$default='',$etag=null)
|
||||
{
|
||||
//error_log(__METHOD__."($id, ..., etag=$etag) ". function_backtrace());
|
||||
return $jpeg || !$default ? array(
|
||||
'menuaction' => 'addressbook.addressbook_ui.photo',
|
||||
'contact_id' => $id,
|
||||
return $jpeg || !$default ? Egw::link('/api/avatar.php', array(
|
||||
'contact_id' => $id
|
||||
)+(isset($etag) ? array(
|
||||
'etag' => $etag,
|
||||
) : array()) : $default;
|
||||
) : array())) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2585,4 +2584,69 @@ class Contacts extends Contacts\Storage
|
||||
//error_log(__METHOD__.'('.array2string($owner).') returning '.array2string($ctag));
|
||||
return $ctag;
|
||||
}
|
||||
|
||||
/**
|
||||
* download photo of the given ($_GET['contact_id'] or $_GET['account_id']) contact
|
||||
*/
|
||||
function photo()
|
||||
{
|
||||
ob_start();
|
||||
|
||||
$contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] :
|
||||
(isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0);
|
||||
|
||||
if (substr($contact_id,0,8) == 'account:')
|
||||
{
|
||||
$contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id,8),'person_id');
|
||||
}
|
||||
|
||||
$contact = $this->read($contact_id);
|
||||
|
||||
if (!($contact) ||
|
||||
empty($contact['jpegphoto']) && // LDAP/AD (not updated SQL)
|
||||
!(($contact['files'] & \EGroupware\Api\Contacts::FILES_BIT_PHOTO) && // new SQL in VFS
|
||||
($size = filesize($url= \EGroupware\Api\Link::vfs_path('addressbook', $contact_id, \EGroupware\Api\Contacts::FILES_PHOTO)))))
|
||||
{
|
||||
if (is_array($contact))
|
||||
{
|
||||
echo \EGroupware\Api\avatar::lavatar(array(
|
||||
'id' => $contact['id'],
|
||||
'firstname' => $contact['n_given'],
|
||||
'lastname' => $contact['n_family'])
|
||||
);
|
||||
exit();
|
||||
}
|
||||
Egw::redirect(\EGroupware\Api\Image::find('addressbook','photo'));
|
||||
}
|
||||
|
||||
// use an etag over the image mapp
|
||||
$etag = '"'.$contact_id.':'.$contact['etag'].'"';
|
||||
if (!ob_get_contents())
|
||||
{
|
||||
header('Content-type: image/jpeg');
|
||||
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']))
|
||||
{
|
||||
\EGroupware\Api\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");
|
||||
}
|
||||
elseif(!empty($contact['jpegphoto']))
|
||||
{
|
||||
header('Content-length: '.bytes($contact['jpegphoto']));
|
||||
echo $contact['jpegphoto'];
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Content-length: '.$size);
|
||||
readfile($url);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1496,8 +1496,7 @@ abstract class Framework extends Framework\Extra
|
||||
foreach($key_pair as $account_id => $name)
|
||||
{
|
||||
$contact = $contact_obj->read('account:'.$account_id, true);
|
||||
$accounts[] = array('value' => $account_id, 'label' => $name, 'icon' => self::link('/index.php', array(
|
||||
'menuaction' => 'addressbook.addressbook_ui.photo',
|
||||
$accounts[] = array('value' => $account_id, 'label' => $name, 'icon' => self::link('/api/avatar.php', array(
|
||||
'contact_id' => $contact['id'],
|
||||
'etag' => $contact['etag']
|
||||
)));
|
||||
|
@ -70,8 +70,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
|
||||
'value' => ''.$account_id,
|
||||
'label' => $account_name,
|
||||
'app' => lang('api-accounts'),
|
||||
'icon' => Api\Framework::link('/index.php', array(
|
||||
'menuaction' => 'addressbook.addressbook_ui.photo',
|
||||
'icon' => Api\Framework::link('/api/avatar.php', array(
|
||||
'contact_id' => $contact['id'],
|
||||
'etag' => $contact['etag'] ? $contact['etag'] : 1
|
||||
))
|
||||
@ -244,8 +243,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
|
||||
case 'c':
|
||||
case '':
|
||||
$contact = $contacts_obj->read($type === '' ? 'account:'.$id : $id, true);
|
||||
if (is_array($contact)) $value['icon'] = Api\Framework::link('/index.php', array(
|
||||
'menuaction' => 'addressbook.addressbook_ui.photo',
|
||||
if (is_array($contact)) $value['icon'] = Api\Framework::link('/api/avatar.php', array(
|
||||
'contact_id' => $contact['id'],
|
||||
'etag' => $contact['etag'] ? $contact['etag'] : 1
|
||||
));
|
||||
|
@ -214,7 +214,7 @@ class Bo extends So {
|
||||
'setProperties' => array(
|
||||
'fullName' => $GLOBALS['egw_info']['user']['account_fullname'],
|
||||
'color' => $GLOBALS['egw_info']['user']['preferences']['filemanager']['collab_user_color'],
|
||||
'imageUrl' => $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=addressbook.addressbook_ui.photo&account_id='.$use_id,
|
||||
'imageUrl' => $GLOBALS['egw_info']['server']['webserver_url'].'/api/avatar.php?account_id='.$use_id,
|
||||
'uid' => $use_id
|
||||
)
|
||||
)
|
||||
|
@ -79,7 +79,7 @@ class So
|
||||
$color = $GLOBALS['egw_info']['user']['preferences']['filemanager']['collab_user_color'];
|
||||
$user_id = $GLOBALS['egw_info']['user']['account_id'];
|
||||
|
||||
$imageUrl = $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=addressbook.addressbook_ui.photo&account_id='.$user_id;
|
||||
$imageUrl = $GLOBALS['egw_info']['server']['webserver_url'].'/api/avatar.php?account_id='.$user_id;
|
||||
|
||||
if (!($result = self::db2id($query->fetchRow())) && $es_id)
|
||||
{
|
||||
|
@ -3647,8 +3647,7 @@ class mail_compose
|
||||
// Add just name for nice display, with title for hover
|
||||
'name' => $contact['n_fn'],
|
||||
'title' => $email,
|
||||
'icon' => Egw::link('/index.php', array(
|
||||
'menuaction' => 'addressbook.addressbook_ui.photo',
|
||||
'icon' => Egw::link('/api/avatar.php', array(
|
||||
'contact_id' => $contact['id'],
|
||||
'etag' => $contact['etag']
|
||||
))
|
||||
|
@ -400,7 +400,7 @@
|
||||
var $user = jQuery('#egw_fw_userinfo .user');
|
||||
|
||||
var $avatar = jQuery('#egw_fw_userinfo .avatar img');
|
||||
$avatar.attr('src', egw.webserverUrl + '/index.php?menuaction=addressbook.addressbook_ui.photo&account_id=' + egw.user('account_id'));
|
||||
$avatar.attr('src', egw.webserverUrl + '/api/avatar.php?account_id=' + egw.user('account_id'));
|
||||
|
||||
var $sidebar = jQuery('#egw_fw_sidebar');
|
||||
$sidebar.removeClass('avatarSubmenu');
|
||||
|
Loading…
Reference in New Issue
Block a user