forked from silverstripe/silverstripe-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC silverstripe#5487 Remove Oembed in favor of embed/embed.
- Loading branch information
1 parent
221fc88
commit bac525e
Showing
11 changed files
with
223 additions
and
667 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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Forms\HtmlEditor; | ||
|
||
use Embed\Adapters\Adapter; | ||
use Embed\Embed; | ||
use ShortcodeHandler; | ||
|
||
/** | ||
* Class EmbedShortcodeProvider | ||
* | ||
* Provider for the [embed] shortcode tag used by the embedding service | ||
* in the HTML Editor field. | ||
* Provides the html needed for the frontend and the editor field itself. | ||
* | ||
* | ||
* @package SilverStripe\Forms\HtmlEditor | ||
*/ | ||
class EmbedShortcodeProvider implements ShortcodeHandler | ||
{ | ||
|
||
/** | ||
* Gets the list of shortcodes provided by this handler | ||
* | ||
* @return mixed | ||
*/ | ||
public static function get_shortcodes() | ||
{ | ||
return array('embed'); | ||
} | ||
|
||
/** | ||
* Embed shortcode parser from Oembed. This is a temporary workaround. | ||
* Oembed class has been replaced with the Embed external service. | ||
* | ||
* @param $arguments | ||
* @param $content | ||
* @param $parser | ||
* @param $shortcode | ||
* @param array $extra | ||
* | ||
* @return string | ||
*/ | ||
public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array()) { | ||
$embed = Embed::create($content, $arguments); | ||
if($embed && $embed instanceof \Embed\Adapters\Adapter) { | ||
return self::embedForTemplate($embed); | ||
} else { | ||
return '<a href="' . $content . '">' . $content . '</a>'; | ||
} | ||
} | ||
|
||
/** | ||
* @param Adapter $embed | ||
* | ||
* @return string | ||
*/ | ||
public static function embedForTemplate($embed) | ||
{ | ||
switch ($embed->type) { | ||
case 'video': | ||
case 'rich': | ||
if ($embed->extraClass) { | ||
return "<div class='media $embed->extraClass'>$embed->code</div>"; | ||
} else { | ||
return "<div class='media'>$embed->code</div>"; | ||
} | ||
break; | ||
case 'link': | ||
return '<a class="' . $embed->extraClass . '" href="' . $embed->origin . '">' . $embed->title . '</a>'; | ||
break; | ||
case 'photo': | ||
return "<img src='$embed->url' width='$embed->width' height='$embed->height' class='$embed->extraClass' />"; | ||
break; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.