public function getThumbsDown($id) { try { $this->googleAnalytics('/comments/thumbs-down/' . $id); $valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 2)->where('object_id', '=', $id)->first(); if ($valid_ip != null) { throw new Exception("Error valid IP", 1); } $comment = Comment::findOrFail($id); $comment->thumbs_down++; $comment->save(); $thumb = new Thumb(); $thumb->ip = Puskice::getIP(); $thumb->object_id = $comment->id; $thumb->object_type = 2; $thumb->save(); $thumbs = array(); if (Cookie::get('ps_thumbs')) { $cookie = Cookie::get('ps_thumbs'); $thumbs = unserialize($cookie); if (isset($thumbs['comments'][$comment->id])) { return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили овај коментар"))); } } $thumbs['comments'][$comment->id] = 'down'; Cookie::queue('ps_thumbs', serialize($thumbs), 2628000); return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $comment->thumbs_up, 'thumbsDown' => $comment->thumbs_down)); } catch (Exception $e) { return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили овај коментар"))); } }
public function destroy($id) { $comment = Comment::findOrFail($id); $this->authorOrAdminPermissioinRequire($comment->user_id); Comment::destroy($id); Flash::success(lang('Operation succeeded.')); return Redirect::route('posts.show', $comment->post_id); }
/** * Update the specified comment in storage. * * @param int $id * @return Response */ public function update($id) { $comment = Comment::findOrFail($id); $validator = Validator::make($data = Input::all(), Comment::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $comment->update($data); return Redirect::route('comments.index'); }
public function applyVote($user, $type, $type_id, $updown) { //deal with item table $item = ""; switch ($type) { case Constant::POST_TYPE: $item = Post::findOrFail($type_id); break; case Constant::COMMENT_TYPE: $item = Comment::findOrFail($type_id); Cache::forget(Constant::COMMENT_CACHE_NEWLIST_NAME . $item->post_id); break; case Constant::SECTION_TYPE: $item = Section::findOrFail($type_id); break; default: throw new UnexpectedValueException("type: {$type} not enumerated"); } //increment our total vote counter $user->increment('votes'); //decrement one point for voting $user->decrement('points'); //double decrement for self upvote if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) { if ($item->user_id == Auth::user()->id && $updown == Constant::VOTE_UP) { $user->decrement('points'); } } //upvote/downvote the item itself if ($updown == Constant::VOTE_UP) { $item->increment('upvotes'); } else { if ($updown == Constant::VOTE_DOWN) { $item->increment('downvotes'); } } //upvote/downvote user who posted (ignore for sections) if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) { $rec_user = User::findOrFail($item->user_id); if ($updown == Constant::VOTE_UP) { $rec_user->increment('points'); } else { if ($updown == Constant::VOTE_DOWN) { $rec_user->decrement('points'); } } } //deal with votes table $vote = new Vote(array('type' => $type, 'user_id' => Auth::user()->id, 'item_id' => $type_id, 'updown' => $updown)); $vote->save(); }
public function delete_comment($article_id, $comment_id) { $commentReference = Comment::findOrFail($comment_id); $commentsAuthor = $commentReference->user()->first(); $commentsAuthor = $commentsAuthor; if (Auth::check() && Auth::user()->username == $commentsAuthor->username || Auth::user()->isAdmin()) { Comment::destroy($comment_id); return Redirect::to(URL::previous()); } else { return Redirect::route('login'); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function getDelete($id) { if (Session::get('user_level') < Config::get('cms.deleteComments')) { return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning'); } try { $comment = Comment::findOrFail($id); $comment->delete(); return Redirect::to(_l(URL::action('CommentController@getIndex')))->with('message', Lang::get('admin.commentDeleted'))->with('notif', 'success'); } catch (Exception $e) { return Redirect::to(_l(URL::action('CommentController@getIndex')))->with('message', Lang::get('admin.noSuchComment'))->with('notif', 'danger'); } }
/** * Displays the default view page * * @access public * @param string $urlkey * @param string $hash * @param string $action * @param string $extra * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect|null */ public function getPaste($urlkey, $hash = '', $action = '', $extra = '') { $site = Site::config('general'); $paste = Paste::where('urlkey', $urlkey)->first(); // Paste was not found if (is_null($paste)) { App::abort(404); // Not found } // Check if the logged in user is the owner of the paste $owner = Auth::access($paste->author_id); // We do not make password prompt mandatory for owners if (!$owner) { // Require hash to be passed for private pastes if ($paste->private and $paste->hash != $hash) { App::abort(401); // Unauthorized } // Check if paste is password protected and user hasn't entered // the password yet if ($paste->password and !Session::has('paste.password' . $paste->id)) { return View::make('site/password', array()); } } // Increment the hit counter if (!Session::has('paste.viewed' . $paste->id)) { $paste->hits++; $paste->save(); Session::put('paste.viewed' . $paste->id, TRUE); } // Let's do some action! switch ($action) { case 'delete': if (empty($extra)) { // Delete the paste if the user has access if ($site->allowPasteDel and $owner) { Revision::where('urlkey', $paste->urlkey)->delete(); $paste->comments()->delete(); $attachment = storage_path() . "/uploads/{$paste->urlkey}"; if ($paste->attachment and File::exists($attachment)) { File::delete($attachment); } $paste->delete(); Session::flash('messages.success', Lang::get('global.paste_deleted')); return Redirect::to('/'); } else { App::abort(401); // Unauthorized } } else { if (is_numeric($extra)) { $comment = Comment::findOrFail($extra); // Delete the comment if the user has access if ($owner or Auth::user()->username == $comment->author) { $comment->delete(); } else { App::abort(401); // Unauthorized } } } return Redirect::to(URL::previous()); case 'raw': $response = Response::make($paste->data); $response->header('Content-Type', 'text/plain'); return $response; case 'toggle': if ($owner) { Revision::where('urlkey', $paste->urlkey)->delete(); $paste->private = $paste->private ? 0 : 1; $paste->password = ''; $paste->save(); } return Redirect::to(URL::previous()); case 'flag': if ($site->flagPaste == 'all' or $site->flagPaste == 'user' and Auth::roles()->user) { $paste->flagged = 1; $paste->save(); Cache::forget('global.flags'); Session::flash('messages.success', Lang::get('global.paste_flagged')); } else { App::abort(401); // Unauthorized } return Redirect::to(URL::previous()); case 'unflag': if (Auth::roles()->admin) { $paste->flagged = 0; $paste->save(); Cache::forget('global.flags'); Session::flash('messages.success', Lang::get('global.paste_unflagged')); } else { App::abort(401); // Unauthorized } return Redirect::to(URL::previous()); } // Build the sharing subject for the paste $subject = sprintf(Lang::get('mail.share_subject'), $site->title, URL::current()); // Build data for show paste page $data = array('paste' => $paste, 'revisions' => $paste->revisions, 'comments' => $paste->comments()->paginate($site->perPage), 'share' => 'mailto:?subject=' . urlencode($subject), 'attachment' => sprintf(Lang::get('show.download_attachment'), Lang::get('show.unknown'))); // If paste has an attachment, get the file type if ($paste->attachment) { $pathToFile = storage_path() . "/uploads/{$paste->urlkey}"; if (File::exists($pathToFile)) { $file = new Symfony\Component\HttpFoundation\File\File($pathToFile); $data['attachment'] = sprintf(Lang::get('show.download_attachment'), $file->getMimeType()); } } // Display the show paste view return View::make('site/show', $data); }
public function vote($id) { $Comment = Comment::findOrFail($id); // +1 or -1 $voteValue = Input::get('vote'); $vote = Vote::firstOrNew(['user_id' => Auth::id(), 'voteable_id' => $id, 'voteable_type' => 'Comment']); $vote->vote = $voteValue; $vote->save(); return Redirect::back(); }