Пример #1
0
 protected function createFakeComment(Content $content)
 {
     $comment = Comment::create(['content_id' => $content->getKey(), 'created_at' => $this->faker->dateTimeThisDecade, 'text' => $this->faker->text(512), 'user_id' => $this->getRandomUser()->getKey()]);
     $repliesNumber = $this->faker->numberBetween(0, 3);
     for ($i = 0; $i < $repliesNumber; $i++) {
         $this->createFakeCommentReply($comment);
     }
 }
Пример #2
0
 /**
  * @param Content $content
  *
  * @return \Illuminate\View\View
  */
 public function chooseThumbnail($content)
 {
     if (!$content->canEdit(user())) {
         return redirect()->route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.');
     }
     try {
         $thumbnails = \OEmbed::getThumbnails($content->url);
     } catch (\Exception $e) {
         $thumbnails = [];
     }
     $thumbnails[] = 'http://img.bitpixels.com/getthumbnail?code=74491&size=200&url=' . urlencode($content->url);
     session(compact('thumbnails'));
     return view('content.thumbnails', compact('content', 'thumbnails'));
 }
Пример #3
0
 /**
  * @param Content $content
  *
  * @return \Illuminate\View\View
  */
 public function chooseThumbnail($content)
 {
     if (!$content->canEdit(Auth::user())) {
         return Redirect::route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.');
     }
     $thumbnails = [];
     try {
         $summon = new Summon($content->getURL());
         $thumbnails = $summon->fetch();
     } catch (\Exception $e) {
     }
     $websiteThumbnail = 'http://img.bitpixels.com/getthumbnail?code=74491&size=100&url=' . urlencode($content->url);
     $thumbnails['thumbnails'][] = $websiteThumbnail;
     Session::put('thumbnails', $thumbnails['thumbnails']);
     return view('content.thumbnails', compact('content', 'thumbnails'));
 }
Пример #4
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]);
 }
Пример #5
0
 /**
  * @param Content $content
  *
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function editContent($content)
 {
     if (!$content->canEdit(user())) {
         return Redirect::route('content_comments', $content->getKey())->with('danger_msg', 'Minął czas dozwolony na edycję treści.');
     }
     $rules = ['title' => 'required|min:1|max:128|not_in:edit,thumbnail', 'description' => 'max:255'];
     if ($content->text) {
         $rules['text'] = 'required|min:1|max:50000';
     } else {
         $rules['url'] = 'required|url_custom|max:2048';
     }
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::action('ContentController@showEditForm', $content->getKey())->withInput()->withErrors($validator);
     }
     $data = request()->only(['title', 'description', 'nsfw', 'eng']);
     $content->fill($data);
     if ($content->text) {
         $content->text = request('text');
     } else {
         $content->url = request('url');
     }
     $content->save();
     return Redirect::route('content_comments', $content);
 }