diff --git a/admin/class-settings-page.php b/admin/class-settings-page.php new file mode 100644 index 0000000..40923ab --- /dev/null +++ b/admin/class-settings-page.php @@ -0,0 +1,107 @@ +guard('cf7stg_save'); + if (!Settings::is_bot_token_constant()) { + $token = (string)($_POST['bot_token'] ?? ''); + if ($token !== '') Settings::set_bot_token($token); + } + if (!Settings::is_chat_id_constant()) { + Settings::set_chat_id(sanitize_text_field((string)($_POST['chat_id'] ?? ''))); + } + Settings::set_site_title(sanitize_text_field((string)($_POST['site_title'] ?? ''))); + $this->redirect_back(['saved' => 1]); + } + + public function handle_test(): void + { + $this->guard('cf7stg_test'); + try { + TelegramClient::send_message( + Settings::get_chat_id(), + '✅ Тестовое сообщение из плагина CF7 Spam → Telegram (' + . esc_html(Settings::get_site_title()) . ')' + ); + Settings::set_last_test(['ok' => true, 'at' => current_time('mysql'), 'err' => '']); + $this->redirect_back(['test' => 'ok']); + } catch (TelegramException $e) { + Settings::set_last_test(['ok' => false, 'at' => current_time('mysql'), 'err' => $e->getMessage()]); + $this->redirect_back(['test' => 'err']); + } + } + + public function handle_retro(): void + { + $this->guard('cf7stg_retro'); + $count = max(1, min(RetroImporter::MAX_COUNT, (int)($_POST['retro_count'] ?? 10))); + $days = max(0, (int)($_POST['retro_days'] ?? 7)); + $repeat = !empty($_POST['retro_repeat']); + $result = RetroImporter::import($count, $days, $repeat); + $this->redirect_back(['retro_added' => (int)$result['added'], 'retro_skipped' => (int)$result['skipped']]); + } + + public function handle_retry_failed(): void + { + $this->guard('cf7stg_retry_failed'); + $n = Queue::retry_all_failed(); + $this->redirect_back(['retried' => $n]); + } + + public function handle_purge_sent(): void + { + $this->guard('cf7stg_purge_sent'); + $n = Queue::purge_sent(); + $this->redirect_back(['purged' => $n]); + } + + private function guard(string $action): void + { + if (!current_user_can('manage_options')) wp_die('forbidden'); + check_admin_referer($action, self::NONCE); + } + + private function redirect_back(array $extra = []): void + { + $url = add_query_arg(array_merge(['page' => self::PAGE_SLUG], $extra), admin_url('options-general.php')); + wp_safe_redirect($url); + exit; + } +} diff --git a/admin/views/settings.php b/admin/views/settings.php new file mode 100644 index 0000000..108d83d --- /dev/null +++ b/admin/views/settings.php @@ -0,0 +1,111 @@ +

Настройки сохранены.

'; +if (($_GET['test'] ?? '') === 'ok') $notice = '

Тестовое сообщение отправлено.

'; +if (($_GET['test'] ?? '') === 'err') $notice = '

Ошибка отправки: ' . esc_html($last_test['err'] ?? '') . '

'; +if (isset($_GET['retro_added'])) $notice = '

Добавлено в очередь: ' . (int)$_GET['retro_added'] . ', пропущено: ' . (int)$_GET['retro_skipped'] . '.

'; +if (isset($_GET['retried'])) $notice = '

Перезапущено с ошибкой: ' . (int)$_GET['retried'] . '.

'; +if (isset($_GET['purged'])) $notice = '

Удалено отправленных: ' . (int)$_GET['purged'] . '.

'; +?> +
+

CF7 Spam → Telegram

+ + +
+ + +

Настройки Telegram

+ + + + + + + + + + + + + +
+ + Задано константой SPAM2TG_BOT_TOKEN в wp-config.php (readonly). + + +

Можно задать константой SPAM2TG_BOT_TOKEN в wp-config.php вместо БД.

+ +
+ + Задано константой SPAM2TG_CHAT_ID (readonly). + + + +
+ +

Если пусто — используется домен (декодированный из Punycode).

+
+ +
+ +
+ + + + + + + ✅ Последняя проверка: — OK + + ⚠️ Последняя проверка: + + + +
+ +
+ +

Ретроспективная выгрузка из Flamingo

+
+ + + + + + + + + + + + + + + +
Количество записей макс. 50
Только за последние дней (0 = без ограничения)
 
+ +
+ +
+ +

Состояние очереди

+

В очереди (ожидают): · Отправлено за сутки: · С ошибками:

+ +
+ + + +
+
+ + + +
+