PluginProbe
The GDPR Framework By Data443 / 2.1.0
The GDPR Framework By Data443 v2.1.0
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / DataSubject / AdminTabDataSubject.php

AdminTabDataSubject.php in The GDPR Framework By Data443 2.1.0, at src/DataSubject/AdminTabDataSubject.php

146 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR\DataSubject;
4
5 use Codelight\GDPR\Admin\AdminTab;
6
7 /**
8 * Class AdminTabDataSubject
9 *
10 * @package Codelight\GDPR\DataSubject
11 */
12 class AdminTabDataSubject extends AdminTab
13 {
14 /* @var string */
15 protected $slug = 'data-subject';
16
17 /* @var DataSubjectManager */
18 protected $dataSubjectManager;
19
20 /**
21 * AdminTabDataSubject constructor.
22 *
23 * @param DataSubjectManager $dataSubjectManager
24 */
25 public function __construct(DataSubjectManager $dataSubjectManager)
26 {
27 $this->title = _x('Data Subjects', '(Admin)', 'gdpr-framework');
28 $this->dataSubjectManager = $dataSubjectManager;
29
30 // Workaround to allow this page to be submitted
31 $this->registerSetting('gdpr_email');
32
33 // Register handler for this action
34 add_action('gdpr/admin/action/search', [$this, 'searchRedirect']);
35 }
36
37 public function init()
38 {
39 $this->registerSettingSection(
40 'gdpr-section-data-subjects',
41 _x('Data Subjects', '(Admin)', 'gdpr-framework'),
42 [$this, 'renderTab']
43 );
44 }
45
46 public function renderTab()
47 {
48 if (isset($_GET['search']) && $_GET['search']) {
49 $searched_email = sanitize_email($_GET['search']);
50
51 $results = $this->getRenderedResults($searched_email, $this->dataSubjectManager->getByEmail($searched_email));
52 } else {
53 $results = '';
54 }
55
56 $nonce = wp_create_nonce('gdpr/admin/action/search');
57 // Fram-136 - define variables before access
58 $exportUrl = '';
59 $deleteUrl = '';
60 echo gdpr('view')->render(
61 'admin/data-subjects/search-form',
62 compact('nonce', 'results', 'exportUrl', 'deleteUrl')
63 );
64 }
65
66 public function getRenderedResults($email, DataSubject $dataSubject)
67 {
68 $hasData = $dataSubject->hasData();
69 $links = [];
70 $userName = false;
71 $adminCap = false;
72 if(isset($_GET['search'])){
73 $searched_email= sanitize_email($_GET['search']);
74 }
75 if ($hasData) {
76 if ($dataSubject->getUserId()) {
77 $userName = get_userdata($dataSubject->getUserId())->user_login;
78 $links['profile'] = get_edit_user_link($dataSubject->getUserId());
79 $adminCap = user_can($dataSubject->getUserId(), 'manage_options');
80 }
81
82 /**
83 * TODO: these actions are currently triggered in DashboardProfilePageController
84 * Should replace this with a generic AdminController!
85 * Also consider namespacing gdpr_action in this case, i.e. profile/delete vs data-subject-tab/delete
86 */
87 $links['view'] = add_query_arg([
88 'gdpr_action' => 'export',
89 'gdpr_format' => 'html',
90 'gdpr_email' => $searched_email,
91 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/export"),
92 ]);
93
94 $links['export'] = add_query_arg([
95 'gdpr_action' => 'export',
96 'gdpr_format' => 'json',
97 'gdpr_email' => $searched_email,
98 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/export"),
99 ]);
100
101 $links['anonymize'] = add_query_arg([
102 'gdpr_email' => $searched_email,
103 'gdpr_action' => 'forget',
104 'gdpr_force_action' => 'anonymize',
105 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/forget"),
106 ]);
107
108 $links['delete'] = add_query_arg([
109 'gdpr_email' => $searched_email,
110 'gdpr_action' => 'forget',
111 'gdpr_force_action' => 'delete',
112 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/forget"),
113 ]);
114 }
115
116 $consentData = $dataSubject->getConsentData();
117
118 return gdpr('view')->render('admin/data-subjects/search-results', compact('email', 'hasData', 'links', 'userName', 'adminCap', 'consentData'));
119 }
120
121 public function renderSubmitButton()
122 {
123 // Intentionally left blank
124 }
125
126 public function searchRedirect()
127 {
128 if (isset($_POST['gdpr_email']) && $_POST['gdpr_email']) {
129 $gdpr_email = sanitize_email($_POST['gdpr_email']);
130 wp_safe_redirect(gdpr('helpers')->getAdminUrl('&gdpr-tab=data-subject&search=' . $gdpr_email));
131 exit;
132 }
133 }
134
135 public function gdpr_get_formatted_billing_name_and_address($user_id)
136 {
137 $address = get_user_meta( $user_id, 'billing_address_1', true )." ";
138 $address .= get_user_meta( $user_id, 'billing_address_2', true )." ";
139 $address .= get_user_meta( $user_id, 'billing_city', true )." ";
140 $address .= get_user_meta( $user_id, 'billing_state', true )." ";
141 $address .= get_user_meta( $user_id, 'billing_postcode', true )." ";
142 $address .= get_user_meta( $user_id, 'billing_country', true )." ";
143 return $address;
144 }
145 }
146