wp/wp-includes/vars.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    20 	$is_apache, $is_IIS, $is_iis7, $is_nginx;
    20 	$is_apache, $is_IIS, $is_iis7, $is_nginx;
    21 
    21 
    22 // On which page are we ?
    22 // On which page are we ?
    23 if ( is_admin() ) {
    23 if ( is_admin() ) {
    24 	// wp-admin pages are checked more carefully
    24 	// wp-admin pages are checked more carefully
    25 	if ( is_network_admin() )
    25 	if ( is_network_admin() ) {
    26 		preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    26 		preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
    27 	elseif ( is_user_admin() )
    27 	} elseif ( is_user_admin() ) {
    28 		preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    28 		preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
    29 	else
    29 	} else {
    30 		preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
    30 		preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
       
    31 	}
    31 	$pagenow = $self_matches[1];
    32 	$pagenow = $self_matches[1];
    32 	$pagenow = trim($pagenow, '/');
    33 	$pagenow = trim( $pagenow, '/' );
    33 	$pagenow = preg_replace('#\?.*?$#', '', $pagenow);
    34 	$pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
    34 	if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
    35 	if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
    35 		$pagenow = 'index.php';
    36 		$pagenow = 'index.php';
    36 	} else {
    37 	} else {
    37 		preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
    38 		preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
    38 		$pagenow = strtolower($self_matches[1]);
    39 		$pagenow = strtolower( $self_matches[1] );
    39 		if ( '.php' !== substr($pagenow, -4, 4) )
    40 		if ( '.php' !== substr( $pagenow, -4, 4 ) ) {
    40 			$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
    41 			$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
       
    42 		}
    41 	}
    43 	}
    42 } else {
    44 } else {
    43 	if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
    45 	if ( preg_match( '#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches ) ) {
    44 		$pagenow = strtolower($self_matches[1]);
    46 		$pagenow = strtolower( $self_matches[1] );
    45 	else
    47 	} else {
    46 		$pagenow = 'index.php';
    48 		$pagenow = 'index.php';
       
    49 	}
    47 }
    50 }
    48 unset($self_matches);
    51 unset( $self_matches );
    49 
    52 
    50 // Simple browser detection
    53 // Simple browser detection
    51 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false;
    54 $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false;
    52 
    55 
    53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
    56 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
    54 	if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
    57 	if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Lynx' ) !== false ) {
    55 		$is_lynx = true;
    58 		$is_lynx = true;
    56 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
    59 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
    57 		$is_edge = true;
    60 		$is_edge = true;
    58 	} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
    61 	} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chrome' ) !== false ) {
    59 		if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
    62 		if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
    60 			$is_admin = is_admin();
    63 			$is_admin = is_admin();
    61 			/**
    64 			/**
    62 			 * Filters whether Google Chrome Frame should be used, if available.
    65 			 * Filters whether Google Chrome Frame should be used, if available.
    63 			 *
    66 			 *
    64 			 * @since 3.2.0
    67 			 * @since 3.2.0
    65 			 *
    68 			 *
    66 			 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
    69 			 * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
    67 			 */
    70 			 */
    68 			if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) )
    71 			if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) ) {
    69 				header( 'X-UA-Compatible: chrome=1' );
    72 				header( 'X-UA-Compatible: chrome=1' );
       
    73 			}
    70 			$is_winIE = ! $is_chrome;
    74 			$is_winIE = ! $is_chrome;
    71 		} else {
    75 		} else {
    72 			$is_chrome = true;
    76 			$is_chrome = true;
    73 		}
    77 		}
    74 	} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
    78 	} elseif ( stripos( $_SERVER['HTTP_USER_AGENT'], 'safari' ) !== false ) {
    75 		$is_safari = true;
    79 		$is_safari = true;
    76 	} elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
    80 	} elseif ( ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident' ) !== false ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Win' ) !== false ) {
    77 		$is_winIE = true;
    81 		$is_winIE = true;
    78 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
    82 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mac' ) !== false ) {
    79 		$is_macIE = true;
    83 		$is_macIE = true;
    80 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
    84 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko' ) !== false ) {
    81 		$is_gecko = true;
    85 		$is_gecko = true;
    82 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
    86 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera' ) !== false ) {
    83 		$is_opera = true;
    87 		$is_opera = true;
    84 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
    88 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Nav' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.' ) !== false ) {
    85 		$is_NS4 = true;
    89 		$is_NS4 = true;
    86 	}
    90 	}
    87 }
    91 }
    88 
    92 
    89 if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
    93 if ( $is_safari && stripos( $_SERVER['HTTP_USER_AGENT'], 'mobile' ) !== false ) {
    90 	$is_iphone = true;
    94 	$is_iphone = true;
       
    95 }
    91 
    96 
    92 $is_IE = ( $is_macIE || $is_winIE );
    97 $is_IE = ( $is_macIE || $is_winIE );
    93 
    98 
    94 // Server detection
    99 // Server detection
    95 
   100 
    96 /**
   101 /**
    97  * Whether the server software is Apache or something else
   102  * Whether the server software is Apache or something else
       
   103  *
    98  * @global bool $is_apache
   104  * @global bool $is_apache
    99  */
   105  */
   100 $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
   106 $is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false );
   101 
   107 
   102 /**
   108 /**
   103  * Whether the server software is Nginx or something else
   109  * Whether the server software is Nginx or something else
       
   110  *
   104  * @global bool $is_nginx
   111  * @global bool $is_nginx
   105  */
   112  */
   106 $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
   113 $is_nginx = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false );
   107 
   114 
   108 /**
   115 /**
   109  * Whether the server software is IIS or something else
   116  * Whether the server software is IIS or something else
       
   117  *
   110  * @global bool $is_IIS
   118  * @global bool $is_IIS
   111  */
   119  */
   112 $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
   120 $is_IIS = ! $is_apache && ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false );
   113 
   121 
   114 /**
   122 /**
   115  * Whether the server software is IIS 7.X or greater
   123  * Whether the server software is IIS 7.X or greater
       
   124  *
   116  * @global bool $is_iis7
   125  * @global bool $is_iis7
   117  */
   126  */
   118 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
   127 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
   119 
   128 
   120 /**
   129 /**
   121  * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
   130  * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
   122  *
   131  *
   123  * @since 3.4.0
   132  * @since 3.4.0
   124  * 
   133  *
   125  * @return bool
   134  * @return bool
   126  */
   135  */
   127 function wp_is_mobile() {
   136 function wp_is_mobile() {
   128 	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
   137 	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
   129 		$is_mobile = false;
   138 		$is_mobile = false;
   130 	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
   139 	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.)
   131 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
   140 		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
   132 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
   141 		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
   133 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
   142 		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
   134 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
   143 		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
   135 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
   144 		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
   136 		|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
   145 		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
   137 			$is_mobile = true;
   146 			$is_mobile = true;
   138 	} else {
   147 	} else {
   139 		$is_mobile = false;
   148 		$is_mobile = false;
   140 	}
   149 	}
   141 
   150