Merge remote-tracking branch 'origin/master' into akun
正在显示
5 个修改的文件
包含
326 行增加
和
56 行删除
| @@ -11,6 +11,7 @@ use App\Models\Inquiry\InquiryFormData; | @@ -11,6 +11,7 @@ use App\Models\Inquiry\InquiryFormData; | ||
| 11 | use App\Models\Nav\BNav; | 11 | use App\Models\Nav\BNav; |
| 12 | use App\Models\Nav\BNavGroup; | 12 | use App\Models\Nav\BNavGroup; |
| 13 | use App\Models\Project\Project; | 13 | use App\Models\Project\Project; |
| 14 | +use App\Models\WebSetting\Translate as TranslateModel; | ||
| 14 | use App\Services\ProjectServer; | 15 | use App\Services\ProjectServer; |
| 15 | use Illuminate\Console\Command; | 16 | use Illuminate\Console\Command; |
| 16 | use Illuminate\Database\Eloquent\Model; | 17 | use Illuminate\Database\Eloquent\Model; |
| @@ -54,6 +55,24 @@ class Test extends Command | @@ -54,6 +55,24 @@ class Test extends Command | ||
| 54 | */ | 55 | */ |
| 55 | public function handle() | 56 | public function handle() |
| 56 | { | 57 | { |
| 58 | + ProjectServer::useProject(3); | ||
| 59 | + $data = [ | ||
| 60 | + 'c' => 'c', | ||
| 61 | + 'b' => 'a', | ||
| 62 | + 'a' => 'b', | ||
| 63 | + 'e' => 'e', | ||
| 64 | + ]; | ||
| 65 | + $param = [ | ||
| 66 | + 'type'=>1, | ||
| 67 | + 'project_id'=>3, | ||
| 68 | + 'url'=>'/', | ||
| 69 | + 'language_id'=>2, | ||
| 70 | + 'alias'=>'zh', | ||
| 71 | + ]; | ||
| 72 | + $param['data'] = json_encode($data,true); | ||
| 73 | + TranslateModel::insert($param); | ||
| 74 | + dd('end'); | ||
| 75 | + $this->model->add($param); | ||
| 57 | ProjectServer::useProject(1); | 76 | ProjectServer::useProject(1); |
| 58 | $group =BNavGroup::where(['id' => 1])->first(); | 77 | $group =BNavGroup::where(['id' => 1])->first(); |
| 59 | $sort_list = json_decode($group->sort_list, true); | 78 | $sort_list = json_decode($group->sort_list, true); |
app/Console/Commands/TranslateRead.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :TranslateRead.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/1/17 16:47 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands; | ||
| 11 | + | ||
| 12 | +use App\Models\Project\Project; | ||
| 13 | +use App\Services\ProjectServer; | ||
| 14 | +use Illuminate\Console\Command; | ||
| 15 | +use Illuminate\Support\Facades\DB; | ||
| 16 | + | ||
| 17 | +class TranslateRead extends Command | ||
| 18 | +{ | ||
| 19 | + /** | ||
| 20 | + * The name and signature of the console command. | ||
| 21 | + * | ||
| 22 | + * @var string | ||
| 23 | + */ | ||
| 24 | + protected $signature = 'translate_read'; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * The console command description. | ||
| 28 | + * | ||
| 29 | + * @var string | ||
| 30 | + */ | ||
| 31 | + protected $description = '生成视频模块'; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * @remark :统一更新路由 | ||
| 35 | + * @name :handle | ||
| 36 | + * @author :lyh | ||
| 37 | + * @method :post | ||
| 38 | + * @time :2023/11/20 15:13 | ||
| 39 | + */ | ||
| 40 | + public function handle(){ | ||
| 41 | + $projectModel = new Project(); | ||
| 42 | + $list = $projectModel->list(['type'=>['!=',0]]); | ||
| 43 | + foreach ($list as $v){ | ||
| 44 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 45 | + ProjectServer::useProject($v['id']); | ||
| 46 | + DB::disconnect('custom_mysql'); | ||
| 47 | + } | ||
| 48 | + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public function read(){ | ||
| 52 | + | ||
| 53 | + } | ||
| 54 | +} |
| @@ -12,8 +12,14 @@ namespace App\Http\Controllers\Bside\Setting; | @@ -12,8 +12,14 @@ namespace App\Http\Controllers\Bside\Setting; | ||
| 12 | use App\Enums\Common\Code; | 12 | use App\Enums\Common\Code; |
| 13 | use App\Http\Controllers\Bside\BaseController; | 13 | use App\Http\Controllers\Bside\BaseController; |
| 14 | use App\Http\Logic\Bside\Setting\TranslateLogic; | 14 | use App\Http\Logic\Bside\Setting\TranslateLogic; |
| 15 | +use App\Models\Blog\Blog; | ||
| 16 | +use App\Models\CustomModule\CustomModuleCategory; | ||
| 17 | +use App\Models\CustomModule\CustomModuleContent; | ||
| 18 | +use App\Models\News\News; | ||
| 19 | +use App\Models\Product\Product; | ||
| 15 | use App\Models\Project\Project; | 20 | use App\Models\Project\Project; |
| 16 | use App\Models\RouteMap\RouteMap; | 21 | use App\Models\RouteMap\RouteMap; |
| 22 | +use App\Models\WebSetting\SettingNum; | ||
| 17 | use App\Models\WebSetting\WebLanguage; | 23 | use App\Models\WebSetting\WebLanguage; |
| 18 | 24 | ||
| 19 | class TranslateController extends BaseController | 25 | class TranslateController extends BaseController |
| @@ -91,55 +97,210 @@ class TranslateController extends BaseController | @@ -91,55 +97,210 @@ class TranslateController extends BaseController | ||
| 91 | * @time :2024/1/12 14:34 | 97 | * @time :2024/1/12 14:34 |
| 92 | */ | 98 | */ |
| 93 | public function getUrl(){ | 99 | public function getUrl(){ |
| 100 | + //查看项目是5.0还是6.0 | ||
| 101 | + if($this->user['is_upgrade'] == Project::IS_UPGRADE_TRUE){//升级项目 | ||
| 102 | + $data = $this->getFiveUrl($this->map); | ||
| 103 | + }else { | ||
| 104 | + $data = $this->getSixUrl($this->map); | ||
| 105 | + } | ||
| 106 | + $this->response('success',Code::SUCCESS,$data); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * @remark :5.0路由 | ||
| 111 | + * @name :getFiveUrl | ||
| 112 | + * @author :lyh | ||
| 113 | + * @method :post | ||
| 114 | + * @time :2024/1/17 16:27 | ||
| 115 | + */ | ||
| 116 | + public function getFiveUrl($map){ | ||
| 94 | $data = []; | 117 | $data = []; |
| 95 | $routeMapModel = new RouteMap(); | 118 | $routeMapModel = new RouteMap(); |
| 96 | - $list = $routeMapModel->list(); | 119 | + $list = $routeMapModel->list($map); |
| 97 | foreach ($list as $k => $v){ | 120 | foreach ($list as $k => $v){ |
| 98 | - //查看项目是5.0还是6.0 | ||
| 99 | - if($this->user['is_upgrade'] == Project::IS_UPGRADE_TRUE){//升级项目 | ||
| 100 | - if(!empty($v['path'])){ | ||
| 101 | - if($v['path'] == 'blog'){ | ||
| 102 | - $v['path'] = $v['path'].'s'; | ||
| 103 | - } | ||
| 104 | - $route = $v['path'].'/'.$v['route']; | ||
| 105 | - }else{ | 121 | + switch ($v['source']){ |
| 122 | + case RouteMap::SOURCE_PAGE: | ||
| 106 | if($v['route'] == 'index'){ | 123 | if($v['route'] == 'index'){ |
| 107 | - $v['route'] = ''; | 124 | + $data[] = '/'; |
| 125 | + }else{ | ||
| 126 | + $data[] = $v['route']; | ||
| 108 | } | 127 | } |
| 109 | - $route = $v['route']; | ||
| 110 | - } | ||
| 111 | - }else{ | ||
| 112 | - if(!empty($v['path'])){ | ||
| 113 | - if($v['path'] == 'blog'){ | ||
| 114 | - $v['path'] = $v['path'].'s'; | ||
| 115 | - }elseif ($v['path'] == RouteMap::PATH_NEWS_CATE){ | ||
| 116 | - $routeMapModel->edit(['path'=>''],['id'=>$v['id']]); | ||
| 117 | - $v['path'] = ''; | ||
| 118 | - }elseif ($v['path'] == RouteMap::PATH_NEWS_CATE){ | ||
| 119 | - $routeMapModel->edit(['path'=>''],['id'=>$v['id']]); | ||
| 120 | - $v['path'] = ''; | 128 | + break; |
| 129 | + case RouteMap::SOURCE_PRODUCT_CATE: | ||
| 130 | + //获取当前产品分类关联多少产品 | ||
| 131 | + $productModel = new Product(); | ||
| 132 | + $count = $productModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 133 | + $this->pageList($data,$count,$v,1,15); | ||
| 134 | + break; | ||
| 135 | + case RouteMap::SOURCE_BLOG: | ||
| 136 | + $data[] = 'blogs/'.$v['route']; | ||
| 137 | + break; | ||
| 138 | + case RouteMap::SOURCE_NEWS: | ||
| 139 | + $data[] = 'news/'.$v['route']; | ||
| 140 | + break; | ||
| 141 | + case RouteMap::SOURCE_BLOG_CATE: | ||
| 142 | + $blogModel = new Blog(); | ||
| 143 | + $count = $blogModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 144 | + $this->pageList($data,$count,$v,2,10); | ||
| 145 | + break; | ||
| 146 | + case RouteMap::SOURCE_NEWS_CATE: | ||
| 147 | + $newsModel = new News(); | ||
| 148 | + $count = $newsModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 149 | + $this->pageList($data,$count,$v,3,10); | ||
| 150 | + break; | ||
| 151 | + case RouteMap::SOURCE_MODULE: | ||
| 152 | + $customModel = new CustomModuleContent(); | ||
| 153 | + $contentInfo = $customModel->read(['id'=>$v['source_id']]); | ||
| 154 | + if(!empty($contentInfo) && !empty($contentInfo['category_id'])){ | ||
| 155 | + $categoryIdArr = $contentInfo['category_id']; | ||
| 156 | + $cate_id = (int)array_shift($categoryIdArr); | ||
| 157 | + $routeInfo = $routeMapModel->read(['source'=>RouteMap::SOURCE_MODULE_CATE,'source_id'=>$cate_id]); | ||
| 158 | + $v['path'] = ($routeInfo['route'] ?? ''); | ||
| 159 | + if(!empty($v['path'])){ | ||
| 160 | + $v['path'] = $v['path'].'/'; | ||
| 161 | + } | ||
| 121 | } | 162 | } |
| 122 | - $route = $v['path'].'/'.$v['route']; | ||
| 123 | - }else{ | 163 | + $data[] = $v['path'].$v['route']; |
| 164 | + break; | ||
| 165 | + case RouteMap::SOURCE_MODULE_CATE: | ||
| 166 | + $customModel = new CustomModuleContent(); | ||
| 167 | + $count = $customModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 168 | + $this->pageSixList($data,$count,$v,3,10); | ||
| 169 | + break; | ||
| 170 | + default: | ||
| 171 | + $data[] = $v['route']; | ||
| 172 | + break; | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + return $this->success($data); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + /** | ||
| 179 | + * @remark :获取6.0的url | ||
| 180 | + * @name :getSixUrl | ||
| 181 | + * @author :lyh | ||
| 182 | + * @method :post | ||
| 183 | + * @time :2024/1/17 15:04 | ||
| 184 | + */ | ||
| 185 | + public function getSixUrl($map){ | ||
| 186 | + $data = []; | ||
| 187 | + $routeMapModel = new RouteMap(); | ||
| 188 | + $list = $routeMapModel->list($map); | ||
| 189 | + foreach ($list as $k => $v){ | ||
| 190 | + switch ($v['source']){ | ||
| 191 | + case RouteMap::SOURCE_PAGE: | ||
| 124 | if($v['route'] == 'index'){ | 192 | if($v['route'] == 'index'){ |
| 125 | - $v['route'] = ''; | 193 | + $data[] = '/';//首页 |
| 194 | + }else{ | ||
| 195 | + $data[] = $v['route']; | ||
| 196 | + } | ||
| 197 | + break; | ||
| 198 | + case RouteMap::SOURCE_PRODUCT_CATE: | ||
| 199 | + //获取当前产品分类关联多少产品 | ||
| 200 | + $productModel = new Product(); | ||
| 201 | + $count = $productModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 202 | + $this->pageSixList($data,$count,$v,1,15); | ||
| 203 | + break; | ||
| 204 | + case RouteMap::SOURCE_BLOG: | ||
| 205 | + $data[] = 'blogs/'.$v['route']; | ||
| 206 | + break; | ||
| 207 | + case RouteMap::SOURCE_NEWS: | ||
| 208 | + $data[] = 'news/'.$v['route']; | ||
| 209 | + break; | ||
| 210 | + case RouteMap::SOURCE_BLOG_CATE: | ||
| 211 | + $blogModel = new Blog(); | ||
| 212 | + $count = $blogModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 213 | + $this->pageSixList($data,$count,$v,2,10); | ||
| 214 | + break; | ||
| 215 | + case RouteMap::SOURCE_NEWS_CATE: | ||
| 216 | + $newsModel = new News(); | ||
| 217 | + $count = $newsModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 218 | + $this->pageSixList($data,$count,$v,3,10); | ||
| 219 | + break; | ||
| 220 | + case RouteMap::SOURCE_MODULE: | ||
| 221 | + $customModel = new CustomModuleContent(); | ||
| 222 | + $contentInfo = $customModel->read(['id'=>$v['source_id']]); | ||
| 223 | + if(!empty($contentInfo) && !empty($contentInfo['category_id'])){ | ||
| 224 | + $categoryIdArr = $contentInfo['category_id']; | ||
| 225 | + $cate_id = (int)array_shift($categoryIdArr); | ||
| 226 | + $routeInfo = $routeMapModel->read(['source'=>RouteMap::SOURCE_MODULE_CATE,'source_id'=>$cate_id]); | ||
| 227 | + $v['path'] = ($routeInfo['route'] ?? ''); | ||
| 228 | + if(!empty($v['path'])){ | ||
| 229 | + $v['path'] = $v['path'].'/'; | ||
| 230 | + } | ||
| 126 | } | 231 | } |
| 127 | - $route = $v['route']; | ||
| 128 | - } | 232 | + $data[] = $v['path'].$v['route']; |
| 233 | + break; | ||
| 234 | + case RouteMap::SOURCE_MODULE_CATE: | ||
| 235 | + $customModel = new CustomModuleContent(); | ||
| 236 | + $count = $customModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%']])->count(); | ||
| 237 | + $this->pageSixList($data,$count,$v,3,10); | ||
| 238 | + break; | ||
| 239 | + default: | ||
| 240 | + $data[] = $v['route']; | ||
| 241 | + break; | ||
| 129 | } | 242 | } |
| 130 | } | 243 | } |
| 131 | - $data[] = $this->user['domain'].$route; | ||
| 132 | - $this->response('success',Code::SUCCESS,$data); | 244 | + return $this->success($data); |
| 133 | } | 245 | } |
| 134 | 246 | ||
| 135 | /** | 247 | /** |
| 136 | - * @remark :获取路由表中没有的路由 | ||
| 137 | - * @name :getFiveUrl | 248 | + * @remark : |
| 249 | + * @name :pageList | ||
| 138 | * @author :lyh | 250 | * @author :lyh |
| 139 | * @method :post | 251 | * @method :post |
| 140 | - * @time :2024/1/17 9:32 | 252 | + * @time :2024/1/17 14:15 |
| 141 | */ | 253 | */ |
| 142 | - public function getFiveUrl($v){ | 254 | + public function pageList(&$data,$count,$v,$type = 1,$pageNum = 15){ |
| 255 | + $page = 1; | ||
| 256 | + if($count != 0){ | ||
| 257 | + //获取默认条数 | ||
| 258 | + $settingNumModel = new SettingNum(); | ||
| 259 | + $numInfo = $settingNumModel->read(['type'=>$type],['num']); | ||
| 260 | + if(!empty($numInfo)){ | ||
| 261 | + $pageNum = $numInfo['num']; | ||
| 262 | + }else{ | ||
| 263 | + $pageNum = $pageNum; | ||
| 264 | + } | ||
| 265 | + $page = ceil($count / $pageNum);//向上取整 | ||
| 266 | + } | ||
| 267 | + for ($i = 1;$i <= $page;$i++){ | ||
| 268 | + if($i == 1){ | ||
| 269 | + $data[] = $v['route']; | ||
| 270 | + }else{ | ||
| 271 | + $data[] = $v['route'].'/page/'.$i; | ||
| 272 | + } | ||
| 273 | + } | ||
| 274 | + return true; | ||
| 275 | + } | ||
| 143 | 276 | ||
| 277 | + /** | ||
| 278 | + * @remark : | ||
| 279 | + * @name :pageList | ||
| 280 | + * @author :lyh | ||
| 281 | + * @method :post | ||
| 282 | + * @time :2024/1/17 14:15 | ||
| 283 | + */ | ||
| 284 | + public function pageSixList(&$data,$count,$v,$type = 1,$pageNum = 15){ | ||
| 285 | + $page = 1; | ||
| 286 | + if($count != 0){ | ||
| 287 | + //获取默认条数 | ||
| 288 | + $settingNumModel = new SettingNum(); | ||
| 289 | + $numInfo = $settingNumModel->read(['type'=>$type],['num']); | ||
| 290 | + if(!empty($numInfo)){ | ||
| 291 | + $pageNum = $numInfo['num']; | ||
| 292 | + }else{ | ||
| 293 | + $pageNum = $pageNum; | ||
| 294 | + } | ||
| 295 | + $page = ceil($count / $pageNum);//向上取整 | ||
| 296 | + } | ||
| 297 | + for ($i = 1;$i <= $page;$i++){ | ||
| 298 | + if($i == 1){ | ||
| 299 | + $data[] = $v['route']; | ||
| 300 | + }else{ | ||
| 301 | + $data[] = $v['route'].'/'.$i; | ||
| 302 | + } | ||
| 303 | + } | ||
| 304 | + return true; | ||
| 144 | } | 305 | } |
| 145 | } | 306 | } |
| @@ -116,7 +116,7 @@ class CustomModuleLogic extends BaseLogic | @@ -116,7 +116,7 @@ class CustomModuleLogic extends BaseLogic | ||
| 116 | public function checkIsName($name,$id = 0){ | 116 | public function checkIsName($name,$id = 0){ |
| 117 | $param['name'] = $name; | 117 | $param['name'] = $name; |
| 118 | if(!empty($id)){ | 118 | if(!empty($id)){ |
| 119 | - $param['id'] = ['id'=>['!=',$id]]; | 119 | + $param['id'] = ['!=',$id]; |
| 120 | } | 120 | } |
| 121 | $info = (new CustomModule())->read($param); | 121 | $info = (new CustomModule())->read($param); |
| 122 | if($info !== false){ | 122 | if($info !== false){ |
| @@ -9,13 +9,10 @@ | @@ -9,13 +9,10 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Http\Logic\Bside\Setting; | 10 | namespace App\Http\Logic\Bside\Setting; |
| 11 | 11 | ||
| 12 | -use App\Enums\Common\Code; | ||
| 13 | use App\Http\Logic\Bside\BaseLogic; | 12 | use App\Http\Logic\Bside\BaseLogic; |
| 14 | -use App\Models\WebSetting\Proofreading; | ||
| 15 | use App\Models\WebSetting\Translate as TranslateModel; | 13 | use App\Models\WebSetting\Translate as TranslateModel; |
| 16 | use App\Models\WebSetting\WebLanguage; | 14 | use App\Models\WebSetting\WebLanguage; |
| 17 | use App\Helper\Translate; | 15 | use App\Helper\Translate; |
| 18 | -use Illuminate\Support\Facades\DB; | ||
| 19 | 16 | ||
| 20 | class TranslateLogic extends BaseLogic | 17 | class TranslateLogic extends BaseLogic |
| 21 | { | 18 | { |
| @@ -34,12 +31,23 @@ class TranslateLogic extends BaseLogic | @@ -34,12 +31,23 @@ class TranslateLogic extends BaseLogic | ||
| 34 | * @time :2024/1/12 9:43 | 31 | * @time :2024/1/12 9:43 |
| 35 | */ | 32 | */ |
| 36 | public function getTranslateList(){ | 33 | public function getTranslateList(){ |
| 34 | + $data = []; | ||
| 35 | + if($this->param['url'] == 'All'){ | ||
| 36 | + $info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | ||
| 37 | + if(!empty($info) && !empty($info['data'])){ | ||
| 38 | + $translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE); | ||
| 39 | + foreach ($translateInfo as $k => $v){ | ||
| 40 | + $data[] = [$k=>$v]; | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + return $this->success($data); | ||
| 44 | + } | ||
| 45 | + $url = $this->user['domain'].(($this->param['url'] != '/') ? $this->param['url'] : ''); | ||
| 37 | $languageInfo = $this->getLanguage($this->param['language_id']); | 46 | $languageInfo = $this->getLanguage($this->param['language_id']); |
| 38 | - $info = $this->model->read(['url'=>str_replace_url($this->param['url']),'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | 47 | + $info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); |
| 39 | //获取当前URl的所有文本内容 | 48 | //获取当前URl的所有文本内容 |
| 40 | - $new_key = $this->getUrlRead($this->param['url']); | 49 | + $new_key = $this->getUrlRead($url); |
| 41 | if($info === false){ | 50 | if($info === false){ |
| 42 | - $data = []; | ||
| 43 | $translate_list = Translate::tran($new_key, $languageInfo['short']); | 51 | $translate_list = Translate::tran($new_key, $languageInfo['short']); |
| 44 | foreach ($new_key as $k=>$v){ | 52 | foreach ($new_key as $k=>$v){ |
| 45 | $data[] = [ | 53 | $data[] = [ |
| @@ -49,20 +57,27 @@ class TranslateLogic extends BaseLogic | @@ -49,20 +57,27 @@ class TranslateLogic extends BaseLogic | ||
| 49 | return $this->success($data); | 57 | return $this->success($data); |
| 50 | } | 58 | } |
| 51 | $old_key = [];//key值组成数据 | 59 | $old_key = [];//key值组成数据 |
| 52 | - $data = json_decode($info['data'],true); | ||
| 53 | - foreach ($data as $k => $v){ | 60 | + $data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE); |
| 61 | + foreach ($data_read as $k => $v){ | ||
| 54 | $old_key[] = $k; | 62 | $old_key[] = $k; |
| 63 | + $data[] = [$k => $v]; | ||
| 55 | } | 64 | } |
| 56 | $arr2 = array_values(array_diff($new_key, $old_key)); | 65 | $arr2 = array_values(array_diff($new_key, $old_key)); |
| 57 | if(!empty($arr2)){ | 66 | if(!empty($arr2)){ |
| 58 | $translate_list = Translate::tran($arr2, $languageInfo['short']); | 67 | $translate_list = Translate::tran($arr2, $languageInfo['short']); |
| 59 | - foreach ($arr2 as $k1=>$v1){ | 68 | + if(count($arr2) == 1){ |
| 60 | $data[] = [ | 69 | $data[] = [ |
| 61 | - trim($v1)=>$translate_list[$k1] | 70 | + $arr2[0]=>$translate_list |
| 62 | ]; | 71 | ]; |
| 72 | + }else{ | ||
| 73 | + foreach ($arr2 as $k => $v){ | ||
| 74 | + $data[] = [ | ||
| 75 | + trim($v)=>$translate_list[$k] | ||
| 76 | + ]; | ||
| 77 | + } | ||
| 63 | } | 78 | } |
| 64 | } | 79 | } |
| 65 | - $this->success($data); | 80 | + return $this->success($data); |
| 66 | } | 81 | } |
| 67 | 82 | ||
| 68 | /** | 83 | /** |
| @@ -73,10 +88,22 @@ class TranslateLogic extends BaseLogic | @@ -73,10 +88,22 @@ class TranslateLogic extends BaseLogic | ||
| 73 | * @time :2023/11/23 17:29 | 88 | * @time :2023/11/23 17:29 |
| 74 | */ | 89 | */ |
| 75 | public function getTranslateImageList(){ | 90 | public function getTranslateImageList(){ |
| 91 | + if($this->param['url'] == 'All'){ | ||
| 92 | + $info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | ||
| 93 | + $data = []; | ||
| 94 | + if(!empty($info) && !empty($info['data'])){ | ||
| 95 | + $translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE); | ||
| 96 | + foreach ($translateInfo as $k => $v){ | ||
| 97 | + $data[] = [$k=>$v]; | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + return $this->success($data); | ||
| 101 | + } | ||
| 102 | + $url = $this->user['domain'].(($this->param['url'] != '/') ? $this->param['url'] : ''); | ||
| 76 | $info = $this->model->read(['url'=>str_replace_url($this->param['url']),'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | 103 | $info = $this->model->read(['url'=>str_replace_url($this->param['url']),'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); |
| 77 | $data = []; | 104 | $data = []; |
| 78 | if($info === false){ | 105 | if($info === false){ |
| 79 | - $new_list = $this->getUrlImageRead($this->param['url']); | 106 | + $new_list = $this->getUrlImageRead($url); |
| 80 | foreach ($new_list as $v){ | 107 | foreach ($new_list as $v){ |
| 81 | $data[] = [ | 108 | $data[] = [ |
| 82 | $v=>$v, | 109 | $v=>$v, |
| @@ -84,11 +111,11 @@ class TranslateLogic extends BaseLogic | @@ -84,11 +111,11 @@ class TranslateLogic extends BaseLogic | ||
| 84 | } | 111 | } |
| 85 | return $this->success($data); | 112 | return $this->success($data); |
| 86 | } | 113 | } |
| 87 | - $new_list = $this->getUrlImageRead($this->param['url']); | 114 | + $new_list = $this->getUrlImageRead($url); |
| 88 | $old_list = []; | 115 | $old_list = []; |
| 89 | - $data = json_decode($info['data'],true); | ||
| 90 | - foreach ($data as $k=>$v){ | ||
| 91 | - $old_list[] = $v; | 116 | + $data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE); |
| 117 | + foreach ($data_read as $k=>$v){ | ||
| 118 | + $old_list[] = $k; | ||
| 92 | $data[] = [ | 119 | $data[] = [ |
| 93 | $k=>$v, | 120 | $k=>$v, |
| 94 | ]; | 121 | ]; |
| @@ -136,6 +163,9 @@ class TranslateLogic extends BaseLogic | @@ -136,6 +163,9 @@ class TranslateLogic extends BaseLogic | ||
| 136 | ]; | 163 | ]; |
| 137 | $context = stream_context_create($contextOptions); | 164 | $context = stream_context_create($contextOptions); |
| 138 | $sourceCode = file_get_contents($url, false, $context); | 165 | $sourceCode = file_get_contents($url, false, $context); |
| 166 | + if(!$sourceCode){ | ||
| 167 | + $this->fail('当前url不存在'); | ||
| 168 | + } | ||
| 139 | // 过滤掉具有 "change-language-cont" 类的元素 | 169 | // 过滤掉具有 "change-language-cont" 类的元素 |
| 140 | $pattern = '/<div\b[^>]*\sclass=[\'"]([^\'"]*change-language-cont[^\'"]*)[\'"][^>]*>(.*?)<\/div>/is'; | 170 | $pattern = '/<div\b[^>]*\sclass=[\'"]([^\'"]*change-language-cont[^\'"]*)[\'"][^>]*>(.*?)<\/div>/is'; |
| 141 | $sourceCode = preg_replace($pattern, '', $sourceCode); | 171 | $sourceCode = preg_replace($pattern, '', $sourceCode); |
| @@ -151,19 +181,25 @@ class TranslateLogic extends BaseLogic | @@ -151,19 +181,25 @@ class TranslateLogic extends BaseLogic | ||
| 151 | $textContentArray = array_filter($matches[1], function($item) { | 181 | $textContentArray = array_filter($matches[1], function($item) { |
| 152 | return !empty(trim($item)); | 182 | return !empty(trim($item)); |
| 153 | }); | 183 | }); |
| 184 | + // 过滤掉包含逗号加换行的内容 | ||
| 185 | + $textContentArray = array_filter($textContentArray, function($item) { | ||
| 186 | + return strpos($item, ',') === false && strpos($item, PHP_EOL) === false; | ||
| 187 | + }); | ||
| 154 | $contentData = []; | 188 | $contentData = []; |
| 155 | foreach ($textContentArray as $v){ | 189 | foreach ($textContentArray as $v){ |
| 156 | $content = trim($v); | 190 | $content = trim($v); |
| 157 | $trimmedString = preg_replace('/\s+/', ' ', $content); | 191 | $trimmedString = preg_replace('/\s+/', ' ', $content); |
| 158 | $contentData[] = $trimmedString; | 192 | $contentData[] = $trimmedString; |
| 159 | } | 193 | } |
| 160 | - $contentData = array_values($contentData); | ||
| 161 | - $pattern = '/<meta\s+[^>]*name=[\'"](keywords|description)[\'"][^>]*content=[\'"]([^\'"]+)[\'"]/i'; // 匹配 name 为 "keywords" 或 "description" 的 meta 标签的正则表达式 | 194 | + $contentData = array_values($textContentArray); |
| 195 | + $pattern = '/<meta\s+[^>]*name=[\'"](keywords|description)[\'"][^>]*content=[\'"]([^\'"]+)[\'"]>/i'; // 匹配 name 为 "keywords" 或 "description" 的 meta 标签的正则表达式 | ||
| 162 | $matches = array(); | 196 | $matches = array(); |
| 163 | preg_match_all($pattern, $strippedContent, $matches); | 197 | preg_match_all($pattern, $strippedContent, $matches); |
| 164 | $metaData = array(); | 198 | $metaData = array(); |
| 165 | foreach ($matches[2] as $index => $content) { | 199 | foreach ($matches[2] as $index => $content) { |
| 166 | - $metaData[] = $content; | 200 | + if(!empty(trim($content))){ |
| 201 | + $metaData[] = $content; | ||
| 202 | + } | ||
| 167 | } | 203 | } |
| 168 | $data = array_merge($metaData, $contentData); | 204 | $data = array_merge($metaData, $contentData); |
| 169 | return $data; | 205 | return $data; |
| @@ -212,16 +248,16 @@ class TranslateLogic extends BaseLogic | @@ -212,16 +248,16 @@ class TranslateLogic extends BaseLogic | ||
| 212 | $info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]); | 248 | $info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]); |
| 213 | if($info === false){ | 249 | if($info === false){ |
| 214 | $param = [ | 250 | $param = [ |
| 215 | - 'type'=>1, | 251 | + 'type'=>$this->param['type'], |
| 216 | 'project_id'=>$this->user['project_id'], | 252 | 'project_id'=>$this->user['project_id'], |
| 217 | 'url'=>str_replace_url($this->param['url']), | 253 | 'url'=>str_replace_url($this->param['url']), |
| 218 | 'language_id'=>$this->param['language_id'], | 254 | 'language_id'=>$this->param['language_id'], |
| 219 | 'alias'=>$this->param['alias'], | 255 | 'alias'=>$this->param['alias'], |
| 220 | ]; | 256 | ]; |
| 221 | - $param['data'] = json_encode($this->param['data'],true); | 257 | + $param['data'] = json_encode($this->param['data'],JSON_UNESCAPED_UNICODE); |
| 222 | $this->model->add($param); | 258 | $this->model->add($param); |
| 223 | }else{ | 259 | }else{ |
| 224 | - $data = json_encode($this->param['data'],true); | 260 | + $data = json_encode($this->param['data'],JSON_UNESCAPED_UNICODE); |
| 225 | $this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]); | 261 | $this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]); |
| 226 | } | 262 | } |
| 227 | // }catch (\Exception $e){ | 263 | // }catch (\Exception $e){ |
-
请 注册 或 登录 后发表评论