-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoot.php
More file actions
76 lines (60 loc) · 3.11 KB
/
Copy pathBoot.php
File metadata and controls
76 lines (60 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace Plugins\EventRegistration;
use App\Component\Hook\HookManager;
use Magepattern\Component\Tool\SmartyTool;
use Plugins\EventRegistration\db\EventAdminDb;
use Plugins\EventRegistration\db\EventFrontDb;
class Boot
{
public function register(): void
{
$module = 'news';
$idKey = 'id_news';
// --- BACKEND : Injection de l'onglet dans l'administration des News ---
HookManager::register("{$module}_edit_tab", 'EventRegistration', function(array $params) {
$smarty = SmartyTool::getInstance('admin');
$file = ROOT_DIR . 'plugins' . DS . 'EventRegistration' . DS . 'views' . DS . 'admin' . DS . 'hooks' . DS . 'tab_button.tpl';
return $smarty->templateExists($file) ? $smarty->fetch($file) : '';
});
HookManager::register("{$module}_edit_content", 'EventRegistration', function(array $params) use ($idKey) {
$smarty = SmartyTool::getInstance('admin');
$idNews = (int)($params[$idKey] ?? 0);
if ($idNews <= 0) return '';
$db = new EventAdminDb();
$smarty->assign([
'id_news' => $idNews,
'event_config' => $db->getEventConfig($idNews),
'hashtoken' => $smarty->getTemplateVars('hashtoken')
]);
$file = ROOT_DIR . 'plugins' . DS . 'EventRegistration' . DS . 'views' . DS . 'admin' . DS . 'hooks' . DS . 'tab_content.tpl';
return $smarty->templateExists($file) ? $smarty->fetch($file) : '';
});
// --- FRONTEND : Injection du formulaire sur le site public ---
HookManager::register('displayNewsBottom', 'EventRegistration', ['\Plugins\EventRegistration\src\FrontendController', 'renderForm']);
// --- OPTIMISATION : Contrôle conditionnel du Google reCAPTCHA ---
if (class_exists('\Plugins\GoogleRecaptcha\src\FrontendController')) {
\Plugins\GoogleRecaptcha\src\FrontendController::addInjectCondition(function(string $currentModule) use ($module) {
// On ne gère le veto que si reCAPTCHA s'apprête à charger sur notre module concerné
if ($currentModule !== $module) {
return true;
}
// Récupération de l'ID courant passé dans l'URL par le routeur
$idItem = (int)($_GET['id'] ?? 0);
// Si pas d'ID, on est sur une liste de news. On n'intervient pas.
if ($idItem <= 0) {
return true;
}
// On vérifie en base si cet événement précis nécessite le formulaire
$db = new EventFrontDb();
$config = $db->getEventConfig($idItem);
// VETO : Si l'inscription est désactivée (ou inexistante), on bloque l'injection du script
if (empty($config) || (int)$config['registration_enabled'] !== 1) {
return false;
}
// Tout est ok, le formulaire va s'afficher, on autorise reCAPTCHA
return true;
});
}
}
}