From 0f82094bb126ee7c7fce314416af96729dbfdba9 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 22 Apr 2026 10:43:45 -0700 Subject: [PATCH 1/3] Support for consent manager --- config/services.yml | 1 + event/listener.php | 46 +++++++++++++-- language/en/viglink_common.php | 43 ++++++++++++++ .../template/event/overall_footer_after.html | 2 +- tests/event/listener_test.php | 59 +++++++++++++++++++ 5 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 language/en/viglink_common.php diff --git a/config/services.yml b/config/services.yml index 75cae88..d4a3f58 100644 --- a/config/services.yml +++ b/config/services.yml @@ -6,6 +6,7 @@ services: class: phpbb\viglink\event\listener arguments: - '@config' + - '@language' - '@template' tags: - { name: event.listener } diff --git a/event/listener.php b/event/listener.php index 63e0855..522b1fe 100644 --- a/event/listener.php +++ b/event/listener.php @@ -20,6 +20,8 @@ class listener implements EventSubscriberInterface /** @var \phpbb\config\config $config Config object */ protected $config; + protected $language; + /** @var \phpbb\template\template $template Template object */ protected $template; @@ -27,11 +29,13 @@ class listener implements EventSubscriberInterface * Constructor * * @param \phpbb\config\config $config Config object + * @param \phpbb\language\language $language Language object * @param \phpbb\template\template $template Template object */ - public function __construct(\phpbb\config\config $config, \phpbb\template\template $template) + public function __construct(\phpbb\config\config $config, \phpbb\language\language $language, \phpbb\template\template $template) { $this->config = $config; + $this->language = $language; $this->template = $template; } @@ -42,6 +46,7 @@ public static function getSubscribedEvents() { return array( 'core.viewtopic_post_row_after' => 'display_viglink', + 'phpbb.consentmanager.collect_registrations' => 'register_viglink', ); } @@ -51,6 +56,39 @@ public static function getSubscribedEvents() * @return void */ public function display_viglink() + { + $viglink_key = $this->get_viglink_key(); + + $this->template->assign_vars(array( + 'VIGLINK_ENABLED' => $this->config['viglink_enabled'] && $viglink_key, + 'VIGLINK_API_KEY' => $viglink_key, + 'VIGLINK_SUB_ID' => md5(urlencode($this->config['viglink_api_siteid']) . $this->config['questionnaire_unique_id']), + )); + } + + /** + * Register Viglink with Consent Manager when available. + * + * @param \phpbb\event\data|array $event The event object or event data + * @return void + */ + public function register_viglink($event) + { + if (!$this->config['viglink_enabled'] || empty($this->get_viglink_key())) + { + return; + } + + $this->language->add_lang('viglink_common', 'phpbb/viglink'); + + $event['consent_manager']->register('phpbb.viglink', [ + 'label' => $this->language->lang('VIGLINK'), + 'category' => 'marketing', + 'description' => $this->language->lang('VIGLINK_DESCRIPTION'), + ]); + } + + protected function get_viglink_key() { $viglink_key = ''; @@ -60,10 +98,6 @@ public function display_viglink() $viglink_key = $this->config['phpbb_viglink_api_key']; } - $this->template->assign_vars(array( - 'VIGLINK_ENABLED' => $this->config['viglink_enabled'] && $viglink_key, - 'VIGLINK_API_KEY' => $viglink_key, - 'VIGLINK_SUB_ID' => md5(urlencode($this->config['viglink_api_siteid']) . $this->config['questionnaire_unique_id']), - )); + return $viglink_key; } } diff --git a/language/en/viglink_common.php b/language/en/viglink_common.php new file mode 100644 index 0000000..560c968 --- /dev/null +++ b/language/en/viglink_common.php @@ -0,0 +1,43 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + */ + +/** + * DO NOT CHANGE + */ +if (!defined('IN_PHPBB')) +{ + exit; +} + +if (empty($lang) || !is_array($lang)) +{ + $lang = array(); +} + +// DEVELOPERS PLEASE NOTE +// +// All language files should use UTF-8 as their encoding and the files must not contain a BOM. +// +// Placeholders can now contain order information, e.g. instead of +// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows +// translators to re-order the output of data while ensuring it remains correct +// +// You do not need this where single placeholders are used, e.g. 'Message %d' is fine +// equally where a string contains only two placeholders which are used to wrap text +// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine +// +// Some characters you may want to copy&paste: +// ’ » “ ” … +// + +$lang = array_merge($lang, array( + 'VIGLINK' => 'VigLink', + 'VIGLINK_DESCRIPTION' => 'Uses third‑party cookies to personalise content and enable site monetisation.', +)); diff --git a/styles/all/template/event/overall_footer_after.html b/styles/all/template/event/overall_footer_after.html index fc983ef..841ee99 100644 --- a/styles/all/template/event/overall_footer_after.html +++ b/styles/all/template/event/overall_footer_after.html @@ -1,5 +1,5 @@ {% if VIGLINK_ENABLED %} -