2003-04-21 23:37:11 +02:00
|
|
|
<?php
|
2008-01-04 21:05:07 +01:00
|
|
|
/**
|
|
|
|
* Creates common globals for the rest of WordPress
|
|
|
|
*
|
|
|
|
* Sets $pagenow global which is the current page. Checks
|
|
|
|
* for the browser to set which one is currently being used.
|
|
|
|
*
|
|
|
|
* Detects which user environment WordPress is being used on.
|
|
|
|
* Only attempts to check for Apache and IIS. Two web servers
|
|
|
|
* with known permalink capability.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2011-10-18 21:44:00 +02:00
|
|
|
global $pagenow,
|
|
|
|
$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE,
|
|
|
|
$is_apache, $is_IIS, $is_iis7;
|
|
|
|
|
2004-04-15 21:08:51 +02:00
|
|
|
// On which page are we ?
|
2007-09-04 05:21:04 +02:00
|
|
|
if ( is_admin() ) {
|
|
|
|
// wp-admin pages are checked more carefully
|
2010-10-07 21:34:18 +02:00
|
|
|
if ( is_network_admin() )
|
2011-10-18 21:37:07 +02:00
|
|
|
preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
|
2010-10-07 21:34:18 +02:00
|
|
|
elseif ( is_user_admin() )
|
2011-10-18 21:37:07 +02:00
|
|
|
preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
|
2010-10-07 21:34:18 +02:00
|
|
|
else
|
2011-10-18 21:37:07 +02:00
|
|
|
preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
|
2004-09-15 10:16:58 +02:00
|
|
|
$pagenow = $self_matches[1];
|
2009-08-01 23:12:17 +02:00
|
|
|
$pagenow = trim($pagenow, '/');
|
2007-09-04 05:21:04 +02:00
|
|
|
$pagenow = preg_replace('#\?.*?$#', '', $pagenow);
|
|
|
|
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
|
|
|
|
$pagenow = 'index.php';
|
|
|
|
} else {
|
|
|
|
preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
|
|
|
|
$pagenow = strtolower($self_matches[1]);
|
|
|
|
if ( '.php' !== substr($pagenow, -4, 4) )
|
|
|
|
$pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
|
|
|
|
}
|
2004-10-09 04:00:34 +02:00
|
|
|
} else {
|
2011-10-18 21:37:07 +02:00
|
|
|
if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
|
2007-09-04 05:21:04 +02:00
|
|
|
$pagenow = strtolower($self_matches[1]);
|
|
|
|
else
|
|
|
|
$pagenow = 'index.php';
|
2003-04-21 23:37:11 +02:00
|
|
|
}
|
2010-10-07 22:12:49 +02:00
|
|
|
unset($self_matches);
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2004-04-15 21:08:51 +02:00
|
|
|
// Simple browser detection
|
2008-12-02 13:32:54 +01:00
|
|
|
$is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = false;
|
2006-04-04 02:25:04 +02:00
|
|
|
|
2009-11-26 12:29:54 +01:00
|
|
|
if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
|
|
|
|
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
|
|
|
|
$is_lynx = true;
|
2010-02-14 03:27:19 +01:00
|
|
|
} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
|
2011-05-25 18:15:00 +02:00
|
|
|
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
|
|
|
|
if ( $is_chrome = apply_filters( 'use_google_chrome_frame', is_admin() ) )
|
|
|
|
header( 'X-UA-Compatible: chrome=1' );
|
|
|
|
$is_winIE = ! $is_chrome;
|
|
|
|
} else {
|
|
|
|
$is_chrome = true;
|
|
|
|
}
|
2010-02-14 03:27:19 +01:00
|
|
|
} elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
|
2009-11-26 12:29:54 +01:00
|
|
|
$is_safari = true;
|
|
|
|
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
|
|
|
|
$is_gecko = true;
|
|
|
|
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
|
|
|
|
$is_winIE = true;
|
|
|
|
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
|
|
|
|
$is_macIE = true;
|
|
|
|
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
|
|
|
|
$is_opera = true;
|
|
|
|
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
|
|
|
|
$is_NS4 = true;
|
|
|
|
}
|
2007-03-11 02:19:16 +01:00
|
|
|
}
|
2006-12-07 04:57:23 +01:00
|
|
|
|
2010-02-14 03:27:19 +01:00
|
|
|
if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
|
2008-12-02 13:32:54 +01:00
|
|
|
$is_iphone = true;
|
|
|
|
|
2006-12-07 04:57:23 +01:00
|
|
|
$is_IE = ( $is_macIE || $is_winIE );
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2004-04-15 21:08:51 +02:00
|
|
|
// Server detection
|
2008-01-04 21:05:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the server software is Apache or something else
|
|
|
|
* @global bool $is_apache
|
|
|
|
*/
|
2009-05-18 16:54:16 +02:00
|
|
|
$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
|
2008-01-04 21:05:07 +01:00
|
|
|
|
2013-09-16 22:07:09 +02:00
|
|
|
/**
|
|
|
|
* Whether the server software is Nginx or something else
|
|
|
|
* @global bool $is_nginx
|
|
|
|
*/
|
|
|
|
$is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
|
|
|
|
|
2008-01-04 21:05:07 +01:00
|
|
|
/**
|
|
|
|
* Whether the server software is IIS or something else
|
|
|
|
* @global bool $is_IIS
|
|
|
|
*/
|
2010-12-14 09:35:48 +01:00
|
|
|
$is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
|
2003-04-21 23:37:11 +02:00
|
|
|
|
2009-05-16 04:04:36 +02:00
|
|
|
/**
|
2013-07-08 22:27:06 +02:00
|
|
|
* Whether the server software is IIS 7.X or greater
|
2009-05-18 16:54:16 +02:00
|
|
|
* @global bool $is_iis7
|
2009-05-16 04:04:36 +02:00
|
|
|
*/
|
2013-07-08 22:27:06 +02:00
|
|
|
$is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
|
2012-04-10 03:19:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
|
|
|
|
*
|
|
|
|
* @return bool true|false
|
|
|
|
*/
|
|
|
|
function wp_is_mobile() {
|
|
|
|
static $is_mobile;
|
|
|
|
|
|
|
|
if ( isset($is_mobile) )
|
|
|
|
return $is_mobile;
|
|
|
|
|
|
|
|
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
|
|
|
|
$is_mobile = false;
|
|
|
|
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
|
|
|
|
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
|
2012-06-04 18:04:54 +02:00
|
|
|
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
|
|
|
|
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
|
2012-04-10 03:19:30 +02:00
|
|
|
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
|
2012-07-30 21:40:52 +02:00
|
|
|
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
|
|
|
|
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
|
2012-04-10 03:19:30 +02:00
|
|
|
$is_mobile = true;
|
|
|
|
} else {
|
|
|
|
$is_mobile = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $is_mobile;
|
|
|
|
}
|