\n" . $tawkto . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( !empty(aio_get_option('opt-enable-chative')) ) {
$chative = aio_get_option('txtChativeScript');
if ( !empty($chative) ) {
echo "\n" . $chative . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
private function send_telegram($message) {
$token = aio_get_option('txtTelegramToken');
$chat_id = aio_get_option('txtTelegramChatId');
if (empty($token) || empty($chat_id)) return;
$url = "https://api.telegram.org/bot{$token}/sendMessage";
wp_remote_post($url, [
'body' => [
'chat_id' => $chat_id,
'text' => $message,
'parse_mode' => 'HTML'
]
]);
}
private function send_larksuite($message, $title = "Notification") {
$webhook = aio_get_option('txtLarksuiteWebhook');
if (empty($webhook)) return;
$body = [
'msg_type' => 'post',
'content' => [
'post' => [
'vi_vn' => [
'title' => $title,
'content' => [
[
[
'tag' => 'text',
'text' => wp_strip_all_tags($message)
]
]
]
]
]
]
];
wp_remote_post($webhook, [
'headers' => ['Content-Type' => 'application/json'],
'body' => wp_json_encode($body)
]);
}
public function notify_cf7_submission($contact_form) {
$enable_tel = !empty(aio_get_option('opt-telegram-cf7'));
$enable_lark = !empty(aio_get_option('opt-larksuite-cf7'));
if (!$enable_tel && !$enable_lark) return;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$form_title = $contact_form->title();
$domain = isset($_SERVER['SERVER_NAME']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])) : '';
$msg = "" . __('New Form Submission', 'aio-tools') . "\n";
$msg .= __('Form:', 'aio-tools') . " {$form_title}\n";
$msg .= __('Domain:', 'aio-tools') . " {$domain}\n";
$msg .= "------------------------\n";
foreach ($posted_data as $key => $value) {
// Ignore internal CF7 fields
if (strpos($key, '_') === 0) continue;
$val = is_array($value) ? implode(', ', $value) : $value;
$msg .= "" . ucfirst($key) . ": " . $val . "\n";
}
if ($enable_tel) $this->send_telegram($msg);
if ($enable_lark) $this->send_larksuite($msg, __('New Contact Form Submission', 'aio-tools'));
}
}
public function notify_woo_order($order_id, $order = null) {
$enable_tel = !empty(aio_get_option('opt-telegram-woo'));
$enable_lark = !empty(aio_get_option('opt-larksuite-woo'));
if (!$enable_tel && (!$enable_lark)) return;
if (!$order) {
$order = wc_get_order($order_id);
}
if (!$order) return;
//$domain = isset($_SERVER['SERVER_NAME']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])) : '';
$total = $order->get_formatted_order_total();
$name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$phone = $order->get_billing_phone();
$address = $order->get_formatted_billing_address();
$address = wp_strip_all_tags( str_replace( array( '
', '
', '
' ), ", ", $address ) );
$items = $order->get_items();
$note = $order->get_customer_note();
/* translators: %s: Order ID */
$msg = "" . sprintf(__('New Order #%s', 'aio-tools'), $order_id) . "\n";
//$msg .= __('Domain:', 'aio-tools') . " {$domain}\n";
$msg .= "------------------------\n";
$msg .= "" . __('Customer:', 'aio-tools') . " " . esc_html($name) . "\n";
$msg .= "" . __('Phone:', 'aio-tools') . " " . esc_html($phone) . "\n";
$msg .= "" . __('Address:', 'aio-tools') . " " . esc_html($address) . "\n";
if ( !empty($note) ) {
$msg .= "" . __('Note:', 'aio-tools') . " " . esc_html($note) . "\n";
}
$msg .= "------------------------\n";
foreach ($items as $item) {
$product_name = $item->get_name();
$qty = $item->get_quantity();
$item_total = wp_strip_all_tags(wc_price($item->get_total()));
$msg .= "• " . esc_html($product_name) . " x{$qty} ({$item_total})\n";
}
$msg .= "------------------------\n";
$msg .= "" . __('Total:', 'aio-tools') . " " . wp_strip_all_tags(html_entity_decode($total)) . "\n";
if ($enable_tel) $this->send_telegram($msg);
/* translators: %s: Order ID */
if ($enable_lark) $this->send_larksuite($msg, sprintf(__('New WooCommerce Order #%s', 'aio-tools'), $order_id));
}
public function notify_fatal_error() {
$enable_tel = !empty(aio_get_option('opt-telegram-error'));
$enable_lark = !empty(aio_get_option('opt-larksuite-error'));
if (!$enable_tel && !$enable_lark) return;
$error = error_get_last();
if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR])) {
$domain = isset($_SERVER['SERVER_NAME']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])) : 'CLI';
$msg = "🚨 " . __('CRITICAL SITE ERROR', 'aio-tools') . "\n";
$msg .= __('Domain:', 'aio-tools') . " {$domain}\n";
$msg .= "------------------------\n";
$msg .= "" . __('Message:', 'aio-tools') . " " . wp_strip_all_tags($error['message']) . "\n";
$msg .= "" . __('File:', 'aio-tools') . " " . $error['file'] . "\n";
$msg .= "" . __('Line:', 'aio-tools') . " " . $error['line'] . "\n";
if ($enable_tel) $this->send_telegram($msg);
if ($enable_lark) $this->send_larksuite($msg, __('CRITICAL SITE ERROR', 'aio-tools'));
}
}
}
new AIO_Messenger();