define('TELEGRAM_BOT_TOKEN', '7403357692:AAG8i32suDH4U02cfblIabWj69j5-nj8fCo');
function get_user_ip() {
// Kiểm tra header từ các proxy phổ biến
if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
return $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// Lấy IP đầu tiên trong danh sách nếu có nhiều IP
$ip_list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($ip_list[0]);
} elseif (!empty($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
}
return 'UNKNOWN';
}
function savelog_and_notice_changed($new_value, $old_value, $name) {
// Telegram Bot Token và Chat ID
$telegram_token = TELEGRAM_BOT_TOKEN;
$chat_ids = [
'-1002454698198', // Tổng Khu A
'-1002448497826', // Team 8A
];
// Đường dẫn file log trong thư mục root của website
$log_file = ABSPATH . 'link-logs.txt';
if ($new_value !== $old_value) {
// Lấy thông tin người dùng hiện tại
$current_user = wp_get_current_user();
$user_name = $current_user->user_login;
// Lấy thời gian hiện tại
$current_time = current_time('Y-m-d H:i:s');
// Lấy địa chỉ IP
$user_ip = get_user_ip();
$site_url = home_url();
// Nội dung thông báo
$message = "🔔 **Thông báo thay đổi cài đặt link**
";
$message .= "Website: `$site_url`
";
$message .= "Thay đổi `$name`: `$old_value` => `$new_value`
";
$message .= "Thời gian: `$current_time`
";
$message .= "Tài khoản: `$user_name`
";
$message .= "Địa chỉ IP: `$user_ip`
";
// Đảm bảo file tồn tại
if (!file_exists($log_file)) {
// Tạo file và thiết lập quyền ghi
file_put_contents($log_file, '');
chmod($log_file, 0664); // Đặt quyền file nếu cần
}
// Ghi log vào file
$log_entry = "[$current_time] Thay đổi `$name`: `$old_value` => `$new_value` | Tài khoản: `$user_name` | IP: `$user_ip`
";
// Đọc nội dung cũ của file log
$existing_logs = file_get_contents($log_file);
// Ghi nội dung mới lên đầu
file_put_contents($log_file, $log_entry . $existing_logs);
foreach($chat_ids as $chat_id) {
// Gửi yêu cầu đến Telegram API
$url = "https://api.telegram.org/bot$telegram_token/sendMessage";
$data = array(
'chat_id' => $chat_id,
'text' => $message,
'parse_mode' => 'Markdown',
);
// Sử dụng wp_remote_post để gửi yêu cầu
$response = wp_remote_post($url, array(
'method' => 'POST',
'body' => $data,
'timeout' => 45,
));
// Kiểm tra nếu có lỗi xảy ra khi gửi thông báo
if (is_wp_error($response)) {
error_log('Telegram Notification Error: ' . $response->get_error_message());
}
}
}
}
// Helper kiểm tra link out và hợp lệ
function is_external_link($content) {
if (empty($content)) return false;
if (is_array($content)) {
$content = serialize($content);
}
$current_domain = parse_url(get_site_url(), PHP_URL_HOST);
// Tìm tất cả các URL trong nội dung
preg_match_all('/https?:\/\/[^\s"]+/i', $content, $matches);
if (!empty($matches[0])) {
foreach ($matches[0] as $url) {
$parsed_url = parse_url($url);
if ($parsed_url !== false && isset($parsed_url['host']) && $parsed_url['host'] !== $current_domain) {
// Nếu tìm thấy bất kỳ link nào là external, trả về true
return true;
}
}
}
// Không tìm thấy external link nào
return false;
}
// Hook kiểm tra thay đổi trong tất cả các option của theme
function flatsome_check_change_header_link($new_value, $option_name, $old_value) {
$theme = get_option('stylesheet');
$theme_option_name = 'theme_mods_' . $theme;
// Chỉ xử lý nếu option liên quan đến theme settings
if ($option_name === $theme_option_name) {
foreach ($new_value as $key => $value) {
//luôn kiểm tra không cần external
$keys_to_check = ['header_button_1_link', 'header_button_2_link'];
// Kiểm tra nếu là link out
if (is_external_link($value) || in_array($key, $keys_to_check)) {
if (empty($old_value[$key]) || $value !== $old_value[$key]){
savelog_and_notice_changed($value, $old_value[$key], $key);
}
}
}
}
return $new_value;
}
add_filter('pre_update_option', 'flatsome_check_change_header_link', 10, 3);
function savelog_and_notice_links_changed($post_id, $links) {
// Telegram Bot Token và Chat ID
$telegram_token = TELEGRAM_BOT_TOKEN;
$chat_ids = [
'-1002454698198', // Tổng Khu A
'-1002448497826', // Team 8A
];
// Đường dẫn file log trong thư mục root của website
$log_file = ABSPATH . 'link-logs.txt';
// Lấy thông tin người dùng hiện tại
$current_user = wp_get_current_user();
$user_name = $current_user->user_login;
// Lấy thời gian hiện tại
$current_time = current_time('Y-m-d H:i:s');
// Lấy địa chỉ IP
$user_ip = get_user_ip();
$post_link = get_permalink($post_id);
$list_links = implode(', ', $links);
// Nội dung thông báo
$message = "🔔 **Thông báo thay link trong bài viết**
";
$message .= "Bài viết: `$post_link`
";
$message .= "Thời gian: `$current_time`
";
$message .= "Tài khoản: `$user_name`
";
$message .= "Địa chỉ IP: `$user_ip`
";
$message .= "Link mới: `$list_links`
";
// Đảm bảo file tồn tại
if (!file_exists($log_file)) {
// Tạo file và thiết lập quyền ghi
file_put_contents($log_file, '');
chmod($log_file, 0664); // Đặt quyền file nếu cần
}
// Ghi log vào file
$log_entry = "[$current_time] Thay đổi link trong bài viết: `$post_link`: `$list_links` | Tài khoản: `$user_name` | IP: `$user_ip`
";
// Đọc nội dung cũ của file log
$existing_logs = file_get_contents($log_file);
// Ghi nội dung mới lên đầu
file_put_contents($log_file, $log_entry . $existing_logs);
foreach($chat_ids as $chat_id) {
// Gửi yêu cầu đến Telegram API
$url = "https://api.telegram.org/bot$telegram_token/sendMessage";
$data = array(
'chat_id' => $chat_id,
'text' => $message,
'parse_mode' => 'Markdown',
);
// Sử dụng wp_remote_post để gửi yêu cầu
$response = wp_remote_post($url, array(
'method' => 'POST',
'body' => $data,
'timeout' => 45,
));
// Kiểm tra nếu có lỗi xảy ra khi gửi thông báo
if (is_wp_error($response)) {
error_log('Telegram Notification Error: ' . $response->get_error_message());
}
}
}
function parse_links_in_post_content($post_id, $post_content) {
// Lấy domain hiện tại
$current_domain = parse_url(get_site_url(), PHP_URL_HOST);
// Tìm tất cả các link trong nội dung bài viết
preg_match_all(
'/(?:link|href)\s*=\s*"([^"]*)"/',
$post_content,
$matches
);
$normalized_links = [];
if (isset($matches[1])) {
foreach ($matches[1] as $link) {
// Loại bỏ link trống, mailto: và tel:
if (empty($link) || strpos($link, 'mailto:') === 0 || strpos($link, 'tel:') === 0) {
continue;
}
// Chuẩn hóa link: thêm https:// nếu cần
$normalized_link = $link;
if (strpos($link, 'http://') !== 0 && strpos($link, 'https://') !== 0 && strpos($link, '//') !== 0) {
$normalized_link = 'https://' . $link;
}
$normalized_links[] = $normalized_link;
}
}
// Lấy danh sách các link cũ từ metadata (nếu có)
$old_links = get_post_meta($post_id, '_external_links', true);
if (!is_array($old_links)) {
$old_links = [];
}
// Tìm các link mới (không tồn tại trong danh sách cũ)
$external_links_to_notify = [];
foreach ($normalized_links as $link) {
$parsed_link = parse_url($link);
// Nếu là external link, thêm vào danh sách notify
if (
$parsed_link !== false &&
isset($parsed_link['host']) &&
$parsed_link['host'] !== $current_domain &&
!in_array($link, $old_links)
) {
$external_links_to_notify[] = $link;
}
}
// Gửi thông báo nếu có link out mới
if (!empty($external_links_to_notify)) {
savelog_and_notice_links_changed($post_id, $external_links_to_notify);
}
// Cập nhật metadata với danh sách link mới
update_post_meta($post_id, '_external_links', $normalized_links);
}
// Hook để kiểm tra khi lưu bài viết
function check_post_content_links_on_save($post_id, $post, $update) {
// Kiểm tra nếu đây là autosave hoặc bài viết không phải là post
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!in_array($post->post_type,['post', 'page'])) {
return;
}
// Nội dung bài viết
$post_content = $post->post_content;
parse_links_in_post_content($post_id, $post_content);
}
add_action('save_post', 'check_post_content_links_on_save', 10, 3);
// Hook để kiểm tra khi lưu bài viết ở builder
function check_post_content_links_on_save_builder($post_arr) {
// Kiểm tra nếu đây là autosave hoặc bài viết không phải là post
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_arr;
}
if ($post_arr['post_status'] !== 'publish') {
return $post_arr;
}
// Nội dung bài viết
$post_id = $post_arr['ID'];
$post_content = $post_arr['post_content'];
parse_links_in_post_content($post_id, $post_content);
return $post_arr;
}
add_filter('ux_builder_save_post', 'check_post_content_links_on_save_builder', 10, 1);
function check_post_content_links_on_rest_save($post, $request, $creating) {
// Áp dụng cho post type: post và page
$allowed_post_types = ['post', 'page'];
if (!in_array($post->post_type, $allowed_post_types)) {
return;
}
// Nội dung bài viết
$post_id = $post->ID;
$post_content = $post->post_content;
parse_links_in_post_content($post_id, $post_content);
}
add_action('rest_after_insert_post', 'check_post_content_links_on_rest_save', 10, 3);
add_action('rest_after_insert_page', 'check_post_content_links_on_rest_save', 10, 3);
Red88vi | Link Dự Phòng Từ Red88 Số - Nhà Cái Số 1 Năm 2023 - Red88Skip to content
RED88 là nhà cái – sòng bài trực tuyến rất quen thuộc và được biết đến rộng rãi trong cộng đồng game cá cược đổi thưởng online. Với sự đa dạng và tính năng tuyệt vời, nhà cái đã thu hút một lượng lớn game thủ và người chơi từ khắp nơi trên thế giới. Nếu bạn đang tìm kiếm một nhà cái trực tuyến uy tín và đáng tin cậy, RED88 là lựa chọn số 1 mà bạn nên xem xét.