/** * Replace embeddable URLs with the embed code. * * @param string $text * * @return string */ public static function OEmbed($text) { $embera = new Embera(); if ($data = $embera->getUrlInfo($text)) { $table = []; foreach ($data as $url => $service) { if (!empty($service['html'])) { $table[$url] = $service['html']; } } foreach ($table as $url => $replacement) { $text = preg_replace('~(?<![\'\\"])' . preg_quote($url) . '(?![\'\\"])(?!\\</a\\>)~', $replacement, $text); } } return $text; }
/** * Retorna todas as informações da $url. * Para saber que tipo de informações são retornadas veja o link. * @link http://oembed.com * @param string $url A Url cujo queres informações. * @return null/array Retorna null se houver erro ao buscar informações sobre a $url. Ou um array com informações sobre a url. */ public function fetchUrlInfo($url, $config = array()) { if (!empty($config)) { $embera = new Embera($config); } else { $embera = new Embera(); } // $embera = new \Embera\Formatter($embera); $urlInfo = $embera->getUrlInfo($url); $errors = $embera->getErrors(); if (!empty($urlInfo) and empty($errors)) { $this->_urlInfo = $urlInfo; return $urlInfo; } return $errors; }