/**
  * Creates a new post for a given user
  *
  * @param User $user
  * @param array $data
  * @return mixed
  * @throws DataSourceException
  */
 public function create(User $user, array $data)
 {
     $activeSlug = setting('branding.slug', false);
     $slug = $activeSlug ? str_slug($data['title']) : str_random(14);
     $data['media'] = isset($data['link']) ? $data['link'] : $data['media'];
     $data['slug'] = $user->id . '-' . mt_rand(10000, 99999) . '-' . $slug;
     if ($this->isVideo($data['media'])) {
         $data = $this->processPostWithVideo($data);
     } else {
         $data = $this->processPostWithImage($data);
     }
     $data['user_id'] = $user->id;
     $post = $this->post->create($data);
     if (!$post) {
         throw new DataSourceException();
     }
     $this->post->update($post, ['slug' => ($activeSlug ? $post->id . '-' : '') . $slug]);
     $this->processCategories($post, $data);
     event(new PostWasCreated($user, $post));
     return $post;
 }