| 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 ScotThread
{
private ?ScotTelegram $telegram;
public function __construct()
{
$this->telegram = ScotTelegram::getInstance();
}
public static function threadsTableName(): string
{
global $wpdb;
return $wpdb->prefix . 'scot_threads';
}
public function getOrCreateThread($user_id)
{
$thread = self::getThread($user_id);
if ($thread) return $thread;
$tread_name = scot_get_option('tread_name', 'Thread for user {{user_id}}');
if (!str_contains($tread_name, '{{user_id}}')) {
$tread_name .= ' {{user_id}}';
}
$tread_name = str_replace('{{user_id}}', $user_id, $tread_name);
$thread_data = $this->telegram->createForumTopic(ScotChat::groupId(), $tread_name);
self::insertThread($thread_data['message_thread_id'], $user_id);
return self::getThread($user_id);
}
public static function getThread($user_id)
{
global $wpdb;
$cache_key = 'thread_user_id_' . $user_id;
$cached_result = wp_cache_get($cache_key);
if ($cached_result !== false) {
return $cached_result;
}
$threads_table_name = self::threadsTableName();
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT thread_id FROM %i WHERE user_id = %d",
$threads_table_name,
$user_id
),
ARRAY_A
); // db call ok
if (!empty($results[0])) {
wp_cache_set($cache_key, $results[0]);
return $results[0];
}
return null;
}
private static function insertThread($thread_id, $user_id, $responder_nickname = '')
{
global $wpdb;
return $wpdb->insert(self::threadsTableName(), [
'thread_id' => $thread_id,
'user_id' => $user_id,
'responder_nickname' => $responder_nickname,
]);
}
}