PluginProbe
The GDPR Framework By Data443 / trunk
The GDPR Framework By Data443 vtrunk
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 trunk, at src/DataSubject/AdminTabDataSubject.php

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