PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.3.7
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.3.7
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
301 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 if ( empty( $t['purposes'] ) ) {
80 $restrictions[ $vendor ]['purposes'] = array();
81 }
82 }
83 } else {
84 $restrictions = array(
85 '0' => array(
86 'purposes' => array(),
87 ),
88 );
89 }
90
91 return $restrictions;
92 }
93
94 private function get_vendor_array( $items, $item_name ) {
95 $array = array(
96 'title' => self::get_vendor_option_content( $item_name, 'title' ),
97 'description' => self::get_vendor_option_content( $item_name, 'description' ),
98 'selected' => self::get_vendor_option_content( $item_name, 'selected' ),
99 );
100 foreach ( $items as $item ) {
101 $array['items'][] = array(
102 'id' => intval( esc_html( $item->id ) ),
103 'name' => esc_html( $item->name ),
104 );
105 }
106 return $array;
107 }
108
109 private function get_extra_providers() {
110 $get_info = array_map( 'str_getcsv', file( self::IAB_GAD_EXTRA_PROVIDERS ) );
111
112 if ( ! $get_info ) {
113 return false;
114 }
115
116 $extra_vendors = array_map(
117 function ( $n ) {
118 return array(
119 'id' => intval( esc_html( $n[0] ) ),
120 'name' => esc_html( $n[1] ),
121 );
122 },
123 $get_info
124 );
125
126 return $extra_vendors ? $extra_vendors : false;
127 }
128
129 private function get_vendor_option_content( $item, $value ) {
130 $defaults = array(
131 self::IAB_PURPOSE_FIELD_NAME => array(
132 'title' => __( 'Purposes of data use', 'cookiebot' ),
133 'description' => __(
134 '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.',
135 'cookiebot'
136 ),
137 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-purposes' ),
138 ),
139 self::IAB_SPECIAL_PURPOSE_FIELD_NAME => array(
140 'title' => __( 'Special purposes of data use', 'cookiebot' ),
141 'description' => __(
142 'Inform your users about special purposes of using their data. We’ll show this on the second layer of your consent banner.',
143 'cookiebot'
144 ),
145 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-special-purposes' ),
146 ),
147 self::IAB_FEATURES_FIELD_NAME => array(
148 'title' => __( 'Features required for data processing', 'cookiebot' ),
149 'description' => __(
150 '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.',
151 'cookiebot'
152 ),
153 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-features' ),
154 ),
155 self::IAB_SPECIAL_FEATURES_FIELD_NAME => array(
156 'title' => __( 'Special features required for data processing', 'cookiebot' ),
157 'description' => __(
158 '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.',
159 'cookiebot'
160 ),
161 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-special-features' ),
162 ),
163 self::IAB_VENDOR_FIELD_NAME => array(
164 'title' => __( 'TCF listed vendors', 'cookiebot' ),
165 'description' => false,
166 'selected' => self::get_vendor_custom_option( 'cookiebot-tcf-vendors' ),
167 ),
168 );
169
170 return isset( $defaults[ $item ] ) ? $defaults[ $item ][ $value ] : array();
171 }
172
173 public function vendor_checked( $id, $selected ) {
174 return in_array( strval( $id ), array_values( $selected ), true );
175 }
176
177 public function return_translation_value( $option, $item ) {
178 $translations = $this->vendor_purpose_translations;
179 return isset( $translations[ $option ][ $item['id'] ] ) ? $translations[ $option ][ $item['id'] ] : $item['name'];
180 }
181
182 private function define_translations() {
183 $this->vendor_purpose_translations = array(
184 self::IAB_PURPOSE_FIELD_NAME => array(
185 '1' => __(
186 'Store and/or access information on a device',
187 'cookiebot'
188 ),
189 '2' => __(
190 'Use limited data to select advertising',
191 'cookiebot'
192 ),
193 '3' => __(
194 'Create profiles for personalised advertising',
195 'cookiebot'
196 ),
197 '4' => __(
198 'Use profiles to select personalised advertising',
199 'cookiebot'
200 ),
201 '5' => __(
202 'Create profiles to personalise content',
203 'cookiebot'
204 ),
205 '6' => __(
206 'Use profiles to select personalised content',
207 'cookiebot'
208 ),
209 '7' => __(
210 'Measure advertising performance',
211 'cookiebot'
212 ),
213 '8' => __(
214 'Measure content performance',
215 'cookiebot'
216 ),
217 '9' => __(
218 'Understand audiences through statistics or combinations of data from different sources',
219 'cookiebot'
220 ),
221 '10' => __(
222 'Develop and improve services',
223 'cookiebot'
224 ),
225 '11' => __(
226 'Use limited data to select content',
227 'cookiebot'
228 ),
229 ),
230 self::IAB_SPECIAL_PURPOSE_FIELD_NAME => array(
231 '1' => __(
232 'Ensure security, prevent and detect fraud, and fix errors',
233 'cookiebot'
234 ),
235 '2' => __(
236 'Deliver and present advertising and content',
237 'cookiebot'
238 ),
239 ),
240 self::IAB_FEATURES_FIELD_NAME => array(
241 '1' => __(
242 'Match and combine data from other data sources',
243 'cookiebot'
244 ),
245 '2' => __(
246 'Link different devices',
247 'cookiebot'
248 ),
249 '3' => __(
250 'Identify devices based on information transmitted automatically',
251 'cookiebot'
252 ),
253 ),
254 self::IAB_SPECIAL_FEATURES_FIELD_NAME => array(
255 '1' => __(
256 'Use precise geolocation data',
257 'cookiebot'
258 ),
259 '2' => __(
260 'Actively scan device characteristics for identification',
261 'cookiebot'
262 ),
263 ),
264 );
265 }
266
267 public static function get_option_attribute_name( $option_name ) {
268 return str_replace( '_', '-', $option_name );
269 }
270
271 public static function get_backup_custom_option( $option_name, $values ) {
272 $inputs = '';
273 if ( $values ) {
274 foreach ( $values as $item ) {
275 $inputs .= '<input type="hidden" name="' . $option_name . '[]" value="' . $item . '">';
276 }
277 }
278 return $inputs;
279 }
280
281 public static function get_backup_custom_restrictions( $values ) {
282 $inputs = '';
283 if ( $values ) {
284 foreach ( $values as $item => $data ) {
285 foreach ( $data['purposes'] as $purpose ) {
286 $inputs .= '<input type="hidden" name="cookiebot-tcf-disallowed[' . $item . '][purposes][]" value="' . $purpose . '">';
287 }
288 }
289 }
290 return $inputs;
291 }
292
293 const IAB_VENDOR_LIST_URL = 'https://vendor-list.consensu.org/v3/vendor-list.json';
294 const IAB_GAD_EXTRA_PROVIDERS = CYBOT_COOKIEBOT_PLUGIN_DIR . 'assets/docs/cookiebot-extra-providers.csv';
295 const IAB_PURPOSE_FIELD_NAME = 'purposes';
296 const IAB_SPECIAL_PURPOSE_FIELD_NAME = 'special_purposes';
297 const IAB_FEATURES_FIELD_NAME = 'features';
298 const IAB_SPECIAL_FEATURES_FIELD_NAME = 'special_features';
299 const IAB_VENDOR_FIELD_NAME = 'vendors';
300 }
301