diff --git a/composer.json b/composer.json
index 8c5a496..4459bee 100644
--- a/composer.json
+++ b/composer.json
@@ -12,7 +12,8 @@
"issues": "https://github.com/nathancox/silverstripe-embedfield/issues"
},
"require": {
- "silverstripe/framework": "~4.0"
+ "embed/embed": "^4",
+ "silverstripe/framework": "^4.11|^5"
},
"extra": {
"screenshots": [
diff --git a/src/Forms/EmbedField.php b/src/Forms/EmbedField.php
index b6e4090..cf2764b 100644
--- a/src/Forms/EmbedField.php
+++ b/src/Forms/EmbedField.php
@@ -7,7 +7,6 @@
use SilverStripe\Forms\TextField;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Security\SecurityToken;
-use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObjectInterface;
use nathancox\EmbedField\Model\EmbedObject;
@@ -75,20 +74,20 @@ public function Type() {
}
public function setValue($value, $data = null) {
-
+
if ($value instanceof EmbedObject) {
$this->object = $value;
parent::setValue($this->object->ID);
-
+
}
$this->object = EmbedObject::get()->byID($value);
-
+
parent::setValue($value);
}
public function saveInto(DataObjectInterface $record) {
-
+
$val = $this->Value(); // array[sourceurl],[data] (as json)
$name = $this->getName();
@@ -142,7 +141,7 @@ public function saveInto(DataObjectInterface $record) {
* This is called by the javascript
*/
public function update(HTTPRequest $request) {
-
+
if (!SecurityToken::inst()->checkRequest($request)) {
return '';
}
@@ -175,14 +174,14 @@ public function update(HTTPRequest $request) {
if ($object && $object->sourceExists()) {
if ($this->embedType && $this->embedType != $object->Type) {
- return Convert::array2json(array(
+ return json_encode(array(
'status' => 'invalidurl',
'message' => '' . $sourceURL . ' is not a valid source type.',
'data' => array()
));
}
- return Convert::array2json(array(
+ return json_encode(array(
'status' => 'success',
'message' => '',
'data' => array(
@@ -194,7 +193,7 @@ public function update(HTTPRequest $request) {
));
} else {
- return Convert::array2json(array(
+ return json_encode(array(
'status' => 'invalidurl',
'message' => '' . $sourceURL . ' is not a valid embed source.',
'data' => array()
@@ -202,7 +201,7 @@ public function update(HTTPRequest $request) {
}
}else{
- return Convert::array2json(array(
+ return json_encode(array(
'status' => 'nourl',
'message' => '',
'data' => array()
diff --git a/src/Model/EmbedObject.php b/src/Model/EmbedObject.php
index eda1b34..08195c2 100644
--- a/src/Model/EmbedObject.php
+++ b/src/Model/EmbedObject.php
@@ -49,38 +49,37 @@ function updateFromURL($sourceURL = null) {
if ($this->SourceURL) {
$sourceURL = $this->SourceURL;
}
- $info = Embed::create($sourceURL);
- //Oembed::get_oembed_from_url($sourceURL);
+ $embed = new Embed();
+ $info = $embed->get($sourceURL);
$this->updateFromObject($info);
}
function updateFromObject($info) {
- if ($info && $info->getWidth()) {
- $this->sourceExists = true;
-
- $this->Title = $info->getTitle();
- $this->Type = $info->type;
+ if ($info && $info->url) {
+ $this->sourceExists = true;
- $this->Width = $info->getWidth();
- $this->Height = $info->getHeight();
+ $this->Title = $info->title;
- $this->ThumbnailURL = $info->getImage();
- $this->ThumbnailWidth = $info->thumbnail_width;
- $this->ThumbnailHeight = $info->thumbnail_height;
+ $this->Type = $info->getOEmbed()->get('type') ? (string) $info->getOEmbed()->get('type') : '';
+ $this->Width = $info->getOEmbed()->get('width') ? (string) $info->getOEmbed()->get('width') : '';
+ $this->Height = $info->getOEmbed()->get('height') ? (string) $info->getOEmbed()->get('height') : '';
- $this->ProviderURL = $info->provider_url;
- $this->ProviderName = $info->provider_name;
+ $this->ThumbnailURL = (string) $info->image;
+ $this->ThumbnailWidth = $info->getOEmbed()->get('thumbnail_width') ? (string) $info->getOEmbed()->get('thumbnail_width') : '';
+ $this->ThumbnailHeight = $info->getOEmbed()->get('thumbnail_height') ? (string) $info->getOEmbed()->get('thumbnail_height') : '';
+ $this->ProviderURL = (string) $info->providerUrl;
+ $this->ProviderName = $info->providerName;
- $this->AuthorURL = $info->author_url;
- $this->AuthorName = $info->author_name;
+ $this->AuthorURL = (string) $info->authorUrl;
+ $this->AuthorName = $info->authorName;
- $embed = $info->getCode();
- $this->EmbedHTML = $embed;
- $this->URL = $info->url;
- $this->Origin = $info->origin;
- $this->WebPage = $info->web_page;
+ $embed = $info->code;
+ $this->EmbedHTML = (string) $embed;
+ $this->URL = (string) $info->url;
+ $this->Origin = (string) $info->providerUrl;
+ $this->WebPage = (string) $info->url;
} else {
$this->sourceExists = false;