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

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

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