BUGFIX Resolve local images correctly even with absolute URLs in HTMLEditorConfig_Toolbar, fixed display of remote images (don't try to format the thumbnail, which only works on local images) (fixes #6952)

This commit is contained in:
Ingo Schommer 2012-03-12 16:31:32 +01:00
parent 4fc3aaf939
commit 95f1800d80

View File

@ -427,14 +427,20 @@ class HtmlEditorField_Toolbar extends RequestHandler {
// TODO Would be cleaner to consistently pass URL for both local and remote files,
// but GridField doesn't allow for this kind of metadata customization at the moment.
if($url = $request->getVar('FileURL')) {
if(Director::is_absolute_url($url)) {
if(Director::is_absolute_url($url) && !Director::is_site_url($url)) {
$url = $url;
$file = null;
$file = new File(array(
'Title' => basename($url),
'Filename' => $url
));
} else {
$url = Director::makeRelative($request->getVar('FileURL'));
$url = preg_replace('/_resampled/[^-]+-/', '', $url);
$url = preg_replace('/_resampled\/[^-]+-/', '', $url);
$file = DataList::create('File')->filter('Filename', $url)->first();
if(!$file) $file = new File(array('Title' => basename($url)));
if(!$file) $file = new File(array(
'Title' => basename($url),
'Filename' => $url
));
}
} elseif($id = $request->getVar('ID')) {
$file = DataObject::get_by_id('File', $id);
@ -449,6 +455,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
} else {
$fileWrapper = new HtmlEditorField_File($url, $file);
}
$fields = $this->getFieldsForFile($url, $fileWrapper);
$this->extend('updateFieldsForFile', $fields, $url, $fileWrapper);
@ -504,10 +511,15 @@ class HtmlEditorField_Toolbar extends RequestHandler {
* @return FieldList
*/
protected function getFieldsForImage($url, $file) {
$formattedImage = $file->getFormattedImage('SetWidth', Image::$asset_preview_width);
$thumbnail = $formattedImage ? $formattedImage->URL : '';
if($file instanceof Image) {
$formattedImage = $file->FormattedImage('SetWidth', Image::$asset_preview_width);
$thumbnailURL = $formattedImage ? $formattedImage->URL : $url;
} else {
$thumbnailURL = $url;
}
$previewField = new LiteralField("ImageFull",
"<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnail}?r=" . rand(1,100000) . "' alt='{$file->Name}' />\n"
"<img id='thumbnailImage' class='thumbnail-preview' src='{$thumbnailURL}?r=" . rand(1,100000) . "' alt='{$file->Name}' />\n"
);
$fields = new FieldList(