Skip to content

Commit

Permalink
filelib MDL-19707 Converted existing ...str_replace('png','gif')... t…
Browse files Browse the repository at this point in the history
…o use file_extension_icon and file_mimetype_icon
  • Loading branch information
samhemelryk committed Jul 7, 2009
1 parent 0578e8e commit 19c9f09
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 45 deletions.
3 changes: 1 addition & 2 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ function blog_print_attachments($blogentry, $return=NULL) {
$filename = $file->get_filename();
$ffurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/'.$blogentry->id.'/'.$filename);
$type = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type("icon", $type));
$type = mimeinfo_from_type("type", $type);

$image = "<img src=\"" . $OUTPUT->old_icon_url('f/' . $icon) . "\" class=\"icon\" alt=\"\" />";
$image = "<img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($type)) . "\" class=\"icon\" alt=\"\" />";

if ($return == "html") {
$output .= "<a href=\"$ffurl\">$image</a> ";
Expand Down
4 changes: 2 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,9 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
if (!empty($customicon)) {
if (substr($customicon, 0, 4) === 'mod/') {
list($modname, $iconname) = explode('/', substr($customicon, 4), 2);
$icon = $OUTPUT->mod_icon_url(str_replace(array('.gif', '.png'), '', $iconname), $modname);
$icon = $OUTPUT->mod_icon_url(file_extension_icon($iconname), $modname);
} else {
$icon = $OUTPUT->old_icon_url(str_replace(array('.gif', '.png'), '', $customicon));
$icon = $OUTPUT->old_icon_url(file_extension_icon($customicon));
}
} else {
$icon = "" . $OUTPUT->mod_icon_url('icon', $mod->modname) . "";
Expand Down
3 changes: 1 addition & 2 deletions files/draftfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@
}

} else {
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$viewurl = file_encode_url("$CFG->wwwroot/draftfile.php", "/$contextid/user_draft/$itemid".$filepath.$filename, false, false);
echo '<div class="file">';
echo "<a href=\"$viewurl\"><img src=\"" . $OUTPUT->old_icon_url('f/' . $icon) . "\" class=\"icon\" alt=\"$strfile\" />&nbsp;".s($filename)." ($filesize)</a> ";
echo "<a href=\"$viewurl\"><img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . "\" class=\"icon\" alt=\"$strfile\" />&nbsp;".s($filename)." ($filesize)</a> ";
echo "<a href=\"draftfiles.php?itemid=$itemid&amp;filepath=$filepath&amp;delete=$filenameurl&amp;subdirs=$subdirs&amp;maxbytes=$maxbytes\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"$strdelete\" /></a>";;
echo '</div>';
}
Expand Down
3 changes: 1 addition & 2 deletions files/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ function displaydir($file_info) {

} else {

$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type("icon", $mimetype));
if ($downloadurl = $child_info->get_url(true)) {
$downloadurl = "&nbsp;<a href=\"$downloadurl\" title=\"" . get_string('downloadfile') . "\"><img src=\"" . $OUTPUT->old_icon_url('t/down') . "\" class=\"iconsmall\" alt=\"$strdownload\" /></a>";
} else {
Expand All @@ -314,7 +313,7 @@ function displaydir($file_info) {

echo "<tr class=\"file\">";
print_cell();
print_cell("left", "<img src=\"" . $OUTPUT->old_icon_url('f/' . $icon) . "\" class=\"icon\" alt=\"$strfile\" />&nbsp;".s($filename).$downloadurl.$viewurl, 'name');
print_cell("left", "<img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . "\" class=\"icon\" alt=\"$strfile\" />&nbsp;".s($filename).$downloadurl.$viewurl, 'name');
print_cell("right", $filesize, 'size');
print_cell("right", $filedate, 'date');
if ($parentwritable) {
Expand Down
3 changes: 1 addition & 2 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1779,9 +1779,8 @@ function print_user_files($userid=0, $return=false) {
$filename = $file->get_filename();
$found = true;
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" class="icon" alt="'.$icon.'" />'.s($filename).'</a>';
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()));
$button->set_formats(portfolio_format_from_file($file));
Expand Down
9 changes: 3 additions & 6 deletions mod/assignment/type/upload/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,8 @@ function print_student_answer($userid, $return=false){
$filename = $file->get_filename();
$found = true;
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->old_icon_url('f/'.$icon).'" alt="'.$icon.'" />'.s($filename).'</a>&nbsp;';
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.s($filename).'</a>&nbsp;';

}

Expand Down Expand Up @@ -346,9 +345,8 @@ function print_user_files($userid=0, $return=false) {
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" class="icon" alt="'.$icon.'" />'.s($filename).'</a>';
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';

if ($candelete) {
$delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&amp;file=".rawurlencode($filename)."&amp;userid={$submission->userid}&amp;mode=$mode&amp;offset=$offset";
Expand Down Expand Up @@ -408,10 +406,9 @@ function print_responsefiles($userid, $return=false) {
$filename = $file->get_filename();
$found = true;
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_response/'.$userid.'/'.$filename);

$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" alt="'.$icon.'" />'.$filename.'</a>';
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.$filename.'</a>';

if ($candelete) {
$delurl = "$CFG->wwwroot/mod/assignment/delete.php?id={$this->cm->id}&amp;file=".rawurlencode($filename)."&amp;userid=$userid&amp;mode=$mode&amp;offset=$offset&amp;action=response";
Expand Down
3 changes: 1 addition & 2 deletions mod/assignment/type/uploadsingle/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ function print_student_answer($userid, $return=false){
$filename = $file->get_filename();
$found = true;
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->old_icon_url('f/'.$icon).'" alt="'.$icon.'" />'.s($filename).'</a><br />';
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.s($filename).'</a><br />';
}
}

Expand Down
6 changes: 2 additions & 4 deletions mod/data/field/file/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ function display_add_field($recordid=0) {
if ($file) {
// Print icon if file already exists
$browser = get_file_browser();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $file->get_mimetype()));
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', $this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
$str .= '<img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" class="icon" alt="'.$icon.'" />'.
$str .= '<img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($file->get_mimetype())).'" class="icon" alt="'.$file->get_mimetype().'" />'.
'<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
}
return $str;
Expand Down Expand Up @@ -118,12 +117,11 @@ function display_browse_field($recordid, $template) {
}

$name = empty($content->content1) ? $file->get_filename() : $content->content1;
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $file->get_mimetype()));
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
$height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';

$str = '<img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" height="16" width="16" alt="'.$icon.'" />&nbsp;'.
$str = '<img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($file->get_mimetype())).'" height="16" width="16" alt="'.$file->get_mimetype().'" />&nbsp;'.
'<a href="'.$src.'" >'.s($name).'</a>';
return $str;
}
Expand Down
3 changes: 1 addition & 2 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4296,8 +4296,7 @@ function forum_print_attachments($post, $cm, $type) {
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$iconimage = '<img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" class="icon" alt="'.$icon.'" />';
$iconimage = '<img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/forum_attachment/'.$post->id.'/'.$filename);

if ($type == 'html') {
Expand Down
3 changes: 1 addition & 2 deletions mod/glossary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,8 +1256,7 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$icon = str_replace(array('.gif', '.png'), '', mimeinfo_from_type('icon', $mimetype));
$iconimage = '<img src="'.$OUTPUT->old_icon_url('f/'.$icon).'" class="icon" alt="'.$icon.'" />';
$iconimage = '<img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/glossary_attachment/'.$entry->id.'/'.$filename);

if ($type == 'html') {
Expand Down
4 changes: 2 additions & 2 deletions mod/resource/type/directory/resource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function display() {
$filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file"));

} else {
$icon = str_replace(array('.gif', '.png'), '', mimeinfo("icon", $file));
$icon = file_extension_icon($file);
$relativeurl = get_file_url("$relativepath/$file");
$filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file"));
}
Expand All @@ -134,7 +134,7 @@ function display() {
} else {
echo '<tr class="file">';
echo '<td class="name">';
link_to_popup_window($relativeurl, "resourcedirectory{$resource->id}", "<img src=\"" . $OUTPUT->old_icon_url('f/' . $icon) . "\" class=\"icon\" alt=\"$strfile\" />&nbsp;$file", 450, 600, '');
link_to_popup_window($relativeurl, "resourcedirectory{$resource->id}", "<img src=\"" . $OUTPUT->old_icon_url($icon) . "\" class=\"icon\" alt=\"$strfile\" />&nbsp;$file", 450, 600, '');
}
echo '</td>';
echo '<td>&nbsp;</td>';
Expand Down
3 changes: 1 addition & 2 deletions mod/wiki/ewiki/plugins/moodle/downloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ function ewiki_entry_downloads($row, $show_section=0, $fullinfo=false) {

/// Moodle Icon Handling
global $CFG;
$icon = str_replace(array('.gif', '.png'), '', mimeinfo("icon", $id));
$p_icon = $OUTPUT->old_icon_url('f/' . $icon);
$p_icon = $OUTPUT->old_icon_url(file_extension_icon($id));
$p_icon_t = '';

$info->id = $id;
Expand Down
5 changes: 2 additions & 3 deletions question/contextmove_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class question_context_move_form extends moodleform {

function definition() {
global $CFG. $OUTPUT;
global $CFG, $OUTPUT;
$mform =& $this->_form;

//--------------------------------------------------------------------------------
Expand All @@ -25,9 +25,8 @@ function definition() {

$i = 0;
foreach (array_keys($urls) as $url){
$iconname = str_replace(array('.gif', '.png'), '', mimeinfo('icon', $url));
$icontype = mimeinfo('type', $url);
$img = "<img src=\"" . $OUTPUT->old_icon_url('f/' . $iconname) . "\" class=\"icon\" alt=\"$icontype\" />";
$img = "<img src=\"" . $OUTPUT->old_icon_url(file_extension_icon($url)) . "\" class=\"icon\" alt=\"$icontype\" />";
if (in_array($url, $brokenurls)){
$mform->addElement('select', "urls[$i]", $img.$url, $brokenfileoptions);
} else {
Expand Down
3 changes: 1 addition & 2 deletions question/contextmoveq_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ function definition() {

$i = 0;
foreach (array_keys($urls) as $url){
$iconname = str_replace(array('.gif', '.png'), '', mimeinfo('icon', $url));
$icontype = mimeinfo('type', $url);
$img = "<img src=\"" . $OUTPUT->old_icon_url('f/$iconname') . "\" class=\"icon\" alt=\"$icontype\" />";
$img = "<img src=\"" . $OUTPUT->old_icon_url(file_extension_icon($url)) . "\" class=\"icon\" alt=\"$icontype\" />";
if (in_array($url, $brokenurls)){
$mform->addElement('select', "urls[$i]", $img.$url, $brokenfileoptions);
} else {
Expand Down
2 changes: 1 addition & 1 deletion repository/alfresco/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function get_listing($uuid = '', $path = '') {
'children'=>array());
} elseif ($child->child->type == $file_filter) {
$ret['list'][] = array('title'=>$child->child->cm_name,
'thumbnail' => $OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $child->child->cm_name))),
'thumbnail' => $OUTPUT->old_icon_url(file_extension_icon($child->child->cm_name, 32)),
'source'=>$child->child->id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion repository/boxnet/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function search($search_text) {
'date'=>$filedates[$n],
'source'=>'http://box.net/api/1.0/download/'
.$this->auth_token.'/'.$fileids[$n],
'thumbnail'=>$OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $v))));
'thumbnail' => $OUTPUT->old_icon_url(file_extension_icon($v, 32)));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion repository/filesystem/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function get_listing($path = '', $page = '') {
'source' => $path.'/'.$file,
'size' => filesize($this->root_path.$file),
'date' => time(),
'thumbnail' => $OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $this->root_path.$file)))
'thumbnail' => $OUTPUT->old_icon_url(file_extension_icon($this->root_path.$file, 32))
);
} else {
if (!empty($path)) {
Expand Down
4 changes: 2 additions & 2 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public static function move_to_filepool($path, $name, $itemid, $filearea = 'user
return array('url'=>$ret->get_url(),
'id'=>$file->get_itemid(),
'file'=>$file->get_filename(),
'icon'=>$OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $path)))
'icon' => $OUTPUT->old_icon_url(file_extension_icon($path, 32))
);
} else {
return null;
Expand Down Expand Up @@ -960,7 +960,7 @@ public static function build_tree($fileinfo, $search, $dynamicmode, &$list) {
'date' => $filedate,
//'source' => $child->get_url(),
'source' => base64_encode($source),
'thumbnail' => $OUTPUT->old_icon_url('f/'. str_replace(array('.gif', '.png'), '', mimeinfo('icon32', $filename)))
'thumbnail'=>$OUTPUT->old_icon_url(file_extension_icon($filename, 32)),
);
$filecount++;
}
Expand Down
2 changes: 1 addition & 1 deletion repository/mahara/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function get_listing($path = null, $page = 1, $search = '') {
if ($file['artefacttype'] == 'image') {
$thumbnail = $host->wwwroot."/artefact/file/download.php?file=".$file['id']."&size=70x55";
} else {
$thumbnail = $OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $file['title'])));
$thumbnail = $OUTPUT->old_icon_url(file_extension_icon( $file['title'], 32));
}
$list[] = array( 'title'=>$file['title'], 'date'=>$file['mtime'], 'source'=>$file['id'], 'thumbnail' => $thumbnail);
}
Expand Down
2 changes: 1 addition & 1 deletion repository/s3/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function get_listing($path = '', $page = '') {
'size'=>$file['size'],
'date'=>userdate($file['time']),
'source'=>$path.'/'.$file['name'],
'thumbnail'=>$OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $file['name'])))
'thumbnail' => $OUTPUT->old_icon_url(file_extension_icon($file['name'], 32))
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion repository/url/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function get_listing($path='', $page='') {
$ret['list'][] = array(
'title'=>$filename,
'source'=>$this->file_url,
'thumbnail' => $OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $filename)))
'thumbnail' => $OUTPUT->old_icon_url(file_extension_icon($filename, 32))
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion repository/webdav/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function get_listing($path='', $page = '') {
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';
$ret['list'][] = array(
'title'=>$title,
'thumbnail' => $OUTPUT->old_icon_url('f/'. str_replace(array('.png', '.gif'), '', mimeinfo('icon32', $title))),
'thumbnail' => $OUTPUT->old_icon_url(file_extension_icon($title, 32)),
'size'=>$size,
'date'=>$filedate,
'source'=>$v['href']
Expand Down
Loading

0 comments on commit 19c9f09

Please sign in to comment.