Skip to content

Commit 6592428

Browse files
committed
Use browser local storage instead of cookies for closed popups
1 parent 459e003 commit 6592428

5 files changed

Lines changed: 11 additions & 77 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

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
}

styles/all/template/includes/phpbb_ads_pop_up.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
'use strict';
55

66
$(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;') }}`);
7+
if (!localStorage.getItem('phpbb_ads_pop_up')) {
8+
localStorage.setItem('phpbb_ads_pop_up', 'true');
9+
phpbb.alert('{{ lang('ADVERTISEMENT')|upper|e('js') }}', `{{ ad.renderAds(AD_POP_UP, AD_POP_UP_ID, AD_POP_UP_CENTER, 'margin: 0;') }}`);
10+
}
911
});
1012
})(jQuery, window, document, phpbb);
1113
</script>

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 function get_all_location_ids_data()
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 function get_all_location_ids_data()
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 function get_all_location_ids_data()
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 function get_all_location_ids_data()
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 function get_all_location_ids_data()
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();

tests/location/location_base.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class location_base extends \phpbb_test_case
2121
/** @var \phpbb\language\language */
2222
protected $language;
2323

24-
/** @var \phpbb\request\request|\PHPUnit\Framework\MockObject\MockObject */
25-
protected $request;
26-
2724
protected static function setup_extensions()
2825
{
2926
return array('phpbb/ads');
@@ -41,13 +38,6 @@ protected function setUp(): void
4138
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
4239
$this->language = new \phpbb\language\language($lang_loader);
4340
$this->user = new \phpbb\user($this->language, '\phpbb\datetime');
44-
$this->request = $this->getMockBuilder('\phpbb\request\request')
45-
->disableOriginalConstructor()
46-
->getMock();
47-
$config = new \phpbb\config\config(array());
48-
$template = $this->getMockBuilder('\phpbb\template\template')
49-
->disableOriginalConstructor()
50-
->getMock();
5141
// Location types
5242
$locations = array(
5343
'above_footer',
@@ -72,14 +62,7 @@ protected function setUp(): void
7262
foreach ($locations as $type)
7363
{
7464
$class = "\\phpbb\\ads\\location\\type\\$type";
75-
if ($type === 'pop_up')
76-
{
77-
$location_types['phpbb.ads.location.type.' . $type] = new $class($this->user, $this->language, $this->request, $config, $template);
78-
}
79-
else
80-
{
81-
$location_types['phpbb.ads.location.type.' . $type] = new $class($this->user, $this->language);
82-
}
65+
$location_types['phpbb.ads.location.type.' . $type] = new $class($this->user, $this->language);
8366
}
8467

8568
$this->template_locations = $location_types;

0 commit comments

Comments
 (0)