Skip to content

Commit 3a1be5a

Browse files
authored
Merge pull request #189 from iMattPro/privacy-update
Amend privacy policy regarding ads
2 parents bfeacd7 + af25985 commit 3a1be5a

12 files changed

Lines changed: 136 additions & 105 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "An extension for phpBB that allows administrators to manage and display advertisements on their forums.",
55
"homepage": "https://www.phpbb.com/customise/db/extension/ads/",
6-
"version": "3.0.0",
6+
"version": "3.0.1-dev",
77
"keywords": ["phpbb", "extension", "advertisement"],
88
"license": "GPL-2.0-only",
99
"authors": [

config/location.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ services:
106106
phpbb.ads.location.type.pop_up:
107107
class: phpbb\ads\location\type\pop_up
108108
parent: phpbb.ads.location.type.base
109-
arguments:
110-
- '@request'
111-
- '@config'
112-
- '@template'
113109
tags:
114110
- { name: phpbb.ads.location.type }
115111

config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ services:
4747
phpbb.ads.listener:
4848
class: phpbb\ads\event\main_listener
4949
arguments:
50+
- '@language'
5051
- '@template'
51-
- '@template_context'
5252
- '@user'
5353
- '@config'
5454
- '@phpbb.ads.ad.manager'

event/main_listener.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
*/
2121
class main_listener implements EventSubscriberInterface
2222
{
23+
/** @var \phpbb\language\language */
24+
protected $language;
25+
2326
/** @var \phpbb\template\template */
2427
protected $template;
2528

26-
/** @var \phpbb\template\context */
27-
protected $template_context;
28-
2929
/** @var \phpbb\user */
3030
protected $user;
3131

@@ -58,7 +58,7 @@ public static function getSubscribedEvents()
5858
return array(
5959
'core.permissions' => 'set_permissions',
6060
'core.user_setup' => 'load_language_on_setup',
61-
'core.page_footer_after' => array(array('setup_ads'), array('visual_demo')),
61+
'core.page_footer_after' => array(array('setup_ads'), array('visual_demo'), array('append_agreement')),
6262
'core.page_header_after' => array(array('adblocker'), array('clicks')),
6363
'core.delete_user_after' => 'remove_ad_owner',
6464
'core.adm_page_header_after' => 'disable_xss_protection',
@@ -70,8 +70,8 @@ public static function getSubscribedEvents()
7070
/**
7171
* Constructor
7272
*
73+
* @param \phpbb\language\language $language Language object
7374
* @param \phpbb\template\template $template Template object
74-
* @param \phpbb\template\context $template_context Template context object
7575
* @param \phpbb\user $user User object
7676
* @param \phpbb\config\config $config Config object
7777
* @param \phpbb\ads\ad\manager $manager Advertisement manager object
@@ -81,10 +81,10 @@ public static function getSubscribedEvents()
8181
* @param \phpbb\cache\driver\driver_interface $cache Cache driver object
8282
* @param string $php_ext PHP extension
8383
*/
84-
public function __construct(\phpbb\template\template $template, \phpbb\template\context $template_context, \phpbb\user $user, \phpbb\config\config $config, \phpbb\ads\ad\manager $manager, \phpbb\ads\location\manager $location_manager, \phpbb\controller\helper $controller_helper, \phpbb\request\request $request, \phpbb\cache\driver\driver_interface $cache, $php_ext)
84+
public function __construct(\phpbb\language\language $language, \phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\ads\ad\manager $manager, \phpbb\ads\location\manager $location_manager, \phpbb\controller\helper $controller_helper, \phpbb\request\request $request, \phpbb\cache\driver\driver_interface $cache, $php_ext)
8585
{
86+
$this->language = $language;
8687
$this->template = $template;
87-
$this->template_context = $template_context;
8888
$this->user = $user;
8989
$this->config = $config;
9090
$this->manager = $manager;
@@ -131,10 +131,8 @@ public function load_language_on_setup($event)
131131
*/
132132
public function setup_ads()
133133
{
134-
// Reason we access template's root ref is to check for existence
135-
// of 'MESSAGE_TEXT', which signals error page.
136-
$rootref = $this->template_context->get_root_ref();
137-
$non_content_page = !empty($rootref['MESSAGE_TEXT']) || $this->is_non_content_page();
134+
// check for the existence of 'MESSAGE_TEXT', which signals it's an error page.
135+
$non_content_page = $this->template->retrieve_var('MESSAGE_TEXT') || $this->is_non_content_page();
138136
$location_ids = $this->location_manager->get_all_location_ids();
139137
$user_groups = $this->manager->load_memberships($this->user->data['user_id']);
140138
$ad_ids = array();
@@ -278,4 +276,23 @@ protected function is_non_content_page()
278276
'adm',
279277
])) > 0;
280278
}
279+
280+
/**
281+
* Append additional agreement details to the privacy agreement.
282+
*
283+
* @return void
284+
*/
285+
public function append_agreement()
286+
{
287+
if ((strpos($this->user->page['page_name'], 'ucp') !== 0)
288+
|| !$this->template->retrieve_var('S_AGREEMENT')
289+
|| ($this->template->retrieve_var('AGREEMENT_TITLE') !== $this->language->lang('PRIVACY')))
290+
{
291+
return;
292+
}
293+
294+
$this->language->add_lang('ucp', 'phpbb/ads');
295+
296+
$this->template->append_var('AGREEMENT_TEXT', $this->language->lang('PHPBB_ADS_PRIVACY_POLICY', $this->config['sitename']));
297+
}
281298
}

