Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR update detectors for Embed 4.x #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/extensions/Embeddable.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,25 @@ public function onBeforeWrite()
{
$owner = $this->owner;
if ($sourceURL = $owner->EmbedSourceURL) {
$embed = Embed::create($sourceURL);
$embed = new Embed();
$embed = $embed->get($sourceURL);
if ($owner->EmbedTitle == '') {
$owner->EmbedTitle = $embed->Title;
$owner->EmbedTitle = $embed->title;
}
if (!$owner->EmbedDescription == '') {
$owner->EmbedDescription = $embed->Description;
$owner->EmbedDescription = $embed->description;
}
$changes = $owner->getChangedFields();
if (isset($changes['EmbedSourceURL']) && !$owner->EmbedImageID) {
$owner->EmbedHTML = $embed->Code;
$owner->EmbedType = $embed->Type;
$owner->EmbedWidth = $embed->Width;
$owner->EmbedHeight = $embed->Height;
$owner->EmbedAspectRatio = $embed->AspectRatio;
if ($owner->EmbedSourceImageURL != $embed->Image) {
$owner->EmbedSourceImageURL = $embed->Image;
$fileExplode = explode('.', $embed->Image);
$owner->EmbedHTML = $embed->code->html;
$owner->EmbedType = 'video';
$owner->EmbedWidth = $embed->code->width;
$owner->EmbedHeight = $embed->code->height;
$owner->EmbedAspectRatio = $embed->code->ratio;

if ($owner->EmbedSourceImageURL != (string) $embed->image) {
$owner->EmbedSourceImageURL = (string) $embed->image;
$fileExplode = explode('.', $embed->image);
$fileExtension = end($fileExplode);
$fileName = Convert::raw2url($owner->obj('EmbedTitle')->LimitCharacters(55)) . '.' . $fileExtension;
$parentFolder = Folder::find_or_make($owner->EmbedFolder);
Expand All @@ -185,7 +187,7 @@ public function onBeforeWrite()
// Save image to server
$imageObject = Image::create();
$imageObject->setFromString(
file_get_contents($embed->Image),
file_get_contents($embed->image),
$owner->EmbedFolder . '/' . $fileName,
null,
null,
Expand All @@ -198,7 +200,7 @@ public function onBeforeWrite()
// Check existing for image object or create new
$imageObject->ParentID = $parentFolder->ID;
$imageObject->Name = $fileName;
$imageObject->Title = $embed->getTitle();
$imageObject->Title = $embed->title;
$imageObject->OwnerID = (Member::currentUserID() ? Member::currentUserID() : 0);
$imageObject->ShowInSearch = false;
$imageObject->write();
Expand All @@ -221,13 +223,15 @@ public function getAllowedEmbedTypes()
* @param ValidationResult $validationResult
* @return ValidationResult
*/
/* remove as `type` detector was removed from Embed 4
public function validate(ValidationResult $validationResult)
{
$owner = $this->owner;
$allowed_types = $owner->AllowedEmbedTypes;
$sourceURL = $owner->EmbedSourceURL;
if ($sourceURL && isset($allowed_types)) {
$embed = Embed::create($sourceURL);
$embed = new Embed();
$embed = $embed->get($sourceURL);
if (!in_array($embed->Type, $allowed_types)) {
$string = implode(', ', $allowed_types);
$string = (substr($string, -1) == ',') ? substr_replace($string, ' or', -1) : $string;
Expand All @@ -238,6 +242,7 @@ public function validate(ValidationResult $validationResult)
}
return $validationResult;
}
*/

/**
* @return string
Expand Down