| Server IP : 91.240.85.141 / Your IP : 216.73.216.223 Web Server : nginx/1.28.0 System : Linux nuevo.ru 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : ( 1029) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wpface_ru_usr/data/www/wpface.ru/wp-content/plugins/plh/inc/ |
Upload File : |
<?php
if (!defined('ABSPATH')) exit;
class ScotTelegram
{
private static ?ScotTelegram $instance = null;
private string $_api_url;
private $token;
private function __construct()
{
$this->_api_url = scot_get_option('telegram_server_url', 'https://api.telegram.org/bot');
$this->token = scot_get_option('bot_api_token', '');
}
static public function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
public function sendMessage($chat_id, $text, $thread_id = '', $debug = false)
{
$data = [
'chat_id' => $chat_id,
'message_thread_id' => $thread_id,
'text' => $text,
'parse_mode' => 'html'
];
$result = $this->makeRequest('sendMessage', $data);
if($debug){
return $result;
}
if (empty($result['ok']) && empty($result['result'])) return null;
return $result['result'];
}
public function createForumTopic($chat_id, $name)
{
$data = [
'chat_id' => $chat_id,
'name' => $name,
];
$result = $this->makeRequest('createForumTopic', $data);
if (empty($result['ok']) && empty($result['result'])) return null;
return $result['result'];
}
public function sendPhoto($chat_id, $photo, $caption = '')
{
$data = [
'chat_id' => $chat_id,
'photo' => $photo,
'caption' => $caption,
'parse_mode' => 'html'
];
return $this->makeRequest('sendPhoto', $data, ["Content-Type:multipart/form-data"]);
}
public function sendDocument($chat_id, $document, $caption = '')
{
$data = [
'chat_id' => $chat_id,
'document' => $document,
];
if (!empty($caption)) {
$data['caption'] = $caption;
}
return $this->makeRequest('sendDocument', $data, ["Content-Type:multipart/form-data"]);
}
public function deleteMessage($chat_id, $message_id)
{
$data = [
'chat_id' => $chat_id,
'message_id' => $message_id,
];
return $this->makeRequest('deleteMessage', $data);
}
public function editMessage($chat_id, $message_id, $new_text)
{
$data = [
'chat_id' => $chat_id,
'message_id' => $message_id,
'text' => $new_text,
];
return $this->makeRequest('editMessageText', $data);
}
private function makeRequest($method, $data, $headers = ["Content-Type: application/json"])
{
if (!$this->token) {
return false;
}
$result = wp_remote_post($this->_api_url . $this->token . '/' . $method,
[
'method' => 'POST',
'body' => $data,
'headers' => $headers,
'timeout' => 45,
]
);
$body = wp_remote_retrieve_body($result);
return json_decode($body, true);
}
public function getFileUrl($file_id)
{
$transient_name = "scot_file_url_$file_id";
$transient = get_transient($transient_name);
if(!empty($transient)) {
return $transient;
}
$api_url = "https://api.telegram.org/bot{$this->token}/getFile?file_id={$file_id}";
$response = wp_remote_get($api_url);
if (is_wp_error($response)) {
return false;
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if (!$data['ok']) {
return false;
}
$file_path = $data['result']['file_path'];
$result = "https://api.telegram.org/file/bot{$this->token}/{$file_path}";
set_transient($transient_name, $result, HOUR_IN_SECONDS);
return $result;
}
}