filelib MDL-19707 Converted existing ...str_replace('png','gif')... to use file_exten...
authorsamhemelryk <samhemelryk>
Tue, 7 Jul 2009 06:16:01 +0000 (06:16 +0000)
committersamhemelryk <samhemelryk>
Tue, 7 Jul 2009 06:16:01 +0000 (06:16 +0000)
23 files changed:
blog/lib.php
course/lib.php
files/draftfiles.php
files/index.php
mod/assignment/lib.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/type/uploadsingle/assignment.class.php
mod/data/field/file/field.class.php
mod/forum/lib.php
mod/glossary/lib.php
mod/resource/type/directory/resource.class.php
mod/wiki/ewiki/plugins/moodle/downloads.php
question/contextmove_form.php
question/contextmoveq_form.php
repository/alfresco/repository.class.php
repository/boxnet/repository.class.php
repository/filesystem/repository.class.php
repository/lib.php
repository/mahara/repository.class.php
repository/s3/repository.class.php
repository/url/repository.class.php
repository/webdav/repository.class.php
repository/wikimedia/repository.class.php

index c9db0f6..aaec990 100755 (executable)
             $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> ";
index 8bd2627..f4ddffd 100644 (file)
@@ -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) . "";
index 5e46e23..ae1d805 100644 (file)
@@ -156,10 +156,9 @@ foreach ($files as $file) {
         }
 
     } 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>';
     }
index 1523d39..7e1d733 100644 (file)
@@ -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 {
@@ -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) {
index ffe7097..96abda7 100644 (file)
@@ -1779,9 +1779,8 @@ class assignment_base {
                 $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));
index 89847e5..1ae3c40 100644 (file)
@@ -286,9 +286,8 @@ class assignment_upload extends assignment_base {
                 $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;';
 
             }
 
@@ -346,9 +345,8 @@ class assignment_upload extends assignment_base {
             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";
@@ -408,10 +406,9 @@ class assignment_upload extends assignment_base {
                 $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";
index 116db58..65690fc 100644 (file)
@@ -21,9 +21,8 @@ class assignment_uploadsingle extends assignment_base {
                 $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 />';
             }
         }
 
index 34d0af3..b4e0d75 100755 (executable)
@@ -59,9 +59,8 @@ class data_field_file extends data_field_base {
         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;
@@ -118,12 +117,11 @@ class data_field_file extends data_field_base {
         }
 
         $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;
     }
index 0d5ae62..52d5006 100644 (file)
@@ -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') {
index a7ce406..9eb76dc 100644 (file)
@@ -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') {
index 353cd50..5fe3156 100644 (file)
@@ -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"));
         }
@@ -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>';
index 7da8c60..0f78863 100644 (file)
@@ -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;
index 1c4618e..f2f20d8 100644 (file)
@@ -5,7 +5,7 @@ require_once($CFG->libdir.'/formslib.php');
 class question_context_move_form extends moodleform {
 
     function definition() {
-        global $CFG. $OUTPUT;
+        global $CFG, $OUTPUT;
         $mform    =& $this->_form;
 
 //--------------------------------------------------------------------------------
@@ -25,9 +25,8 @@ class question_context_move_form extends moodleform {
 
             $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 {
index 94b21f0..ee0232d 100644 (file)
@@ -26,9 +26,8 @@ class question_context_move_question_form extends moodleform {
 
             $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 {
index 2e19ffa..2b13342 100755 (executable)
@@ -128,7 +128,7 @@ class repository_alfresco extends repository {
                         '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);
                 }
             }
index 5e04cb1..ef206cd 100755 (executable)
@@ -154,7 +154,7 @@ class repository_boxnet extends repository {
                             '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)));
                 }
             }
         }
index 25f2bea..c0dc239 100644 (file)
@@ -64,7 +64,7 @@ class repository_filesystem extends repository {
                             '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)) {
index 63e7dda..12f3ed9 100644 (file)
@@ -769,7 +769,7 @@ abstract class repository {
                 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;
@@ -960,7 +960,7 @@ abstract class repository {
                     '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++;
             }
index 10dc683..75cc8a9 100644 (file)
@@ -214,7 +214,7 @@ class repository_mahara extends repository {
                 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);
             }
index aaf9b38..185764c 100644 (file)
@@ -45,7 +45,7 @@ class repository_s3 extends repository {
                     '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))
                     );
             }
         }
index 4a99f13..b67a390 100755 (executable)
@@ -101,7 +101,7 @@ EOD;
                 $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))
                     );
             }
         }
index c675587..d327713 100644 (file)
@@ -121,7 +121,7 @@ class repository_webdav extends repository {
                 $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']
index bc76c06..5d985a7 100644 (file)
@@ -15,7 +15,7 @@ class repository_wikimedia extends repository {
         foreach ($result as $title=>$url) {
             $list['list'][] = array(
                 'title'=>substr($title, 5),
-                'thumbnail'=>$OUTPUT->old_icon_url('f/'.str_replace(array('.gif', '.png'), '', mimeinfo('icon32', 'xx.jpg'))),
+                'thumbnail'=>$OUTPUT->old_icon_url(file_extension_icon('xx.jpg', 32)),
                 // plugin-dependent unique path to the file (id, url, path, etc.)
                 'source'=>$url,
                 // the accessible url of the file