Beispiel #1
0
 /**
  * Notify bucket owners and followers of a new comment
  * 
  * @return	void
  */
 public static function notify_new_bucket_comment($comment, $bucket)
 {
     $html = View::factory('emails/html/comment');
     $text = View::factory('emails/text/comment');
     $html->is_drop = $text->is_drop = FALSE;
     $html->from_name = $text->from_name = $comment->user->name;
     $html->avatar = Swiftriver_Users::gravatar($comment->user->email, 80);
     $html->from_link = URL::site($comment->user->account->account_path, TRUE);
     $html->asset = $text->asset = 'bucket';
     $html->asset_name = $text->asset_name = $bucket->bucket_name;
     $html->asset_link = $text->asset_link = URL::site($bucket->get_base_url(), TRUE);
     $html->link = $text->link = URL::site($bucket->get_base_url() . '/discussion#comment-' . $comment->id, TRUE);
     $text->comment = $comment->comment_content;
     $html->comment = Markdown::instance()->transform($comment->comment_content);
     $subject = __(':from commented on the ":name" bucket.', array(":from" => $comment->user->name, ":name" => $bucket->bucket_name));
     // Add owner of the bucket first
     $emails = array($bucket->user->email);
     // Then collaborators
     foreach ($bucket->get_collaborators(TRUE) as $collaborator) {
         $emails[] = $collaborator['email'];
     }
     // Then followers
     foreach ($bucket->subscriptions->find_all() as $follower) {
         $emails[] = $follower->email;
     }
     $text_body = $text->render();
     $html_body = $html->render();
     $site_email = Swiftriver_Mail::get_default_address();
     $from = '"' . $comment->user->name . '" <notifications@' . Swiftriver_Mail::get_email_domain() . '>';
     $token_data = array('bucket_id' => $comment->bucket_id);
     $token = Model_Auth_Token::create_token('bucket-comment', $token_data);
     $reply_to = 'bucket-comment-' . $token->token . '@' . Swiftriver_Mail::get_comments_email_domain();
     foreach ($emails as $email) {
         if ($email != $comment->user->email) {
             Swiftriver_Mail::send($email, $subject, $text_body, $html_body, $from, array('Reply-To' => $reply_to));
         }
     }
 }