Skip to content

Commit 439226b

Browse files
committed
Merge branch 'master' into dev/4.0
2 parents 96ad70a + 3a1be5a commit 439226b

11 files changed

Lines changed: 135 additions & 104 deletions

File tree

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
@@ -38,12 +38,12 @@ class main_listener_base extends phpbb_database_test_case
3838
/** @var template|MockObject */
3939
protected template|MockObject $template;
4040

41-
/** @var context|MockObject */
42-
protected context|MockObject $template_context;
43-
4441
/** @var user|MockObject */
4542
protected user|MockObject $user;
4643

44+
/** @var \phpbb\language\language */
45+
protected $language;
46+
4747
/** @var string ads_table */
4848
protected string $ads_table;
4949

@@ -107,8 +107,8 @@ protected function setUp(): void
107107
->getMock();
108108
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
109109
$lang_loader = new language_file_loader($phpbb_root_path, $phpEx);
110-
$lang = new language($lang_loader);
111-
$user = new user($lang, datetime::class);
110+
$this->language = new language($lang_loader);
111+
$user = new user($this->language, datetime::class);
112112
$request = $this->getMockBuilder(request::class)
113113
->disableOriginalConstructor()
114114
->getMock();
@@ -144,21 +144,18 @@ protected function setUp(): void
144144
$class = "\\phpbb\\ads\\location\\type\\$type";
145145
if ($type === 'pop_up')
146146
{
147-
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $lang, $request, $config, $template);
147+
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $this->language, $request, $config, $template);
148148
}
149149
else
150150
{
151-
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $lang);
151+
$location_types['phpbb.ads.location.type.' . $type] = new $class($user, $this->language);
152152
}
153153
}
154154

155155
// Load/Mock classes required by the listener class
156156
$this->template = $this->getMockBuilder(template::class)
157157
->disableOriginalConstructor()
158158
->getMock();
159-
$this->template_context = $this->getMockBuilder(context::class)
160-
->disableOriginalConstructor()
161-
->getMock();
162159
$this->user = $user;
163160
$this->config = new config(array('phpbb_ads_adblocker_message' => '0'));
164161
$this->manager = new ad_manager($this->new_dbal(), $this->config, $this->ads_table, $this->ad_locations_table, $this->ad_group_table);
@@ -181,8 +178,8 @@ protected function setUp(): void
181178
protected function get_listener(): main_listener
182179
{
183180
return new main_listener(
181+
$this->language,
184182
$this->template,
185-
$this->template_context,
186183
$this->user,
187184
$this->config,
188185
$this->manager,

tests/functional/ucp_test.php

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

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

tests/location/get_all_location_ids_test.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class get_all_location_ids_test extends location_base
2020
public static function get_all_location_ids_data(): array
2121
{
2222
return array(
23-
array('index', '', false, array(
23+
array('index', '', array(
2424
'above_header',
2525
'after_header_navbar',
2626
'below_header',
@@ -31,7 +31,7 @@ public static function get_all_location_ids_data(): array
3131
'slide_up',
3232
'scripts',
3333
)),
34-
array('viewtopic', '', false, array(
34+
array('viewtopic', '', array(
3535
'above_header',
3636
'after_header_navbar',
3737
'below_header',
@@ -48,7 +48,7 @@ public static function get_all_location_ids_data(): array
4848
'slide_up',
4949
'scripts',
5050
)),
51-
array('memberlist', 'viewprofile', false, array(
51+
array('memberlist', 'viewprofile', array(
5252
'above_header',
5353
'after_header_navbar',
5454
'below_header',
@@ -61,13 +61,14 @@ public static function get_all_location_ids_data(): array
6161
'slide_up',
6262
'scripts',
6363
)),
64-
array('index', '', true, array(
64+
array('index', '', array(
6565
'above_header',
6666
'after_header_navbar',
6767
'below_header',
6868
'above_footer',
6969
'after_footer_navbar',
7070
'below_footer',
71+
'pop_up',
7172
'slide_up',
7273
'scripts',
7374
)),
@@ -79,16 +80,11 @@ public static function get_all_location_ids_data(): array
7980
*
8081
* @dataProvider get_all_location_ids_data
8182
*/
82-
public function test_get_all_location_ids($page_name, $query_string, $cookie, $expected)
83+
public function test_get_all_location_ids($page_name, $query_string, $expected)
8384
{
8485
$this->user->page['page_name'] = $page_name;
8586
$this->user->page['query_string'] = $query_string;
8687

87-
$this->request
88-
->method('is_set')
89-
->with('_pop_up')
90-
->willReturn($cookie);
91-
9288
$manager = $this->get_manager();
9389

9490
$location_ids = $manager->get_all_location_ids();

0 commit comments

Comments
 (0)