-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from sheadawson/master
Merge master into 1.2
- Loading branch information
Showing
11 changed files
with
716 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# For more information about the properties used in this file, | ||
# please see the EditorConfig documentation: | ||
# http://editorconfig.org | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[{*.yml,package.json}] | ||
indent_size = 2 | ||
|
||
# The indent size used in the package.json file cannot be changed: | ||
# https://github.com/npm/npm/pull/3180#issuecomment-16336516 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,83 +7,88 @@ | |
* @license BSD License http://www.silverstripe.org/bsd-license | ||
* @author <[email protected]> | ||
**/ | ||
class EmbeddedObject extends DataObject { | ||
private static $db = array( | ||
'Title' => 'Varchar(255)', | ||
'Type' => 'Varchar', | ||
'SourceURL' => 'Varchar(255)', | ||
'Width' => 'Varchar', | ||
'Height' => 'Varchar', | ||
'Description' => 'HTMLText', | ||
'ThumbURL' => 'Varchar(255)', | ||
'ExtraClass' => 'Varchar(64)', | ||
'EmbedHTML' => 'Text', | ||
); | ||
class EmbeddedObject extends DataObject | ||
{ | ||
private static $db = array( | ||
'Title' => 'Varchar(255)', | ||
'Type' => 'Varchar', | ||
'SourceURL' => 'Varchar(255)', | ||
'Width' => 'Varchar', | ||
'Height' => 'Varchar', | ||
'Description' => 'HTMLText', | ||
'ThumbURL' => 'Varchar(255)', | ||
'ExtraClass' => 'Varchar(64)', | ||
'EmbedHTML' => 'Text', | ||
); | ||
|
||
public function Embed() { | ||
$options = array( | ||
'width' => $this->Width, | ||
'height' => $this->Height, | ||
); | ||
$this->setFromURL($this->SourceURL); | ||
return $this; | ||
} | ||
public function Embed() | ||
{ | ||
$options = array( | ||
'width' => $this->Width, | ||
'height' => $this->Height, | ||
); | ||
$this->setFromURL($this->SourceURL); | ||
return $this; | ||
} | ||
|
||
public function onBeforeWrite() { | ||
$changes = $this->getChangedFields(); | ||
public function onBeforeWrite() | ||
{ | ||
$changes = $this->getChangedFields(); | ||
|
||
if (isset($changes['Width']) && $changes['Width']['before']) { | ||
$this->updateEmbedHTML(); | ||
} | ||
if (isset($changes['Width']) && $changes['Width']['before']) { | ||
$this->updateEmbedHTML(); | ||
} | ||
|
||
if (isset($changes['Height']) && $changes['Height']['before']) { | ||
$this->updateEmbedHTML(); | ||
} | ||
if (isset($changes['Height']) && $changes['Height']['before']) { | ||
$this->updateEmbedHTML(); | ||
} | ||
|
||
parent::onBeforeWrite(); | ||
parent::onBeforeWrite(); | ||
} | ||
|
||
} | ||
public function updateEmbedHTML() | ||
{ | ||
$this->setFromURL($this->SourceURL); | ||
} | ||
|
||
public function updateEmbedHTML() { | ||
$this->setFromURL($this->SourceURL); | ||
} | ||
public function setFromURL($url) | ||
{ | ||
if ($url) { | ||
$info = Embed\Embed::create($url); // , array('image' => array('minImageWidth' => $this->Width, 'minImageHeight' => $this->Height))); | ||
$this->setFromEmbed($info); | ||
} | ||
} | ||
|
||
public function setFromURL($url) { | ||
if($url) { | ||
$info = Embed\Embed::create($url); // , array('image' => array('minImageWidth' => $this->Width, 'minImageHeight' => $this->Height))); | ||
$this->setFromEmbed($info); | ||
} | ||
} | ||
public function setFromEmbed(\Embed\Adapters\Adapter $info) | ||
{ | ||
$this->Title = $info->getTitle(); | ||
$this->SourceURL = $info->getUrl(); | ||
$this->Width = $info->getWidth(); | ||
$this->Height = $info->getHeight(); | ||
$this->ThumbURL = $info->getImage(); | ||
$this->Description = $info->getDescription() ? $info->getDescription(): $info->getTitle(); | ||
$this->Type = $info->getType(); | ||
$embed = $info->getCode(); | ||
$this->EmbedHTML = $embed ? $embed : $this->EmbedHTML; | ||
} | ||
|
||
public function setFromEmbed(\Embed\Adapters\Adapter $info) { | ||
|
||
$this->Title = $info->getTitle(); | ||
$this->SourceURL = $info->getUrl(); | ||
$this->Width = $info->getWidth(); | ||
$this->Height = $info->getHeight(); | ||
$this->ThumbURL = $info->getImage(); | ||
$this->Description = $info->getDescription() ? $info->getDescription(): $info->getTitle(); | ||
$this->Type = $info->getType(); | ||
$embed = $info->getCode(); | ||
$this->EmbedHTML = $embed ? $embed : $this->EmbedHTML; | ||
} | ||
|
||
public function forTemplate() { | ||
switch($this->Type) { | ||
case 'video': | ||
case 'rich': | ||
if($this->ExtraClass) { | ||
return "<div class='$this->ExtraClass'>$this->EmbedHTML</div>"; | ||
} else { | ||
return $this->EmbedHTML; | ||
} | ||
break; | ||
case 'link': | ||
return '<a class="' . $this->ExtraClass . '" href="' . $this->SourceURL . '">' . $this->Title . '</a>'; | ||
break; | ||
case 'photo': | ||
return "<img src='$this->SourceURL' width='$this->Width' height='$this->Height' class='$this->ExtraClass' />"; | ||
break; | ||
} | ||
} | ||
public function forTemplate() | ||
{ | ||
switch ($this->Type) { | ||
case 'video': | ||
case 'rich': | ||
if ($this->ExtraClass) { | ||
return "<div class='$this->ExtraClass'>$this->EmbedHTML</div>"; | ||
} else { | ||
return $this->EmbedHTML; | ||
} | ||
break; | ||
case 'link': | ||
return '<a class="' . $this->ExtraClass . '" href="' . $this->SourceURL . '">' . $this->Title . '</a>'; | ||
break; | ||
case 'photo': | ||
return "<img src='$this->SourceURL' width='$this->Width' height='$this->Height' class='$this->ExtraClass' />"; | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.