)|)!i', $line)) break; if (preg_match('!]*rel\s*=\s*["\']?(?:shortcut\s+)?icon["\']?[^>]*)/?>!i', $line, $match) && preg_match('!href\s*=\s*[\'"]?([^\s\'">]+)[\'"]?!i', $match[1], $fav)) { $favicon = $fav[1]; break; } } fclose($fp); if ($favicon) { $favicon_url = parse_url($favicon); if (empty($favicon_url['scheme'])) $favicon_url['scheme'] = $parsed_url['scheme']; if (empty($favicon_url['host'])) $favicon_url['host'] = $parsed_url['host']; if ($favicon_url['path'][0] != '/') $favicon_url['path'] = preg_replace('!/[^/]*$!U', '', $parsed_url['path']) . $favicon_url['path']; $favicon = $favicon_url['scheme'] . '://' . $favicon_url['host'] . $favicon_url['path']; $fp = @fopen($favicon, 'r', false, self::_getStreamContext('HEAD')); if (!$fp) { // throw new Exception("Can't reach ".$favicon); return false; } fclose($fp); return $favicon; } $favicon = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/favicon.ico'; $fp = @fopen($favicon, 'r', false, self::_getStreamContext('HEAD')); if (!$fp) { // throw new Exception("Can't reach ".$favicon); return false; } fclose($fp); return $favicon; } static public function check($favicon) { $img = getimagesize($favicon); if ($img[0] != self::$allowed_width || $img[1] != self::$allowed_height) { return self::WRONG_DIMENSIONS; } if (!in_array($img[2], self::$allowed_image_types, true)) { return self::WRONG_FORMAT; } return true; } static protected function _getStreamContext($method = 'GET') { return stream_context_create( array( 'http' => array( 'method' => $method, 'timeout' => self::$http_timeout, 'header' => "User-Agent: Opera/9.80 (X11; Linux i686; U; fr) Presto/2.2.15 Version/10.10\r\n", ) ) ); } } ?>