-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpptext-action.php
More file actions
132 lines (99 loc) · 3.34 KB
/
Copy pathpptext-action.php
File metadata and controls
132 lines (99 loc) · 3.34 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
<?php
require_once("base.inc");
list($workdir, $workurl, $upid) = init_workdir();
$extensions = ["txt", "TXT"]; // allowed file extensions
// ----- process the main project file ---------------------------------
$target_name = process_file_upload("userfile", $workdir, $extensions);
// ----- do that all again for the goodwords file, if present ------
if (@$_FILES['goodfile']["name"]) {
$gtarget_name = process_file_upload("goodfile", $workdir, $extensions);
} else {
$gtarget_name = "";
}
// ----- no errors. proceed ----------------------------------------
log_tool_access("pptext", $upid);
// ----- user has option of uploading a Latin-1 file -------------------
// main file
ensure_utf8_file($target_name);
// good words file
if ($gtarget_name) {
ensure_utf8_file($gtarget_name);
}
// ----- process user options ------------------------------------------
// aggregate user-selected tests
$available_tests = [
"rat" => "a",
"rspl" => "s",
"redi" => "e",
"rtxt" => "t",
"rthc" => "1",
"rhsc" => "2",
"rsqc" => "q",
"rjee" => "j",
];
// get user inputs & validate combinations
$utests = [];
foreach($available_tests as $key => $val) {
if(isset($_POST[$key]) && $_POST[$key] == 'Yes') {
$utests[] = $val;
}
}
// get the user's chosen language(s)
$wlangs = $_POST['wlangs'] ?? [];
// see if user has ticked the "verbose" box
$verbose = isset($_POST['ver']) && $_POST['ver'] == 'Yes';
// skip spellcheck if dependent tests weren't selected
$skip_aspell = !in_array("a", $utests) && !in_array("s", $utests) && !in_array("e", $utests);
if (!$skip_aspell && count($wlangs) == 0) {
echo "Please select at least one language when using spellcheck or edit distance check. Exiting.";
exit(1);
}
$options = [];
$options[] = "-a " . escapeshellarg(join(",", $wlangs));
$options[] = "-t " . escapeshellarg(join("", $utests));
// user wants verbose output
if ($verbose) {
$options[] = " -v ";
}
// if spellcheck wasn't requested, explicitly skip it with -s
if ($skip_aspell) {
$options[] = " -s ";
}
// include good words file if present
if ($gtarget_name) {
$options[] = "-g " . escapeshellarg($gtarget_name);
}
// ----- run the pptext command ----------------------------------------
// build the command
$command = join(" ", [
"nice",
"$base_codedir/bin/pptext/pptext",
join(" ", $options),
"-i " . escapeshellarg($target_name),
"-o " . escapeshellarg($workdir),
"2>&1",
]);
log_tool_action($workdir, "command", $command);
// and finally, run pptext
$output = shell_exec($command);
log_tool_action($workdir, "output", $output);
// ----- display results -------------------------------------------
output_header("pptext Results");
$reportok = false;
echo "<p>";
if (file_exists("$workdir/report.html")) {
echo "results available: <a href='$workurl/report.html'>here</a>.<br>";
$reportok = true;
}
if (file_exists("$workdir/scanreport.txt")) {
echo "punctuation scan report: <a href='$workurl/scanreport.txt'>here</a>.<br>";
$reportok = true;
}
if ($reportok) {
echo "Left click to view. Right click to download.</p>";
} else {
echo "<p>Whoops! Something went wrong and no output was generated.
The error message was<br><br>
<tt>$output</tt></p>
</p>For more assistance, ask in the <a href='$help_url'>discussion topic</a> and include this identifier: $upid</p>";
}