Changeset 2099362
- Timestamp:
- 06/02/2019 02:39:52 PM (7 years ago)
- Location:
- xcoobee-sar/trunk
- Files:
-
- 3 edited
-
includes/class-xcoobee-sar-request.php (modified) (6 diffs)
-
readme.txt (modified) (1 diff)
-
xcoobee-sar.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
xcoobee-sar/trunk/includes/class-xcoobee-sar-request.php
r2087174 r2099362 27 27 public function __construct() { 28 28 add_action( 'xbee_endpoint_webhook', [ $this, 'handle_sar' ], 10, 2 ); 29 add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 ); 29 30 } 30 31 … … 36 37 */ 37 38 public function handle_sar( $headers, $payload ) { 38 39 39 if ( ! isset( $headers['Xbee-Event'] ) || 'UserDataRequest' !== $headers['Xbee-Event'] ) { 40 40 return; … … 115 115 116 116 $request_id = $requests_query->posts[0]; 117 } else { 118 wp_privacy_generate_personal_data_export_file( $request_id ); 119 } 117 } 118 119 // Create personal data file. 120 wp_privacy_generate_personal_data_export_file( $request_id ); 121 $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); 122 $exporters_count = count( $exporters ); 123 $response = $this->do_next_export( $request_id, $exporters_count, 1, 1 ); 120 124 121 125 // Update request status. … … 131 135 $destination_path = $destination['basedir'] . '/wp-personal-data-exports/' . $file_name; 132 136 137 // Unzip data file generated by WordPress. 133 138 $unzip_data_file = unzip_file( $data_file, $destination_path ); 134 135 139 if ( is_wp_error( $unzip_data_file ) ) { 136 140 return; 137 141 } 138 142 143 // Rename file from index.html to sar_request_site.com.html 139 144 $data_file = rtrim( $data_file, '.zip' ) . '/index.html'; 145 rename( $data_file, rtrim( $data_file, 'index.html' ) . 'sar_request_' . parse_url( get_site_url() )['host'] . '.html' ); 146 147 update_post_meta( $request_id, 'xbee_sar_xid', $xid ); 140 148 141 149 try { … … 153 161 update_post_meta( $request_id, 'xbee_sar_status', [ 'status' => 'sent', 'date' => time() ] ); 154 162 update_post_meta( $request_id, 'xbee_sar_user_reference', $response->request_id ); 155 update_post_meta( $request_id, 'xbee_sar_xid', $xid );156 163 } else { 157 164 update_post_meta( $request_id, 'xbee_sar_status', [ 'status' => 'error', 'date' => time() ] ); 165 166 wp_send_json( (object) [ 167 'result' => false, 168 'status' => 'error', 169 'code' => 'error_set_user_data_response', 170 'errors' => $response->errors, 171 ] ); 158 172 } 159 173 } catch ( Exception $e ) { … … 168 182 } 169 183 } 184 185 /** 186 * Retrieve user personal data. 187 * 188 * @since next 189 * 190 * @param int $request_id 191 * @param int $page_index 192 * @param int $exporter 193 * 194 * @return array 195 */ 196 protected function get_personal_data( $request_id, $exporter_index, $page_index ) { 197 if ( empty( $request_id ) ) { 198 return array( 199 'success' => false, 200 'data' => __( 'Missing request ID.', 'xcoobee' ), 201 ); 202 } 203 204 if ( ! isset( $exporter_index ) ) { 205 return array( 206 'success' => false, 207 'data' => __( 'Missing exporter index.', 'xcoobee' ), 208 ); 209 } 210 211 if ( ! isset( $page_index ) ) { 212 return array( 213 'success' => false, 214 'data' => __( 'Missing page index.', 'xcoobee' ), 215 ); 216 } 217 218 if ( $request_id < 1 ) { 219 return array( 220 'success' => false, 221 'data' => __( 'Invalid request ID.', 'xcoobee' ), 222 ); 223 } 224 225 // Get the request data. 226 $request = wp_get_user_request_data( $request_id ); 227 228 if ( ! $request ) { 229 return array( 230 'success' => false, 231 'data' => __( 'Invalid request type.', 'xcoobee' ), 232 ); 233 } 234 235 $email_address = $request->email; 236 if ( ! $request ) { 237 return array( 238 'success' => false, 239 'data' => __( 'A valid email address must be given.', 'xcoobee' ), 240 ); 241 } 242 243 /** This filter is documented in wp-admin/includes/ajax-actions.php */ 244 $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); 245 246 if ( ! is_array( $exporters ) ) { 247 return array( 248 'success' => false, 249 'data' => __( 'An exporter has improperly used the registration filter.', 'xcoobee' ), 250 ); 251 } 252 253 // Do we have any registered exporters? 254 if ( 0 < count( $exporters ) ) { 255 if ( $exporter_index < 1 ) { 256 return array( 257 'success' => false, 258 'data' => __( 'Exporter index cannot be negative.', 'xcoobee' ), 259 ); 260 } 261 262 if ( $exporter_index > count( $exporters ) ) { 263 return array( 264 'success' => false, 265 'data' => __( 'Exporter index is out of range.', 'xcoobee' ), 266 ); 267 } 268 269 if ( $page_index < 1 ) { 270 return array( 271 'success' => false, 272 'data' => __( 'Page index cannot be less than one.', 'xcoobee' ), 273 ); 274 } 275 276 $exporter_keys = array_keys( $exporters ); 277 $exporter_key = $exporter_keys[ $exporter_index - 1 ]; 278 $exporter = $exporters[ $exporter_key ]; 279 280 if ( ! is_array( $exporter ) ) { 281 return array( 282 'success' => false, 283 /* translators: %s: exporter array index */ 284 'data' => sprintf( __( 'Expected an array describing the exporter at index %s.', 'xcoobee' ), $exporter_key ), 285 ); 286 } 287 288 if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { 289 return array( 290 'success' => false, 291 /* translators: %s: exporter array index */ 292 'data' => sprintf( __( 'Exporter array at index %s does not include a friendly name.', 'xcoobee' ), $exporter_key ) 293 ); 294 } 295 296 $exporter_friendly_name = $exporter['exporter_friendly_name']; 297 298 if ( ! array_key_exists( 'callback', $exporter ) ) { 299 return array( 300 'success' => false, 301 /* translators: %s: exporter friendly name */ 302 'data' => sprintf( __( 'Exporter does not include a callback: %s.', 'xcoobee' ), esc_html( $exporter_friendly_name ) ) 303 ); 304 } 305 if ( ! is_callable( $exporter['callback'] ) ) { 306 return array( 307 'success' => false, 308 /* translators: %s: exporter friendly name */ 309 'data' => sprintf( __( 'Exporter callback is not a valid callback: %s.', 'xcoobee' ), esc_html( $exporter_friendly_name ) ) 310 ); 311 } 312 313 $callback = $exporter['callback']; 314 $response = call_user_func( $callback, $email_address, $page_index ); 315 316 if ( is_wp_error( $response ) ) { 317 return array( 318 'success' => false, 319 'data' => $response->get_error_message(), 320 ); 321 } 322 323 if ( ! is_array( $response ) ) { 324 return array( 325 'success' => false, 326 /* translators: %s: exporter friendly name */ 327 'data' => sprintf( __( 'Expected response as an array from exporter: %s.', 'xcoobee' ), esc_html( $exporter_friendly_name ) ) 328 ); 329 } 330 if ( ! array_key_exists( 'data', $response ) ) { 331 return array( 332 'success' => false, 333 /* translators: %s: exporter friendly name */ 334 'data' => sprintf( __( 'Expected data in response array from exporter: %s.', 'xcoobee' ), esc_html( $exporter_friendly_name ) ) 335 ); 336 } 337 if ( ! is_array( $response['data'] ) ) { 338 return array( 339 'success' => false, 340 /* translators: %s: exporter friendly name */ 341 'data' => sprintf( __( 'Expected data array in response array from exporter: %s.', 'xcoobee' ), esc_html( $exporter_friendly_name ) ) 342 ); 343 } 344 if ( ! array_key_exists( 'done', $response ) ) { 345 return array( 346 'success' => false, 347 /* translators: %s: exporter friendly name */ 348 'data' => sprintf( __( 'Expected done (boolean) in response array from exporter: %s.', 'xcoobee' ), esc_html( $exporter_friendly_name ) ) 349 ); 350 } 351 } else { 352 // No exporters, so we're done. 353 $exporter_key = ''; 354 355 $response = array( 356 'data' => array(), 357 'done' => true, 358 ); 359 } 360 361 $send_as_email = false; 362 363 /** This filter is documented in wp-admin/includes/ajax-actions.php */ 364 $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page_index, $request_id, $send_as_email, $exporter_key ); 365 $response = wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page_index, $request_id, $send_as_email, $exporter_key ); 366 367 if ( is_wp_error( $response ) ) { 368 return array( 369 'success' => false, 370 'data' => $response 371 ); 372 } 373 374 return array( 375 'success' => true, 376 'data' => $response 377 ); 378 } 379 380 /** 381 * A clone of doNextExport() in wp-admin/js/xfn.js. 382 * 383 * @since next 384 * 385 * @param int $request_id 386 * @param int $exporters_count 387 * @param int $exporter_index 388 * @param int $page_index 389 */ 390 protected function do_next_export( $request_id, $exporters_count, $exporter_index, $page_index ) { 391 $response = $this->get_personal_data( $request_id, $exporter_index, $page_index ); 392 $success = $response['success']; 393 $data = $response['data']; 394 395 if ( $success ) { 396 if ( ! $data['done'] ) { 397 return $this->do_next_export( $request_id, $exporters_count, $exporter_index, $page_index + 1 ); 398 } else { 399 if ( $exporter_index < $exporters_count ) { 400 return $this->do_next_export( $request_id, $exporters_count, $exporter_index + 1, 1 ); 401 } else { 402 return array( 403 'success' => true, 404 'data' => $data 405 ); 406 } 407 } 408 } else { 409 return array( 410 'success' => false, 411 'data' => $data 412 ); 413 } 414 } 170 415 } 171 416 -
xcoobee-sar/trunk/readme.txt
r2087174 r2099362 4 4 Requires at least: 4.4.0 5 5 Tested up to: 5.2 6 Stable tag: 1.2. 06 Stable tag: 1.2.1 7 7 License: GPLv3 8 8 License URI: https://www.gnu.org/licenses/gpl-3.0.html -
xcoobee-sar/trunk/xcoobee-sar.php
r2087174 r2099362 5 5 * Author URI: https://www.xcoobee.com/ 6 6 * Description: Enable full automation for the full Subject Data Export Lifecycle. 7 * Version: 1.2. 07 * Version: 1.2.1 8 8 * Author: XcooBee 9 9 * License: GPLv3
Note: See TracChangeset
for help on using the changeset viewer.