TemplateRender.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. <?php
  2. namespace App\Http\Api;
  3. use Illuminate\Support\Facades\Cache;
  4. use Illuminate\Support\Facades\Log;
  5. use Illuminate\Support\Str;
  6. use Illuminate\Support\Facades\Http;
  7. use App\Models\DhammaTerm;
  8. use App\Models\PaliText;
  9. use App\Models\Channel;
  10. use App\Models\PageNumber;
  11. use App\Http\Controllers\CorpusController;
  12. use App\Tools\RedisClusters;
  13. use App\Http\Api\ChannelApi;
  14. use App\Http\Api\MdRender;
  15. class TemplateRender{
  16. protected $param = [];
  17. protected $mode = "read";
  18. protected $channel_id = [];
  19. protected $debug = [];
  20. protected $format = 'react';
  21. protected $studioId = null;
  22. /**
  23. * Create a new command instance.
  24. * string $mode 'read' | 'edit'
  25. * string $format 'react' | 'text' | 'tex' | 'unity'
  26. * @return void
  27. */
  28. public function __construct($param, $channelInfo, $mode,$format='react',$studioId,$debug=[])
  29. {
  30. $this->param = $param;
  31. foreach ($channelInfo as $value) {
  32. $this->channel_id[] = $value->uid;
  33. }
  34. $this->channelInfo = $channelInfo;
  35. $this->mode = $mode;
  36. $this->format = $format;
  37. $this->studioId = $studioId;
  38. $this->debug = $debug;
  39. }
  40. private function info($message,$debug){
  41. if(in_array($debug,$this->debug)){
  42. Log::info($message);
  43. }
  44. }
  45. private function error($message,$debug){
  46. if(in_array($debug,$this->debug)){
  47. Log::error($message);
  48. }
  49. }
  50. public function render($tpl_name){
  51. switch ($tpl_name) {
  52. case 'term':
  53. # 术语
  54. $result = $this->render_term();
  55. break;
  56. case 'note':
  57. $result = $this->render_note();
  58. break;
  59. case 'sent':
  60. $result = $this->render_sent();
  61. break;
  62. case 'quote':
  63. $result = $this->render_quote();
  64. break;
  65. case 'ql':
  66. $result = $this->render_quote_link();
  67. break;
  68. case 'exercise':
  69. $result = $this->render_exercise();
  70. break;
  71. case 'article':
  72. $result = $this->render_article();
  73. break;
  74. case 'nissaya':
  75. $result = $this->render_nissaya();
  76. break;
  77. case 'mermaid':
  78. $result = $this->render_mermaid();
  79. break;
  80. default:
  81. # code...
  82. $result = [
  83. 'props'=>base64_encode(\json_encode([])),
  84. 'html'=>'',
  85. 'tag'=>'span',
  86. 'tpl'=>'unknown',
  87. ];
  88. break;
  89. }
  90. return $result;
  91. }
  92. public function getTermProps($word,$tag){
  93. if(count($this->channel_id)>0){
  94. $channelId = $this->channel_id[0];
  95. }else{
  96. $channelId = null;
  97. }
  98. $channelInfo = $this->channelInfo[0];
  99. if(Str::isUuid($channelId)){
  100. $lang = Channel::where('uid',$channelId)->value('lang');
  101. if(!empty($lang)){
  102. $langFamily = explode('-',$lang)[0];
  103. }else{
  104. $langFamily = 'zh';
  105. }
  106. $this->info("term:{$word} 先查属于这个channel 的",'term');
  107. $this->info('channel id'.$channelId,'term');
  108. $table = DhammaTerm::where("word",$word)
  109. ->where('channal',$channelId);
  110. if(!empty($tag)){
  111. $table = $table->where('tag',$tag);
  112. }
  113. $tplParam = $table->orderBy('updated_at','desc')
  114. ->first();
  115. $studioId = $channelInfo->owner_uid;
  116. }else{
  117. $tplParam = false;
  118. $lang = '';
  119. $langFamily = '';
  120. $studioId = $this->studioId;
  121. }
  122. if(!$tplParam){
  123. if(Str::isUuid($studioId)){
  124. /**
  125. * 没有,再查这个studio的
  126. * 按照语言过滤
  127. * 完全匹配的优先
  128. * 语族匹配也行
  129. */
  130. $this->info("没有-再查这个studio的",'term');
  131. $table = DhammaTerm::where("word",$word);
  132. if(!empty($tag)){
  133. $table = $table->where('tag',$tag);
  134. }
  135. $termsInStudio = $table->where('owner',$channelInfo->owner_uid)
  136. ->orderBy('updated_at','desc')
  137. ->get();
  138. if(count($termsInStudio)>0){
  139. $list = array();
  140. foreach ($termsInStudio as $key=>$term) {
  141. if(empty($term->channal)){
  142. if($term->language===$lang){
  143. $list[$term->guid]=2;
  144. }else if(strpos($term->language,$langFamily) !== false){
  145. $list[$term->guid]=1;
  146. }
  147. }
  148. }
  149. if(count($list)>0){
  150. arsort($list);
  151. foreach ($list as $key => $one) {
  152. foreach ($termsInStudio as $term) {
  153. if($term->guid===$key){
  154. $tplParam = $term;
  155. break;
  156. }
  157. }
  158. break;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. if(!$tplParam){
  165. $this->info("没有,再查社区",'term');
  166. $community_channel = ChannelApi::getSysChannel("_community_term_zh-hans_");
  167. $table = DhammaTerm::where("word",$word);
  168. if(!empty($tag)){
  169. $table = $table->where('tag',$tag);
  170. }
  171. $tplParam = $table->where('channal',$community_channel)
  172. ->first();
  173. if($tplParam){
  174. $isCommunity = true;
  175. }else{
  176. $this->info("查社区没有",'term');
  177. }
  178. }
  179. $output = [
  180. "word" => $word,
  181. "parentChannelId" => $channelId,
  182. "parentStudioId" => $channelInfo->owner_uid,
  183. ];
  184. $innerString = $output["word"];
  185. if($tplParam){
  186. $output["id"] = $tplParam->guid;
  187. $output["meaning"] = $tplParam->meaning;
  188. $output["channel"] = $tplParam->channal;
  189. if(isset($isCommunity)){
  190. $output["isCommunity"] = true;
  191. }
  192. $innerString = "{$output["meaning"]}({$output["word"]})";
  193. if(!empty($tplParam->other_meaning)){
  194. $output["meaning2"] = $tplParam->other_meaning;
  195. }
  196. }
  197. $output['innerHtml'] = $innerString;
  198. return $output;
  199. }
  200. private function render_term(){
  201. $word = $this->get_param($this->param,"word",1);
  202. $props = $this->getTermProps($word,'');
  203. //$key = "/term/{$channelId}/{$word}";
  204. $output = $props['word'];
  205. switch ($this->format) {
  206. case 'react':
  207. $output=[
  208. 'props'=>base64_encode(\json_encode($props)),
  209. 'html'=>$props['innerHtml'],
  210. 'tag'=>'span',
  211. 'tpl'=>'term',
  212. ];
  213. break;
  214. case 'unity':
  215. $output=[
  216. 'props'=>base64_encode(\json_encode($props)),
  217. 'tpl'=>'term',
  218. ];
  219. break;
  220. case 'html':
  221. if(isset($props["meaning"])){
  222. $key = 'term-'.$props["word"];
  223. $termHead = "<a href='#'>".$props['meaning']."</a>";
  224. if(isset($GLOBALS[$key])){
  225. $output = $termHead;
  226. }else{
  227. $GLOBALS[$key] = 1;
  228. $output = $termHead.'(<em>'.$props["word"].'</em>)';
  229. }
  230. }else{
  231. $output = $props["word"];
  232. }
  233. break;
  234. case 'text':
  235. if(isset($props["meaning"])){
  236. $key = 'term-'.$props["word"];
  237. if(isset($GLOBALS[$key])){
  238. $output = $props["meaning"];
  239. }else{
  240. $GLOBALS[$key] = 1;
  241. $output = $props["meaning"].'('.$props["word"].')';
  242. }
  243. }else{
  244. $output = $props["word"];
  245. }
  246. break;
  247. case 'tex':
  248. if(isset($props["meaning"])){
  249. $key = 'term-'.$props["word"];
  250. if(isset($GLOBALS[$key])){
  251. $output = $props["meaning"];
  252. }else{
  253. $GLOBALS[$key] = 1;
  254. $output = $props["meaning"].'('.$props["word"].')';
  255. }
  256. }else{
  257. $output = $props["word"];
  258. }
  259. break;
  260. case 'simple':
  261. if(isset($props["meaning"])){
  262. $output = $props["meaning"];
  263. }else{
  264. $output = $props["word"];
  265. }
  266. break;
  267. default:
  268. if(isset($props["meaning"])){
  269. $output = $props["meaning"];
  270. }else{
  271. $output = $props["word"];
  272. }
  273. break;
  274. }
  275. return $output;
  276. }
  277. private function render_note(){
  278. $note = $this->get_param($this->param,"text",1);
  279. $trigger = $this->get_param($this->param,"trigger",2);
  280. $props = ["note" => $note ];
  281. $innerString = "";
  282. if(!empty($trigger)){
  283. $props["trigger"] = $trigger;
  284. $innerString = $props["trigger"];
  285. }
  286. if($this->format==='unity'){
  287. $props["note"] = MdRender::render($props["note"],
  288. $this->channel_id,
  289. null,
  290. 'read',
  291. 'translation',
  292. 'markdown',
  293. 'unity'
  294. );
  295. }
  296. $output = $note;
  297. switch ($this->format) {
  298. case 'react':
  299. $output=[
  300. 'props'=>base64_encode(\json_encode($props)),
  301. 'html'=>$innerString,
  302. 'tag'=>'span',
  303. 'tpl'=>'note',
  304. ];
  305. break;
  306. case 'unity':
  307. $output=[
  308. 'props'=>base64_encode(\json_encode($props)),
  309. 'tpl'=>'note',
  310. ];
  311. break;
  312. case 'html':
  313. if(isset($GLOBALS['note_sn'])){
  314. $GLOBALS['note_sn']++;
  315. }else{
  316. $GLOBALS['note_sn'] = 1;
  317. $GLOBALS['note'] = array();
  318. }
  319. $GLOBALS['note'][] = [
  320. 'sn' => 1,
  321. 'trigger' => $trigger,
  322. 'content' => MdRender::render($props["note"],
  323. $this->channel_id,
  324. null,
  325. 'read',
  326. 'translation',
  327. 'markdown',
  328. 'html'
  329. ),
  330. ];
  331. $link="<a href='#footnote-".$GLOBALS['note_sn']."' name='note-".$GLOBALS['note_sn']."'>";
  332. if(empty($trigger)){
  333. $output = $link. "<sup>[" . $GLOBALS['note_sn'] . "]</sup></a>";
  334. }else{
  335. $output = $link . $trigger . "</a>";
  336. }
  337. break;
  338. case 'text':
  339. $output = $trigger;
  340. break;
  341. case 'tex':
  342. $output = $trigger;
  343. break;
  344. case 'simple':
  345. $output = '';
  346. break;
  347. default:
  348. $output = '';
  349. break;
  350. }
  351. return $output;
  352. }
  353. private function render_nissaya(){
  354. $pali = $this->get_param($this->param,"pali",1);
  355. $meaning = $this->get_param($this->param,"meaning",2);
  356. $innerString = "";
  357. $props = [
  358. "pali" => $pali,
  359. "meaning" => $meaning,
  360. ];
  361. switch ($this->format) {
  362. case 'react':
  363. $output = [
  364. 'props'=>base64_encode(\json_encode($props)),
  365. 'html'=>$innerString,
  366. 'tag'=>'span',
  367. 'tpl'=>'nissaya',
  368. ];
  369. break;
  370. case 'unity':
  371. $output = [
  372. 'props'=>base64_encode(\json_encode($props)),
  373. 'tpl'=>'nissaya',
  374. ];
  375. break;
  376. case 'text':
  377. $output = $pali.'၊'.$meaning;
  378. break;
  379. case 'tex':
  380. $output = $pali.'၊'.$meaning;
  381. break;
  382. case 'simple':
  383. $output = $pali.'၊'.$meaning;
  384. break;
  385. default:
  386. $output = $pali.'၊'.$meaning;
  387. break;
  388. }
  389. return $output;
  390. }
  391. private function render_exercise(){
  392. $id = $this->get_param($this->param,"id",1);
  393. $title = $this->get_param($this->param,"title",1);
  394. $props = [
  395. "id" => $id,
  396. "title" => $title,
  397. "channel" => $this->channel_id[0],
  398. ];
  399. switch ($this->format) {
  400. case 'react':
  401. $output = [
  402. 'props'=>base64_encode(\json_encode($props)),
  403. 'html'=>"",
  404. 'tag'=>'span',
  405. 'tpl'=>'exercise',
  406. ];
  407. break;
  408. case 'unity':
  409. $output = [
  410. 'props'=>base64_encode(\json_encode($props)),
  411. 'tpl'=>'exercise',
  412. ];
  413. break;
  414. case 'text':
  415. $output = $title;
  416. break;
  417. case 'tex':
  418. $output = $title;
  419. break;
  420. case 'simple':
  421. $output = $title;
  422. break;
  423. default:
  424. $output = '';
  425. break;
  426. }
  427. return $output;
  428. }
  429. private function render_article(){
  430. $type = $this->get_param($this->param,"type",1);
  431. $id = $this->get_param($this->param,"id",2);
  432. $title = $this->get_param($this->param,"title",3);
  433. $channel = $this->get_param($this->param,"channel",4,$this->channel_id[0]);
  434. $style = $this->get_param($this->param,"style",5);
  435. $props = [
  436. "type" => $type,
  437. "id" => $id,
  438. "channel" => $channel,
  439. 'style' => $style,
  440. ];
  441. if(!empty($title)){
  442. $props['title'] = $title;
  443. }
  444. switch ($this->format) {
  445. case 'react':
  446. $output = [
  447. 'props'=>base64_encode(\json_encode($props)),
  448. 'html'=>"",
  449. 'text'=>$title,
  450. 'tag'=>'span',
  451. 'tpl'=>'article',
  452. ];
  453. break;
  454. case 'unity':
  455. $output = [
  456. 'props'=>base64_encode(\json_encode($props)),
  457. 'tpl'=>'article',
  458. ];
  459. break;
  460. case 'text':
  461. $output = $title;
  462. break;
  463. case 'tex':
  464. $output = $title;
  465. break;
  466. case 'simple':
  467. $output = $title;
  468. break;
  469. default:
  470. $output = '';
  471. break;
  472. }
  473. return $output;
  474. }
  475. private function render_quote(){
  476. $paraId = $this->get_param($this->param,"para",1);
  477. $channelId = $this->channel_id[0];
  478. $props = RedisClusters::remember("/quote/{$channelId}/{$paraId}",
  479. config('mint.cache.expire'),
  480. function() use($paraId,$channelId){
  481. $para = \explode('-',$paraId);
  482. $output = [
  483. "paraId" => $paraId,
  484. "channel" => $channelId,
  485. "innerString" => $paraId,
  486. ];
  487. if(count($para)<2){
  488. return $output;
  489. }
  490. $PaliText = PaliText::where("book",$para[0])
  491. ->where("paragraph",$para[1])
  492. ->select(['toc','path'])
  493. ->first();
  494. if($PaliText){
  495. $output["pali"] = $PaliText->toc;
  496. $output["paliPath"] = \json_decode($PaliText->path);
  497. $output["innerString"]= $PaliText->toc;
  498. }
  499. return $output;
  500. });
  501. switch ($this->format) {
  502. case 'react':
  503. $output = [
  504. 'props'=>base64_encode(\json_encode($props)),
  505. 'html'=>$props["innerString"],
  506. 'tag'=>'span',
  507. 'tpl'=>'quote',
  508. ];
  509. break;
  510. case 'unity':
  511. $output = [
  512. 'props'=>base64_encode(\json_encode($props)),
  513. 'tpl'=>'quote',
  514. ];
  515. break;
  516. case 'text':
  517. $output = $props["innerString"];
  518. break;
  519. case 'tex':
  520. $output = $props["innerString"];
  521. break;
  522. case 'simple':
  523. $output = $props["innerString"];
  524. break;
  525. default:
  526. $output = $props["innerString"];
  527. break;
  528. }
  529. return $output;
  530. }
  531. private function render_quote_link(){
  532. $type = $this->get_param($this->param,"type",1);
  533. $bookName = $this->get_param($this->param,"bookname",2,false);
  534. $volume = $this->get_param($this->param,"volume",3,false);
  535. $page = $this->get_param($this->param,"page",4,false);
  536. $style = $this->get_param($this->param,"style",5,'modal');
  537. $title = $this->get_param($this->param,"title",6,false);
  538. $book = $this->get_param($this->param,"book",7,false);
  539. $para = $this->get_param($this->param,"para",8,false);
  540. if(!$bookName || !$volume || !$page){
  541. /**
  542. * 没有指定书名,根据book para 查询
  543. */
  544. if($book && $para){
  545. $pageInfo = PageNumber::where('type',strtoupper($type))
  546. ->where('book',$book)
  547. ->where('paragraph','<=',$para)
  548. ->orderBy('paragraph','desc')
  549. ->first();
  550. if($pageInfo){
  551. if(!$bookName){
  552. foreach (BookTitle::get() as $value) {
  553. if($value['id']===$pageInfo->pcd_book_id){
  554. switch (strtoupper($type)) {
  555. case 'M':
  556. $key = 'm_title';
  557. break;
  558. case 'P':
  559. $key = 'p_title';
  560. break;
  561. case 'V':
  562. $key = 'v_title';
  563. break;
  564. default:
  565. $key = 'term';
  566. break;
  567. }
  568. $bookName = $value[$key];
  569. }
  570. }
  571. }
  572. if(!$volume){
  573. $volume = $pageInfo->volume;
  574. }
  575. if(!$page){
  576. $page = $pageInfo->page;
  577. }
  578. }
  579. }
  580. }
  581. $props = [
  582. 'type' => $type,
  583. 'bookName' => $bookName,
  584. 'volume' => $volume,
  585. 'page' => $page,
  586. 'style' => $style,
  587. ];
  588. if($book && $para){
  589. $props['book'] = $book;
  590. $props['para'] = $para;
  591. }
  592. if($title){
  593. $props['title'] = $title;
  594. }
  595. $term = $this->getTermProps($bookName,':quote:');
  596. $props['term'] = $term;
  597. if(isset($term['id'])){
  598. $props['bookNameLocal'] = $term['meaning'];
  599. $text = $term['meaning'];
  600. }else{
  601. $text = $bookName;
  602. }
  603. $text .= " {$volume}.{$page}";
  604. switch ($this->format) {
  605. case 'react':
  606. $output = [
  607. 'props'=>base64_encode(\json_encode($props)),
  608. 'html'=>'',
  609. 'tag'=>'span',
  610. 'tpl'=>'quote-link',
  611. ];
  612. break;
  613. case 'unity':
  614. $output = [
  615. 'props'=>base64_encode(\json_encode($props)),
  616. 'tpl'=>'quote-link',
  617. ];
  618. break;
  619. default:
  620. $output = $text;
  621. break;
  622. }
  623. return $output;
  624. }
  625. private function render_sent(){
  626. $sid = $this->get_param($this->param,"sid",1);
  627. $channel = $this->get_param($this->param,"channel",2);
  628. if(!empty($channel)){
  629. $channels = explode(',',$channel);
  630. }else{
  631. $channels = $this->channel_id;
  632. }
  633. $sentInfo = explode('@',trim($sid));
  634. $sentId = $sentInfo[0];
  635. if(isset($sentInfo[1])){
  636. $channels = [$sentInfo[1]];
  637. }
  638. $Sent = new CorpusController();
  639. $props = $Sent->getSentTpl($sentId,$channels,
  640. $this->mode,true,
  641. $this->format);
  642. if($props === false){
  643. $props['error']="句子模版渲染错误。句子参数个数不符。应该是四个。";
  644. }
  645. if($this->mode==='read'){
  646. $tpl = "sentread";
  647. }else{
  648. $tpl = "sentedit";
  649. }
  650. switch ($this->format) {
  651. case 'react':
  652. $output = [
  653. 'props'=>base64_encode(\json_encode($props)),
  654. 'html'=>"",
  655. 'tag'=>'span',
  656. 'tpl'=>$tpl,
  657. ];
  658. break;
  659. case 'unity':
  660. $output = [
  661. 'props'=>base64_encode(\json_encode($props)),
  662. 'tpl'=>$tpl,
  663. ];
  664. break;
  665. case 'text':
  666. $output = '';
  667. if(isset($props['translation']) && is_array($props['translation'])){
  668. foreach ($props['translation'] as $key => $value) {
  669. $output .= $value['html'];
  670. }
  671. }
  672. break;
  673. case 'html':
  674. $output = '';
  675. if(isset($props['translation']) && is_array($props['translation'])){
  676. foreach ($props['translation'] as $key => $value) {
  677. $output .= '<span class="sentence">'.$value['html'].'</span>';
  678. }
  679. }
  680. break;
  681. case 'tex':
  682. $output = '';
  683. if(isset($props['translation']) && is_array($props['translation'])){
  684. foreach ($props['translation'] as $key => $value) {
  685. $output .= $value['html'];
  686. }
  687. }
  688. break;
  689. case 'simple':
  690. $output = '';
  691. if(isset($props['translation']) &&
  692. is_array($props['translation']) &&
  693. count($props['translation']) > 0
  694. ){
  695. $sentences = $props['translation'];
  696. foreach ($sentences as $key => $value) {
  697. $output .= $value['html'];
  698. }
  699. }
  700. if(empty($output)){
  701. if(isset($props['origin']) &&
  702. is_array($props['origin']) &&
  703. count($props['origin']) > 0
  704. ){
  705. $sentences = $props['origin'];
  706. foreach ($sentences as $key => $value) {
  707. $output .= $value['html'];
  708. }
  709. }
  710. }
  711. break;
  712. default:
  713. $output = '';
  714. break;
  715. }
  716. return $output;
  717. }
  718. private function render_mermaid(){
  719. $text = json_decode(base64_decode($this->get_param($this->param,"text",1)));
  720. $props = ["text" => implode("\n",$text)];
  721. switch ($this->format) {
  722. case 'react':
  723. $output = [
  724. 'props'=>base64_encode(\json_encode($props)),
  725. 'html'=>"mermaid",
  726. 'tag'=>'div',
  727. 'tpl'=>'mermaid',
  728. ];
  729. break;
  730. case 'unity':
  731. $output = [
  732. 'props'=>base64_encode(\json_encode($props)),
  733. 'tpl'=>'mermaid',
  734. ];
  735. break;
  736. case 'text':
  737. $output = 'mermaid';
  738. break;
  739. case 'tex':
  740. $output = 'mermaid';
  741. break;
  742. case 'simple':
  743. $output = 'mermaid';
  744. break;
  745. default:
  746. $output = 'mermaid';
  747. break;
  748. }
  749. return $output;
  750. }
  751. private function get_param(array $param,string $name,int $id,string $default=''){
  752. if(isset($param[$name])){
  753. return trim($param[$name]);
  754. }else if(isset($param["{$id}"])){
  755. return trim($param["{$id}"]);
  756. }else{
  757. return $default;
  758. }
  759. }
  760. }