/** * Notify all previous commenters about a new comment * * @param Fishpig_Wordpress_Model_Post_Comment $comment */ public function notify(Fishpig_Wordpress_Model_Post_Comment $comment) { if ($this->isEnabled() && $comment->getPost()->getCommentCount() > 1) { // Load a collection of applicable comments $collection = Mage::getResourceModel('wordpress/post_comment_collection'); $collection->addPostIdFilter($comment->getPostId()); if ($comment->getUserId()) { $collection->addUserIdFilter(array('neq' => $comment->getUserId())); } $collection->addCommentAuthorEmailFilter(array('neq' => $comment->getCommentAuthorEmail())); if ($this->canDisplayOptIn()) { $collection->getSelect()->where('comment_mail_notify=?', 1); } $collection->addOrderByDate('asc'); $collection->addCommentApprovedFilter(); $collection->load(); // Determine whether to check for Admin or post author $checkUserStatus = $this->getPluginOption('mail_notify') == 'admin'; // Store emails already notified to stop duplicates being sent // to users with multiple comments $emailsNotified = array(); foreach ($collection as $oldComment) { if (!$checkUserStatus || $newComment->getUserId() == $newComment->getPostId()) { if (!in_array($oldComment->getCommentAuthorEmail(), $emailsNotified)) { $emailsNotified[] = $oldComment->getCommentAuthorEmail(); $this->_notify($oldComment, $comment); } } } } }