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