mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-04 23:44:33 +02:00
Show user avatar next to its name, in all possible locations
This commit is contained in:
parent
29bce6f19f
commit
97b87dee5f
9 changed files with 143 additions and 47 deletions
|
@ -220,13 +220,6 @@ class UserController extends AdminPages\BaseAdminController
|
|||
return $table->getResponse();
|
||||
}
|
||||
|
||||
if ($this->getParameter('partdb.users.use_gravatar')) {
|
||||
//If no email is existing just set some string to show a gravatar
|
||||
$avatar = $this->getGravatar($user->getEmail() ?? 'partdb', 200, 'identicon');
|
||||
} else {
|
||||
$avatar = $packages->getUrl('/img/default_avatar.png');
|
||||
}
|
||||
|
||||
//Show permissions to user
|
||||
$builder = $this->createFormBuilder()->add('permissions', PermissionsType::class, [
|
||||
'mapped' => false,
|
||||
|
@ -237,42 +230,8 @@ class UserController extends AdminPages\BaseAdminController
|
|||
|
||||
return $this->renderForm('Users/user_info.html.twig', [
|
||||
'user' => $user,
|
||||
'avatar' => $avatar,
|
||||
'form' => $builder->getForm(),
|
||||
'datatable' => $table,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get either a Gravatar URL or complete image tag for a specified email address.
|
||||
*
|
||||
* @param string|null $email The email address
|
||||
* @param int $s Size in pixels, defaults to 80px [ 1 - 2048 ]
|
||||
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
|
||||
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
|
||||
* @param bool $img True to return a complete IMG tag False for just the URL
|
||||
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
|
||||
*
|
||||
* @return string containing either just a URL or a complete image tag
|
||||
* @source https://gravatar.com/site/implement/images/php/
|
||||
*/
|
||||
public function getGravatar(?string $email, int $s = 80, string $d = 'mm', string $r = 'g', bool $img = false, array $atts = []): string
|
||||
{
|
||||
if (null === $email) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = 'https://www.gravatar.com/avatar/';
|
||||
$url .= md5(strtolower(trim($email)));
|
||||
$url .= "?s=${s}&d=${d}&r=${r}";
|
||||
if ($img) {
|
||||
$url = '<img src="'.$url.'"';
|
||||
foreach ($atts as $key => $val) {
|
||||
$url .= ' '.$key.'="'.$val.'"';
|
||||
}
|
||||
$url .= ' />';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue