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

252 行
11 KiB
PHP
Raw 通常表示 履歴

2020-10-06 11:22:46 +09:00
<?php
namespace App\Http\Controllers\Video;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Engine;
2020-10-06 11:22:46 +09:00
// use Illuminate\Support\Facades\Log;
class Prayer extends Engine {
private $engine;
2020-10-06 11:22:46 +09:00
public function __construct () {
$this->engine = new Engine;
2020-10-06 11:22:46 +09:00
}
public function index ($vid) {
$res = DB::table('vid_video')->where('vid', $vid)->first();
if (!$res) return view('pages.site.notfound');
2020-10-06 11:22:46 +09:00
$game = DB::table('vid_game')->where('id', $res->game_id)->first();
if (!$game) return view('pages.site.notfound');
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);
$res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1], $slugger) : 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']);
}
}
2021-06-28 16:03:50 +09:00
$res->kvcomment = array();
$kvslug = explode('/', $res->kerotube);
2021-11-06 20:00:41 +09:00
if (isset($kvslug[5]) && $kvslug[3] == 'videos') {
DB::table('vid_video')->where('vid', $res->vid)->update(['kerotube' => 'https://video.076.ne.jp/w/'.$kvslug[5]]);
$kvslug = explode('/', $res->kerotube);
}
if (isset($kvslug[4])) {
$res->kvcomment = $this->getPeerCome($kvslug[4], '');
2021-06-28 16:03:50 +09:00
}
2021-01-10 14:59:51 +09:00
if ($res->ytcomment) $res->ytcomment = $this->backupYTComment($slugger, $res->ytcomment);
2020-11-02 15:15:05 +09:00
$res->lbcomment = array();
2021-06-29 09:31:36 +09:00
if ($res->kvcomment) $res->kvcomment = $this->backupPeerComment($slugger, $res->kvcomment);
2020-10-06 11:22:46 +09:00
foreach ($comments as $k => $c) {
2021-01-03 21:49:12 +09:00
$c->replyCount = 0;
$c->isvideo = 't';
2021-06-28 16:03:50 +09:00
$c->src = 'TS';
2021-01-03 21:49:12 +09:00
if (!is_null($c->user_id) && !empty(userDetail($c->user_id))) {
2020-10-06 11:22:46 +09:00
$det = userDetail($c->user_id);
$c->user_id = $det['user_id'];
$c->showname = $det['showname'];
$c->showcol = $det['showcol'];
$c->avatar = $det['avatar'];
}
2021-11-06 20:00:41 +09:00
unset($c->email);
2021-11-06 20:06:52 +09:00
unset($c->ipaddress);
unset($c->isShadow);
2021-11-06 20:00:41 +09:00
$c->created = date('Y年m月d日 H:i:s', $c->created);
2020-10-06 11:22:46 +09:00
}
$res->user = userDetail(null, (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : ''));
$res->comments['total'] = count($comments);
$res->comments['come'] = $comments;
2021-01-03 22:51:58 +09:00
$res->comments['total'] += (isset($res->ytcomment['total']) ? $res->ytcomment['total'] : 0);
2021-06-28 16:03:50 +09:00
$res->comments['total'] += (isset($res->kvcomment['total']) ? $res->kvcomment['total'] : 0);
2021-01-03 22:51:58 +09:00
if (isset($res->ytcomment['come'])) $res->comments['come'] = array_merge($res->comments['come'], $res->ytcomment['come']);
2021-06-28 16:03:50 +09:00
if (isset($res->kvcomment['come'])) $res->comments['come'] = array_merge($res->comments['come'], $res->kvcomment['come']);
2020-10-06 11:22:46 +09:00
2021-02-06 13:19:25 +09:00
DB::table('vid_video')->where('vid', $vid)->update(['view' => $res->view+1]);
return view('pages.site.video.prayer', ['res' => $res, 'user' => $this->user]);
2020-10-06 11:22:46 +09:00
}
2021-06-29 09:31:36 +09:00
function getPeerCome ($slug, $tslug) {
2021-06-28 16:03:50 +09:00
$come = [];
$ch = curl_init();
2021-06-29 09:31:36 +09:00
curl_setopt($ch, CURLOPT_URL, env('PEER_URI').'/api/v1/videos/'.$slug.'/comment-threads');
2021-06-28 16:03:50 +09:00
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$get = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!$get) return $err;
$get = json_decode($get);
2021-12-02 02:08:28 +09:00
if (isset($get->status) && $get->status == 404) return [];
2021-06-28 16:03:50 +09:00
$come = array();
$come['come'] = array();
if (isset($get->error) || !$get) {
if ($tslug != '') {
if (!$get = DB::table('vid_kerocomment')->where('vid', $tslug)->first()) return array();
$come = unserialize($get->come);
return $come;
}
}
if (isset($get->data)) {
foreach ($get->data as $g) {
$g->comments = new \stdClass();
$g->comments->id = $g->id;
$g->comments->name = $g->account->displayName;
$g->comments->channel = $g->account->url;
2021-12-02 02:08:28 +09:00
$g->comments->icon = !is_null($g->account->avatar) ? env('PEER_URI').$g->account->avatar->path : '/img/noicon.jpg';
2021-06-28 16:03:50 +09:00
$g->comments->message = strip_tags($g->text, array('<br />'));
$g->comments->createdTS = strtotime($g->createdAt);
$g->comments->created = date('Y年m月d日 H:i:s', strtotime($g->createdAt));
$g->comments->replyCount = (isset($g->totalReplies) ? $g->totalReplies : 0);
$g->comments->isvideo = 'n';
$g->comments->src = '076';
$come['come'][] = $g->comments;
}
}
$come['total'] = $get->totalNotDeletedComments;
return $come;
}
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, $tslug, $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);
$come['come'] = array();
2020-10-06 11:22:46 +09:00
2021-01-10 15:29:19 +09:00
if (isset($get->error) || !$get) {
if ($tslug != '') {
if (!$get = DB::table('vid_ytcomment')->where('vid', $tslug)->first()) return array();
$come = unserialize($get->come);
return $come;
}
}
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->createdTS = strtotime($g->snippet->topLevelComment->snippet->publishedAt);
2020-10-06 11:22:46 +09:00
$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);
2021-01-03 21:49:12 +09:00
$g->comment->isvideo = 'n';
2021-06-28 16:03:50 +09:00
$g->comment->src = 'YT';
if (isset($g->replies)) {
$g->comment->replies = array();
foreach ($g->replies->comments as $k => $c) {
$g->comment->replies[$k]['id'] = (isset($c->id) ? $c->id : $c['id']);
$g->comment->replies[$k]['name'] = (isset($c->snippet->authorDisplayName) ? $c->snippet->authorDisplayName : $c['snippet']['authorDisplayName']);
$g->comment->replies[$k]['channel'] = (isset($c->snippet->authorChannelUrl) ? $c->snippet->authorChannelUrl : $c['snippet']['authorChannelUrl']);
$g->comment->replies[$k]['icon'] = (isset($c->snippet->authorProfileImageUrl) ? $c->snippet->authorProfileImageUrl : $c['snippet']['authorProfileImageUrl']);
$g->comment->replies[$k]['createdTS'] = strtotime((isset($c->snippet->publishedAt) ? $c->snippet->publishedAt : $c['snippet']['publishedAt']));
$g->comment->replies[$k]['created'] = date('Y年m月d日 H:i:s', strtotime((isset($c->snippet->publishedAt) ? $c->snippet->publishedAt : $c['snippet']['publishedAt'])));
$g->comment->replies[$k]['message'] = strip_tags((isset($c->snippet->textDisplay) ? $c->snippet->textDisplay : $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;
}
function backupYTComment ($slug, $com) {
foreach ($com['come'] as $c) {
$icon = substr($c->icon, 0, strpos($c->icon, "="));
$icon = str_replace('https://yt3.ggpht.com/', '', $icon).'.jpg';
$icon = str_replace('ytc/', '', $icon).'.jpg';
if ($icon != '.jpg') {
$isicon = array_diff(scandir(dirname(__DIR__, 4).'/storage/app/public/yt_icon'), array('..', '.'));
if (!in_array($icon, $isicon)) passthru('wget -O '.dirname(__DIR__, 4).'/storage/app/public/yt_icon/'.$icon.' '.$c->icon);
$c->icon = '/storage/yt_icon/'.$icon;
}
if (isset($c->replies)) {
foreach ($c->replies as $i => $r) {
$icon = substr($r['icon'], 0, strpos($r['icon'], "="));
$icon = str_replace('https://yt3.ggpht.com/', '', $icon).'.jpg';
$icon = str_replace('ytc/', '', $icon).'.jpg';
if ($icon != '.jpg') {
$isicon = array_diff(scandir(dirname(__DIR__, 4).'/storage/app/public/yt_icon'), array('..', '.'));
if (!in_array($icon, $isicon)) passthru('wget -O '.dirname(__DIR__, 4).'/storage/app/public/yt_icon/'.$icon.' '.$r['icon']);
$c->replies[$i]['icon'] = '/storage/yt_icon/'.$icon;
}
}
}
}
if ($chk = DB::table('vid_ytcomment')->where('vid', $slug)->first()) DB::table('vid_ytcomment')->where('vid', $slug)->update(['come' => serialize($com)]);
else DB::table('vid_ytcomment')->insert(['vid' => $slug, 'come' => serialize($com)]);
return $com;
}
2021-06-28 16:03:50 +09:00
2021-06-29 09:31:36 +09:00
function backupPeerComment ($slug, $com) {
2021-06-28 16:03:50 +09:00
foreach ($com['come'] as $c) {
$icon = strstr($c->icon, 'avatars/');
$icon = str_replace('avatars/', '', $icon);
if ($icon != '.jpg') {
$isicon = array_diff(scandir(dirname(__DIR__, 4).'/storage/app/public/kero_icon'), array('..', '.'));
if (!in_array($icon, $isicon)) passthru('wget -O '.dirname(__DIR__, 4).'/storage/app/public/kero_icon/'.$icon.' '.$c->icon);
$c->icon = '/storage/kero_icon/'.$icon;
}
}
if ($chk = DB::table('vid_kerocomment')->where('vid', $slug)->first()) DB::table('vid_kerocomment')->where('vid', $slug)->update(['come' => serialize($com)]);
else DB::table('vid_kerocomment')->insert(['vid' => $slug, 'come' => serialize($com)]);
return $com;
}
}