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