index.php
15.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
ini_set("display_errors",1);
session_start();
require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/proofreading/simple_html_dom.php');
$service_path = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/cache/all_language/';
if (!isset($_SESSION['is_login']) || $_SESSION['is_login'] != 1) {
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/admin/plugins/proofreading/login.php';
header('Location: ' . $url);
}
$param = $_GET;
$language_form = isset($param['language']) ? $param['language'] : '';
if (!empty($language_form)) {
$change_language = $service_path . $language_form . '_proofreading.json';
// echo $change_language;
$change_language_content = [];
if (!empty($language_form) && file_exists($change_language)) {
$all_language = file_get_contents($change_language);
$all_language = !empty($all_language) ? json_decode($all_language, true) : [];
}else{
if(!file_exists($service_path."all.json")){
$arrContextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
];
$pages = explode("<br/>",file_get_contents('http://' . $_SERVER['HTTP_HOST'] . "/extend_api.php?w=66", false, stream_context_create($arrContextOptions)));
$content = [];
foreach ($pages as $url){
$html = file_get_html($url);
$es = $html->find("text");
$description = $html->find("meta[name=description]",0);
$keywords = $html->find("meta[name=keywords]",0);
if($description->content){
$content[] = $description->content;
}
if($keywords->content){
$content[] = $keywords->content;
}
foreach($es as $e){
$tag= $e->parent()->tag;
$tags = ["script","style"];
if(!in_array($tag,$tags)){
$t = trim($e->text());
if($t && strlen($t)>2){
$lanclass = method_exists($e->parent()->parent(),"find")?$e->parent()->parent()->find("b",0)->class:"";
if( $lanclass != "country-flag"){
$content[] = $t;
}
}
}
}
}
$content = array_values(array_unique($content));
file_put_contents($service_path."all.json",json_encode($content));
}else{
$content = json_decode(file_get_contents($service_path."all.json"),true);
}
//var_dump($content);exit;
$texts = [
"tls"=>[$language_form],
"texts"=>$content,
];
$texts["sl"] = "en";
$json = json_encode($texts,JSON_UNESCAPED_UNICODE);
$str = 'application/json';
$final_data = $json;
$options[ 'http' ] = array(
'timeout' => 30,
'method' => 'POST',
'header' => "Content-Type: $str;charset=utf-8",
'content' => $final_data,
);
$res = file_get_contents("http://134.73.71.2:8000/globalso_trans", false, stream_context_create($options));
$res = json_decode($res,true);
if(isset($res[0]["code"]) && $res[0]["code"] == 200){
$all_language = [];
$transcontent = $res[0]["texts"];
foreach ($content as $k=>$c){
$all_language[$c] = $transcontent[$k];
}
file_put_contents($change_language,json_encode($all_language));
}
}
//var_dump($all_language);exit;
// 分页设置
$page_size = isset($param['page_size']) ? (int)$param['page_size'] : 500; // 每页显示数量 默认为500
$page = isset($param['page']) ? (int)$param['page'] : 1;
$page_data = array_slice($all_language, ($page - 1) * $page_size, $page * $page_size);
$all_page = ceil(count($all_language) / $page_size);
}
$language = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/proofreading/json/language.json');
$language = json_decode($language, true);
$change_language = $_SERVER['DOCUMENT_ROOT'].'/uploads/json/en_' . $language_form . '_all.json';
$change_language_content = [];
if (!empty($language_form) && file_exists($change_language)) {
$change_language_content = file_get_contents($change_language);
$change_language_content = !empty($change_language_content) ? json_decode($change_language_content, true) : [];
}
?>
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta name="screen-orientation" content="portrait">
<meta name="x5-orientation" content="portrait">
<meta name="full-screen" content="yes">
<meta name="x5-fullscreen" content="true">
<meta name="browsermode" content="application">
<meta name="x5-page-mode" content="app">
<title></title>
<link rel="stylesheet" type="text/css" href="/wp-content/plugins/proofreading/resource/css/global.css">
<link rel="stylesheet" type="text/css" href="/wp-content/plugins/proofreading/resource/css/pages.css">
</head>
<style>
.add_ai_content_left {
width: 100%;
}
</style>
<body>
<div class="sys-page">
<div class="ai-biz-panel ai-biz-list" style="height:83px">
<div class="search_select_wrap" style="margin:20px 0 0 20px;">
<!-- <input type="text" class="search_text" placeholder="请输入Email进行精准挖掘" data-text="email">-->
<form action="#" method="get">
<div class="select_inner">
<div class="title"><span>请选择语言</span></div>
<div class="content">
<button type="button" data-text="请选择语言">请选择语言</button>
<!--<button type="button" data-text="phone">Phone</button> -->
</div>
</div>
<select name="language" id="" class="search_text select-box" data-text="language">
<option value="0">请选择需要校对的语言</option>
<?php
foreach ($language as $item) {
$is_selected = $item["short"] == $language_form ? 'selected' : '';
echo '<option value="' . $item['short'] . '" ' . $is_selected . '>' . $item['chinese'] . '</option>';
}
?>
</select>
<button class="search_btn" type="submit">
确认
</button>
</form>
</div>
</div>
<div class="ai-biz-panel ai-biz-list ">
<div class="ai-trade-panel add_ai_content">
<div class="add_ai_content_left">
<div class="add_ai_content_left_title">
<div class="panel-col-hd">
<i class="col-hd-ico hd-ico-user hd-ico-user_add"></i>
<h3 class="col-hd-title">编辑校对内容</h3>
</div>
</div>
<div class="information_items nav_information_items">
<ul class="nav_information_items_wrap loading" style="overflow: scroll;">
<?php
$table_html = '';
if (count($page_data) > 0) {
$table_list = '';
foreach ($page_data as $key => $value) {
$is_change = in_array($key, array_keys($change_language_content));
$color = $is_change ? 'style="color: #ff0000"' : '';
$new_value = $is_change ? $change_language_content[$key] : $value;
$table_list .= '<tr>
<td>
<textarea class="language-textarea source" rows="4" disabled>' . $key . '</textarea>
</td>
<td style="text-align: center; vertical-align: middle; width: 50px"> >> </td>
<td>
<textarea data-default-value="' . $new_value . '" class="language-textarea change_value" rows="4" ' . $color . '>' . $new_value . '</textarea>
</td>
</tr>';
}
$table_html = '<div class="form-group">
<table id="json-table" class="language-table-list">
' . $table_list . '
</table>
</div>';
echo $table_html;
}
?>
</ul>
<div id="page" class="page_btn">
<?php
if (count($page_data) > 0) {
$page_buttons = '';
// 当前页面连接
$page_url = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?language=' . $language_form . '&page_size=' . $page_size . '&page=';
// 最多显示多少个按钮
$max_buttons = 6;
// 计算开始按钮
$start_page = $all_page > $max_buttons ? ($all_page - $page >= $max_buttons ? $page + 1 : $all_page - $max_buttons + 1) : 0;
$count = 1;
for ($i = $start_page; $i <= $all_page; $i ++) {
if ($count <= $max_buttons) {
$active = $i == $page ? 'active' : '';
$page_buttons .= '<li class="page-item ' . $active . '"><a class="page-link" href="' . $page_url . $i . '">' . $i . '</a></li>';
$count ++;
}
}
// 编辑上一页按钮
$prev_page_button = '';
if ($page <= 1) {
$prev_page_button = '<li class="page-item disabled"><a class="page-link" href="#" tabindex="-1" aria-disabled="true">上一页</a></li>';
} else {
$prev_page_button = '<li class="page-item"><a class="page-link" href="' . $page_url . ($page - 1) . '">上一页</a></li>';
}
// 编辑下一页按钮
$next_page_button = '';
if ($page == $all_page) {
$next_page_button = '<li class="page-item"><a class="page-link" href="#">下一页</a></li>';
} else {
$next_page_button = '<li class="page-item"><a class="page-link" href="' . $page_url . ($page + 1) . '">下一页</a></li>';
}
// 编辑每页显示数量
$page_number_list = [200, 500, 1000, 3000, 5000];
$page_number = '<select style="border: none" data-language="' . $language_form . '" name="page_size">';
foreach ($page_number_list as $vo) {
$select = $vo == $page_size ? 'selected' : '';
$page_number .= '<option ' . $select . ' value="' . $vo . '">' . $vo . '</option>';
}
$page_number .= '</select>';
echo '<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center" style="float: left">
'. $prev_page_button . $page_buttons . $next_page_button . '
<li class="page-item"><a href="javascript:;">每页 ' . $page_number . '</a></li>
<li class="page-item"><a class="page-link" href="javascript:;">' . $page . '/' . $all_page . ' 共 ' . $all_page . ' 页</a></li>
</ul>
</nav>';
// if ($page == $all_page) {
echo '<div class="all_language_proofreading"><button class="language-submit-button" id="language-submit-button">提交校对</button></div>';
//}
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="error_tips">
<div class="wrap">演示账号无法查看具体联系方式<i class="close"></i></div>
</div>
</body>
<script src="/wp-content/plugins/proofreading/resource/js/jquery-2.1.4.min.js"></script>
<script src="/wp-content/plugins/proofreading/resource/layer/layer.js"></script>
<script>
$('select[name=page_size]').on('change', function () {
let default_url = '<?php echo 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; ?>';
let language = $(this).attr('data-language');
let page_size = $(this).find('option:selected').val();
window.location.href = default_url + '?language=' + language + '&page_size=' + page_size;
})
$('.change_value').unbind('blur').bind('blur', function () {
let language = '<?php echo $language_form ?>';
let new_string = $(this).val();
let old_string = $(this).attr('data-default-value');
let source_string = $(this).parents('tr').find('.source').val();
let ajax_data = {
'language': language,
'old_string': source_string,
'new_string': new_string
}
let that = this;
if (old_string != new_string) {
$.post('/admin/plugins/proofreading/api.php?type=change_language', ajax_data, function (result) {
result = JSON.parse(result);
if (result.status == 1) {
$(that).css('color', '#ff0000');
}
})
}
})
$('#language-submit-button').unbind('click').bind('click', function () {
let lay_index = layer.load(1, {
shade: [0.5,'#000']
});
let language = '<?php echo $language_form ?>';
$.post('/admin/plugins/proofreading/api.php?type=proofreading_all_language', {language: language}, function (result) {
layer.close(lay_index);
result = JSON.parse(result);
if (parseInt(result.status) === 1) {
layer.msg(result.msg, {icon: 1, shade: [0.3, '#393D49'], shadeClose: true, time: 1000}, function () {
$.post('/admin/plugins/proofreading/api.php?type=proofreading_success', {'language' : language})
window.open('/wp-content/cache/all/' + language);
})
} else {
layer.msg(result.msg, {icon: 5, shade: [0.3, '#393D49'], shadeClose: true, time: 1000})
}
})
})
</script>
</html>