Skip to content

Commit 19b4e05

Browse files
authored
Merge pull request #191 from iMattPro/ad-privacy-switch
Allow toggling ads privacy policy amendment
2 parents 3a1be5a + c397c90 commit 19b4e05

8 files changed

Lines changed: 73 additions & 11 deletions

File tree

adm/style/settings_ads.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ <h3>{{ lang('WARNING') }}</h3>
3737
<dd><label><input type="radio" class="radio" id="enable_clicks" name="enable_clicks" value="1"{% if ENABLE_CLICKS %} checked{% endif %} /> {{ lang('YES') }}</label>
3838
<label><input type="radio" class="radio" name="enable_clicks" value="0"{% if not ENABLE_CLICKS %} checked{% endif %} /> {{ lang('NO') }}</label></dd>
3939
</dl>
40+
<dl>
41+
<dt><label for="show_agreement">{{ lang('SHOW_AGREEMENT') ~ lang('COLON') }}</label><br /><span>{{ lang('SHOW_AGREEMENT_EXPLAIN') }}</span></dt>
42+
<dd><label><input type="radio" class="radio" id="show_agreement" name="show_agreement" value="1"{% if SHOW_AGREEMENT %} checked{% endif %} /> {{ lang('YES') }}</label>
43+
<label><input type="radio" class="radio" name="show_agreement" value="0"{% if not SHOW_AGREEMENT %} checked{% endif %} /> {{ lang('NO') }}</label></dd>
44+
</dl>
4045
</fieldset>
4146
<fieldset class="submit-buttons">
4247
<input class="button1" type="submit" id="submit" name="submit" value="{{ lang('SUBMIT') }}" />&nbsp;

controller/admin_controller.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function mode_settings()
123123
$this->config->set('phpbb_ads_adblocker_message', $this->request->variable('adblocker_message', 0));
124124
$this->config->set('phpbb_ads_enable_views', $this->request->variable('enable_views', 0));
125125
$this->config->set('phpbb_ads_enable_clicks', $this->request->variable('enable_clicks', 0));
126+
$this->config->set('phpbb_ads_show_agreement', $this->request->variable('show_agreement', 0));
126127

127128
$this->success('ACP_AD_SETTINGS_SAVED');
128129
}
@@ -136,6 +137,7 @@ public function mode_settings()
136137
'AD_BLOCK_CONFIG' => $this->config['phpbb_ads_adblocker_message'],
137138
'ENABLE_VIEWS' => $this->config['phpbb_ads_enable_views'],
138139
'ENABLE_CLICKS' => $this->config['phpbb_ads_enable_clicks'],
140+
'SHOW_AGREEMENT' => $this->config['phpbb_ads_show_agreement'],
139141
));
140142
}
141143

