/**
  * Create a wall activity for this user after posting an answer.
  *
  * @param CMA_Thread $instance
  * @param CMA_Answer $answer
  */
 static function answer_posted_activity(CMA_Thread $instance, CMA_Answer $answer)
 {
     if (!$instance->isPublished()) {
         return;
     } else {
         if (!$answer->isApproved() or $answer->isPrivate()) {
             return;
         }
     }
     $post = $instance->getPost();
     $user_id = $answer->getAuthorId();
     $permalink = $answer->getPermalink();
     $action = sprintf(CMA::__('%s answered to the question "%s"'), bp_core_get_userlink($user_id), sprintf('<a href="%s">%s</a>', esc_attr($permalink), esc_html($instance->getTitle())));
     $content = CMA_Thread::lightContent($answer->getContent());
     if (function_exists('bp_activity_add')) {
         bp_activity_add(array('action' => $action, 'content' => $content, 'component' => self::COMPONENT, 'type' => 'answer_posted', 'primary_link' => $permalink, 'user_id' => $user_id, 'item_id' => $answer->getId()));
     }
     if ($category = $instance->getCategory()) {
         $groups = self::getRelatedGroups(array($category->getId(), $category->getParentId()));
         if ($groups) {
             foreach ($groups as $groupId) {
                 if (function_exists('groups_record_activity')) {
                     groups_record_activity(array('action' => $action, 'content' => $content, 'type' => 'new_groupblog_post', 'primary_link' => $permalink, 'item_id' => $groupId, 'secondary_item_id' => $answer->getAuthorId(), 'hide_sitewide' => 0));
                 }
             }
         }
     }
 }
 static function bestAnswerNotification(CMA_Thread $thread)
 {
     global $wpdb;
     $answer = $thread->getBestAnswer();
     $receivers = array();
     $receiversOption = CMA_Settings::getOption(CMA_Settings::OPTION_NOTIF_BEST_ANSWER_RECEIVERS);
     if (in_array(CMA_Settings::NOTIF_QUESTION_AUTHOR, $receiversOption)) {
         $receivers[] = $thread->getAuthorEmail();
     }
     if (in_array(CMA_Settings::NOTIF_ANSWER_AUTHOR, $receiversOption)) {
         $receivers[] = $answer->getAuthorEmail();
     }
     if (in_array(CMA_Settings::NOTIF_FOLLOWERS, $receiversOption)) {
         $receivers = array_merge($receivers, $thread->getFollowersEmails());
     }
     if (in_array(CMA_Settings::NOTIF_CONTRIBUTORS, $receiversOption)) {
         $receivers = array_merge($receivers, $thread->getContributorsEmails());
         $receivers[] = $thread->getAuthorEmail();
     }
     $receivers = array_filter(array_unique($receivers));
     if (!empty($receivers)) {
         $message = CMA_Settings::getOption(CMA_Settings::OPTION_NOTIF_BEST_ANSWER_CONTENT);
         $title = CMA_Settings::getOption(CMA_Settings::OPTION_NOTIF_BEST_ANSWER_TITLE);
         $replace = array('[blogname]' => get_bloginfo('name'), '[question_title]' => strip_tags($thread->getTitle()), '[question_body]' => strip_tags($thread->getContent()), '[question_author]' => strip_tags($thread->getAuthorName()), '[answer]' => strip_tags($answer->getContent()), '[answer_link]' => $answer->getPermalink(), '[answer_author]' => strip_tags($answer->getAuthorName()));
         CMA_Email::send($receivers, $title, $message, $replace);
     }
 }