[ Index ]

WordPress Cross Reference

title

Body

[close]

/wp-includes/ -> vars.php (source)

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


Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu