public static function notifyAdmin(array $comment)
{
// don't notify admin in case of spam
if ($comment['status'] == 'spam') {
return;
}
// get settings
$notifyByMailOnComment = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment', false);
$notifyByMailOnCommentToModerate = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment_to_moderate', false);
// create URLs
$url = SITE_URL . FrontendNavigation::getURLForBlock('Blog', 'Detail') . '/' . $comment['post_url'] . '#comment-' . $comment['id'];
$backendURL = SITE_URL . FrontendNavigation::getBackendURLForBlock('comments', 'Blog') . '#tabModeration';
// notify on all comments
if ($notifyByMailOnComment) {
// init var
$variables = null;
// comment to moderate
if ($comment['status'] == 'moderation') {
$variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $url, $comment['post_title'], $backendURL));
} elseif ($comment['status'] == 'published') {
// comment was published
$variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewComment'), array($comment['author'], $url, $comment['post_title']));
}
$to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
$from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
$replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
$message = Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Core/Layout/Templates/Mails/Notification.html.twig', $variables, true);
FrontendModel::get('mailer')->send($message);
} elseif ($notifyByMailOnCommentToModerate && $comment['status'] == 'moderation') {
// only notify on new comments to moderate and if the comment is one to moderate
// set variables
$variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $url, $comment['post_title'], $backendURL));
$to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
$from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
$replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
$message = Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Core/Layout/Templates/Mails/Notification.html.twig', $variables, true);
FrontendModel::get('mailer')->send($message);
}
}