/**
  * @param PostWillBeSaved $event
  */
 public function unapproveNewPosts(PostWillBeSaved $event)
 {
     $post = $event->post;
     if (!$post->exists) {
         $ability = $post->discussion->number_index == 0 ? 'startWithoutApproval' : 'replyWithoutApproval';
         if ($event->actor->can($ability, $post->discussion)) {
             if ($post->is_approved === null) {
                 $post->is_approved = true;
             }
             return;
         }
         $post->is_approved = false;
         $post->afterSave(function ($post) {
             if ($post->number == 1) {
                 $post->discussion->is_approved = false;
                 $post->discussion->save();
             }
             $flag = new Flag();
             $flag->post_id = $post->id;
             $flag->type = 'approval';
             $flag->time = time();
             $flag->save();
         });
     }
 }
示例#2
0
 /**
  * @param PostWillBeSaved $event
  */
 public function validatePost(PostWillBeSaved $event)
 {
     $post = $event->post;
     if ($post->exists || $post->user->groups()->count()) {
         return;
     }
     $isSpam = $this->getAkismet()->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment');
     if ($isSpam) {
         $post->is_approved = false;
         $post->is_spam = true;
         $post->afterSave(function ($post) {
             $flag = new Flag();
             $flag->post_id = $post->id;
             $flag->type = 'akismet';
             $flag->time = time();
             $flag->save();
         });
     }
 }