| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\Properties; |
| 4 |
|
| 5 |
use ImportWP\Common\Util\Singleton; |
| 6 |
|
| 7 |
#[\AllowDynamicProperties] |
| 8 |
class Properties |
| 9 |
{ |
| 10 |
use Singleton; |
| 11 |
|
| 12 |
public $plugin_dir_path; |
| 13 |
public $plugin_folder_name; |
| 14 |
public $plugin_basename; |
| 15 |
public $view_dir; |
| 16 |
public $plugin_domain; |
| 17 |
public $plugin_version; |
| 18 |
public $plugin_file_path; |
| 19 |
public $encodings; |
| 20 |
public $chunk_timeout; |
| 21 |
public $chunk_limit; |
| 22 |
public $chunk_size; |
| 23 |
public $file_rotation; |
| 24 |
public $log_rotation; |
| 25 |
public $timeout; |
| 26 |
public $is_pro; |
| 27 |
|
| 28 |
public $mu_plugin_version; |
| 29 |
public $mu_plugin_dir; |
| 30 |
public $mu_plugin_source; |
| 31 |
public $mu_plugin_dest; |
| 32 |
|
| 33 |
public $rest_version; |
| 34 |
public $rest_namespace; |
| 35 |
|
| 36 |
public function __construct() |
| 37 |
{ |
| 38 |
$this->plugin_file_path = realpath(dirname(__DIR__) . '/../../jc-importer.php'); |
| 39 |
$this->plugin_dir_path = plugin_dir_path($this->plugin_file_path); |
| 40 |
$this->plugin_folder_name = basename($this->plugin_dir_path); |
| 41 |
$this->plugin_basename = plugin_basename($this->plugin_file_path); |
| 42 |
$this->plugin_domain = 'importwp'; |
| 43 |
$this->plugin_version = IWP_VERSION; |
| 44 |
$this->is_pro = false; |
| 45 |
$this->encodings = $this->get_available_encodings(); |
| 46 |
|
| 47 |
$this->view_dir = $this->plugin_dir_path . trailingslashit('views'); |
| 48 |
|
| 49 |
$this->rest_namespace = 'iwp'; |
| 50 |
$this->rest_version = 'v1'; |
| 51 |
|
| 52 |
$this->file_rotation = intval(apply_filters('iwp/file_rotation', $this->get_setting('file_rotation'))); |
| 53 |
$this->log_rotation = intval(apply_filters('iwp/log_rotation', $this->get_setting('log_rotation'))); |
| 54 |
$this->timeout = intval(apply_filters('iwp/timeout', $this->get_setting('timeout'))); |
| 55 |
} |
| 56 |
|
| 57 |
protected function get_available_encodings() |
| 58 |
{ |
| 59 |
$output = []; |
| 60 |
|
| 61 |
if (function_exists('mb_list_encodings')) { |
| 62 |
$encodings = mb_list_encodings(); |
| 63 |
foreach ($encodings as $encoding) { |
| 64 |
$output[$encoding] = $encoding; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return $output; |
| 69 |
} |
| 70 |
|
| 71 |
public function _default_settings() |
| 72 |
{ |
| 73 |
return [ |
| 74 |
'debug' => [ |
| 75 |
'type' => 'bool', |
| 76 |
'value' => false, |
| 77 |
], |
| 78 |
'cleanup' => [ |
| 79 |
'type' => 'bool', |
| 80 |
'value' => false |
| 81 |
], |
| 82 |
'file_rotation' => [ |
| 83 |
'type' => 'number', |
| 84 |
'value' => 5 |
| 85 |
], |
| 86 |
'log_rotation' => [ |
| 87 |
'type' => 'number', |
| 88 |
'value' => -1 |
| 89 |
], |
| 90 |
'timeout' => [ |
| 91 |
'type' => 'number', |
| 92 |
'value' => 30 |
| 93 |
], |
| 94 |
]; |
| 95 |
} |
| 96 |
|
| 97 |
public function get_settings() |
| 98 |
{ |
| 99 |
$defaults = $this->_default_settings(); |
| 100 |
$settings = get_option('iwp_settings', []); |
| 101 |
$output = []; |
| 102 |
|
| 103 |
foreach ($defaults as $setting => $default) { |
| 104 |
$output[$setting] = isset($settings[$setting]) ? $settings[$setting] : $default['value']; |
| 105 |
} |
| 106 |
|
| 107 |
return $output; |
| 108 |
} |
| 109 |
|
| 110 |
public function get_setting($key) |
| 111 |
{ |
| 112 |
$defaults = $this->_default_settings(); |
| 113 |
$settings = get_option('iwp_settings', []); |
| 114 |
|
| 115 |
if (!isset($defaults[$key])) { |
| 116 |
return false; |
| 117 |
} |
| 118 |
|
| 119 |
return isset($settings[$key]) ? $settings[$key] : $defaults[$key]['value']; |
| 120 |
} |
| 121 |
} |
| 122 |
|