diff --git a/app/Http/Controllers/Video/Prayer.php b/app/Http/Controllers/Video/Prayer.php index 4e2aac5..25374c6 100644 --- a/app/Http/Controllers/Video/Prayer.php +++ b/app/Http/Controllers/Video/Prayer.php @@ -42,14 +42,22 @@ class Prayer { } } + $res->kvcomment = array(); + $kvslug = explode('/', $res->kerotube); + if (isset($kvslug[5])) { + $res->kvcomment = $this->getKeroCome($kvslug[5], ''); + } + if ($res->ytcomment) $res->ytcomment = $this->backupYTComment($slugger, $res->ytcomment); $res->nicocomment = array(); $res->bccomment = array(); $res->lbcomment = array(); + if ($res->kvcomment) $res->kvcomment = $this->backupKeroComment($slugger, $res->kvcomment); foreach ($comments as $k => $c) { $c->replyCount = 0; $c->isvideo = 't'; + $c->src = 'TS'; if (!is_null($c->user_id) && !empty(userDetail($c->user_id))) { $det = userDetail($c->user_id); @@ -74,13 +82,63 @@ class Prayer { $res->comments['total'] = count($comments); $res->comments['come'] = $comments; $res->comments['total'] += (isset($res->ytcomment['total']) ? $res->ytcomment['total'] : 0); + $res->comments['total'] += (isset($res->kvcomment['total']) ? $res->kvcomment['total'] : 0); if (isset($res->ytcomment['come'])) $res->comments['come'] = array_merge($res->comments['come'], $res->ytcomment['come']); + if (isset($res->kvcomment['come'])) $res->comments['come'] = array_merge($res->comments['come'], $res->kvcomment['come']); DB::table('vid_video')->where('vid', $vid)->update(['view' => $res->view+1]); return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]); } + function getKeroCome ($slug, $tslug) { + $come = []; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, env('KERO_URI').'/api/v1/videos/'.$slug.'/comment-threads'); + 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); + + $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; + $g->comments->icon = env('KERO_URI').$g->account->avatar->path; + $g->comments->message = strip_tags($g->text, array('
')); + $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; } @@ -124,6 +182,7 @@ class Prayer { $g->comment->message = strip_tags($g->snippet->topLevelComment->snippet->textDisplay, array('
')); $g->comment->replyCount = (isset($g->snippet->totalReplyCount) ? $g->snippet->totalReplyCount : 0); $g->comment->isvideo = 'n'; + $g->comment->src = 'YT'; if (isset($g->replies)) { $g->comment->replies = array(); @@ -176,4 +235,21 @@ class Prayer { return $com; } + + function backupKeroComment ($slug, $com) { + 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; + } } \ No newline at end of file diff --git a/resources/js/components/comments.vue b/resources/js/components/comments.vue index 05d6985..4a6fd77 100644 --- a/resources/js/components/comments.vue +++ b/resources/js/components/comments.vue @@ -44,7 +44,7 @@