2
0

TermSummaryController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Api\ChannelApi;
  4. use App\Models\DhammaTerm;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Response;
  7. class TermSummaryController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return Response
  13. */
  14. public function index()
  15. {
  16. //
  17. }
  18. /**
  19. * Store a newly created resource in storage.
  20. *
  21. * @return Response
  22. */
  23. public function store(Request $request)
  24. {
  25. //
  26. }
  27. /**
  28. * Display the specified resource.
  29. *
  30. * @return Response
  31. */
  32. public function show(string $id)
  33. {
  34. //
  35. $term = DhammaTerm::where('guid', $id)->first();
  36. if (! $term) {
  37. return $this->error('no id');
  38. }
  39. if (empty($term->note)) {
  40. $community_channel = ChannelApi::getSysChannel('_community_term_zh-hans_');
  41. // 查找社区解释
  42. $note = DhammaTerm::where('word', $term->word)
  43. ->where('channal', $community_channel)
  44. ->value('note');
  45. } else {
  46. $note = $term->note;
  47. }
  48. // 替换术语
  49. $pattern = "/\[\[(.+?)\]\]/";
  50. $replacement = '$1';
  51. $html = preg_replace($pattern, $replacement, $note);
  52. $pattern = "/\{\{(.+?)\}\}/";
  53. $replacement = '';
  54. $html = preg_replace($pattern, $replacement, $html);
  55. $html = mb_substr($html, 0, 500, 'UTF-8');
  56. return $this->ok($html);
  57. }
  58. /**
  59. * Update the specified resource in storage.
  60. *
  61. * @return Response
  62. */
  63. public function update(Request $request, DhammaTerm $dhammaTerm)
  64. {
  65. //
  66. }
  67. /**
  68. * Remove the specified resource from storage.
  69. *
  70. * @return Response
  71. */
  72. public function destroy(DhammaTerm $dhammaTerm)
  73. {
  74. //
  75. }
  76. }