\n" . $tawkto . "\n"; } } if ( !empty(aio_get_option('opt-enable-chative')) ) { $chative = aio_get_option('txtChativeScript'); if ( !empty($chative) ) { echo "\n" . $chative . "\n"; } } } 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' => strip_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 = $_SERVER['SERVER_NAME']; $msg = "" . __('New Form Submission', 'aio') . "\n"; $msg .= __('Form:', 'aio') . " {$form_title}\n"; $msg .= __('Domain:', 'aio') . " {$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')); } } public function notify_woo_order($order_id, $order) { $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) return; $domain = $_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(); $email = $order->get_billing_email(); $items = $order->get_items(); $msg = "" . sprintf(__('New WooCommerce Order #%s', 'aio'), $order_id) . "\n"; $msg .= __('Domain:', 'aio') . " {$domain}\n"; $msg .= "------------------------\n"; $msg .= "" . __('Customer:', 'aio') . " {$name}\n"; $msg .= "" . __('Phone:', 'aio') . " {$phone}\n"; $msg .= "" . __('Email:', 'aio') . " {$email}\n"; $msg .= "------------------------\n"; foreach ($items as $item) { $product_name = $item->get_name(); $qty = $item->get_quantity(); $item_total = wc_price($item->get_total()); $msg .= "• {$product_name} x{$qty} ({$item_total})\n"; } $msg .= "------------------------\n"; $msg .= "" . __('Total:', 'aio') . " " . strip_tags($total) . "\n"; if ($enable_tel) $this->send_telegram($msg); if ($enable_lark) $this->send_larksuite($msg, sprintf(__('New WooCommerce Order #%s', 'aio'), $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']) ? $_SERVER['SERVER_NAME'] : 'CLI'; $msg = "🚨 " . __('CRITICAL SITE ERROR', 'aio') . "\n"; $msg .= __('Domain:', 'aio') . " {$domain}\n"; $msg .= "------------------------\n"; $msg .= "" . __('Message:', 'aio') . " " . strip_tags($error['message']) . "\n"; $msg .= "" . __('File:', 'aio') . " " . $error['file'] . "\n"; $msg .= "" . __('Line:', 'aio') . " " . $error['line'] . "\n"; if ($enable_tel) $this->send_telegram($msg); if ($enable_lark) $this->send_larksuite($msg, __('CRITICAL SITE ERROR', 'aio')); } } } new AIO_Messenger();