Browse Source

add MdTpl

visuddhinanda 2 years ago
parent
commit
0cea803738
1 changed files with 9 additions and 4 deletions
  1. 9 4
      app/Http/Controllers/DictController.php

+ 9 - 4
app/Http/Controllers/DictController.php

@@ -206,19 +206,24 @@ class DictController extends Controller
 
     private function GrmAbbr($input,$dictid){
         $mean = $input;
-
+        $replaced = array();
         foreach (GRM_ABBR as $key => $value) {
-            # code...
+            if(in_array($value["abbr"],$replaced)){
+                continue;
+            }else{
+                $replaced[] = $value["abbr"];
+            }
             if($dictid !== 0){
                 if($value["dictid"]=== $dictid && strpos($input,$value["abbr"]."|") == false){
                     $mean = str_ireplace($value["abbr"],"|@{$value["abbr"]}-{$value["replace"]}",$mean);
                 }
             }else{
                 if( strpos($mean,"|@".$value["abbr"]) == false){
-                    $mean = str_ireplace($value["abbr"],"|@{$value["abbr"]}-{$value["replace"]}|",$mean);
+                    $props=base64_encode(\json_encode(['text'=>$value["abbr"],'gid'=>$value["replace"]]));
+                    $tpl = "<MdTpl name='grammar-pop' tpl='grammar-pop' props='{$props}'></MdTpl>";
+                    $mean = str_ireplace($value["abbr"],$tpl,$mean);
                 }
             }
-
         }
         return $mean;
     }