mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX insertion of images (trac #7438)
Allow insertion of images via oEmbed dialog using a direct url
This commit is contained in:
parent
e2d7352c81
commit
e582935582
@ -515,7 +515,8 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Instanciate file wrapper and get fields based on its type
|
// Instanciate file wrapper and get fields based on its type
|
||||||
if($file && $file->appCategory() == 'image') {
|
// Check if appCategory is an image and exists on the local system, otherwise use oEmbed to refference a remote image
|
||||||
|
if($file && $file->appCategory() == 'image' && Director::is_site_url($url)) {
|
||||||
$fileWrapper = new HtmlEditorField_Image($url, $file);
|
$fileWrapper = new HtmlEditorField_Image($url, $file);
|
||||||
} elseif(!Director::is_site_url($url)) {
|
} elseif(!Director::is_site_url($url)) {
|
||||||
$fileWrapper = new HtmlEditorField_Embed($url, $file);
|
$fileWrapper = new HtmlEditorField_Embed($url, $file);
|
||||||
|
@ -132,6 +132,13 @@ class Oembed {
|
|||||||
$oembedUrl = Controller::join_links($endpoint, '?format=json&url=' . rawurlencode($url));
|
$oembedUrl = Controller::join_links($endpoint, '?format=json&url=' . rawurlencode($url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If autodescovery failed the resource might be a direct link to a file
|
||||||
|
if(!$oembedUrl) {
|
||||||
|
if(File::get_app_category(File::get_file_extension($url))) {
|
||||||
|
return new Oembed_Result($url, $url, $type, $options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($oembedUrl) {
|
if($oembedUrl) {
|
||||||
// Inject the options into the Oembed URL.
|
// Inject the options into the Oembed URL.
|
||||||
if($options) {
|
if($options) {
|
||||||
@ -233,7 +240,20 @@ class Oembed_Result extends ViewableData {
|
|||||||
$body = $body->getBody();
|
$body = $body->getBody();
|
||||||
$data = json_decode($body, true);
|
$data = json_decode($body, true);
|
||||||
if(!$data) {
|
if(!$data) {
|
||||||
|
// if the response is no valid JSON we might have received a binary stream to an image
|
||||||
$data = array();
|
$data = array();
|
||||||
|
$image = @imagecreatefromstring($body);
|
||||||
|
if($image !== FALSE) {
|
||||||
|
preg_match("/^(http:\/\/)?([^\/]+)/i", $this->url, $matches);
|
||||||
|
$protocoll = $matches[1];
|
||||||
|
$host = $matches[2];
|
||||||
|
$data['type'] = "photo";
|
||||||
|
$data['title'] = basename($this->url) . " ($host)";
|
||||||
|
$data['url'] = $this->url;
|
||||||
|
$data['provider_url'] = $protocoll.$host;
|
||||||
|
$data['width'] = imagesx($image);
|
||||||
|
$data['height'] = imagesy($image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert all keys to lowercase
|
// Convert all keys to lowercase
|
||||||
|
Loading…
Reference in New Issue
Block a user