| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 4 |
|
| 5 |
require_once(WPO_PLUGIN_MAIN_PATH . 'vendor/autoload.php'); |
| 6 |
use HtaccessCapabilityTester\HtaccessCapabilityTester; |
| 7 |
|
| 8 |
class WPO_Htaccess_Capabilities { |
| 9 |
|
| 10 |
private static $_instance = null; |
| 11 |
|
| 12 |
/** |
| 13 |
* Tests and sets up server's htaccess capabilities as properties |
| 14 |
* |
| 15 |
* @var HtaccessCapabilityTester |
| 16 |
*/ |
| 17 |
public $hct; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var bool |
| 21 |
*/ |
| 22 |
public $htaccess_enabled; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var bool |
| 26 |
*/ |
| 27 |
public $mod_headers; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var bool |
| 31 |
*/ |
| 32 |
public $mod_mime; |
| 33 |
|
| 34 |
/** |
| 35 |
* @var bool |
| 36 |
*/ |
| 37 |
public $mod_rewrite; |
| 38 |
|
| 39 |
/** |
| 40 |
* Constructor |
| 41 |
*/ |
| 42 |
public function __construct() { |
| 43 |
$uploads = wp_upload_dir(); |
| 44 |
$this->hct = new HtaccessCapabilityTester($uploads['basedir'] . '/wpo', $uploads['baseurl'] . '/wpo'); |
| 45 |
$this->htaccess_enabled = (bool) $this->hct->htaccessEnabled(); |
| 46 |
$this->mod_headers = $this->get_mod_header_status(); |
| 47 |
$this->mod_mime = $this->get_mod_mime_status(); |
| 48 |
$this->mod_rewrite = $this->get_mod_rewrite_status(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Gets singleton instance |
| 53 |
* |
| 54 |
* @return self |
| 55 |
*/ |
| 56 |
public static function get_instance() { |
| 57 |
if (null === self::$_instance) { |
| 58 |
self::$_instance = new WPO_Htaccess_Capabilities(); |
| 59 |
} |
| 60 |
return self::$_instance; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Gets `mod_headers` status by checking if it is loaded and working |
| 65 |
* |
| 66 |
* @return bool |
| 67 |
*/ |
| 68 |
public function get_mod_header_status() { |
| 69 |
return (true === $this->hct->moduleLoaded('headers') && true === $this->hct->headerSetWorks()); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Gets `mod_mime` status by checking if it is loaded and working |
| 74 |
* |
| 75 |
* @return bool |
| 76 |
*/ |
| 77 |
public function get_mod_mime_status() { |
| 78 |
return (true === $this->hct->moduleLoaded('mime') && true === $this->hct->addTypeWorks()); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Gets `mod_rewrite` status by checking if it is loaded and working |
| 83 |
* |
| 84 |
* @return bool |
| 85 |
*/ |
| 86 |
public function get_mod_rewrite_status() { |
| 87 |
return (true === $this->hct->moduleLoaded('rewrite') && true == $this->hct->rewriteWorks()); |
| 88 |
} |
| 89 |
} |
| 90 |
|