language/en/ucp.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@
2929
'ACTIVE_ADS' => 'Active ads',
3030
'EXPIRED_ADS' => 'Expired ads',
3131
'NO_ADS' => '<strong>You do not have any advertisements displayed on this board.</strong>',
32+
33+
'PHPBB_ADS_PRIVACY_POLICY' => '
34+
<br><br>
35+
<h3>Advertising</h3>
36+
“%1$s” may display advertising provided by third-party networks or services. These advertisements may use cookies, tracking pixels, or similar technologies to collect information about your browsing activities on this site and, in some cases, across other websites. This information may be used to deliver relevant advertisements, measure the effectiveness of advertising campaigns, and tailor content to your interests.
37+
<br><br>
38+
Any data collected through such third-party advertising services is subject to the privacy and cookie policies of the respective providers. “%1$s” does not control the cookies or data collection practices of these third parties. We encourage you to review the policies of the relevant advertising providers for more details on how your information is processed.
39+
',
3240
));

location/type/pop_up.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,6 @@
1212

1313
class pop_up extends base
1414
{
15-
/** @var \phpbb\request\request */
16-
protected $request;
17-
/** @var \phpbb\config\config */
18-
protected $config;
19-
/** @var \phpbb\template\template */
20-
protected $template;
21-
22-
/**
23-
* pop_up location constructor.
24-
*
25-
* @param \phpbb\user $user User object
26-
* @param \phpbb\language\language $language Language object
27-
* @param \phpbb\request\request $request Request object
28-
* @param \phpbb\config\config $config Config object
29-
* @param \phpbb\template\template $template Template object
30-
*/
31-
public function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\config\config $config, \phpbb\template\template $template)
32-
{
33-
parent::__construct($user, $language);
34-
35-
$this->request = $request;
36-
$this->config = $config;
37-
$this->template = $template;
38-
}
39-
4015
/**
4116
* {@inheritDoc}
4217
*/
@@ -52,22 +27,4 @@ public function get_category()
5227
{
5328
return self::CAT_INTERACTIVE;
5429
}
55-
56-
/**
57-
* {@inheritDoc}
58-
*/
59-
public function will_display()
60-
{
61-
if ($this->request->is_set($this->config['cookie_name'] . '_pop_up', \phpbb\request\request_interface::COOKIE))
62-
{
63-
return false;
64-
}
65-
66-
$this->template->assign_vars(array(
67-
'POP_UP_COOKIE_NAME' => $this->config['cookie_name'] . '_pop_up',
68-
'POP_UP_COOKIE_EXPIRES' => gmdate('D, d M Y H:i:s T', strtotime('+1 day')),
69-
'POP_UP_COOKIE_PATH' => $this->config['cookie_path'],
70-
));
71-
return true;
72-
}
7330
}
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
{% import '@phpbb_ads/phpbb_ads_macro.html' as ad %}
22
<script>
3-
(function($, window, document, phpbb) {
3+
(() => {
44
'use strict';
55

6-
$(window).on('load', function() {
7-
document.cookie = '{{ POP_UP_COOKIE_NAME }}=true; expires={{ POP_UP_COOKIE_EXPIRES }}; path={{ POP_UP_COOKIE_PATH }}';
8-
phpbb.alert('{{ lang('ADVERTISEMENT')|upper|e('js') }}', `{{ ad.renderAds(AD_POP_UP, AD_POP_UP_ID, AD_POP_UP_CENTER, 'margin: 0;') }}`);
9-
});
10-
})(jQuery, window, document, phpbb);
6+
const key = 'phpbb_ads_pop_up';
7+
const interval_days = 1;
8+
const lastShown = localStorage.getItem(key);
9+
10+
if (!lastShown || Date.now() - +lastShown >= interval_days * 86400000) {
11+
localStorage.setItem(key, Date.now());
12+
window.addEventListener('load', () => {
13+
phpbb.alert(
14+
'{{ lang('ADVERTISEMENT')|upper|e('js') }}',
15+
`{{ ad.renderAds(AD_POP_UP, AD_POP_UP_ID, AD_POP_UP_CENTER, 'margin: 0;') }}`
16+
);
17+
});
18+
}
19+
})();
1120
</script>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ads\tests\event;
12+
13+
class amend_agreement_test extends main_listener_base
14+
{
15+
/**
16+
* Data for test_append_agreement
17+
*
18+
* @return array
19+
*/
20+
public function append_agreement_data()
21+
{
22+
return [
23+
[false, 'PRIVACY', 0], // No agreement
24+
[true, 'TERMS', 0], // Wrong title
25+
[true, 'PRIVACY', 1], // Correct conditions
26+
];
27+
}
28+
29+
/**
30+
* Test the append_agreement method
31+
*
32+
* @dataProvider append_agreement_data
33+
* @param mixed $s_agreement S_AGREEMENT template variable value
34+
* @param mixed $agreement_title AGREEMENT_TITLE template variable value
35+
* @param int $expected_append_calls Expected append_var calls
36+
*/
37+
public function test_append_agreement($s_agreement, $agreement_title, $expected_append_calls)
38+
{
39+
$this->config['sitename'] = 'Test Forum';
40+
$this->user->page['page_name'] = 'ucp.php';
41+
42+
$this->template->expects(self::atMost(2))
43+
->method('retrieve_var')
44+
->withConsecutive(['S_AGREEMENT'], ['AGREEMENT_TITLE'])
45+
->willReturnOnConsecutiveCalls($s_agreement, $this->language->lang($agreement_title));
46+
47+
if ($expected_append_calls > 0)
48+
{
49+
$this->template->expects(self::once())
50+
->method('append_var')
51+
->with('AGREEMENT_TEXT', $this->language->lang('PHPBB_ADS_PRIVACY_POLICY', 'Test Forum'));
52+
}
53+
else
54+
{
55+
$this->template->expects(self::never())
56+
->method('append_var');
57+
}
58+
59+
$listener = $this->get_listener();
60+
$listener->append_agreement();
61+
}
62+
}

