/** * * @param HttpResource $asset */ public function render($asset) { if (!$this->accept($asset)) { return; } $width = (int) $asset->config('size'); $width = (24 <= $width && $width <= 800) ? $width : 300; $url = $asset->url(); $oembed = self::API_ENDPOINT . '?url=' . urlencode($url) . '&maxwidth=' . $width; $data = HttpResource::fetch_json($oembed); if (empty($data)) { return false; } $result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : ''; $result[self::TITLE] = isset($data['title']) ? $data['title'] : ''; $result[self::EMBED_SNIPPET] = isset($data['html']) ? $data['html'] : ''; return $result; }
/** * * @param HttpResource $asset */ public function render($asset) { $link = $asset->get_link('type', 'application/json+oembed'); if (empty($link)) { return false; } $width = (int) $asset->config('size'); $width = (24 <= $width && $width <= 800) ? $width : 300; $href = $link['href']; $data = HttpResource::fetch_json("$href&maxwidth=$width"); //&maxheight=$height if (empty($data)) { return false; } $data['title'] = isset($data['title']) ? $data['title'] : ''; $data['width'] = isset($data['width']) ? intval($data['width']) : ''; $data['height'] = isset($data['height']) ? intval($data['height']) : ''; $type = $data['type']; $f = array($this, "render_$type"); if (is_callable($f)) { $result = call_user_func($f, $asset, $data); } else { $result = array(); } $result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : ''; $result[self::TITLE] = isset($data['title']) ? $data['title'] : ''; return $result; }