| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * This class is responsible for fetching and managing Google Bot IPs. |
| 12 | 12 | */ |
| 13 | -class Google_Bot implements Bots_Interface { | |
| 13 | +class Google_Bot extends Abstract_Bot { | |
| 14 | 14 | /** |
| 15 | 15 | * Returns the name of the bot. |
| 16 | 16 | * |
| 17 | 17 | * @return string The name of the bot. |
| @@ -46,6 +46,33 @@ | ||
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | return $ips; |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Checks if the user agent belongs to Google. | |
| 54 | + * | |
| 55 | + * @param string $user_agent Optional user agent string to check. | |
| 56 | + * | |
| 57 | + * @return bool | |
| 58 | + */ | |
| 59 | + public function is_ua( string $user_agent = '' ): bool { | |
| 60 | + $ua = $this->normalize_ua( $user_agent ); | |
| 61 | + if ( '' === $ua ) { | |
| 62 | + return false; | |
| 63 | + } | |
| 64 | + | |
| 65 | + return false !== stristr( $ua, 'googlebot' ); | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Checks if IP is from Google, based on DNS verification. | |
| 70 | + * | |
| 71 | + * @param string $ip The IP address to check. | |
| 72 | + * | |
| 73 | + * @return bool | |
| 74 | + */ | |
| 75 | + public function is_ip( string $ip ): bool { | |
| 76 | + return $this->verify_dns( $ip, '(^|\.)(googlebot\.com|google\.com)' ); | |
| 50 | 77 | } |
| 51 | 78 | } |