Пример #1
0
 /**
  * @param Request $request
  *
  * @return mixed
  */
 public function addContent(Request $request)
 {
     $rules = ['title' => 'required|min:1|max:128|not_in:edit,thumbnail', 'description' => 'max:255', 'groupname' => 'required|exists:groups,urlname'];
     if (Input::get('type') == 'link') {
         $rules['url'] = 'required|url_custom|max:2048';
     } else {
         $rules['text'] = 'required|min:1|max:50000';
     }
     $this->validate($request, $rules);
     $group = Group::name(Input::get('groupname'))->firstOrFail();
     $group->checkAccess();
     if (Auth::user()->isBanned($group)) {
         return Redirect::action('ContentController@showAddForm')->withInput()->with('danger_msg', 'Zostałeś zbanowany w wybranej grupie');
     }
     if ($group->type == 'announcements' && !Auth::user()->isModerator($group)) {
         return Redirect::action('ContentController@showAddForm')->withInput()->with('danger_msg', 'Nie możesz dodawać treści do wybranej grupy');
     }
     $content = new Content(Input::only(['title', 'description', 'nsfw', 'eng']));
     if (Input::get('type') == 'link') {
         $content->url = Input::get('url');
     } else {
         $content->text = Input::get('text');
     }
     $content->user()->associate(Auth::user());
     $content->group()->associate($group);
     $content->save();
     if (Input::get('thumbnail') == 'on') {
         Queue::push('Strimoid\\Handlers\\DownloadThumbnail', ['id' => $content->getKey()]);
     }
     return Redirect::route('content_comments', $content);
 }
Пример #2
0
 /**
  * Add new content.
  *
  * @param Request $request
  *
  * @return mixed
  */
 public function store(Request $request)
 {
     $rules = ['title' => 'required|min:1|max:128|not_in:edit,thumbnail', 'description' => 'max:255', 'group' => 'required|exists:groups,urlname'];
     if (request('text')) {
         $rules['text'] = 'required|min:1|max:50000';
     } else {
         $rules['url'] = 'required|url_custom';
     }
     $this->validate($request, $rules);
     $group = Group::name(request('group'))->firstOrFail();
     $group->checkAccess();
     if (user()->isBanned($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik został zbanowany w wybranej grupie.'], 400);
     }
     if ($group->type == 'announcements' && !user()->isModerator($group)) {
         return response()->json(['status' => 'error', 'error' => 'Użytkownik nie może dodawać treści w tej grupie.'], 400);
     }
     $content = new Content($request->only(['title', 'description', 'nsfw', 'eng']));
     if (request('text')) {
         $content->text = request('text');
     } else {
         $content->url = request('url');
     }
     $content->user()->associate(user());
     $content->group()->associate($group);
     $content->save();
     // Download thumbnail in background to don't waste user time
     $thumbnail = $request->get('thumbnail');
     if ($thumbnail != 'false' && $thumbnail != 'off') {
         $content->thumbnail_loading = true;
         Queue::push('Strimoid\\Handlers\\DownloadThumbnail', ['id' => $content->getKey()]);
     }
     return response()->json(['status' => 'ok', '_id' => $content->getKey(), 'content' => $content]);
 }