Răsfoiți Sursa

sent支持mode参数

visuddhinanda 3 zile în urmă
părinte
comite
c025bcb916
1 a modificat fișierele cu 22 adăugiri și 20 ștergeri
  1. 22 20
      api-v13/app/Http/Api/TemplateRender.php

+ 22 - 20
api-v13/app/Http/Api/TemplateRender.php

@@ -361,7 +361,7 @@ class TemplateRender
                 $langFamily = 'zh';
             }
             $this->info("term:{$word} 先查属于这个channel 的", 'term');
-            $this->info('channel id'.$channelId, 'term');
+            $this->info('channel id' . $channelId, 'term');
             $table = DhammaTerm::where('word', $word)
                 ->where('channal', $channelId);
             if ($tag && ! empty($tag)) {
@@ -505,13 +505,13 @@ class TemplateRender
                 break;
             case 'markdown':
                 if (isset($props['meaning'])) {
-                    $key = 'term-'.$props['word'];
+                    $key = 'term-' . $props['word'];
                     if (isset($GLOBALS[$key]) && $GLOBALS[$key] === 1) {
                         $GLOBALS[$key]++;
                         $output = $props['meaning'];
                     } else {
                         $GLOBALS[$key] = 1;
-                        $output = $props['meaning'].'('.$props['word'].')';
+                        $output = $props['meaning'] . '(' . $props['word'] . ')';
                     }
                 } else {
                     $output = $props['word'];
@@ -525,7 +525,7 @@ class TemplateRender
                         $GLOBALS['note'] = [];
                     }
                     $content = $props['note'];
-                    $output .= '[^'.$GLOBALS['note_sn'].']';
+                    $output .= '[^' . $GLOBALS['note_sn'] . ']';
                     $GLOBALS['note'][] = [
                         'sn' => $GLOBALS['note_sn'],
                         'trigger' => '',
@@ -600,11 +600,11 @@ class TemplateRender
                     'content' => $noteContent,
                 ];
 
-                $link = "<a href='#footnote-".$GLOBALS['note_sn']."' name='note-".$GLOBALS['note_sn']."'>";
+                $link = "<a href='#footnote-" . $GLOBALS['note_sn'] . "' name='note-" . $GLOBALS['note_sn'] . "'>";
                 if (empty($trigger)) {
-                    $output = $link.'<sup>['.$GLOBALS['note_sn'].']</sup></a>';
+                    $output = $link . '<sup>[' . $GLOBALS['note_sn'] . ']</sup></a>';
                 } else {
-                    $output = $link.$trigger.'</a>';
+                    $output = $link . $trigger . '</a>';
                 }
                 $output = "<label for=\"sn-{$GLOBALS['note_sn']}\"
                 class=\"margin-toggle sidenote-number\" >{$trigger}</label>
@@ -637,7 +637,7 @@ class TemplateRender
                     'markdown',
                     'markdown'
                 );
-                $output = '[^'.$GLOBALS['note_sn'].']';
+                $output = '[^' . $GLOBALS['note_sn'] . ']';
                 $GLOBALS['note'][] = [
                     'sn' => $GLOBALS['note_sn'],
                     'trigger' => $trigger,
@@ -679,10 +679,10 @@ class TemplateRender
                 ];
                 break;
             case 'prompt':
-                $output = Tools::MyToRm($pali).':'.end($props['meaning']);
+                $output = Tools::MyToRm($pali) . ':' . end($props['meaning']);
                 break;
             default:
-                $output = $pali.'၊'.$meaning;
+                $output = $pali . '၊' . $meaning;
                 break;
         }
 
@@ -1067,6 +1067,7 @@ class TemplateRender
         $sid = $this->get_param($this->param, 'id', 1);
         $channel = $this->get_param($this->param, 'channel', 2);
         $show = $this->get_param($this->param, 'text', 2, 'both');
+        $mode = $this->get_param($this->param, 'mode', 3, null);
 
         if (! empty($channel)) {
             $channels = explode(',', $channel);
@@ -1079,10 +1080,11 @@ class TemplateRender
             $channels = [$sentInfo[1]];
         }
         $Sent = new CorpusController;
+        $currMode = $mode ?? $this->mode;
         $props = $Sent->getSentTpl(
             $sentId,
             $channels,
-            $this->mode,
+            $currMode,
             true,
             $this->format
         );
@@ -1090,7 +1092,7 @@ class TemplateRender
             $props['error'] = '句子模版渲染错误。句子参数个数不符。应该是四个。';
             Log::error('句子模版渲染错误。句子参数个数不符。应该是四个。');
         }
-        if ($this->mode === 'read') {
+        if ($currMode === 'read') {
             $tpl = 'sentread';
         } else {
             $tpl = 'sentedit';
@@ -1158,14 +1160,14 @@ class TemplateRender
                 if ($show === 'both' || $show === 'origin') {
                     if (isset($props['origin']) && is_array($props['origin'])) {
                         foreach ($props['origin'] as $key => $value) {
-                            $output .= '<span class="origin">'.$value['html'].'</span>';
+                            $output .= '<span class="origin">' . $value['html'] . '</span>';
                         }
                     }
                 }
                 if ($show === 'both' || $show === 'translation') {
                     if (isset($props['translation']) && is_array($props['translation'])) {
                         foreach ($props['translation'] as $key => $value) {
-                            $output .= '<span class="translation">'.$value['html'].'</span>';
+                            $output .= '<span class="translation">' . $value['html'] . '</span>';
                         }
                     }
                 }
@@ -1342,7 +1344,7 @@ class TemplateRender
         $props = ['word' => $word];
 
         $localTermChannel = ChannelApi::getSysChannel(
-            '_System_Grammar_Term_'.strtolower($this->lang).'_',
+            '_System_Grammar_Term_' . strtolower($this->lang) . '_',
             '_System_Grammar_Term_en_'
         );
         $term = $this->getTermProps($word, null, $localTermChannel);
@@ -1469,15 +1471,15 @@ class TemplateRender
             case 'markdown':
                 $output = '';
                 foreach ($references as $key => $reference) {
-                    $output .= '['.$reference['sn'].'] **'.ucfirst($reference['title']).'** ';
-                    $output .= $reference['copyright']."\n\n";
+                    $output .= '[' . $reference['sn'] . '] **' . ucfirst($reference['title']) . '** ';
+                    $output .= $reference['copyright'] . "\n\n";
                 }
                 break;
             default:
                 $output = '';
                 foreach ($references as $key => $reference) {
-                    $output .= '['.$reference['sn'].'] '.ucfirst($reference['title']).' ';
-                    $output .= $reference['copyright']."\n";
+                    $output .= '[' . $reference['sn'] . '] ' . ucfirst($reference['title']) . ' ';
+                    $output .= $reference['copyright'] . "\n";
                 }
                 break;
         }
@@ -1557,7 +1559,7 @@ class TemplateRender
         return $output;
     }
 
-    private function get_param(array $param, string $name, int $id, string $default = '')
+    private function get_param(array $param, string $name, int $id, ?string $default = '')
     {
         if (isset($param[$name])) {
             return trim($param[$name]);