From 1dfbf846f8db71ab8ce9a38b31ea6c64f7b9f48e Mon Sep 17 00:00:00 2001 From: dongsheng <dongsheng> Date: Wed, 16 Apr 2008 02:46:03 +0000 Subject: [PATCH] MDL-14320, improve coding style, thanks Petr, merged from MOODLE_19_STABLE --- mod/data/field/file/field.class.php | 42 +++++++++++++---------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index 25bbd14f34..8cbb4cb5ef 100755 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -97,35 +97,29 @@ class data_field_file extends data_field_base { 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; } -- 2.39.5