ソースを参照

Merge branch 'dev-master' of git.076.ne.jp:TechnicalSuwako/076server

master
テクニカル諏訪子 1ヶ月前
コミット
2b5acff135
  1. 1
      app/Http/Controllers/Peertube/Common.php
  2. 103
      app/Http/Controllers/Peertube/Watch.php
  3. 47
      app/helpers.php
  4. 39
      resources/views/theme/techsuwa/component/peertube/w/info/comments.blade.php
  5. 2
      resources/views/theme/techsuwa/component/peertube/w/player.blade.php

1
app/Http/Controllers/Peertube/Common.php

@ -52,6 +52,7 @@ class Common extends Engine {
}
public function ptapi ($url, $param='', $method='get', $contenttype='json') {
set_time_limit(0);
$this->access_token = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : null;
$this->refresh_token = isset($_COOKIE['refresh_token']) ? $_COOKIE['refresh_token'] : null;
$header = ['Content-Type: application/'.$contenttype, 'Host: '.str_replace('https://', '', env('PEER_URI'))];

103
app/Http/Controllers/Peertube/Watch.php

@ -20,7 +20,7 @@ class Watch extends Common {
'userinfo' => $this->common->user,
];
$res['detail'] = $this->getDetail($id);
$res['comment'] = $this->getComment($id);
$res = $this->getComment($id, $res);
$tags = [];
if (!is_null($res['detail']->tags)) $tags = $res['detail']->tags;
@ -42,7 +42,104 @@ class Watch extends Common {
return $this->ptapi('/api/v1/search/videos?start=0&count=6&nsfw=both&'.$tag.'sort=-publishedAt&searchTarget=local');
}
function getComment ($id) {
return $this->ptapi('/api/v1/videos/'.$id.'/comment-threads');
function getComment ($id, $res) {
$get = null;
// PeerTube
$res['comment'] = $this->ptapi('/api/v1/videos/'.$id.'/comment-threads');
foreach ($res['comment']->data as $co) {
$co->src = 'PT';
}
// テク諏訪
if (
null !== ($get = DB::table('vid_video')->where('kerotube', env('PEER_URI').'/w/'.$res['detail']->uuid)->first()) ||
null !== ($get = DB::table('vid_video')->where('kerotube', env('PEER_URI').'/w/'.$res['detail']->shortUUID)->first())
) {
if (null !== ($ts = DB::table('blg_comments')->where('video_id', $get->vid)->orderBy('created', 'desc')->get()->toArray())) {
foreach ($ts as $t) {
if (!is_null($t->user_id)) {
if (null !== ($user = DB::table('users')->where('id', $t->user_id)->first())) {
$t->user_id = new \stdClass();
$t->user_id->id = $user->id;
$t->user_id->name = $user->username;
if (null !== ($user = DB::table('usr_profile')->where('user_id', $t->user_id->id)->first())) {
$t->user_id->avatar = $user->avatar;
$t->user_id->displayName = $user->display_name;
$t->user_id->gender = $user->gender;
$t->user_id->nameStyle = $user->name_style;
}
}
}
$obj = new \stdClass();
$acc = new \stdClass();
$ava = !is_null($t->user_id) && !is_null($t->user_id->avatar) ? new \stdClass() : null;
if (!is_null($ava)) $ava->path = env('APP_URL').'/'.(!is_null($t->user_id) && !is_null($t->user_id->avatar) ? $t->user_id->avatar : 'img/noicon.jpg');
$acc->url = !is_null($t->user_id) ? '/profile/'.$t->user_id->id : '';
$acc->name = !is_null($t->user_id) ? $t->user_id->name : (!is_null($t->name) ? $t->name : '名無しのテクニシャン');
$acc->host = 'technicalsuwako.jp';
$acc->displayName = !is_null($t->user_id) ? $t->user_id->displayName : '名無しのテクニシャン';
$acc->gender = !is_null($t->user_id) ? $t->user_id->gender : null;
$acc->user_id = $t->user_id;
$acc->avatar = $ava;
$acc->nameStyle = !is_null($t->user_id) ? $t->user_id->nameStyle : null;
$obj->id = $t->id;
$obj->threadId = $t->id;
$obj->isDeleted = false;
$obj->src = 'TS';
$obj->text = $t->message;
$obj->createdAt = date('Y-m-d H:i:s', $t->created);
$obj->updatedAt = date('Y-m-d H:i:s', $t->created);
$obj->account = $acc;
$res['comment']->data[] = $obj;
$res['comment']->total++;
$res['comment']->totalNotDeletedComments++;
}
}
}
if (!is_null($get)) {
// YouTube
if (null !== ($yt = DB::table('vid_ytcomment')->where('vid', $get->vid)->first())) {
$yt = unserialize($yt->come);
foreach ($yt['come'] as $t) {
$obj = new \stdClass();
$acc = new \stdClass();
$ava = !is_null($t->icon) ? new \stdClass() : null;
if (!is_null($ava)) $ava->path = env('APP_URL').(!is_null($t->icon) ? $t->icon : 'img/noicon.jpg');
$acc->url = str_replace('www.youtube.com', 'youtube.076.ne.jp', $t->channel);
$acc->name = $t->name;
$acc->host = 'youtube.076.ne.jp';
$acc->avatar = $ava;
$acc->displayName = $t->name;
$obj->id = $t->id;
$obj->threadId = $t->id;
$obj->isDeleted = false;
$obj->src = 'YT';
$obj->text = $t->message;
$obj->createdAt = date('Y-m-d H:i:s', $t->createdTS);
$obj->updatedAt = date('Y-m-d H:i:s', $t->createdTS);
$obj->account = $acc;
$res['comment']->data[] = $obj;
$res['comment']->total++;
$res['comment']->totalNotDeletedComments++;
}
}
// Odysee
// $odysee = $get->odysee;
// 作成日順番
usort($res['comment']->data, function ($a, $b) { return strtotime($b->createdAt) - strtotime($a->createdAt); });
}
return $res;
}
}

47
app/helpers.php

@ -41,12 +41,57 @@ function checkLegit ($t) {
return $check->id;
}
function ptComeSrc ($v) {
$res = new \stdClass();
$res->bg = '#';
$res->fg = '#fcfcfc';
$res->tx = '不明';
switch ($v) {
case 'PT':
$res->bg .= 'ffad5c';
$res->tx = 'PeerTube';
break;
case 'TS':
$res->bg .= 'cb81ea';
$res->tx = 'テク諏訪';
break;
case 'YT':
$res->bg .= 'f50057';
$res->tx = 'YouTube';
break;
case 'OD':
$res->bg .= '33b58f';
$res->tx = 'LBRY';
break;
default:
$res->bg = 'transparent';
break;
}
return $res;
}
function ptFullHandle ($v) {
return $v->name.($v->host != str_replace('https://', '', env('PEER_URI')) ? '@'.$v->host : '');
}
function ptAvatar ($v) {
return isset($v->avatar) && !is_null($v->avatar) ? env('PEER_URI').$v->avatar->path : '/img/noicon.jpg';
$placeholder = '/img/noicon.jpg';
$res = '';
if (isset($v->avatar)) {
if (is_null($v->avatar)) return $placeholder;
$ava = $v->avatar->path;
$ava = str_replace(env('APP_URL'), '', $ava);
$res = str_starts_with(env('APP_URL'), $ava) ? env('PEER_URI') : '';
if ($ava == '/') return '/img/noicon.jpg';
else if (str_starts_with($ava, '/lazy-static')) $res = env('PEER_URI');
return $res.$ava;
}
return '/img/noicon.jpg';
}
function userDetail ($id, $kero=null) {

39
resources/views/theme/techsuwa/component/peertube/w/info/comments.blade.php

@ -52,13 +52,34 @@
</div>
<div class="right mb-3">
<div class="comment">
<div class="highlighted-comment ng-star-inserted">注目のコメント</div>
@php
$comsrc = ptComeSrc($v->src);
@endphp
<div class="highlighted-comment ng-star-inserted" style="background-color: {{ $comsrc->bg }}; color: {{ $comsrc->fg }};">{{ $comsrc->tx }}</div>
<div class="comment-account-date ng-star-inserted">
<div class="comment-account">
<a href="/peertube/a/{{ ptFullHandle($v->account) }}">
<span class="comment-account-name"> {{ $v->account->displayName }} </span>
<span class="comment-account-fid ml-1">{{ ptFullHandle($v->account) }}</span>
</a>
@if ($v->src != 'TS' && $v->src != 'PT')
<a href="{{ $v->account->url }}">
<span class="comment-account-name"> {{ $v->account->displayName }} </span>
</a>
@elseif ($v->src == 'TS')
@if (!is_null($v->account->user_id))
<a href="{{ $v->account->url }}" style="{{ $v->account->nameStyle }}">
@else
<span style="font-size: 16px; font-style: normal; color: #20ec77;">
@endif
{{ $v->account->displayName }}
@if (!is_null($v->account->user_id))
</a>
@else
</span>
@endif
@else
<a href="/peertube/a/{{ ptFullHandle($v->account) }}">
<span class="comment-account-name"> {{ $v->account->displayName }} </span>
<span class="comment-account-fid ml-1">{{ ptFullHandle($v->account) }}</span>
</a>
@endif
</div>
<a class="comment-date" title="{{ date('Y/m/d', strtotime($v->createdAt)) }}" href="/w/{{ request()->route('id') }}#threadId={{ $v->threadId }}">
{{ date('Y年m月d日 H:i:s T', strtotime($v->createdAt)) }}
@ -67,9 +88,11 @@
<div mytimestamproutetransformer="" class="comment-html ng-star-inserted">
<?php echo $v->text; ?>
</div>
<div class="comment-actions ng-star-inserted">
<div tabindex="0" class="comment-action-reply">返事</div>
</div>
@if ($v->src == 'TS' || $v->src == 'PT')
<div class="comment-actions ng-star-inserted">
<div tabindex="0" class="comment-action-reply">返事</div>
</div>
@endif
<div class="ng-star-inserted"></div>
</div>
</div>

2
resources/views/theme/techsuwa/component/peertube/w/player.blade.php

@ -12,7 +12,7 @@
playsinline="playsinline"
tabindex="-1"
poster="https://video.076.ne.jp{{ $res['detail']->previewPath }}"
style="width: 813px; height: 458px;"
style="width: 100%; max-height: 720px;"
controls=""
>
@if (!empty($res['detail']->streamingPlaylists))

読み込み中…
キャンセル
保存