|
1 | 1 | <?php |
2 | 2 |
|
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 | + } |
9 | 19 | } |
| 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; |
0 commit comments