| 1 |
<?php |
| 2 |
if (!defined('WPO_PLUGIN_MAIN_PATH')) die('No direct access allowed'); |
| 3 |
|
| 4 |
class WPO_Server_Info { |
| 5 |
|
| 6 |
private static $_instance = null; |
| 7 |
|
| 8 |
/** |
| 9 |
* @var $_server_name Web server engine name |
| 10 |
*/ |
| 11 |
private $_server_name; |
| 12 |
|
| 13 |
/** |
| 14 |
* @var $_rewrite_status Web server's URL rewrite ability |
| 15 |
*/ |
| 16 |
private $_rewrite_status; |
| 17 |
|
| 18 |
/** |
| 19 |
* Setup server information |
| 20 |
*/ |
| 21 |
public function __construct() { |
| 22 |
$this->set_server_name(); |
| 23 |
$this->set_rewrite_status(); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Gets singleton instance |
| 28 |
* |
| 29 |
* @return object |
| 30 |
*/ |
| 31 |
public static function get_instance() { |
| 32 |
if (null === self::$_instance) { |
| 33 |
self::$_instance = new self(); |
| 34 |
} |
| 35 |
return self::$_instance; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Detect and set web server names |
| 40 |
*/ |
| 41 |
private function set_server_name() { |
| 42 |
global $is_apache, $is_nginx, $is_iis7, $is_IIS; |
| 43 |
|
| 44 |
if ($is_apache) { |
| 45 |
$this->_server_name = 'apache'; |
| 46 |
} |
| 47 |
|
| 48 |
if ($is_iis7) { |
| 49 |
$this->_server_name = 'iis7'; |
| 50 |
} |
| 51 |
|
| 52 |
if ($is_IIS) { |
| 53 |
$this->_server_name = 'iis'; |
| 54 |
} |
| 55 |
|
| 56 |
if ($is_nginx) { |
| 57 |
$this->_server_name = 'nginx'; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Sets web server's rewrite ability |
| 63 |
*/ |
| 64 |
private function set_rewrite_status() { |
| 65 |
if ('apache' === $this->_server_name) { |
| 66 |
$this->test_htaccess_capabilities(); |
| 67 |
} else { |
| 68 |
$this->_rewrite_status = false; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Test Apache/LiteSpeed server's htaccess capabilities, and sets status and info |
| 74 |
*/ |
| 75 |
private function test_htaccess_capabilities() { |
| 76 |
$htc = WPO_Htaccess_Capabilities::get_instance(); |
| 77 |
if ($htc->htaccess_enabled && $htc->mod_rewrite && $htc->mod_headers && $htc->mod_mime) { |
| 78 |
$this->_rewrite_status = true; |
| 79 |
} elseif ($htc->htaccess_enabled) { |
| 80 |
$this->_rewrite_status = false; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Getter for web server name |
| 86 |
* |
| 87 |
* @return string |
| 88 |
*/ |
| 89 |
public function get_server_name() { |
| 90 |
return $this->_server_name; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Getter for web server's rewrite capability |
| 95 |
* |
| 96 |
* @return bool |
| 97 |
*/ |
| 98 |
public function get_rewrite_status() { |
| 99 |
return $this->_rewrite_status; |
| 100 |
} |
| 101 |
} |
| 102 |
|