Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
The user agent class. More...
Static Public Member Functions | |
static | check_browser_operating_system ($brand) |
Check if the user agent matches a given brand. | |
static | check_browser_version ($brand, $version=null) |
Returns true if the user agent matches the given brand and the version is equal to or greater than that specified. | |
static | check_chrome_version ($version=null) |
Checks the user agent is Chrome based and that the version is equal to or greater than that specified. | |
static | check_edge_version ($version=null) |
Check the User Agent for the version of Edge. | |
static | check_firefox_version ($version=null) |
Checks the user agent is Firefox based and that the version is equal to or greater than that specified. | |
static | check_gecko_version ($version=null) |
Checks the user agent is Gecko based and that the version is equal to or greater than that specified. | |
static | check_ie_compatibility_view () |
Checks the user agent is IE and that IE is running under Compatibility View setting. | |
static | check_ie_properties () |
Checks the user agent is IE and returns its main properties: | |
static | check_ie_version ($version=null) |
Checks the user agent is IE and that the version is equal to or greater than that specified. | |
static | check_opera_version ($version=null) |
Checks the user agent is Opera and that the version is equal to or greater than that specified. | |
static | check_safari_ios_version ($version=null) |
Checks the user agent is Safari on iOS and that the version is equal to or greater than that specified. | |
static | check_safari_version ($version=null) |
Checks the user agent is Safari based and that the version is equal to or greater than that specified. | |
static | check_webkit_android_version ($version=null) |
Checks the user agent is Webkit based and on Android and that the version is equal to or greater than that specified. | |
static | check_webkit_version ($version=null) |
Checks the user agent is Webkit based and that the version is equal to or greater than that specified. | |
static | get_browser_version_classes () |
Gets an array of CSS classes to represent the user agent. | |
static | get_device_type () |
Returns the device type we believe is being used. | |
static | get_device_type_cfg_var_name ($devicetype=null) |
Returns the CFG var used to find the theme to use for the given device. | |
static | get_device_type_list ($includecustomtypes=true) |
Gets a list of known device types. | |
static | get_device_type_theme ($devicetype=null) |
Returns the theme to use for the given device type. | |
static | get_moodlebot_useragent () |
Get the MoodleBot UserAgent for this site. | |
static | get_user_agent_string () |
Returns the user agent string. | |
static | get_user_device_type () |
Gets the device type the user is currently using. | |
static | instance ($reload=false, $forceuseragent=null) |
Get an instance of the user agent object. | |
static | is_chrome () |
Checks the user agent is Chrome. | |
static | is_edge () |
Checks the user agent is Edge (of any version). | |
static | is_firefox () |
Checks the user agent is Firefox (of any version). | |
static | is_gecko () |
Checks the user agent is Gecko based (of any version). | |
static | is_ie () |
Checks the user agent is IE (of any version). | |
static | is_ios ($version=null) |
Returns true if the client appears to be a device using iOS (iPhone, iPad, iPod). | |
static | is_moodle_app () |
Returns true if the client appears to be the Moodle app (or an app based on the Moodle app code). | |
static | is_msword () |
Checks if the user agent is MS Word. | |
static | is_opera () |
Checks the user agent is Opera (of any version). | |
static | is_safari () |
Checks the user agent is Safari. | |
static | is_safari_ios () |
Checks the user agent is Safari on iOS. | |
static | is_web_crawler () |
Returns true if the client appears to be some kind of web crawler. | |
static | is_webkit () |
Checks the user agent is webkit based. | |
static | is_webkit_android () |
Checks the user agent is webkit android based. | |
static | set_user_device_type ($newdevice) |
Switches the device type we think the user is using to what ever was given. | |
static | supports_html5 ($extension) |
Checks if current browser supports files with give extension as <video> or <audio> source. | |
static | supports_json_contenttype () |
Returns true if the user agent supports the MIME media type for JSON text, as defined in RFC 4627. | |
static | supports_media_source_extensions (string $extension) |
Checks if current browser supports the HLS and MPEG-DASH media streaming formats. | |
static | supports_svg () |
Returns true if the user agent supports the display of SVG images. | |
Public Attributes | |
const | DEVICETYPE_DEFAULT = 'default' |
The default for devices, think of as a computer. | |
const | DEVICETYPE_LEGACY = 'legacy' |
Legacy devices, or at least legacy browsers. | |
const | DEVICETYPE_MOBILE = 'mobile' |
Mobile devices like your cell phone or hand held gaming device. | |
const | DEVICETYPE_TABLET = 'tablet' |
Tables, larger than hand held, but still easily portable and smaller than a laptop. | |
Static Public Attributes | |
static array | $devicetypes |
The device types we track. | |
Protected Member Functions | |
__construct ($forceuseragent=null) | |
Constructs a new user agent object. | |
guess_device_type () | |
Guesses the device type the user agent is running on. | |
is_useragent_mobile () | |
Returns true if the user appears to be on a mobile device. | |
is_useragent_tablet () | |
Returns true if the user appears to be on a tablet. | |
is_useragent_web_crawler () | |
Whether the user agent relates to a web crawler. | |
Static Protected Member Functions | |
static | check_camino_version ($version=null) |
Checks the user agent is camino based and that the version is equal to or greater than that specified. | |
Protected Attributes | |
string | $devicetype = null |
The users device type, one of self\DEVICETYPE_*. | |
bool null | $supportssvg = null |
True if the user agent supports the display of svg images. | |
string bool null | $useragent = null |
The current requests user agent string if there was one. | |
Static Protected Attributes | |
static core_useragent | $instance = null |
An instance of this class. | |
The user agent class.
It's important to note that we do not like browser sniffing and its use in core code is highly discouraged. No new uses of this API will be integrated unless there is absolutely no alternative.
This API supports the few browser checks we do have in core, all of which one day will hopefully be removed. The API will remain to support any third party use out there, however at some point like all code it will be deprecated.
Use sparingly and only with good cause!
|
protected |
Constructs a new user agent object.
Publically you must use the instance method above.
string | null | $forceuseragent | Optional a user agent to force. |
|
static |
Check if the user agent matches a given brand.
Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
string | $brand |
bool |
|
static |
Returns true if the user agent matches the given brand and the version is equal to or greater than that specified.
string | $brand | The branch to check for. |
scalar | $version | The version if we need to find out if it is equal to or greater than that specified. |
bool |
|
staticprotected |
Checks the user agent is camino based and that the version is equal to or greater than that specified.
Camino browser is at the end of its life, its no longer being developed or supported, just don't worry about it.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Chrome based and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Check the User Agent for the version of Edge.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Firefox based and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Gecko based and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is IE and that IE is running under Compatibility View setting.
bool | true if internet explorer runs in Compatibility View mode. |
|
static |
Checks the user agent is IE and returns its main properties:
bool|array | False if not IE, otherwise an associative array of properties. |
|
static |
Checks the user agent is IE and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Opera and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Safari on iOS and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Safari based and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Webkit based and on Android and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Checks the user agent is Webkit based and that the version is equal to or greater than that specified.
string | int | $version | A version to check for, returns true if its equal to or greater than that specified. |
bool |
|
static |
Gets an array of CSS classes to represent the user agent.
array |
|
static |
Returns the device type we believe is being used.
string |
|
static |
Returns the CFG var used to find the theme to use for the given device.
Used to be get_device_cfg_var_name.
null | string | $devicetype | The device type to find out for. Defaults to the device the user is using, |
string |
|
static |
Gets a list of known device types.
bool | $includecustomtypes | If set to true we'll include types that have been added by the admin. |
array |
|
static |
Returns the theme to use for the given device type.
This used to be get_selected_theme_for_device_type.
null | string | $devicetype | The device type to find out for. Defaults to the device the user is using, |
bool |
|
static |
Get the MoodleBot UserAgent for this site.
string | UserAgent |
|
static |
Returns the user agent string.
bool|string | The user agent string or false if one isn't available. |
|
static |
Gets the device type the user is currently using.
string |
|
protected |
Guesses the device type the user agent is running on.
string |
|
static |
Get an instance of the user agent object.
bool | $reload | If set to true the user agent will be reset and all ascertations remade. |
string | $forceuseragent | The string to force as the user agent, don't use unless absolutely unavoidable. |
core_useragent |
|
static |
Checks the user agent is Chrome.
bool | true if chrome |
|
static |
Checks the user agent is Edge (of any version).
bool | true if Edge |
|
static |
Checks the user agent is Firefox (of any version).
bool | true if firefox |
|
static |
Checks the user agent is Gecko based (of any version).
bool | true if Gecko based. |
|
static |
Checks the user agent is IE (of any version).
bool | true if internet exporeer |
|
static |
Returns true if the client appears to be a device using iOS (iPhone, iPad, iPod).
scalar | $version | The version if we need to find out if it is equal to or greater than that specified. |
bool | true if the client is using iOS |
|
static |
|
static |
Checks if the user agent is MS Word.
Not perfect, as older versions of Word use standard IE6/7 user agents without any identifying traits.
bool | true if user agent could be identified as MS Word. |
|
static |
Checks the user agent is Opera (of any version).
bool | true if opera |
|
static |
Checks the user agent is Safari.
bool | true if safari |
|
static |
Checks the user agent is Safari on iOS.
bool | true if Safari on iOS |
|
protected |
Returns true if the user appears to be on a mobile device.
bool |
|
protected |
Returns true if the user appears to be on a tablet.
int |
|
protected |
Whether the user agent relates to a web crawler.
This includes all types of web crawler.
bool |
|
static |
Returns true if the client appears to be some kind of web crawler.
This may include other types of crawler.
bool |
|
static |
Checks the user agent is webkit based.
bool | true if webkit |
|
static |
Checks the user agent is webkit android based.
bool | true if webkit based and on Android |
|
static |
Switches the device type we think the user is using to what ever was given.
string | $newdevice |
bool |
coding_exception |
|
static |
Checks if current browser supports files with give extension as <video> or <audio> source.
Note, the check here is not 100% accurate!
First, we do not know which codec is used in .mp4 or .webm files. Not all browsers support all codecs.
Also we assume that users of Firefox/Chrome/Safari do not use the ancient versions of browsers.
We check the exact version for IE/Edge though. We know that there are still users of very old versions that are afraid to upgrade or have slow IT department.
Resources: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats https://en.wikipedia.org/wiki/HTML5_video https://en.wikipedia.org/wiki/HTML5_Audio
string | $extension | extension without leading . |
bool |
|
static |
Returns true if the user agent supports the MIME media type for JSON text, as defined in RFC 4627.
bool |
|
static |
Checks if current browser supports the HLS and MPEG-DASH media streaming formats.
Most browsers get this from Media Source Extensions. Safari on iOS, doesn't support MPEG-DASH at all.
Note, the check here is not 100% accurate!
Also we assume that users of Firefox/Chrome/Safari do not use the ancient versions of browsers. We check the exact version for IE/Edge though. We know that there are still users of very old versions that are afraid to upgrade or have slow IT department.
Resources: https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API https://caniuse.com/#search=mpeg-dash https://caniuse.com/#search=hls
string | $extension |
bool |
|
static |
Returns true if the user agent supports the display of SVG images.
bool |
|
protected |
The users device type, one of self\DEVICETYPE_*.
null until initialised
|
static |
The device types we track.
|
protected |
True if the user agent supports the display of svg images.
False if not. Null until initialised, then true or false.
|
protected |
The current requests user agent string if there was one.
Null until initialised, false if none available, or string when available.
const core_useragent::DEVICETYPE_LEGACY = 'legacy' |
Legacy devices, or at least legacy browsers.
These are older devices/browsers that don't support standards.