Skip to content

Commit 7b38152

Browse files
authored
Merge pull request #15 from iMattPro/registry
Create registry of services in the ACP
2 parents 4c45e8d + 98b7bd7 commit 7b38152

3 files changed

Lines changed: 87 additions & 3 deletions

File tree

adm/style/consentmanager_acp.html

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,52 @@ <h3>{{ lang('WARNING') }}</h3>
3737
</dl>
3838
</fieldset>
3939

40+
<fieldset>
41+
<legend>{{ lang('ACP_CONSENTMANAGER_REGISTRATIONS') }}</legend>
42+
<dl>
43+
<dt><span>{{ lang('ACP_CONSENTMANAGER_REGISTRATIONS_EXPLAIN') }}</span></dt>
44+
<dd>
45+
{% if CONSENTMANAGER_SERVICES %}
46+
{% set services = S_CONSENTMANAGER_MEDIA ? CONSENTMANAGER_SERVICES|merge([{'category': 'media', 'label': 'iframe bbcodes', 'id': 'phpbb.consentmanager'}]) : CONSENTMANAGER_SERVICES %}
47+
{% for category in [
48+
{ id: 'necessary', label: lang('CONSENTMANAGER_CATEGORY_NECESSARY') },
49+
{ id: 'analytics', label: lang('CONSENTMANAGER_CATEGORY_ANALYTICS') },
50+
{ id: 'marketing', label: lang('CONSENTMANAGER_CATEGORY_MARKETING') },
51+
{ id: 'media', label: lang('CONSENTMANAGER_CATEGORY_MEDIA') }
52+
] %}
53+
{% set category_has_services = false %}
54+
{% for service in services if service.category == category.id %}
55+
{% if not category_has_services %}
56+
{% set category_has_services = true %}
57+
<strong>{{ category.label }}</strong>
58+
<ul>
59+
{% endif %}
60+
<li style="font-size: 0.7rem">{{ service.label }} » <em>{{ service.id }}</em></li>
61+
{% endfor %}
62+
{% if category_has_services %}
63+
</ul>
64+
{% endif %}
65+
{% endfor %}
66+
{% else %}
67+
{{ lang('ACP_CONSENTMANAGER_REGISTRATIONS_NONE') }}
68+
{% endif %}
69+
</dd>
70+
</dl>
71+
</fieldset>
72+
4073
<fieldset>
4174
<legend>{{ lang('ACP_CONSENTMANAGER_INTEGRATIONS') }}</legend>
4275
<dl>
4376
<dt><label for="consentmanager_integrations">{{ lang('ACP_CONSENTMANAGER_INTEGRATIONS') ~ lang('COLON') }}</label><br><span>{{ lang('ACP_CONSENTMANAGER_INTEGRATIONS_EXPLAIN') }}</span><br><br>
4477
<span><strong>{{ lang('EXAMPLE') ~ lang('COLON') }}</strong></span><br>
4578
<pre><samp class="error">{{ CONSENTMANAGER_INTEGRATIONS_EXAMPLE }}</samp></pre>
4679
</dt>
47-
<dd><textarea id="consentmanager_integrations" name="consentmanager_integrations" rows="14" cols="90">{{ CONSENTMANAGER_INTEGRATIONS|e('html') }}</textarea></dd>
80+
<dd>
81+
<div style="position: relative; display: inline-block;">
82+
<textarea id="consentmanager_integrations" name="consentmanager_integrations" rows="14" cols="90" style="padding-right: 7.5em; padding-bottom: 1.8em;">{{ CONSENTMANAGER_INTEGRATIONS|e('html') }}</textarea>
83+
<span id="consentmanager_integrations_warning" style="position: absolute; right: 0.8em; bottom: 0.8em; color: #bc2a4d; font-size: 0.85em; font-weight: bold; pointer-events: none; display: none;">{{ lang('ACP_CONSENTMANAGER_INVALID_JSON') }}</span>
84+
</div>
85+
</dd>
4886
</dl>
4987
</fieldset>
5088

@@ -63,4 +101,41 @@ <h3>{{ lang('WARNING') }}</h3>
63101
</fieldset>
64102
</form>
65103

104+
<script>
105+
document.addEventListener('DOMContentLoaded', function() {
106+
var textarea = document.getElementById('consentmanager_integrations');
107+
var warning = document.getElementById('consentmanager_integrations_warning');
108+
109+
if (!textarea || !warning)
110+
{
111+
return;
112+
}
113+
114+
var updateWarning = function() {
115+
var value = textarea.value.trim();
116+
var isValidArray = false;
117+
118+
if (value === '')
119+
{
120+
warning.style.display = 'none';
121+
return;
122+
}
123+
124+
try
125+
{
126+
isValidArray = Array.isArray(JSON.parse(value));
127+
}
128+
catch (error)
129+
{
130+
isValidArray = false;
131+
}
132+
133+
warning.style.display = isValidArray ? 'none' : 'block';
134+
};
135+
136+
textarea.addEventListener('input', updateWarning);
137+
updateWarning();
138+
});
139+
</script>
140+
66141
{% include 'overall_footer.html' %}

language/en/acp_consentmanager.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,24 @@
2727
'ACP_CONSENTMANAGER_MARKETING_EXPLAIN' => 'Allows advertising and marketing integrations to be presented to users and loaded after consent.',
2828
'ACP_CONSENTMANAGER_MEDIA' => 'Enable embedded media category',
2929
'ACP_CONSENTMANAGER_MEDIA_EXPLAIN' => 'Allows videos, players, widgets, and other iframe-based external media to be loaded after consent.',
30-
'ACP_CONSENTMANAGER_INTEGRATIONS' => 'ACP-managed integrations',
31-
'ACP_CONSENTMANAGER_INTEGRATIONS_EXPLAIN' => 'Use this to add simple third-party analytics, marketing, or scripts directly from the ACP instead of through an extension. These entries appear in the consent UI and are only loaded after consent.<br><br>Provide a JSON array of integrations.<br><br>Each object must include: <samp class="error">id</samp>, <samp class="error">category</samp>, <samp class="error">src</samp>. The <samp class="error">id</samp> may only use letters, numbers, dots, underscores, colons, and hyphens. The <samp class="error">category</samp> must be <samp class="error">necessary</samp>, <samp class="error">analytics</samp>, or <samp class="error">marketing</samp>. The <samp class="error">src</samp> must be a valid http, https, or relative script URL.<br><br>Optional fields: <samp class="error">label</samp>, <samp class="error">description</samp>, <samp class="error">async</samp>, <samp class="error">defer</samp>.',
30+
'ACP_CONSENTMANAGER_INTEGRATIONS' => 'Manual integrations',
31+
'ACP_CONSENTMANAGER_INTEGRATIONS_EXPLAIN' => 'Use this to add third-party analytics, marketing, or other scripts directly from the ACP. These integrations appear in the consent UI and are only loaded after the required consent has been granted.<br><br>Provide a JSON array of integrations.<br><br>Each object must include: <samp class="error">id</samp>, <samp class="error">category</samp>, <samp class="error">src</samp>. The <samp class="error">id</samp> may only use letters, numbers, dots, underscores, colons, and hyphens. The <samp class="error">category</samp> must be <samp class="error">necessary</samp>, <samp class="error">analytics</samp>, or <samp class="error">marketing</samp>. The <samp class="error">src</samp> must be a valid http, https, or relative script URL.<br><br>Optional fields: <samp class="error">label</samp>, <samp class="error">description</samp>, <samp class="error">async</samp>, <samp class="error">defer</samp>.',
3232
'ACP_CONSENTMANAGER_INTEGRATIONS_EXAMPLE_LABEL' => 'Example Analytics',
3333
'ACP_CONSENTMANAGER_INTEGRATIONS_EXAMPLE_DESC' => 'Loads a simple analytics library after consent.',
34+
'ACP_CONSENTMANAGER_REGISTRATIONS' => 'Registered integrations',
35+
'ACP_CONSENTMANAGER_REGISTRATIONS_EXPLAIN' => 'These services are registered with Consent Manager and automatically respect consent settings.',
36+
'ACP_CONSENTMANAGER_REGISTRATIONS_NONE' => 'No services are currently registered with Consent Manager.',
3437
'ACP_CONSENTMANAGER_VERSION' => 'Current consent version',
3538
'ACP_CONSENTMANAGER_VERSION_EXPLAIN' => 'Increase the version to force a fresh prompt for every visitor when the consent text or integrations materially change.',
3639
'ACP_CONSENTMANAGER_FORCE_REPROMPT' => 'Force re-prompt',
3740
'ACP_CONSENTMANAGER_REPROMPT_SUCCESS' => 'Consent version increased. Visitors will be asked to review their settings again.',
3841
'ACP_CONSENTMANAGER_INVALID_INTEGRATIONS' => 'The integrations field must contain a valid JSON array.',
3942
'ACP_CONSENTMANAGER_INVALID_INTEGRATION_ENTRY' => 'Integration entry %1$s is invalid. Each entry must include a safe id, supported category, and valid script source URL.',
43+
'ACP_CONSENTMANAGER_INVALID_JSON' => 'Invalid JSON',
44+
'CONSENTMANAGER_CATEGORY_NECESSARY' => 'Necessary',
45+
'CONSENTMANAGER_CATEGORY_ANALYTICS' => 'Analytics',
46+
'CONSENTMANAGER_CATEGORY_MARKETING' => 'Marketing',
47+
'CONSENTMANAGER_CATEGORY_MEDIA' => 'Media',
4048
'EXAMPLE' => 'Example',
4149

4250
// Consent logs

service/acp_manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function get_settings_template_data()
100100
'S_CONSENTMANAGER_MARKETING' => (bool) $this->config['consentmanager_marketing_enabled'],
101101
'S_CONSENTMANAGER_MEDIA' => (bool) $this->config['consentmanager_media_enabled'],
102102
'CONSENTMANAGER_VERSION' => (int) $this->config['consentmanager_consent_version'],
103+
'CONSENTMANAGER_SERVICES' => $this->consent_manager->get_services(),
103104
'CONSENTMANAGER_INTEGRATIONS' => $this->get_integrations_json(),
104105
'CONSENTMANAGER_INTEGRATIONS_EXAMPLE' => $this->get_integrations_example_json(),
105106
];

0 commit comments

Comments
 (0)