Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.0 - 2026-02-16

- add privacy information

## 1.0.7 - 2026-01-13

- add french translation
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
23 changes: 22 additions & 1 deletion event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}

Expand Down Expand Up @@ -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']));
}
}
47 changes: 47 additions & 0 deletions language/de/matomoanalytics_ucp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
*
* Google Analytics extension for the phpBB Forum Software package.
*
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
* @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' => '
<h3>Website Analytics (Matomo)</h3>
<p>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.</p>
<p>Die durch Matomo erfassten Informationen über die Benutzung von „%1$s“ werden auf unserem Server gespeichert. Die IP-Adresse wird vor der Speicherung anonymisiert.</p>
<p>Du kannst dem sammelen von Nutzungsinformationen wiedersprechen, indem du im folgenden die checkbox entfernst:</p>
<div id="matomo-opt-out"></div><script src="%2$s/index.php?module=CoreAdminHome&action=optOutJS&div=matomo-opt-out&showIntro=0&language=de"></script>',
]);
50 changes: 50 additions & 0 deletions language/en/matomoanalytics_ucp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
*
* Google Analytics extension for the phpBB Forum Software package.
*
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
* @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' => '
<br><br>
<b>Website Analytics (Matomo)</b><br>
We use Matomo Analytics to measure, collect, analyse and report visitors’ data for purposes of understanding and optimising our website.
<br>
The Informationen the usage of “%1$s” collected by Matomo is stored on our servers. IP-adresses are anonymized before beeing stored.
<br>
You can opt out of Matomo by unchecking the following checkbox:
<div id="matomo-opt-out"></div><script src="%2$s/index.php?module=CoreAdminHome&action=optOutJS&div=matomo-opt-out&showIntro=0&language=en"></script>',
]);
49 changes: 49 additions & 0 deletions language/fr/matomoanalytics_ucp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
*
* Google Analytics extension for the phpBB Forum Software package.
*
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
* @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' => '
<br><br>
<b>Analyse du trafic sur le site (Matomo)</b><br>
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.
<br>
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.
<br>
Vous pouvez désactiver Matomo en décochant la case suivante: <div id="matomo-opt-out"></div><script src="%2$s/index.php?module=CoreAdminHome&action=optOutJS&div=matomo-opt-out&showIntro=0&language=fr"></script>',
]);
74 changes: 65 additions & 9 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -21,14 +19,23 @@ 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;

/** @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
*/
Expand All @@ -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;
}
Expand All @@ -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
);
Expand All @@ -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()));
}

Expand Down Expand Up @@ -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']);

Expand Down Expand Up @@ -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();
}
}
Loading