Skip to content

Commit

Permalink
Merge pull request #47 from sheadawson/master
Browse files Browse the repository at this point in the history
Merge master into 1.2
  • Loading branch information
sheadawson committed Feb 2, 2016
2 parents 4548fd0 + 8b39e98 commit 3a8bec6
Show file tree
Hide file tree
Showing 11 changed files with 716 additions and 624 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ See 1.1 branch/releases for SilverStripe 3.1 support

## Maintainers

* shea@silverstripe.com.au
* shea@livesource.co.nz

## Description

Expand Down
145 changes: 75 additions & 70 deletions code/dataobjects/EmbeddedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Loading

0 comments on commit 3a8bec6

Please sign in to comment.