-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.php
67 lines (59 loc) · 1.89 KB
/
index.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
<?php
namespace CMH\Multilingual;
use ExternalModules\AbstractExternalModule;
use ExternalModules\ExternalModules;
$data = @$_POST['data'];
if(isset($data) && $data != ''){
$data = json_decode($data, true);
if ($data['action'] == 'SAVE_SURVEY_SETTINGS' && $data['payload']) {
$module->saveSurveySettings($data['payload']);
} else if ($data['action'] == 'GET_SURVEY_SETTINGS') {
$module->getSurveySettings($data);
}
switch($data['todo']){
case 1:
$module->getTranslations($data, $module->getProjectSettings());
break;
case 2:
$module->getAnswers($data);
break;
case 3:
$module->getSettings($data);
break;
case 4:
$module->getSavedLang($data);
break;
default:
exit;
}
}
elseif($_GET['todo'] == 2){
$module->exportData($_GET['pid'], $_GET['lang']);
}
elseif ($iso_code = $_GET['translate_settings_iso_code']) {
$response = new \stdClass();
/* NEVER DO THE FOLLOWING -- UNSAFE AGAINST PATH TRAVERSAL ATTACKS */
// $translations_filepath = $module->getModulePath() . "/def_translations/$iso_code.txt";
/* getSafePath PREVENTS PATH TRAVERSAL ATTACKS */
$translations_filepath = $module->getSafePath("/def_translations/$iso_code.txt");
if (!file_exists($translations_filepath)) {
$response->error = "Couldn't find translations for language with ISO code $iso_code";
} else {
$file_contents = file_get_contents($translations_filepath);
$translations = [];
$file_lines = preg_split('/\n|\r\n?/', $file_contents);
foreach ($file_lines as $i => $line) {
$translations[$i] = $line;
}
if (!empty($translations)) {
$response->success = true;
$response->translations = $translations;
}
}
header('Content-Type: application/json; charset=UTF-8');
exit(json_encode($response));
}
else{
header("HTTP/1.0 404 Not Found");
}
?>