api.php
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
$service_path = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/proofreading/services/FileService.php';
require_once($service_path);
$service = new FileService();
$method = $_GET['type'];
// 获取当前需要翻译的文件的数据 返回到前端
if ($method == 'change_language') {
$param = $_POST;
$language = isset($param['language']) ? $param['language'] : '';
$old_string = isset($param['old_string']) ? $param['old_string'] : '';
$new_string = isset($param['new_string']) ? $param['new_string'] : '';
if (empty($language) || empty($old_string) || empty($new_string)) {
echo json_encode(['status' => 0, 'msg' => '操作失败,参数错误!']);
exit();
}
foreach($language_data['change_data'] as $k=>&$v){
if($v["type"] == "texts"){
$v['source'] = base64_decode($v['source']);
$v['new_string'] = stripslashes($v['new_string']);
}
}
$language_data = [];
$language_data['change_data'][0] = [
"type"=>"texts",
"source"=>$old_string,
"new_string"=>$new_string
];
$service->proofreading(1, '/', $language, $language_data);
//$service->changeLanguageString($language, $old_string, $new_string);
echo json_encode(['status' => 1, 'msg' => '操作成功!']);
}
if ($method == 'proofreading_all_language')
{
$param = $_POST;
$language = isset($param['language']) ? $param['language'] : '';
if (empty($language)) {
echo json_encode(['status' => 0, 'msg' => '操作失败,参数错误!']);
exit();
}
$result = $service->proofreading(3, '', $language, []);
echo $result;
exit();
}
// 校对密码
if ($method == 'login') {
$param = $_POST;
$password = isset($param['password']) ? $param['password'] : '';
if (empty($password)) {
echo json_encode(['status' => 0, '登录失败,请输入密码!']);
exit();
}
$user_password = $service->getUserConfig('password');
if ($password == $user_password) {
session_start();
$_SESSION['is_login'] = 1;
echo json_encode(['status' => 1, 'msg' => '登录成功!']);
} else {
echo json_encode(['status' => 0, 'msg' => '登录失败,请输入正确的密码!']);
}
}
// 校对成功过后 在后台执行文件上传 用户无感知
if ($method == 'proofreading_success') {
// 校对成功后 后台上传校对后的json 文件
ignore_user_abort();
set_time_limit(0);
$qiNiuService = new QiNiuService();
$pages = $qiNiuService->pages;
$param = $_POST;
$language = isset($param['language']) ? $param['language'] : '';
foreach ($pages as $key => $value) {
$json_file_name = $service->getJsonFileName($value['path'], $language);
$local_file_path = $qiNiuService->jsonPath . '/' . $json_file_name;
if (file_exists($local_file_path)) {
$content = file_get_contents($local_file_path);
if ($content != null || !empty($content)) {
$load_result = $qiNiuService->uploadFile($local_file_path);
if ($load_result) {
$qiNiuService->writeLog(3, '文件上传成功: ' . $local_file_path);
} else {
$qiNiuService->writeLog(3, '文件上传失败: ' . $local_file_path);
}
}
} else {
$qiNiuService->writeLog(3, '文件上传失败,找不到文件 == ' . $local_file_path);
}
}
}