|
| 1 | +<?php |
| 2 | + |
| 3 | +/* For licensing terms, see /license.txt */ |
| 4 | + |
| 5 | +/** |
| 6 | + * Plugin that displays the current user's name in configured plugin regions. |
| 7 | + */ |
| 8 | +class ShowUserInfoPlugin extends Plugin |
| 9 | +{ |
| 10 | + protected function __construct() |
| 11 | + { |
| 12 | + parent::__construct( |
| 13 | + '1.2', |
| 14 | + 'Julio Montoya', |
| 15 | + [] |
| 16 | + ); |
| 17 | + } |
| 18 | + |
| 19 | + public static function create(): self |
| 20 | + { |
| 21 | + static $result = null; |
| 22 | + |
| 23 | + return $result ?: $result = new self(); |
| 24 | + } |
| 25 | + |
| 26 | + public function get_info(): array |
| 27 | + { |
| 28 | + $info = parent::get_info(); |
| 29 | + $info['title'] = $this->get_lang('plugin_title'); |
| 30 | + $info['comment'] = $this->get_lang('plugin_comment'); |
| 31 | + $info['supports_regions'] = true; |
| 32 | + |
| 33 | + return $info; |
| 34 | + } |
| 35 | + |
| 36 | + public function renderRegion($region): string |
| 37 | + { |
| 38 | + return $this->renderUserBlock(); |
| 39 | + } |
| 40 | + |
| 41 | + public function renderUserBlock(): string |
| 42 | + { |
| 43 | + if (api_is_anonymous()) { |
| 44 | + return ''; |
| 45 | + } |
| 46 | + |
| 47 | + $userId = api_get_user_id(); |
| 48 | + |
| 49 | + if (empty($userId)) { |
| 50 | + return ''; |
| 51 | + } |
| 52 | + |
| 53 | + $userInfo = api_get_user_info($userId); |
| 54 | + |
| 55 | + if (empty($userInfo) || empty($userInfo['complete_name'])) { |
| 56 | + return ''; |
| 57 | + } |
| 58 | + |
| 59 | + $completeName = Security::remove_XSS((string) $userInfo['complete_name']); |
| 60 | + $title = Security::remove_XSS($this->get_lang('UserInformation')); |
| 61 | + $label = Security::remove_XSS($this->get_lang('SignedInAs')); |
| 62 | + $message = Security::remove_XSS(sprintf($this->get_lang('WelcomeUserX'), $completeName)); |
| 63 | + |
| 64 | + return '<section class="show-user-info-plugin rounded-2xl border border-gray-25 bg-white p-4 shadow-sm">' |
| 65 | + .'<div class="flex items-center gap-4">' |
| 66 | + .'<div class="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-primary/10">' |
| 67 | + .'<span class="mdi mdi-account-circle ch-tool-icon text-2xl" aria-hidden="true"></span>' |
| 68 | + .'</div>' |
| 69 | + .'<div class="min-w-0">' |
| 70 | + .'<p class="m-0 text-xs font-semibold uppercase tracking-wide text-gray-50">'.$title.'</p>' |
| 71 | + .'<p class="m-0 text-base font-semibold text-gray-90">'.$message.'</p>' |
| 72 | + .'<p class="m-0 text-sm text-gray-50">'.$label.'</p>' |
| 73 | + .'</div>' |
| 74 | + .'</div>' |
| 75 | + .'</section>'; |
| 76 | + } |
| 77 | +} |
0 commit comments