forked from Sophia/better-yourls-blacklist-domains
Add possible regex handling
This commit is contained in:
@@ -45,13 +45,20 @@ function better_blacklist_domain_check( $shunt, $url ) {
|
|||||||
$blacklisted_domains = unserialize( $blacklisted_domains );
|
$blacklisted_domains = unserialize( $blacklisted_domains );
|
||||||
|
|
||||||
foreach ( $blacklisted_domains as $blacklisted_domain ) {
|
foreach ( $blacklisted_domains as $blacklisted_domain ) {
|
||||||
// Use a regex to match the domain or subdomain
|
// Check if the entry starts with '/', then consider regex handling
|
||||||
|
if (strpos($blacklisted_domain, '/') === 0) {
|
||||||
|
if (@preg_match($blacklisted_domain, $domain)) {
|
||||||
|
return blacklist_fail_response();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise treat as plain domain (old behavior)
|
||||||
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
|
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
|
||||||
if ( preg_match( $pattern, $domain ) ) {
|
if ( preg_match( $pattern, $domain ) ) {
|
||||||
return blacklist_fail_response();
|
return blacklist_fail_response();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// No match, allow the URL
|
// No match, allow the URL
|
||||||
return $shunt;
|
return $shunt;
|
||||||
|
|||||||
Reference in New Issue
Block a user