menu = $m; $this->cook = $c; $this->user = $u; } public function index ($vid) { $res = DB::table('vid_video')->where('vid', $vid)->first(); if (!$res) return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]); $game = DB::table('vid_game')->where('id', $res->game_id)->first(); if (!$game) return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]); $res->publish_date = date('Y月m月d日', $res->publish_date); $res->gametitle = explode('】', $res->title); $res->title = $res->gametitle[1]; $res->gametitle = $res->gametitle[0]; $res->gametitle = str_replace('【'.$game->name, '', $res->gametitle); $res->mgametitle = $game->name; $slugger = $res->vid; $res->slug = $game->slug; $res->pageslug = $vid; if ($res->gametitle == '') $res->gametitle = '初代'; $comments = DB::table('blg_comments')->where('video_id', $vid)->orderBy('id', 'asc')->get()->toArray(); $ytslug = explode('?v=', $res->youtube); $res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1]) : array()); $res->nicocomment = array(); $res->bccomment = array(); $res->lbcomment = array(); foreach ($comments as $k => $c) { if (count(userDetail($c->user_id)) > 0) { $det = userDetail($c->user_id); $c->user_id = $det['user_id']; $c->showname = $det['showname']; $c->showcol = $det['showcol']; $c->avatar = $det['avatar']; } if ($c->isShadow == 0) { if (getIp() != $c->ipaddress) unset($comments[$k]); } else { unset($c->email); unset($c->ipaddress); unset($c->isShadow); $c->created = date('Y年m月d日 H:i:s', $c->created); } } $res->user = userDetail(null, $this->cook); $res->comments = $comments; return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]); } function getYouTubeCome ($slug) { $ch = curl_init(); $url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=published&videoId='.$slug.'&key='.env('YOUTUBE_API'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $get = curl_exec($ch); curl_close($ch); $come = array(); $get = json_decode($get, false); if (isset($get->error)) return array(); foreach ($get->items as $g) { $g->comment = new \stdClass(); $g->comment->id = $g->id; $g->comment->name = $g->snippet->topLevelComment->snippet->authorDisplayName; $g->comment->channel = $g->snippet->topLevelComment->snippet->authorChannelUrl; $g->comment->icon = $g->snippet->topLevelComment->snippet->authorProfileImageUrl; $g->comment->created = date('Y年m月d日 H:i:s', strtotime($g->snippet->topLevelComment->snippet->publishedAt)); $g->comment->message = $g->snippet->topLevelComment->snippet->textDisplay; $come[] = $g->comment; } return $come; } }