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

135 行
4.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\SiteController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Log;
class VideoController extends Controller {
private $objAuth;
private $objUser;
private $menu;
private $cook;
private $id;
private $user;
public function __construct() {
$this->objAuth = new AuthController();
$this->objUser = new UserController();
$this->menu = getPagesInMenu();
$this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
$this->id = $this->objAuth->checkLegit($this->cook);
$this->user = $this->objUser->getLoggedUser($this->id, $this->cook);
}
public function index () {
$res = DB::table('vid_game')->get();
foreach ($res as $r) {
$p = DB::table('vid_platform')->where('id', $r->platform_id)->first();
$r->name = $r->name.'('.$p->name.')';
}
return view('pages.site.video.game', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
}
public function table ($slug) {
$slg = DB::table('vid_game')->select('id', 'name')->where('slug', $slug)->first();
$res = DB::table('vid_video')->where('game_id', $slg->id)->orderBy('id', 'desc')->get();
foreach ($res as $r) {
$r->gametitle = explode('】', $r->title);
$r->title = $r->gametitle[1];
$r->gametitle = $r->gametitle[0];
$r->gametitle = str_replace('【'.$slg->name, '', $r->gametitle);
if ($r->gametitle == '') $r->gametitle = '初代';
}
return view('pages.site.video.videotable', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
}
public function prayer ($vid) {
$res = DB::table('vid_video')->where('vid', $vid)->first();
$game = DB::table('vid_game')->where('id', $res->game_id)->first();
$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 = $this->getYouTubeCome($ytslug[1]);
$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;
}
}