Automattic\Jetpack\Device_Detection

User_Agent_Info::get_blackbeberry_OS_version()public staticWPSCache 1.0

Retrieve the blackberry OS version.

Return strings are from the following list:

  • blackberry-10
  • blackberry-7
  • blackberry-6
  • blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule.
  • blackberry-5
  • blackberry-4.7
  • blackberry-4.6
  • blackberry-4.5

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

No Hooks.

Return

String. Version of the BB OS. If version is not found, get_blackbeberry_OS_version will return boolean false.

Usage

$result = User_Agent_Info::get_blackbeberry_OS_version();

Код User_Agent_Info::get_blackbeberry_OS_version() WPSCache 1.9.1

public static function get_blackbeberry_OS_version() {

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

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

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

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

	// Blackberry devices OS 6.0 or higher.
	// Mozilla/5.0 (BlackBerry; U; BlackBerry 9670; en) AppleWebKit/534.3+ (KHTML, like Gecko) Version/6.0.0.286 Mobile Safari/534.3+.
	// Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+.
	// Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+.
	$pos_webkit = stripos( $agent, 'webkit' );
	if ( false !== $pos_webkit ) {
		// Detected blackberry webkit browser.
		$pos_torch = stripos( $agent, 'BlackBerry 9800' );
		if ( false !== $pos_torch ) {
			return 'blackberry-torch'; // Match the torch first edition. the 2nd edition should use the OS7 and doesn't need any special rule.
		} else {
			// Detecting the BB OS version for devices running OS 6.0 or higher.
			if ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) {
				$version     = $matches[1];
				$version_num = explode( '.', $version );
				if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
					return 'blackberry-6'; // not a BB device that match our rule.
				} else {
					return 'blackberry-' . $version_num[0];
				}
			} else {
				// if doesn't match returns the minimun version with a webkit browser. we should never fall here.
				return 'blackberry-6'; // not a BB device that match our rule.
			}
		}
	}

	// Blackberry devices <= 5.XX.
	// BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179.
	if ( preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) {
		$version = $matches[1];
	} else {
		return false; // not a BB device that match our rule.
	}

	$version_num = explode( '.', $version );

	if ( is_array( $version_num ) === false || 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';
	} elseif ( 4 === $version_num_major && 5 === $version_num_minor ) {
		return 'blackberry-4.5';
	} else {
		return false;
	}

}