/wp-includes/vars.php

https://github.com/sharpmachine/wakeupmedia.com · PHP · 126 lines · 79 code · 14 blank · 33 comment · 32 complexity · ff63e764a310743855c77b6e13333ae4 MD5 · raw file

  1. <?php
  2. /**
  3. * Creates common globals for the rest of WordPress
  4. *
  5. * Sets $pagenow global which is the current page. Checks
  6. * for the browser to set which one is currently being used.
  7. *
  8. * Detects which user environment WordPress is being used on.
  9. * Only attempts to check for Apache and IIS. Two web servers
  10. * with known permalink capability.
  11. *
  12. * @package WordPress
  13. */
  14. global $pagenow,
  15. $is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE,
  16. $is_apache, $is_IIS, $is_iis7;
  17. // On which page are we ?
  18. if ( is_admin() ) {
  19. // wp-admin pages are checked more carefully
  20. if ( is_network_admin() )
  21. preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
  22. elseif ( is_user_admin() )
  23. preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
  24. else
  25. preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
  26. $pagenow = $self_matches[1];
  27. $pagenow = trim($pagenow, '/');
  28. $pagenow = preg_replace('#\?.*?$#', '', $pagenow);
  29. if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
  30. $pagenow = 'index.php';
  31. } else {
  32. preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
  33. $pagenow = strtolower($self_matches[1]);
  34. if ( '.php' !== substr($pagenow, -4, 4) )
  35. $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
  36. }
  37. } else {
  38. if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
  39. $pagenow = strtolower($self_matches[1]);
  40. else
  41. $pagenow = 'index.php';
  42. }
  43. unset($self_matches);
  44. // Simple browser detection
  45. $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = false;
  46. if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
  47. if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
  48. $is_lynx = true;
  49. } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
  50. if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
  51. if ( $is_chrome = apply_filters( 'use_google_chrome_frame', is_admin() ) )
  52. header( 'X-UA-Compatible: chrome=1' );
  53. $is_winIE = ! $is_chrome;
  54. } else {
  55. $is_chrome = true;
  56. }
  57. } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
  58. $is_safari = true;
  59. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
  60. $is_gecko = true;
  61. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
  62. $is_winIE = true;
  63. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
  64. $is_macIE = true;
  65. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
  66. $is_opera = true;
  67. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
  68. $is_NS4 = true;
  69. }
  70. }
  71. if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
  72. $is_iphone = true;
  73. $is_IE = ( $is_macIE || $is_winIE );
  74. // Server detection
  75. /**
  76. * Whether the server software is Apache or something else
  77. * @global bool $is_apache
  78. */
  79. $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
  80. /**
  81. * Whether the server software is IIS or something else
  82. * @global bool $is_IIS
  83. */
  84. $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
  85. /**
  86. * Whether the server software is IIS 7.X
  87. * @global bool $is_iis7
  88. */
  89. $is_iis7 = $is_IIS && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
  90. /**
  91. * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
  92. *
  93. * @return bool true|false
  94. */
  95. function wp_is_mobile() {
  96. static $is_mobile;
  97. if ( isset($is_mobile) )
  98. return $is_mobile;
  99. if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
  100. $is_mobile = false;
  101. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
  102. || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
  103. || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
  104. || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
  105. || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
  106. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) {
  107. $is_mobile = true;
  108. } else {
  109. $is_mobile = false;
  110. }
  111. return $is_mobile;
  112. }