]> git.mjollnir.org Git - moodle.git/commitdiff
tex filter: MDL-18230 ensure we always generate valid XHTML.
authortjhunt <tjhunt>
Tue, 17 Feb 2009 05:24:41 +0000 (05:24 +0000)
committertjhunt <tjhunt>
Tue, 17 Feb 2009 05:24:41 +0000 (05:24 +0000)
filter/tex/filter.php

index 54cbe8acc0c7bb184b15503dec5ed71313054e34..01ee633d77edba4992e34722067f56730b0cc591 100644 (file)
 /////////////////////////////////////////////////////////////////////////////
 
 function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle", $alt='') {
-    if($alt==='') {
-        $alt=s($tex);
-    }
-    // Given the path to a picture file in a course, or a URL,
-    // this function includes the picture in the page.
     global $CFG;
 
-    $output = "";
-    $origtex = $tex;
+    if ($alt==='') {
+        $alt = s($tex);
+    }
+
+    // Work out any necessary inline style.
+    $rules = array();
     if ($align !== 'middle') {
-        $style = ' style="vertical-align:'.$align.';';
-    } else {
-        $style = '';
+        $rules[] = 'vertical-align:' . $align . ';';
     }
     if ($height) {
-        $style .= " height:{$height}px;";
+        $rules[] = 'height:' . $height . 'px;';
     }
     if ($width) {
-        $style .= " width:{$width}px;";
+        $rules[] = 'width:' . $width . 'px;';
     }
-    $style .= '"';
+    if (!empty($rules)) {
+        $style = ' style="' . implode('', $rules) . '" ';
+    } else {
+        $style = '';
+    }
+
+    // Prepare the title attribute.
     if ($tex) {
         $tex = str_replace('&','&amp;',$tex);
         $tex = str_replace('<','&lt;',$tex);
@@ -71,6 +74,9 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
         // code. 
         $title = "title=\"$tex\"";
     }
+
+    // Build the output.
+    $output = "";
     if ($imagefile) {
         if (!file_exists("$CFG->dataroot/filter/tex/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
           $output .= "<a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">";
@@ -87,7 +93,7 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
         } else {
             $output .= "$CFG->wwwroot/filter/tex/pix.php?file=$imagefile";
         }
-        $output .= "\" $style />";
+        $output .= "\" $style/>";
         $output .= "</a>";
     } else {
         $output .= "Error: must pass URL or course";