|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Avatars; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Text; |
|
7
|
|
|
|
|
8
|
|
|
class InitialsAvatar extends AbstractSvgAvatar |
|
9
|
|
|
{ |
|
10
|
18 |
|
public function generate(string $from): string |
|
11
|
|
|
{ |
|
12
|
18 |
|
$colors = [ |
|
13
|
18 |
|
['background' => '#e3effb', 'color' => '#134d92'], // blue |
|
14
|
18 |
|
['background' => '#e1f0ee', 'color' => '#125960'], // green |
|
15
|
18 |
|
['background' => '#ffeff7', 'color' => '#ba3a80'], // pink |
|
16
|
18 |
|
['background' => '#fcece3', 'color' => '#a14326'], // red |
|
17
|
18 |
|
['background' => '#faf7d9', 'color' => '#da9640'], // yellow |
|
18
|
18 |
|
]; |
|
19
|
18 |
|
$colors = glsr()->filterArray('avatar/colors', $colors); |
|
20
|
18 |
|
shuffle($colors); |
|
21
|
18 |
|
$color = Arr::getAs('array', $colors, 0); |
|
22
|
18 |
|
$data = wp_parse_args($color, [ |
|
23
|
18 |
|
'background' => '#dcdce6', |
|
24
|
18 |
|
'color' => '#6f6f87', |
|
25
|
18 |
|
'text' => $this->filename($from), |
|
26
|
18 |
|
]); |
|
27
|
18 |
|
return trim(glsr()->build('avatar', $data)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
18 |
|
protected function filename(string $from): string |
|
31
|
|
|
{ |
|
32
|
18 |
|
$initials = Text::initials((string) $from); |
|
33
|
18 |
|
if (1 === mb_strlen($initials)) { |
|
34
|
1 |
|
$initials = mb_substr(trim($from), 0, 2, 'UTF-8'); |
|
35
|
1 |
|
$initials = mb_strtoupper($initials, 'UTF-8'); |
|
36
|
|
|
} |
|
37
|
18 |
|
$initials = mb_substr($initials, 0, 2, 'UTF-8'); |
|
38
|
18 |
|
return $initials; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|