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 / DashboardDataPageController.php

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

204 lines 6.2 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\DataSubjectAuthenticator;
8
9 /**
10 * Handles Users > Privacy Tools page
11 *
12 * Class DashboardDataPageController
13 *
14 * @package Codelight\GDPR\Modules\WordpressUser\Controllers
15 */
16 class DashboardDataPageController
17 {
18 protected $dataExporter;
19 protected $dataSubjectAuthenticator;
20
21 /**
22 * DashboardDataPageController constructor.
23 *
24 * @param DataExporter $dataExporter
25 */
26 public function __construct(DataExporter $dataExporter, DataSubjectAuthenticator $dataSubjectAuthenticator)
27 {
28 $this->dataExporter = $dataExporter;
29 $this->dataSubjectAuthenticator = $dataSubjectAuthenticator;
30
31 add_action('gdpr/dashboard/privacy-tools/content', [$this, 'renderHeader'], 10);
32 add_action('gdpr/dashboard/privacy-tools/content', [$this, 'renderConsentForm'], 20);
33 add_action('gdpr/dashboard/privacy-tools/content', [$this, 'renderExportForm'], 30);
34 add_action('gdpr/dashboard/privacy-tools/content', [$this, 'renderDeleteForm'], 40);
35
36 add_action('gdpr/dashboard/privacy-tools/action/withdraw_consent', [$this, 'withdrawConsent']);
37 add_action('gdpr/dashboard/privacy-tools/action/export', [$this, 'export']);
38 add_action('gdpr/dashboard/privacy-tools/action/forget', [$this, 'forget']);
39
40 add_action('admin_notices', [$this, 'renderAdminNotices']);
41 }
42
43 /**
44 * Render success notices via admin_notice action
45 */
46 public function renderAdminNotices()
47 {
48 if ('profile_page_gdpr-profile' !== get_current_screen()->base) {
49 return;
50 }
51
52 if (!isset($_REQUEST['gdpr_notice'])) {
53 return;
54 }
55
56 if ('request_sent' === sanitize_key($_REQUEST['gdpr_notice'])) {
57 $message = __('We have received your request and will reply within 30 days.', 'gdpr-framework');
58 $class = 'notice notice-success';
59 }
60
61 if ('consent_withdrawn' === sanitize_key($_REQUEST['gdpr_notice'])) {
62 $message = __('Consent withdrawn.', 'gdpr-framework');
63 $class = 'notice notice-success';
64 }
65
66 echo gdpr('view')->render('admin/notice', compact('message', 'class'));
67 }
68
69 /**
70 * Render page header
71 */
72 public function renderHeader()
73 {
74 echo gdpr('view')->render(
75 "modules/wordpress-user/dashboard/data-page/header"
76 );
77 }
78
79 /**
80 * Render the consent form
81 *
82 * @param DataSubject $dataSubject
83 */
84 public function renderConsentForm(DataSubject $dataSubject)
85 {
86 global $gdpr;
87 $consentData = $dataSubject->getVisibleConsentData();
88
89 foreach ($consentData as &$item) {
90 $item['withdraw_url'] = add_query_arg([
91 'gdpr_action' => 'withdraw_consent',
92 'gdpr_nonce' => wp_create_nonce("gdpr/dashboard/privacy-tools/action/withdraw_consent"),
93 'email' => $dataSubject->getEmail(),
94 'consent' => $item['slug'],
95 ]);
96 }
97
98 $consentInfo = wpautop($gdpr->Options->get('consent_info'));
99
100 echo gdpr('view')->render(
101 "modules/wordpress-user/dashboard/data-page/form-consent",
102 compact('consentData', 'consentInfo')
103 );
104 }
105
106 /**
107 * Render the buttons that allow exporting data
108 */
109 public function renderExportForm()
110 {
111 $exportHTMLUrl = add_query_arg([
112 'gdpr_action' => 'export',
113 'gdpr_format' => 'html',
114 'gdpr_nonce' => wp_create_nonce("gdpr/dashboard/privacy-tools/action/export"),
115 ]);
116
117 $exportJSONUrl = add_query_arg([
118 'gdpr_action' => 'export',
119 'gdpr_format' => 'json',
120 'gdpr_nonce' => wp_create_nonce("gdpr/dashboard/privacy-tools/action/export"),
121 ]);
122
123 echo gdpr('view')->render(
124 "modules/wordpress-user/dashboard/form-export",
125 compact('exportHTMLUrl', 'exportJSONUrl')
126 );
127 }
128
129 /**
130 * Render the delete data button
131 */
132 public function renderDeleteForm()
133 {
134 $showDelete = !current_user_can('manage_options');
135 $url = add_query_arg([
136 'gdpr_action' => 'forget',
137 'gdpr_nonce' => wp_create_nonce("gdpr/dashboard/privacy-tools/action/forget"),
138 ]);
139
140 echo gdpr('view')->render(
141 "modules/wordpress-user/dashboard/data-page/form-delete",
142 compact('url', 'showDelete')
143 );
144 }
145
146 /**
147 * @param DataSubject $dataSubject
148 */
149 public function withdrawConsent(DataSubject $dataSubject)
150 {
151 $consent = sanitize_key($_REQUEST['consent']);
152 $dataSubject->withdrawConsent($consent);
153 $this->redirect(['gdpr_notice' => 'consent_withdrawn']);
154 }
155
156 /**
157 * @param DataSubject $dataSubject
158 */
159 public function export(DataSubject $dataSubject)
160 {
161 $gdpr_format = sanitize_key($_REQUEST['gdpr_format']);
162 $data = $dataSubject->export($gdpr_format);
163
164 if (!is_null($data)) {
165 // If there is data, download it
166 $this->dataExporter->export($data, $dataSubject, $gdpr_format);
167 } else {
168 // If there's no data, then show notification that your request has been sent.
169 $this->redirect(['gdpr_notice' => 'request_sent']);
170 }
171 }
172
173 /**
174 * @param DataSubject $dataSubject
175 */
176 public function forget(DataSubject $dataSubject)
177 {
178 $status = $dataSubject->forget();
179
180 if (!$status) {
181 $this->redirect(['gdpr_notice' => 'request_sent']);
182 } else {
183 $this->dataSubjectAuthenticator->deleteSession();
184 $this->redirect([], '/');
185 }
186 }
187
188 /**
189 * Redirect the visitor to an appropriate location
190 *
191 * @param array $args
192 * @param null $baseUrl
193 */
194 protected function redirect($args = [], $baseUrl = null)
195 {
196 if (!$baseUrl) {
197 $baseUrl = gdpr('helpers')->getDashboardDataPageUrl();
198 }
199
200 wp_safe_redirect(add_query_arg($args, $baseUrl));
201 exit;
202 }
203 }
204