/////////////////////////////////////////////////////////////////////////////
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('&','&',$tex);
$tex = str_replace('<','<',$tex);
// 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\">";
} else {
$output .= "$CFG->wwwroot/filter/tex/pix.php?file=$imagefile";
}
- $output .= "\" $style />";
+ $output .= "\" $style/>";
$output .= "</a>";
} else {
$output .= "Error: must pass URL or course";