forked from Wavyzz/dolibarr
FIX The thumb of user into top menu was using the image in full size.
This make a large download at each page call. We must use the mini thumbs.
This commit is contained in:
@@ -5134,10 +5134,11 @@ class Form
|
|||||||
* @param int $width Width of photo
|
* @param int $width Width of photo
|
||||||
* @param int $height Height of photo (auto if 0)
|
* @param int $height Height of photo (auto if 0)
|
||||||
* @param int $caneditfield Add edit fields
|
* @param int $caneditfield Add edit fields
|
||||||
|
* @param string $imagesize 'mini', 'small' or '' (original)
|
||||||
* @param string $cssclass CSS name to use on img for photo
|
* @param string $cssclass CSS name to use on img for photo
|
||||||
* @return string HTML code to output photo
|
* @return string HTML code to output photo
|
||||||
*/
|
*/
|
||||||
static function showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin')
|
static function showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='')
|
||||||
{
|
{
|
||||||
global $conf,$langs;
|
global $conf,$langs;
|
||||||
|
|
||||||
@@ -5156,7 +5157,12 @@ class Form
|
|||||||
else if ($modulepart=='userphoto')
|
else if ($modulepart=='userphoto')
|
||||||
{
|
{
|
||||||
$dir=$conf->user->dir_output;
|
$dir=$conf->user->dir_output;
|
||||||
if ($object->photo) $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo;
|
if (! empty($object->photo))
|
||||||
|
{
|
||||||
|
if ($imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_mini');
|
||||||
|
else if ($imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'user').getImageFileNameForSize($object->photo, '_small');
|
||||||
|
else $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo;
|
||||||
|
}
|
||||||
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
|
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
|
||||||
$email=$object->email;
|
$email=$object->email;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5118,3 +5118,32 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filename of file to get the thumbs
|
||||||
|
*
|
||||||
|
* @param string $file Original filename
|
||||||
|
* @param string $extName Extension to differenciate thumb file name ('', '_small', '_mini')
|
||||||
|
* @param string $extImgTarget Force image format for thumbs. Use '' to keep same extension than original image.
|
||||||
|
* @return string New file name
|
||||||
|
*/
|
||||||
|
function getImageFileNameForSize($file, $extName, $extImgTarget='')
|
||||||
|
{
|
||||||
|
$dirName = dirname($file);
|
||||||
|
if ($dirName == '.') $dirName='';
|
||||||
|
|
||||||
|
$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file); // On enleve extension quelquesoit la casse
|
||||||
|
$fileName = basename($fileName);
|
||||||
|
|
||||||
|
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i',$file)?'.jpg':'');
|
||||||
|
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'');
|
||||||
|
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i',$file)?'.gif':'');
|
||||||
|
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i',$file)?'.png':'');
|
||||||
|
if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i',$file)?'.bmp':'');
|
||||||
|
|
||||||
|
if (! $extImgTarget) return $file;
|
||||||
|
|
||||||
|
$subdir='';
|
||||||
|
if ($extName) $subdir = 'thumbs/';
|
||||||
|
|
||||||
|
return $dirName.$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
|
||||||
|
}
|
||||||
|
|||||||
@@ -1443,7 +1443,7 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
|
|||||||
|
|
||||||
// User photo
|
// User photo
|
||||||
$toprightmenu.='<div class="inline-block nowrap"><div class="inline-block login_block_elem" style="padding: 0px;">';
|
$toprightmenu.='<div class="inline-block nowrap"><div class="inline-block login_block_elem" style="padding: 0px;">';
|
||||||
$toprightmenu.=$user->getPhotoUrl(16,16,'loginphoto');
|
$toprightmenu.=$user->getPhotoUrl(16,16,'loginphoto','mini');
|
||||||
$toprightmenu.='</div></div>';
|
$toprightmenu.='</div></div>';
|
||||||
|
|
||||||
// Login name with tooltip
|
// Login name with tooltip
|
||||||
|
|||||||
@@ -1813,14 +1813,15 @@ class User extends CommonObject
|
|||||||
* @param int $width Width of image
|
* @param int $width Width of image
|
||||||
* @param int $height Height of image
|
* @param int $height Height of image
|
||||||
* @param string $cssclass Force a css class
|
* @param string $cssclass Force a css class
|
||||||
|
* @param string $imagesize 'mini', 'small' or '' (original)
|
||||||
* @return string String with URL link
|
* @return string String with URL link
|
||||||
*/
|
*/
|
||||||
function getPhotoUrl($width, $height, $cssclass='')
|
function getPhotoUrl($width, $height, $cssclass='', $imagesize='')
|
||||||
{
|
{
|
||||||
$result='';
|
$result='';
|
||||||
|
|
||||||
$result.='<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$this->id.'">';
|
$result.='<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$this->id.'">';
|
||||||
$result.=Form::showphoto('userphoto', $this, $width, $height, 0, $cssclass);
|
$result.=Form::showphoto('userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
|
||||||
$result.='</a>';
|
$result.='</a>';
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
Reference in New Issue
Block a user