global $CFG;
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
- $contents[0] = $content->content;
- $contents[1] = $content->content1;
+ if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ return false;
+ }
- $src = empty($contents[0])? '':$contents[0];
- $name = empty($contents[1])? $src:$contents[1];
+ $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
+ $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
- $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
+ if (empty($content->content)) {
+ return '';
+ }
- if ($CFG->slasharguments) {
- $source = $CFG->wwwroot.'/file.php/'.$path;
- } else {
- $source = $CFG->wwwroot.'/file.php?file=/'.$path;
- }
+ require_once($CFG->libdir.'/filelib.php');
- $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
- $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
+ $src = $content->content;
+ $name = empty($content->content1) ? $src : $content->content1;
- if (isset($contents[0])) {
- require_once($CFG->libdir.'/filelib.php');
- $icon = mimeinfo('icon', $src);
- $str = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" /> '.
- '<a href="'.$source.'/'.$src.'" >'.$name.'</a>';
- } else {
- $str = '';
- }
- return $str;
- }
- return false;
+ $source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid);
+
+ $icon = mimeinfo('icon', $src);
+ $str = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" /> '.
+ '<a href="'.$source.'/'.$src.'" >'.$name.'</a>';
+
+ return $str;
}