ようつべである20以上件のコメも見える

このコミットが含まれているのは:
テクニカル諏訪子 2020-12-30 14:15:53 +09:00
コミット 8f2560a70e
2個のファイルの変更29行の追加10行の削除

ファイルの表示

@ -36,6 +36,11 @@ class Prayer {
$comments = DB::table('blg_comments')->where('video_id', $vid)->orderBy('id', 'asc')->get()->toArray(); $comments = DB::table('blg_comments')->where('video_id', $vid)->orderBy('id', 'asc')->get()->toArray();
$ytslug = explode('?v=', $res->youtube); $ytslug = explode('?v=', $res->youtube);
$res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1]) : array()); $res->ytcomment = (isset($ytslug[1]) ? $this->getYouTubeCome($ytslug[1]) : array());
if ($res->ytcomment['nextPage'] != '') {
while ($res->ytcomment['nextPage'] != '') {
$res->ytcomment = $this->checkYouTubeCome($res->ytcomment, $ytslug[1], $res->ytcomment['nextPage']);
}
}
$res->nicocomment = array(); $res->nicocomment = array();
$res->bccomment = array(); $res->bccomment = array();
$res->lbcomment = array(); $res->lbcomment = array();
@ -61,14 +66,24 @@ class Prayer {
} }
$res->user = userDetail(null, $this->cook); $res->user = userDetail(null, $this->cook);
$res->comments = $comments; $res->comments['total'] = count($comments);
$res->comments['come'] = $comments;
return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]); return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
} }
function getYouTubeCome ($slug) { 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='') {
$ch = curl_init(); $ch = curl_init();
$url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=published&videoId='.$slug.'&key='.env('YOUTUBE_API'); $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;
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
@ -80,6 +95,7 @@ class Prayer {
$come = array(); $come = array();
$get = json_decode($get, false); $get = json_decode($get, false);
if (isset($get->error)) return array(); if (isset($get->error)) return array();
$come['come'] = array();
foreach ($get->items as $g) { foreach ($get->items as $g) {
$g->comment = new \stdClass(); $g->comment = new \stdClass();
@ -103,9 +119,13 @@ class Prayer {
} }
} }
$come[] = $g->comment; $come['come'][] = $g->comment;
} }
$come['total'] = $get->pageInfo->totalResults;
$come['prevPage'] = (isset($get->prevPageToken) ? $get->prevPageToken : '');
$come['nextPage'] = (isset($get->nextPageToken) ? $get->nextPageToken : '');
return $come; return $come;
} }
} }

ファイルの表示

@ -1,17 +1,17 @@
<template> <template>
<div id="comments" class="comments-area clearfix"> <div id="comments" class="comments-area clearfix">
<h3 class="comments-count section-heading uppercase"><span>{{ total }} コメント</span></h3> <h3 class="comments-count section-heading uppercase"><span>{{ comment.total }}{{ (comment.nextPage ? '以上' : '') }} 件のコメント</span></h3>
<div v-if="total === 0">コメントがありません</div> <div v-if="total === 0">コメントがありません</div>
<span v-else> <span v-else>
<ul class="commentlist" v-for="(c, i) in comment" :key="`comment-${i}`"> <ul class="commentlist" v-for="(c, i) in comment.come" :key="`comment-${i}`">
<li class="comment even thread-even depth-1" :id="`li-comment-${c.id}`"> <li class="comment even thread-even depth-1" :id="`li-comment-${c.id}`">
<div class="commentnumber">{{ i+1 }}</div> <div class="commentnumber">{{ Number(i)+1 }}</div>
<div :id="`comment-${c.id}`"> <div :id="`comment-${c.id}`">
<div> <div>
<cite class="fn"> <cite class="fn">
<span v-if="isvideo === 'n'"> <span v-if="isvideo === 'n'">
<img style="height: 24px;" :src="c.icon" :alt="`${c.name}さんのアイコン`"> <img style="height: 24px;" :src="c.icon" :alt="`${c.name}さんのアイコン`">
<a :href="c.channel">{{ (c.name || '名無しのテクニシャン') }}</a> <a :href="c.channel" style="overflow-wrap: break-word;">{{ (c.name || '名無しのテクニシャン') }}</a>
</span> </span>
<span v-else> <span v-else>
<span v-if="c.user_id"><a :href="`/profile/${c.user_id}`" :style="c.showcol"><img style="width: 24px; height: 24px;" :src="c.avatar" :alt="`${c.showname}さんのアイコン`"> {{ c.showname }}</a></span> <span v-if="c.user_id"><a :href="`/profile/${c.user_id}`" :style="c.showcol"><img style="width: 24px; height: 24px;" :src="c.avatar" :alt="`${c.showname}さんのアイコン`"> {{ c.showname }}</a></span>
@ -91,7 +91,7 @@
<script> <script>
export default { export default {
props: { user: Object, slug: '', isvideo: '', comments: Array }, props: { user: Object, slug: '', isvideo: '', comments: Object },
data: function () { return { comment: this.comments, newComment: {}, err: '', loading: true, sending: false } }, data: function () { return { comment: this.comments, newComment: {}, err: '', loading: true, sending: false } },
computed: { computed: {
total: function () { total: function () {
@ -106,7 +106,6 @@
this.newComment.mail = ''; this.newComment.mail = '';
this.newComment.text = ''; this.newComment.text = '';
}, },
page () {},
send () { send () {
if (this.isvideo !== 'n') { if (this.isvideo !== 'n') {
this.err = ''; this.err = '';