コード例 #1
0
ファイル: Post.php プロジェクト: RustyGamer/infinity-next
 /**
  * Returns the last post made by this user across the entire site.
  *
  * @static
  * @param  string  $ip
  * @return \App\Post
  */
 public static function getLastPostForIP($ip = null)
 {
     if (is_null($ip)) {
         $ip = new IP();
     }
     return Post::whereAuthorIP($ip)->orderBy('created_at', 'desc')->take(1)->get()->first();
 }
コード例 #2
0
 /**
  * 
  */
 public function getMod(Request $request, Board $board, Post $post)
 {
     if (!$post->exists) {
         abort(404);
     }
     // Take trailing arguments,
     // compare them against a list of real actions,
     // intersect the liss to find the true commands.
     $actions = ["delete", "ban", "all", "global"];
     $argList = func_get_args();
     $modActions = array_intersect($actions, array_splice($argList, 2));
     sort($modActions);
     $ban = in_array("ban", $modActions);
     $delete = in_array("delete", $modActions);
     $all = in_array("all", $modActions);
     $global = in_array("global", $modActions);
     if (!$ban && !$delete) {
         return abort(404);
     }
     if ($ban) {
         if ($global && !$this->user->canBanGlobally()) {
             return abort(403);
         } else {
             if (!$this->user->canBan($board)) {
                 return abort(403);
             }
         }
         return $this->view(static::VIEW_MOD, ["actions" => $modActions, "form" => "ban", "board" => $board, "post" => $post, "banMaxLength" => $this->option('banMaxLength')]);
     } else {
         if ($delete) {
             if ($global) {
                 if (!$this->user->canDeleteGlobally()) {
                     return abort(403);
                 }
                 $posts = Post::whereAuthorIP($post->author_ip)->with('reports')->get();
                 $this->log('log.post.delete.global', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "posts" => $posts->count()]);
                 Post::whereIn('post_id', $posts->pluck('post_id'))->delete();
                 foreach ($posts as $post) {
                     Event::fire(new PostWasModerated($post, $this->user));
                 }
             } else {
                 if (!$this->user->canDelete($post)) {
                     return abort(403);
                 }
                 if ($all) {
                     $posts = Post::whereAuthorIP($post->author_ip)->where('board_uri', $board->board_uri)->with('reports')->get();
                     $this->log('log.post.delete.local', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "posts" => $posts->count()]);
                     Post::whereIn('post_id', $posts->pluck('post_id'))->delete();
                     foreach ($posts as $post) {
                         Event::fire(new PostWasModerated($post, $this->user));
                     }
                 } else {
                     if (!$post->isAuthoredByClient()) {
                         if ($post->reply_to) {
                             $this->log('log.post.delete.reply', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "op_id" => $post->op->board_id]);
                         } else {
                             $this->log('log.post.delete.op', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "replies" => $post->replies()->count()]);
                         }
                     }
                     $post->delete();
                     Event::fire(new PostWasModerated($post, $this->user));
                 }
             }
             return back();
         }
     }
     return abort(403);
 }