$this->book, 'paragraph' => $this->paragraph, ]; if (isset($this->rank)) { $data['rank'] = $this->rank; } $paliText = PaliText::where('book', $this->book) ->where('paragraph', $this->paragraph) ->first(); if ($paliText) { $data['path'] = json_decode($paliText->path); if ($paliText->level < 100) { $data['paliTitle'] = $paliText->toc; $book = $this->book; $para = $this->paragraph; $data['link'] = config('app.url')."/library/tipitaka/{$book}-{$para}/read"; } else { $data['paliTitle'] = PaliText::where('book', $this->book) ->where('paragraph', $paliText->parent) ->value('toc'); $book = end($data['path'])['book']; $para = end($data['path'])['paragraph']; $data['link'] = config('app.url')."/library/tipitaka/{$book}-{$para}/read#{$this->paragraph}"; } $keyWords = explode(',', $request->input('key')); $keyWordsUpper = $keyWords; foreach ($keyWords as $key => $word) { if (mb_substr($word, -3, null, 'UTF-8') === 'nti') { $keyWordsUpper[] = mb_substr($word, 0, mb_strlen($word, 'UTF-8') - 3, 'UTF-8'); } elseif (mb_substr($word, -3, null, 'UTF-8') === 'ti') { $keyWordsUpper[] = mb_substr($word, 0, mb_strlen($word, 'UTF-8') - 2, 'UTF-8'); } } foreach ($keyWords as $key => $word) { $keyWordsUpper[] = mb_strtoupper(mb_substr($word, 0, 1, 'UTF-8'), 'UTF-8').mb_substr($word, 1, null, 'UTF-8'); } $keyReplace = []; foreach ($keyWordsUpper as $key => $word) { $keyReplace[] = "{$word}"; } $data['highlight'] = str_replace($keyWordsUpper, $keyReplace, $paliText->html); } $pageNumbers = PageNumber::where('book', $this->book) ->where('paragraph', $this->paragraph) ->orderBy('wid') ->get() ->unique('type') ->map(fn ($pageNumber) => [ 'type' => $pageNumber->type, 'page' => $pageNumber->page, ]) ->values() ->all(); if ($pageNumbers !== []) { $data['ref'] = $pageNumbers; } return $data; } }