diff --git a/CHANGELOG.md b/CHANGELOG.md index f21e518..ac61855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.0 - 2026-02-16 + +- add privacy information + ## 1.0.7 - 2026-01-13 - add french translation diff --git a/composer.json b/composer.json index a971723..dcfa48f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "phpbb-extension", "description": "A extention to allow easy integration of the matomo tracking code. Forked from the official phpbb-googleanalytics extention.", "homepage": "https://github.com/Cube707/phpbb-matomoanalytics", - "version": "1.0.7", + "version": "1.1.0", "keywords": ["phpbb", "extension", "matomo", "analytics"], "license": "GPL-2.0-only", "authors": [ diff --git a/event/listener.php b/event/listener.php index 79a8875..e9cbfb6 100644 --- a/event/listener.php +++ b/event/listener.php @@ -60,9 +60,10 @@ public function __construct(config $config, language $language, template $templa public static function getSubscribedEvents() { return [ - 'core.acp_board_config_edit_add' => 'add_matomoanalytics_configs', 'core.page_header' => 'load_matomoanalytics', + 'core.acp_board_config_edit_add' => 'add_matomoanalytics_configs', 'core.validate_config_variable' => 'validate_matomoanalytics_url', + 'core.page_footer_after' => 'append_agreement', ]; } @@ -159,4 +160,24 @@ public function validate_matomoanalytics_url($event) // Update error event data $event['error'] = $error; } + + /** + * Append additional agreement details to the privacy agreement. + * + * @return void + */ + public function append_agreement() + { + if (!$this->config['matomoanalytics_enabled'] + || (strpos($this->user->page['page_name'], 'ucp') !== 0) + || !$this->template->retrieve_var('S_AGREEMENT') + || ($this->template->retrieve_var('AGREEMENT_TITLE') !== $this->language->lang('PRIVACY'))) + { + return; + } + + $this->language->add_lang('googleanalytics_ucp', 'cube/matomoanalytics'); + + $this->template->append_var('AGREEMENT_TEXT', $this->language->lang('PHPBB_ANALYTICS_PRIVACY_POLICY', $this->config['sitename'])); + } } diff --git a/language/de/matomoanalytics_ucp.php b/language/de/matomoanalytics_ucp.php new file mode 100644 index 0000000..d4ce77b --- /dev/null +++ b/language/de/matomoanalytics_ucp.php @@ -0,0 +1,47 @@ + +* @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 = []; +} + +// 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, [ + 'PHPBB_ANALYTICS_PRIVACY_POLICY' => ' +

Website Analytics (Matomo)

+

Der Betreiber benutzt den Open Source Webanalysedienst Matomo um Besucherdaten zu messen, zu sammeln, zu analysieren und auszuwerten, mit dem Ziel, unsere Website besser zu verstehen und zu optimieren.

+

Die durch Matomo erfassten Informationen über die Benutzung von „%1$s“ werden auf unserem Server gespeichert. Die IP-Adresse wird vor der Speicherung anonymisiert.

+

Du kannst dem sammelen von Nutzungsinformationen wiedersprechen, indem du im folgenden die checkbox entfernst:

+
', +]); diff --git a/language/en/matomoanalytics_ucp.php b/language/en/matomoanalytics_ucp.php new file mode 100644 index 0000000..c8cceb0 --- /dev/null +++ b/language/en/matomoanalytics_ucp.php @@ -0,0 +1,50 @@ + +* @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 = []; +} + +// 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, [ + 'PHPBB_ANALYTICS_PRIVACY_POLICY' => ' +

+ Website Analytics (Matomo)
+ We use Matomo Analytics to measure, collect, analyse and report visitors’ data for purposes of understanding and optimising our website. +
+ The Informationen the usage of “%1$s” collected by Matomo is stored on our servers. IP-adresses are anonymized before beeing stored. +
+ You can opt out of Matomo by unchecking the following checkbox: +
', +]); diff --git a/language/fr/matomoanalytics_ucp.php b/language/fr/matomoanalytics_ucp.php new file mode 100644 index 0000000..0d80d7c --- /dev/null +++ b/language/fr/matomoanalytics_ucp.php @@ -0,0 +1,49 @@ + +* @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 = []; +} + +// 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, [ + 'PHPBB_ANALYTICS_PRIVACY_POLICY' => ' +

