web/wp-includes/vars.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    10  * with known permalink capability.
    10  * with known permalink capability.
    11  *
    11  *
    12  * @package WordPress
    12  * @package WordPress
    13  */
    13  */
    14 
    14 
       
    15 global $pagenow,
       
    16 	$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE,
       
    17 	$is_apache, $is_IIS, $is_iis7;
       
    18 
    15 // On which page are we ?
    19 // On which page are we ?
    16 if ( is_admin() ) {
    20 if ( is_admin() ) {
    17 	// wp-admin pages are checked more carefully
    21 	// wp-admin pages are checked more carefully
    18 	preg_match('#/wp-admin/?(.*?)$#i', $PHP_SELF, $self_matches);
    22 	if ( is_network_admin() )
       
    23 		preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
       
    24 	elseif ( is_user_admin() )
       
    25 		preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
       
    26 	else
       
    27 		preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    19 	$pagenow = $self_matches[1];
    28 	$pagenow = $self_matches[1];
    20 	$pagenow = trim($pagenow, '/');
    29 	$pagenow = trim($pagenow, '/');
    21 	$pagenow = preg_replace('#\?.*?$#', '', $pagenow);
    30 	$pagenow = preg_replace('#\?.*?$#', '', $pagenow);
    22 	if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
    31 	if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
    23 		$pagenow = 'index.php';
    32 		$pagenow = 'index.php';
    26 		$pagenow = strtolower($self_matches[1]);
    35 		$pagenow = strtolower($self_matches[1]);
    27 		if ( '.php' !== substr($pagenow, -4, 4) )
    36 		if ( '.php' !== substr($pagenow, -4, 4) )
    28 			$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
    37 			$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
    29 	}
    38 	}
    30 } else {
    39 } else {
    31 	if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $PHP_SELF, $self_matches) )
    40 	if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
    32 		$pagenow = strtolower($self_matches[1]);
    41 		$pagenow = strtolower($self_matches[1]);
    33 	else
    42 	else
    34 		$pagenow = 'index.php';
    43 		$pagenow = 'index.php';
    35 }
    44 }
       
    45 unset($self_matches);
    36 
    46 
    37 // Simple browser detection
    47 // Simple browser detection
    38 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = false;
    48 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = false;
    39 
    49 
    40 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
    50 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
    41 	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
    51 	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
    42 		$is_lynx = true;
    52 		$is_lynx = true;
    43 	} elseif ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'chrome') !== false ) {
    53 	} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
    44 		$is_chrome = true;
    54 		if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
    45 	} elseif ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false ) {
    55 			if ( $is_chrome = apply_filters( 'use_google_chrome_frame', is_admin() ) )
       
    56 				header( 'X-UA-Compatible: chrome=1' );
       
    57 			$is_winIE = ! $is_chrome;
       
    58 		} else {
       
    59 			$is_chrome = true;
       
    60 		}
       
    61 	} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
    46 		$is_safari = true;
    62 		$is_safari = true;
    47 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
    63 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
    48 		$is_gecko = true;
    64 		$is_gecko = true;
    49 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
    65 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
    50 		$is_winIE = true;
    66 		$is_winIE = true;
    55 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
    71 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
    56 		$is_NS4 = true;
    72 		$is_NS4 = true;
    57 	}
    73 	}
    58 }
    74 }
    59 
    75 
    60 if ( $is_safari && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') !== false )
    76 if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
    61 	$is_iphone = true;
    77 	$is_iphone = true;
    62 
    78 
    63 $is_IE = ( $is_macIE || $is_winIE );
    79 $is_IE = ( $is_macIE || $is_winIE );
    64 
    80 
    65 // Server detection
    81 // Server detection
    72 
    88 
    73 /**
    89 /**
    74  * Whether the server software is IIS or something else
    90  * Whether the server software is IIS or something else
    75  * @global bool $is_IIS
    91  * @global bool $is_IIS
    76  */
    92  */
    77 $is_IIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
    93 $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
    78 
    94 
    79 /**
    95 /**
    80  * Whether the server software is IIS 7.X
    96  * Whether the server software is IIS 7.X
    81  * @global bool $is_iis7
    97  * @global bool $is_iis7
    82  */
    98  */
    83 $is_iis7 = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
    99 $is_iis7 = $is_IIS && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
    84 
   100 
       
   101 /**
       
   102  * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
       
   103  *
       
   104  * @return bool true|false
       
   105  */
       
   106 function wp_is_mobile() {
       
   107 	static $is_mobile;
    85 
   108 
    86 ?>
   109 	if ( isset($is_mobile) )
       
   110 		return $is_mobile;
       
   111 
       
   112 	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
       
   113 		$is_mobile = false;
       
   114 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
       
   115 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
       
   116 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
       
   117 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
       
   118 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
       
   119 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) {
       
   120 			$is_mobile = true;
       
   121 	} else {
       
   122 		$is_mobile = false;
       
   123 	}
       
   124 
       
   125 	return $is_mobile;
       
   126 }