Skip to content

Instantly share code, notes, and snippets.

@TrywaR
Last active October 15, 2019 02:01
Show Gist options
  • Save TrywaR/c569fe52e8151bab46fda941ac4971f8 to your computer and use it in GitHub Desktop.
Save TrywaR/c569fe52e8151bab46fda941ac4971f8 to your computer and use it in GitHub Desktop.
MODX Revo | AjaxForm | Telegram | antiSpam > Прокачка антиспама до отправки уведомлений через чат бот в канал телеграмма
<?php
function text_error(){
return false;
die();
}
if(isset($_POST['org'])){
if($hook->getValue('org')!=''){
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Ошибка заполнения формы: не пустое поле антиспама');
$modx->log(xPDO::LOG_LEVEL_ERROR, print_r($_POST, 1));
text_error();
}else{
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Сообщение успешно отправленно');
$modx->log(xPDO::LOG_LEVEL_ERROR, print_r($_POST, 1));
// - Стучим в телегу
// -- Параметры
$sApiKey = '1111111111111111111111111111';
$sChatId = '1111111111111111111111111111';
$sPageUrl = $modx->config['site_url'] . $modx->resource->get('uri');
$sPageTitle = $modx->resource->get('pagetitle');
$sformName = $hook->formit->config['formName'];
$sTxt = '*Заполненна форма*: '.$sformName.'%0A';
$sTxt .= 'на странице: ['.$sPageTitle.']('.$sPageUrl.')%0A';
$sUrl = 'https://api.telegram.org/bot'.$sApiKey.'/sendMessage?chat_id='.$sChatId.'&parse_mode=Markdown&text='.$sTxt;
// -- Записываем данные с формы
foreach ($_POST as $key => $value)
if ( $value != '' && $key != 'pageId' )
$sUrl .= '*'.$key.'*: '.$value.'%0A';
// -- Паша, отправь плз
file_get_contents($sUrl);
// $modx->log(xPDO::LOG_LEVEL_ERROR, 'Шлём в телегу');
// $modx->log(xPDO::LOG_LEVEL_ERROR, print_r($content, 1));
// - Стучим в телегу х
return true;
}
}else{
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Ошибка заполнения формы: нет поля антиспама');
$modx->log(xPDO::LOG_LEVEL_ERROR, print_r($_POST, 1));
text_error();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment