| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Rules\Condition\Advanced; |
| 4 |
|
| 5 |
use Averta\Core\Utility\Arr; |
| 6 |
use Depicter\Rules\Condition\Base as ConditionBase; |
| 7 |
use Depicter\Utility\Sanitize; |
| 8 |
|
| 9 |
class Referrer extends ConditionBase |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @inheritdoc |
| 13 |
*/ |
| 14 |
public $slug = 'Advanced_Referrer'; |
| 15 |
|
| 16 |
/** |
| 17 |
* @inheritdoc |
| 18 |
*/ |
| 19 |
public $control = 'comparison'; |
| 20 |
|
| 21 |
/** |
| 22 |
* @inheritdoc |
| 23 |
*/ |
| 24 |
protected $belongsTo = 'Advanced'; |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* @inheritdoc |
| 29 |
*/ |
| 30 |
public function getLabel(): ?string{ |
| 31 |
return __('Referrer Path', 'depicter' ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @inheritDoc |
| 36 |
*/ |
| 37 |
public function getControlOptions(): array{ |
| 38 |
return []; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @inheritdoc |
| 43 |
*/ |
| 44 |
public function check( $value = null ): bool{ |
| 45 |
|
| 46 |
$value = $value ?? $this->value; |
| 47 |
$isIncluded = empty( $value ); |
| 48 |
if ( ! $isIncluded ) { |
| 49 |
$value = Arr::merge( $value, [ |
| 50 |
'targetParam' => $_SERVER['HTTP_REFERER'] ? Sanitize::textfield( $_SERVER['HTTP_REFERER'] ) : '', |
| 51 |
'comparisonFunction' => 'equal', |
| 52 |
'targetValue' => '' |
| 53 |
]); |
| 54 |
|
| 55 |
$isIncluded = $this->compare( trim( $value['targetParam'], '/'), $value['comparisonFunction'], trim( $value['targetValue'], '/' ) ); |
| 56 |
} |
| 57 |
|
| 58 |
return $this->selectionMode === 'include' ? $isIncluded : ! $isIncluded; |
| 59 |
} |
| 60 |
} |
| 61 |
|