/** * @return bool */ private static function isRefererOnBlocklist() { $referer = self::getHttpReferer(); if ($referer === null) { self::$debug = "Not blocking because referral header is not set or empty"; return false; } $rootDomain = Domainparser::getRootDomain($referer); if ($rootDomain === false) { self::$debug = "Not blocking because we couldn't parse referral domain"; return false; } if (substr_count(self::getConcatenateBlocklist(), self::SEPERATOR . $rootDomain . self::SEPERATOR) === 0) { self::$debug = "Not blocking because referral domain (" . $rootDomain . ") is not found on blocklist"; return false; } self::$debug = "Blocking because referral domain (" . $rootDomain . ") is found on blocklist"; return true; }
/** * The public use of this function is undocumented. * * @param string $url * @param string $entity * * @return bool */ 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; }