Last active
October 1, 2015 00:07
-
-
Save tristanlins/1883699 to your computer and use it in GitHub Desktop.
Avisota E-Mail Benachrichtigung bei Anmeldung, Aktivierung und Abmeldung für Anbieter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config.php | |
<?php | |
$GLOBALS['TL_HOOKS']['avisotaSubscribe'][] = array('CustomAvisotaNotification', 'hookAvisotaSubscribe'); | |
$GLOBALS['TL_HOOKS']['avisotaActivateSubscribtion'][] = array('CustomAvisotaNotification', 'hookAvisotaActivateSubscribtion'); | |
$GLOBALS['TL_HOOKS']['avisotaUnsubscribe'][] = array('CustomAvisotaNotification', 'hookAvisotaUnsubscribe'); | |
?> | |
// CustomAvisotaNotification.php | |
<?php | |
class CustomAvisotaNotification | |
{ | |
function hookAvisotaSubscribe($arrRecipient, $arrTokens) | |
{ | |
$arrLists = array_keys($arrTokens); | |
$objLists = \Database::getInstance() | |
->execute("SELECT * FROM tl_avisota_recipient_list WHERE id IN (0," . implode(',', $arrLists) . ")"); | |
$strEmail = $arrRecipient['email']; | |
$arrListNames = $objLists->fetchEach('title'); | |
$arrPersonals = array(); | |
foreach ($arrRecipient as $key => $value) { | |
$arrPersonals[] = sprintf('%s: %s', $key, $value); | |
} | |
$this->sendMessage( | |
'Newsletter Anmeldung', | |
sprintf( | |
"Der Abonnent %s hat seine Anmeldung zu folgenden Listen bestätigt:\n- %s\n\nSeine persönlichen Daten:\n- %s", | |
$strEmail, | |
implode("\n- ", $arrListNames), | |
implode("\n- ", $arrPersonals) | |
) | |
); | |
} | |
function hookAvisotaActivateSubscribtion($id, $strEmail, $strToken) | |
{ | |
$arrRecipient = \Database::getInstance() | |
->prepare("SELECT * FROM tl_avisota_recipient WHERE id=?") | |
->limit(1) | |
->execute($id) | |
->fetchAssoc(); | |
$arrLists = array($arrRecipient['pid']); | |
$objLists = \Database::getInstance() | |
->execute("SELECT * FROM tl_avisota_recipient_list WHERE id IN (0," . implode(',', $arrLists) . ")"); | |
$strEmail = $arrRecipient['email']; | |
$arrListNames = $objLists->fetchEach('title'); | |
$arrPersonals = array(); | |
foreach ($arrRecipient as $key => $value) { | |
$arrPersonals[] = sprintf('%s: %s', $key, $value); | |
} | |
$this->sendMessage( | |
'Newsletter Anmeldung bestätigt', | |
sprintf( | |
"Der Abonnent %s hat seine Anmeldung zu folgender Liste bestätigt:\n- %s\n\nSeine persönlichen Daten:\n- %s", | |
$strEmail, | |
implode("\n- ", $arrListNames), | |
implode("\n- ", $arrPersonals) | |
) | |
); | |
} | |
public function hookAvisotaUnsubscribe() | |
{ | |
// unsubscribe by direct link | |
if (func_num_args() == 2) { | |
list($strEmail, $arrLists) = func_get_args(); | |
$arrRecipient = \Database::getInstance() | |
->prepare("SELECT * FROM tl_avisota_recipient WHERE email=?") | |
->limit(1) | |
->execute($strEmail) | |
->fetchAssoc(); | |
} | |
// unsubscribe via module | |
else { | |
list($arrRecipient) = func_get_args(); | |
$arrLists = $arrRecipient['lists']; | |
} | |
$objLists = \Database::getInstance() | |
->execute("SELECT * FROM tl_avisota_recipient_list WHERE id IN (0," . implode(',', $arrLists) . ")"); | |
$strEmail = $arrRecipient['email']; | |
$arrListNames = $objLists->fetchEach('title'); | |
$arrPersonals = array(); | |
foreach ($arrRecipient as $key => $value) { | |
$arrPersonals[] = sprintf('%s: %s', $key, $value); | |
} | |
$this->sendMessage( | |
'Newsletter Abmeldung', | |
sprintf( | |
"Der Abonnent %s hat sich von den folgenden Liste abgemeldet:\n- %s\n\nSeine persönlichen Daten:\n- %s", | |
$strEmail, | |
implode("\n- ", $arrListNames), | |
implode("\n- ", $arrPersonals) | |
) | |
); | |
} | |
protected function sendMessage($subject, $body) | |
{ | |
$objEmail = new Email(); | |
// TODO change your sender | |
$objEmail->from = '[email protected]'; | |
$objEmail->fromName = 'Avisota custom notification'; | |
$objEmail->subject = $subject; | |
$objEmail->text = $body; | |
// TODO change you recipient | |
$objEmail->sendTo('[email protected]'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment