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