/** * Actually run an individual test. * * @param string $url * @param string $expectedType */ function _doTest($url, $expectedType) { try { $data = oEmbedHelper::getObject($url); $this->assertEquals($expectedType, $data->type); if ($data->type == 'photo') { $this->assertTrue(!empty($data->url), 'Photo must have a URL.'); $this->assertTrue(!empty($data->width), 'Photo must have a width.'); $this->assertTrue(!empty($data->height), 'Photo must have a height.'); } else { if ($data->type == 'video') { $this->assertTrue(!empty($data->html), 'Video must have embedding HTML.'); $this->assertTrue(!empty($data->thumbnail_url), 'Video should have a thumbnail.'); } } if (!empty($data->thumbnail_url)) { $this->assertTrue(!empty($data->thumbnail_width), 'Thumbnail must list a width.'); $this->assertTrue(!empty($data->thumbnail_height), 'Thumbnail must list a height.'); } } catch (Exception $e) { if ($expectedType == 'none') { $this->assertEquals($expectedType, 'none', 'Should not have data for this URL.'); } else { throw $e; } } }
function handle($args) { // Trigger short error responses; not a human-readable web page. StatusNet::setApi(true); // We're not a general oEmbed proxy service; limit to valid sessions. $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { // TRANS: Client error displayed when the session token does not match or is not given. $this->clientError(_m('There was a problem with your session token. ' . 'Try again, please.')); } $format = $this->arg('format'); if ($format && $format != 'json') { // TRANS: Client exception thrown when requesting a different format than JSON. throw new ClientException(_m('Invalid format; only JSON supported.')); } $url = $this->arg('url'); if (!common_valid_http_url($url)) { // TRANS: Client exception thrown when not providing a valid URL. throw new ClientException(_m('Invalid URL.')); } $params = array(); if ($this->arg('maxwidth')) { $params['maxwidth'] = $this->arg('maxwidth'); } if ($this->arg('maxheight')) { $params['maxheight'] = $this->arg('maxheight'); } $data = oEmbedHelper::getObject($url, $params); $this->init_document('json'); print json_encode($data); }
static function _getOembed($url) { try { return oEmbedHelper::getObject($url); } catch (Exception $e) { common_log(LOG_INFO, "Error during oembed lookup for {$url} - " . $e->getMessage()); return false; } }
static function _getOembed($url) { $parameters = array('maxwidth' => common_config('thumbnail', 'width'), 'maxheight' => common_config('thumbnail', 'height')); try { return oEmbedHelper::getObject($url, $parameters); } catch (Exception $e) { common_log(LOG_INFO, "Error during oembed lookup for {$url} - " . $e->getMessage()); return false; } }
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! } }
#!/usr/bin/env php <?php define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); $shortoptions = 'u:'; $longoptions = array('url='); $helptext = <<<END_OF_HELP poll_oembed.php --url URL Test oEmbed API on a URL. -u --url URL to try oEmbed against END_OF_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; if (!have_option('u', 'url')) { echo 'No URL given.'; exit(1); } $url = get_option_value('u', 'url'); print "Contacting URL\n"; $oEmbed = oEmbedHelper::getObject($url); var_dump($oEmbed); print "\nDONE.\n";