Merge branch 'MDL-45044-master' of https://github.com/dthies/moodle

This commit is contained in:
Sam Hemelryk 2014-07-29 08:46:49 +12:00
commit 964b220c83
4 changed files with 36 additions and 17 deletions

View file

@ -94,6 +94,7 @@
if (empty($pathlatex)) { if (empty($pathlatex)) {
return false; return false;
} }
$pathlatex = escapeshellarg(trim($pathlatex, " '\""));
$doc = $this->construct_latex_document( $formula, $fontsize ); $doc = $this->construct_latex_document( $formula, $fontsize );
@ -114,15 +115,15 @@
fclose( $fh ); fclose( $fh );
// run latex on document // run latex on document
$command = "{$pathlatex} --interaction=nonstopmode --halt-on-error $tex"; $command = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
chdir( $this->temp_dir ); chdir( $this->temp_dir );
if ($this->execute($command, $log)) { // It allways False on Windows if ($this->execute($command, $log)) { // It allways False on Windows
// return false; // return false;
} }
// run dvips (.dvi to .ps) // run dvips (.dvi to .ps)
$pathdvips = get_config('filter_tex', 'pathdvips'); $pathdvips = escapeshellarg(trim(get_config('filter_tex', 'pathdvips'), " '\""));
$command = "{$pathdvips} -E $dvi -o $ps"; $command = "$pathdvips -E $dvi -o $ps";
if ($this->execute($command, $log )) { if ($this->execute($command, $log )) {
return false; return false;
} }
@ -134,11 +135,11 @@
$bg_opt = ""; $bg_opt = "";
} }
if ($convertformat == 'svg') { if ($convertformat == 'svg') {
$pathdvisvgm = get_config('filter_tex', 'pathdvisvgm'); $pathdvisvgm = escapeshellarg(trim(get_config('filter_tex', 'pathdvisvgm'), " '\""));
$command = "{$pathdvisvgm} -E $ps -o $img"; $command = "$pathdvisvgm -E $ps -o $img";
} else { } else {
$pathconvert = get_config('filter_tex', 'pathconvert'); $pathconvert = escapeshellarg(trim(get_config('filter_tex', 'pathconvert'), " '\""));
$command = "{$pathconvert} -density $density -trim $bg_opt $ps $img"; $command = "$pathconvert -density $density -trim $bg_opt $ps $img";
} }
if ($this->execute($command, $log )) { if ($this->execute($command, $log )) {
return false; return false;

View file

@ -125,9 +125,10 @@ function filter_tex_updatedcallback($name) {
return; return;
} }
$pathdvips = get_config('filter_tex', 'pathdvips'); $pathlatex = trim($pathlatex, " '\"");
$pathconvert = get_config('filter_tex', 'pathconvert'); $pathdvips = trim(get_config('filter_tex', 'pathdvips'), " '\"");
$pathdvisvgm = get_config('filter_tex', 'pathdvisvgm'); $pathconvert = trim(get_config('filter_tex', 'pathconvert'), " '\"");
$pathdvisvgm = trim(get_config('filter_tex', 'pathdvisvgm'), " '\"");
$supportedformats = array('gif'); $supportedformats = array('gif');
if ((is_file($pathlatex) && is_executable($pathlatex)) && if ((is_file($pathlatex) && is_executable($pathlatex)) &&

View file

@ -55,9 +55,22 @@ if ($ADMIN->fulltree) {
} else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') { } else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') {
// note: you need Ghostscript installed (standard), miktex (standard) // note: you need Ghostscript installed (standard), miktex (standard)
// and ImageMagick (install at c:\ImageMagick) // and ImageMagick (install at c:\ImageMagick)
$default_filter_tex_pathlatex = "\"c:\\texmf\\miktex\\bin\\latex.exe\" "; $default_filter_tex_pathlatex = "c:\\texmf\\miktex\\bin\\latex.exe";
$default_filter_tex_pathdvips = "\"c:\\texmf\\miktex\\bin\\dvips.exe\" "; $default_filter_tex_pathdvips = "c:\\texmf\\miktex\\bin\\dvips.exe";
$default_filter_tex_pathconvert = "\"c:\\imagemagick\\convert.exe\" "; $default_filter_tex_pathdvisvgm = "c:\\texmf\\miktex\\bin\\dvisvgm.exe";
$default_filter_tex_pathconvert = "c:\\imagemagick\\convert.exe";
}
$pathlatex = get_config('filter_tex', 'pathlatex');
$pathdvips = get_config('filter_tex', 'pathdvips');
$pathconvert = get_config('filter_tex', 'pathconvert');
$pathdvisvgm = get_config('filter_tex', 'pathdvisvgm');
if (strrpos($pathlatex . $pathdvips . $pathconvert . $pathdvisvgm, '"') or
strrpos($pathlatex . $pathdvips . $pathconvert . $pathdvisvgm, "'")) {
set_config('pathlatex', trim($pathlatex, " '\""), 'filter_tex');
set_config('pathdvips', trim($pathdvips, " '\""), 'filter_tex');
set_config('pathconvert', trim($pathconvert, " '\""), 'filter_tex');
set_config('pathdvisvgm', trim($pathdvisvgm, " '\""), 'filter_tex');
} }
$items[] = new admin_setting_configexecutable('filter_tex/pathlatex', get_string('pathlatex', 'filter_tex'), '', $default_filter_tex_pathlatex); $items[] = new admin_setting_configexecutable('filter_tex/pathlatex', get_string('pathlatex', 'filter_tex'), '', $default_filter_tex_pathlatex);

View file

@ -200,28 +200,28 @@
// first check if it is likely to work at all // first check if it is likely to work at all
$output .= "<h3>Checking executables</h3>\n"; $output .= "<h3>Checking executables</h3>\n";
$executablesexist = true; $executablesexist = true;
$pathlatex = get_config('filter_tex', 'pathlatex'); $pathlatex = trim(get_config('filter_tex', 'pathlatex'), " '\"");
if (is_file($pathlatex)) { if (is_file($pathlatex)) {
$output .= "latex executable ($pathlatex) is readable<br />\n"; $output .= "latex executable ($pathlatex) is readable<br />\n";
} else { } else {
$executablesexist = false; $executablesexist = false;
$output .= "<b>Error:</b> latex executable ($pathlatex) is not readable<br />\n"; $output .= "<b>Error:</b> latex executable ($pathlatex) is not readable<br />\n";
} }
$pathdvips = get_config('filter_tex', 'pathdvips'); $pathdvips = trim(get_config('filter_tex', 'pathdvips'), " '\"");
if (is_file($pathdvips)) { if (is_file($pathdvips)) {
$output .= "dvips executable ($pathdvips) is readable<br />\n"; $output .= "dvips executable ($pathdvips) is readable<br />\n";
} else { } else {
$executablesexist = false; $executablesexist = false;
$output .= "<b>Error:</b> dvips executable ($pathdvips) is not readable<br />\n"; $output .= "<b>Error:</b> dvips executable ($pathdvips) is not readable<br />\n";
} }
$pathconvert = get_config('filter_tex', 'pathconvert'); $pathconvert = trim(get_config('filter_tex', 'pathconvert'), " '\"");
if (is_file($pathconvert)) { if (is_file($pathconvert)) {
$output .= "convert executable ($pathconvert) is readable<br />\n"; $output .= "convert executable ($pathconvert) is readable<br />\n";
} else { } else {
$executablesexist = false; $executablesexist = false;
$output .= "<b>Error:</b> convert executable ($pathconvert) is not readable<br />\n"; $output .= "<b>Error:</b> convert executable ($pathconvert) is not readable<br />\n";
} }
$pathdvisvgm = get_config('filter_tex', 'pathdvisvgm'); $pathdvisvgm = trim(get_config('filter_tex', 'pathdvisvgm'), " '\"");
if (is_file($pathdvisvgm)) { if (is_file($pathdvisvgm)) {
$output .= "dvisvgm executable ($pathdvisvgm) is readable<br />\n"; $output .= "dvisvgm executable ($pathdvisvgm) is readable<br />\n";
} else { } else {
@ -252,17 +252,21 @@
chdir($latex->temp_dir); chdir($latex->temp_dir);
// step 1: latex command // step 1: latex command
$pathlatex = escapeshellarg($pathlatex);
$cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex"; $cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
$output .= execute($cmd); $output .= execute($cmd);
// step 2: dvips command // step 2: dvips command
$pathdvips = escapeshellarg($pathdvips);
$cmd = "$pathdvips -E $dvi -o $ps"; $cmd = "$pathdvips -E $dvi -o $ps";
$output .= execute($cmd); $output .= execute($cmd);
// Step 3: Set convert or dvisvgm command. // Step 3: Set convert or dvisvgm command.
if ($convertformat == 'svg') { if ($convertformat == 'svg') {
$pathdvisvgm = escapeshellarg($pathdvisvgm);
$cmd = "$pathdvisvgm -E $ps -o $img"; $cmd = "$pathdvisvgm -E $ps -o $img";
} else { } else {
$pathconvert = escapeshellarg($pathconvert);
$cmd = "$pathconvert -density 240 -trim $ps $img "; $cmd = "$pathconvert -density 240 -trim $ps $img ";
} }
$output .= execute($cmd); $output .= execute($cmd);