mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-50891 useragent: Move web crawler checks to useragent class
This commit is contained in:
parent
6d392b3027
commit
34c6ec1869
6 changed files with 283 additions and 90 deletions
|
@ -71,7 +71,7 @@ class core_useragent {
|
|||
self::DEVICETYPE_DEFAULT,
|
||||
self::DEVICETYPE_LEGACY,
|
||||
self::DEVICETYPE_MOBILE,
|
||||
self::DEVICETYPE_TABLET
|
||||
self::DEVICETYPE_TABLET,
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -201,6 +201,7 @@ class core_useragent {
|
|||
|
||||
/**
|
||||
* Returns true if the user appears to be on a tablet.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function is_useragent_tablet() {
|
||||
|
@ -208,6 +209,16 @@ class core_useragent {
|
|||
return (preg_match($tabletregex, $this->useragent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user agent relates to a web crawler.
|
||||
* This includes all types of web crawler.
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_useragent_web_crawler() {
|
||||
$regex = '/Googlebot|google\.com|Yahoo! Slurp|\[ZSEBOT\]|msnbot|bingbot|BingPreview|Yandex|AltaVista|Baiduspider|Teoma/';
|
||||
return (preg_match($regex, $this->useragent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of known device types.
|
||||
*
|
||||
|
@ -926,4 +937,15 @@ class core_useragent {
|
|||
// This browser does not support json.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the client appears to be some kind of web crawler.
|
||||
* This may include other types of crawler.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_web_crawler() {
|
||||
$instance = self::instance();
|
||||
return (bool) $instance->is_useragent_web_crawler();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue