api.php
6.7 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
require dirname(__FILE__) . '/services/FileService.php';
$service = new FileService();
$method = $_GET['type'];
function unescape ($source){
$decodedStr = "";
$pos = 0;
$len = strlen ($source);
while ($pos < $len){
$charAt = substr ($source, $pos, 1);
if ($charAt == '%'){
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == 'u'){
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$entity = "&#". $unicode . ';';
$decodedStr .= utf8_encode ($entity);
$pos += 4;
}else{
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
}else{
$decodedStr .= $charAt;
$pos++;
}
}
return $decodedStr;
}
// 获取当前需要翻译的文件的数据 返回到前端
if ($method == 'get_json') {
$param = $_POST;
$result = $service->getLanguageJson($param['path'], $param['language'],$param['t']);
echo $result;
}
if($method == "get_user_language"){
$user_language_path = dirname(__FILE__) . '/json/user_language.json';
if (file_exists($user_language_path)) {
$user_language = file_get_contents(dirname(__FILE__) . '/json/user_language.json');
} else {
$user_language ="[]";
}
echo $user_language;
}
// 提交校对
if ($method == 'proofreading') {
$param = $_POST;
$type = isset($param['status']) ? intval($param['status']) : 1;
$path = isset($param['path']) ? $param['path'] : '';
$language = isset($param['language']) ? $param['language'] : '';
$language_data = isset($param['language_data']) ? $param['language_data'] : [];
if (empty($path) || empty($language) || count($language_data) <= 0) {
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']);
}
}
$result = $service->proofreading($type, $path, $language, $language_data);
echo $result;
}
// 校对成功过后 在后台执行文件上传 用户无感知
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);
}
}
}
// 用户选择语言操作
if ($method == 'chooseLanguage') {
$param = $_POST;
$language_all = isset($param['language_all']) ? $param['language_all'] : [];
$language_choose = isset($param['language_choose']) ? $param['language_choose'] : [];
$link_type = isset($param['link_type']) ? $param['link_type'] : 1;
$is_start = isset($param['is_start']) ? (int)$param['is_start'] : 2;
$is_open_customer_proofreading = isset($param['is_open_customer_proofreading']) ? (int)$param['is_open_customer_proofreading'] : 2;
$service->getUserConfig('link_type', $link_type);
$service->getUserConfig('is_start', $is_start);
$service->getUserConfig('is_open_customer_proofreading', $is_open_customer_proofreading);
if (empty($language_all)) {
echo json_encode(['status' => 0, 'msg' => '操作失败!']);
}
$result = $service->chooseLanguage($language_all, $language_choose);
echo $result;
}
// 修改或者编辑校对页面登录米面
if ($method == 'changePassword') {
$param = $_POST;
$password = isset($param['password']) ? $param['password'] : '';
if (empty($password) || strlen($password) < 6) {
echo json_encode(['status' => 1, 'msg' => '密码长度必须大于登录6位!']);
}
$service->getUserConfig('password', $password);
echo json_encode(['status' => 1, 'msg' => '密码修改成功!']);
}
// 清除page缓存
if ($method === 'clearPagesCache') {
$page_path = $service->pagesFilePath;
$service->deleteDir($service->allLanguageFilePath);
unlink($page_path);
echo json_encode(['status' => 1, 'msg' => '缓存清除成功!']);
}
// 清除page备份
if ($method === 'clearPFilebak') {
$param = $_POST;
if(!$param['path']){
die(json_encode(['status' => 1, 'msg' => '选择一个页面']));
}
if($param["language"]){
$json_file_name = $service->getJsonFileName($param['path'], $param["language"]);
// echo $json_file_name;
$local_file_path = $qiNiuService->jsonPath . '/' . $json_file_name;
$qiNiuService = new QiNiuService();
$qiNiuService->deleteFile($local_file_path);
echo json_encode(['status' => 1, 'msg' => '缓存清除成功!']);
}else{
$user_language_path = dirname(__FILE__) . '/json/user_language.json';
if (file_exists($user_language_path)) {
$user_language = json_decode(file_get_contents(dirname(__FILE__) . '/json/user_language.json'));
} else {
$user_language =[];
}
foreach($user_language as $k=>$v){
$json_file_name = $service->getJsonFileName($param['path'], $v->short);
$local_file_path = $qiNiuService->jsonPath . '/' . $json_file_name;
$qiNiuService = new QiNiuService();
$qiNiuService->deleteFile($local_file_path);
}
echo json_encode(['status' => 1, 'msg' => '备份清除成功!']);
}
}