tests/event/main_listener_base.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class main_listener_base extends \phpbb_database_test_case
1818
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\template\template */
1919
protected $template;
2020

21-
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\template\context */
22-
protected $template_context;
23-
2421
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\user */
2522
protected $user;
2623

24+
/** @var \phpbb\language\language */
25+
protected $language;
26+
2727
/** @var string ads_table */
2828
protected $ads_table;
2929

@@ -87,8 +87,8 @@ protected function setUp(): void
8787
->getMock();
8888
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
8989
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
90-
$lang = new \phpbb\language\language($lang_loader);
91-
$user = new \phpbb\user($lang, '\phpbb\datetime');
90+
$this->language = new \phpbb\language\language($lang_loader);
91+
$user = new \phpbb\user($this->language, '\phpbb\datetime');
9292
$request = $this->getMockBuilder('\phpbb\request\request')
9393
->disableOriginalConstructor()
9494
->getMock();
@@ -124,21 +124,18 @@ protected function setUp(): void
124124
$class = "\\phpbb\\ads\\location\\type\\$type";
125125
if ($type === 'pop_up')
126126
{
127-
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $lang, $request, $config, $template);
127+
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $this->language, $request, $config, $template);
128128
}
129129
else
130130
{
131-
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $lang);
131+
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $this->language);
132132
}
133133
}
134134

135135
// Load/Mock classes required by the listener class
136136
$this->template = $this->getMockBuilder('\phpbb\template\template')
137137
->disableOriginalConstructor()
138138
->getMock();
139-
$this->template_context = $this->getMockBuilder('\phpbb\template\context')
140-
->disableOriginalConstructor()
141-
->getMock();
142139
$this->user = $user;
143140
$this->config = new \phpbb\config\config(array('phpbb_ads_adblocker_message' => '0'));
144141
$this->manager = new \phpbb\ads\ad\manager($this->new_dbal(), $this->config, $this->ads_table, $this->ad_locations_table, $this->ad_group_table);
@@ -161,8 +158,8 @@ protected function setUp(): void
161158
protected function get_listener()
162159
{
163160
return new \phpbb\ads\event\main_listener(
161+
$this->language,
164162
$this->template,
165-
$this->template_context,
166163
$this->user,
167164
$this->config,
168165
$this->manager,

tests/functional/ucp_test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public function test_ucp_module()
5454
$this->assertContainsLang('AD_NAME', $crawler->filter('.table1')->text());
5555
}
5656

57+
public function test_ucp_agreement()
58+
{
59+
$crawler = self::request('GET', 'ucp.php?mode=privacy');
60+
$this->assertStringContainsString($this->lang('PHPBB_ADS_PRIVACY_POLICY', 'yourdomain.com'), $crawler->filter('.agreement')->html());
61+
}
62+
5763
protected function get_ucp_module($assert_response_html = true)
5864
{
5965
return self::request('GET', "ucp.php?i=-phpbb-ads-ucp-main_module&mode=stats&sid={$this->sid}", array(), $assert_response_html);

0 commit comments

Comments
 (0)