mirror of
https://github.com/roundcube/roundcubemail.git
synced 2025-12-28 07:55:07 +00:00
Identicon: Make background color of the image to match the current skin colors (#8256)
This commit is contained in:
parent
cca73cc285
commit
7337e7608e
@ -16,6 +16,7 @@
|
||||
- Add option to control links handling behavior on html to text conversion (#6485)
|
||||
- SMTP: If requested use TLS also without authentication (#4590, #8111)
|
||||
- Enigma: Upgrade to OpenPGP.js v5.0
|
||||
- Identicon: Make background color of the image to match the current skin colors (#8256)
|
||||
- Password: Remove password_blowfish_cost option, in favor of password_algorithm_options
|
||||
- Password: Remove support for password_algorithms crypt, hash and cram-md5
|
||||
- Password: Remove support for %c, %d, %n, %q variables in password_query
|
||||
|
||||
@ -55,7 +55,14 @@ class identicon extends rcube_plugin
|
||||
if ($email) {
|
||||
require_once __DIR__ . '/identicon_engine.php';
|
||||
|
||||
$identicon = new identicon_engine($email);
|
||||
if (!empty($args['attrib']['bg-color'])) {
|
||||
$bgcolor = $args['attrib']['bg-color'];
|
||||
}
|
||||
else {
|
||||
$bgcolor = rcube_utils::get_input_string('_bgcolor', rcube_utils::INPUT_GET);
|
||||
}
|
||||
|
||||
$identicon = new identicon_engine($email, null, $bgcolor);
|
||||
|
||||
if ($rcmail->action == 'show') {
|
||||
// set photo URL using data-uri
|
||||
@ -66,7 +73,6 @@ class identicon extends rcube_plugin
|
||||
}
|
||||
else {
|
||||
// send the icon to the browser
|
||||
$identicon = new identicon_engine($email);
|
||||
if ($identicon->sendOutput()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -34,10 +34,11 @@ class identicon_engine
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $ident Unique identifier (email address)
|
||||
* @param int $size Icon size in pixels
|
||||
* @param string $ident Unique identifier (email address)
|
||||
* @param int $size Icon size in pixels
|
||||
* @param string $bgcolor Icon background color
|
||||
*/
|
||||
public function __construct($ident, $size = null)
|
||||
public function __construct($ident, $size = null, $bgcolor = null)
|
||||
{
|
||||
if (!$size) {
|
||||
$size = self::ICON_SIZE;
|
||||
@ -48,6 +49,18 @@ class identicon_engine
|
||||
$this->width = (int) round(($size - $this->margin * 2) / self::GRID_SIZE) * self::GRID_SIZE + $this->margin * 2;
|
||||
$this->height = $this->width;
|
||||
|
||||
if ($bgcolor) {
|
||||
if (preg_match('/^#?[0-9a-f]{6}$/', $bgcolor)) {
|
||||
if ($bgcolor[0] != '#') {
|
||||
$bgcolor = "#{$bgcolor}";
|
||||
}
|
||||
$this->bgcolor = $bgcolor;
|
||||
}
|
||||
else if ($bgcolor === 'transparent') {
|
||||
$this->bgcolor = $bgcolor;
|
||||
}
|
||||
}
|
||||
|
||||
$this->generate();
|
||||
}
|
||||
|
||||
@ -136,13 +149,20 @@ class identicon_engine
|
||||
*/
|
||||
private function generateGD()
|
||||
{
|
||||
$color = $this->toRGB($this->color);
|
||||
$bgcolor = $this->toRGB($this->bgcolor);
|
||||
|
||||
// create an image, setup colors
|
||||
$image = imagecreate($this->width, $this->height);
|
||||
$color = imagecolorallocate($image, $color[0], $color[1], $color[2]);
|
||||
$bgcolor = imagecolorallocate($image, $bgcolor[0], $bgcolor[1], $bgcolor[2]);
|
||||
$image = imagecreate($this->width, $this->height);
|
||||
|
||||
$color = $this->toRGB($this->color);
|
||||
$color = imagecolorallocate($image, $color[0], $color[1], $color[2]);
|
||||
|
||||
if ($this->bgcolor === 'transparent') {
|
||||
$bgcolor = imagecolorallocatealpha($image, 0, 0, 0, 127);
|
||||
imagesavealpha($image, true);
|
||||
}
|
||||
else {
|
||||
$bgcolor = $this->toRGB($this->bgcolor);
|
||||
$bgcolor = imagecolorallocate($image, $bgcolor[0], $bgcolor[1], $bgcolor[2]);
|
||||
}
|
||||
|
||||
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $bgcolor);
|
||||
|
||||
|
||||
@ -1319,14 +1319,14 @@ class rcmail_action_contacts_index extends rcmail_action
|
||||
$photo_img = 'data:image/gif;base64,' . rcmail_output::BLANK_GIF;
|
||||
}
|
||||
|
||||
|
||||
$rcmail->output->set_env('photo_placeholder', $photo_img);
|
||||
|
||||
unset($attrib['placeholder']);
|
||||
|
||||
$plugin = $rcmail->plugins->exec_hook('contact_photo', [
|
||||
'record' => $record,
|
||||
'data' => $record['photo'] ?? null
|
||||
'data' => $record['photo'] ?? null,
|
||||
'attrib' => $attrib
|
||||
]);
|
||||
|
||||
// check if we have photo data from contact form
|
||||
|
||||
@ -370,6 +370,7 @@ class rcmail_action_mail_show extends rcmail_action_mail_index
|
||||
'_action' => 'photo',
|
||||
'_email' => self::$MESSAGE->sender['mailto'],
|
||||
'_error' => $error_handler ? 1 : null,
|
||||
'_bgcolor' => $attrib['bg-color'] ?? null
|
||||
]);
|
||||
}
|
||||
else {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<div class="contact-header">
|
||||
<div id="contactphoto" class="contact-photo">
|
||||
<roundcube:object name="contactphoto" id="contactpic" placeholder="/images/contactpic.svg"
|
||||
placeholderGroup="/images/contactgroup.svg" />
|
||||
placeholderGroup="/images/contactgroup.svg" bg-color="transparent" />
|
||||
</div>
|
||||
<roundcube:object name="contacthead" id="contacthead" class="contact-head readonly" with-source="true" />
|
||||
</div>
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
<roundcube:endif />
|
||||
</h2>
|
||||
<div class="header">
|
||||
<roundcube:object name="contactphoto" class="contactphoto" placeholder="/images/contactpic.svg" />
|
||||
<roundcube:object name="contactphoto" class="contactphoto" placeholder="/images/contactpic.svg" bg-color="transparent" />
|
||||
<div class="header-content">
|
||||
<roundcube:object name="messageSummary" class="header-summary" addicon="virtual" />
|
||||
<roundcube:object name="messageHeaders" class="header-headers" addicon="virtual" exclude="subject" max="10" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user