| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server / SAPI detection. |
| 4 |
* |
| 5 |
* Used by Gzip and the UI to decide which optimizations are server-applied |
| 6 |
* (Apache / LiteSpeed via .htaccess) vs. require manual config (nginx). |
| 7 |
* |
| 8 |
* @package XSpeed |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace XSpeed; |
| 12 |
|
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
class Server { |
| 16 |
|
| 17 |
const APACHE = 'apache'; |
| 18 |
const LITESPEED = 'litespeed'; |
| 19 |
const NGINX = 'nginx'; |
| 20 |
const IIS = 'iis'; |
| 21 |
const UNKNOWN = 'unknown'; |
| 22 |
|
| 23 |
public static function type() { |
| 24 |
global $is_apache, $is_nginx, $is_IIS, $is_iis7; |
| 25 |
|
| 26 |
$signature = self::server_signature(); |
| 27 |
|
| 28 |
if ( false !== stripos( $signature, 'litespeed' ) ) { |
| 29 |
return self::LITESPEED; |
| 30 |
} |
| 31 |
if ( ! empty( $is_apache ) || function_exists( 'apache_get_modules' ) || false !== stripos( $signature, 'apache' ) ) { |
| 32 |
return self::APACHE; |
| 33 |
} |
| 34 |
if ( ! empty( $is_nginx ) || false !== stripos( $signature, 'nginx' ) ) { |
| 35 |
return self::NGINX; |
| 36 |
} |
| 37 |
if ( ! empty( $is_IIS ) || ! empty( $is_iis7 ) || false !== stripos( $signature, 'microsoft-iis' ) ) { |
| 38 |
return self::IIS; |
| 39 |
} |
| 40 |
|
| 41 |
// Fallback: presence of .htaccess implies an Apache-compatible host. |
| 42 |
if ( file_exists( ABSPATH . '.htaccess' ) ) { |
| 43 |
return self::APACHE; |
| 44 |
} |
| 45 |
|
| 46 |
return self::UNKNOWN; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Whether the server respects .htaccess / web.config-style file-based config. |
| 51 |
*/ |
| 52 |
public static function supports_htaccess() { |
| 53 |
$t = self::type(); |
| 54 |
return self::APACHE === $t || self::LITESPEED === $t; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* GZIP support category for the UI: |
| 59 |
* 'auto' — toggling writes server config (Apache / LiteSpeed) |
| 60 |
* 'manual' — must be configured outside the plugin (nginx, IIS, unknown) |
| 61 |
*/ |
| 62 |
public static function gzip_mode() { |
| 63 |
return self::supports_htaccess() ? 'auto' : 'manual'; |
| 64 |
} |
| 65 |
|
| 66 |
private static function server_signature() { |
| 67 |
return isset( $_SERVER['SERVER_SOFTWARE'] ) |
| 68 |
? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) |
| 69 |
: ''; |
| 70 |
} |
| 71 |
} |
| 72 |
|