このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/Video/Prayer.php

132 行
4.9 KiB
PHP
Raw 通常表示 履歴

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
2020-12-12 19:51:17 +09:00
$res->publish_date = date('Y月m月d日', $res->publish_date);
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());
2021-01-02 02:49:09 +09:00
if (isset($res->ytcomment['nextPage']) && $res->ytcomment['nextPage'] != '') {
while ($res->ytcomment['nextPage'] != '') {
$res->ytcomment = $this->checkYouTubeCome($res->ytcomment, $ytslug[1], $res->ytcomment['nextPage']);
}
}
2020-10-06 11:22:46 +09:00
$res->nicocomment = array();
$res->bccomment = array();
2020-11-02 15:15:05 +09:00
$res->lbcomment = array();
2020-10-06 11:22:46 +09:00
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;
2020-10-06 11:22:46 +09:00
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='') {
2020-10-06 11:22:46 +09:00
$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;
2020-10-06 11:22:46 +09:00
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();
2020-10-06 11:22:46 +09:00
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('<br />'));
$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('<br />'));
}
}
2020-10-06 11:22:46 +09:00
$come['come'][] = $g->comment;
2020-10-06 11:22:46 +09:00
}
$come['total'] = $get->pageInfo->totalResults;
$come['prevPage'] = (isset($get->prevPageToken) ? $get->prevPageToken : '');
$come['nextPage'] = (isset($get->nextPageToken) ? $get->nextPageToken : '');
2020-10-06 11:22:46 +09:00
return $come;
}
}