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 / Components / WordpressUser / Controllers / DashboardProfilePageController.php

DashboardProfilePageController.php in The GDPR Framework By Data443 2.1.0, at src/Components/WordpressUser/Controllers/DashboardProfilePageController.php

148 lines 5.1 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\Components\WordpressUser\Controllers;
4
5 use Codelight\GDPR\DataSubject\DataExporter;
6 use Codelight\GDPR\DataSubject\DataSubject;
7 use Codelight\GDPR\DataSubject\DataSubjectManager;
8
9 class DashboardProfilePageController
10 {
11 protected $dataSubjectManager;
12 protected $dataExporter;
13
14 public function __construct(DataSubjectManager $dataSubjectManager, DataExporter $dataExporter)
15 {
16 $this->dataSubjectManager = $dataSubjectManager;
17 $this->dataExporter = $dataExporter;
18
19 add_action('gdpr/dashboard/profile-page/content', [$this, 'renderHeader'], 10);
20 add_action('gdpr/dashboard/profile-page/content', [$this, 'renderConsentTable'], 20);
21 add_action('gdpr/dashboard/profile-page/content', [$this, 'renderExportForm'], 30);
22 add_action('gdpr/dashboard/profile-page/content', [$this, 'renderDeleteForm'], 40);
23 add_action('gdpr/dashboard/profile-page/contentuser', [$this, 'renderHeader'], 10);
24 add_action('gdpr/dashboard/profile-page/contentuser', [$this, 'renderConsentTable'], 20);
25 add_action('gdpr/dashboard/profile-page/userlogs', [$this, 'gdpr_user_logs'], 50);
26
27 add_action('gdpr/admin/action/export', [$this, 'export']);
28 add_action('gdpr/admin/action/forget', [$this, 'forget']);
29 }
30
31 protected function isUserAnonymized(DataSubject $dataSubject)
32 {
33 return !$dataSubject->getEmail();
34 }
35
36 public function renderHeader(DataSubject $dataSubject)
37 {
38 $isAnonymized = $this->isUserAnonymized($dataSubject);
39
40 echo gdpr('view')->render(
41 "modules/wordpress-user/dashboard/profile-page/header",
42 compact('isAnonymized')
43 );
44 }
45
46
47 public function gdpr_user_logs(DataSubject $dataSubject)
48 {
49 if ($this->isUserAnonymized($dataSubject)) {
50 return;
51 }
52
53 $userlogData = $dataSubject->getuserlogsData();
54 echo gdpr('view')->render(
55 "modules/wordpress-user/dashboard/profile-page/user-logs",
56 compact('userlogData')
57 );
58 }
59
60 public function renderConsentTable(DataSubject $dataSubject)
61 {
62 if ($this->isUserAnonymized($dataSubject)) {
63 return;
64 }
65
66 $consentData = $dataSubject->getConsentData();
67
68 echo gdpr('view')->render(
69 "modules/wordpress-user/dashboard/profile-page/table-consent",
70 compact('consentData')
71 );
72 }
73
74 public function renderExportForm(DataSubject $dataSubject)
75 {
76 if ($this->isUserAnonymized($dataSubject)) {
77 return;
78 }
79
80 $exportHTMLUrl = add_query_arg([
81 'gdpr_action' => 'export',
82 'gdpr_format' => 'html',
83 'gdpr_email' => $dataSubject->getEmail(),
84 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/export"),
85 ]);
86
87 $exportJSONUrl = add_query_arg([
88 'gdpr_action' => 'export',
89 'gdpr_format' => 'json',
90 'gdpr_email' => $dataSubject->getEmail(),
91 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/export"),
92 ]);
93
94 echo gdpr('view')->render(
95 "modules/wordpress-user/dashboard/form-export",
96 compact('exportHTMLUrl', 'exportJSONUrl')
97 );
98 }
99
100 public function renderDeleteForm(DataSubject $dataSubject)
101 {
102 if ($this->isUserAnonymized($dataSubject)) {
103 return;
104 }
105
106 // Hide the delete button away from site admins on their own profile page to avoid accidents
107 $showDelete = !(current_user_can('manage_options') && wp_get_current_user()->ID === $dataSubject->getUserId());
108
109 $anonymizeUrl = add_query_arg([
110 'gdpr_email' => $dataSubject->getEmail(),
111 'gdpr_action' => 'forget',
112 'gdpr_force_action' => 'anonymize',
113 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/forget"),
114 ]);
115
116 $deleteUrl = add_query_arg([
117 'gdpr_email' => $dataSubject->getEmail(),
118 'gdpr_action' => 'forget',
119 'gdpr_force_action' => 'delete',
120 'gdpr_nonce' => wp_create_nonce("gdpr/admin/action/forget"),
121 ]);
122
123 echo gdpr('view')->render(
124 "modules/wordpress-user/dashboard/profile-page/form-delete",
125 compact('anonymizeUrl', 'deleteUrl', 'showDelete')
126 );
127 }
128
129 public function export()
130 {
131 $gdpr_email = sanitize_email($_REQUEST['gdpr_email']);
132 $gdpr_format = sanitize_key($_REQUEST['gdpr_format']);
133 $dataSubject = $this->dataSubjectManager->getByEmail($gdpr_email);
134 $data = $dataSubject->export($gdpr_format, true);
135 $this->dataExporter->export($data, $dataSubject, $gdpr_format);
136 }
137
138 public function forget()
139 {
140 $gdpr_email = sanitize_email($_REQUEST['gdpr_email']);
141 $gdpr_force_action = sanitize_key($_REQUEST['gdpr_force_action']);
142 $dataSubject = $this->dataSubjectManager->getByEmail($gdpr_email);
143 $dataSubject->forget($gdpr_force_action);
144
145 wp_safe_redirect(admin_url('users.php'));
146 }
147 }
148