Skip to content

Commit

Permalink
MDL-32247,MDL-32831,MDL-32900 Use correct url building of file type i…
Browse files Browse the repository at this point in the history
…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
marinaglancy committed May 21, 2012
1 parent 8177b7b commit 559276b
Show file tree
Hide file tree
Showing 48 changed files with 523 additions and 587 deletions.
5 changes: 2 additions & 3 deletions admin/tool/unittest/coveragefile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
5 changes: 4 additions & 1 deletion blocks/activity_modules/block_activity_modules.php
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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;';
Expand Down
5 changes: 2 additions & 3 deletions blocks/private_files/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
Expand Down
7 changes: 2 additions & 5 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions files/filebrowser_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
37 changes: 22 additions & 15 deletions files/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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).'" />';
}

Expand Down
35 changes: 26 additions & 9 deletions lang/en/mimetypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading

0 comments on commit 559276b

Please sign in to comment.