MDL-32247,MDL-32831,MDL-32900 Use correct url building of file type icons
authorMarina Glancy <marina@moodle.com>
Mon, 21 May 2012 07:17:53 +0000 (15:17 +0800)
committerMarina Glancy <marina@moodle.com>
Mon, 21 May 2012 08:01:04 +0000 (16:01 +0800)
- function get_mimetypes_array() now contains also information about filetype groups and language strings
- use 'smart' human-readable mimetype description
- never determine filetype group based on filetype icon image! remove function mimeinfo_from_icon()
- get rid of class filetype_parser and file lib/filestorage/file_types.mm, replaced with functions file_get_typegroup(), file_extension_in_typegroup() and file_mimetype_in_typegroup()
- support multiple icon sizes, not only 16 and 32
- retrieve filetype icon only using proper functions file_..._icon() from lib/filelib.php throughout the code
- increase size of repository thumbnails to 90 and icons to 24 (will take effect when new icons exist)

48 files changed:
admin/tool/unittest/coveragefile.php
blocks/activity_modules/block_activity_modules.php
blocks/private_files/renderer.php
blog/locallib.php
course/lib.php
files/filebrowser_ajax.php
files/renderer.php
grade/lib.php
lang/en/mimetypes.php
lib/filelib.php
lib/filestorage/file_types.mm [deleted file]
lib/filestorage/stored_file.php
lib/portfolio/formats.php
mod/assign/renderer.php
mod/assignment/lib.php
mod/assignment/renderer.php
mod/assignment/type/online/assignment.class.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/type/uploadsingle/assignment.class.php
mod/data/field/file/field.class.php
mod/data/field/picture/field.class.php
mod/forum/lib.php
mod/glossary/lib.php
mod/resource/lib.php
mod/resource/locallib.php
mod/url/locallib.php
mod/wiki/edit_form.php
mod/wiki/editors/wikifiletable.php
mod/wiki/renderer.php
mod/workshop/renderer.php
question/type/essay/renderer.php
repository/alfresco/lib.php
repository/boxnet/lib.php
repository/coursefiles/lib.php
repository/draftfiles_manager.php
repository/dropbox/lib.php
repository/filesystem/lib.php
repository/lib.php
repository/local/lib.php
repository/merlot/lib.php
repository/recent/lib.php
repository/repository_ajax.php
repository/s3/lib.php
repository/upload/lib.php
repository/user/lib.php
repository/webdav/lib.php
repository/wikimedia/wikimedia.php
user/renderer.php

index 8c17b60..d3c8737 100644 (file)
@@ -60,9 +60,8 @@ if (!isset($args[0]) || !in_array($args[0], $alloweddirs)) {
     print_error('invalidarguments');
 }
 
