Skip to content

Commit 92f5a04

Browse files
authored
Merge pull request #90 from iMattPro/update
Drop phpBB 3.1 support so we can move forward
2 parents 79c68b2 + 7bbbedc commit 92f5a04

9 files changed

Lines changed: 268 additions & 229 deletions

File tree

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "A phpBB official extension that allows administrators to easily add Google Analytics to their forums.",
55
"homepage": "https://www.phpbb.com",
6-
"version": "1.0.6",
6+
"version": "1.1.0-dev",
77
"keywords": ["phpbb", "extension", "google", "analytics"],
88
"license": "GPL-2.0-only",
99
"authors": [
@@ -35,7 +35,7 @@
3535
}
3636
],
3737
"require": {
38-
"php": ">=5.3.3",
38+
"php": ">=5.4",
3939
"composer/installers": "~1.0"
4040
},
4141
"require-dev": {
@@ -44,12 +44,13 @@
4444
"extra": {
4545
"display-name": "Google Analytics",
4646
"soft-require": {
47-
"phpbb/phpbb": ">=3.1.0"
47+
"phpbb/phpbb": ">=3.2.0"
4848
},
4949
"version-check": {
5050
"host": "www.phpbb.com",
5151
"directory": "/customise/db/extension/googleanalytics",
52-
"filename": "version_check"
52+
"filename": "version_check",
53+
"ssl": true
5354
}
5455
}
5556
}

config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
class: phpbb\googleanalytics\event\listener
44
arguments:
55
- '@config'
6+
- '@language'
67
- '@template'
78
- '@user'
89
tags:

event/listener.php

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,135 @@
11
<?php
22
/**
3-
*
4-
* Google Analytics 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-
*/
3+
*
4+
* Google Analytics 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+
*/
1010

1111
namespace phpbb\googleanalytics\event;
1212

13+
use phpbb\config\config;
14+
use phpbb\language\language;
15+
use phpbb\template\template;
16+
use phpbb\user;
1317
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1418

