Automattic\Jetpack\Device_Detection

User_Agent_Info::detect_blackberry_browser_version()public staticWPSCache 1.0

Retrieve the blackberry browser version.

Return string are from the following list:

  • blackberry-10
  • blackberry-webkit
  • blackberry-5
  • blackberry-4.7
  • blackberry-4.6

Метод класса: User_Agent_Info{}

Хуков нет.

Возвращает

Строку. Type of the BB browser. If browser's version is not found, detect_blackbeberry_browser_version will return boolean false.

Использование

$result = User_Agent_Info::detect_blackberry_browser_version();

Код User_Agent_Info::detect_blackberry_browser_version() WPSCache 1.12.4

public static function detect_blackberry_browser_version() {

	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
		return false;
	}

	$agent = strtolower( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This is validating.

	if ( self::is_blackberry_10() ) {
		return 'blackberry-10';
	}

	$pos_blackberry = strpos( $agent, 'blackberry' );
	if ( false === $pos_blackberry ) {
		// Not a blackberry device.
		return false;
	}

	$pos_webkit = strpos( $agent, 'webkit' );

	if ( ! ( false === $pos_webkit ) ) {
		return 'blackberry-webkit';
	} else {
		if ( ! preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) {
			return false; // not a BB device that match our rule.
		}

		$version_num = explode( '.', $matches[1] );

		if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
			return false;
		}

		$version_num_major = (int) $version_num[0];
		$version_num_minor = (int) $version_num[1];

		if ( 5 === $version_num_major ) {
			return 'blackberry-5';
		} elseif ( 4 === $version_num_major && 7 === $version_num_minor ) {
			return 'blackberry-4.7';
		} elseif ( 4 === $version_num_major && 6 === $version_num_minor ) {
			return 'blackberry-4.6';
		} else {
			// A very old BB device is found or this is a BB device that doesn't match our rules.
			return false;
		}
	}
}