From 6042538d8e0dab231614b379150c6a68e996d5cd Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 6 Mar 2023 14:48:05 +0700 Subject: [PATCH] Move send SMS/Wa/Telegram to class --- system/autoload/Message.php | 58 +++++++++++++++++++++++++++++++++++++ system/boot.php | 34 ---------------------- 2 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 system/autoload/Message.php diff --git a/system/autoload/Message.php b/system/autoload/Message.php new file mode 100644 index 0000000..2ac91ad --- /dev/null +++ b/system/autoload/Message.php @@ -0,0 +1,58 @@ + 5 + && !empty($textExpired) && in_array($via, ['sms', 'wa']) + ) { + $msg = str_replace('[[name]]', $name, $textExpired); + $msg = str_replace('[[package]]', $package, $msg); + if ($via == 'sms') { + Message::sendSMS($phone, $msg); + } else if ($via == 'wa') { + Message::sendWhatsapp($phone, $msg); + } + } + } + +} diff --git a/system/boot.php b/system/boot.php index 01c4d67..2b55909 100644 --- a/system/boot.php +++ b/system/boot.php @@ -228,40 +228,6 @@ function alphanumeric($str, $tambahan = "") return preg_replace("/[^a-zA-Z0-9" . $tambahan . "]+/", "", $str); } - -function sendTelegram($txt) -{ - global $config; - run_hook('send_telegram'); #HOOK - if (!empty($config['telegram_bot']) && !empty($config['telegram_target_id'])) { - file_get_contents('https://api.telegram.org/bot' . $config['telegram_bot'] . '/sendMessage?chat_id=' . $config['telegram_target_id'] . '&text=' . urlencode($txt)); - } -} - - -function sendSMS($phone, $txt) -{ - global $config; - run_hook('send_sms'); #HOOK - if (!empty($config['sms_url'])) { - $smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']); - $smsurl = str_replace('[text]', urlencode($txt), $smsurl); - file_get_contents($smsurl); - } -} - -function sendWhatsapp($phone, $txt) -{ - global $config; - run_hook('send_whatsapp'); #HOOK - if (!empty($config['wa_url'])) { - $waurl = str_replace('[number]', urlencode($phone), $config['wa_url']); - $waurl = str_replace('[text]', urlencode($txt), $waurl); - file_get_contents($waurl); - } -} - - function time_elapsed_string($datetime, $full = false) { $now = new DateTime;