2020-10-06 11:22:46 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Video;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
// use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class Prayer {
|
|
|
|
private $menu;
|
|
|
|
private $cook;
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function __construct ($m, $c, $u) {
|
|
|
|
$this->menu = $m;
|
|
|
|
$this->cook = $c;
|
|
|
|
$this->user = $u;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index ($vid) {
|
|
|
|
$res = DB::table('vid_video')->where('vid', $vid)->first();
|
2020-10-08 11:03:51 +09:00
|
|
|
if (!$res) return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]);
|
2020-10-06 11:22:46 +09:00
|
|
|
$game = DB::table('vid_game')->where('id', $res->game_id)->first();
|
2020-10-08 11:03:51 +09:00
|
|
|
if (!$game) return view('pages.site.notfound', ['menu' => $this->menu, 'user' => $this->user]);
|
2020-10-06 11:22:46 +09:00
|
|
|
|
|
|
|
$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);
|
2020-10-08 10:15:36 +09:00
|
|
|
$res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1]) : array());
|
2020-10-06 11:22:46 +09:00
|
|
|
$res->nicocomment = array();
|
|
|
|
$res->bccomment = 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;
|
|
|
|
}
|
|
|
|
}
|