Censoring.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Pages\Admin;
  10. use ForkBB\Models\Page;
  11. use ForkBB\Models\Pages\Admin;
  12. use function \ForkBB\__;
  13. class Censoring extends Admin
  14. {
  15. /**
  16. * Просмотр, редактирвоание и добавление запрещенных слов
  17. */
  18. public function edit(array $args, string $method): Page
  19. {
  20. $this->c->Lang->load('validator');
  21. $this->c->Lang->load('admin_censoring');
  22. if ('POST' === $method) {
  23. $v = $this->c->Validator->reset()
  24. ->addRules([
  25. 'token' => 'token:AdminCensoring',
  26. 'b_censoring' => 'required|integer|in:0,1',
  27. 'form.*.search_for' => 'string:trim|max:60',
  28. 'form.*.replace_with' => 'string:trim|max:60',
  29. ])->addAliases([
  30. ])->addArguments([
  31. ])->addMessages([
  32. ]);
  33. if ($v->validation($_POST)) {
  34. $this->c->config->b_censoring = $v->b_censoring;
  35. $this->c->config->save();
  36. $this->c->censorship->save($v->form);
  37. return $this->c->Redirect->page('AdminCensoring')->message('Data updated redirect');
  38. }
  39. $this->fIswev = $v->getErrors();
  40. }
  41. $this->nameTpl = 'admin/form';
  42. $this->aIndex = 'censoring';
  43. $this->form = $this->formEdit();
  44. $this->classForm = ['editcensorship'];
  45. $this->titleForm = 'Censoring';
  46. return $this;
  47. }
  48. /**
  49. * Подготавливает массив данных для формы
  50. */
  51. protected function formEdit(): array
  52. {
  53. $form = [
  54. 'action' => $this->c->Router->link('AdminCensoring'),
  55. 'hidden' => [
  56. 'token' => $this->c->Csrf->create('AdminCensoring'),
  57. ],
  58. 'sets' => [
  59. 'onoff' => [
  60. 'fields' => [
  61. 'b_censoring' => [
  62. 'type' => 'radio',
  63. 'value' => $this->c->config->b_censoring,
  64. 'values' => [1 => __('Yes'), 0 => __('No')],
  65. 'caption' => 'Censor words label',
  66. 'help' => 'Censor words help',
  67. ],
  68. ],
  69. ],
  70. 'onoff-info' => [
  71. 'info' => [
  72. [
  73. 'value' => __('Censoring info'),
  74. 'html' => true,
  75. ],
  76. ],
  77. ],
  78. ],
  79. 'btns' => [
  80. 'submit' => [
  81. 'type' => 'submit',
  82. 'value' => __('Save changes'),
  83. ],
  84. ],
  85. ];
  86. $fieldset = [];
  87. foreach ($this->c->censorship->load() as $id => $row) {
  88. $fieldset["form[{$id}][search_for]"] = [
  89. 'class' => ['censor'],
  90. 'type' => 'text',
  91. 'maxlength' => '60',
  92. 'value' => $row['search_for'],
  93. 'caption' => 'Censored word label',
  94. ];
  95. $fieldset["form[{$id}][replace_with]"] = [
  96. 'class' => ['censor'],
  97. 'type' => 'text',
  98. 'maxlength' => '60',
  99. 'value' => $row['replace_with'],
  100. 'caption' => 'Replacement label',
  101. ];
  102. }
  103. $fieldset["form[0][search_for]"] = [
  104. 'class' => ['censor'],
  105. 'type' => 'text',
  106. 'maxlength' => '60',
  107. 'value' => '',
  108. 'caption' => 'Censored word label',
  109. ];
  110. $fieldset["form[0][replace_with]"] = [
  111. 'class' => ['censor'],
  112. 'type' => 'text',
  113. 'maxlength' => '60',
  114. 'value' => '',
  115. 'caption' => 'Replacement label',
  116. ];
  117. $form['sets']['censtable'] = [
  118. 'class' => ['censor'],
  119. 'fields' => $fieldset,
  120. ];
  121. return $form;
  122. }
  123. }