Skip to content

Commit 597b524

Browse files
Merge pull request #8517 from christianbeeznest/fixes-plugin-showregions01
Plugin: Adapt ShowRegions to rendered Chamilo 2 regions
2 parents 1627e1b + e5b1c84 commit 597b524

4 files changed

Lines changed: 101 additions & 23 deletions

File tree

public/main/admin/settings.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ function getStablePluginAllowList(): array
352352
'Dashboard',
353353
'ExtraMenuFromWebservice',
354354
'Mobidico',
355+
'ShowRegions',
355356
];
356357
}
357358

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
Show Regions plugin
2-
===
1+
# Show regions plugin for Chamilo 2
32

4-
This plugin fills the different regions to make it easier to understand what regions are and where they are located in Chamilo.
3+
Show regions is a small diagnostic plugin that renders a visible marker in each plugin region where it is assigned.
4+
5+
## Purpose
6+
7+
Use this plugin to identify where Chamilo 2 plugin regions are rendered in the current layout.
8+
9+
The marker is shown only to platform administrators. Regular users do not see anything.
10+
11+
## How to use
12+
13+
1. Install and enable the plugin from `Administration > Plugins`.
14+
2. Open `Administration > Settings > Regions`.
15+
3. Assign `Show regions` to one or more regions.
16+
4. Save the settings.
17+
5. Browse the platform as a platform administrator.
18+
19+
Each enabled region displays a small yellow marker with the technical region name.
20+
21+
## Recommended usage
22+
23+
Enable it only while developing or debugging plugin layouts, then remove the assigned regions when finished.
24+
25+
## Security notes
26+
27+
- The output is restricted to platform administrators.
28+
- The region name and request path are escaped before rendering.
29+
- The plugin does not write database records beyond the standard Chamilo plugin region assignment.
30+
- The plugin does not create tables, entities, Vue components or Symfony controllers.
Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,58 @@
11
<?php
22

3-
// Only show the region information if the admin is logged in.
4-
if (api_is_platform_admin()) {
5-
echo '<div style="color:black;height:50px;width:200px;background-color:#FFE378">';
6-
//We can have access to the current block and the block information with the variable $plugin_info (see your plugin.php)
7-
echo $plugin_info['current_region'];
8-
echo '</div>';
3+
/* For licensing terms, see /license.txt */
4+
5+
/**
6+
* Show the current plugin region to platform administrators only.
7+
*
8+
* This file can be included by the plugin region loader or opened directly.
9+
* Direct access bootstraps the legacy environment so the admin check remains
10+
* safe and consistent.
11+
*/
12+
13+
if (!function_exists('api_is_platform_admin')) {
14+
$globalInc = __DIR__.'/../../main/inc/global.inc.php';
15+
16+
if (is_file($globalInc)) {
17+
require_once $globalInc;
18+
}
919
}
20+
21+
if (!function_exists('api_is_platform_admin') || !api_is_platform_admin()) {
22+
if (isset($_SERVER['SCRIPT_FILENAME']) && realpath((string) $_SERVER['SCRIPT_FILENAME']) === __FILE__) {
23+
http_response_code(403);
24+
}
25+
26+
return;
27+
}
28+
29+
$region = '';
30+
31+
if (isset($plugin_info) && is_array($plugin_info)) {
32+
$region = (string) ($plugin_info['current_region'] ?? '');
33+
}
34+
35+
if ('' === $region && isset($_GET['region'])) {
36+
$region = (string) $_GET['region'];
37+
}
38+
39+
$region = preg_replace('/[^a-zA-Z0-9_\-]/', '', $region) ?: 'unknown';
40+
$escapedRegion = htmlspecialchars($region, ENT_QUOTES, 'UTF-8');
41+
$escapedPath = htmlspecialchars((string) ($_SERVER['REQUEST_URI'] ?? ''), ENT_QUOTES, 'UTF-8');
42+
43+
echo <<<HTML
44+
<div class="show-regions-marker my-2 rounded-xl border border-yellow-300 bg-yellow-50 px-4 py-3 text-sm text-yellow-900 shadow-sm" data-show-regions-region="{$escapedRegion}">
45+
<div class="flex flex-wrap items-center gap-2">
46+
<span class="mdi mdi-map-marker-radius-outline text-lg text-yellow-700" aria-hidden="true"></span>
47+
<span class="font-semibold">Plugin region</span>
48+
<code class="rounded-md bg-yellow-100 px-2 py-1 font-mono text-xs text-yellow-900">{$escapedRegion}</code>
49+
<span class="rounded-full bg-yellow-100 px-2 py-0.5 text-xs font-medium text-yellow-800">admin only</span>
50+
</div>
51+
<div class="mt-2 text-xs text-yellow-800">
52+
This marker is generated by the Show regions plugin to help locate Chamilo plugin regions.
53+
</div>
54+
<div class="mt-1 break-all text-[11px] text-yellow-700">
55+
{$escapedPath}
56+
</div>
57+
</div>
58+
HTML;
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
2+
3+
/* For licensing terms, see /license.txt */
4+
25
/**
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).
6+
* Plugin details.
57
*
6-
* @author Julio Montoya <gugli100@gmail.com>
7-
*/
8-
/**
9-
* Plugin details (must be present).
8+
* This plugin intentionally stays as a simple region renderer. It must not be
9+
* marked as an admin plugin because administrators need to assign it to several
10+
* layout regions from the Regions settings page.
1011
*/
1112

12-
//the plugin title
13-
$plugin_info['title'] = 'Show regions';
14-
//the comments that go with the plugin
15-
$plugin_info['comment'] = 'This is useful when trying to find the Chamilo regions, (<strong>only the admin </strong>can view this plugin). You have to activate all the items in the Regions area';
16-
//the plugin version
17-
$plugin_info['version'] = '1.0';
18-
//the plugin author
19-
$plugin_info['author'] = 'Julio Montoya';
13+
$plugin_info = [
14+
'title' => 'Show regions',
15+
'comment' => 'Displays visible markers for enabled plugin regions. Markers are shown only to platform administrators.',
16+
'version' => '2.0.0',
17+
'author' => 'Chamilo',
18+
'source' => 'official',
19+
'commercial_model' => 'free',
20+
'supports_regions' => true,
21+
];

0 commit comments

Comments
 (0)