+ Analyse du trafic sur le site (Matomo)
+ Nous utilisons Matomo Analytics comme silution pour mesurer, collecter, analyser et présenter les données des visiteurs afin de comprendre et d\'optimiser notre site web. +
+ Les informations relatives à l\'utilisation de "%1$s" collectées par Matomo sont stockées sur nos serveurs. Les adresses IP sont anonymisées avant d\'être stockées. +
+ Vous pouvez désactiver Matomo en décochant la case suivante:
', +]); diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index 80f3827..7cbeef5 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -10,8 +10,6 @@ namespace cube\matomoanalytics\tests\event; -require_once __DIR__ . '/../../../../../includes/functions_acp.php'; - class listener_test extends \phpbb_test_case { /** @var \cube\matomoanalytics\event\listener */ @@ -21,7 +19,7 @@ class listener_test extends \phpbb_test_case protected $config; /** @var \phpbb\language\language */ - protected $lang; + protected $language; /** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\template\template */ protected $template; @@ -29,6 +27,15 @@ class listener_test extends \phpbb_test_case /** @var \phpbb\user */ protected $user; + public static function setUpBeforeClass(): void + { + $acp_functions = __DIR__ . '/../../../../../includes/functions_acp.php'; + if (is_file($acp_functions)) + { + require_once $acp_functions; + } + } + /** * Setup test environment */ @@ -47,8 +54,8 @@ protected function setUp(): void $this->template = $this->getMockBuilder('\phpbb\template\template') ->getMock(); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); - $this->lang = new \phpbb\language\language($lang_loader); - $this->user = new \phpbb\user($this->lang, '\phpbb\datetime'); + $this->language = new \phpbb\language\language($lang_loader); + $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); $this->user->data['user_id'] = 2; $this->user->data['is_registered'] = true; } @@ -60,7 +67,7 @@ protected function set_listener() { $this->listener = new \cube\matomoanalytics\event\listener( $this->config, - $this->lang, + $this->language, $this->template, $this->user ); @@ -81,9 +88,10 @@ public function test_construct() public function test_getSubscribedEvents() { self::assertEquals([ - 'core.acp_board_config_edit_add', 'core.page_header', + 'core.acp_board_config_edit_add', 'core.validate_config_variable', + 'core.page_footer_after', ], array_keys(\cube\matomoanalytics\event\listener::getSubscribedEvents())); } @@ -152,7 +160,7 @@ public function test_add_matomoanalytics_configs($mode, $display_vars, $expected $event_data = ['display_vars', 'mode']; $event_data_after = $dispatcher->trigger_event('core.acp_board_config_edit_add', compact($event_data)); - extract($event_data_after, EXTR_OVERWRITE); + extract($event_data_after); $keys = array_keys($display_vars['vars']); @@ -233,8 +241,56 @@ public function test_validate_matomoanalytics_url($cfg_array, $expected_error) { self::assertArrayHasKey($expected, $event_data_after); } - extract($event_data_after, EXTR_OVERWRITE); + extract($event_data_after); self::assertEquals($expected_error, $error); } + + /** + * Data for test_append_agreement + * + * @return array + */ + public function append_agreement_data() + { + return [ + [false, 'PRIVACY', 0], // No agreement + [true, 'TERMS', 0], // Wrong title + [true, 'PRIVACY', 1], // Correct conditions + ]; + } + + /** + * Test the append_agreement method + * + * @dataProvider append_agreement_data + * @param mixed $s_agreement S_AGREEMENT template variable value + * @param mixed $agreement_title AGREEMENT_TITLE template variable value + * @param int $expected_append_calls Expected append_var calls + */ + public function test_append_agreement($s_agreement, $agreement_title, $expected_append_calls) + { + $this->config['sitename'] = 'Test Forum'; + $this->user->page['page_name'] = 'ucp.php'; + + $this->template->expects(self::atMost(2)) + ->method('retrieve_var') + ->withConsecutive(['S_AGREEMENT'], ['AGREEMENT_TITLE']) + ->willReturnOnConsecutiveCalls($s_agreement, $this->language->lang($agreement_title)); + + if ($expected_append_calls > 0) + { + $this->template->expects(self::once()) + ->method('append_var') + ->with('AGREEMENT_TEXT', $this->language->lang('PHPBB_ANALYTICS_PRIVACY_POLICY', 'Test Forum')); + } + else + { + $this->template->expects(self::never()) + ->method('append_var'); + } + + $this->set_listener(); + $this->listener->append_agreement(); + } }