| 1 |
<?php |
| 2 |
namespace Codelight\GDPR\Modules\NewsletterGdpr; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
use Codelight\GDPR\Components\Consent\ConsentManager; |
| 7 |
use Codelight\GDPR\DataSubject\DataSubjectManager; |
| 8 |
|
| 9 |
if(file_exists(dirname( ES_PLUGIN_FILE ) . '/includes/db/class-es-db-contacts.php')) |
| 10 |
{ |
| 11 |
include_once dirname( ES_PLUGIN_FILE ) . '/includes/db/class-es-db-contacts.php'; |
| 12 |
}else{ |
| 13 |
include_once dirname( ES_PLUGIN_FILE ) . '/lite/includes/db/class-es-db-contacts.php'; |
| 14 |
} |
| 15 |
|
| 16 |
// Support plugin name: Email Subscribers & Newsletters |
| 17 |
|
| 18 |
class NewsletterGdpr |
| 19 |
{ |
| 20 |
/* @var DataSubjectManager */ |
| 21 |
protected $dataSubjectManager; |
| 22 |
|
| 23 |
/* @var ConsentManager */ |
| 24 |
protected $consentManager; |
| 25 |
|
| 26 |
public function __construct(DataSubjectManager $dataSubjectManager, ConsentManager $consentManager) |
| 27 |
{ |
| 28 |
$this->dataSubjectManager = $dataSubjectManager; |
| 29 |
$this->consentManager = $consentManager; |
| 30 |
|
| 31 |
if (!defined('ES_PLUGIN_VERSION')) |
| 32 |
{ |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
add_filter('gdpr/data-subject/data', [$this, 'getNewsletterExportData'], 20, 2); |
| 37 |
add_action('gdpr/data-subject/delete', [$this, 'deleteNewsletterEntries']); |
| 38 |
add_action('gdpr/data-subject/anonymize', [$this, 'deleteNewsletterEntries']); |
| 39 |
add_action('ig_es_after_form_fields',[$this, 'newsletter_checkbox_consent']); |
| 40 |
add_filter('ig_es_add_subscriber_data', [$this, 'newsletter_gdpr_consent']); |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
public function newsletter_checkbox_consent($data) |
| 45 |
{ |
| 46 |
global $gdpr; |
| 47 |
$policyPage = $gdpr->Options->get('policy_page'); |
| 48 |
|
| 49 |
$policyPageUrl = get_permalink($policyPage); |
| 50 |
|
| 51 |
add_filter( 'gdpr-framework-consent-policy', 'gdprfPrivacyPolicy' ); |
| 52 |
|
| 53 |
$gdpr_text_policy = apply_filters( 'gdpr-framework-consent-policy','true'); |
| 54 |
|
| 55 |
$data = '<div class="es-field-wrap"> |
| 56 |
<input type="checkbox" name="es-gdpr-agree" id="es-gdpr-agree" value="1" required="required"> '; |
| 57 |
$data .= sprintf( |
| 58 |
__($gdpr_text_policy, 'gdpr-framework'), |
| 59 |
"<a href='{$policyPageUrl}' target='_blank'>", |
| 60 |
"</a>"); |
| 61 |
$data .='</div>'; |
| 62 |
|
| 63 |
echo $data; |
| 64 |
} |
| 65 |
|
| 66 |
public function newsletter_gdpr_consent($data){ |
| 67 |
if($_POST['esfpx_email']){ |
| 68 |
|
| 69 |
$esfpx_email = sanitize_email($_POST['esfpx_email']); |
| 70 |
$dataSubject = $this->dataSubjectManager->getByEmail($esfpx_email); |
| 71 |
$dataSubject->giveConsent('privacy-policy'); |
| 72 |
} |
| 73 |
return $data; |
| 74 |
} |
| 75 |
|
| 76 |
public function getNewsletterExportData(array $data, $email) |
| 77 |
{ |
| 78 |
global $wpdb; |
| 79 |
|
| 80 |
$results = $wpdb->get_row($wpdb->prepare("SELECT wc.*, GROUP_CONCAT(DISTINCT ls.name ORDER BY ls.name) as list_details FROM {$wpdb->prefix}ig_contacts as wc LEFT JOIN {$wpdb->prefix}ig_lists_contacts as wl ON wc.id = wl.contact_id LEFT JOIN {$wpdb->prefix}ig_lists as ls ON ls.id = wl.list_id WHERE email = %s",sanitize_email($email)),ARRAY_A); |
| 81 |
|
| 82 |
if (!count($results)) { |
| 83 |
return $data; |
| 84 |
} |
| 85 |
|
| 86 |
unset($results['hash'],$results['is_rolebased'],$results['is_webmail'],$results['is_deliverable'],$results['is_sendsafely'],$results['is_verified'],$results['is_disposable'],$results['id']); |
| 87 |
|
| 88 |
if($results['email']) |
| 89 |
{ |
| 90 |
$title = __('Newsletter Form submissions: ', 'gdpr'); |
| 91 |
foreach ($results as $i => $message) |
| 92 |
{ |
| 93 |
$data[$title][$i] = $message; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return $data; |
| 98 |
} |
| 99 |
/* |
| 100 |
* Delete user information from order by email address. |
| 101 |
*/ |
| 102 |
public function deleteNewsletterEntries($email) |
| 103 |
{ |
| 104 |
$contact_id = \ES_DB_Contacts::get_contact_id_by_email($email); |
| 105 |
if($contact_id){ |
| 106 |
\ES_DB_Contacts::delete_subscribers(array($contact_id)); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|