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..811efda 100644 --- a/event/listener.php +++ b/event/listener.php @@ -20,18 +20,25 @@ class listener implements EventSubscriberInterface /** @var \phpbb\config\config $config Config object */ protected $config; + protected $language; + /** @var \phpbb\template\template $template Template object */ protected $template; + /** @var string|null Cached VigLink API key */ + protected $viglink_key; + /** * 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 +49,7 @@ public static function getSubscribedEvents() { return array( 'core.viewtopic_post_row_after' => 'display_viglink', + 'phpbb.consentmanager.collect_registrations' => 'register_viglink', ); } @@ -52,6 +60,44 @@ public static function getSubscribedEvents() */ 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() + { + if ($this->viglink_key !== null) + { + return $this->viglink_key; + } + $viglink_key = ''; if ($this->config['allow_viglink_phpbb'] && $this->config['phpbb_viglink_api_key']) @@ -60,10 +106,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 $this->viglink_key = $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 %} -