| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\Admin\Controller; |
| 4 |
|
| 5 |
use Asylum\Utility\Arr; |
| 6 |
use AgeGate\Admin\Settings\Message; |
| 7 |
use League\HTMLToMarkdown\HtmlConverter; |
| 8 |
use AgeGate\Common\Admin\AbstractController; |
| 9 |
use AgeGate\Common\Immutable\Constants as Immutable; |
| 10 |
|
| 11 |
class MessageController extends AbstractController |
| 12 |
{ |
| 13 |
use Message; |
| 14 |
// const PERMISSION = Constants::RESTRICTIONS; |
| 15 |
public const PERMISSION = Immutable::MESSAGES; |
| 16 |
public const OPTION = Immutable::OPTION_MESSAGE; |
| 17 |
|
| 18 |
protected function required(): bool |
| 19 |
{ |
| 20 |
return current_user_can(self::PERMISSION); |
| 21 |
} |
| 22 |
|
| 23 |
public function register(): void |
| 24 |
{ |
| 25 |
$this->menu(__('Messages', 'age-gate'), self::PERMISSION); |
| 26 |
} |
| 27 |
|
| 28 |
protected function data(): array |
| 29 |
{ |
| 30 |
return Arr::dot(get_option(self::OPTION, []) ?: []); |
| 31 |
} |
| 32 |
|
| 33 |
protected function fields(): array |
| 34 |
{ |
| 35 |
return $this->getMessageFields(); |
| 36 |
} |
| 37 |
|
| 38 |
public function enqueue(): void |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
protected function store() |
| 43 |
{ |
| 44 |
$_POST['ag_settings'] = wp_unslash($this->sanitizeHtml($_POST['ag_settings'])); |
| 45 |
|
| 46 |
parent::store(); |
| 47 |
} |
| 48 |
|
| 49 |
protected function sanitizeHtml($array) |
| 50 |
{ |
| 51 |
$converter = new HtmlConverter(); |
| 52 |
foreach ($array ?? [] as $key => $setting) { |
| 53 |
|
| 54 |
if (is_array($setting)) { |
| 55 |
$array[$key] = $this->sanitizeHtml($setting); |
| 56 |
} else { |
| 57 |
|
| 58 |
$array[$key] = $converter->convert(html_entity_decode($setting)); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
return $array; |
| 64 |
} |
| 65 |
|
| 66 |
protected function rules() : array |
| 67 |
{ |
| 68 |
return [ |
| 69 |
// 'headline' => 'ag_message', |
| 70 |
// 'subheadline' => 'ag_message', |
| 71 |
// 'label_remember' => 'alpha_numeric_space', |
| 72 |
// 'label_aria' => 'ag_message', |
| 73 |
// 'label_buttons' => 'ag_message', |
| 74 |
// 'label_yes' => 'alpha_numeric_space', |
| 75 |
// 'label_no' => 'alpha_numeric_space', |
| 76 |
// 'label_day' => 'alpha_numeric_space', |
| 77 |
// 'label_month' => 'alpha_numeric_space', |
| 78 |
// 'label_year' => 'alpha_numeric_space', |
| 79 |
// 'placeholder_day' => 'alpha_numeric_space', |
| 80 |
// 'placeholder_month' => 'alpha_numeric_space', |
| 81 |
// 'placeholder_year' => 'alpha_numeric_space', |
| 82 |
// 'label_submit' => 'alpha_numeric_space', |
| 83 |
// 'label_no_cookies' => 'ag_message', |
| 84 |
// 'error_invalid' => 'ag_message_md', |
| 85 |
// 'error_failed' => 'ag_message_md', |
| 86 |
// 'error_generic' => 'ag_message_md', |
| 87 |
]; |
| 88 |
} |
| 89 |
} |
| 90 |
|