Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

142 rader
5.2 KiB

  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, Nginx and IIS -- three web
  10. * servers with known pretty permalink capability.
  11. *
  12. * Note: Though Nginx is detected, WordPress does not currently
  13. * generate rewrite rules for it. See https://codex.wordpress.org/Nginx
  14. *
  15. * @package WordPress
  16. */
  17. global $pagenow,
  18. $is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE, $is_edge,
  19. $is_apache, $is_IIS, $is_iis7, $is_nginx;
  20. // On which page are we ?
  21. if ( is_admin() ) {
  22. // wp-admin pages are checked more carefully
  23. if ( is_network_admin() )
  24. preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
  25. elseif ( is_user_admin() )
  26. preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
  27. else
  28. preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
  29. $pagenow = $self_matches[1];
  30. $pagenow = trim($pagenow, '/');
  31. $pagenow = preg_replace('#\?.*?$#', '', $pagenow);
  32. if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
  33. $pagenow = 'index.php';
  34. } else {
  35. preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
  36. $pagenow = strtolower($self_matches[1]);
  37. if ( '.php' !== substr($pagenow, -4, 4) )
  38. $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
  39. }
  40. } else {
  41. if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $_SERVER['PHP_SELF'], $self_matches) )
  42. $pagenow = strtolower($self_matches[1]);
  43. else
  44. $pagenow = 'index.php';
  45. }
  46. unset($self_matches);
  47. // Simple browser detection
  48. $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = $is_iphone = $is_edge = false;
  49. if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
  50. if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
  51. $is_lynx = true;
  52. } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Edge' ) !== false ) {
  53. $is_edge = true;
  54. } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
  55. if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
  56. $is_admin = is_admin();
  57. /**
  58. * Filters whether Google Chrome Frame should be used, if available.
  59. *
  60. * @since 3.2.0
  61. *
  62. * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
  63. */
  64. if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) )
  65. header( 'X-UA-Compatible: chrome=1' );
  66. $is_winIE = ! $is_chrome;
  67. } else {
  68. $is_chrome = true;
  69. }
  70. } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
  71. $is_safari = true;
  72. } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
  73. $is_winIE = true;
  74. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
  75. $is_macIE = true;
  76. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
  77. $is_gecko = true;
  78. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
  79. $is_opera = true;
  80. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
  81. $is_NS4 = true;
  82. }
  83. }
  84. if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
  85. $is_iphone = true;
  86. $is_IE = ( $is_macIE || $is_winIE );
  87. // Server detection
  88. /**
  89. * Whether the server software is Apache or something else
  90. * @global bool $is_apache
  91. */
  92. $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
  93. /**
  94. * Whether the server software is Nginx or something else
  95. * @global bool $is_nginx
  96. */
  97. $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
  98. /**
  99. * Whether the server software is IIS or something else
  100. * @global bool $is_IIS
  101. */
  102. $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
  103. /**
  104. * Whether the server software is IIS 7.X or greater
  105. * @global bool $is_iis7
  106. */
  107. $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
  108. /**
  109. * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
  110. *
  111. * @return bool
  112. */
  113. function wp_is_mobile() {
  114. if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
  115. $is_mobile = false;
  116. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
  117. || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
  118. || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
  119. || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
  120. || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
  121. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
  122. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
  123. $is_mobile = true;
  124. } else {
  125. $is_mobile = false;
  126. }
  127. return $is_mobile;
  128. }