コード例 #1
0
ファイル: Post.php プロジェクト: libre-net-society/onelon
 public static function createPost($user_fp, $input, $timestamp = false)
 {
     $timestamp = $timestamp ? $timestamp : date('Y-m-d H:i:s');
     if ($input['parent_id'] != 0) {
         $parent_post = Post::findOrFail($input['parent_id']);
         if ($parent_post->parent_id != 0) {
             App::abort(500, "Illegal post_id");
         }
         if (Ban::isBanned($parent_post->user_fp, $user_fp)) {
             App::abort(500, "You are banned");
         }
         if ($parent_post->group_name != "" && Group::where('group_name', $parent_post->group_name)->first()->is_private == 1) {
             if (!Gsub::membership($user_fp, $parent_post->group_name)) {
                 App::abort(500, 'Only members of group can leave comments.');
             }
         }
     } else {
         if ($input['group_name']) {
             $group = Group::where('group_name', $input['group_name'])->firstOrFail();
             if ($group->is_private == 1) {
                 if (!Gsub::membership($user_fp, $input['group_name'])) {
                     App::abort(500, 'Membership required to post.');
                 }
             }
         }
     }
     $message = rtrim($input['message']);
     $plaintext = BaseController::isSigned($message);
     $post = new Post();
     $post->parent_id = $input['parent_id'] ? $input['parent_id'] : 0;
     $post->user_fp = $user_fp;
     $post->timestamp = $timestamp;
     if ($input['source_link']) {
         $post->source_link = $input['source_link'];
     }
     if ($input['title']) {
         $post->title = $input['title'];
     }
     if ($plaintext) {
         $post->clear_message = self::convertEmoji($plaintext);
         $post->message = $message;
     } else {
         $post->clear_message = "";
         $post->message = self::convertEmoji($message);
     }
     if (!isset($parent_post)) {
         if ($input['chan']) {
             $post->chan = $input['chan'];
         }
         if ($input['group_name']) {
             $post->group_name = $input['group_name'];
         }
     }
     $post->save();
     if (isset($parent_post)) {
         $parent_post->replies += 1;
         $parent_post->save();
     }
     return $post;
 }