/**
* Add the subscription and send the activation mail (double opt-in)
*
* @param CommentsModel $objComment
*/
public static function addCommentsSubscription(CommentsModel $objComment)
{
$objNotify = \CommentsNotifyModel::findBySourceParentAndEmail($objComment->source, $objComment->parent, $objComment->email);
// The subscription exists already
if ($objNotify !== null) {
return;
}
$time = time();
// Prepare the record
$arrSet = array('tstamp' => $time, 'source' => $objComment->source, 'parent' => $objComment->parent, 'name' => $objComment->name, 'email' => $objComment->email, 'url' => \Environment::get('request'), 'addedOn' => $time, 'ip' => \System::anonymizeIp(\Environment::get('ip')), 'tokenConfirm' => md5(uniqid(mt_rand(), true)), 'tokenRemove' => md5(uniqid(mt_rand(), true)));
// Store the subscription
$objNotify = new \CommentsNotifyModel();
$objNotify->setRow($arrSet)->save();
$strUrl = \Idna::decode(\Environment::get('base')) . \Environment::get('request');
$strConnector = strpos($strUrl, '?') !== false ? '&' : '?';
// Send the activation mail
$objEmail = new \Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
$objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['com_optInSubject'], \Idna::decode(\Environment::get('host')));
$objEmail->text = sprintf($GLOBALS['TL_LANG']['MSC']['com_optInMessage'], $objComment->name, $strUrl, $strUrl . $strConnector . 'token=' . $objNotify->tokenConfirm, $strUrl . $strConnector . 'token=' . $objNotify->tokenRemove);
$objEmail->sendTo($objComment->email);
}