Skip to content

Commit a1164f9

Browse files
Merge pull request #8466 from christianbeeznest/fixes-plugin-showuserinfo01
Plugin: Integrate ShowUserInfo plugin
2 parents 728b532 + f83a7fc commit a1164f9

7 files changed

Lines changed: 105 additions & 63 deletions

File tree

public/main/admin/settings.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ function getStablePluginAllowList(): array
325325
'CourseHomeNotify',
326326
'CourseLegal',
327327
'Static',
328+
'ShowUserInfo',
328329
];
329330
}
330331

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<?php
2-
// A user must be logged in.
3-
$_template['show_message'] = false;
42

5-
if (!api_is_anonymous()) {
6-
$_template['show_message'] = true;
3+
/* For licensing terms, see /license.txt */
74

8-
// Getting the current user id.
9-
$user_id = api_get_user_id();
5+
/**
6+
* Region entry point.
7+
*
8+
* AppPlugin::getAllPluginContentsByRegion() executes this file for the configured region.
9+
* The visible output must be printed directly from index.php, following the Static plugin pattern.
10+
*/
1011

11-
//Getting the current user info.
12-
$user_info = api_get_user_info($user_id);
12+
require_once __DIR__.'/lib/show_user_info_plugin.class.php';
1313

14-
// You can also use template setting variables in the special variable called template.
15-
$_template['user_info'] = $user_info;
16-
$_template['username'] = $user_info['username'];
17-
}
14+
echo ShowUserInfoPlugin::create()->renderUserBlock();
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<?php
22

3-
$strings['WelcomeToChamiloUserX'] = "Welcome to Chamilo %s!";
3+
$strings['plugin_title'] = 'Show user information';
4+
$strings['plugin_comment'] = 'Shows a welcome message with the current user name in selected plugin regions.';
5+
$strings['UserInformation'] = 'User information';
6+
$strings['SignedInAs'] = 'Signed in to the platform';
7+
$strings['WelcomeUserX'] = 'Welcome, %s';
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<?php
22

3-
$strings['WelcomeToChamiloUserX'] = "Bienvenido a Chamilo %s!";
3+
$strings['plugin_title'] = 'Mostrar información del usuario';
4+
$strings['plugin_comment'] = 'Muestra un mensaje de bienvenida con el nombre del usuario actual en las regiones configuradas del plugin.';
5+
$strings['UserInformation'] = 'Información del usuario';
6+
$strings['SignedInAs'] = 'Sesión iniciada en la plataforma';
7+
$strings['WelcomeUserX'] = 'Bienvenido, %s';
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
<?php
2-
/**
3-
* This script is a configuration file for the date plugin. You can use it as a master for other platform plugins (course plugins are slightly different).
4-
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins).
5-
*
6-
* @package chamilo.plugin
7-
*
8-
* @author Julio Montoya <gugli100@gmail.com>
9-
*/
10-
/**
11-
* Plugin details (must be present).
12-
*/
132

14-
// The plugin title
15-
$plugin_info['title'] = 'Show user information';
16-
// The comments that go with the plugin
17-
$plugin_info['comment'] = "Shows a welcome message, (this is an example to uses the template system: Twig)";
18-
// The plugin version
19-
$plugin_info['version'] = '1.0';
20-
// The plugin author
21-
$plugin_info['author'] = 'Julio Montoya';
22-
// Set the templates that are going to be used
23-
$plugin_info['templates'] = ['template.tpl'];
3+
/* For licensing terms, see /license.txt */
4+
5+
require_once __DIR__.'/lib/show_user_info_plugin.class.php';
6+
7+
$plugin_info = ShowUserInfoPlugin::create()->get_info();
Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
{#
2-
This is a Chamilo plugin using Twig you can use these handy shorcuts like:
3-
4-
1. Shortcuts
5-
6-
_p = url chamilo paths
7-
app.user = user information of the current user
8-
9-
2. i18n
10-
11-
You can use i18n variables just use this syntax:
12-
13-
{{ "HelloWorld"|get_lang }}
14-
15-
Now you can add your variables in the main/lang/english/ or main/lang/spanish/ for example in spanish:
16-
$HelloWorld = "Hola Mundo";
17-
18-
3. Portal settings
19-
You can access the portal settings using:
20-
{{ "siteName"|api_get_setting }}
21-
For more settings check the settings_current database table
22-
4. Read more
23-
You can also see more examples in main/template/default/layout
2+
Kept only for backward compatibility with older plugin renderers.
3+
The current Chamilo region renderer executes index.php, and index.php prints
4+
the visible output directly, matching the Static plugin pattern.
245
#}
25-
26-
{% if show_user_info.show_message is not null and is_granted('IS_AUTHENTICATED_FULLY') %}
27-
<div class="well">
28-
{{ "WelcomeToChamiloUserX" | get_lang | format(show_user_info.user_info.complete_name) }}
29-
</div>
30-
{% endif %}

0 commit comments

Comments
 (0)