$m->connect('main/oembed', array('action' => 'oembed'));
}
+ public function onGetRemoteUrlMetadataFromDom($url, DOMDocument $dom, stdClass &$metadata)
+ {
+ try {
+ common_log(LOG_INFO, 'Trying to discover an oEmbed endpoint using link headers.');
+ $api = oEmbedHelper::oEmbedEndpointFromHTML($dom);
+ common_log(LOG_INFO, 'Found API endpoint ' . $api . ' for URL ' . $url);
+ $params = array(
+ 'maxwidth' => common_config('thumbnail', 'width'),
+ 'maxheight' => common_config('thumbnail', 'height'),
+ );
+ $metadata = oEmbedHelper::getOembedFrom($api, $url, $params);
+
+ } catch (Exception $e) {
+ common_log(LOG_INFO, 'Could not find an oEmbed endpoint using link headers.');
+ // Just ignore it!
+ }
+ }
+
public function onEndShowHeadElements(Action $action)
{
switch ($action->getActionName()) {
* Normally this event is called through File::saveNew()
*
* @param File $file The newly inserted File object.
- * @param array $redir_data lookup data eg from File_redirection::where()
- * @param string $given_url
*
* @return boolean success
*/
- public function onEndFileSaveNew(File $file, array $redir_data, $given_url)
+ public function onEndFileSaveNew(File $file)
{
$fo = File_oembed::getKV('file_id', $file->id);
if ($fo instanceof File_oembed) {
return true;
}
- if (isset($redir_data['oembed']['json'])
- && !empty($redir_data['oembed']['json'])) {
- File_oembed::saveNew($redir_data['oembed']['json'], $file->id);
- } elseif (isset($redir_data['type'])
- && (('text/html' === substr($redir_data['type'], 0, 9)
- || 'application/xhtml+xml' === substr($redir_data['type'], 0, 21)))) {
+ if (isset($file->mimetype)
+ && (('text/html' === substr($file->mimetype, 0, 9)
+ || 'application/xhtml+xml' === substr($file->mimetype, 0, 21)))) {
try {
- $oembed_data = File_oembed::_getOembed($given_url);
+ $oembed_data = File_oembed::_getOembed($file->url);
if ($oembed_data === false) {
throw new Exception('Did not get oEmbed data from URL');
}