home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / vars.php < prev    next >
Encoding:
PHP Script  |  2017-06-15  |  5.5 KB  |  151 lines

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