2
0

TermSummaryController.php 2.2 KB

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