]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/vars.php
WordPress 4.2.5-scripts
[autoinstalls/wordpress.git] / wp-includes / vars.php
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,
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 = false;
52
53 if ( isset($_SERVER['HTTP_USER_AGENT']) ) {
54         if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false ) {
55                 $is_lynx = true;
56         } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false ) {
57                 if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'chromeframe' ) !== false ) {
58                         $is_admin = is_admin();
59                         /**
60                          * Filter whether Google Chrome Frame should be used, if available.
61                          *
62                          * @since 3.2.0
63                          *
64                          * @param bool $is_admin Whether to use the Google Chrome Frame. Default is the value of is_admin().
65                          */
66                         if ( $is_chrome = apply_filters( 'use_google_chrome_frame', $is_admin ) )
67                                 header( 'X-UA-Compatible: chrome=1' );
68                         $is_winIE = ! $is_chrome;
69                 } else {
70                         $is_chrome = true;
71                 }
72         } elseif ( stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false ) {
73                 $is_safari = true;
74         } elseif ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false ) && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false ) {
75                 $is_winIE = true;
76         } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false ) {
77                 $is_macIE = true;
78         } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false ) {
79                 $is_gecko = true;
80         } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ) {
81                 $is_opera = true;
82         } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false ) {
83                 $is_NS4 = true;
84         }
85 }
86
87 if ( $is_safari && stripos($_SERVER['HTTP_USER_AGENT'], 'mobile') !== false )
88         $is_iphone = true;
89
90 $is_IE = ( $is_macIE || $is_winIE );
91
92 // Server detection
93
94 /**
95  * Whether the server software is Apache or something else
96  * @global bool $is_apache
97  */
98 $is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
99
100 /**
101  * Whether the server software is Nginx or something else
102  * @global bool $is_nginx
103  */
104 $is_nginx = (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
105
106 /**
107  * Whether the server software is IIS or something else
108  * @global bool $is_IIS
109  */
110 $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false);
111
112 /**
113  * Whether the server software is IIS 7.X or greater
114  * @global bool $is_iis7
115  */
116 $is_iis7 = $is_IIS && intval( substr( $_SERVER['SERVER_SOFTWARE'], strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/' ) + 14 ) ) >= 7;
117
118 /**
119  * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
120  *
121  * @return bool true|false
122  */
123 function wp_is_mobile() {
124         static $is_mobile;
125
126         if ( isset($is_mobile) )
127                 return $is_mobile;
128
129         if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
130                 $is_mobile = false;
131         } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
132                 || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
133                 || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
134                 || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
135                 || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
136                 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
137                 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
138                         $is_mobile = true;
139         } else {
140                 $is_mobile = false;
141         }
142
143         return $is_mobile;
144 }