private function getMetaRefreshURL($url, $html)
{
if ($html == '') {
return false;
}
// <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.bernama.com/bernama/v6/newsindex.php?id=943513">
if (!preg_match('!<meta http-equiv=["\']?refresh["\']? content=["\']?[0-9];\\s*url=["\']?([^"\'>]+)["\']?!i', $html, $match)) {
return false;
}
$redirectUrl = str_replace('&', '&', trim($match[1]));
if (preg_match('!^https?://!i', $redirectUrl)) {
// already absolute
$this->logger->log('debug', 'Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $redirectUrl);
return $redirectUrl;
}
// absolutize redirect URL
$base = new \SimplePie_IRI($url);
// remove '//' in URL path (causes URLs not to resolve properly)
if (isset($base->ipath)) {
$base->ipath = str_replace('//', '/', $base->ipath);
}
if ($absolute = \SimplePie_IRI::absolutize($base, $redirectUrl)) {
$this->logger->log('debug', 'Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $absolute);
return $absolute->get_iri();
}
return false;
}