-
Notifications
You must be signed in to change notification settings - Fork 1
/
editpo.php
350 lines (313 loc) · 11.7 KB
/
editpo.php
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
<?php
/**
* Copyright (C) 2004-2006 Jarno Elonen <[email protected]>
* Copyright (C) 2015-2018 Agentcobra <[email protected]>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
require_once("config.inc.php");
require_once("utils.inc.php");
require_once("poparse.inc.php");
require_once("htpasswd.inc.php");
forceNoCache();
// Remember the password
if (isset($_POST["pass"])) {
setcookie("editpo_pass", $_POST["pass"]);
} else {
if (isset($_COOKIE["editpo_pass"])) {
$_POST["pass"] = $_COOKIE["editpo_pass"];
}
}
$filename = trim($_GET["file"]);
// Take extra care not to open a security hole with
// user-passed file names.
$rp = realpath($filename);
if (!is_string($rp) ||
strpos(realpath($filename), realpath('po/')) !== 0 ||
!preg_match('/^po\\/[^.\\/]+\\/[^\\/]+[.]po$/', $filename) ||
strpos($filename, '..') !== false) {
die("Non-allowed filename; only the PO files in the correct directory are accepted.");
}
$dir = preg_replace('/\\/[^\\/]*$/', '', $filename);
$user = preg_replace('/^.*\\//', '', $dir);
$red_color = "FF6060";
$blue_color = "9090FF";
$yellow_color = "F0F000";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>'<?php print_encoded($filename); ?>' - PHPPOEdit</title>
<!--
これはUTF-8 としてこのファイルを確認するためにソフトウェアを助ける模造のテキストである。
Tämä on testitekstiä, joka toivottavasti auttaa ohjelmia tunnistamaan tekstin UTF8:ksi.
This is some test text that hopefully helps browsers to detect this as UTF8.
-->
</head>
<body>
<h1>Edit '<?php print_encoded($filename); ?>'</h1>
<?php
/**
* @param $post_key
* @return string
*/
function strip_post($post_key)
{
global $_POST;
return stripslashes(str_replace("\r", "", $_POST[$post_key]));
}
/**
* @param $txt
* @return array
*/
function explode_nl($txt)
{
if (strlen($txt)) {
return explode("\n", $txt);
} else {
return array();
}
}
/**
* @param $post_key
* @return array
*/
function explode_post($post_key)
{
return explode_nl(strip_post($post_key));
}
if (isset($_POST["save"])) {
$pass_array = load_htpasswd();
$error = false;
if (!isset($_POST["pass"])) {
$error = "No password given!";
} else {
if (!isset($pass_array[$user])) {
$error = sprintf("No such username '%s'", $user);
} else {
if (!test_htpasswd($pass_array, $user, $_POST["pass"])) {
$error = sprintf("Incorrect password for user '%s'", $user);
}
}
}
if ($error !== false) {
printf("<strong>%s</strong>", htmlentities($error));
print "<br>Click 'back' and try again.";
die;
}
$ids = array();
foreach ($_POST as $k => $v) {
if (substr($k, 0, 5) == "msgid") {
$ids[] = preg_replace('/^.*_/', '', $k);
}
}
$entries = array();
foreach ($ids as $k => $v) {
$flags = preg_split('/[ ,]+/', $_POST["otherflags_$v"], -1, PREG_SPLIT_NO_EMPTY);
if (!in_array('fuzzy', $flags) && isset($_POST["fuzzy_$v"]) && $_POST["fuzzy_$v"]) {
$flags[] = "fuzzy";
}
$entries[] = array(
"comments" => explode_post("comments_$v"),
"autocomments" => explode_nl(base64_decode($_POST["autocomments_$v"])),
"sources" => explode_nl(base64_decode($_POST["sources_$v"])),
"flags" => $flags,
"msgid" => base64_decode($_POST["msgid_$v"]),
"msgstr" => strip_post("msgstr_$v")
);
}
$new_file = unparse_po($entries);
$error = false;
if (!is_writable($filename)) {
$error = $error = "File is not writable ($filename)";
} else {
if (!$fp = fopen($filename, 'w')) {
$error = "Cannot open file ($filename)";
} else {
if (fwrite($fp, $new_file) === false) {
$error = "Cannot write to file ($filename)";
}
}
}
if ($error !== false) {
printf("The file could not be written: '%s'.<br />" .
"This is a bug in system configuration. Please report.", $error);
die;
}
fclose($fp);
?>
<div style="height: 100%; border: 1px gray dotted; color: green;">
<strong>Modifications saved.</strong>
</div>
<?php
}
?>
<p>
<a href="./">Back to main page</a>
</p>
<div style="border: 1px gray dotted;">
<table>
<tr>
<td colspan="2"><strong>Legend:</strong></td>
</tr>
<tr>
<td width="16" style="background: #<?php print $blue_color ?>;"> </td>
<td>completed translation</td>
</tr>
<tr>
<td width="16" style="background: #<?php print $red_color ?>;"> </td>
<td>missing translation</td>
</tr>
<tr>
<td width="16" style="background: #<?php print $yellow_color ?>;"> </td>
<td>fuzzy/uncertain translation (e.g. automatically translated)</td>
</tr>
</table>
<div class="alert alert-info" role="alert">
NOTE! This system <em>requires</em> UTF-8 character encoding.
If you don't see some Japanese text here: "日本語",
adjust your browser settings.
</div>
</div>
<p></p>
<?php
if (strpos($filename, "../") !== false || $filename[0] == "/" || !preg_match('/.*[.]po$/', $filename)) {
print '<strong>Forbidden</strong>';
die;
}
$parsed = parse_po(file($filename));
/**
* @param $entry_id
* @param $label
* @param $content
* @param $http_parm
* @param $rows
* @param $force
* @param $propo
*/
function print_field_if_nonempty($entry_id, $label, $content, $http_parm, $rows, $force, $propo)
{
if (is_array($content)) {
$content = join("\n", $content);
}
if ($force || strlen($content)) {
?>
<tr>
<td><strong><?php print_encoded($label); ?></strong></td>
<?php
if ($propo) {
print "<td>";
} else {
print "<td style='background: #E0E0E0;'>";
}
if ($rows > 0) {
printf('<textarea wrap="off" cols="60" rows="%d" name="%s_%s">%s</textarea>' . "\n", $rows, $http_parm,
$entry_id, xhtml_encode($content));
} else {
printf('<input type="hidden" name="%s_%s" value="%s">' . "\n", $http_parm, $entry_id,
base64_encode($content));
if ($propo) {
print nl2br(xhtml_encode($content));
} else {
print "<code>" . nl2br(xhtml_encode($content)) . "</code>";
}
}
?></td>
</tr>
<?php
}
}
?>
<div class="alert alert-info" role="alert">
TRANSLATIONS: NOTE! You can ignore the first box (translation info, meta data etc).
</div>
<form action="<?php echo htmlentities($_SERVER["REQUEST_URI"]); ?>" method="post">
<input type="hidden" name="save" value="1">
<?php
foreach ($parsed as $checksum => $e) {
$flags = $e["flags"];
$fuzzy = (in_array('fuzzy', $e["flags"]));
foreach ($flags as $k => $v) {
if ($v == "fuzzy") {
unset($flags[$k]);
}
}
$bgcolor = $red_color;
if (strlen($e["msgstr"])) {
$bgcolor = $blue_color;
}
if ($fuzzy) {
$bgcolor = $yellow_color;
}
print "<table style='background: #$bgcolor;' border='1'>\n";
print_field_if_nonempty($checksum, "from", $e["sources"], "sources", 0, false, true);
print_field_if_nonempty($checksum, "note", $e["autocomments"], "autocomments", 0, false, true);
if ($e["msgid"] == "") {
print "<input type='hidden' name='msgid_$checksum' value=''>\n";
print_field_if_nonempty($checksum, "translation info", $e["comments"], "comments", 6, true, true);
print_field_if_nonempty($checksum, "meta data", $e["msgstr"], "msgstr", 6, true, false);
} else {
print_field_if_nonempty($checksum, "text", $e["msgid"], "msgid", 0, false, false);
print_field_if_nonempty($checksum, "translation", $e["msgstr"], "msgstr", 6, true, false);
print_field_if_nonempty($checksum, "comments", $e["comments"], "comments", 2, true, true);
}
?>
<tr>
<td><strong>flags</strong></td>
<td><?php
if (count($flags)) {
print join(", ", $flags) . ", ";
}
printf('<input type="hidden" name="otherflags_%s" value="%s">' . "\n", $checksum,
numeric_html_encode(join(", ", $flags)));
?>
<input type="checkbox" value="1" id="fuzzy_<?php print $checksum; ?>"
name="fuzzy_<?php print $checksum; ?>" <?php if ($fuzzy) {
print "checked";
} ?>> <label for="fuzzy_<?php print $checksum; ?>">fuzzy</label>
</td>
</tr>
<?php
print "</table>\n";
}
?>
<label for="pass">Password (for user '<?php print htmlentities($user); ?>'):</label><input type="password"
value="<?php if (isset($_POST["pass"])) {
print $_POST["pass"];
} ?>" name="pass"
id="pass"/><br/>
<input type="submit" class="btn btn-primary" value="Save all">
</form>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</body>
</html>