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 / Installer / Steps / PolicySettings.php

PolicySettings.php in The GDPR Framework By Data443 2.1.0, at src/Installer/Steps/PolicySettings.php

265 lines 9.4 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\Installer\Steps;
4
5 use Codelight\GDPR\Installer\InstallerStep;
6 use Codelight\GDPR\Installer\InstallerStepInterface;
7
8 class PolicySettings extends InstallerStep implements InstallerStepInterface
9 {
10 protected $slug = 'policy-settings';
11
12 protected $type = 'wizard';
13
14 protected $template = 'installer/steps/policy-settings';
15
16 protected $activeSteps = 2;
17
18 protected function renderContent()
19 {
20 global $gdpr;
21 $policyPage = $gdpr->Options->get('policy_page');
22 $policyPageSelector = wp_dropdown_pages([
23 'name' => 'gdpr_policy_page',
24 'show_option_none' => _x('&mdash; Create a new page &mdash;', '(Admin)', 'gdpr-framework'),
25 'option_none_value' => 'new',
26 'selected' => $policyPage ? $policyPage : 'new',
27 'echo' => false,
28 'class' => 'gdpr-select js-gdpr-select2',
29 ]);
30
31 $hasTermsPage = $gdpr->Options->get('has_terms_page');
32 $termsPage = $gdpr->Options->get('terms_page');
33 $policy_page_url = $gdpr->Options->get('custom_policy_page');
34 // Woo compatibility
35 if (!$termsPage && get_option('woocommerce_terms_page_id')) {
36 $hasTermsPage = 'yes';
37 $termsPage = get_option('woocommerce_terms_page_id');
38 $termsPageNote = _x(
39 'We have automatically selected your WooCommerce Terms & Conditions page.',
40 '(Admin)',
41 'gdpr-framework'
42 );
43 } else {
44 $termsPageNote = false;
45 }
46
47 $termsPageSelector = wp_dropdown_pages([
48 'name' => 'gdpr_terms_page',
49 'show_option_none' => _x('&mdash; Create a new page &mdash;', '(Admin)', 'gdpr-framework'),
50 'option_none_value' => 'new',
51 'selected' => $termsPage ? $termsPage : 'new',
52 'echo' => false,
53 'class' => 'gdpr-select js-gdpr-select2',
54 ]);
55 $termsPageUrl = $gdpr->Options->get('custom_terms_page');
56
57 $companyName = $gdpr->Options->get('company_name');
58 $companyLocation = $gdpr->Options->get('company_location');
59 $countryOptions = gdpr('helpers')->getCountrySelectOptions($companyLocation);
60 $contactEmail = $gdpr->Options->get('contact_email') ?
61 $gdpr->Options->get('contact_email') :
62 get_option('admin_email');
63
64 $representativeContactName = $gdpr->Options->get('representative_contact_name');
65 $representativeContactEmail = $gdpr->Options->get('representative_contact_email');
66 $representativeContactPhone = $gdpr->Options->get('representative_contact_phone');
67
68 $dpaWebsite = $gdpr->Options->get('dpa_website');
69 $dpaEmail = $gdpr->Options->get('dpa_email');
70 $dpaPhone = $gdpr->Options->get('dpa_phone');
71 $dpaData = json_encode(gdpr('helpers')->getDataProtectionAuthorities());
72
73 $hasDPO = $gdpr->Options->get('has_dpo');
74 $dpoName = $gdpr->Options->get('dpo_name');
75 $dpoEmail = $gdpr->Options->get('dpo_email');
76
77 echo gdpr('view')->render(
78 $this->template,
79 compact(
80 'policyPage',
81 'policyPageSelector',
82 'policy_page_url',
83 'companyName',
84 'companyLocation',
85 'contactEmail',
86 'countryOptions',
87 'hasDPO',
88 'dpoEmail',
89 'dpoName',
90 'representativeContactName',
91 'representativeContactEmail',
92 'representativeContactPhone',
93 'dpaWebsite',
94 'dpaEmail',
95 'dpaPhone',
96 'dpaData',
97 'hasTermsPage',
98 'termsPage',
99 'termsPageSelector',
100 'termsPageNote',
101 'termsPageUrl'
102 )
103 );
104 }
105
106 /*
107 public function validate()
108 {
109 if (!is_email($_POST['gdpr_contact_email'])) {
110 $this->errors = 'Company email is not a valid email!';
111 return false;
112 }
113
114 return true;
115
116 //filter_var($url, FILTER_VALIDATE_URL) === FALSE
117 }
118 */
119
120 public function submit()
121 {
122 global $gdpr;
123 /**
124 * Policy page
125 */
126 if (isset($_POST['gdpr_create_policy_page']) && 'yes' === $_POST['gdpr_create_policy_page']) {
127 $id = $this->createPolicyPage();
128 $gdpr->Options->set('policy_page', $id);
129 } else {
130 $gdpr->Options->set('policy_page', sanitize_text_field($_POST['gdpr_policy_page']));
131 }
132
133
134 /**
135 * Custom Policy page URL
136 */
137 if (isset($_POST['gdpr_custom_policy_page']) && '' != $_POST['gdpr_custom_policy_page']) {
138 $gdpr->Options->set('custom_policy_page',sanitize_text_field($_POST['gdpr_custom_policy_page']));
139 } else {
140 $gdpr->Options->set('custom_policy_page', "");
141 }
142
143 /**
144 * 'Generate policy' checkbox
145 */
146 if (isset($_POST['gdpr_generate_policy']) && 'yes' === $_POST['gdpr_generate_policy']) {
147 $this->generatePolicy();
148 $gdpr->Options->set('policy_generated', true);
149 } else {
150 $gdpr->Options->set('policy_generated', false);
151 }
152
153 /**
154 * Company information
155 */
156 $gdpr->Options->set('company_name', sanitize_text_field($_POST['gdpr_company_name']));
157 $gdpr->Options->set('company_location', sanitize_text_field($_POST['gdpr_company_location']));
158
159 if (is_email($_POST['gdpr_contact_email'])) {
160 $gdpr->Options->set('contact_email', sanitize_email($_POST['gdpr_contact_email']));
161 }
162
163 /**
164 * Data Protection Officer
165 */
166 if (isset($_POST['gdpr_has_dpo'])) {
167 $gdpr->Options->set('has_dpo', sanitize_text_field($_POST['gdpr_has_dpo']));
168 }
169
170 $gdpr->Options->set('dpo_name', sanitize_text_field($_POST['gdpr_dpo_name']));
171
172 if (is_email($_POST['gdpr_dpo_email'])) {
173 $gdpr->Options->set('dpo_email', sanitize_email($_POST['gdpr_dpo_email']));
174 }
175
176 /**
177 * Representative contact
178 */
179 $gdpr->Options->set('representative_contact_name', sanitize_text_field($_POST['gdpr_representative_contact_name']));
180 $gdpr->Options->set('representative_contact_phone', sanitize_text_field($_POST['gdpr_representative_contact_phone']));
181
182 if (is_email($_POST['gdpr_representative_contact_email'])) {
183 $gdpr->Options->set('representative_contact_email', sanitize_email($_POST['gdpr_representative_contact_email']));
184 }
185
186 /**
187 * Data protection authority
188 */
189 $gdpr->Options->set('dpa_website', sanitize_text_field($_POST['gdpr_dpa_website']));
190 $gdpr->Options->set('dpa_phone', sanitize_text_field($_POST['gdpr_dpa_phone']));
191
192 if (is_email($_POST['gdpr_dpa_email'])) {
193 $gdpr->Options->set('dpa_email', sanitize_email($_POST['gdpr_dpa_email']));
194 }
195
196
197 /**
198 * Terms page
199 */
200 if (isset($_POST['gdpr_has_terms_page'])) {
201 $gdpr->Options->set('has_terms_page', sanitize_text_field($_POST['gdpr_has_terms_page']));
202 }
203
204 if (isset($_POST['gdpr_has_terms_page']) && 'yes' === $_POST['gdpr_has_terms_page'] && isset($_POST['gdpr_terms_page'])) {
205 $gdpr->Options->set('terms_page', sanitize_text_field($_POST['gdpr_terms_page']));
206 } else {
207 $gdpr->Options->delete('terms_page');
208 }
209 }
210
211 protected function createPolicyPage()
212 {
213 $id = wp_insert_post([
214 'post_title' => __('Privacy Policy', 'gdpr-framework'),
215 'post_type' => 'page',
216 ]);
217
218 return $id;
219 }
220
221 protected function generatePolicy()
222 {
223 global $gdpr;
224 wp_update_post([
225 'ID' => $gdpr->Options->get('policy_page'),
226 'post_content' => gdpr('view')->render(
227 'policy/policy',
228 $this->getData()
229 ),
230 ]);
231 }
232
233 public function getData()
234 {
235 global $gdpr;
236 $location = $gdpr->Options->get('company_location');
237 $date = date(get_option('date_format'));
238
239 return [
240 'companyName' => $gdpr->Options->get('company_name'),
241 'companyLocation' => $location,
242 'contactEmail' => $gdpr->Options->get('contact_email') ?
243 $gdpr->Options->get('contact_email') :
244 get_option('admin_email'),
245
246 'hasRepresentative' => gdpr('helpers')->countryNeedsRepresentative($location),
247 'representativeContactName' => $gdpr->Options->get('representative_contact_name'),
248 'representativeContactEmail' => $gdpr->Options->get('representative_contact_email'),
249 'representativeContactPhone' => $gdpr->Options->get('representative_contact_phone'),
250
251 'dpaWebsite' => $gdpr->Options->get('dpa_website'),
252 'dpaEmail' => $gdpr->Options->get('dpa_email'),
253 'dpaPhone' => $gdpr->Options->get('dpa_phone'),
254
255 'hasDpo' => $gdpr->Options->get('has_dpo'),
256 'dpoName' => $gdpr->Options->get('dpo_name'),
257 'dpoEmail' => $gdpr->Options->get('dpo_email'),
258
259 'hasTerms' => $gdpr->Options->get('terms_page'),
260
261 'date' => $date,
262 ];
263 }
264 }
265