1519
/**
16-
* Event listener
17-
*/
20+
* Event listener
21+
*/
1822
class listener implements EventSubscriberInterface
1923
{
20-
/** @var \phpbb\config\config */
24+
/** @var config */
2125
protected $config;
2226

23-
/** @var \phpbb\template\template */
27+
/** @var language */
28+
protected $language;
29+
30+
/** @var template */
2431
protected $template;
2532

26-
/** @var \phpbb\user */
33+
/** @var user */
2734
protected $user;
2835

2936
/**
30-
* Constructor
31-
*
32-
* @param \phpbb\config\config $config Config object
33-
* @param \phpbb\template\template $template Template object
34-
* @param \phpbb\user $user User object
35-
* @access public
36-
*/
37-
public function __construct(\phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user)
37+
* Constructor
38+
*
39+
* @param config $config Config object
40+
* @param language $language Language object
41+
* @param template $template Template object
42+
* @param user $user User object
43+
* @access public
44+
*/
45+
public function __construct(config $config, language $language, template $template, user $user)
3846
{
3947
$this->config = $config;
48+
$this->language = $language;
4049
$this->template = $template;
4150
$this->user = $user;
4251
}
4352

4453
/**
45-
* Assign functions defined in this class to event listeners in the core
46-
*
47-
* @return array
48-
* @static
49-
* @access public
50-
*/
54+
* Assign functions defined in this class to event listeners in the core
55+
*
56+
* @return array
57+
* @static
58+
* @access public
59+
*/
5160
public static function getSubscribedEvents()
5261
{
53-
return array(
62+
return [
5463
'core.acp_board_config_edit_add' => 'add_googleanalytics_configs',
5564
'core.page_header' => 'load_google_analytics',
5665
'core.validate_config_variable' => 'validate_googleanalytics_id',
57-
);
66+
];
5867
}
5968

6069
/**
61-
* Load Google Analytics js code
62-
*
63-
* @return void
64-
* @access public
65-
*/
70+
* Load Google Analytics js code
71+
*
72+
* @return void
73+
* @access public
74+
*/
6675
public function load_google_analytics()
6776
{
68-
$this->template->assign_vars(array(
77+
$this->template->assign_vars([
6978
'GOOGLEANALYTICS_ID' => $this->config['googleanalytics_id'],
7079
'GOOGLEANALYTICS_TAG' => $this->config['googleanalytics_tag'],
7180
'GOOGLEANALYTICS_USER_ID' => $this->user->data['user_id'],
7281
'S_ANONYMIZE_IP' => $this->config['ga_anonymize_ip'],
73-
));
82+
]);
7483
}
7584

7685
/**
77-
* Add config vars to ACP Board Settings
78-
*
79-
* @param \phpbb\event\data $event The event object
80-
* @return void
81-
* @access public
82-
*/
86+
* Add config vars to ACP Board Settings
87+
*
88+
* @param \phpbb\event\data $event The event object
89+
* @return void
90+
* @access public
91+
*/
8392
public function add_googleanalytics_configs($event)
8493
{
8594
// Add a config to the settings mode, after warnings_expire_days
8695
if ($event['mode'] === 'settings' && isset($event['display_vars']['vars']['warnings_expire_days']))
8796
{
8897
// Load language file
89-
$this->user->add_lang_ext('phpbb/googleanalytics', 'googleanalytics_acp');
98+
$this->language->add_lang('googleanalytics_acp', 'phpbb/googleanalytics');
9099

91100
// Store display_vars event in a local variable
92101
$display_vars = $event['display_vars'];
93102

94103
// Define the new config vars
95-
$ga_config_vars = array(
104+
$ga_config_vars = [
96105
'legend_googleanalytics' => 'ACP_GOOGLEANALYTICS',
97-
'googleanalytics_id' => array(
106+
'googleanalytics_id' => [
98107
'lang' => 'ACP_GOOGLEANALYTICS_ID',
99108
'validate' => 'googleanalytics_id',
100109
'type' => 'text:40:20',
101110
'explain' => true,
102-
),
103-
'ga_anonymize_ip' => array(
111+
],
112+
'ga_anonymize_ip' => [
104113
'lang' => 'ACP_GA_ANONYMIZE_IP',
105114
'validate' => 'bool',
106115
'type' => 'radio:yes_no',
107116
'explain' => true,
108-
),
109-
'googleanalytics_tag' => array(
117+
],
118+
'googleanalytics_tag' => [
110119
'lang' => 'ACP_GOOGLEANALYTICS_TAG',
111120
'validate' => 'int',
112121
'type' => 'select',
113122
'function' => 'build_select',
114-
'params' => array(array(
123+
'params' => [[
115124
0 => 'ACP_GA_ANALYTICS_TAG',
116125
1 => 'ACP_GA_GTAGS_TAG',
117-
), '{CONFIG_VALUE}'),
126+
], '{CONFIG_VALUE}'],
118127
'explain' => true,
119-
),
120-
);
128+
],
129+
];
121130

122131
// Add the new config vars after warnings_expire_days in the display_vars config array
123-
$insert_after = array('after' => 'warnings_expire_days');
132+
$insert_after = ['after' => 'warnings_expire_days'];
124133
$display_vars['vars'] = phpbb_insert_config_array($display_vars['vars'], $ga_config_vars, $insert_after);
125134

126135
// Update the display_vars event with the new array
@@ -129,12 +138,12 @@ public function add_googleanalytics_configs($event)
129138
}
130139

131140
/**
132-
* Validate the Google Analytics ID
133-
*
134-
* @param \phpbb\event\data $event The event object
135-
* @return void
136-
* @access public
137-
*/
141+
* Validate the Google Analytics ID
142+
*
143+
* @param \phpbb\event\data $event The event object
144+
* @return void
145+
* @access public
146+
*/
138147
public function validate_googleanalytics_id($event)
139148
{
140149
// Check if the validate test is for google_analytics
@@ -150,13 +159,13 @@ public function validate_googleanalytics_id($event)
150159
// Add error message if the input is not a valid Google Analytics ID
151160
if (!preg_match('/^UA-\d{4,9}-\d{1,4}$|^G-[A-Z0-9]{10}$/', $input))
152161
{
153-
$error[] = $this->user->lang('ACP_GOOGLEANALYTICS_ID_INVALID', $input);
162+
$error[] = $this->language->lang('ACP_GOOGLEANALYTICS_ID_INVALID', $input);
154163
}
155164

156165
// Add error message if GTAG is not selected for use with a Measurement ID
157-
if (preg_match('/^G-[A-Z0-9]{10}$/', $input) && (int) $event['cfg_array']['googleanalytics_tag'] === 0)
166+
if ((int) $event['cfg_array']['googleanalytics_tag'] === 0 && preg_match('/^G-[A-Z0-9]{10}$/', $input))
158167
{
159-
$error[] = $this->user->lang('ACP_GOOGLEANALYTICS_TAG_INVALID', $input);
168+
$error[] = $this->language->lang('ACP_GOOGLEANALYTICS_TAG_INVALID', $input);
160169
}
161170

162171
// Update error event data

ext.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
*
4+
* Google Analytics extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2021 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\googleanalytics;
12+
13+
use phpbb\extension\base;
14+
15+
class ext extends base
16+
{
17+
/**
18+
* {@inheritDoc}
19+
*/
20+
public function is_enableable()
21+
{
22+
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=');
23+
}
24+
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
<?php
22
/**
3-
*
4-
* Google Analytics 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-
*/
3+
*
4+
* Google Analytics 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+
*/
1010

1111
namespace phpbb\googleanalytics\migrations\v10x;
1212

1313
/**
14-
* Migration stage 1: Initial data changes to the database
15-
*/
14+
* Migration stage 1: Initial data changes to the database
15+
*/
1616
class m1_initial_data extends \phpbb\db\migration\migration
1717
{
1818
/**
19-
* Assign migration file dependencies for this migration
20-
*
21-
* @return array Array of migration files
22-
* @static
23-
* @access public
24-
*/
19+
* Assign migration file dependencies for this migration
20+
*
21+
* @return array Array of migration files
22+
* @static
23+
* @access public
24+
*/
2525
public static function depends_on()
2626
{
27-
return array('\phpbb\db\migration\data\v310\gold');
27+
return ['\phpbb\db\migration\data\v310\gold'];
2828
}
2929

3030
/**
31-
* Add Google Analytics data to the database.
32-
*
33-
* @return array Array of table data
34-
* @access public
35-
*/
31+
* Add Google Analytics data to the database.
32+
*
33+
* @return array Array of table data
34+
* @access public
35+
*/
3636
public function update_data()
3737
{
38-
return array(
39-
array('config.add', array('googleanalytics_id', '')),
40-
);
38+
return [
39+
['config.add', ['googleanalytics_id', '']],
40+
];
4141
}
4242
}

migrations/v10x/m2_anonymize_ip.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class m2_anonymize_ip extends \phpbb\db\migration\migration
2020
*/
2121
public static function depends_on()
2222
{
23-
return array('\phpbb\googleanalytics\migrations\v10x\m1_initial_data');
23+
return ['\phpbb\googleanalytics\migrations\v10x\m1_initial_data'];
2424
}
2525

2626
/**
2727
* {@inheritdoc}
2828
*/
2929
public function update_data()
3030
{
31-
return array(
32-
array('config.add', array('ga_anonymize_ip', 0)),
33-
);
31+
return [
32+
['config.add', ['ga_anonymize_ip', 0]],
33+
];
3434
}
3535
}

0 commit comments

Comments
 (0)