| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_Defender\Model\Setting; |
| 4 |
|
| 5 |
use Calotes\Model\Setting; |
| 6 |
|
| 7 |
class Security_Tweaks extends Setting { |
| 8 |
public $table = 'hardener_settings'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Store a list of issues tweaks, as slug. |
| 12 |
* @var array |
| 13 |
*/ |
| 14 |
public $issues = array(); |
| 15 |
|
| 16 |
/** |
| 17 |
* Store a list of fixed tweaks, as slug. |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
public $fixed = array(); |
| 21 |
|
| 22 |
/** |
| 23 |
* Store a list of ignored tweaks, as slug. |
| 24 |
* @var array |
| 25 |
*/ |
| 26 |
public $ignore = array(); |
| 27 |
|
| 28 |
/** |
| 29 |
* Contains all the data generated by rules. |
| 30 |
* @var array |
| 31 |
*/ |
| 32 |
public $data = array(); |
| 33 |
|
| 34 |
/** |
| 35 |
* Last time visit into the hardener page. |
| 36 |
* @var integer |
| 37 |
*/ |
| 38 |
public $last_seen; |
| 39 |
|
| 40 |
/** |
| 41 |
* Last notification sent out. |
| 42 |
* @var integer |
| 43 |
*/ |
| 44 |
public $last_sent; |
| 45 |
|
| 46 |
public $automate = false; |
| 47 |
|
| 48 |
/** |
| 49 |
* @param $slug |
| 50 |
* |
| 51 |
* @return bool |
| 52 |
*/ |
| 53 |
public function is_tweak_ignore( $slug ) { |
| 54 |
// Empty ignored tweak is string on old versions, so change it to array. |
| 55 |
if ( is_string( $this->ignore ) ) { |
| 56 |
$this->ignore = empty( $this->ignore ) ? array() : array( $this->ignore ); |
| 57 |
$this->save(); |
| 58 |
} |
| 59 |
return in_array( $slug, $this->ignore, true ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @param $as |
| 64 |
* @param $slug |
| 65 |
*/ |
| 66 |
public function mark( $as, $slug ) { |
| 67 |
foreach ( [ 'issues', 'fixed', 'ignore' ] as $list ) { |
| 68 |
$arr = $this->$list; |
| 69 |
$index = array_search( $slug, $arr, true ); |
| 70 |
if ( $index !== false ) { |
| 71 |
unset( $arr[ $index ] ); |
| 72 |
} |
| 73 |
$this->$list = $arr; |
| 74 |
} |
| 75 |
if ( \WP_Defender\Controller\Security_Tweaks::STATUS_RESTORE === $as ) { |
| 76 |
$as = \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES; |
| 77 |
} |
| 78 |
$list = $this->{$as}; |
| 79 |
$list[] = $slug; |
| 80 |
$this->{$as} = $list; |
| 81 |
$this->save(); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Define labels for settings key. |
| 86 |
* |
| 87 |
* @param string|null $key |
| 88 |
* |
| 89 |
* @return string|array|null |
| 90 |
*/ |
| 91 |
public function labels( $key = null ) { |
| 92 |
$labels = array( |
| 93 |
'data' => 'data', |
| 94 |
'fixed' => __( 'Actioned', 'wpdef' ), |
| 95 |
'issues' => __( 'Recommendations', 'wpdef' ), |
| 96 |
'ignore' => __( 'Ignored', 'wpdef' ), |
| 97 |
'automate' => 'automate', |
| 98 |
); |
| 99 |
|
| 100 |
if ( ! is_null( $key ) ) { |
| 101 |
return $labels[ $key ] ?? null; |
| 102 |
} |
| 103 |
|
| 104 |
return $labels; |
| 105 |
} |
| 106 |
} |
| 107 |
|