Calcetines Extreme

Calcetines Extreme
Take care of you using the best socks

Saturday, September 15, 2012

Update K2 to send mail notifications on new comments

Problem:

Really it's not a problem, is a new requirement to allow Joomla K2 component to send notifications when a new comment has been published on frontpage; i still don't understand how that functionality has not been implementd on standar release of K2.

Solution:

we need to edit the code that allow to save new comments, you can find that on components/com_k2/models/item.php once.

1.- edit item.php and search for function comment()

2.- search string "...K2_COMMENT_ADDED_AND_WAITING_FOR_APPROVAL..."

3.- before that line add the next code:


$mainframe = &JFactory::getApplication(); $mail = &JFactory::getMailer(); $senderEmail = $mainframe->getCfg('mailfrom'); $senderName = $mainframe->getCfg('fromname'); $mail->setSender(array($senderEmail, $senderName)); $mail->setSubject(JText::_('K2_COMMENT_REPORT')); $mail->IsHTML(true); $body = " <strong>".JText::_('K2_NAME')."</strong>: ".$name." <br/> <strong>".JText::_('K2_REPORT_REASON')."</strong>: ".$reportReason." <br/> <strong>".JText::_('K2_COMMENT')."</strong>: ".nl2br($row->commentText)." <br/> "; $mail->setBody($body); $mail->ClearAddresses(); $mail->AddAddress($params->get('commentsReportRecipient', $mainframe->getCfg('mailfrom'))); $mail->Send();