Skip to content

Commit 1c20a13

Browse files
committed
fix: embed version 4 update
1 parent f9fff54 commit 1c20a13

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/extensions/Embeddable.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,25 @@ public function onBeforeWrite()
156156
$config = [
157157
'choose_bigger_image' => true,
158158
];
159-
$embed = Embed::create($sourceURL, $config);
159+
$embed = new Embed();
160+
$info=$embed->get($sourceURL);
161+
$oembed = $info->getOEmbed();
160162
if ($owner->EmbedTitle == '') {
161-
$owner->EmbedTitle = $embed->Title;
163+
$owner->EmbedTitle = $info->title;
162164
}
163165
if ($owner->EmbedDescription == '') {
164-
$owner->EmbedDescription = $embed->Description;
166+
$owner->EmbedDescription = $info->description;
165167
}
166168
$changes = $owner->getChangedFields();
167169
if (isset($changes['EmbedSourceURL']) && !$owner->EmbedImageID) {
168-
$owner->EmbedHTML = $embed->Code;
169-
$owner->EmbedType = $embed->Type;
170-
$owner->EmbedWidth = $embed->Width;
171-
$owner->EmbedHeight = $embed->Height;
172-
$owner->EmbedAspectRatio = $embed->AspectRatio;
173-
if ($owner->EmbedSourceImageURL != $embed->Image) {
174-
$owner->EmbedSourceImageURL = $embed->Image;
175-
$fileExplode = explode('.', $embed->Image);
170+
$owner->EmbedHTML = $info->code->html;
171+
$owner->EmbedType = $info->getOEmbed()->get('type');
172+
$owner->EmbedWidth = $info->code->width;
173+
$owner->EmbedHeight = $info->code->height;
174+
$owner->EmbedAspectRatio = $info->code->ratio;
175+
if ($owner->EmbedSourceImageURL != $info->image) {
176+
$owner->EmbedSourceImageURL = $info->image;
177+
$fileExplode = explode('.', $info->image);
176178
$fileExtensionExplode = explode('?', end($fileExplode));
177179
$fileExtension = $fileExtensionExplode[0];
178180
$fileExtensionQuery = $fileExtensionExplode[0];
@@ -190,7 +192,7 @@ public function onBeforeWrite()
190192
// Save image to server
191193
$imageObject = Image::create();
192194
$imageObject->setFromString(
193-
file_get_contents($embed->Image),
195+
file_get_contents($info->image),
194196
$owner->EmbedFolder . '/' . $fileName,
195197
null,
196198
null,
@@ -203,7 +205,7 @@ public function onBeforeWrite()
203205
// Check existing for image object or create new
204206
$imageObject->ParentID = $parentFolder->ID;
205207
$imageObject->Name = $fileName;
206-
$imageObject->Title = $embed->getTitle();
208+
$imageObject->Title = $info->title;
207209
$imageObject->OwnerID = (Member::currentUserID() ? Member::currentUserID() : 0);
208210
$imageObject->ShowInSearch = false;
209211
$imageObject->write();
@@ -232,8 +234,10 @@ public function validate(ValidationResult $validationResult)
232234
$allowed_types = $owner->AllowedEmbedTypes;
233235
$sourceURL = $owner->EmbedSourceURL;
234236
if ($sourceURL && isset($allowed_types)) {
235-
$embed = Embed::create($sourceURL);
236-
if (!in_array($embed->Type, $allowed_types)) {
237+
$embed = new Embed();
238+
$info=$embed->get($sourceURL);
239+
$oembed = $info->getOEmbed();
240+
if (!in_array($oembed->get('type'), $allowed_types)) {
237241
$string = implode(', ', $allowed_types);
238242
$string = (substr($string, -1) == ',') ? substr_replace($string, ' or', -1) : $string;
239243
$validationResult->addError(

0 commit comments

Comments
 (0)