| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Options for a redirect source URL |
| 5 |
*/ |
| 6 |
class Red_Source_Options { |
| 7 |
/** |
| 8 |
* Exclude this from logging. |
| 9 |
* |
| 10 |
* @var boolean |
| 11 |
*/ |
| 12 |
private $log_exclude = false; |
| 13 |
|
| 14 |
/** |
| 15 |
* Constructor |
| 16 |
* |
| 17 |
* @param array|null $options Options. |
| 18 |
*/ |
| 19 |
public function __construct( $options = null ) { |
| 20 |
if ( $options ) { |
| 21 |
$this->set_options( $options ); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Set options |
| 27 |
* |
| 28 |
* @param array $options Options. |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public function set_options( $options ) { |
| 32 |
if ( isset( $options['log_exclude'] ) && $options['log_exclude'] === true ) { |
| 33 |
$this->log_exclude = true; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Can this source be logged? |
| 39 |
* |
| 40 |
* @return boolean |
| 41 |
*/ |
| 42 |
public function can_log() { |
| 43 |
$options = red_get_options(); |
| 44 |
|
| 45 |
if ( isset( $options['expire_redirect'] ) && $options['expire_redirect'] !== -1 ) { |
| 46 |
return ! $this->log_exclude; |
| 47 |
} |
| 48 |
|
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Get options as JSON |
| 54 |
* |
| 55 |
* @return array |
| 56 |
*/ |
| 57 |
public function get_json() { |
| 58 |
return array_filter( [ |
| 59 |
'log_exclude' => $this->log_exclude, |
| 60 |
] ); |
| 61 |
} |
| 62 |
} |
| 63 |
|