event/main_listener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ protected function is_non_content_page()
284284
*/
285285
public function append_agreement()
286286
{
287-
if ((strpos($this->user->page['page_name'], 'ucp') !== 0)
287+
if (!$this->config['phpbb_ads_show_agreement']
288+
|| (strpos($this->user->page['page_name'], 'ucp') !== 0)
288289
|| !$this->template->retrieve_var('S_AGREEMENT')
289290
|| ($this->template->retrieve_var('AGREEMENT_TITLE') !== $this->language->lang('PRIVACY')))
290291
{

language/en/acp.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'AD_NOTE' => 'Notes',
3232
'AD_NOTE_EXPLAIN' => 'Enter any notes for this advertisement. These notes are not shown anywhere except in the ACP and are optional.',
3333
'AD_CODE' => 'Code',
34-
'AD_CODE_EXPLAIN' => 'Enter the advertisement code here. All code must use HTML markup, BBCodes are not supported.',
34+
'AD_CODE_EXPLAIN' => 'Enter the advertisement code here. All code must use HTML markup, BBCodes are not supported.<br><br>Note: If your ad code places cookies, collects user data, or tracks user behaviour (for example, ads from Google AdSense or other third-party ad networks), then you should enable the <strong>Advertising Disclosure</strong> in the <strong>Advertisement Management Settings</strong> panel to ensure compliance. If you are uncertain, it is recommended that you enable it.',
3535
'ANALYSE_AD_CODE' => 'Analyse advertisement code',
3636
'EVERYTHING_OK' => 'The code appears OK.',
3737
'AD_BANNER' => 'Advertisement banner',
@@ -124,6 +124,8 @@
124124
'ENABLE_VIEWS_EXPLAIN' => 'This will enable counting how many times every ad has been displayed. Note, that it adds extra load to the server, so if you do not need this feature, disable it.',
125125
'ENABLE_CLICKS' => 'Count clicks',
126126
'ENABLE_CLICKS_EXPLAIN' => 'This will enable counting how many times every ad has been clicked. Note, that it adds extra load to the server, so if you do not need this feature, disable it.',
127+
'SHOW_AGREEMENT' => 'Advertising disclosure',
128+
'SHOW_AGREEMENT_EXPLAIN' => 'Show details in the Privacy Policy about how third-party advertising and tracking technologies are used on this forum. This disclosure must be enabled if advertisements on your forum collect or track user information.',
127129
'HIDE_GROUPS' => 'Hide advertisement for groups',
128130
'HIDE_GROUPS_EXPLAIN' => 'Members of selected groups will not see this advertisement. Use CTRL+CLICK (or CMD+CLICK on Mac) to select/deselect more than one group.',
129131

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
*
4+
* Advertisement management. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2025 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ads\migrations\v20x;
12+
13+
/**
14+
* Migration stage 5: Add setting to show privacy agreement
15+
*/
16+
class m5_add_privacy_setting extends \phpbb\db\migration\migration
17+
{
18+
/**
19+
* {@inheritdoc
20+
*/
21+
public function effectively_installed()
22+
{
23+
$this->config->offsetExists('phpbb_ads_show_agreement');
24+
}
25+
26+
/**
27+
* {@inheritDoc}
28+
*/
29+
public static function depends_on()
30+
{
31+
return ['\phpbb\ads\migrations\v20x\m4_admin_permission'];
32+
}
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
public function update_data()
38+
{
39+
return [
40+
['config.add', ['phpbb_ads_show_agreement', 0]],
41+
];
42+
}
43+
}

tests/controller/admin_controller_test.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected function setUp(): void
114114
$this->analyser = $this->getMockBuilder('\phpbb\ads\analyser\manager')
115115
->disableOriginalConstructor()
116116
->getMock();
117-
$this->controller_helper = $this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
117+
$this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
118118
->disableOriginalConstructor()
119119
->getMock();
120120
$this->root_path = $phpbb_root_path;
@@ -171,6 +171,7 @@ public function test_mode_settings_no_submit()
171171
'AD_BLOCK_CONFIG' => $this->config['phpbb_ads_adblocker_message'],
172172
'ENABLE_VIEWS' => $this->config['phpbb_ads_enable_views'],
173173
'ENABLE_CLICKS' => $this->config['phpbb_ads_enable_clicks'],
174+
'SHOW_AGREEMENT' => $this->config['phpbb_ads_show_agreement'],
174175
));
175176

176177
$controller->mode_settings();
@@ -208,26 +209,29 @@ public function test_mode_settings_submit($valid_form, $adblocker_data, $hide_gr
208209
if ($valid_form)
209210
{
210211
$this->request
211-
->expects(self::exactly(3))
212+
->expects(self::exactly(4))
212213
->method('variable')
213214
->withConsecutive(
214215
['adblocker_message', 0],
215216
['enable_views', 0],
216-
['enable_clicks', 0]
217+
['enable_clicks', 0],
218+
['show_agreement', 0]
217219
)
218220
->willReturnOnConsecutiveCalls(
219221
$adblocker_data,
220222
1,
223+
1,
221224
1
222225
);
223226

224227
$this->config
225-
->expects(self::exactly(3))
228+
->expects(self::exactly(4))
226229
->method('set')
227230
->withConsecutive(
228231
['phpbb_ads_adblocker_message', $adblocker_data],
229232
['phpbb_ads_enable_views', 1],
230-
['phpbb_ads_enable_clicks', 1]
233+
['phpbb_ads_enable_clicks', 1],
234+
['phpbb_ads_show_agreement', 1]
231235
);
232236

233237
$this->setExpectedTriggerError(E_USER_NOTICE, 'ACP_AD_SETTINGS_SAVED');

tests/event/amend_agreement_test.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ class amend_agreement_test extends main_listener_base
2020
public function append_agreement_data()
2121
{
2222
return [
23-
[false, 'PRIVACY', 0], // No agreement
24-
[true, 'TERMS', 0], // Wrong title
25-
[true, 'PRIVACY', 1], // Correct conditions
23+
[true, false, 'PRIVACY', 0], // No agreement
24+
[true, true, 'TERMS', 0], // Wrong title
25+
[false, true, 'PRIVACY', 0], // don't display agreement
26+
[true, true, 'PRIVACY', 1], // Correct conditions
2627
];
2728
}
2829

2930
/**
3031
* Test the append_agreement method
3132
*
3233
* @dataProvider append_agreement_data
34+
* @param bool $s_show S_SHOW template variable value
3335
* @param mixed $s_agreement S_AGREEMENT template variable value
3436
* @param mixed $agreement_title AGREEMENT_TITLE template variable value
3537
* @param int $expected_append_calls Expected append_var calls
3638
*/
37-
public function test_append_agreement($s_agreement, $agreement_title, $expected_append_calls)
39+
public function test_append_agreement($s_show, $s_agreement, $agreement_title, $expected_append_calls)
3840
{
41+
$this->config['phpbb_ads_show_agreement'] = $s_show;
3942
$this->config['sitename'] = 'Test Forum';
4043
$this->user->page['page_name'] = 'ucp.php';
4144

tests/functional/acp_settings_test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function test_acp_settings()
3131
'adblocker_message' => 1,
3232
'enable_views' => 1,
3333
'enable_clicks' => 1,
34+
'show_agreement' => 1,
3435
);
3536
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
3637
$crawler = self::submit($form, $form_data);
@@ -43,6 +44,7 @@ public function test_acp_settings()
4344
self::assertEquals('1', $crawler->filter('option[selected]')->attr('value'));
4445
self::assertEquals('1', $crawler->filter('input[name="enable_views"][checked]')->attr('value'));
4546
self::assertEquals('1', $crawler->filter('input[name="enable_clicks"][checked]')->attr('value'));
47+
self::assertEquals('1', $crawler->filter('input[name="show_agreement"][checked]')->attr('value'));
4648
}
4749

4850
protected function get_settings_page()

0 commit comments

Comments
 (0)