Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX insertion of images (trac #7438)

Allow insertion of images via oEmbed dialog using a direct url
  • Loading branch information...
commit e5829355821bd930e00bed76e2acd15ce96d8816 1 parent e2d7352
mightycoco mightycoco authored
Showing with 22 additions and 1 deletion.
  1. +2 −1  forms/HtmlEditorField.php
  2. +20 −0 oembed/Oembed.php
3  forms/HtmlEditorField.php
View
@@ -515,7 +515,8 @@ public function viewfile($request) {
}
// 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);
} elseif(!Director::is_site_url($url)) {
$fileWrapper = new HtmlEditorField_Embed($url, $file);
20 oembed/Oembed.php
View
@@ -131,6 +131,13 @@ public static function get_oembed_from_url($url, $type = false, array $options =
// Build the url manually - we gave all needed information.
$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) {
// Inject the options into the Oembed URL.
@@ -233,7 +240,20 @@ protected function loadData() {
$body = $body->getBody();
$data = json_decode($body, true);
if(!$data) {
+ // if the response is no valid JSON we might have received a binary stream to an image
$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
Please sign in to comment.
Something went wrong with that request. Please try again.