PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
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.5.4, at includes/admin/settings/miscellaneous-settings/class-wpsc-ms-gdpr.php

680 lines 22.8 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( 'Unauthorized 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( 'Unauthorized 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 if (customField.find('input:checked').length === 0) {
336 showFieldError(customField, supportcandy.translations.req_gdpr);
337 isValid = false;
338 }
339 break;
340 <?php
341 echo PHP_EOL;
342 }
343
344 /**
345 * Make tickets anonymous - gdpr setting - Personal data retention
346 *
347 * @return void
348 */
349 public static function personal_data_eraser() {
350
351 $settings = get_option( 'wpsc-gdpr-settings', array() );
352
353 // return if age.
354 if ( $settings['personal-data-retention-time'] === 0 ) {
355 return;
356 }
357
358 $tz = wp_timezone();
359 $today = new DateTime( 'now', $tz );
360
361 if ( $settings['personal-data-retention-unit'] == 'days' ) {
362 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'D' ) );
363 } elseif ( $settings['personal-data-retention-unit'] == 'month' ) {
364 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'M' ) );
365 } else {
366 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'Y' ) );
367 }
368
369 $filters = array(
370 'items_per_page' => 0,
371 'meta_query' => array(
372 'relation' => 'AND',
373 array(
374 'slug' => 'date_updated',
375 'compare' => '<',
376 'val' => $today->format( 'Y-m-d' ),
377 ),
378 array(
379 'slug' => 'customer',
380 'compare' => 'NOT IN',
381 'val' => array( 0 ),
382 ),
383 ),
384 );
385
386 // Anonymize active tickets.
387 $active_tickets = WPSC_Ticket::find( $filters );
388 $active_tickets = $active_tickets['results'];
389 foreach ( $active_tickets as $ticket ) {
390 self::anonymize_ticket( $ticket );
391 }
392
393 // Anonymize archive tickets.
394 $archive_tickets = WPSC_Archive_Ticket::find( $filters );
395 $archive_tickets = $archive_tickets['results'];
396 foreach ( $archive_tickets as $ticket ) {
397 self::anonymize_ticket( $ticket );
398 }
399 }
400
401 /**
402 * Anonymize ticket & customer data
403 *
404 * @param WPSC_Ticket/WPSC_Archive_Ticket $ticket - ticket object.
405 * @return void
406 */
407 public static function anonymize_ticket( $ticket ) {
408
409 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
410
411 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && $cf->is_personal_info ) {
412 $val = $cf->type::$has_multiple_val ? array() : '';
413 $ticket->{$cf->slug} = $val;
414 }
415 }
416
417 $filters = array(
418 'meta_query' => array(
419 'relation' => 'AND',
420 array(
421 'slug' => 'customer',
422 'compare' => '=',
423 'val' => $ticket->customer->id,
424 ),
425 ),
426 );
427
428 $thread_class = is_a( $ticket, 'WPSC_Ticket' ) ? 'WPSC_Thread' : 'WPSC_Archive_Thread';
429 $threads = $thread_class::find( $filters )['results'];
430
431 $anonymous_customer = WPSC_Functions::anonymous_customer();
432 foreach ( $threads as $thread ) {
433 $thread->customer = $anonymous_customer;
434 $thread->save();
435 }
436
437 $ticket->customer = $anonymous_customer;
438 $ticket->save();
439
440 do_action( 'wpsc_after_anonymizing_ticket', $ticket );
441 }
442
443 /**
444 * Register privacy exporters
445 *
446 * @param array $exporters - privacy expoters.
447 * @return array
448 */
449 public static function wpsc_register_privacy_exporters( $exporters ) {
450
451 $exporters['wpsc_ticket_cust'] = array(
452 'exporter_friendly_name' => __( 'Ticket Customer', 'supportcandy' ),
453 'callback' => array( __CLASS__, 'wpsc_privacy_ticket_customer_exporter' ),
454 );
455
456 $exporters['wpsc_tickets'] = array(
457 'exporter_friendly_name' => __( 'Tickets', 'supportcandy' ),
458 'callback' => array( __CLASS__, 'wpsc_privacy_ticket_exporter' ),
459 );
460
461 return $exporters;
462 }
463
464 /**
465 * Add customer data to privacy exporter
466 *
467 * @param string $email_address - email address.
468 * @param integer $page - page numbers.
469 * @return array
470 */
471 public static function wpsc_privacy_ticket_customer_exporter( $email_address = '', $page = 1 ) {
472
473 $customer = WPSC_Customer::get_by_email( $email_address );
474 if ( ! $customer->id ) {
475 return;
476 }
477
478 $data = array(
479 array(
480 'name' => __( 'Name', 'supportcandy' ),
481 'value' => $customer->name,
482 ),
483 array(
484 'name' => __( 'Email', 'supportcandy' ),
485 'value' => $customer->email,
486 ),
487 );
488
489 $export_customer = array();
490 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
491
492 if ( $cf->field == 'customer' && $cf->is_personal_info && ! in_array( $cf->slug, WPSC_DF_Customer::$ignore_customer_info_cft ) && $customer->{$cf->slug} ) {
493
494 $data[] = array(
495 'name' => stripslashes( $cf->name ),
496 'value' => $cf->type::get_customer_field_val( $cf, $customer ),
497 );
498 }
499 }
500
501 $export_customer[] = array(
502 'group_id' => 'wpsc_ticket_cust',
503 'group_label' => __( 'Ticket Customer', 'supportcandy' ),
504 'item_id' => "wpsc_cust_id-{$customer->id}",
505 'data' => $data,
506 );
507
508 return array(
509 'data' => $export_customer,
510 'done' => true,
511 );
512 }
513
514 /**
515 * Add ticket data to privacy exporter
516 *
517 * @param string $email_address - email address.
518 * @param integer $page - page numbers.
519 * @return array
520 */
521 public static function wpsc_privacy_ticket_exporter( $email_address = '', $page = 1 ) {
522
523 $customer = WPSC_Customer::get_by_email( $email_address );
524 if ( ! $customer->id ) {
525 return;
526 }
527
528 $filters = array(
529 'items_per_page' => 0,
530 'meta_query' => array(
531 'relation' => 'AND',
532 array(
533 'slug' => 'customer',
534 'compare' => '=',
535 'val' => $customer->id,
536 ),
537 ),
538 );
539
540 // Get active tickets.
541 $active_tickets = WPSC_Ticket::find( $filters )['results'];
542 $active_export_tickets = array();
543 $active_export_tickets = self::get_export_ticket_data( $active_tickets );
544
545 // Get archive tickets.
546 $archive_tickets = WPSC_Archive_Ticket::find( $filters )['results'];
547 $archive_export_tickets = array();
548 $archive_export_tickets = self::get_export_ticket_data( $archive_tickets );
549
550 return array(
551 'data' => array_merge( $active_export_tickets, $archive_export_tickets ),
552 'done' => true,
553 );
554 }
555
556 /**
557 * Dummy function to avoid ending class with last public function.
558 *
559 * @param array $tickets - tickets array.
560 * @return array
561 */
562 private static function get_export_ticket_data( $tickets ) {
563
564 $export_tickets = array();
565 foreach ( $tickets as $key => $ticket ) {
566
567 $data = array(
568 array(
569 'name' => __( 'Ticket ID', 'supportcandy' ),
570 'value' => $ticket->id,
571 ),
572 array(
573 'name' => __( 'Subject', 'supportcandy' ),
574 'value' => $ticket->subject,
575 ),
576 array(
577 'name' => __( 'IP Address', 'supportcandy' ),
578 'value' => $ticket->ip_address,
579 ),
580 array(
581 'name' => __( 'Browser', 'supportcandy' ),
582 'value' => $ticket->browser,
583 ),
584 array(
585 'name' => __( 'Operating System', 'supportcandy' ),
586 'value' => $ticket->os,
587 ),
588 );
589 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
590
591 if ( $cf->is_personal_info && in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && ! $cf->type::$is_default && $ticket->{$cf->slug} ) {
592 $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 );
593 $data[] = array(
594 'name' => stripslashes( $cf->name ),
595 'value' => $val,
596 );
597 }
598 }
599
600 $export_tickets[] = array(
601 'group_id' => 'wpsc_tickets',
602 'group_label' => __( 'User Tickets', 'supportcandy' ),
603 'item_id' => "wpsc_ticket_id-{$ticket->id}",
604 'data' => $data,
605 );
606 }
607 return $export_tickets;
608 }
609
610 /**
611 * Register privacy erasers
612 *
613 * @param array $erasers - rpivacy erasers.
614 * @return array
615 */
616 public static function wpsc_register_privacy_erasers( $erasers = array() ) {
617
618 $erasers[] = array(
619 'eraser_friendly_name' => __( 'Ticket Records', 'supportcandy' ),
620 'callback' => array( __CLASS__, 'wpsc_privacy_customer_erasers' ),
621 );
622
623 return $erasers;
624 }
625
626 /**
627 * Erase customer ticket data
628 *
629 * @param string $email_address - email address.
630 * @param integer $page - page numbers.
631 * @return array
632 */
633 public static function wpsc_privacy_customer_erasers( $email_address, $page = 1 ) {
634
635 $customer = WPSC_Customer::get_by_email( $email_address );
636 if ( ! $customer->id ) {
637 return;
638 }
639
640 $filters = array(
641 'items_per_page' => 0,
642 'meta_query' => array(
643 'relation' => 'AND',
644 array(
645 'slug' => 'customer',
646 'compare' => '=',
647 'val' => $customer->id,
648 ),
649 ),
650 );
651
652 // Anonymize active tickets.
653 $tickets = WPSC_Ticket::find( $filters )['results'];
654 foreach ( $tickets as $ticket ) {
655 self::anonymize_ticket( $ticket );
656 }
657
658 // Anonymize archived tickets.
659 $tickets = WPSC_Archive_Ticket::find( $filters )['results'];
660 foreach ( $tickets as $ticket ) {
661 self::anonymize_ticket( $ticket );
662 }
663
664 // Delete customer record.
665 WPSC_Customer::destroy( $customer );
666
667 /* translators: %s: email address */
668 $message = sprintf( __( 'Tickets of customer having email %s has been anonymized.', 'supportcandy' ), $email_address );
669 return array(
670 'items_removed' => true,
671 'items_retained' => false,
672 'messages' => array( $message ),
673 'done' => true,
674 );
675 }
676 }
677 endif;
678
679 WPSC_MS_GDPR::init();
680