Move tryoembed to Content\OEmbed

- Add bbcode functions documentation
- Add Exception handling to OEmbed::getHTML
- Fix formatting
This commit is contained in:
Hypolite Petovan 2018-01-07 00:44:23 -05:00
parent 1cd8001833
commit d8a312d286
2 changed files with 67 additions and 48 deletions

View file

@ -15,6 +15,7 @@ use dba;
use DOMDocument;
use DOMXPath;
use DOMNode;
use Exception;
require_once 'include/dba.php';
require_once 'mod/proxy.php';
@ -305,6 +306,27 @@ class OEmbed
return allowed_domain($domain, $allowed, true);
}
public static function getHTML($url, $title = null)
{
// Always embed the SSL version
$url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),
array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);
$o = OEmbed::fetchURL($url);
if (!is_object($o) || $o->type == 'error') {
throw new Exception('OEmbed failed for URL: ' . $url);
}
if (x($title)) {
$o->title = $title;
}
$html = OEmbed::formatObject($o);
return $html;
}
/**
* @brief Generates the iframe HTML for an oembed attachment.
*