Browse files

MDL-32247,MDL-32831,MDL-32900 Use correct url building of file type i…

…cons

- 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)
  • Loading branch information...
1 parent 8177b7b commit 559276b153640310d6c7fa3695f8d71ad0396f39 @marinaglancy marinaglancy committed May 21, 2012
Showing with 523 additions and 587 deletions.
  1. +2 −3 admin/tool/unittest/coveragefile.php
  2. +4 −1 blocks/activity_modules/block_activity_modules.php
  3. +2 −3 blocks/private_files/renderer.php
  4. +2 −5 blog/locallib.php
  5. +0 −7 course/lib.php
  6. +2 −2 files/filebrowser_ajax.php
  7. +22 −15 files/renderer.php
  8. +2 −1 grade/lib.php
  9. +26 −9 lang/en/mimetypes.php
  10. +363 −289 lib/filelib.php
  11. +0 −112 lib/filestorage/file_types.mm
  12. +1 −2 lib/filestorage/stored_file.php
  13. +5 −17 lib/portfolio/formats.php
  14. +2 −3 mod/assign/renderer.php
  15. +1 −1 mod/assignment/lib.php
  16. +2 −3 mod/assignment/renderer.php
  17. +2 −2 mod/assignment/type/online/assignment.class.php
  18. +1 −1 mod/assignment/type/upload/assignment.class.php
  19. +2 −2 mod/assignment/type/uploadsingle/assignment.class.php
  20. +2 −2 mod/data/field/file/field.class.php
  21. +1 −1 mod/data/field/picture/field.class.php
  22. +1 −1 mod/forum/lib.php
  23. +1 −1 mod/glossary/lib.php
  24. +1 −1 mod/resource/lib.php
  25. +5 −6 mod/resource/locallib.php
  26. +4 −5 mod/url/locallib.php
  27. +1 −2 mod/wiki/edit_form.php
  28. +5 −5 mod/wiki/editors/wikifiletable.php
  29. +2 −3 mod/wiki/renderer.php
  30. +2 −3 mod/workshop/renderer.php
  31. +1 −2 question/type/essay/renderer.php
  32. +2 −2 repository/alfresco/lib.php
  33. +1 −1 repository/boxnet/lib.php
  34. +2 −2 repository/coursefiles/lib.php
  35. +3 −5 repository/draftfiles_manager.php
  36. +2 −2 repository/dropbox/lib.php
  37. +3 −2 repository/filesystem/lib.php
  38. +20 −41 repository/lib.php
  39. +3 −2 repository/local/lib.php
  40. +1 −1 repository/merlot/lib.php
  41. +3 −2 repository/recent/lib.php
  42. +2 −3 repository/repository_ajax.php
  43. +2 −2 repository/s3/lib.php
  44. +3 −3 repository/upload/lib.php
  45. +3 −2 repository/user/lib.php
  46. +2 −2 repository/webdav/lib.php
  47. +2 −2 repository/wikimedia/wikimedia.php
  48. +2 −3 user/renderer.php
View
5 admin/tool/unittest/coveragefile.php
@@ -60,9 +60,8 @@
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');
}
View
5 blocks/activity_modules/block_activity_modules.php
@@ -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 @@ function get_content() {
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;';
View
5 blocks/private_files/renderer.php
@@ -65,14 +65,13 @@ protected function htmllize_tree($tree, $dir) {
}
$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>';
View
7 blog/locallib.php
@@ -513,10 +513,7 @@ public function print_attachments($return=false) {
$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 @@ public function print_attachments($return=false) {
$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);
View
7 course/lib.php
@@ -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.
View
4 files/filebrowser_ajax.php
@@ -70,10 +70,10 @@
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;
}
View
37 files/renderer.php
@@ -56,25 +56,31 @@ public function render_files_tree_viewer(files_tree_viewer $tree) {
$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 @@ public function __construct(file_info $file_info, array $options = null) {
$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()) {
View
3 grade/lib.php
@@ -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 @@ public function get_element_icon(&$element, $spacerifnone=false) {
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).'" />';
}
View
35 lang/en/mimetypes.php
@@ -18,22 +18,39 @@
/**
* 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';
View
652 lib/filelib.php
@@ -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,65 +1321,90 @@ 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.
* Associative array of extension (lower-case) to associative array
* 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,33 +1500,33 @@ 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'),
'xlam' => array ('type'=>'application/vnd.ms-excel.addin.macroEnabled.12', 'icon'=>'xlam'),
'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,44 +1722,87 @@ 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
* to conform with that.
* @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);
@@ -1702,6 +1811,74 @@ function get_mimetype_description($mimetype, $capitalise=false) {
}
/**
+ * 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
*
* @global stdClass $CFG
@@ -3166,109 +3343,6 @@ public function refresh() {
}
/**
- * 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
*
* @param string $relativepath
View
112 lib/filestorage/file_types.mm
@@ -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>
View
3 lib/filestorage/stored_file.php
@@ -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 @@ public function get_imageinfo() {
*/
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()) {
View
22 lib/portfolio/formats.php
@@ -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');
}
}
View
5 mod/assign/renderer.php
@@ -579,20 +579,19 @@ protected function htmllize_tree(assign_files $tree, $dir) {
$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>';
}
View
2 mod/assignment/lib.php
@@ -2118,7 +2118,7 @@ function print_user_files($userid=0, $return=false) {
$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);
View
5 mod/assignment/renderer.php
@@ -59,20 +59,19 @@ protected function htmllize_tree($tree, $dir) {
$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>';
}
View
4 mod/assignment/type/online/assignment.class.php
@@ -208,7 +208,7 @@ function print_student_answer($userid, $return=false){
$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 @@ function print_user_files($userid=0, $return=false) {
$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>';
View
2 mod/assignment/type/upload/assignment.class.php
@@ -1123,7 +1123,7 @@ function extend_settings_navigation($node) {
$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),''));
}
}
}
View
4 mod/assignment/type/uploadsingle/assignment.class.php
@@ -42,7 +42,7 @@ function print_student_answer($userid, $return=false){
$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 />';