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()); if ($res->ytcomment['nextPage'] != '') { while ($res->ytcomment['nextPage'] != '') { $res->ytcomment = $this->checkYouTubeCome($res->ytcomment, $ytslug[1], $res->ytcomment['nextPage']); } } $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['total'] = count($comments); $res->comments['come'] = $comments; return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]); } function checkYouTubeCome ($res, $slug, $next='') { $come = $this->getYouTubeCome($slug, $next); foreach ($come['come'] as $com) { $res['come'][] = $com; } $res['total'] += $come['total']; $res['nextPage'] = $come['nextPage']; return $res; } function getYouTubeCome ($slug, $page='') { $ch = curl_init(); $url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=published&videoId='.$slug.'&key='.env('YOUTUBE_API').'&pageToken='.$page;//.'&order=date&pageToken='.$page; 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(); $come['come'] = 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 = strip_tags($g->snippet->topLevelComment->snippet->textDisplay, array('
')); $g->comment->replyCount = (isset($g->snippet->totalReplyCount) ? $g->snippet->totalReplyCount : 0); if (isset($g->replies)) { $g->comment->replies = array(); foreach ($g->replies->comments as $k => $c) { $g->comment->replies[$k]['id'] = $c->id; $g->comment->replies[$k]['name'] = $c->snippet->authorDisplayName; $g->comment->replies[$k]['channel'] = $c->snippet->authorChannelUrl; $g->comment->replies[$k]['icon'] = $c->snippet->authorProfileImageUrl; $g->comment->replies[$k]['created'] = date('Y年m月d日 H:i:s', strtotime($c->snippet->publishedAt)); $g->comment->replies[$k]['message'] = strip_tags($c->snippet->textDisplay, array('
')); } } $come['come'][] = $g->comment; } $come['total'] = $get->pageInfo->totalResults; $come['prevPage'] = (isset($get->prevPageToken) ? $get->prevPageToken : ''); $come['nextPage'] = (isset($get->nextPageToken) ? $get->nextPageToken : ''); return $come; } }