PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.2
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / admin / settings / miscellaneous-settings / class-wpsc-ms-gdpr.php

class-wpsc-ms-gdpr.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.2, at includes/admin/settings/miscellaneous-settings/class-wpsc-ms-gdpr.php

681 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_MS_GDPR' ) ) :
7
8 final class WPSC_MS_GDPR {
9
10 /**
11 * Initialize this class
12 *
13 * @return void
14 */
15 public static function init() {
16
17 // User interface.
18 add_action( 'wp_ajax_wpsc_get_ms_gdpr', array( __CLASS__, 'load_settings_ui' ) );
19 add_action( 'wp_ajax_wpsc_set_ms_gdpr', array( __CLASS__, 'save_settings' ) );
20 add_action( 'wp_ajax_wpsc_reset_ms_gdpr', array( __CLASS__, 'reset_settings' ) );
21
22 // Print in create ticket form.
23 add_action( 'wpsc_print_tff', array( __CLASS__, 'print_tff' ) );
24
25 // TFF! validation.
26 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
27
28 // make tickets anonymous - gdpr setting.
29 add_action( 'wpsc_cron_daily', array( __CLASS__, 'personal_data_eraser' ) );
30
31 // GDPR.
32 add_filter( 'wp_privacy_personal_data_exporters', array( __CLASS__, 'wpsc_register_privacy_exporters' ) );
33 add_filter( 'wp_privacy_personal_data_erasers', array( __CLASS__, 'wpsc_register_privacy_erasers' ) );
34 }
35
36 /**
37 * Reset settings
38 *
39 * @return void
40 */
41 public static function reset() {
42
43 $gdpr_text = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
44 $gdpr = apply_filters(
45 'wpsc_gdpr_settings',
46 array(
47 'allow-gdpr' => 1,
48 'gdpr-text' => $gdpr_text,
49 'personal-data-retention-time' => 0,
50 'personal-data-retention-unit' => 'days',
51 'editor' => 'html',
52 'allow-gdpr-reg-user' => 1,
53 'gdpr-text-reg-user' => $gdpr_text,
54 'editor-reg-user' => 'html',
55 'ip-address-collection' => 1,
56 )
57 );
58 update_option( 'wpsc-gdpr-settings', $gdpr );
59 WPSC_Translations::remove( 'wpsc-gdpr', $gdpr['gdpr-text'] );
60 WPSC_Translations::remove( 'wpsc-gdpr-reg-user', $gdpr['gdpr-text-reg-user'] );
61 }
62
63 /**
64 * Settings user interface
65 *
66 * @return void
67 */
68 public static function load_settings_ui() {
69
70 if ( ! WPSC_Functions::is_site_admin() ) {
71 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
72 }
73 $settings = get_option( 'wpsc-gdpr-settings', array() );?>
74
75 <form action="#" onsubmit="return false;" class="wpsc-frm-ms-gdpr">
76 <div class="wpsc-dock-container">
77 <?php
78 printf(
79 /* translators: Click here to see the documentation */
80 esc_attr__( '%s to see the documentation!', 'supportcandy' ),
81 '<a href="https://supportcandy.net/docs/gdpr/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>'
82 );
83 ?>
84 </div>
85 <h3><?php esc_attr_e( 'Create ticket form', 'supportcandy' ); ?></h3>
86
87 <div class="wpsc-input-group">
88 <div class="label-container">
89 <label for=""><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></label>
90 </div>
91 <select id="wpsc-allow-gdpr" name="allow-gdpr">
92 <option <?php selected( $settings['allow-gdpr'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
93 <option <?php selected( $settings['allow-gdpr'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
94 </select>
95 </div>
96 <div class="wpsc-input-group">
97 <div class="label-container">
98 <label for=""><?php esc_attr_e( 'Checkbox text', 'supportcandy' ); ?></label>
99 </div>
100 <div class="textarea-container ">
101 <div class="wpsc_tinymce_editor_btns">
102 <div class="inner-container">
103 <button class="visual wpsc-switch-editor wpsc-switch-editor-ct <?php echo esc_attr( $settings['editor'] ) == 'html' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_tinymce(this, 'gdpr-text','gdpr_body');"><?php esc_attr_e( 'Visual', 'supportcandy' ); ?></button>
104 <button class="text wpsc-switch-editor wpsc-switch-editor-ct <?php echo esc_attr( $settings['editor'] ) == 'text' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_textarea(this, 'gdpr-text')"><?php esc_attr_e( 'Text', 'supportcandy' ); ?></button>
105 </div>
106 </div>
107 <?php
108 $gdpr_text = $settings['gdpr-text'] ? WPSC_Translations::get( 'wpsc-gdpr', stripslashes( $settings['gdpr-text'] ) ) : stripslashes( $settings['gdpr-text'] );
109 ?>
110 <textarea name="gdpr-text" id="gdpr-text" class="wpsc_textarea"><?php echo wp_kses_post( $gdpr_text ); ?></textarea>
111 </div>
112 </div>
113
114 <hr>
115 <h3><?php esc_attr_e( 'Registration form', 'supportcandy' ); ?></h3>
116
117 <div class="wpsc-input-group">
118 <div class="label-container">
119 <label for=""><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></label>
120 </div>
121 <select id="wpsc-allow-gdpr-reg-user" name="allow-gdpr-reg-user">
122 <option <?php selected( $settings['allow-gdpr-reg-user'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
123 <option <?php selected( $settings['allow-gdpr-reg-user'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
124 </select>
125 </div>
126 <div class="wpsc-input-group">
127 <div class="label-container">
128 <label for=""><?php esc_attr_e( 'Checkbox text', 'supportcandy' ); ?></label>
129 </div>
130 <div class="textarea-container ">
131 <div class="wpsc_tinymce_editor_btns">
132 <div class="inner-container">
133 <button class="visual wpsc-switch-editor wpsc-switch-editor-reg-user <?php echo esc_attr( $settings['editor-reg-user'] ) == 'html' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_tinymce(this, 'gdpr-text-reg-user','gdpr_body');"><?php esc_attr_e( 'Visual', 'supportcandy' ); ?></button>
134 <button class="text wpsc-switch-editor wpsc-switch-editor-reg-user <?php echo esc_attr( $settings['editor-reg-user'] ) == 'text' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_textarea(this, 'gdpr-text-reg-user')"><?php esc_attr_e( 'Text', 'supportcandy' ); ?></button>
135 </div>
136 </div>
137 <?php
138 $gdpr_text = $settings['gdpr-text-reg-user'] ? WPSC_Translations::get( 'wpsc-gdpr-reg-user', stripslashes( $settings['gdpr-text-reg-user'] ) ) : stripslashes( $settings['gdpr-text-reg-user'] );
139 ?>
140 <textarea name="gdpr-text-reg-user" id="gdpr-text-reg-user" class="wpsc_textarea"><?php echo wp_kses_post( $gdpr_text ); ?></textarea>
141 </div>
142 </div>
143 <hr>
144 <div class="wpsc-input-group">
145 <div class="label-container">
146 <label for=""><?php esc_attr_e( 'Personal data retention', 'supportcandy' ); ?></label>
147 </div>
148 <div class="divide-bar">
149 <input type="number" id="wpsc-personal-data-retention-time" name="personal-data-retention-time" value="<?php echo esc_attr( $settings['personal-data-retention-time'] ); ?>">
150 <select id="wpsc-personal-data-retention-unit" name="personal-data-retention-unit">
151 <option <?php selected( $settings['personal-data-retention-unit'], 'days' ); ?> value="days"><?php esc_attr_e( 'Day(s)', 'supportcandy' ); ?></option>
152 <option <?php selected( $settings['personal-data-retention-unit'], 'month' ); ?> value="month"><?php esc_attr_e( 'Month(s)', 'supportcandy' ); ?></option>
153 <option <?php selected( $settings['personal-data-retention-unit'], 'year' ); ?> value="year"><?php esc_attr_e( 'Year(s)', 'supportcandy' ); ?></option>
154 </select>
155 </div>
156 </div>
157 <div class="wpsc-input-group">
158 <div class="label-container">
159 <label for=""><?php esc_attr_e( 'IP Address Collection', 'supportcandy' ); ?></label>
160 </div>
161 <select id="wpsc-ip-address-collection" name="ip-address-collection">
162 <option <?php selected( $settings['ip-address-collection'], 1 ); ?> value="1"><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></option>
163 <option <?php selected( $settings['ip-address-collection'], 0 ); ?> value="0"><?php esc_attr_e( 'Disable', 'supportcandy' ); ?></option>
164 </select>
165 </div>
166 <?php do_action( 'wpsc_ms_gdpr' ); ?>
167 <input type="hidden" name="action" value="wpsc_set_ms_gdpr">
168 <input id="editor" type="hidden" name="editor" value="<?php echo esc_attr( $settings['editor'] ); ?>">
169 <input id="editor-reg-user" type="hidden" name="editor-reg-user" value="<?php echo esc_attr( $settings['editor-reg-user'] ); ?>">
170 <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_ms_gdpr' ) ); ?>">
171 </form>
172 <script>
173 <?php
174 if ( $settings['editor'] == 'html' ) {
175 ?>
176 jQuery('.wpsc-switch-editor-ct.visual').trigger('click');
177 <?php
178 }
179 if ( $settings['editor-reg-user'] == 'html' ) {
180 ?>
181 jQuery('.wpsc-switch-editor-reg-user.visual').trigger('click');
182 <?php
183 }
184 ?>
185
186 function wpsc_get_tinymce(el, selector, body_id){
187 jQuery(el).parent().find('.text').removeClass('active');
188 jQuery(el).addClass('active');
189 tinymce.remove('#'+selector);
190 tinymce.init({
191 selector:'#'+selector,
192 body_id: body_id,
193 menubar: false,
194 statusbar: false,
195 height : '200',
196 plugins: [
197 'lists link image directionality'
198 ],
199 image_advtab: true,
200 toolbar: 'bold italic underline blockquote | alignleft aligncenter alignright | bullist numlist | rtl | link image',
201 directionality: '<?php echo is_rtl() ? 'rtl' : 'ltr'; ?>',
202 branding: false,
203 autoresize_bottom_margin: 20,
204 browser_spellcheck : true,
205 relative_urls : false,
206 remove_script_host : false,
207 convert_urls : true,
208 setup: function (editor) {
209 }
210 });
211 if( selector == 'gdpr-text' ) {
212 jQuery('#editor').val('html');
213 }else{
214 jQuery('#editor-reg-user').val('html');
215 }
216 }
217
218 function wpsc_get_textarea(el, selector){
219 jQuery(el).parent().find('.visual').removeClass('active');
220 jQuery(el).addClass('active');
221 tinymce.remove('#'+selector);
222 if( selector == 'gdpr-text' ) {
223 jQuery('#editor').val('text');
224 }else{
225 jQuery('#editor-reg-user').val('text');
226 }
227 }
228 </script>
229 <div class="setting-footer-actions">
230 <button
231 class="wpsc-button normal primary margin-right"
232 onclick="wpsc_set_ms_gdpr(this);">
233 <?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button>
234 <button
235 class="wpsc-button normal secondary"
236 onclick="wpsc_reset_ms_gdpr(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_ms_gdpr' ) ); ?>');">
237 <?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button>
238 </div>
239 <?php
240 wp_die();
241 }
242
243 /**
244 * Save settings
245 *
246 * @return void
247 */
248 public static function save_settings() {
249
250 if ( check_ajax_referer( 'wpsc_set_ms_gdpr', '_ajax_nonce', false ) != 1 ) {
251 wp_send_json_error( 'Unauthorised request!', 401 );
252 }
253
254 if ( ! WPSC_Functions::is_site_admin() ) {
255 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
256 }
257
258 $settings = apply_filters(
259 'wpsc_set_gdpr',
260 array(
261 'allow-gdpr' => isset( $_POST['allow-gdpr'] ) ? intval( $_POST['allow-gdpr'] ) : 1,
262 'gdpr-text' => isset( $_POST ) && isset( $_POST['gdpr-text'] ) ? wp_kses_post( wp_unslash( $_POST['gdpr-text'] ) ) : '',
263 'personal-data-retention-time' => isset( $_POST['personal-data-retention-time'] ) ? intval( $_POST['personal-data-retention-time'] ) : 0,
264 'personal-data-retention-unit' => isset( $_POST['personal-data-retention-unit'] ) ? sanitize_text_field( wp_unslash( $_POST['personal-data-retention-unit'] ) ) : 'days',
265 'editor' => isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : 'html',
266 'allow-gdpr-reg-user' => isset( $_POST['allow-gdpr-reg-user'] ) ? intval( $_POST['allow-gdpr-reg-user'] ) : 1,
267 'gdpr-text-reg-user' => isset( $_POST ) && isset( $_POST['gdpr-text-reg-user'] ) ? wp_kses_post( wp_unslash( $_POST['gdpr-text-reg-user'] ) ) : '',
268 'editor-reg-user' => isset( $_POST['editor-reg-user'] ) ? sanitize_text_field( wp_unslash( $_POST['editor-reg-user'] ) ) : 'html',
269 'ip-address-collection' => isset( $_POST['ip-address-collection'] ) ? intval( $_POST['ip-address-collection'] ) : 0,
270 )
271 );
272 update_option( 'wpsc-gdpr-settings', $settings );
273
274 // remove string translations.
275 WPSC_Translations::remove( 'wpsc-gdpr' );
276 WPSC_Translations::remove( 'wpsc-gdpr-reg-user' );
277
278 // add string translations.
279 WPSC_Translations::add( 'wpsc-gdpr', $settings['gdpr-text'] );
280 WPSC_Translations::add( 'wpsc-gdpr-reg-user', $settings['gdpr-text-reg-user'] );
281 wp_die();
282 }
283
284 /**
285 * Reset settings to default
286 *
287 * @return void
288 */
289 public static function reset_settings() {
290
291 if ( check_ajax_referer( 'wpsc_reset_ms_gdpr', '_ajax_nonce', false ) != 1 ) {
292 wp_send_json_error( 'Unauthorised request!', 401 );
293 }
294
295 if ( ! WPSC_Functions::is_site_admin() ) {
296 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
297 }
298 self::reset();
299 wp_die();
300 }
301
302 /**
303 * Print ticket form field
304 *
305 * @return void
306 */
307 public static function print_tff() {
308
309 $gdpr = get_option( 'wpsc-gdpr-settings' );
310 if ( intval( $gdpr['allow-gdpr'] ) === 1 ) {
311 ?>
312 <div class="wpsc-tff wpsc-gdpr wpsc-xs-12 wpsc-sm-12 wpsc-md-12 wpsc-lg-12 required wpsc-visible" data-cft="gdpr">
313 <div class="checkbox-container">
314 <?php $unique_id = uniqid( 'wpsc_' ); ?>
315 <input id="<?php echo esc_attr( $unique_id ); ?>" type="checkbox" value="1"/>
316 <?php
317 $name = WPSC_Translations::get( 'wpsc-gdpr', stripslashes( $gdpr['gdpr-text'] ) );
318 ?>
319 <label for="<?php echo esc_attr( $unique_id ); ?>"><?php echo wp_kses_post( $name ); ?></label>
320 </div>
321 </div>
322 <?php
323 }
324 }
325
326 /**
327 * Validate this type field in create ticket
328 *
329 * @return void
330 */
331 public static function js_validate_ticket_form() {
332 ?>
333
334 case 'gdpr':
335 var checkbox = customField.find('input:checked');
336 if (checkbox.length === 0) {
337 isValid = false;
338 alert(supportcandy.translations.req_gdpr);
339 }
340 break;
341 <?php
342 echo PHP_EOL;
343 }
344
345 /**
346 * Make tickets anonymous - gdpr setting - Personal data retention
347 *
348 * @return void
349 */
350 public static function personal_data_eraser() {
351
352 $settings = get_option( 'wpsc-gdpr-settings', array() );
353
354 // return if age.
355 if ( $settings['personal-data-retention-time'] === 0 ) {
356 return;
357 }
358
359 $tz = wp_timezone();
360 $today = new DateTime( 'now', $tz );
361
362 if ( $settings['personal-data-retention-unit'] == 'days' ) {
363 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'D' ) );
364 } elseif ( $settings['personal-data-retention-unit'] == 'month' ) {
365 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'M' ) );
366 } else {
367 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'Y' ) );
368 }
369
370 $filters = array(
371 'items_per_page' => 0,
372 'meta_query' => array(
373 'relation' => 'AND',
374 array(
375 'slug' => 'date_updated',
376 'compare' => '<',
377 'val' => $today->format( 'Y-m-d' ),
378 ),
379 array(
380 'slug' => 'customer',
381 'compare' => 'NOT IN',
382 'val' => array( 0 ),
383 ),
384 ),
385 );
386
387 // Anonymize active tickets.
388 $active_tickets = WPSC_Ticket::find( $filters );
389 $active_tickets = $active_tickets['results'];
390 foreach ( $active_tickets as $ticket ) {
391 self::anonymize_ticket( $ticket );
392 }
393
394 // Anonymize archive tickets.
395 $archive_tickets = WPSC_Archive_Ticket::find( $filters );
396 $archive_tickets = $archive_tickets['results'];
397 foreach ( $archive_tickets as $ticket ) {
398 self::anonymize_ticket( $ticket );
399 }
400 }
401
402 /**
403 * Anonymize ticket & customer data
404 *
405 * @param WPSC_Ticket/WPSC_Archive_Ticket $ticket - ticket object.
406 * @return void
407 */
408 public static function anonymize_ticket( $ticket ) {
409
410 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
411
412 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && $cf->is_personal_info ) {
413 $val = $cf->type::$has_multiple_val ? array() : '';
414 $ticket->{$cf->slug} = $val;
415 }
416 }
417
418 $filters = array(
419 'meta_query' => array(
420 'relation' => 'AND',
421 array(
422 'slug' => 'customer',
423 'compare' => '=',
424 'val' => $ticket->customer->id,
425 ),
426 ),
427 );
428
429 $thread_class = ( is_object( $ticket ) && is_a( $ticket, 'WPSC_Ticket' ) && ! empty( $ticket->id ) ) ? 'WPSC_Thread' : 'WPSC_Archive_Thread';
430 $threads = $thread_class::find( $filters )['results'];
431
432 $anonymous_customer = WPSC_Functions::anonymous_customer();
433 foreach ( $threads as $thread ) {
434 $thread->customer = $anonymous_customer;
435 $thread->save();
436 }
437
438 $ticket->customer = $anonymous_customer;
439 $ticket->save();
440
441 do_action( 'wpsc_after_anonymizing_ticket', $ticket );
442 }
443
444 /**
445 * Register privacy exporters
446 *
447 * @param array $exporters - privacy expoters.
448 * @return array
449 */
450 public static function wpsc_register_privacy_exporters( $exporters ) {
451
452 $exporters['wpsc_ticket_cust'] = array(
453 'exporter_friendly_name' => __( 'Ticket Customer', 'supportcandy' ),
454 'callback' => array( __CLASS__, 'wpsc_privacy_ticket_customer_exporter' ),
455 );
456
457 $exporters['wpsc_tickets'] = array(
458 'exporter_friendly_name' => __( 'Tickets', 'supportcandy' ),
459 'callback' => array( __CLASS__, 'wpsc_privacy_ticket_exporter' ),
460 );
461
462 return $exporters;
463 }
464
465 /**
466 * Add customer data to privacy exporter
467 *
468 * @param string $email_address - email address.
469 * @param integer $page - page numbers.
470 * @return array
471 */
472 public static function wpsc_privacy_ticket_customer_exporter( $email_address = '', $page = 1 ) {
473
474 $customer = WPSC_Customer::get_by_email( $email_address );
475 if ( ! $customer->id ) {
476 return;
477 }
478
479 $data = array(
480 array(
481 'name' => __( 'Name', 'supportcandy' ),
482 'value' => $customer->name,
483 ),
484 array(
485 'name' => __( 'Email', 'supportcandy' ),
486 'value' => $customer->email,
487 ),
488 );
489
490 $export_customer = array();
491 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
492
493 if ( $cf->field == 'customer' && $cf->is_personal_info && ! in_array( $cf->slug, WPSC_DF_Customer::$ignore_customer_info_cft ) && $customer->{$cf->slug} ) {
494
495 $data[] = array(
496 'name' => stripslashes( $cf->name ),
497 'value' => $cf->type::get_customer_field_val( $cf, $customer ),
498 );
499 }
500 }
501
502 $export_customer[] = array(
503 'group_id' => 'wpsc_ticket_cust',
504 'group_label' => __( 'Ticket Customer', 'supportcandy' ),
505 'item_id' => "wpsc_cust_id-{$customer->id}",
506 'data' => $data,
507 );
508
509 return array(
510 'data' => $export_customer,
511 'done' => true,
512 );
513 }
514
515 /**
516 * Add ticket data to privacy exporter
517 *
518 * @param string $email_address - email address.
519 * @param integer $page - page numbers.
520 * @return array
521 */
522 public static function wpsc_privacy_ticket_exporter( $email_address = '', $page = 1 ) {
523
524 $customer = WPSC_Customer::get_by_email( $email_address );
525 if ( ! $customer->id ) {
526 return;
527 }
528
529 $filters = array(
530 'items_per_page' => 0,
531 'meta_query' => array(
532 'relation' => 'AND',
533 array(
534 'slug' => 'customer',
535 'compare' => '=',
536 'val' => $customer->id,
537 ),
538 ),
539 );
540
541 // Get active tickets.
542 $active_tickets = WPSC_Ticket::find( $filters )['results'];
543 $active_export_tickets = array();
544 $active_export_tickets = self::get_export_ticket_data( $active_tickets );
545
546 // Get archive tickets.
547 $archive_tickets = WPSC_Archive_Ticket::find( $filters )['results'];
548 $archive_export_tickets = array();
549 $archive_export_tickets = self::get_export_ticket_data( $archive_tickets );
550
551 return array(
552 'data' => array_merge( $active_export_tickets, $archive_export_tickets ),
553 'done' => true,
554 );
555 }
556
557 /**
558 * Dummy function to avoid ending class with last public function.
559 *
560 * @param array $tickets - tickets array.
561 * @return array
562 */
563 private static function get_export_ticket_data( $tickets ) {
564
565 $export_tickets = array();
566 foreach ( $tickets as $key => $ticket ) {
567
568 $data = array(
569 array(
570 'name' => __( 'Ticket ID', 'supportcandy' ),
571 'value' => $ticket->id,
572 ),
573 array(
574 'name' => __( 'Subject', 'supportcandy' ),
575 'value' => $ticket->subject,
576 ),
577 array(
578 'name' => __( 'IP Address', 'supportcandy' ),
579 'value' => $ticket->ip_address,
580 ),
581 array(
582 'name' => __( 'Browser', 'supportcandy' ),
583 'value' => $ticket->browser,
584 ),
585 array(
586 'name' => __( 'Operating System', 'supportcandy' ),
587 'value' => $ticket->os,
588 ),
589 );
590 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
591
592 if ( $cf->is_personal_info && in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && ! $cf->type::$is_default && $ticket->{$cf->slug} ) {
593 $val = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? $cf->type::get_ticket_field_val( $cf, $ticket ) : $cf->type::get_customer_field_val( $cf, $ticket->customer );
594 $data[] = array(
595 'name' => stripslashes( $cf->name ),
596 'value' => $val,
597 );
598 }
599 }
600
601 $export_tickets[] = array(
602 'group_id' => 'wpsc_tickets',
603 'group_label' => __( 'User Tickets', 'supportcandy' ),
604 'item_id' => "wpsc_ticket_id-{$ticket->id}",
605 'data' => $data,
606 );
607 }
608 return $export_tickets;
609 }
610
611 /**
612 * Register privacy erasers
613 *
614 * @param array $erasers - rpivacy erasers.
615 * @return array
616 */
617 public static function wpsc_register_privacy_erasers( $erasers = array() ) {
618
619 $erasers[] = array(
620 'eraser_friendly_name' => __( 'Ticket Records', 'supportcandy' ),
621 'callback' => array( __CLASS__, 'wpsc_privacy_customer_erasers' ),
622 );
623
624 return $erasers;
625 }
626
627 /**
628 * Erase customer ticket data
629 *
630 * @param string $email_address - email address.
631 * @param integer $page - page numbers.
632 * @return array
633 */
634 public static function wpsc_privacy_customer_erasers( $email_address, $page = 1 ) {
635
636 $customer = WPSC_Customer::get_by_email( $email_address );
637 if ( ! $customer->id ) {
638 return;
639 }
640
641 $filters = array(
642 'items_per_page' => 0,
643 'meta_query' => array(
644 'relation' => 'AND',
645 array(
646 'slug' => 'customer',
647 'compare' => '=',
648 'val' => $customer->id,
649 ),
650 ),
651 );
652
653 // Anonymize active tickets.
654 $tickets = WPSC_Ticket::find( $filters )['results'];
655 foreach ( $tickets as $ticket ) {
656 self::anonymize_ticket( $ticket );
657 }
658
659 // Anonymize archived tickets.
660 $tickets = WPSC_Archive_Ticket::find( $filters )['results'];
661 foreach ( $tickets as $ticket ) {
662 self::anonymize_ticket( $ticket );
663 }
664
665 // Delete customer record.
666 WPSC_Customer::destroy( $customer );
667
668 /* translators: %s: email address */
669 $message = sprintf( __( 'Tickets of customer having email %s has been anonymized.', 'supportcandy' ), $email_address );
670 return array(
671 'items_removed' => true,
672 'items_retained' => false,
673 'messages' => array( $message ),
674 'done' => true,
675 );
676 }
677 }
678 endif;
679
680 WPSC_MS_GDPR::init();
681