From d7e3f044c19ac2455626b602f57442da8ea75f0d Mon Sep 17 00:00:00 2001 From: fiedorow Date: Thu, 10 Feb 2005 22:19:08 +0000 Subject: [PATCH] various improvements: better debugging, image positioning, XHTML validation --- filter/algebra/algebradebug.php | 26 ++++++++++++++++++++++++++ filter/algebra/filter.php | 16 ++++++++++++---- filter/algebra/pix.php | 8 ++++---- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/filter/algebra/algebradebug.php b/filter/algebra/algebradebug.php index ea2f2e15e78..5ce4826d839 100644 --- a/filter/algebra/algebradebug.php +++ b/filter/algebra/algebradebug.php @@ -90,9 +90,35 @@ function algebra2tex($algebra) { if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) { $algebra = "\"". str_replace('"','\"',$algebra) . "\""; + $cmd = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl x/2"; + $test = `$cmd`; + if ($test != '\frac{x}{2}') { + echo "There is a problem with either Perl or the script algebra2tex.pl
"; + $ecmd = $cmd . " 2>&1"; + echo `$ecmd` . "
\n"; + echo "The shell command
$cmd
returned status = $status
\n"; + $commandpath = "$CFG->dirroot\\$CFG->algebrafilterdirwin\\algebra2tex.pl"; + if (file_exists($commandpath)) { + echo "The file permissions of algebra2tex.pl are: " . decoct(fileperms($commandpath)) . "
"; + } + die; + } $cmd = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl $algebra"; } else { $algebra = escapeshellarg($algebra); + $cmd = "cd $CFG->dirroot/$CFG->algebrafilterdir; ./algebra2tex.pl x/2"; + $test = `$cmd`; + if ($test != '\frac{x}{2}') { + echo "There is a problem with either Perl or the script algebra2tex.pl
"; + $ecmd = $cmd . " 2>&1"; + echo `$ecmd` . "
\n"; + echo "The shell command
$cmd
returned status = $status
\n"; + $commandpath = "$CFG->dirroot/$CFG->algebrafilterdir/algebra2tex.pl"; + if (file_exists($commandpath)) { + echo "The file permissions of algebra2tex.pl are: " . decoct(fileperms($commandpath)) . "
"; + } + die; + } $cmd = "cd $CFG->dirroot/$CFG->algebrafilterdir; ./algebra2tex.pl $algebra"; } $texexp = `$cmd`; diff --git a/filter/algebra/filter.php b/filter/algebra/filter.php index 450fb5aabe3..c3aef2d0e77 100644 --- a/filter/algebra/filter.php +++ b/filter/algebra/filter.php @@ -46,7 +46,7 @@ $CFG->algebrafilterdirwin = "filter\\algebra"; } -function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="") { +function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="", $align="middle") { // Given the path to a picture file in a course, or a URL, // this function includes the picture in the page. global $CFG; @@ -72,7 +72,7 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="" } else { $output .= "wwwroot/$CFG->texfilterdir/displaytex.php?"; - $output .= urlencode($tex) . "\" onClick=\"return openpopup('/$CFG->texfilterdir/displaytex.php?"; + $output .= urlencode($tex) . "\" onclick=\"return openpopup('/$CFG->texfilterdir/displaytex.php?"; $output .= urlencode($tex) . "', 'popup', 'menubar=0,location=0,scrollbars,"; $output .= "resizable,width=300,height=240', 0);\">"; } @@ -82,7 +82,7 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="" } else { $output .= "$CFG->wwwroot/$CFG->algebrafilterdir/pix.php?file=$imagefile"; } - $output .= "\" />"; + $output .= "\" style=\"vertical-align:$align\" />"; $output .= ""; } else { $output .= "Error: must pass URL or course"; @@ -136,6 +136,14 @@ function algebra_filter ($courseid, $text) { $algebra = $matches[1][$i] . $matches[2][$i]; $algebra = str_replace('','',$algebra); $algebra = str_replace('','',$algebra); + $align = "middle"; + if (preg_match('/^align=bottom /',$algebra)) { + $align = "text-bottom"; + $algebra = preg_replace('/^align=bottom /','',$algebra); + } else if (preg_match('/^align=top /',$algebra)) { + $align = "text-top"; + $algebra = preg_replace('/^align=top /','',$algebra); + } $md5 = md5($algebra); $filename = $md5 . ".gif"; if (! $texcache = get_record("cache_filters","filter","algebra", "md5key", $md5)) { @@ -221,7 +229,7 @@ function algebra_filter ($courseid, $text) { $texcache->rawtext = addslashes($texexp); $texcache->timemodified = time(); insert_record("cache_filters",$texcache); - $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp), $text); + $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp, '', '', $align), $text); } else { $text = str_replace( $matches[0][$i],"Undetermined error: ",$text); } diff --git a/filter/algebra/pix.php b/filter/algebra/pix.php index e70fd3afcab..67d9d9b133e 100644 --- a/filter/algebra/pix.php +++ b/filter/algebra/pix.php @@ -46,20 +46,20 @@ $texexp = str_replace('"','\"',$texexp); $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe"; $cmd = str_replace(' ','^ ',$cmd); - $cmd .= " ++ -e \"$pathname\" \"$texexp\""; + $cmd .= " ++ -e \"$pathname\" -- \"$texexp\""; } else if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { /// Use the custom binary - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp); + $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- ". escapeshellarg($texexp); } else { /// Auto-detect the right TeX binary switch (PHP_OS) { case "Linux": - $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp); + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- ". escapeshellarg($texexp); break; case "Darwin": - $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp); + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- ". escapeshellarg($texexp); break; default: /// Nothing was found, so tell them how to fix it.