PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.3.9
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.3.9
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / src / settings / pages / Iab_Page.php
cookiebot / src / settings / pages Last commit date
Dashboard_Page.php 3 years ago Debug_Page.php 2 years ago Gcm_Page.php 2 years ago Gtm_Page.php 3 years ago Iab_Page.php 2 years ago Legislations_Page.php 4 years ago Multiple_Page.php 3 years ago Settings_Page.php 3 years ago Settings_Page_Interface.php 3 years ago Support_Page.php 3 years ago
Iab_Page.php
299 lines
1 <?php
2
3 namespace cybot\cookiebot\settings\pages;
4
5 use InvalidArgumentException;
6 use function cybot\cookiebot\lib\include_view;
7
8 class Iab_Page implements Settings_Page_Interface {
9
10 public $vendor_purpose_translations;
11
12 public function __construct() {
13 $this->define_translations();
14 }
15
16 public function menu() {
17 add_submenu_page(
18 'cookiebot',
19 __( 'IAB', 'cookiebot' ),
20 __( 'IAB', 'cookiebot' ),
21 'manage_options',
22 'cookiebot_iab',
23 array( $this, 'display' ),
24 30
25 );
26 }
27
28 /**
29 * @throws InvalidArgumentException
30 */
31 public function display() {
32 $args = array(
33 'cookiebot_iab' => get_option( 'cookiebot-iab' ),
34 'cookiebot_tcf_version' => empty( get_option( 'cookiebot-tcf-version' ) ) ? 'IAB' : get_option( 'cookiebot-tcf-version' ),
35 'custom_tcf_purposes' => self::get_vendor_custom_option( 'cookiebot-tcf-purposes' ),
36 'custom_tcf_special_purposes' => self::get_vendor_custom_option( 'cookiebot-tcf-special-purposes' ),
37 'custom_tcf_features' => self::get_vendor_custom_option( 'cookiebot-tcf-features' ),
38 'custom_tcf_special_features' => self::get_vendor_custom_option( 'cookiebot-tcf-special-features' ),
39 'custom_tcf_vendors' => self::get_vendor_custom_option( 'cookiebot-tcf-vendors' ),
40 'custom_tcf_ac_vendors' => self::get_vendor_custom_option( 'cookiebot-tcf-ac-vendors' ),
41 'custom_tcf_restrictions' => self::get_restrictions_custom_option(),
42 'vendor_data' => self::get_vendor_list_data(),
43 'extra_providers' => self::get_extra_providers(),
44 );
45
46 include_view( 'admin/settings/iab-page.php', $args );
47 }
48
49 public function get_vendor_list_data() {
50 $json = wp_safe_remote_request( self::IAB_VENDOR_LIST_URL );
51
52 if ( is_wp_error( $json ) ) {
53 return false;
54 }
55
56 $response = json_decode( $json['body'] );
57
58 return array(
59 'purposes' => self::get_vendor_array( $response->purposes, self::IAB_PURPOSE_FIELD_NAME ),
60 //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
61 'special_purposes' => self::get_vendor_array( $response->specialPurposes, self::IAB_SPECIAL_PURPOSE_FIELD_NAME ),
62 'features' => self::get_vendor_array( $response->features, self::IAB_FEATURES_FIELD_NAME ),
63 //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
64 'special_features' => self::get_vendor_array( $response->specialFeatures, self::IAB_SPECIAL_FEATURES_FIELD_NAME ),
65 'vendors' => self::get_vendor_array( $response->vendors, self::IAB_VENDOR_FIELD_NAME ),
66 );
67 }
68
69 private function get_vendor_custom_option( $option ) {
70 return empty( get_option( $option ) ) ? array() : get_option( $option );
71 }
72
73 private function get_restrictions_custom_option() {
74 $restrictions = array();
75 $custom_tcf_restrictions = get_option( 'cookiebot-tcf-disallowed' );
76
77 if ( ! empty( $custom_tcf_restrictions ) ) {
78 foreach ( $custom_tcf_restrictions as $vendor => $t ) {
79 $restrictions[ $vendor ] = empty( $t['purposes'] ) ? array( 'purposes' => array() ) : $t;
80 }
81 } else {
82 $restrictions = array(
83 '0' => array(
84 'purposes' => array(),
85 ),
86 );
87 }
88
89 return $restrictions;
90 }
91
92 private function get_vendor_array( $items, $item_name ) {
93 $array = array(
94 'title' => self::get_vendor_option_content( $item_name, 'title' ),
95 'description' => self::get_vendor_option_content( $item_name, 'description' ),
96 'selected' => self::get_vendor_option_content( $item_name, 'selected' ),
97 );
98 foreach ( $items as $item ) {
99 $array['items'][] = array(
100 'id' => intval( esc_html( $item->id ) ),
101 'name' => esc_html( $item->name ),
102 );
103 }
104 return $array;
105 }
106
107 private function get_extra_providers() {
108 $get_info = array_map( 'str_getcsv', file( self::IAB_GAD_EXTRA_PROVIDERS ) );
109
110 if ( ! $get_info ) {
111 return false;
112 }
113
114 $extra_vendors = array_map(
115 function ( $n ) {
116 return array(
117 'id' => intval( esc_html( $n[0] ) ),
118 'name' => esc_html( $n[1] ),
119 );
120 },
121 $get_info
122 );
123
124 return $extra_vendors ? $extra_vendors : false;
125 }
126
127 private function get_vendor_option_content( $item, $value ) {
128 $defaults = array(
129 self::IAB_PURPOSE_FIELD_NAME => array(
130 'title' => __( 'Purposes of data use', 'cookiebot' ),
131 'description' => __(
132 'Inform your users how you’ll use their data. We’ll show this on the second layer of your consent banner, where users interested in more granular detail about data processing can view it.',
133 'cookiebot'
134 ),
135 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-purposes' ),
136 ),
137 self::IAB_SPECIAL_PURPOSE_FIELD_NAME => array(
138 'title' => __( 'Special purposes of data use', 'cookiebot' ),
139 'description' => __(
140 'Inform your users about special purposes of using their data. We’ll show this on the second layer of your consent banner.',
141 'cookiebot'
142 ),
143 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-special-purposes' ),
144 ),
145 self::IAB_FEATURES_FIELD_NAME => array(
146 'title' => __( 'Features required for data processing', 'cookiebot' ),
147 'description' => __(
148 'Inform users about the features necessary for processing their personal data. We’ll list the selected features on the second layer of your consent banner.',
149 'cookiebot'
150 ),
151 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-features' ),
152 ),
153 self::IAB_SPECIAL_FEATURES_FIELD_NAME => array(
154 'title' => __( 'Special features required for data processing', 'cookiebot' ),
155 'description' => __(
156 'Inform users about any specially categorized features required for processing their personal data. We’ll list the selected features on the second layer of your consent banner, offering options for users to enable or disable them.',
157 'cookiebot'
158 ),
159 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-special-features' ),
160 ),
161 self::IAB_VENDOR_FIELD_NAME => array(
162 'title' => __( 'TCF listed vendors', 'cookiebot' ),
163 'description' => false,
164 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-vendors' ),
165 ),
166 );
167
168 return isset( $defaults[ $item ] ) ? $defaults[ $item ][ $value ] : array();
169 }
170
171 public function vendor_checked( $id, $selected ) {
172 return in_array( strval( $id ), array_values( $selected ), true );
173 }
174
175 public function return_translation_value( $option, $item ) {
176 $translations = $this->vendor_purpose_translations;
177 return isset( $translations[ $option ][ $item['id'] ] ) ? $translations[ $option ][ $item['id'] ] : $item['name'];
178 }
179
180 private function define_translations() {
181 $this->vendor_purpose_translations = array(
182 self::IAB_PURPOSE_FIELD_NAME => array(
183 '1' => __(
184 'Store and/or access information on a device',
185 'cookiebot'
186 ),
187 '2' => __(
188 'Use limited data to select advertising',
189 'cookiebot'
190 ),
191 '3' => __(
192 'Create profiles for personalised advertising',
193 'cookiebot'
194 ),
195 '4' => __(
196 'Use profiles to select personalised advertising',
197 'cookiebot'
198 ),
199 '5' => __(
200 'Create profiles to personalise content',
201 'cookiebot'
202 ),
203 '6' => __(
204 'Use profiles to select personalised content',
205 'cookiebot'
206 ),
207 '7' => __(
208 'Measure advertising performance',
209 'cookiebot'
210 ),
211 '8' => __(
212 'Measure content performance',
213 'cookiebot'
214 ),
215 '9' => __(
216 'Understand audiences through statistics or combinations of data from different sources',
217 'cookiebot'
218 ),
219 '10' => __(
220 'Develop and improve services',
221 'cookiebot'
222 ),
223 '11' => __(
224 'Use limited data to select content',
225 'cookiebot'
226 ),
227 ),
228 self::IAB_SPECIAL_PURPOSE_FIELD_NAME => array(
229 '1' => __(
230 'Ensure security, prevent and detect fraud, and fix errors',
231 'cookiebot'
232 ),
233 '2' => __(
234 'Deliver and present advertising and content',
235 'cookiebot'
236 ),
237 ),
238 self::IAB_FEATURES_FIELD_NAME => array(
239 '1' => __(
240 'Match and combine data from other data sources',
241 'cookiebot'
242 ),
243 '2' => __(
244 'Link different devices',
245 'cookiebot'
246 ),
247 '3' => __(
248 'Identify devices based on information transmitted automatically',
249 'cookiebot'
250 ),
251 ),
252 self::IAB_SPECIAL_FEATURES_FIELD_NAME => array(
253 '1' => __(
254 'Use precise geolocation data',
255 'cookiebot'
256 ),
257 '2' => __(
258 'Actively scan device characteristics for identification',
259 'cookiebot'
260 ),
261 ),
262 );
263 }
264
265 public static function get_option_attribute_name( $option_name ) {
266 return str_replace( '_', '-', $option_name );
267 }
268
269 public static function get_backup_custom_option( $option_name, $values ) {
270 $inputs = '';
271 if ( $values ) {
272 foreach ( $values as $item ) {
273 $inputs .= '<input type="hidden" name="' . $option_name . '[]" value="' . $item . '">';
274 }
275 }
276 return $inputs;
277 }
278
279 public static function get_backup_custom_restrictions( $values ) {
280 $inputs = '';
281 if ( $values ) {
282 foreach ( $values as $item => $data ) {
283 foreach ( $data['purposes'] as $purpose ) {
284 $inputs .= '<input type="hidden" name="cookiebot-tcf-disallowed[' . $item . '][purposes][]" value="' . $purpose . '">';
285 }
286 }
287 }
288 return $inputs;
289 }
290
291 const IAB_VENDOR_LIST_URL = 'https://vendor-list.consensu.org/v3/vendor-list.json';
292 const IAB_GAD_EXTRA_PROVIDERS = CYBOT_COOKIEBOT_PLUGIN_DIR . 'assets/docs/cookiebot-extra-providers.csv';
293 const IAB_PURPOSE_FIELD_NAME = 'purposes';
294 const IAB_SPECIAL_PURPOSE_FIELD_NAME = 'special_purposes';
295 const IAB_FEATURES_FIELD_NAME = 'features';
296 const IAB_SPECIAL_FEATURES_FIELD_NAME = 'special_features';
297 const IAB_VENDOR_FIELD_NAME = 'vendors';
298 }
299