diff --git a/lib/filelib.php b/lib/filelib.php index aa46e625863..48f8c3632a7 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -3612,7 +3612,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { } // fix file name automatically - if ($filename !== 'f1' and $filename !== 'f2') { + if ($filename !== 'f1' and $filename !== 'f2' and $filename !== 'f3') { $filename = 'f1'; } @@ -3625,20 +3625,28 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { redirect($theme->pix_url('u/'.$filename, 'moodle')); // intentionally not cached } - if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'/.png')) { - if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'/.jpg')) { - // bad reference - try to prevent future retries as hard as possible! - if ($user = $DB->get_record('user', array('id'=>$context->instanceid), 'id, picture')) { - if ($user->picture == 1 or $user->picture > 10) { - $DB->set_field('user', 'picture', 0, array('id'=>$user->id)); + if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'.png')) { + if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', $filename.'.jpg')) { + if ($filename === 'f3') { + // f3 400x400px was introduced in 2.3, there might be only the smaller version. + if (!$file = $fs->get_file($context->id, 'user', 'icon', 0, '/', 'f1.png')) { + $file = $fs->get_file($context->id, 'user', 'icon', 0, '/', 'f1.jpg'); } } - // no redirect here because it is not cached - $theme = theme_config::load($themename); - $imagefile = $theme->resolve_image_location('u/'.$filename, 'moodle'); - send_file($imagefile, basename($imagefile), 60*60*24*14); } } + if (!$file) { + // bad reference - try to prevent future retries as hard as possible! + if ($user = $DB->get_record('user', array('id'=>$context->instanceid), 'id, picture')) { + if ($user->picture > 0) { + $DB->set_field('user', 'picture', 0, array('id'=>$user->id)); + } + } + // no redirect here because it is not cached + $theme = theme_config::load($themename); + $imagefile = $theme->resolve_image_location('u/'.$filename, 'moodle'); + send_file($imagefile, basename($imagefile), 60*60*24*14); + } send_stored_file($file, 60*60*24*365, 0, false, array('preview' => $preview)); // enable long caching, there are many images on each page diff --git a/lib/gdlib.php b/lib/gdlib.php index 68d891aac81..65e6d5ebd7b 100644 --- a/lib/gdlib.php +++ b/lib/gdlib.php @@ -166,19 +166,27 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil if (function_exists('imagecreatetruecolor') and $CFG->gdversion >= 2) { $im1 = imagecreatetruecolor(100, 100); $im2 = imagecreatetruecolor(35, 35); + $im3 = imagecreatetruecolor(512, 512); if ($image->type == IMAGETYPE_PNG and $imagefnc === 'imagepng') { imagealphablending($im1, false); $color = imagecolorallocatealpha($im1, 0, 0, 0, 127); imagefill($im1, 0, 0, $color); imagesavealpha($im1, true); + imagealphablending($im2, false); $color = imagecolorallocatealpha($im2, 0, 0, 0, 127); imagefill($im2, 0, 0, $color); imagesavealpha($im2, true); + + imagealphablending($im3, false); + $color = imagecolorallocatealpha($im3, 0, 0, 0, 127); + imagefill($im3, 0, 0, $color); + imagesavealpha($im3, true); } } else { $im1 = imagecreate(100, 100); $im2 = imagecreate(35, 35); + $im3 = imagecreate(512, 512); } $cx = $image->width / 2; @@ -192,6 +200,7 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil imagecopybicubic($im1, $im, 0, 0, $cx - $half, $cy - $half, 100, 100, $half * 2, $half * 2); imagecopybicubic($im2, $im, 0, 0, $cx - $half, $cy - $half, 35, 35, $half * 2, $half * 2); + imagecopybicubic($im3, $im, 0, 0, $cx - $half, $cy - $half, 512, 512, $half * 2, $half * 2); $fs = get_file_storage(); @@ -220,6 +229,17 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil $icon['filename'] = 'f2'.$imageext; $fs->create_file_from_string($icon, $data); + ob_start(); + if (!$imagefnc($im3, NULL, $quality, $filters)) { + ob_end_clean(); + $fs->delete_area_files($context->id, $component, $filearea, $itemid); + return false; + } + $data = ob_get_clean(); + imagedestroy($im3); + $icon['filename'] = 'f3'.$imageext; + $fs->create_file_from_string($icon, $data); + return $file1->get_id(); } diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 514eac9b055..4bd0673dc2b 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -321,6 +321,9 @@ class user_picture implements renderable { } else if ($this->size === true or $this->size == 1) { $filename = 'f1'; $size = 100; + } else if ($this->size > 100) { + $filename = 'f3'; + $size = (int)$this->size; } else if ($this->size >= 50) { $filename = 'f1'; $size = (int)$this->size; diff --git a/pix/u/f3.png b/pix/u/f3.png new file mode 100644 index 00000000000..27e35162046 Binary files /dev/null and b/pix/u/f3.png differ diff --git a/theme/upgrade.txt b/theme/upgrade.txt index 4e9b5f1a37a..4d18a33411a 100644 --- a/theme/upgrade.txt +++ b/theme/upgrade.txt @@ -2,6 +2,11 @@ This files describes API changes in /theme/* themes, information provided here is intended especially for theme designer. +=== 2.3 === + +optional changes: +* add new u/f3.png image when theme contains customised f1 and f2 default user images + === 2.2 === required changes: