Adds a new extension allowing injection of custom code into the page head. Includes an admin interface for saving snippets, secure save routes with CSRF protection, and tests verifying the functionality. Also updates core Extensions.php to support callable HTML blocks for lazy evaluation.
22 lines
639 B
PHP
22 lines
639 B
PHP
<?php
|
|
|
|
phpb_requires_authenticated();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !phpb_validate_csrf()) {
|
|
http_response_code(403);
|
|
exit('Forbidden');
|
|
}
|
|
|
|
if (!isset($_POST['snippet']) || !is_string($_POST['snippet'])) {
|
|
http_response_code(400);
|
|
exit('Invalid snippet');
|
|
}
|
|
|
|
$saved = (new \Plugi\Repositories\SettingRepository())->updateSettings([
|
|
'ext--tracking--head' => $_POST['snippet'],
|
|
]);
|
|
|
|
phpb_redirect(phpb_url('website_manager', ['tab' => 'ext--tracking']), [
|
|
'message-type' => $saved ? 'success' : 'error',
|
|
'message' => $saved ? 'Tracking snippet saved.' : 'Tracking snippet could not be saved.',
|
|
]); |