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
1111namespace phpbb \googleanalytics \event ;
1212
13+ use phpbb \config \config ;
14+ use phpbb \language \language ;
15+ use phpbb \template \template ;
16+ use phpbb \user ;
1317use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
1418
1519/**
16- * Event listener
17- */
20+ * Event listener
21+ */
1822class 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
0 commit comments