MDL-33158 fixed bugs with restricting file typs in filepicker
- extension was returned without leading dot which resulted in improper validation - fixed human-readable mime type in error message - fixed youtube repository to support video files and pass filetype validation
This commit is contained in:
+6
-6
@@ -1595,22 +1595,22 @@ function mimeinfo_from_type($element, $mimetype) {
|
||||
foreach($mimeinfo as $filetype => $values) {
|
||||
if ($values['type'] == $mimetype) {
|
||||
if ($cached[$mimetype] === null) {
|
||||
$cached[$mimetype] = $filetype;
|
||||
$cached[$mimetype] = '.'.$filetype;
|
||||
}
|
||||
if (!empty($values['defaulticon'])) {
|
||||
$cached[$mimetype] = $filetype;
|
||||
$cached[$mimetype] = '.'.$filetype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($cached[$mimetype])) {
|
||||
$cached[$mimetype] = 'xxx';
|
||||
$cached[$mimetype] = '.xxx';
|
||||
}
|
||||
}
|
||||
if ($element === 'extension') {
|
||||
return $cached[$mimetype];
|
||||
} else {
|
||||
return mimeinfo($element, '.'.$cached[$mimetype]);
|
||||
return mimeinfo($element, $cached[$mimetype]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1831,7 +1831,7 @@ function file_get_typegroup($element, $groups) {
|
||||
$mimeinfo = & get_mimetypes_array();
|
||||
$cached[$element][$group] = array();
|
||||
foreach ($mimeinfo as $extension => $value) {
|
||||
$value['extension'] = $extension;
|
||||
$value['extension'] = '.'.$extension;
|
||||
if (empty($value[$element])) {
|
||||
continue;
|
||||
}
|
||||
@@ -1859,7 +1859,7 @@ function file_get_typegroup($element, $groups) {
|
||||
*/
|
||||
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))) {
|
||||
if (!empty($extension) && in_array('.'.strtolower($extension), file_get_typegroup('extension', $groups))) {
|
||||
return true;
|
||||
}
|
||||
return $checktype && file_mimetype_in_typegroup(mimeinfo('type', $filename), $groups);
|
||||
|
||||
+2
-3
@@ -1728,9 +1728,8 @@ abstract class repository {
|
||||
or (is_array($accepted_types) and in_array('*', $accepted_types))) {
|
||||
return true;
|
||||
} else {
|
||||
$extensions = file_get_typegroup('extension', $accepted_types);
|
||||
foreach ($extensions as $ext) {
|
||||
if (preg_match('#\.'.$ext.'$#i', $value['title'])) {
|
||||
foreach ($accepted_types as $ext) {
|
||||
if (preg_match('#'.$ext.'$#i', $value['title'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,10 +173,7 @@ class repository_upload extends repository {
|
||||
// check filetype
|
||||
$filemimetype = mimeinfo('type', $_FILES[$elname]['name']);
|
||||
if (!in_array($filemimetype, $this->mimetypes)) {
|
||||
if ($sm->string_exists($filemimetype, 'mimetypes')) {
|
||||
$filemimetype = get_string($filemimetype, 'mimetypes');
|
||||
}
|
||||
throw new moodle_exception('invalidfiletype', 'repository', '', $filemimetype);
|
||||
throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $_FILES[$elname]['name'])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,17 +111,23 @@ class repository_youtube extends repository {
|
||||
$links = $xml->children('http://www.w3.org/2005/Atom');
|
||||
foreach ($xml->entry as $entry) {
|
||||
$media = $entry->children('http://search.yahoo.com/mrss/');
|
||||
$title = $media->group->title;
|
||||
$title = (string)$media->group->title;
|
||||
$description = (string)$media->group->description;
|
||||
if (empty($description)) {
|
||||
$description = $title;
|
||||
}
|
||||
$attrs = $media->group->thumbnail[2]->attributes();
|
||||
$thumbnail = $attrs['url'];
|
||||
$arr = explode('/', $entry->id);
|
||||
$id = $arr[count($arr)-1];
|
||||
$source = 'http://www.youtube.com/v/' . $id . '#' . $title;
|
||||
$list[] = array(
|
||||
'title'=>(string)$title,
|
||||
'shorttitle'=>$title,
|
||||
'thumbnail_title'=>$description,
|
||||
'title'=>$title.'.avi', // this is a hack so we accept this file by extension
|
||||
'thumbnail'=>(string)$attrs['url'],
|
||||
'thumbnail_width'=>150,
|
||||
'thumbnail_height'=>120,
|
||||
'thumbnail_width'=>(int)$attrs['width'],
|
||||
'thumbnail_height'=>(int)$attrs['height'],
|
||||
'size'=>'',
|
||||
'date'=>'',
|
||||
'source'=>$source
|
||||
@@ -186,7 +192,7 @@ class repository_youtube extends repository {
|
||||
* @return array
|
||||
*/
|
||||
public function supported_filetypes() {
|
||||
return array('web_video');
|
||||
return array('video');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user