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.
26 lines
1.4 KiB
PHP
26 lines
1.4 KiB
PHP
<?php
|
|
|
|
$snippet = \Plugi\Setting::get('ext--tracking--head') ?? '';
|
|
?>
|
|
<section class="card border border-base-300/60 bg-base-100 shadow-sm" aria-labelledby="tracking-settings-title">
|
|
<div class="card-body gap-5 p-4 sm:p-6 lg:p-8">
|
|
<div>
|
|
<h2 class="card-title text-xl" id="tracking-settings-title">Tracking snippet</h2>
|
|
<p class="mt-1 text-sm text-base-content/60">Add one HTML or JavaScript snippet to the public page head.</p>
|
|
</div>
|
|
<div class="alert alert-warning" role="alert">
|
|
<i class="ph ph-warning-circle" aria-hidden="true"></i>
|
|
<span>Saved code is inserted as-is and executes on every public page. Only save code you trust.</span>
|
|
</div>
|
|
<form method="post" action="<?= phpb_e(phpb_full_url('/ext--tracking/save')) ?>" class="space-y-4">
|
|
<?php phpb_csrf_field(); ?>
|
|
<div class="form-control w-full">
|
|
<label class="label" for="tracking-snippet">
|
|
<span class="label-text">HTML / JavaScript</span>
|
|
</label>
|
|
<textarea id="tracking-snippet" name="snippet" rows="14" spellcheck="false" class="textarea textarea-bordered w-full font-mono"><?= phpb_e($snippet) ?></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save snippet</button>
|
|
</form>
|
|
</div>
|
|
</section>
|