| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codelight\GDPR\Components\PrivacyPolicy; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 |
|
| 7 |
use Codelight\GDPR\Admin\AdminTab; |
| 8 |
|
| 9 |
class AdminTabPrivacyPolicy extends AdminTab |
| 10 |
{ |
| 11 |
/* @var string */ |
| 12 |
protected $slug = 'privacy-policy'; |
| 13 |
|
| 14 |
/* @var PolicyGenerator */ |
| 15 |
protected $policyGenerator; |
| 16 |
|
| 17 |
public function __construct(PolicyGenerator $policyGenerator) |
| 18 |
{ |
| 19 |
$this->policyGenerator = $policyGenerator; |
| 20 |
|
| 21 |
$this->title = _x('Privacy Policy', '(Admin)', 'gdpr-framework'); |
| 22 |
|
| 23 |
$this->registerSetting('gdpr_company_name'); |
| 24 |
$this->registerSetting('gdpr_contact_email'); |
| 25 |
$this->registerSetting('gdpr_company_location'); |
| 26 |
|
| 27 |
$this->registerSetting('gdpr_representative_contact_name'); |
| 28 |
$this->registerSetting('gdpr_representative_contact_email'); |
| 29 |
$this->registerSetting('gdpr_representative_contact_phone'); |
| 30 |
|
| 31 |
$this->registerSetting('gdpr_dpa_website'); |
| 32 |
$this->registerSetting('gdpr_dpa_email'); |
| 33 |
$this->registerSetting('gdpr_dpa_phone'); |
| 34 |
|
| 35 |
$this->registerSetting('gdpr_has_dpo'); |
| 36 |
$this->registerSetting('gdpr_dpo_name'); |
| 37 |
$this->registerSetting('gdpr_dpo_email'); |
| 38 |
$this->registerSetting('gdpr_delete_text'); |
| 39 |
|
| 40 |
/* |
| 41 |
$this->registerSetting('gdpr_pp_data_gathered_1'); |
| 42 |
$this->registerSetting('gdpr_pp_data_gathered_2'); |
| 43 |
$this->registerSetting('gdpr_pp_data_gathered_3'); |
| 44 |
$this->registerSetting('gdpr_pp_data_gathered_4'); |
| 45 |
|
| 46 |
$this->registerSetting('gdpr_pp_data_usage_1'); |
| 47 |
$this->registerSetting('gdpr_pp_data_usage_2'); |
| 48 |
$this->registerSetting('gdpr_pp_data_usage_3'); |
| 49 |
$this->registerSetting('gdpr_pp_data_usage_4'); |
| 50 |
|
| 51 |
$this->registerSetting('gdpr_pp_data_partners'); |
| 52 |
*/ |
| 53 |
|
| 54 |
add_action('gdpr/admin/action/privacy-policy/generate', [$this, 'generatePolicy']); |
| 55 |
} |
| 56 |
|
| 57 |
public function init() |
| 58 |
{ |
| 59 |
/** |
| 60 |
* General settings |
| 61 |
*/ |
| 62 |
$this->registerSettingSection( |
| 63 |
'gdpr_section_privacy_policy', |
| 64 |
_x('Privacy Policy', '(Admin)', 'gdpr-framework'), |
| 65 |
[$this, 'renderHeader'] |
| 66 |
); |
| 67 |
|
| 68 |
/** |
| 69 |
* Company info |
| 70 |
*/ |
| 71 |
$this->registerSettingSection( |
| 72 |
'gdpr_section_privacy_policy_company', |
| 73 |
_x('Company information', '(Admin)', 'gdpr-framework') |
| 74 |
); |
| 75 |
|
| 76 |
$this->registerSettingField( |
| 77 |
'gdpr_company_name', |
| 78 |
_x('Company Name', '(Admin)', 'gdpr-framework'), |
| 79 |
[$this, 'renderCompanyNameHtml'], |
| 80 |
'gdpr_section_privacy_policy_company' |
| 81 |
); |
| 82 |
|
| 83 |
|
| 84 |
$this->registerSettingField( |
| 85 |
'gdpr_company_email', |
| 86 |
_x('Company Email', '(Admin)', 'gdpr-framework'), |
| 87 |
[$this, 'renderCompanyEmailHtml'], |
| 88 |
'gdpr_section_privacy_policy_company' |
| 89 |
); |
| 90 |
|
| 91 |
$this->registerSettingField( |
| 92 |
'gdpr_company_location', |
| 93 |
_x('Company Location', '(Admin)', 'gdpr-framework'), |
| 94 |
[$this, 'renderCompanyLocationHtml'], |
| 95 |
'gdpr_section_privacy_policy_company' |
| 96 |
); |
| 97 |
|
| 98 |
/** |
| 99 |
* Representative |
| 100 |
*/ |
| 101 |
$this->registerSettingSection( |
| 102 |
'gdpr_section_privacy_policy_representative', |
| 103 |
false, |
| 104 |
[$this, 'renderRepresentativeOpen'] |
| 105 |
); |
| 106 |
|
| 107 |
$this->registerSettingField( |
| 108 |
'gdpr_representative_contact_name', |
| 109 |
_x('Representative Contact Name', '(Admin)', 'gdpr-framework'), |
| 110 |
[$this, 'renderRepresentativeContactName'], |
| 111 |
'gdpr_section_privacy_policy_representative' |
| 112 |
); |
| 113 |
|
| 114 |
$this->registerSettingField( |
| 115 |
'gdpr_representative_contact_email', |
| 116 |
_x('Representative Contact Email', '(Admin)', 'gdpr-framework'), |
| 117 |
[$this, 'renderRepresentativeContactEmail'], |
| 118 |
'gdpr_section_privacy_policy_representative' |
| 119 |
); |
| 120 |
|
| 121 |
$this->registerSettingField( |
| 122 |
'gdpr_representative_contact_phone', |
| 123 |
_x('Representative Contact Phone', '(Admin)', 'gdpr-framework'), |
| 124 |
[$this, 'renderRepresentativeContactPhone'], |
| 125 |
'gdpr_section_privacy_policy_representative' |
| 126 |
); |
| 127 |
|
| 128 |
$this->registerSettingSection( |
| 129 |
'gdpr_section_privacy_policy_representative_close', |
| 130 |
false, |
| 131 |
[$this, 'renderRepresentativeClose'] |
| 132 |
); |
| 133 |
|
| 134 |
/** |
| 135 |
* DPA |
| 136 |
*/ |
| 137 |
$this->registerSettingSection( |
| 138 |
'gdpr_section_privacy_policy_dpa', |
| 139 |
_x('Data Protection Authority', '(Admin)', 'gdpr-framework'), |
| 140 |
[$this, 'renderDpaJS'] |
| 141 |
); |
| 142 |
|
| 143 |
$this->registerSettingField( |
| 144 |
'gdpr_dpa_website', |
| 145 |
_x('Data Protection Authority Website', '(Admin)', 'gdpr-framework'), |
| 146 |
[$this, 'renderDpaWebsite'], |
| 147 |
'gdpr_section_privacy_policy_dpa' |
| 148 |
); |
| 149 |
|
| 150 |
$this->registerSettingField( |
| 151 |
'gdpr_dpa_email', |
| 152 |
_x('Data Protection Authority Email', '(Admin)', 'gdpr-framework'), |
| 153 |
[$this, 'renderDpaEmail'], |
| 154 |
'gdpr_section_privacy_policy_dpa' |
| 155 |
); |
| 156 |
|
| 157 |
$this->registerSettingField( |
| 158 |
'gdpr_dpa_phone', |
| 159 |
_x('Data Protection Authority Phone', '(Admin)', 'gdpr-framework'), |
| 160 |
[$this, 'renderDpaPhone'], |
| 161 |
'gdpr_section_privacy_policy_dpa' |
| 162 |
); |
| 163 |
|
| 164 |
/** |
| 165 |
* DPO |
| 166 |
*/ |
| 167 |
$this->registerSettingSection( |
| 168 |
'gdpr_section_privacy_policy_dpo', |
| 169 |
_x('Data Protection Officer', '(Admin)', 'gdpr-framework'), |
| 170 |
function() { |
| 171 |
echo "<a href='https://data443.atlassian.net/servicedesk/customer/portal/2/article/28213359' target='_blank'>"; |
| 172 |
echo _x('Knowledge base: Do I need to appoint a Data Protection Officer?', '(Admin)', 'gdpr-framework'); |
| 173 |
echo "</a>"; |
| 174 |
} |
| 175 |
); |
| 176 |
|
| 177 |
$this->registerSettingField( |
| 178 |
'gdpr_has_dpo', |
| 179 |
_x('Data Protection Officer', '(Admin)', 'gdpr-framework'), |
| 180 |
[$this, 'renderHasDPOHtml'], |
| 181 |
'gdpr_section_privacy_policy_dpo' |
| 182 |
); |
| 183 |
|
| 184 |
$this->registerSettingField( |
| 185 |
'gdpr_dpo_name', |
| 186 |
_x('Data Protection Officer Name', '(Admin)', 'gdpr-framework'), |
| 187 |
[$this, 'renderDPONameHtml'], |
| 188 |
'gdpr_section_privacy_policy_dpo', |
| 189 |
['class' => 'gdpr-dpo hidden'] |
| 190 |
); |
| 191 |
|
| 192 |
$this->registerSettingField( |
| 193 |
'gdpr_dpo_email', |
| 194 |
_x('Data Protection Officer Email', '(Admin)', 'gdpr-framework'), |
| 195 |
[$this, 'renderDPOEmailHtml'], |
| 196 |
'gdpr_section_privacy_policy_dpo', |
| 197 |
['class' => 'gdpr-dpo hidden'] |
| 198 |
); |
| 199 |
|
| 200 |
/** |
| 201 |
* Change Delete Text |
| 202 |
*/ |
| 203 |
|
| 204 |
$this->registerSettingField( |
| 205 |
'gdpr_delete_text', |
| 206 |
_x('Delete Text', '(Admin)', 'gdpr-framework'), |
| 207 |
[$this, 'renderDeleteTextHtml'], |
| 208 |
'gdpr_section_privacy_policy_company' |
| 209 |
); |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
public function renderHeader() |
| 214 |
{ |
| 215 |
echo gdpr('view')->render('admin/privacy-policy/header'); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Company info |
| 220 |
*/ |
| 221 |
|
| 222 |
public function renderCompanyNameHtml() |
| 223 |
{ |
| 224 |
global $gdpr; |
| 225 |
$value = $gdpr->Options->get('company_name') ? esc_attr($gdpr->Options->get('company_name')) : ''; |
| 226 |
$placeholder = _x('Company Name', '(Admin)', 'gdpr-framework'); |
| 227 |
echo "<input name='gdpr_company_name' placeholder='{$placeholder}' value='{$value}'>"; |
| 228 |
} |
| 229 |
|
| 230 |
public function renderCompanyEmailHtml() |
| 231 |
{ |
| 232 |
global $gdpr; |
| 233 |
$value = $gdpr->Options->get('contact_email') ? esc_attr($gdpr->Options->get('contact_email')) : ''; |
| 234 |
$placeholder = _x('Contact Email', '(Admin)', 'gdpr-framework'); |
| 235 |
echo "<input type='email' name='gdpr_contact_email' placeholder='{$placeholder}' value='{$value}'>"; |
| 236 |
} |
| 237 |
|
| 238 |
public function renderCompanyLocationHtml() |
| 239 |
{ |
| 240 |
global $gdpr; |
| 241 |
$country = $gdpr->Options->get('company_location') ? $gdpr->Options->get('company_location') : ''; |
| 242 |
$countrySelectOptions = gdpr('helpers')->getCountrySelectOptions($country); |
| 243 |
echo gdpr('view')->render('admin/privacy-policy/company-location', compact('countrySelectOptions')); |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Representative contact |
| 248 |
*/ |
| 249 |
|
| 250 |
public function renderRepresentativeOpen() |
| 251 |
{ |
| 252 |
echo "<span class='gdpr-representative hidden'>"; |
| 253 |
echo "<h3>"; |
| 254 |
echo _x('Representative Contact', '(Admin)', 'gdpr-framework'); |
| 255 |
echo "</h3>"; |
| 256 |
echo "<a href='https://data443.atlassian.net/servicedesk/customer/portal/2/article/28082218' target='_blank'>"; |
| 257 |
echo _x('Knowledge base: Do I need to appoint an EU-based representative?', '(Admin)', 'gdpr-framework'); |
| 258 |
echo "</a>"; |
| 259 |
} |
| 260 |
|
| 261 |
public function renderRepresentativeContactName() |
| 262 |
{ |
| 263 |
global $gdpr; |
| 264 |
$value = $gdpr->Options->get('representative_contact_name') ? esc_attr($gdpr->Options->get('representative_contact_name')) : ''; |
| 265 |
$placeholder = _x('Representative Contact Name', '(Admin)', 'gdpr-framework'); |
| 266 |
echo "<input name='gdpr_representative_contact_name' placeholder='{$placeholder}' value='{$value}'>"; |
| 267 |
} |
| 268 |
|
| 269 |
public function renderRepresentativeContactEmail() |
| 270 |
{ |
| 271 |
global $gdpr; |
| 272 |
$value = $gdpr->Options->get('representative_contact_email') ? esc_attr($gdpr->Options->get('representative_contact_email')) : ''; |
| 273 |
$placeholder = _x('Representative Contact Email', '(Admin)', 'gdpr-framework'); |
| 274 |
echo "<input type='email' name='gdpr_representative_contact_email' placeholder='{$placeholder}' value='{$value}'>"; |
| 275 |
} |
| 276 |
|
| 277 |
public function renderRepresentativeContactPhone() |
| 278 |
{ |
| 279 |
global $gdpr; |
| 280 |
$value = $gdpr->Options->get('representative_contact_phone') ? esc_attr($gdpr->Options->get('representative_contact_phone')) : ''; |
| 281 |
$placeholder = _x('Representative Contact Phone', '(Admin)', 'gdpr-framework'); |
| 282 |
echo "<input name='gdpr_representative_contact_phone' placeholder='{$placeholder}' value='{$value}'>"; |
| 283 |
} |
| 284 |
|
| 285 |
public function renderRepresentativeClose() |
| 286 |
{ |
| 287 |
echo "</span>"; |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Data Protection Authority |
| 292 |
*/ |
| 293 |
public function renderDpaJS() |
| 294 |
{ |
| 295 |
//echo "<a href='https://data443.com/wordpress-gdpr-framework/knowledge-base/do-i-need-to-appoint-an-eu-based-representative/' target='_blank'>"; |
| 296 |
echo sprintf( |
| 297 |
_x('See the %slist of contacts here%s.', '(Admin)', 'gdpr-framework'), |
| 298 |
'<a href="http://ec.europa.eu/justice/data-protection/article-29/structure/data-protection-authorities/index_en.htm" target="_blank">', |
| 299 |
'</a>' |
| 300 |
); |
| 301 |
//echo "</a>"; |
| 302 |
|
| 303 |
$dpaData = json_encode(gdpr('helpers')->getDataProtectionAuthorities()); |
| 304 |
echo gdpr('view')->render('admin/privacy-policy/dpa', compact('dpaData')); |
| 305 |
} |
| 306 |
|
| 307 |
public function renderDpaWebsite() |
| 308 |
{ |
| 309 |
global $gdpr; |
| 310 |
$value = $gdpr->Options->get('dpa_website') ? esc_attr($gdpr->Options->get('dpa_website')) : ''; |
| 311 |
$placeholder = _x('Data Protection Authority Website', '(Admin)', 'gdpr-framework'); |
| 312 |
echo "<input name='gdpr_dpa_website' id='gdpr_dpa_website' placeholder='{$placeholder}' value='{$value}' data-set='{$value}'>"; |
| 313 |
} |
| 314 |
|
| 315 |
public function renderDpaEmail() |
| 316 |
{ |
| 317 |
global $gdpr; |
| 318 |
$value = $gdpr->Options->get('dpa_email') ? esc_attr($gdpr->Options->get('dpa_email')) : ''; |
| 319 |
$placeholder = _x('Data Protection Authority Email', '(Admin)', 'gdpr-framework'); |
| 320 |
echo "<input type='email' name='gdpr_dpa_email' id='gdpr_dpa_email' placeholder='{$placeholder}' value='{$value}' data-set='{$value}'>"; |
| 321 |
} |
| 322 |
|
| 323 |
public function renderDpaPhone() |
| 324 |
{ |
| 325 |
global $gdpr; |
| 326 |
$value = $gdpr->Options->get('dpa_phone') ? esc_attr($gdpr->Options->get('dpa_phone')) : ''; |
| 327 |
$placeholder = _x('Data Protection Authority Phone', '(Admin)', 'gdpr-framework'); |
| 328 |
echo "<input name='gdpr_dpa_phone' id='gdpr_dpa_phone' placeholder='{$placeholder}' value='{$value}' data-set='{$value}'>"; |
| 329 |
} |
| 330 |
|
| 331 |
/** |
| 332 |
* Data Protection Officer |
| 333 |
*/ |
| 334 |
|
| 335 |
public function renderHasDPOHtml() |
| 336 |
{ |
| 337 |
global $gdpr; |
| 338 |
$hasDPO = $gdpr->Options->get('has_dpo'); |
| 339 |
echo gdpr('view')->render('admin/privacy-policy/has-dpo', compact('hasDPO')); |
| 340 |
} |
| 341 |
|
| 342 |
public function renderDPONameHtml() |
| 343 |
{ |
| 344 |
global $gdpr; |
| 345 |
$value = $gdpr->Options->get('dpo_name') ? esc_attr($gdpr->Options->get('dpo_name')) : ''; |
| 346 |
$placeholder = _x('DPO Name', '(Admin)', 'gdpr-framework'); |
| 347 |
echo "<input name='gdpr_dpo_name' placeholder='{$placeholder}' value='{$value}'>"; |
| 348 |
} |
| 349 |
|
| 350 |
public function renderDPOEmailHtml() |
| 351 |
{ |
| 352 |
global $gdpr; |
| 353 |
$value = $gdpr->Options->get('dpo_email') ? esc_attr($gdpr->Options->get('dpo_email')) : ''; |
| 354 |
$placeholder = _x('DPO Email', '(Admin)', 'gdpr-framework'); |
| 355 |
echo "<input type='email' name='gdpr_dpo_email' placeholder='{$placeholder}' value='{$value}'>"; |
| 356 |
} |
| 357 |
|
| 358 |
public function renderDeleteTextHtml() |
| 359 |
{ |
| 360 |
global $gdpr; |
| 361 |
$value = $gdpr->Options->get('delete_text') ? esc_attr($gdpr->Options->get('delete_text')) : ''; |
| 362 |
$placeholder = _x('Delete Text', '(Admin)', 'gdpr-framework'); |
| 363 |
echo "<input name='gdpr_delete_text' placeholder='{$placeholder}' value='{$value}'>"; |
| 364 |
} |
| 365 |
|
| 366 |
public function generatePolicy() |
| 367 |
{ |
| 368 |
global $gdpr; |
| 369 |
$policyPage = $gdpr->Options->get('policy_page'); |
| 370 |
|
| 371 |
if ( ! $policyPage) { |
| 372 |
return; |
| 373 |
} |
| 374 |
|
| 375 |
$policy = gdpr('view')->render( |
| 376 |
'policy/policy' |
| 377 |
); |
| 378 |
|
| 379 |
wp_update_post([ |
| 380 |
'ID' => $policyPage, |
| 381 |
'post_content' => $policy, |
| 382 |
]); |
| 383 |
|
| 384 |
wp_safe_redirect(gdpr('helpers')->getAdminUrl('&gdpr-tab=privacy-policy&gdpr_notice=policy_generated')); |
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* Render either the settings or the generated policy |
| 389 |
*/ |
| 390 |
public function renderContents() |
| 391 |
{ |
| 392 |
if (isset($_GET['settings-updated']) && 'true' == $_GET['settings-updated']) { |
| 393 |
return $this->renderPolicy(); |
| 394 |
} else { |
| 395 |
return parent::renderContents(); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
public function renderPolicy() |
| 400 |
{ |
| 401 |
global $gdpr; |
| 402 |
$policyPageId = $gdpr->Options->get('policy_page'); |
| 403 |
if ($policyPageId) { |
| 404 |
$policyUrl = get_edit_post_link($policyPageId); |
| 405 |
} else { |
| 406 |
$policyUrl = false; |
| 407 |
} |
| 408 |
|
| 409 |
$editor = $this->getPolicyEditor(); |
| 410 |
$backUrl = gdpr('helpers')->getAdminUrl('&gdpr-tab=privacy-policy'); |
| 411 |
|
| 412 |
return gdpr('view')->render('admin/privacy-policy/generated', compact('editor', 'policyUrl', 'backUrl')); |
| 413 |
} |
| 414 |
|
| 415 |
protected function getPolicyEditor() |
| 416 |
{ |
| 417 |
ob_start(); |
| 418 |
|
| 419 |
wp_editor( |
| 420 |
wp_kses_post($this->policyGenerator->generate()), |
| 421 |
'gdpr_policy', |
| 422 |
[ |
| 423 |
'media_buttons' => false, |
| 424 |
'editor_height' => 600, |
| 425 |
'teeny' => true, |
| 426 |
'editor_css' => '<style>#mceu_16 { display: none; }</style>' |
| 427 |
] |
| 428 |
); |
| 429 |
|
| 430 |
return ob_get_clean(); |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Render WP's default submit button |
| 435 |
*/ |
| 436 |
public function renderSubmitButton() |
| 437 |
{ |
| 438 |
submit_button(_x('Save & Generate Policy', '(Admin)', 'gdpr-framework')); |
| 439 |
} |
| 440 |
} |
| 441 |
|