-// only serve some controlled extensions
-$allowedextensions = array('text/html', 'text/css', 'image/gif', 'application/x-javascript');
-if (!in_array(mimeinfo('type', $filepath), $allowedextensions)) {
+// only serve some controlled extensions/mimetypes
+if (!file_extension_in_typegroup($filepath, array('web_file', 'web_image'), true)) {
     print_error('invalidarguments');
 }
 
index c290b24..2aa2578 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+defined('MOODLE_INTERNAL') || die();
+require_once($CFG->libdir . '/filelib.php');
+
 class block_activity_modules extends block_list {
     function init() {
         $this->title = get_string('pluginname', 'block_activity_modules');
@@ -50,7 +53,7 @@ class block_activity_modules extends block_list {
 
         foreach ($modfullnames as $modname => $modfullname) {
             if ($modname === 'resources') {
-                $icon = '<img src="'.$OUTPUT->pix_url('f/html') . '" class="icon" alt="" />&nbsp;';
+                $icon = $OUTPUT->pix_icon(file_extension_icon('.htm'), '', 'moodle', array('class' => 'icon')). '&nbsp;';
                 $this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/resources.php?id='.$course->id.'">'.$icon.$modfullname.'</a>';
             } else {
                 $icon = '<img src="'.$OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" />&nbsp;';
index 5c27971..eb109fa 100644 (file)
@@ -65,14 +65,13 @@ class block_private_files_renderer extends plugin_renderer_base {
         }
         $result = '<ul>';
         foreach ($dir['subdirs'] as $subdir) {
-            $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
         }
         foreach ($dir['files'] as $file) {
             $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
             $filename = $file->get_filename();
-            $icon = mimeinfo("icon", $filename);
-            $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.html_writer::link($url, $image.'&nbsp;'.$filename).'</div></li>';
         }
         $result .= '</ul>';
index 9eb1e8f..6ac8944 100644 (file)
@@ -513,10 +513,7 @@ class blog_entry {
             $ffurl    = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/attachment/'.$this->id.'/'.$filename);
             $mimetype = $file->get_mimetype();
 
-            $icon     = mimeinfo_from_type("icon", $mimetype);
-            $type     = mimeinfo_from_type("type", $mimetype);
-
-            $image = $OUTPUT->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $image = $OUTPUT->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
 
             if ($return == "html") {
                 $output .= html_writer::link($ffurl, $image);
@@ -526,7 +523,7 @@ class blog_entry {
                 $output .= "$strattachment $filename:\n$ffurl\n";
 
             } else {
-                if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {    // Image attachments don't get printed as links
+                if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {    // Image attachments don't get printed as links
                     $imagereturn .= '<br /><img src="'.$ffurl.'" alt="" />';
                 } else {
                     $imagereturn .= html_writer::link($ffurl, $image);
index 9a64052..8e07373 100644 (file)
@@ -1518,13 +1518,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
             //Accessibility: for files get description via icon, this is very ugly hack!
             $altname = '';
             $altname = $mod->modfullname;
-            if (!empty($customicon)) {
-                $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
-                if ($archetype == MOD_ARCHETYPE_RESOURCE) {
-                    $mimetype = mimeinfo_from_icon('type', $customicon);
-                    $altname = get_mimetype_description($mimetype);
-                }
-            }
             // Avoid unnecessary duplication: if e.g. a forum name already
             // includes the word forum (or Forum, etc) then it is unhelpful
             // to include that in the accessible description that is added.
index 2d651e9..a8b638b 100644 (file)
@@ -70,10 +70,10 @@ switch ($action) {
             if ($child->is_directory()) {
                 $fileitem['isdir'] = true;
                 $fileitem['url'] = $url->out(false);
-                $fileitem['icon'] = $OUTPUT->pix_icon('f/folder', get_string('icon'));
+                $fileitem['icon'] = $OUTPUT->pix_icon(file_folder_icon(), get_string('icon'));
             } else {
                 $fileitem['url'] = $child->get_url();
-                $fileitem['icon'] = $OUTPUT->pix_icon('f/'.mimeinfo('icon', $child->get_visible_name()), get_string('icon'));
+                $fileitem['icon'] = $OUTPUT->pix_icon(file_file_icon($child), get_string('icon'));
             }
             $tree[] = $fileitem;
         }
index e9479f7..e6f0a22 100644 (file)
@@ -56,25 +56,31 @@ class core_files_renderer extends plugin_renderer_base {
 
         $html .= $this->output->box_start();
         $table = new html_table();
-        $table->head = array(get_string('filename', 'backup'), get_string('size'), get_string('modified'));
-        $table->align = array('left', 'right', 'right');
+        $table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository'));
+        $table->align = array('left', 'left', 'left', 'left');
         $table->width = '100%';
         $table->data = array();
 
         foreach ($tree->tree as $file) {
-            if (!empty($file['isdir'])) {
-                $table->data[] = array(
-                    html_writer::link($file['url'], $this->output->pix_icon('f/folder', 'icon') . ' ' . $file['filename']),
-                    '',
-                    $file['filedate'],
-                    );
+            $filedate = $filesize = $filetype = '';
+            if ($file['filedate']) {
+                $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig'));
+            }
+            if (empty($file['isdir'])) {
+                if ($file['filesize']) {
+                    $filesize = display_size($file['filesize']);
+                }
+                $fileicon = file_file_icon($file, 24);
+                $filetype = get_mimetype_description($file);
             } else {
-                $table->data[] = array(
-                    html_writer::link($file['url'], $this->output->pix_icon('f/'.mimeinfo('icon', $file['filename']), get_string('icon')) . ' ' . $file['filename']),
-                    $file['filesize'],
-                    $file['filedate'],
-                    );
+                $fileicon = file_folder_icon(24);
             }
+            $table->data[] = array(
+                html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']),
+                $filedate,
+                $filesize,
+                $filetype
+                );
         }
 
         $html .= html_writer::table($table);
@@ -952,8 +958,9 @@ class files_tree_viewer implements renderable {
             $fileitem = array(
                     'params'   => $params,
                     'filename' => $child->get_visible_name(),
-                    'filedate' => $filedate ? userdate($filedate) : '',
-                    'filesize' => $filesize ? display_size($filesize) : ''
+                    'mimetype' => $child->get_mimetype(),
+                    'filedate' => $filedate ? $filedate : '',
+                    'filesize' => $filesize ? $filesize : ''
                     );
             $url = new moodle_url('/files/index.php', $params);
             if ($child->is_directory()) {
index 185fed5..e1937be 100644 (file)
@@ -1049,6 +1049,7 @@ class grade_structure {
      */
     public function get_element_icon(&$element, $spacerifnone=false) {
         global $CFG, $OUTPUT;
+        require_once $CFG->libdir.'/filelib.php';
 
         switch ($element['type']) {
             case 'item':
@@ -1114,7 +1115,7 @@ class grade_structure {
 
             case 'category':
                 $strcat = get_string('category', 'grades');
-                return '<img src="'.$OUTPUT->pix_url('f/folder') . '" class="icon itemicon" ' .
+                return '<img src="'.$OUTPUT->pix_url(file_folder_icon()) . '" class="icon itemicon" ' .
                         'title="'.s($strcat).'" alt="'.s($strcat).'" />';
         }
 
index 17d224e..9cb966d 100644 (file)
 /**
  * Strings for component 'mimetypes', language 'en', branch 'MOODLE_20_STABLE'
  *
+ * Strings are used to display human-readable name of mimetype. Some mimetypes share the same
+ * string. The following attributes are passed in the parameter when processing the string:
+ *   $a->ext - filename extension in lower case
+ *   $a->EXT - filename extension, capitalized
+ *   $a->Ext - filename extension with first capital letter
+ *   $a->mimetype - file mimetype
+ *   $a->mimetype1 - first chunk of mimetype (before /)
+ *   $a->mimetype2 - second chunk of mimetype (after /)
+ *   $a->Mimetype, $a->MIMETYPE, $a->Mimetype1, $a->Mimetype2, $a->MIMETYPE1, $a->MIMETYPE2
+ *      - the same with capitalized first/all letters
+ *
+ * @see       get_mimetypes_array()
+ * @see       get_mimetype_description()
  * @package   mimetypes
  * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 
 $string['application/msword'] = 'Word document';
 $string['application/pdf'] = 'PDF document';
+$string['application/vnd.moodle.backup'] = 'Moodle backup';
 $string['application/vnd.ms-excel'] = 'Excel spreadsheet';
 $string['application/vnd.ms-powerpoint'] = 'Powerpoint presentation';
-$string['application/zip'] = 'zip archive';
-$string['audio/mp3'] = 'MP3 audio file';
-$string['audio/wav'] = 'sound file';
-$string['document/unknown'] = 'file';
-$string['image/bmp'] = 'uncompressed BMP image';
-$string['image/gif'] = 'GIF image';
-$string['image/jpeg'] = 'JPEG image';
-$string['image/png'] = 'PNG image';
-$string['text/plain'] = 'text file';
+$string['application/vnd.openxmlformats-officedocument.presentationml.presentation'] = 'Powerpoint presentation';
+$string['application/vnd.openxmlformats-officedocument.presentationml.slideshow'] = 'Powerpoint slideshow';
+$string['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'] = 'Excel spreadsheet';
+$string['application/vnd.openxmlformats-officedocument.spreadsheetml.template'] = 'Excel template';
+$string['application/vnd.openxmlformats-officedocument.wordprocessingml.document'] = 'Word document';
+$string['archive'] = 'Archive ({$a->EXT})';
+$string['audio'] = 'Audio file ({$a->EXT})';
+$string['default'] = '{$a->mimetype}';
+$string['document/unknown'] = 'File';
+$string['image'] = 'Image ({$a->MIMETYPE2})';
+$string['text/html'] = 'HTML document';
+$string['text/plain'] = 'Text file';
 $string['text/rtf'] = 'RTF document';
index a38cba1..972a8d1 100644 (file)
@@ -590,8 +590,6 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
             $item->size = $filesize ? $filesize : null;
             $item->filesize = $filesize ? display_size($filesize) : '';
 
-            $icon = mimeinfo_from_type('icon', $file->get_mimetype());
-            $item->icon = $OUTPUT->pix_url('f/' . $icon)->out();
             $item->sortorder = $file->get_sortorder();
             $item->author = $file->get_author();
             $item->license = $file->get_license();
@@ -605,25 +603,25 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
                 $item->refcount = $fs->search_references_count($source->original);
             }
 
-            // TODO MDL-32900 this is not the correct way to check that it is archive, use filetype_parser instead
-            if ($icon == 'zip') {
-                $item->type = 'zip';
-            } else {
-                $item->type = 'file';
-            }
-
             if ($file->is_directory()) {
                 $item->filesize = 0;
-                $item->icon = $OUTPUT->pix_url('f/folder')->out();
+                $item->icon = $OUTPUT->pix_url(file_folder_icon(24))->out(false);
                 $item->type = 'folder';
                 $foldername = explode('/', trim($item->filepath, '/'));
                 $item->fullname = trim(array_pop($foldername), '/');
-                $item->thumbnail = $OUTPUT->pix_url('f/folder-32')->out(false);
+                $item->thumbnail = $OUTPUT->pix_url(file_folder_icon(90))->out(false);
             } else {
                 // do NOT use file browser here!
+                $item->mimetype = get_mimetype_description($file);
+                if (file_mimetype_in_typegroup($item->mimetype, 'archive')) {
+                    $item->type = 'zip';
+                } else {
+                    $item->type = 'file';
+                }
                 $itemurl = moodle_url::make_draftfile_url($draftitemid, $item->filepath, $item->filename);
                 $item->url = $itemurl->out();
-                $item->thumbnail = $OUTPUT->pix_url(file_extension_icon($item->filename, 32))->out(false);
+                $item->icon = $OUTPUT->pix_url(file_file_icon($file, 24))->out(false);
+                $item->thumbnail = $OUTPUT->pix_url(file_file_icon($file, 90))->out(false);
                 if ($imageinfo = $file->get_imageinfo()) {
                     $item->realthumbnail = $itemurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
                     $item->realicon = $itemurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
@@ -1323,7 +1321,32 @@ function download_file_content_write_handler($received, $ch, $data) {
 }
 
 /**
- * Returns a list of information about file t ypes based on extensions
+ * Returns a list of information about file types based on extensions.
+ *
+ * The following elements expected in value array for each extension:
+ * 'type' - mimetype
+ * 'icon' - location of the icon file. If value is FILENAME, then either pix/f/FILENAME.gif
+ *     or pix/f/FILENAME.png must be present in moodle and contain 16x16 filetype icon;
+ *     also files with bigger sizes under names
+ *     FILENAME-24, FILENAME-32, FILENAME-64, FILENAME-128, FILENAME-256 are recommended.
+ * 'groups' (optional) - array of filetype groups this filetype extension is part of;
+ *     commonly used in moodle the following groups:
+ *       - web_image - image that can be included as <img> in HTML
+ *       - image - image that we can parse using GD to find it's dimensions, also used for portfolio format
+ *       - video - file that can be imported as video in text editor
+ *       - audio - file that can be imported as audio in text editor
+ *       - archive - we can extract files from this archive
+ *       - spreadsheet - used for portfolio format
+ *       - document - used for portfolio format
+ *       - presentation - used for portfolio format
+ * 'string' (optional) - the name of the string from lang/en/mimetypes.php that displays
+ *     human-readable description for this filetype;
+ *     Function {@link get_mimetype_description()} first looks at the presence of string for
+ *     particular mimetype (value of 'type'), if not found looks for string specified in 'string'
+ *     attribute, if not found returns the value of 'type';
+ * 'defaulticon' (boolean, optional) - used by function {@link file_mimetype_icon()} to find
+ *     an icon for mimetype. If an entry with 'defaulticon' is not found for a particular mimetype,
+ *     this function will return first found icon; Especially usefull for types such as 'text/plain'
  *
  * @category files
  * @return array List of information about file types based on extensions.
@@ -1331,57 +1354,57 @@ function download_file_content_write_handler($received, $ch, $data) {
  *   from 'element name' to data. Current element names are 'type' and 'icon'.
  *   Unknown types should use the 'xxx' entry which includes defaults.
  */
-function get_mimetypes_array() {
+function &get_mimetypes_array() {
     static $mimearray = array (
         'xxx'  => array ('type'=>'document/unknown', 'icon'=>'unknown'),
-        '3gp'  => array ('type'=>'video/quicktime', 'icon'=>'video'),
-        'aac'  => array ('type'=>'audio/aac', 'icon'=>'audio'),
-        'ai'   => array ('type'=>'application/postscript', 'icon'=>'image'),
-        'aif'  => array ('type'=>'audio/x-aiff', 'icon'=>'audio'),
-        'aiff' => array ('type'=>'audio/x-aiff', 'icon'=>'audio'),
-        'aifc' => array ('type'=>'audio/x-aiff', 'icon'=>'audio'),
+        '3gp'  => array ('type'=>'video/quicktime', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'aac'  => array ('type'=>'audio/aac', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'ai'   => array ('type'=>'application/postscript', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
+        'aif'  => array ('type'=>'audio/x-aiff', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'aiff' => array ('type'=>'audio/x-aiff', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'aifc' => array ('type'=>'audio/x-aiff', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
         'applescript'  => array ('type'=>'text/plain', 'icon'=>'text'),
         'asc'  => array ('type'=>'text/plain', 'icon'=>'text'),
         'asm'  => array ('type'=>'text/plain', 'icon'=>'text'),
-        'au'   => array ('type'=>'audio/au', 'icon'=>'audio'),
-        'avi'  => array ('type'=>'video/x-ms-wm', 'icon'=>'avi'),
-        'bmp'  => array ('type'=>'image/bmp', 'icon'=>'image'),
+        'au'   => array ('type'=>'audio/au', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'avi'  => array ('type'=>'video/x-ms-wm', 'icon'=>'avi', 'groups'=>array('video'), 'string'=>'video'),
+        'bmp'  => array ('type'=>'image/bmp', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
         'c'    => array ('type'=>'text/plain', 'icon'=>'text'),
         'cct'  => array ('type'=>'shockwave/director', 'icon'=>'flash'),
         'cpp'  => array ('type'=>'text/plain', 'icon'=>'text'),
         'cs'   => array ('type'=>'application/x-csh', 'icon'=>'text'),
-        'css'  => array ('type'=>'text/css', 'icon'=>'text'),
-        'csv'  => array ('type'=>'text/csv', 'icon'=>'excel'),
-        'dv'   => array ('type'=>'video/x-dv', 'icon'=>'video'),
+        'css'  => array ('type'=>'text/css', 'icon'=>'text', 'groups'=>array('web_file')),
+        'csv'  => array ('type'=>'text/csv', 'icon'=>'excel', 'groups'=>array('spreadsheet')),
+        'dv'   => array ('type'=>'video/x-dv', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
         'dmg'  => array ('type'=>'application/octet-stream', 'icon'=>'dmg'),
 
-        'doc'  => array ('type'=>'application/msword', 'icon'=>'word'),
-        'docx' => array ('type'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'icon'=>'docx'),
+        'doc'  => array ('type'=>'application/msword', 'icon'=>'word', 'groups'=>array('document')),
+        'docx' => array ('type'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'icon'=>'docx', 'groups'=>array('document')),
         'docm' => array ('type'=>'application/vnd.ms-word.document.macroEnabled.12', 'icon'=>'docm'),
         'dotx' => array ('type'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'icon'=>'dotx'),
         'dotm' => array ('type'=>'application/vnd.ms-word.template.macroEnabled.12', 'icon'=>'dotm'),
 
         'dcr'  => array ('type'=>'application/x-director', 'icon'=>'flash'),
-        'dif'  => array ('type'=>'video/x-dv', 'icon'=>'video'),
+        'dif'  => array ('type'=>'video/x-dv', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
         'dir'  => array ('type'=>'application/x-director', 'icon'=>'flash'),
         'dxr'  => array ('type'=>'application/x-director', 'icon'=>'flash'),
         'eps'  => array ('type'=>'application/postscript', 'icon'=>'pdf'),
         'fdf'  => array ('type'=>'application/pdf', 'icon'=>'pdf'),
-        'flv'  => array ('type'=>'video/x-flv', 'icon'=>'video'),
-        'f4v'  => array ('type'=>'video/mp4', 'icon'=>'video'),
-        'gif'  => array ('type'=>'image/gif', 'icon'=>'image'),
-        'gtar' => array ('type'=>'application/x-gtar', 'icon'=>'zip'),
-        'tgz'  => array ('type'=>'application/g-zip', 'icon'=>'zip'),
-        'gz'   => array ('type'=>'application/g-zip', 'icon'=>'zip'),
-        'gzip' => array ('type'=>'application/g-zip', 'icon'=>'zip'),
+        'flv'  => array ('type'=>'video/x-flv', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'f4v'  => array ('type'=>'video/mp4', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'gif'  => array ('type'=>'image/gif', 'icon'=>'image', 'groups'=>array('image', 'web_image'), 'string'=>'image'),
+        'gtar' => array ('type'=>'application/x-gtar', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
+        'tgz'  => array ('type'=>'application/g-zip', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
+        'gz'   => array ('type'=>'application/g-zip', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
+        'gzip' => array ('type'=>'application/g-zip', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
         'h'    => array ('type'=>'text/plain', 'icon'=>'text'),
         'hpp'  => array ('type'=>'text/plain', 'icon'=>'text'),
-        'hqx'  => array ('type'=>'application/mac-binhex40', 'icon'=>'zip'),
+        'hqx'  => array ('type'=>'application/mac-binhex40', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
         'htc'  => array ('type'=>'text/x-component', 'icon'=>'text'),
-        'html' => array ('type'=>'text/html', 'icon'=>'html'),
+        'html' => array ('type'=>'text/html', 'icon'=>'html', 'groups'=>array('web_file')),
         'xhtml'=> array ('type'=>'application/xhtml+xml', 'icon'=>'html'),
-        'htm'  => array ('type'=>'text/html', 'icon'=>'html'),
-        'ico'  => array ('type'=>'image/vnd.microsoft.icon', 'icon'=>'image'),
+        'htm'  => array ('type'=>'text/html', 'icon'=>'html', 'groups'=>array('web_file')),
+        'ico'  => array ('type'=>'image/vnd.microsoft.icon', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
         'ics'  => array ('type'=>'text/calendar', 'icon'=>'text'),
         'isf'  => array ('type'=>'application/inspiration', 'icon'=>'isf'),
         'ist'  => array ('type'=>'application/inspiration.template', 'icon'=>'isf'),
@@ -1391,52 +1414,52 @@ function get_mimetypes_array() {
         'jcw'  => array ('type'=>'text/xml', 'icon'=>'jcw'),
         'jmt'  => array ('type'=>'text/xml', 'icon'=>'jmt'),
         'jmx'  => array ('type'=>'text/xml', 'icon'=>'jmx'),
-        'jpe'  => array ('type'=>'image/jpeg', 'icon'=>'image'),
-        'jpeg' => array ('type'=>'image/jpeg', 'icon'=>'image'),
-        'jpg'  => array ('type'=>'image/jpeg', 'icon'=>'image'),
+        'jpe'  => array ('type'=>'image/jpeg', 'icon'=>'image', 'groups'=>array('image', 'web_image'), 'string'=>'image'),
+        'jpeg' => array ('type'=>'image/jpeg', 'icon'=>'image', 'groups'=>array('image', 'web_image'), 'string'=>'image'),
+        'jpg'  => array ('type'=>'image/jpeg', 'icon'=>'image', 'groups'=>array('image', 'web_image'), 'string'=>'image'),
         'jqz'  => array ('type'=>'text/xml', 'icon'=>'jqz'),
-        'js'   => array ('type'=>'application/x-javascript', 'icon'=>'text'),
+        'js'   => array ('type'=>'application/x-javascript', 'icon'=>'text', 'groups'=>array('web_file')),
         'latex'=> array ('type'=>'application/x-latex', 'icon'=>'text'),
         'm'    => array ('type'=>'text/plain', 'icon'=>'text'),
         'mbz'  => array ('type'=>'application/vnd.moodle.backup', 'icon'=>'moodle'),
-        'mov'  => array ('type'=>'video/quicktime', 'icon'=>'video'),
-        'movie'=> array ('type'=>'video/x-sgi-movie', 'icon'=>'video'),
-        'm3u'  => array ('type'=>'audio/x-mpegurl', 'icon'=>'audio'),
-        'mp3'  => array ('type'=>'audio/mp3', 'icon'=>'audio'),
-        'mp4'  => array ('type'=>'video/mp4', 'icon'=>'video'),
-        'm4v'  => array ('type'=>'video/mp4', 'icon'=>'video'),
-        'm4a'  => array ('type'=>'audio/mp4', 'icon'=>'audio'),
-        'mpeg' => array ('type'=>'video/mpeg', 'icon'=>'video'),
-        'mpe'  => array ('type'=>'video/mpeg', 'icon'=>'video'),
-        'mpg'  => array ('type'=>'video/mpeg', 'icon'=>'video'),
-
-        'odt'  => array ('type'=>'application/vnd.oasis.opendocument.text', 'icon'=>'odt'),
-        'ott'  => array ('type'=>'application/vnd.oasis.opendocument.text-template', 'icon'=>'odt'),
-        'oth'  => array ('type'=>'application/vnd.oasis.opendocument.text-web', 'icon'=>'odt'),
+        'mov'  => array ('type'=>'video/quicktime', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'movie'=> array ('type'=>'video/x-sgi-movie', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'm3u'  => array ('type'=>'audio/x-mpegurl', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'mp3'  => array ('type'=>'audio/mp3', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'mp4'  => array ('type'=>'video/mp4', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'm4v'  => array ('type'=>'video/mp4', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'm4a'  => array ('type'=>'audio/mp4', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'mpeg' => array ('type'=>'video/mpeg', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'mpe'  => array ('type'=>'video/mpeg', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'mpg'  => array ('type'=>'video/mpeg', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+
+        'odt'  => array ('type'=>'application/vnd.oasis.opendocument.text', 'icon'=>'odt', 'groups'=>array('document')),
+        'ott'  => array ('type'=>'application/vnd.oasis.opendocument.text-template', 'icon'=>'odt', 'groups'=>array('document')),
+        'oth'  => array ('type'=>'application/vnd.oasis.opendocument.text-web', 'icon'=>'odt', 'groups'=>array('document')),
         'odm'  => array ('type'=>'application/vnd.oasis.opendocument.text-master', 'icon'=>'odm'),
         'odg'  => array ('type'=>'application/vnd.oasis.opendocument.graphics', 'icon'=>'odg'),
         'otg'  => array ('type'=>'application/vnd.oasis.opendocument.graphics-template', 'icon'=>'odg'),
         'odp'  => array ('type'=>'application/vnd.oasis.opendocument.presentation', 'icon'=>'odp'),
         'otp'  => array ('type'=>'application/vnd.oasis.opendocument.presentation-template', 'icon'=>'odp'),
-        'ods'  => array ('type'=>'application/vnd.oasis.opendocument.spreadsheet', 'icon'=>'ods'),
-        'ots'  => array ('type'=>'application/vnd.oasis.opendocument.spreadsheet-template', 'icon'=>'ods'),
+        'ods'  => array ('type'=>'application/vnd.oasis.opendocument.spreadsheet', 'icon'=>'ods', 'groups'=>array('spreadsheet')),
+        'ots'  => array ('type'=>'application/vnd.oasis.opendocument.spreadsheet-template', 'icon'=>'ods', 'groups'=>array('spreadsheet')),
         'odc'  => array ('type'=>'application/vnd.oasis.opendocument.chart', 'icon'=>'odc'),
         'odf'  => array ('type'=>'application/vnd.oasis.opendocument.formula', 'icon'=>'odf'),
         'odb'  => array ('type'=>'application/vnd.oasis.opendocument.database', 'icon'=>'odb'),
         'odi'  => array ('type'=>'application/vnd.oasis.opendocument.image', 'icon'=>'odi'),
-        'oga'  => array ('type'=>'audio/ogg', 'icon'=>'audio'),
-        'ogg'  => array ('type'=>'audio/ogg', 'icon'=>'audio'),
-        'ogv'  => array ('type'=>'video/ogg', 'icon'=>'video'),
+        'oga'  => array ('type'=>'audio/ogg', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'ogg'  => array ('type'=>'audio/ogg', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'ogv'  => array ('type'=>'video/ogg', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
 
-        'pct'  => array ('type'=>'image/pict', 'icon'=>'image'),
+        'pct'  => array ('type'=>'image/pict', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
         'pdf'  => array ('type'=>'application/pdf', 'icon'=>'pdf'),
         'php'  => array ('type'=>'text/plain', 'icon'=>'text'),
-        'pic'  => array ('type'=>'image/pict', 'icon'=>'image'),
-        'pict' => array ('type'=>'image/pict', 'icon'=>'image'),
-        'png'  => array ('type'=>'image/png', 'icon'=>'image'),
+        'pic'  => array ('type'=>'image/pict', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
+        'pict' => array ('type'=>'image/pict', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
+        'png'  => array ('type'=>'image/png', 'icon'=>'image', 'groups'=>array('image', 'web_image'), 'string'=>'image'),
 
-        'pps'  => array ('type'=>'application/vnd.ms-powerpoint', 'icon'=>'powerpoint'),
-        'ppt'  => array ('type'=>'application/vnd.ms-powerpoint', 'icon'=>'powerpoint'),
+        'pps'  => array ('type'=>'application/vnd.ms-powerpoint', 'icon'=>'powerpoint', 'groups'=>array('presentation')),
+        'ppt'  => array ('type'=>'application/vnd.ms-powerpoint', 'icon'=>'powerpoint', 'groups'=>array('presentation')),
         'pptx' => array ('type'=>'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'icon'=>'pptx'),
         'pptm' => array ('type'=>'application/vnd.ms-powerpoint.presentation.macroEnabled.12', 'icon'=>'pptm'),
         'potx' => array ('type'=>'application/vnd.openxmlformats-officedocument.presentationml.template', 'icon'=>'potx'),
@@ -1446,22 +1469,22 @@ function get_mimetypes_array() {
         'ppsm' => array ('type'=>'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', 'icon'=>'ppsm'),
 
         'ps'   => array ('type'=>'application/postscript', 'icon'=>'pdf'),
-        'qt'   => array ('type'=>'video/quicktime', 'icon'=>'video'),
-        'ra'   => array ('type'=>'audio/x-realaudio-plugin', 'icon'=>'audio'),
-        'ram'  => array ('type'=>'audio/x-pn-realaudio-plugin', 'icon'=>'audio'),
+        'qt'   => array ('type'=>'video/quicktime', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'ra'   => array ('type'=>'audio/x-realaudio-plugin', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'ram'  => array ('type'=>'audio/x-pn-realaudio-plugin', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
         'rhb'  => array ('type'=>'text/xml', 'icon'=>'xml'),
-        'rm'   => array ('type'=>'audio/x-pn-realaudio-plugin', 'icon'=>'audio'),
-        'rmvb' => array ('type'=>'application/vnd.rn-realmedia-vbr', 'icon'=>'video'),
-        'rtf'  => array ('type'=>'text/rtf', 'icon'=>'text'),
+        'rm'   => array ('type'=>'audio/x-pn-realaudio-plugin', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'rmvb' => array ('type'=>'application/vnd.rn-realmedia-vbr', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'rtf'  => array ('type'=>'text/rtf', 'icon'=>'text', 'groups'=>array('document')),
         'rtx'  => array ('type'=>'text/richtext', 'icon'=>'text'),
-        'rv'   => array ('type'=>'audio/x-pn-realaudio-plugin', 'icon'=>'video'),
+        'rv'   => array ('type'=>'audio/x-pn-realaudio-plugin', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
         'sh'   => array ('type'=>'application/x-sh', 'icon'=>'text'),
-        'sit'  => array ('type'=>'application/x-stuffit', 'icon'=>'zip'),
+        'sit'  => array ('type'=>'application/x-stuffit', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
         'smi'  => array ('type'=>'application/smil', 'icon'=>'text'),
         'smil' => array ('type'=>'application/smil', 'icon'=>'text'),
         'sqt'  => array ('type'=>'text/xml', 'icon'=>'xml'),
-        'svg'  => array ('type'=>'image/svg+xml', 'icon'=>'image'),
-        'svgz' => array ('type'=>'image/svg+xml', 'icon'=>'image'),
+        'svg'  => array ('type'=>'image/svg+xml', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
+        'svgz' => array ('type'=>'image/svg+xml', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
         'swa'  => array ('type'=>'application/x-director', 'icon'=>'flash'),
         'swf'  => array ('type'=>'application/x-shockwave-flash', 'icon'=>'flash'),
         'swfl' => array ('type'=>'application/x-shockwave-flash', 'icon'=>'flash'),
@@ -1477,25 +1500,25 @@ function get_mimetypes_array() {
         'sxg'  => array ('type'=>'application/vnd.sun.xml.writer.global', 'icon'=>'odt'),
         'sxm'  => array ('type'=>'application/vnd.sun.xml.math', 'icon'=>'odt'),
 
-        'tar'  => array ('type'=>'application/x-tar', 'icon'=>'zip'),
-        'tif'  => array ('type'=>'image/tiff', 'icon'=>'image'),
-        'tiff' => array ('type'=>'image/tiff', 'icon'=>'image'),
+        'tar'  => array ('type'=>'application/x-tar', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive'),
+        'tif'  => array ('type'=>'image/tiff', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
+        'tiff' => array ('type'=>'image/tiff', 'icon'=>'image', 'groups'=>array('image'), 'string'=>'image'),
         'tex'  => array ('type'=>'application/x-tex', 'icon'=>'text'),
         'texi' => array ('type'=>'application/x-texinfo', 'icon'=>'text'),
         'texinfo'  => array ('type'=>'application/x-texinfo', 'icon'=>'text'),
         'tsv'  => array ('type'=>'text/tab-separated-values', 'icon'=>'text'),
-        'txt'  => array ('type'=>'text/plain', 'icon'=>'text'),
-        'wav'  => array ('type'=>'audio/wav', 'icon'=>'audio'),
-        'webm'  => array ('type'=>'video/webm', 'icon'=>'video'),
-        'wmv'  => array ('type'=>'video/x-ms-wmv', 'icon'=>'avi'),
-        'asf'  => array ('type'=>'video/x-ms-asf', 'icon'=>'avi'),
+        'txt'  => array ('type'=>'text/plain', 'icon'=>'text', 'defaulticon'=>true),
+        'wav'  => array ('type'=>'audio/wav', 'icon'=>'audio', 'groups'=>array('audio'), 'string'=>'audio'),
+        'webm'  => array ('type'=>'video/webm', 'icon'=>'video', 'groups'=>array('video'), 'string'=>'video'),
+        'wmv'  => array ('type'=>'video/x-ms-wmv', 'icon'=>'avi', 'groups'=>array('video'), 'string'=>'video'),
+        'asf'  => array ('type'=>'video/x-ms-asf', 'icon'=>'avi', 'groups'=>array('video'), 'string'=>'video'),
         'xdp'  => array ('type'=>'application/pdf', 'icon'=>'pdf'),
         'xfd'  => array ('type'=>'application/pdf', 'icon'=>'pdf'),
         'xfdf' => array ('type'=>'application/pdf', 'icon'=>'pdf'),
 
-        'xls'  => array ('type'=>'application/vnd.ms-excel', 'icon'=>'excel'),
+        'xls'  => array ('type'=>'application/vnd.ms-excel', 'icon'=>'excel', 'groups'=>array('spreadsheet')),
         'xlsx' => array ('type'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'icon'=>'xlsx'),
-        'xlsm' => array ('type'=>'application/vnd.ms-excel.sheet.macroEnabled.12', 'icon'=>'xlsm'),
+        'xlsm' => array ('type'=>'application/vnd.ms-excel.sheet.macroEnabled.12', 'icon'=>'xlsm', 'groups'=>array('spreadsheet')),
         'xltx' => array ('type'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'icon'=>'xltx'),
         'xltm' => array ('type'=>'application/vnd.ms-excel.template.macroEnabled.12', 'icon'=>'xltm'),
         'xlsb' => array ('type'=>'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'icon'=>'xlsb'),
@@ -1503,7 +1526,7 @@ function get_mimetypes_array() {
 
         'xml'  => array ('type'=>'application/xml', 'icon'=>'xml'),
         'xsl'  => array ('type'=>'text/xml', 'icon'=>'xml'),
-        'zip'  => array ('type'=>'application/zip', 'icon'=>'zip')
+        'zip'  => array ('type'=>'application/zip', 'icon'=>'zip', 'groups'=>array('archive'), 'string'=>'archive')
     );
     return $mimearray;
 }
@@ -1515,39 +1538,41 @@ function get_mimetypes_array() {
  *
  * @category files
  * @param string $element Desired information (usually 'icon'
- *   for icon filename or 'type' for MIME type)
+ *   for icon filename or 'type' for MIME type. Can also be
+ *   'icon24', ...32, 48, 64, 72, 80, 96, 128, 256)
  * @param string $filename Filename we're looking up
  * @return string Requested piece of information from array
  */
 function mimeinfo($element, $filename) {
     global $CFG;
-    $mimeinfo = get_mimetypes_array();
-
-    if (preg_match('/\.([a-z0-9]+)$/i', $filename, $match)) {
-        if (isset($mimeinfo[strtolower($match[1])][$element])) {
-            return $mimeinfo[strtolower($match[1])][$element];
-        } else {
-            if ($element == 'icon32') {
-                if (isset($mimeinfo[strtolower($match[1])]['icon'])) {
-                    $filename = $mimeinfo[strtolower($match[1])]['icon'];
-                } else {
-                    $filename = 'unknown';
+    $mimeinfo = & get_mimetypes_array();
+    static $iconpostfixes = array(256=>'-256', 128=>'-128', 96=>'-96', 80=>'-80', 72=>'-72', 64=>'-64', 48=>'-48', 32=>'-32', 24=>'-24', 16=>'');
+
+    $filetype = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
+    if (empty($filetype)) {
+        $filetype = 'xxx'; // file without extension
+    }
+    if (preg_match('/^icon(\d*)$/', $element, $iconsizematch)) {
+        $iconsize = max(array(16, (int)$iconsizematch[1]));
+        $filenames = array($mimeinfo['xxx']['icon']);
+        if ($filetype != 'xxx' && isset($mimeinfo[$filetype]['icon'])) {
+            array_unshift($filenames, $mimeinfo[$filetype]['icon']);
+        }
+        // find the file with the closest size, first search for specific icon then for default icon
+        foreach ($filenames as $filename) {
+            foreach ($iconpostfixes as $size => $postfix) {
+                $fullname = $CFG->dirroot.'/pix/f/'.$filename.$postfix;
+                if ($iconsize >= $size && (file_exists($fullname.'.png') || file_exists($fullname.'.gif'))) {
+                    return $filename.$postfix;
                 }
-                $filename .= '-32';
-                if (file_exists($CFG->dirroot.'/pix/f/'.$filename.'.png') or file_exists($CFG->dirroot.'/pix/f/'.$filename.'.gif')) {
-                    return $filename;
-                } else {
-                    return 'unknown-32';
-                }
-            } else {
-                return $mimeinfo['xxx'][$element];   // By default
             }
         }
-    } else {
-        if ($element == 'icon32') {
-            return 'unknown-32';
-        }
+    } else if (isset($mimeinfo[$filetype][$element])) {
+        return $mimeinfo[$filetype][$element];
+    } else if (isset($mimeinfo['xxx'][$element])) {
         return $mimeinfo['xxx'][$element];   // By default
+    } else {
+        return null;
     }
 }
 
@@ -1556,66 +1581,115 @@ function mimeinfo($element, $filename) {
  * the other way around.
  *
  * @category files
- * @param string $element Desired information (usually 'icon')
+ * @param string $element Desired information ('extension', 'icon', 'icon-24', etc.)
  * @param string $mimetype MIME type we're looking up
  * @return string Requested piece of information from array
  */
 function mimeinfo_from_type($element, $mimetype) {
-    $mimeinfo = get_mimetypes_array();
-
-    foreach($mimeinfo as $values) {
-        if ($values['type']==$mimetype) {
-            if (isset($values[$element])) {
-                return $values[$element];
+    /* array of cached mimetype->extension associations */
+    static $cached = array();
+    $mimeinfo = & get_mimetypes_array();
+
+    if (!array_key_exists($mimetype, $cached)) {
+        $cached[$mimetype] = null;    
+        foreach($mimeinfo as $filetype => $values) {
+            if ($values['type'] == $mimetype) {
+                if ($cached[$mimetype] === null) {
+                    $cached[$mimetype] = $filetype;
+                }
+                if (!empty($values['defaulticon'])) {
+                    $cached[$mimetype] = $filetype;
+                    break;
+                }
             }
-            break;
         }
     }
-    return $mimeinfo['xxx'][$element]; // Default
+    if ($cached[$mimetype] !== null && $cached[$mimetype] !== 'xxx') {
+        if ($element = 'extension') {
+            return $cached[$mimetype];
+        } else {
+            return mimeinfo($element, '.'.$cached[$mimetype]);
+        }
+    } else {
+        return mimeinfo($element, '');
+    }
 }
 
 /**
- * Get information about a filetype based on the icon file.
+ * Return the relative icon path for a given file
  *
- * @category files
- * @param string $element Desired information (usually 'icon')
- * @param string $icon Icon file name without extension
- * @param bool $all return all matching entries (defaults to false - best (by ext)/last match)
- * @return string Requested piece of information from array
+ * Usage:
+ * <code>
+ * // $file - instance of stored_file or file_info
+ * $icon = $OUTPUT->pix_url(file_file_icon($file))->out();
+ * echo html_writer::empty_tag('img', array('src' => $icon, 'alt' => get_mimetype_description($file)));
+ * </code>
+ * or
+ * <code>
+ * echo $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file));
+ * </code>
+ *
+ * @param stored_file|file_info|stdClass|array $file (in case of object attributes $file->filename
+ *     and $file->mimetype are expected)
+ * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256
+ * @return string
  */
-function mimeinfo_from_icon($element, $icon, $all=false) {
-    $mimeinfo = get_mimetypes_array();
-
-    if (preg_match("/\/(.*)/", $icon, $matches)) {
-        $icon = $matches[1];
-    }
-    // Try to get the extension
-    $extension = '';
-    if (($cutat = strrpos($icon, '.')) !== false && $cutat < strlen($icon)-1) {
-        $extension = substr($icon, $cutat + 1);
+function file_file_icon($file, $size = null) {
+    if (!is_object($file)) {
+        $file = (object)$file;
+    }
+    if (isset($file->filename)) {
+        $filename = $file->filename;
+    } else if (method_exists($file, 'get_filename')) {
+        $filename = $file->get_filename();
+    } else if (method_exists($file, 'get_visible_name')) {
+        $filename = $file->get_visible_name();
+    } else {
+        $filename = '';
     }
-    $info = array($mimeinfo['xxx'][$element]); // Default
-    foreach($mimeinfo as $key => $values) {
-        if ($values['icon']==$icon) {
-            if (isset($values[$element])) {
-                $info[$key] = $values[$element];
-            }
-            //No break, for example for 'excel' we don't want 'csv'!
-        }
+    if (isset($file->mimetype)) {
+        $mimetype = $file->mimetype;
+    } else if (method_exists($file, 'get_mimetype')) {
+        $mimetype = $file->get_mimetype();
+    } else {
+        $mimetype = '';
     }
-    if ($all) {
-        if (count($info) > 1) {
-            array_shift($info); // take off document/unknown if we have better options
-        }
-        return array_values($info); // Keep keys out when requesting all
+    if ($filename && pathinfo($filename, PATHINFO_EXTENSION) &&
+            (!$mimetype || mimeinfo('type', $filename) === $mimetype)) {
+        // files with different extensions sharing the same mimetype (i.e. 'text/plain') may have different icons
+        return file_extension_icon($filename, $size);
+    } else {
+        // if mimetype and extension do not match we assume that mimetype is more correct
+        return file_mimetype_icon($mimetype, $size);
     }
+}
 
-    // Requested only one, try to get the best by extension coincidence, else return the last
-    if ($extension && isset($info[$extension])) {
-        return $info[$extension];
+/**
+ * Return the relative icon path for a folder image
+ *
+ * Usage:
+ * <code>
+ * $icon = $OUTPUT->pix_url(file_folder_icon())->out();
+ * echo html_writer::empty_tag('img', array('src' => $icon));
+ * </code>
+ * or
+ * <code>
+ * echo $OUTPUT->pix_icon(file_folder_icon(32));
+ * </code>
+ *
+ * @param int $iconsize The size of the icon. Defaults to 16 can also be 24, 32, 48, 64, 72, 80, 96, 128, 256
+ * @return string
+ */
+function file_folder_icon($iconsize = null) {
+    global $CFG;
+    static $iconpostfixes = array(256=>'-256', 128=>'-128', 96=>'-96', 80=>'-80', 72=>'-72', 64=>'-64', 48=>'-48', 32=>'-32', 24=>'-24', 16=>'');
+    $iconsize = max(array(16, (int)$iconsize));
+    foreach ($iconpostfixes as $size => $postfix) {
+        $fullname = $CFG->dirroot.'/pix/f/folder'.$postfix;
+        if ($iconsize >= $size && (file_exists($fullname.'.png') || file_exists($fullname.'.gif'))) {
+            return 'f/folder'.$postfix;
+        }
     }
-
-    return array_pop($info); // Return last match (mimicking behaviour/comment inside foreach loop)
 }
 
 /**
@@ -1626,27 +1700,19 @@ function mimeinfo_from_icon($element, $icon, $all=false) {
  *
  * <code>
  * $mimetype = 'image/jpg';
- * $icon = $OUTPUT->pix_url(file_mimetype_icon($mimetype));
- * echo '<img src="'.$icon.'" alt="'.$mimetype.'" />';
+ * $icon = $OUTPUT->pix_url(file_mimetype_icon($mimetype))->out();
+ * echo html_writer::empty_tag('img', array('src' => $icon, 'alt' => get_mimetype_description($mimetype)));
  * </code>
  *
  * @category files
  * @todo MDL-31074 When an $OUTPUT->icon method is available this function should be altered
  * to conform with that.
  * @param string $mimetype The mimetype to fetch an icon for
- * @param int $size The size of the icon. Not yet implemented
+ * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256
  * @return string The relative path to the icon
  */
 function file_mimetype_icon($mimetype, $size = NULL) {
-    global $CFG;
-
-    $icon = mimeinfo_from_type('icon', $mimetype);
-    if ($size) {
-        if (file_exists("$CFG->dirroot/pix/f/$icon-$size.png") or file_exists("$CFG->dirroot/pix/f/$icon-$size.gif")) {
-            $icon = "$icon-$size";
-        }
-    }
-    return 'f/'.$icon;
+    return 'f/'.mimeinfo_from_type('icon'.$size, $mimetype);
 }
 
 /**
@@ -1656,9 +1722,9 @@ function file_mimetype_icon($mimetype, $size = NULL) {
  * a return the full path to an icon.
  *
  * <code>
- * $filename = 'jpg';
- * $icon = $OUTPUT->pix_url(file_extension_icon($filename));
- * echo '<img src="'.$icon.'" alt="blah" />';
+ * $filename = '.jpg';
+ * $icon = $OUTPUT->pix_url(file_extension_icon($filename))->out();
+ * echo html_writer::empty_tag('img', array('src' => $icon, 'alt' => '...'));
  * </code>
  *
  * @todo MDL-31074 When an $OUTPUT->icon method is available this function should be altered
@@ -1666,34 +1732,77 @@ function file_mimetype_icon($mimetype, $size = NULL) {
  * @todo MDL-31074 Implement $size
  * @category files
  * @param string $filename The filename to get the icon for
- * @param int $size The size of the icon. Defaults to null can also be 32
+ * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256
  * @return string
  */
 function file_extension_icon($filename, $size = NULL) {
-    global $CFG;
-
-    $icon = mimeinfo('icon', $filename);
-    if ($size) {
-        if (file_exists("$CFG->dirroot/pix/f/$icon-$size.png") or file_exists("$CFG->dirroot/pix/f/$icon-$size.gif")) {
-            $icon = "$icon-$size";
-        }
-    }
-    return 'f/'.$icon;
+    return 'f/'.mimeinfo('icon'.$size, $filename);
 }
 
 /**
  * Obtains descriptions for file types (e.g. 'Microsoft Word document') from the
  * mimetypes.php language file.
  *
- * @param string $mimetype MIME type (can be obtained using the mimeinfo function)
+ * @param mixed $obj - instance of stored_file or file_info or array/stdClass with field
+ *   'filename' and 'mimetype', or just a string with mimetype (though it is recommended to
+ *   have filename); In case of array/stdClass the field 'mimetype' is optional.
  * @param bool $capitalise If true, capitalises first character of result
  * @return string Text description
  */
-function get_mimetype_description($mimetype, $capitalise=false) {
+function get_mimetype_description($obj, $capitalise=false) {
+    if (is_object($obj) && method_exists($obj, 'get_filename') && method_exists($obj, 'get_mimetype')) {
+        // this is an instance of stored_file
+        $mimetype = $obj->get_mimetype();
+        $filename = $obj->get_filename();
+    } else if (is_object($obj) && method_exists($obj, 'get_visible_name') && method_exists($obj, 'get_mimetype')) {
+        // this is an instance of file_info
+        $mimetype = $obj->get_mimetype();
+        $filename = $obj->get_visible_name();
+    } else if (is_array($obj) || is_object ($obj)) {
+        $obj = (array)$obj;
+        if (!empty($obj['filename'])) {
+            $filename = $obj['filename'];
+        } else {
+            $filename = '';
+        }
+        if (!empty($obj['mimetype'])) {
+            $mimetype = $obj['mimetype'];
+        } else {
+            $mimetype = mimeinfo('type', $filename);
+        }
+    } else {
+        $mimetype = $obj;
+        $filename = '';
+    }
+    $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
+    if (empty($extension)) {
+        $mimetypestr = mimeinfo_from_type('string', $mimetype);
+        $extension = mimeinfo_from_type('extension', $mimetype);
+    } else {
+        $mimetypestr = mimeinfo('string', $filename);
+    }
+    $chunks = explode('/', $mimetype, 2);
+    $chunks[] = '';
+    $attr = array(
+        'mimetype' => $mimetype,
+        'ext' => $extension,
+        'mimetype1' => $chunks[0],
+        'mimetype2' => $chunks[1],
+    );
+    $a = array();
+    foreach ($attr as $key => $value) {
+        $a[$key] = $value;
+        $a[strtoupper($key)] = strtoupper($value);
+        $a[ucfirst($key)] = ucfirst($value);
+    }
     if (get_string_manager()->string_exists($mimetype, 'mimetypes')) {
-        $result = get_string($mimetype, 'mimetypes');
+        $result = get_string($mimetype, 'mimetypes', (object)$a);
+    } else if (get_string_manager()->string_exists($mimetypestr, 'mimetypes')) {
+        $result = get_string($mimetypestr, 'mimetypes', (object)$a);
+    } else if (get_string_manager()->string_exists('default', 'mimetypes')) {
+        $result = get_string('default', 'mimetypes', (object)$a);
     } else {
-        $result = get_string('document/unknown','mimetypes');
+        $result = $mimetype;
     }
     if ($capitalise) {
         $result=ucfirst($result);
@@ -1701,6 +1810,74 @@ function get_mimetype_description($mimetype, $capitalise=false) {
     return $result;
 }
 
+/**
+ * Returns array of elements of type $element in type group(s)
+ *
+ * @param string $element name of the element we are interested in, usually 'type' or 'extension'
+ * @param string|array $groups one group or array of groups/extensions/mimetypes
+ * @return array
+ */
+function file_get_typegroup($element, $groups) {
+    static $cached = array();
+    if (!is_array($groups)) {
+        $groups = array($groups);
+    }
+    if (!array_key_exists($element, $cached)) {
+        $cached[$element] = array();
+    }
+    $result = array();
+    foreach ($groups as $group) {
+        if (!array_key_exists($group, $cached[$element])) {
+            // retrieive and cache all elements of type $element for group $group
+            $mimeinfo = & get_mimetypes_array();
+            $cached[$element][$group] = array();
+            foreach ($mimeinfo as $extension => $value) {
+                $value['extension'] = $extension;
+                if (empty($value[$element])) {
+                    continue;
+                }
+                if (($group === $extension || $group === $value['type'] ||
+                        (!empty($value['groups']) && in_array($group, $value['groups']))) &&
+                        !in_array($value[$element], $cached[$element][$group])) {
+                    $cached[$element][$group][] = $value[$element];
+                }
+            }
+        }
+        $result = array_merge($result, $cached[$element][$group]);
+    }
+    return array_unique($result);
+}
+
+/**
+ * Checks if file with name $filename has one of the extensions in groups $groups
+ *
+ * @see get_mimetypes_array()
+ * @param string $filename name of the file to check
+ * @param string|array $groups one group or array of groups to check
+ * @param bool $checktype if true and extension check fails, find the mimetype and check if
+ * file mimetype is in mimetypes in groups $groups
+ * @return bool
+ */
+function file_extension_in_typegroup($filename, $groups, $checktype = false) {
+    $extension = pathinfo($filename, PATHINFO_EXTENSION);
+    if (!empty($extension) && in_array(strtolower($extension), file_get_typegroup('extension', $groups))) {
+        return true;
+    }
+    return $checktype && file_mimetype_in_typegroup(mimeinfo('type', $filename), $groups);
+}
+
+/**
+ * Checks if mimetype $mimetype belongs to one of the groups $groups
+ *
+ * @see get_mimetypes_array()
+ * @param string $mimetype
+ * @param string|array $groups one group or array of groups to check
+ * @return bool
+ */
+function file_mimetype_in_typegroup($mimetype, $groups) {
+    return !empty($mimetype) && in_array($mimetype, file_get_typegroup('type', $groups));
+}
+
 /**
  * Requested file is not found or not accessible, does not return, terminates script
  *
@@ -3165,109 +3342,6 @@ class curl_cache {
     }
 }
 
-/**
- * This class is used to parse lib/file/file_types.mm which help get file extensions by file types.
- *
- * The file_types.mm file can be edited by freemind in graphic environment.
- *
- * @package   core_files
- * @category  files
- * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class filetype_parser {
-    /**
-     * Check file_types.mm file, setup variables
-     *
-     * @global stdClass $CFG
-     * @param string $file
-     */
-    public function __construct($file = '') {
-        global $CFG;
-        if (empty($file)) {
-            $this->file = $CFG->libdir.'/filestorage/file_types.mm';
-        } else {
-            $this->file = $file;
-        }
-        $this->tree = array();
-        $this->result = array();
-    }
-
-    /**
-     * A private function to browse xml nodes
-     *
-     * @param array $parent
-     * @param array $types
-     */
-    private function _browse_nodes($parent, $types) {
-        $key = (string)$parent['TEXT'];
-        if(isset($parent->node)) {
-            $this->tree[$key] = array();
-            if (in_array((string)$parent['TEXT'], $types)) {
-                $this->_select_nodes($parent, $this->result);
-            } else {
-                foreach($parent->node as $v){
-                    $this->_browse_nodes($v, $types);
-                }
-            }
-        } else {
-            $this->tree[] = $key;
-        }
-    }
-
-    /**
-     * A private function to select text nodes
-     *
-     * @param array $parent
-     */
-    private function _select_nodes($parent){
-        if(isset($parent->node)) {
-            foreach($parent->node as $v){
-                $this->_select_nodes($v, $this->result);
-            }
-        } else {
-            $this->result[] = (string)$parent['TEXT'];
-        }
-    }
-
-
-    /**
-     * Get file extensions by file types names.
-     *
-     * @param array $types
-     * @return mixed
-     */
-    public function get_extensions($types) {
-        if (!is_array($types)) {
-            $types = array($types);
-        }
-        $this->result = array();
-        if ((is_array($types) && in_array('*', $types)) ||
-            $types == '*' || empty($types)) {
-            return array('*');
-        }
-        foreach ($types as $key=>$value){
-            if (strpos($value, '.') !== false) {
-                $this->result[] = $value;
-                unset($types[$key]);
-            }
-        }
-        if (file_exists($this->file)) {
-            $xml = simplexml_load_file($this->file);
-            foreach($xml->node->node as $v){
-                if (in_array((string)$v['TEXT'], $types)) {
-                    $this->_select_nodes($v);
-                } else {
-                    $this->_browse_nodes($v, $types);
-                }
-            }
-        } else {
-            exit('Failed to open file lib/filestorage/file_types.mm');
-        }
-        return $this->result;
-    }
-}
-
 /**
  * This function delegates file serving to individual plugins
  *
diff --git a/lib/filestorage/file_types.mm b/lib/filestorage/file_types.mm
deleted file mode 100644 (file)
index 71ff4fb..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<map version="0.7.1">
-<node ID="_Freemind_Link_1016958583" TEXT="Root">
-<node TEXT="image" POSITION="right">
-<node TEXT="web_image">
-<node ID="_Freemind_Link_750128103" TEXT=".jpg"/>
-<node ID="_Freemind_Link_1840944189" TEXT=".png"/>
-<node ID="_Freemind_Link_1710862996" TEXT=".gif"/>
-</node>
-<node TEXT="non_web_image">
-<node ID="_Freemind_Link_481322493" TEXT=".bmp"/>
-<node ID="_Freemind_Link_1948466853" TEXT=".svg"/>
-<node ID="_Freemind_Link_82277447" TEXT=".psd"/>
-</node>
-</node>
-<node TEXT="audio" POSITION="left">
-<node ID="_Freemind_Link_606456130" TEXT="web_audio">
-<node ID="_Freemind_Link_59286792" TEXT=".wav"/>
-<node ID="_Freemind_Link_618796935" TEXT=".mp3"/>
-<node ID="_Freemind_Link_313976796" TEXT=".ra"/>
-<node ID="_Freemind_Link_709595453" TEXT=".wma"/>
-<node TEXT=".ogg"/>
-<node ID="ID_421461117" TEXT=".aac"/>
-</node>
-<node ID="_Freemind_Link_1800832653" TEXT="non_web_audio">
-<node ID="_Freemind_Link_1772266185" TEXT=".ape"/>
-<node ID="_Freemind_Link_964578090" TEXT=".au"/>
-<node ID="_Freemind_Link_1295244579" TEXT=".mid"/>
-</node>
-</node>
-<node ID="_Freemind_Link_70165685" TEXT="video" POSITION="right">
-<node ID="_Freemind_Link_164412832" TEXT="web_video">
-<node ID="_Freemind_Link_1674188247" TEXT=".flv"/>
-<node ID="_Freemind_Link_1109951130" TEXT=".swf"/>
-<node ID="_Freemind_Link_441200481" TEXT=".mov"/>
-<node ID="_Freemind_Link_1073677924" TEXT=".rm"/>
-<node ID="_Freemind_Link_810187762" TEXT=".wmv"/>
-<node ID="_Freemind_Link_763870397" TEXT=".asf"/>
-<node TEXT=".ogv"/>
-<node TEXT=".f4v"/>
-<node TEXT=".m4v"/>
-<node TEXT=".webm"/>
-</node>
-<node ID="_Freemind_Link_1019644700" TEXT="non_web_video">
-<node ID="_Freemind_Link_190589975" TEXT=".avi"/>
-<node ID="_Freemind_Link_1728963308" TEXT=".mpg"/>
-<node ID="_Freemind_Link_761274675" TEXT=".mp4"/>
-</node>
-</node>
-<node ID="_Freemind_Link_1159259702" TEXT="document" POSITION="left">
-<node ID="_Freemind_Link_395227081" TEXT="msoffice">
-<node ID="_Freemind_Link_1480546733" TEXT=".doc"/>
-<node ID="_Freemind_Link_983591781" TEXT=".ppt"/>
-<node ID="_Freemind_Link_922920573" TEXT=".xls"/>
-</node>
-<node TEXT="openoffice">
-<node ID="_Freemind_Link_368708997" TEXT=".odt"/>
-<node ID="_Freemind_Link_725490871" TEXT=".odp"/>
-</node>
-<node ID="_Freemind_Link_1253224142" TEXT="other">
-<node ID="_Freemind_Link_1202332406" TEXT=".pdf"/>
-<node ID="_Freemind_Link_1229438606" TEXT=".ps"/>
-</node>
-</node>
-<node ID="_Freemind_Link_525709024" TEXT="text" POSITION="right">
-<node ID="_Freemind_Link_1252355401" TEXT="source">
-<node ID="_Freemind_Link_1783454794" TEXT=".c"/>
-<node ID="_Freemind_Link_603295666" TEXT=".cpp"/>
-<node ID="_Freemind_Link_1939719884" TEXT=".java"/>
-</node>
-<node TEXT="script">
-<node ID="_Freemind_Link_567551283" TEXT=".php"/>
-<node ID="_Freemind_Link_829963573" TEXT=".py"/>
-<node ID="_Freemind_Link_699741325" TEXT=".lua"/>
-<node ID="_Freemind_Link_841176112" TEXT=".rb"/>
-</node>
-<node ID="_Freemind_Link_466282865" TEXT="markup">
-<node ID="_Freemind_Link_776860364" TEXT=".xml"/>
-<node ID="_Freemind_Link_428374654" TEXT=".html"/>
-<node ID="_Freemind_Link_1636201602" TEXT=".xhtml"/>
-</node>
-<node TEXT="plaintext">
-<node ID="_Freemind_Link_304679617" TEXT=".txt"/>
-<node ID="_Freemind_Link_988584709" TEXT=".log"/>
-<node ID="_Freemind_Link_778232964" TEXT=".csv"/>
-</node>
-</node>
-<node ID="_Freemind_Link_329759178" TEXT="moodle" POSITION="left">
-<node ID="_Freemind_Link_864349088" TEXT=".mb.zip"/>
-<node ID="_Freemind_Link_1509389480" TEXT=".ld.zip"/>
-</node>
-<node ID="_Freemind_Link_907467024" TEXT="archive" POSITION="right">
-<node ID="_Freemind_Link_637157755" TEXT=".rar"/>
-<node ID="_Freemind_Link_628673054" TEXT=".cab"/>
-<node ID="_Freemind_Link_1141513740" TEXT=".iso"/>
-<node ID="_Freemind_Link_1269400334" TEXT=".img"/>
-<node ID="_Freemind_Link_1973736841" TEXT=".tar.gz"/>
-<node ID="_Freemind_Link_1525022758" TEXT=".zip"/>
-</node>
-<node ID="_Freemind_Link_1332471247" TEXT="application" POSITION="left">
-<node TEXT="windows">
-<node ID="_Freemind_Link_1154060414" TEXT=".exe"/>
-<node ID="_Freemind_Link_1578063867" TEXT=".dll"/>
-</node>
-<node TEXT="linux">
-<node ID="_Freemind_Link_68848485" TEXT=".bin"/>
-</node>
-<node ID="_Freemind_Link_317684862" TEXT="mac">
-<node ID="_" TEXT=".app"/>
-</node>
-</node>
-</node>
-</map>
index e9b2e3f..1885026 100644 (file)
@@ -25,7 +25,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-require_once("$CFG->libdir/filestorage/stored_file.php");
 require_once("$CFG->dirroot/repository/lib.php");
 
 /**
@@ -444,7 +443,7 @@ class stored_file {
      */
     public function is_valid_image() {
         $mimetype = $this->get_mimetype();
-        if ($mimetype !== 'image/gif' and $mimetype !== 'image/jpeg' and $mimetype !== 'image/png') {
+        if (!file_mimetype_in_typegroup($mimetype, 'web_image')) {
             return false;
         }
         if (!$info = $this->get_imageinfo()) {
index 56f6ece..09c45e7 100644 (file)
@@ -198,7 +198,7 @@ class portfolio_format_image extends portfolio_format_file {
      * @return string
      */
     public static function mimetypes() {
-        return mimeinfo_from_icon('type', 'image', true);
+        return file_get_typegroup('type', 'image');
     }
 
     /**
@@ -286,10 +286,7 @@ class portfolio_format_video extends portfolio_format_file {
       * @return array
       */
     public static function mimetypes() {
-        return array_merge(
-            mimeinfo_from_icon('type', 'video', true),
-            mimeinfo_from_icon('type', 'avi', true)
-        );
+        return file_get_typegroup('type', 'video');
     }
 }
 
@@ -561,12 +558,7 @@ class portfolio_format_document extends portfolio_format_file {
      * @return array of documents mimetypes
      */
     public static function mimetypes() {
-        return array_merge(
-            array('text/plain', 'text/rtf'),
-            mimeinfo_from_icon('type', 'word', true),
-            mimeinfo_from_icon('type', 'docx', true),
-            mimeinfo_from_icon('type', 'odt', true)
-        );
+        return file_get_typegroup('type', 'document');
     }
 }
 
@@ -588,11 +580,7 @@ class portfolio_format_spreadsheet extends portfolio_format_file {
      * @return array of documents mimetypes
      */
     public static function mimetypes() {
-        return array_merge(
-            mimeinfo_from_icon('type', 'excel', true),
-            mimeinfo_from_icon('type', 'xlsm', true),
-            mimeinfo_from_icon('type', 'ods', true)
-        );
+        return file_get_typegroup('type', 'spreadsheet');
     }
 }
 
@@ -614,6 +602,6 @@ class portfolio_format_presentation extends portfolio_format_file {
      * @return array presentation document mimetypes
      */
     public static function mimetypes() {
-        return mimeinfo_from_icon('type', 'powerpoint', true);
+        return file_get_typegroup('type', 'presentation');
     }
 }
index 8fca9b0..598969e 100644 (file)
@@ -579,20 +579,19 @@ class mod_assign_renderer extends plugin_renderer_base {
 
         $result = '<ul>';
         foreach ($dir['subdirs'] as $subdir) {
-            $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
         }
 
         foreach ($dir['files'] as $file) {
             $filename = $file->get_filename();
-            $icon = mimeinfo("icon", $filename);
             if ($CFG->enableplagiarism) {
                 require_once($CFG->libdir.'/plagiarismlib.php');
                 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
             } else {
                 $plagiarsmlinks = '';
             }
-            $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
         }
 
index 617b6fc..f82005d 100644 (file)
@@ -2118,7 +2118,7 @@ class assignment_base {
                 $filename = $file->get_filename();
                 $mimetype = $file->get_mimetype();
                 $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
-                $output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
+                $output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a>';
                 if ($CFG->enableportfolios && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                     $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $submission->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
                     $button->set_format_by_file($file);
index 2faed7a..f514e7f 100644 (file)
@@ -59,20 +59,19 @@ class mod_assignment_renderer extends plugin_renderer_base {
 
         $result = '<ul>';
         foreach ($dir['subdirs'] as $subdir) {
-            $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
         }
 
         foreach ($dir['files'] as $file) {
             $filename = $file->get_filename();
-            $icon = mimeinfo("icon", $filename);
             if ($CFG->enableplagiarism) {
                 require_once($CFG->libdir.'/plagiarismlib.php');
                 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
             } else {
                 $plagiarsmlinks = '';
             }
-            $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
         }
 
index be5a238..163bdab 100644 (file)
@@ -208,7 +208,7 @@ class assignment_online extends assignment_base {
         $popup = $OUTPUT->action_link($link, shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15), $action, array('title'=>get_string('submission', 'assignment')));
 
         $output = '<div class="files">'.
-                  '<img src="'.$OUTPUT->pix_url('f/html') . '" class="icon" alt="html" />'.
+                  $OUTPUT->pix_icon(file_extension_icon('.htm'), 'html', 'moodle', array('class' => 'icon')).
                   $popup .
                   '</div>';
                   return $output;
@@ -233,7 +233,7 @@ class assignment_online extends assignment_base {
         $popup = $OUTPUT->action_link($link, get_string('popupinnewwindow','assignment'), $action, array('title'=>get_string('submission', 'assignment')));
 
         $output = '<div class="files">'.
-                  '<img align="middle" src="'.$OUTPUT->pix_url('f/html') . '" height="16" width="16" alt="html" />'.
+                  $OUTPUT->pix_icon(file_extension_icon('.htm'), 'html', 'moodle', array('height' => 16, 'width' => 16)).
                   $popup .
                   '</div>';
 
index a14fee1..6971120 100644 (file)
@@ -1123,7 +1123,7 @@ class assignment_upload extends assignment_base {
                     $filename = $file->get_filename();
                     $mimetype = $file->get_mimetype();
                     $link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
-                    $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_mimetype_icon($mimetype),''));
+                    $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file),''));
                 }
             }
         }
index 7ffca6f..080d201 100644 (file)
@@ -42,7 +42,7 @@ class assignment_uploadsingle extends assignment_base {
                     $found = true;
                     $mimetype = $file->get_mimetype();
                     $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
-                    $output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.s($filename).'</a><br />';
+                    $output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a><br />';
                     $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
                     $output .='<br/>';
                 }
@@ -370,7 +370,7 @@ class assignment_uploadsingle extends assignment_base {
                     $filename = $file->get_filename();
                     $mimetype = $file->get_mimetype();
                     $link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment', 'submission/'.$submission->id.'/'.$filename);
-                    $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_mimetype_icon($mimetype), ''));
+                    $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file), ''));
                 }
             }
         }
index f7bd7ac..aede3f0 100644 (file)
@@ -50,7 +50,7 @@ class data_field_file extends data_field_base {
                         if (empty($content->content1)) {
                             // Print icon if file already exists
                             $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
-                            $displayname = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" class="icon" alt="'.$file->get_mimetype().'" />'. '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
+                            $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')). '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
 
                         } else {
                             $displayname = 'no file added';
@@ -142,7 +142,7 @@ class data_field_file extends data_field_base {
         $width  = $this->field->param1 ? ' width  = "'.s($this->field->param1).'" ':' ';
         $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
 
-        $str = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" height="16" width="16" alt="'.$file->get_mimetype().'" />&nbsp;'.
+        $str = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('width' => 16, 'height' => 16)). '&nbsp;'.
                '<a href="'.$src.'" >'.s($name).'</a>';
         return $str;
     }
index e587488..290558b 100644 (file)
@@ -52,7 +52,7 @@ class data_field_picture extends data_field_base {
                         if (empty($content->content1)) {
                             // Print icon if file already exists
                             $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
-                            $displayname = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" class="icon" alt="'.$file->get_mimetype().'" />'. '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
+                            $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')). '<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
 
                         } else {
                             $displayname = get_string('nofilesattached', 'repository');
index d3b609e..3d6aebd 100644 (file)
@@ -3911,7 +3911,7 @@ function forum_print_attachments($post, $cm, $type) {
         foreach ($files as $file) {
             $filename = $file->get_filename();
             $mimetype = $file->get_mimetype();
-            $iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
+            $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
             $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename);
 
             if ($type == 'html') {
index 8e25256..a50ba24 100644 (file)
@@ -1553,7 +1553,7 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
         foreach ($files as $file) {
             $filename = $file->get_filename();
             $mimetype = $file->get_mimetype();
-            $iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />';
+            $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
             $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_glossary/attachment/'.$entry->id.'/'.$filename);
 
             if ($type == 'html') {
index 3e44d09..179c507 100644 (file)
@@ -256,7 +256,7 @@ function resource_get_coursemodule_info($coursemodule) {
     $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
     if (count($files) >= 1) {
         $mainfile = reset($files);
-        $info->icon = file_extension_icon($mainfile->get_filename());
+        $info->icon = file_file_icon($mainfile);
         $resource->mainfile = $mainfile->get_filename();
     }
 
index af38003..64f7fcc 100644 (file)
@@ -303,14 +303,13 @@ function resource_get_optional_details($resource, $cm) {
             // For a typical file resource, the sortorder is 1 for the main file
             // and 0 for all other files. This sort approach is used just in case
             // there are situations where the file has a different sort order
-            $mimetype = $DB->get_field_sql(
-                    'SELECT mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC',
+            $record = $DB->get_record_sql(
+                    'SELECT filename, mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC',
                     array($context->id), IGNORE_MULTIPLE);
             // Only show type if it is not unknown
-            if ($mimetype && $mimetype !== 'document/unknown') {
-                $type = get_mimetype_description($mimetype);
-                // There are some known mimetypes which don't have descriptions
-                if ($type === get_string('document/unknown','mimetypes')) {
+            if ($record) {
+                $type = get_mimetype_description($record);
+                if ($type === get_mimetype_description('document/unknown')) {
                     $type = '';
                 }
             }
index 68664cb..c2db043 100644 (file)
@@ -549,14 +549,13 @@ function url_guess_icon($fullurl) {
 
     if (substr_count($fullurl, '/') < 3 or substr($fullurl, -1) === '/') {
         // most probably default directory - index.php, index.html, etc.
-        return 'f/web';
+        return file_extension_icon('.htm');
     }
 
-    $icon = mimeinfo('icon', $fullurl);
-    $icon = 'f/'.str_replace(array('.gif', '.png'), '', $icon);
+    $icon = file_extension_icon($fullurl);
 
-    if ($icon === 'f/html' or $icon === 'f/unknown') {
-        $icon = 'f/web';
+    if ($icon === file_extension_icon('')) {
+        return file_extension_icon('.htm');
     }
 
     return $icon;
index 14278b7..b213a94 100644 (file)
@@ -67,8 +67,7 @@ class mod_wiki_edit_form extends moodleform {
         $fieldname = get_string('format' . $format, 'wiki');
         if ($format != 'html') {
             // Use wiki editor
-            $ft = new filetype_parser;
-            $extensions = $ft->get_extensions('image');
+            $extensions = file_get_typegroup('extension', 'web_image');
             $fs = get_file_storage();
             $tree = $fs->get_area_tree($contextid, 'mod_wiki', $this->_customdata['filearea'], $this->_customdata['fileitemid']);
             $files = array();
index 4271e07..01c1849 100644 (file)
@@ -105,18 +105,18 @@ class MoodleQuickForm_wikifiletable extends HTML_QuickForm_element {
                 $checkbox .= " />";
 
                 //actions
-                $icon = mimeinfo_from_type('icon', $file->get_mimetype());
+                $icon = file_file_icon($file);
                 $file_url = file_encode_url($CFG->wwwroot.'/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/".$file->get_filename());
 
                 $action_icons = "";
                 if(!empty($tags['attach'])) {
-                    $action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/pdf')->out()."\" alt=\"Attach\" /></a>"; //TODO: localize
+                    $action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Attach")."</a>"; //TODO: localize
                 }
 
-                $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/web')->out()."\" alt=\"Link\" /></a>";
+                $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Link")."</a>";
 
-                if ($icon == 'image') {
-                    $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\"><img src=\"".$OUTPUT->pix_url('f/image')->out()."\" alt=\"Image\" /></a>"; //TODO: localize
+                if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {
+                    $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Image")."</a>"; //TODO: localize
                 }
 
                 $htmltable->data[] = array($checkbox, '<a href="'.$file_url.'">'.$file->get_filename().'</a>', $action_icons);
index 763a673..b89cdff 100644 (file)
@@ -526,14 +526,13 @@ class mod_wiki_renderer extends plugin_renderer_base {
         }
         $result = '<ul>';
         foreach ($dir['subdirs'] as $subdir) {
-            $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
         }
         foreach ($dir['files'] as $file) {
             $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_wiki/attachments/' . $tree->subwiki->id . '/'. $file->get_filepath() . $file->get_filename(), true);
             $filename = $file->get_filename();
-            $icon = mimeinfo("icon", $filename);
-            $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
         }
         $result .= '</ul>';
index d7cb903..eeee5ad 100644 (file)
@@ -749,14 +749,13 @@ class mod_workshop_renderer extends plugin_renderer_base {
             $fileurl    = file_encode_url($CFG->wwwroot . '/pluginfile.php',
                                 '/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
             $type       = $file->get_mimetype();
-            $type       = mimeinfo_from_type('type', $type);
-            $image      = html_writer::empty_tag('img', array('src'=>$this->output->pix_url(file_mimetype_icon($type)), 'alt'=>$type, 'class'=>'icon'));
+            $image      = $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
 
             $linkhtml   = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
             $linktxt    = "$filename [$fileurl]";
 
             if ($format == 'html') {
-                if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
+                if (file_mimetype_in_typegroup($type, 'web_image')) {
                     $preview     = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
                     $preview     = html_writer::tag('a', $preview, array('href' => $fileurl));
                     $outputimgs .= $this->output->container($preview);
index 061d449..afb52f8 100644 (file)
@@ -84,9 +84,8 @@ class qtype_essay_renderer extends qtype_renderer {
         $output = array();
 
         foreach ($files as $file) {
-            $mimetype = $file->get_mimetype();
             $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),
-                    $this->output->pix_icon(file_mimetype_icon($mimetype), $mimetype,
+                    $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
                     'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));
         }
         return implode($output);
index 8b8e1d8..62d9f75 100644 (file)
@@ -177,11 +177,11 @@ class repository_alfresco extends repository {
                 {
                     $ret['list'][] = array('title'=>$child->child->cm_name,
                         'path'=>$child->child->id,
-                        'thumbnail'=>$OUTPUT->pix_url('f/folder-32') . '',
+                        'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
                         'children'=>array());
                 } elseif ($child->child->type == $file_filter) {
                     $ret['list'][] = array('title'=>$child->child->cm_name,
-                        'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->child->cm_name, 32))->out(false),
+                        'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->child->cm_name, 90))->out(false),
                         'source'=>$child->child->id);
                 }
             }
index 3ff8f34..d4102d3 100644 (file)
@@ -138,7 +138,7 @@ class repository_boxnet extends repository {
                             'date'=>$filedates[$n],
                             'source'=>'http://box.net/api/1.0/download/'
                                 .$this->auth_token.'/'.$fileids[$n],
-                            'thumbnail' => $OUTPUT->pix_url(file_extension_icon($v, 32))->out(false));
+                            'thumbnail' => $OUTPUT->pix_url(file_extension_icon($v, 90))->out(false));
                 }
             }
         }
index 1045731..2f1e8fe 100644 (file)
@@ -109,7 +109,7 @@ class repository_coursefiles extends repository {
                         'datecreated' => $child->get_timecreated(),
                         'path' => $encodedpath,
                         'children'=>array(),
-                        'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false)
+                        'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)
                     );
                     $list[] = $node;
                 } else {
@@ -122,7 +122,7 @@ class repository_coursefiles extends repository {
                         'datemodified' => $child->get_timemodified(),
                         'datecreated' => $child->get_timecreated(),
                         'source'=> $encodedpath,
-                        'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->get_visible_name(), 32))->out(false)
+                        'thumbnail' => $OUTPUT->pix_url(file_file_icon($child, 90))->out(false)
                     );
                     if ($imageinfo = $child->get_imageinfo()) {
                         $fileurl = new moodle_url($child->get_url());
index d48b09f..b3f1dde 100644 (file)
@@ -303,10 +303,8 @@ default:
             if ($file->type != 'folder') {
                 $drafturl = $file->url;
                 // a file
-                $fileicon = $OUTPUT->pix_url(file_extension_icon($file->filename))->out(false);
-                $type = mimeinfo('icon', $file->filename);
                 echo '<li>';
-                echo '<img src="'.$fileicon. '" class="iconsmall" />';
+                echo $OUTPUT->pix_icon(file_file_icon($file), '', 'moodle', array('class' => 'iconsmall'));
                 echo html_writer::link($drafturl, $file->filename);
 
                 $home_url->param('filename', $file->filename);
@@ -321,7 +319,7 @@ default:
                 $home_url->param('action', 'renameform');
                 echo ' [<a href="'.$home_url->out().'" class="fm-operation">'.get_string('rename').'</a>]';
 
-                if ($type == 'zip') {
+                if (file_extension_in_typegroup($file->filename, 'archive', true)) {
                     $home_url->param('action', 'unzip');
                     $home_url->param('draftpath', $file->filepath);
                     echo ' [<a href="'.$home_url->out().'" class="fm-operation">'.get_string('unzip').'</a>]';
@@ -331,7 +329,7 @@ default:
             } else {
                 // a folder
                 echo '<li>';
-                echo '<img src="'.$OUTPUT->pix_url('f/folder') . '" class="iconsmall" />';
+                echo '<img src="'.$OUTPUT->pix_url(file_folder_icon()) . '" class="iconsmall" />';
 
                 $home_url->param('action', 'browse');
                 $home_url->param('draftpath', $file->filepath);
index 659b91a..e454615 100644 (file)
@@ -217,7 +217,7 @@ class repository_dropbox extends repository {
                     'path' => file_correct_filepath($file->path),
                     'size' => $file->size,
                     'date' => $file->modified,
-                    'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false),
+                    'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false),
                     'children' => array(),
                 );
             } else {
@@ -226,7 +226,7 @@ class repository_dropbox extends repository {
                     'source' => $file->path,
                     'size' => $file->size,
                     'date' => $file->modified,
-                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file->path, 32))->out(false)
+                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file->path, 90))->out(false)
                 );
             }
         }
index 8dcfe52..99b9dad 100644 (file)
@@ -101,7 +101,8 @@ class repository_filesystem extends repository {
                             'size' => filesize($this->root_path.$file),
                             'datecreated' => filectime($this->root_path.$file),
                             'datemodified' => filemtime($this->root_path.$file),
-                            'thumbnail' => $OUTPUT->pix_url(file_extension_icon($this->root_path.$file, 32))->out(false)
+                            'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file, 90))->out(false),
+                            'icon' => $OUTPUT->pix_url(file_extension_icon($file, 24))->out(false)
                         );
                     } else {
                         if (!empty($path)) {
@@ -114,7 +115,7 @@ class repository_filesystem extends repository {
                             'children' => array(),
                             'datecreated' => filectime($this->root_path.$file),
                             'datemodified' => filemtime($this->root_path.$file),
-                            'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false),
+                            'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false),
                             'path' => $current_path
                             );
                     }
index 20849b0..bb6c4eb 100644 (file)
@@ -844,7 +844,6 @@ abstract class repository {
         }
 
         $repositories = array();
-        $ft = new filetype_parser();
         if (isset($args['accepted_types'])) {
             $accepted_types = $args['accepted_types'];
         } else {
@@ -875,16 +874,10 @@ abstract class repository {
             } else {
                 // check mimetypes
                 if ($accepted_types !== '*' and $repository->supported_filetypes() !== '*') {
-                    $accepted_types = $ft->get_extensions($accepted_types);
-                    $supported_filetypes = $ft->get_extensions($repository->supported_filetypes());
-
-                    $is_supported = false;
-                    foreach  ($supported_filetypes as $type) {
-                        if (in_array($type, $accepted_types)) {
-                            $is_supported = true;
-                        }
-                    }
-
+                    $accepted_ext = file_get_typegroup('extension', $accepted_types);
+                    $supported_ext = file_get_typegroup('extension', $repository->supported_filetypes());
+                    $valid_ext = array_intersect($accepted_ext, $supported_ext);
+                    $is_supported = !empty($valid_ext);
                 }
                 // check return values
                 if ($returntypes !== 3 and $repository->supported_returntypes() !== 3) {
@@ -1223,7 +1216,7 @@ abstract class repository {
                     'size' => 0,
                     'date' => $filedate,
                     'path' => array_reverse($path),
-                    'thumbnail' => $OUTPUT->pix_url('f/folder-32')
+                    'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)
                 );
 
                 //if ($dynamicmode && $child->is_writable()) {
@@ -1260,7 +1253,8 @@ abstract class repository {
                     'date' => $filedate,
                     //'source' => $child->get_url(),
                     'source' => base64_encode($source),
-                    'thumbnail'=>$OUTPUT->pix_url(file_extension_icon($filename, 32)),
+                    'icon'=>$OUTPUT->pix_url(file_file_icon($child, 24))->out(false),
+                    'thumbnail'=>$OUTPUT->pix_url(file_file_icon($child, 90))->out(false),
                 );
                 $filecount++;
             }
@@ -1549,13 +1543,12 @@ abstract class repository {
      */
     final public function get_meta() {
         global $CFG, $OUTPUT;
-        $ft = new filetype_parser;
         $meta = new stdClass();
         $meta->id   = $this->id;
         $meta->name = $this->get_name();
         $meta->type = $this->options['type'];
         $meta->icon = $OUTPUT->pix_url('icon', 'repository_'.$meta->type)->out(false);
-        $meta->supported_types = $ft->get_extensions($this->supported_filetypes());
+        $meta->supported_types = file_get_typegroup('extension', $this->supported_filetypes());
         $meta->return_types = $this->supported_returntypes();
         $meta->sortorder = $this->options['sortorder'];
         return $meta;
@@ -1724,35 +1717,26 @@ abstract class repository {
      * @return bool
      */
     public function filter(&$value) {
-        $pass = false;
         $accepted_types = optional_param_array('accepted_types', '', PARAM_RAW);
-        $ft = new filetype_parser;
-        //$ext = $ft->get_extensions($this->supported_filetypes());
         if (isset($value['children'])) {
-            $pass = true;
             if (!empty($value['children'])) {
                 $value['children'] = array_filter($value['children'], array($this, 'filter'));
             }
+            return true; // always return directories
         } else {
             if ($accepted_types == '*' or empty($accepted_types)
                 or (is_array($accepted_types) and in_array('*', $accepted_types))) {
-                $pass = true;
-            } elseif (is_array($accepted_types)) {
-                foreach ($accepted_types as $type) {
-                    $extensions = $ft->get_extensions($type);
-                    if (!is_array($extensions)) {
-                        $pass = true;
-                    } else {
-                        foreach ($extensions as $ext) {
-                            if (preg_match('#'.$ext.'$#i', $value['title'])) {
-                                $pass = true;
-                            }
-                        }
+                return true;
+            } else {
+                $extensions = file_get_typegroup('extension', $accepted_types);
+                foreach ($extensions as $ext) {
+                    if (preg_match('#\.'.$ext.'$#i', $value['title'])) {
+                        return true;
                     }
                 }
             }
         }
-        return $pass;
+        return false;
     }
 
     /**
@@ -1843,17 +1827,13 @@ abstract class repository {
                 $filename = $file['fullname'];
             }
             if (!isset($file['mimetype']) && !$isfolder && $filename) {
-                $mimetype = mimeinfo('type', $filename);
-                if (get_string_manager()->string_exists($mimetype, 'mimetypes')) {
-                    $mimetype = get_string($mimetype, 'mimetypes');
-                }
-                $file['mimetype'] = $mimetype;
+                $file['mimetype'] = get_mimetype_description(array('filename' => $filename));
             }
             if (!isset($file['icon'])) {
                 if ($isfolder) {
-                    $file['icon'] = $OUTPUT->pix_url('f/folder')->out(false);
+                    $file['icon'] = $OUTPUT->pix_url(file_folder_icon(24))->out(false);
                 } else if ($filename) {
-                    $file['icon'] = $OUTPUT->pix_url('f/'.mimeinfo('icon', $filename))->out(false);
+                    $file['icon'] = $OUTPUT->pix_url(file_extension_icon($filename, 24))->out(false);
                 }
             }
             if ($converttoobject) {
@@ -2455,7 +2435,6 @@ function initialise_filepicker($args) {
 
     $return->author = fullname($USER);
 
-    $ft = new filetype_parser();
     if (empty($args->context)) {
         $context = $PAGE->context;
     } else {
@@ -2492,7 +2471,7 @@ function initialise_filepicker($args) {
     }
 
     // provided by form element
-    $return->accepted_types = $ft->get_extensions($args->accepted_types);
+    $return->accepted_types = file_get_typegroup('extension', $args->accepted_types);
     $return->return_types = $args->return_types;
     foreach ($repositories as $repository) {
         $meta = $repository->get_meta();
index 9c204a9..72ba3d3 100644 (file)
@@ -213,14 +213,15 @@ class repository_local_file {
         );
         if ($this->isdir) {
             $node['path'] = $encodedpath;
-            $node['thumbnail'] = $OUTPUT->pix_url('f/folder-32')->out(false);
+            $node['thumbnail'] = $OUTPUT->pix_url(file_folder_icon(90))->out(false);
             $node['children'] = array();
         } else {
             $node['size'] = $this->fileinfo->get_filesize();
             $node['author'] = $this->fileinfo->get_author();
             $node['license'] = $this->fileinfo->get_license();
             $node['source'] = $encodedpath;
-            $node['thumbnail'] = $OUTPUT->pix_url(file_extension_icon($node['title'], 32))->out(false);
+            $node['thumbnail'] = $OUTPUT->pix_url(file_file_icon($this->fileinfo, 90))->out(false);
+            $node['icon'] = $OUTPUT->pix_url(file_file_icon($this->fileinfo), 24)->out(false);
             if ($imageinfo = $this->fileinfo->get_imageinfo()) {
                 // what a beautiful picture, isn't it
                 $fileurl = new moodle_url($this->fileinfo->get_url());
index 7f87643..0ad1418 100644 (file)
@@ -92,7 +92,7 @@ class repository_merlot extends repository {
         foreach ($xml->results->material as $entry) {
             $list[] = array(
                 'title'=>(string)$entry->title,
-                'thumbnail'=>$OUTPUT->pix_url('f/unknown-32')->out(false),
+                'thumbnail'=>$OUTPUT->pix_url(file_extension_icon($entry->title, 90))->out(false),
                 'date'=>userdate((int)$entry->creationDate),
                 'size'=>'',
                 'source'=>(string)$entry->URL
index f7d91d4..a491015 100644 (file)
@@ -128,14 +128,15 @@ class repository_recent extends repository {
                 if ($fileinfo) {
                     $params = base64_encode(serialize($file));
                     $node = array(
-                        'title' => $file['filename'],
+                        'title' => $fileinfo->get_visible_name(),
                         'size' => $fileinfo->get_filesize(),
                         'datemodified' => $fileinfo->get_timemodified(),
                         'datecreated' => $fileinfo->get_timecreated(),
                         'author' => $fileinfo->get_author(),
                         'license' => $fileinfo->get_license(),
                         'source'=> $params,
-                        'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['filename'], 32))->out(false),
+                        'icon' => $OUTPUT->pix_url(file_file_icon($fileinfo, 24))->out(false),
+                        'thumbnail' => $OUTPUT->pix_url(file_file_icon($fileinfo, 90))->out(false),
                     );
                     if ($imageinfo = $fileinfo->get_imageinfo()) {
                         $fileurl = new moodle_url($fileinfo->get_url());
index 55c65eb..c004388 100644 (file)
@@ -181,7 +181,7 @@ switch ($action) {
                 $mimetypes[] = mimeinfo('type', $type);
             }
             if (!in_array(mimeinfo('type', $saveas_filename), $mimetypes)) {
-                throw new moodle_exception('invalidfiletype', 'repository', '', get_string(mimeinfo('type', $saveas_filename), 'mimetypes'));
+                throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $saveas_filename)));
             }
         }
 
@@ -266,7 +266,6 @@ switch ($action) {
             $record->timecreated  = $now;
             $record->timemodified = $now;
             $record->userid       = $USER->id;
-            $record->mimetype     = mimeinfo('type', $record->filename);
 
 
             if ($usefilereference == 'yes') {
@@ -304,7 +303,7 @@ switch ($action) {
                     'url'=>moodle_url::make_draftfile_url($storedfile->get_itemid(), $storedfile->get_filepath(), $storedfile->get_filename())->out(),
                     'id'=>$storedfile->get_itemid(),
                     'file'=>$storedfile->get_filename(),
-                    'icon' => $OUTPUT->pix_url(file_extension_icon($storedfile->get_filename(), 32))->out(),
+                    'icon' => $OUTPUT->pix_url(file_file_icon($storedfile, 32))->out(),
                 );
                 echo json_encode($info);
                 die;
index b74a87d..2479050 100644 (file)
@@ -78,7 +78,7 @@ class repository_s3 extends repository {
                 $folder = array(
                     'title' => $bucket,
                     'children' => array(),
-                    'thumbnail'=>$OUTPUT->pix_url('f/folder-32')->out(false),
+                    'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
                     'path'=>$bucket
                     );
                 $tree[] = $folder;
@@ -92,7 +92,7 @@ class repository_s3 extends repository {
                     'size'=>$file['size'],
                     'date'=>userdate($file['time']),
                     'source'=>$path.'/'.$file['name'],
-                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['name'], 32))->out(false)
+                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['name'], 90))->out(false)
                     );
             }
         }
index cd5ac10..db029d1 100644 (file)
@@ -201,18 +201,18 @@ class repository_upload extends repository {
             $event['newfile'] = new stdClass;
             $event['newfile']->filepath = $record->filepath;
             $event['newfile']->filename = $unused_filename;
-            $event['newfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $unused_filename)->out();
+            $event['newfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $unused_filename)->out(false);
 
             $event['existingfile'] = new stdClass;
             $event['existingfile']->filepath = $record->filepath;
             $event['existingfile']->filename = $existingfilename;
-            $event['existingfile']->url      = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $existingfilename)->out();;
+            $event['existingfile']->url      = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $existingfilename)->out(false);
             return $event;
         } else {
             $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']);
 
             return array(
-                'url'=>moodle_url::make_draftfile_url($record->itemid, $record->filepath, $record->filename)->out(),
+                'url'=>moodle_url::make_draftfile_url($record->itemid, $record->filepath, $record->filename)->out(false),
                 'id'=>$record->itemid,
                 'file'=>$record->filename);
         }
index d15f572..7a46557 100644 (file)
@@ -100,7 +100,7 @@ class repository_user extends repository {
                             'datecreated' => $child->get_timecreated(),
                             'path' => $encodedpath,
                             'children'=>array(),
-                            'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false)
+                            'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)
                         );
                         $list[] = $node;
                     } else {
@@ -113,7 +113,8 @@ class repository_user extends repository {
                             'author' => $child->get_author(),
                             'license' => $child->get_license(),
                             'source'=> $encodedpath,
-                            'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->get_visible_name(), 32))->out(false)
+                            'icon' => $OUTPUT->pix_url(file_file_icon($child, 24))->out(false),
+                            'thumbnail' => $OUTPUT->pix_url(file_file_icon($child, 90))->out(false)
                         );
                         if ($imageinfo = $child->get_imageinfo()) {
                             $fileurl = new moodle_url($child->get_url());
index bccb7f0..a8d4bb9 100644 (file)
@@ -127,7 +127,7 @@ class repository_webdav extends repository {
                 if ($path != $v['href']) {
                     $folders[] = array(
                         'title'=>$title,
-                        'thumbnail'=>$OUTPUT->pix_url('f/folder-32')->out(false),
+                        'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
                         'children'=>array(),
                         'datemodified'=>$v['lastmodified'],
                         'path'=>$v['href']
@@ -138,7 +138,7 @@ class repository_webdav extends repository {
                 $size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';
                 $files[] = array(
                     'title'=>$title,
-                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 32))->out(false),
+                    'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false),
                     'size'=>$size,
                     'datemodified'=>$v['lastmodified'],
                     'source'=>$v['href']
index ce186b8..d02b181 100644 (file)
@@ -118,9 +118,9 @@ class wikimedia {
             $commons_main_dir = 'http://upload.wikimedia.org/wikipedia/commons/';
             if ($image_url) {
                 $short_path = str_replace($commons_main_dir, '', $image_url);
-                $extension = pathinfo($short_path, PATHINFO_EXTENSION);
+                $extension = strtolower(pathinfo($short_path, PATHINFO_EXTENSION));
                 if (strcmp($extension, 'gif') == 0) {  //no thumb for gifs
-                    return $OUTPUT->pix_url(file_extension_icon('xx.jpg', 32));
+                    return $OUTPUT->pix_url(file_extension_icon('.gif', $thumb_width))->out(false);
                 }
                 $dir_parts = explode('/', $short_path);
                 $file_name = end($dir_parts);
index 73212d5..09f30d7 100644 (file)
@@ -64,14 +64,13 @@ class core_user_renderer extends plugin_renderer_base {
         }
         $result = '<ul>';
         foreach ($dir['subdirs'] as $subdir) {
-            $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
         }
         foreach ($dir['files'] as $file) {
             $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
             $filename = $file->get_filename();
-            $icon = mimeinfo("icon", $filename);
-            $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
         }
         $result .= '</ul>';