public static function isUrlOnBlocklist($url, $entity = 'url')
{
$rootDomain = Domainparser::getRootDomain($url);
if ($rootDomain === false) {
self::$reason = "Not blocking because we couldn't parse root domain";
return false;
}
$blocklist = self::getConcatenateBlocklist();
if (substr_count($blocklist, self::SEPERATOR . $rootDomain . self::SEPERATOR)) {
self::$reason = 'Blocking because ' . $entity . ' root domain (' . $rootDomain . ') is found on blocklist';
return true;
}
$hostname = Domainparser::getHostname($url);
if (substr_count($blocklist, self::SEPERATOR . $hostname . self::SEPERATOR)) {
self::$reason = 'Blocking because ' . $entity . ' hostname (' . $hostname . ') is found on blocklist';
return true;
}
$path = Domainparser::getPath($url);
if (trim($path, '/')) {
if (substr_count($blocklist, self::SEPERATOR . $rootDomain . $path . self::SEPERATOR)) {
self::$reason = 'Blocking because ' . $entity . ' root domain/path (' . $rootDomain . $path . ') is found on blocklist';
return true;
}
if (substr_count($blocklist, self::SEPERATOR . $hostname . $path . self::SEPERATOR)) {
self::$reason = 'Blocking because ' . $entity . ' hostname/path (' . $hostname . $path . ') is found on blocklist';
return true;
}
}
self::$reason = 'Not blocking because ' . $entity . ' (' . $url . ') is not matched against blocklist';
return false;
}