Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: Telegram.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Telegram extends MY_Home_Controller { private $defaultMessage = ''; private $rsStngs = array(); private $userId = null; public function __construct() { parent::__construct(); $this->defaultMessage = 'Sorry, I do not understand.'; $this->rsStngs = (object)array(); } public function generate_one_time_token() { $UserId = $this->userId; //@file_put_contents(FCPATH . 'tele.txt', "User ID:" . $UserId . "\n\n", FILE_APPEND); $token = ''; if (!empty($UserId)) { //@file_put_contents(FCPATH . 'tele.txt', "before helper:\n\n\n" , FILE_APPEND); $this->load->helper('string'); //@file_put_contents(FCPATH . 'tele.txt', "after helper:\n\n\n" , FILE_APPEND); $token = random_string('alnum', 30); //@file_put_contents(FCPATH . 'tele.txt', "after TOKEN:$token\n\n\n" , FILE_APPEND); $this->db->where('UserId', $UserId) ->update('tbl_gf_users', ['onetimetoken' => $token]); //@file_put_contents(FCPATH . 'tele.txt', "after QUERY:\n\n\n" , FILE_APPEND); return $token; } else return 0; } public function generate_token() { $UserId = $this->session->userdata('GSM_FUS_UserId'); $token = ''; if (!empty($UserId)) { $this->load->helper('string'); $token = random_string('numeric', 6); $failSafe = 0; # to prevent infinite while loop # checking if same token already exists while ((!!$this->db->query("SELECT * FROM tbl_gf_users WHERE TelegramToken = '$token'")->row()) && ($failSafe <= 1000)) { $token = random_string('numeric', 6); $failSafe++; } $this->db->where('UserId', $UserId) ->update('tbl_gf_users', ['TelegramToken' => $token, 'genratedTime' => date('Y-m-d h:i')]); } $botName = ''; $telegramBotKey = $this->db->query("SELECT TelegramBotKey FROM tbl_gf_email_settings WHERE Id = 1")->row(); if ($telegramBotKey && $telegramBotKey->TelegramBotKey) { $bot = new \TelegramBot\Api\BotApi($telegramBotKey->TelegramBotKey); $botName = $bot->getMe()->getUsername(); } $html = 'Connect your account with your Telegram to get security alerts, orders status, check orders etc...<br><br>'; if (!empty($botName)) { $html .= 'Just search for "<b>' . $botName . '</b>" with contacts'; } $html .= '<div style="text-align: center;background: #ddd;padding: 10px;width: 50%;margin: 15px auto 0 auto;"><h3>' . $token . '</h3>Pairing Code</div><br>Note: This code will expire in about 5 minutes'; echo $html; } public function autobot() { try { $inline = false; $messageId = null; $flag = "1"; $this->rsStngs = $this->db->query("SELECT TelegramBotKey, Brnd FROM tbl_gf_email_settings WHERE Id = 1")->row(); $telegramBotKey = $this->rsStngs; if ($telegramBotKey && $telegramBotKey->TelegramBotKey) { $bot = new \TelegramBot\Api\Client($telegramBotKey->TelegramBotKey); // run, bot, run! $flag .= "2"; $bot->run(); $update = json_decode(file_get_contents("php://input"), TRUE); //@file_put_contents(FCPATH . 'tele.txt', "newinstance:" . print_r($update, true) . "\n"); if ($update['callback_query']) { $chatId = $update["callback_query"]["message"]["chat"]["id"]; } else { $chatId = $update["message"]["chat"]["id"]; } $message = $this->cleanEmojis($update["message"]["text"]); //@file_put_contents(FCPATH . 'tele.txt', "message:" . $message . "\n", FILE_APPEND); $telegramAuth = $this->db->where('TelegramId', $chatId)->get('tbl_gf_telegram_auth')->row(); $pairAccount = true; $pairStep = NULL; $pairCode = NULL; $pairUsername = NULL; $userId = null; if ($telegramAuth) { $flag .= "3"; if ($telegramAuth->UserId) { $flag .= "4"; $this->userId = $userId = $telegramAuth->UserId; $pairAccount = false; } elseif($telegramAuth->stepNo == 2) { $pairStep = $telegramAuth->stepNo; $pairCode = $telegramAuth->code; $pairUsername = $message; } else { $pairStep = $telegramAuth->stepNo; $this->db->where('TelegramId', $chatId)->update('tbl_gf_telegram_auth', array( 'code' => $message, 'stepNo' => 2 )); } } else { $flag .= "5"; $this->db->insert('tbl_gf_telegram_auth', ['UserId' => NULL, 'TelegramId' => $chatId, 'stepNo' => 1]); } $reply = ''; $keyboard = null; //@file_put_contents(FCPATH . 'tele.txt', "User ID:" . $userId . "\n\n", FILE_APPEND); $this->userId = $userId; //Call back block if ($update['callback_query']) { $flag .= "6"; //@file_put_contents(FCPATH . 'tele.txt', "In call back:\n\n\n", FILE_APPEND); $messageId = $update['callback_query']['message']['message_id']; $chatId = $update['callback_query']['message']['chat']['id']; // Get callback data (pressed number) $callBackData = $update['callback_query']['data']; //@file_put_contents(FCPATH . 'tele.txt', "call back data:" . $callBackData . "\n\n\n", FILE_APPEND); $callBackData = explode(":", $callBackData); //@file_put_contents(FCPATH . 'tele.txt', "back data array:" . print_r($callBackData, true) . "\n\n\n", FILE_APPEND); //get Services if(strtolower($callBackData[0]) == 'imeicat') //if it came from Services Categories list { $flag .= "-6A"; if($callBackData[1] == 'Close') { //Close the section //@file_put_contents(FCPATH . 'tele.txt', "closed call:\n\n\n", FILE_APPEND); $bot->deleteMessage($chatId, $messageId); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } else { //get IMEI Services Information $flag .= "-6B"; //@file_put_contents(FCPATH . 'tele.txt', "getting services:\n\n\n", FILE_APPEND); $keyboard = $this->getImeiServices($callBackData[1]); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($keyboard, true) . "\n", FILE_APPEND); $replyText = "please select service"; $response = $bot->editMessageText($chatId, $messageId, $replyText, null, false, $keyboard, null); //$response = $bot->editReplyMarkup($chatId, $messageId, $replyText, null, false, $keyboard, null); //@file_put_contents(FCPATH . 'tele.txt', "response:" . print_r($response, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } }//get Server Services Information elseif(strtolower($callBackData[0]) == strtolower('Servercat')) //if it came from Services Categories list { $flag .= "-6A"; if($callBackData[1] == 'Close') { //Close the section //@file_put_contents(FCPATH . 'tele.txt', "closed call:\n\n\n", FILE_APPEND); $bot->deleteMessage($chatId, $messageId); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } else { //get Service Information $flag .= "-6B"; //@file_put_contents(FCPATH . 'tele.txt', "getting services:\n\n\n", FILE_APPEND); $keyboard = $this->getServerServices($callBackData[1]); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($keyboard, true) . "\n", FILE_APPEND); $replyText = "please select service"; $response = $bot->editMessageText($chatId, $messageId, $replyText, null, false, $keyboard, null); //$response = $bot->editReplyMarkup($chatId, $messageId, $replyText, null, false, $keyboard, null); //@file_put_contents(FCPATH . 'tele.txt', "response:" . print_r($response, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } } //Get IMEI Service Details elseif(strtolower($callBackData[0]) == 'imeiservice') { $flag .= "-6C"; if($callBackData[1] == 'Back') { $keyboard = $this->getImeiServicesCategories(); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:\n\n\n" . print_r($keyboard, true) . "\n", FILE_APPEND); $replyText = "select category."; $response = $bot->editMessageText($chatId, $messageId, $replyText, null, false, $keyboard, null); //$response = $bot->editReplyMarkup($chatId, $messageId, $replyText, null, false, $keyboard, null); //@file_put_contents(FCPATH . 'tele.txt', "response:" . print_r($response, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } else { //get Service details $flag .= "-6D"; $responseArray = $this->getImeiServiceInfo($callBackData[1], $callBackData[2]); $keyboard = $responseArray['keyboard']; $replyText = $responseArray['text']; //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($keyboard, true) . "\n", FILE_APPEND); $response = $bot->editMessageText($chatId, $messageId, $replyText, 'html', false, $keyboard, null); //$response = $bot->editReplyMarkup($chatId, $messageId, $replyText, null, false, $keyboard, null); //@file_put_contents(FCPATH . 'tele.txt', "response:" . print_r($response, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } }//Get SERVER Service Details elseif(strtolower($callBackData[0]) == strtolower('ServerService')) { $flag .= "-6C"; if($callBackData[1] == 'Back') { $keyboard = $this->getServerServicesCategories(); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:\n\n\n" . print_r($keyboard, true) . "\n", FILE_APPEND); $replyText = "select category."; $response = $bot->editMessageText($chatId, $messageId, $replyText, null, false, $keyboard, null); //$response = $bot->editReplyMarkup($chatId, $messageId, $replyText, null, false, $keyboard, null); //@file_put_contents(FCPATH . 'tele.txt', "response:" . print_r($response, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } else { //get Service details $flag .= "-6D"; $responseArray = $this->getServerServiceInfo($callBackData[1], $callBackData[2]); $keyboard = $responseArray['keyboard']; $replyText = $responseArray['text']; //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($keyboard, true) . "\n", FILE_APPEND); $response = $bot->editMessageText($chatId, $messageId, $replyText, 'html', false, $keyboard, null); //$response = $bot->editReplyMarkup($chatId, $messageId, $replyText, null, false, $keyboard, null); //@file_put_contents(FCPATH . 'tele.txt', "response:" . print_r($response, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); } } elseif(strtolower($callBackData[0]) == strtolower("ImeiServiceInfo")) { $keyboard = $this->getImeiServices($callBackData[2]); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($keyboard, true) . "\n", FILE_APPEND); $replyText = "please select service"; $response = $bot->editMessageText($chatId, $messageId, $replyText, null, false, $keyboard, null); } elseif(strtolower($callBackData[0]) == strtolower("ServerServiceInfo")) { $keyboard = $this->getServerServices($callBackData[2]); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($keyboard, true) . "\n", FILE_APPEND); $replyText = "please select service"; $response = $bot->editMessageText($chatId, $messageId, $replyText, null, false, $keyboard, null); } } else { //If not Call back then $flag .= "7"; # check IMEI order if ($userId && ($telegramAuth && $telegramAuth->stepNo == 1)) { $flag .= "8"; $this->db->where('Id', $telegramAuth->Id)->update('tbl_gf_telegram_auth', array( 'stepNo' => NULL, )); $imei_number = $message; $order_row = $this->db->query("SELECT t1.CodeId, t1.CodeStatusId, t2.CodeStatus FROM tbl_gf_codes t1 LEFT JOIN tbl_gf_code_status t2 ON t1.CodeStatusId = t2.CodeStatusId WHERE t1.UserId = {$userId} AND IMEINo = '{$imei_number}'")->row(); if ($order_row) { if ($order_row->CodeStatusId == 2) $status_emoji = "\xE2\x9C\x85"; else $status_emoji = "\xE2\x9D\x8C"; $reply = "Order ID: #" . $order_row->CodeId . " " . $status_emoji . "\nStatus: " . $order_row->CodeStatus . "\n"; } else { $reply = "Order not found"; } } # check server order elseif ($userId && ($telegramAuth && $telegramAuth->stepNo == 2)) { $flag .= "9"; $this->db->where('Id', $telegramAuth->Id)->update('tbl_gf_telegram_auth', array( 'stepNo' => NULL, )); $order_id = $message; $order_row = $this->db->query("SELECT t1.LogRequestId, t1.StatusId, t2.CodeStatus FROM tbl_gf_log_requests t1 LEFT JOIN tbl_gf_code_status t2 ON t1.StatusId = t2.CodeStatusId WHERE t1.UserId = {$userId} AND LogRequestId = '{$order_id}'")->row(); if ($order_row) { if ($order_row->StatusId == 2) $status_emoji = "\xE2\x9C\x85"; else $status_emoji = "\xE2\x9D\x8C"; $reply = "Order ID: #" . $order_row->LogRequestId . " " . $status_emoji . "\nStatus: " . $order_row->CodeStatus . "\n"; } else { $reply = "Order not found"; } } elseif ($pairAccount && $message == '/start') { $flag .= "A"; $reply = 'Welcome to <b>' . $this->config->item('app_name') . '</b>. What is your pairing code?'; $keyboard = $this->makePairAccountKeyboard(); } else if ($pairAccount && $message == 'Pair Account') { $flag .= "B"; if ($pairAccount) { $reply = 'Welcome to <b>' . $this->config->item('app_name') . "</b>\n"; $reply .= "Login to our website\n\n"; $reply .= "Click on \"Connect Telegram\" on dashboard page.\n\n"; $reply .= "Get pairing code to pair account."; } } else if ($userId && ($message == '/help' || $message == 'Help')) { $flag .= "C"; $reply = $this->commandsList(); } else if ($userId && $message == '/checkimei') { $flag .= "D"; $this->db->where('Id', $telegramAuth->Id)->update('tbl_gf_telegram_auth', array( 'stepNo' => 1, )); $reply = 'Enter IMEI number'; } else if ($userId && $message == '/checkserver') { $flag .= "E"; $this->db->where('Id', $telegramAuth->Id)->update('tbl_gf_telegram_auth', array( 'stepNo' => 2, )); $reply = 'Enter server order id'; } else if ($userId && preg_match('/^\/checkserver (\d+)$/', $message, $grps)) { $flag .= "F"; $order_id = $grps[1]; $order_row = $this->db->query("SELECT t1.LogRequestId, t1.StatusId, t2.CodeStatus FROM tbl_gf_log_requests t1 LEFT JOIN tbl_gf_code_status t2 ON t1.StatusId = t2.CodeStatusId WHERE t1.UserId = {$userId} AND LogRequestId = '{$order_id}'")->row(); if ($order_row) { if ($order_row->StatusId == 2) $status_emoji = "\xE2\x9C\x85"; else $status_emoji = "\xE2\x9D\x8C"; $reply = "Order ID: #" . $order_row->LogRequestId . " " . $status_emoji . "\nStatus: " . $order_row->CodeStatus . "\n"; } else { $reply = "Order not found"; } } else if ($userId && preg_match('/^\/checkimei (\d+)$/', $message, $grps)) { $flag .= "G"; $imei_number = $grps[1]; $order_row = $this->db->query("SELECT t1.CodeId, t1.CodeStatusId, t2.CodeStatus FROM tbl_gf_codes t1 LEFT JOIN tbl_gf_code_status t2 ON t1.CodeStatusId = t2.CodeStatusId WHERE t1.UserId = {$userId} AND IMEINo = '{$imei_number}'")->row(); if ($order_row) { if ($order_row->CodeStatusId == 2) $status_emoji = "\xE2\x9C\x85"; else $status_emoji = "\xE2\x9D\x8C"; $reply = "Order ID: #" . $order_row->CodeId . " " . $status_emoji . "\nStatus: " . $order_row->CodeStatus . "\n"; } else { $reply = "Order not found"; } } $flag .= "H"; //@file_put_contents(FCPATH . 'tele.txt', "message:[[" . $message . "]]\n", FILE_APPEND); if ($userId && ($message == '/serverorders' || $message == 'Server Orders')) { $flag .= "I"; $last_ten_orders = $this->db->where('UserId', $userId) ->limit(10) ->order_by('LogRequestId', 'DESC') ->get('tbl_gf_log_requests') ->result(); //@file_put_contents(FCPATH . 'tele.txt', "query:[[" . $this->db->last_query() . "]]\n", FILE_APPEND); if($last_ten_orders){ foreach ($last_ten_orders as $order) { $status_emoji = ""; # success emoji if ($order->StatusId == 2) $status_emoji = "\xE2\x9C\x85"; else $status_emoji = "\xE2\x9D\x8C"; $reply .= "Order ID: #" . $order->LogRequestId . " " . $status_emoji . "\n"; } } else { $reply = "No Order Found"; } } else if ($userId && ($message == '/imeiorders' || $message == 'IMEI Orders')) { $last_ten_orders = $this->db->where('UserId', $userId) ->limit(10) ->order_by('CodeId', 'DESC') ->get('tbl_gf_codes') ->result(); if($last_ten_orders){ foreach ($last_ten_orders as $order) { $status_emoji = ""; # success emoji if ($order->CodeStatusId == 2) $status_emoji = "\xE2\x9C\x85"; else $status_emoji = "\xE2\x9D\x8C"; $reply .= "Order ID: #" . $order->CodeId . " " . $status_emoji . "\nIMEI: " . $order->IMEINo . "\n"; } } else { $reply = "No Order Found"; } } else if ($userId && ($message == '/me' || $message == 'My Account')) { $userInfo = $this->db->where('UserId', $userId)->get('tbl_gf_users')->row(); $reply = $userInfo->FirstName . ' ' . $userInfo->LastName . "\n"; $keys = crypt_key($userId); $reply .= "Credits: " . decrypt($userInfo->Credits, $keys); } else if ($userId && $message == '/unpair') { $this->db->where('Id', $telegramAuth->Id) ->delete('tbl_gf_telegram_auth'); $userId = null; $reply = "Your account is unpaired."; } else if ($userId && (strtolower($message) == strtolower('New IMEI Order') || strtolower($message) == strtolower('/NewImeiOrders'))) { //@file_put_contents(FCPATH . 'tele.txt', "before keyboard:\n\n\n", FILE_APPEND); $keyboard = $this->getImeiServicesCategories(); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:\n\n\n" . print_r($keyboard, true) . "\n", FILE_APPEND); $reply = "select category."; $inline = true; } else if ($userId && (strtolower($message) == strtolower('New Server Order') || strtolower($message) == strtolower('/NewServerOrders'))) { //@file_put_contents(FCPATH . 'tele.txt', "before keyboard:\n\n\n", FILE_APPEND); $keyboard = $this->getServerServicesCategories(); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:\n\n\n" . print_r($keyboard, true) . "\n", FILE_APPEND); $reply = "select category."; $inline = true; } else { if ($pairAccount) { if($pairStep == 1) { //update stepNo to 2 $this->db->where('TelegramId', $chatId); $reply = "Please enter your Username."; $keyboard = $this->makePairAccountKeyboard(); } else { $pairingUser = $this->db->select('UserId') ->where('TelegramToken', $pairCode) ->where('UserName', $pairUsername) ->get('tbl_gf_users') ->row(); if ($pairingUser && $telegramAuth) { # Updating user id in auth table $this->db->where('Id', $telegramAuth->Id) ->update('tbl_gf_telegram_auth', ['UserId' => $pairingUser->UserId]); # Resetting user token $this->db->where('UserId', $pairingUser->UserId) ->update('tbl_gf_users', ['TelegramToken' => NULL]); $userId = $pairingUser->UserId; $reply = "Account paired successfully\n"; $reply .= "I can help you to place orders, security notifications and check order status etc..\n\n"; $reply .= "You can control me by sending these commands:\n\n"; $reply .= $this->commandsList(); } else { $reply = "Wrong information...\nPlease enter Pairing Code"; $keyboard = $this->makePairAccountKeyboard(); $this->db->where('TelegramId', $chatId)->update('tbl_gf_telegram_auth', array( 'code' => '', 'stepNo' => 1 )); } } } } $flag .= "Z"; if (!empty($userId) && empty($keyboard)) { $keyboard = $this->makeActionsKeyboard(); } if ($reply !== false) { if (empty($reply)) { $reply = $this->defaultMessage; } } //@file_put_contents(FCPATH . 'tele.txt', "message was:\n\n\n[" . $message . "]\nflag=" . $flag , FILE_APPEND); if($inline) { $messageId = $bot->sendMessage($chatId, utf8_encode($reply), 'html', false, null, $keyboard); } else { $messageId = $bot->sendMessage($chatId, $reply, 'html', false, null, $keyboard); } //@file_put_contents(FCPATH . 'tele.txt', "response_normal_chat:\n\n\n" . print_r($messageId, true) . "\n", FILE_APPEND); } } } catch (Exception $e) { @file_put_contents(FCPATH . 'tele.txt', "Exception:\n\n\n" . print_r($e, true) . "\n", FILE_APPEND); } } public function getImeiServiceInfo($serviceId, $catId) { $PCK_TITLE = 'PackageTitle'; $TIME_TAKEN = 'TimeTaken'; $IMP_INFO = 'MustRead'; $rsPackage = $this->User_model->get_packages($PCK_TITLE, $TIME_TAKEN, $IMP_INFO, $serviceId); $userCurrency = $this->User_model->getUserCurrency($this->userId); $packagePrice = getpackprice($serviceId, $userCurrency->CurrencyId, 0, $this->userId, 3); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($rsPackage, true) . "\n", FILE_APPEND); $iCount = 0; //@file_put_contents(FCPATH . 'tele.txt', "getting token:\n\n\n" , FILE_APPEND); try { $randomToken = $this->generate_one_time_token(); $buttons = array(); $buttons[$iCount++][] = array( 'text' => "Place Order", 'url' => base_url("/login/getTelegramLogin?service_id={$serviceId}&token={$randomToken}") ); //@file_put_contents(FCPATH . 'tele.txt', "URL is: " . base_url("/login/getTelegramLogin?service_id={$serviceId}&token={$randomToken}") . "\n\n\n" , FILE_APPEND); $buttons[$iCount++][] = array( 'text' => iconv('UCS-4LE', 'UTF-8', pack('V', 0x21A9)) . ' Back', 'callback_data' => "ImeiServiceInfo:Back:{$catId}"); //@file_put_contents(FCPATH . 'tele.txt', "keyboard-getImeiServiceInfo:" . print_r($buttons, true) . "\n", FILE_APPEND); // truncate string $stringCut = substr($rsPackage->MustRead, 0, 500); $endPoint = strrpos($stringCut, ' '); //if the string doesn't contain any space then it will cut without word basis. $serviceDescription = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0); $serviceDescription .= '...'; $keyboard = $this->makeInlineActionsKeyboard($buttons); //@file_put_contents(FCPATH . 'tele.txt', "BEFORE getServicePrice: serviceId=$serviceId\n", FILE_APPEND); $servicePrice = $this->getServicePrice(0, $this->userId, $serviceId); return $arrayResult = array('text' => "Service Name: <b>" . $rsPackage->PackageTitle . "</b>\n\n<b>Service Info</b>: " . html_entity_decode(strip_tags($serviceDescription)) . "\n\nTime Taken: <b>" . $rsPackage->TimeTaken . "</b>\n\nPrice: <b>" . $userCurrency->CurrencyAbb . " " . $packagePrice . "</b>", "keyboard" => $keyboard); } catch (Exception $e) { @file_put_contents(FCPATH . 'tele.txt', "getImeiServicesCategories function exception:\n\n\n" . print_r($e, true) . "\n", FILE_APPEND); } } public function getServerServiceInfo($serviceId, $catId) { $rsPackage = $this->User_model->get_log_packages($serviceId); //@file_put_contents(FCPATH . 'tele.txt', "keyboard:" . print_r($rsPackage, true) . "\n", FILE_APPEND); $iCount = 0; //@file_put_contents(FCPATH . 'tele.txt', "getting token:\n\n\n" , FILE_APPEND); try { $randomToken = $this->generate_one_time_token(); $buttons = array(); $buttons[$iCount++][] = array( 'text' => "Place Order", 'url' => base_url("/login/getTelegramLogin?service_id={$serviceId}&token={$randomToken}&type=2") ); //@file_put_contents(FCPATH . 'tele.txt', "URL is: " . base_url("/login/getTelegramLogin?service_id={$serviceId}&token={$randomToken}") . "\n\n\n" , FILE_APPEND); $buttons[$iCount++][] = array( 'text' => iconv('UCS-4LE', 'UTF-8', pack('V', 0x21A9)) . ' Back', 'callback_data' => "ServerServiceInfo:Back:{$catId}"); //@file_put_contents(FCPATH . 'tele.txt', "keyboard-getServerServiceInfo:" . print_r($buttons, true) . "\n", FILE_APPEND); // truncate string $stringCut = substr($rsPackage->LogPackageDetail, 0, 500); $endPoint = strrpos($stringCut, ' '); //if the string doesn't contain any space then it will cut without word basis. $serviceDescription = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0); $serviceDescription .= '...'; $keyboard = $this->makeInlineActionsKeyboard($buttons); //@file_put_contents(FCPATH . 'tele.txt', "BEFORE getServicePrice: serviceId=$serviceId\n", FILE_APPEND); //$servicePrice = $this->getServicePrice(2, $this->userId, $serviceId); $userCurrency = $this->User_model->getUserCurrency($userId); $default_currency = fetch_currency_data(); $packagePrice = getlogpackprice($userId, $serviceId, $default_currency->CurrencyId, null, $userCurrency->ConversionRate, 2); return $arrayResult = array('text' => "Service Name: <b>" . $rsPackage->LogPackageTitle . "</b>\n\n<b>Service Info</b>: " . html_entity_decode(strip_tags($serviceDescription)) . "\n\nTime Taken: <b>" . $rsPackage->DeliveryTime . "</b>\n\nPrice: <b>" . $userCurrency->CurrencyAbb . " " . $packagePrice . "</b>", "keyboard" => $keyboard); } catch (Exception $e) { @file_put_contents(FCPATH . 'tele.txt', "getImeiServicesCategories function exception:\n\n\n" . print_r($e, true) . "\n", FILE_APPEND); } } public function getImeiServices($catId) { $sType = 0; $rsIds = $this->User_model->search_get_cat_imei_services($catId); $strServiceIds = '0'; $buttons = array(); $iCount = 0; //@file_put_contents(FCPATH . 'tele.txt', "getting token:\n\n\n" , FILE_APPEND); $randomToken = $this->generate_one_time_token(); //@file_put_contents(FCPATH . 'tele.txt', "TOKEN:\n\n\n" . var_dump($randomToken) . "\n", FILE_APPEND); foreach ($rsIds as $row) { $strServiceIds .= ', ' . $row->PackageId; $buttons[$iCount++][] = array( 'text' => $row->PackageTitle, 'callback_data' => 'ImeiService:' . $row->PackageId . ":{$catId}" //'url' => base_url("/page/telegramorder?service_id={$row->PackageId}&token={$randomToken}") ); } $buttons[$iCount++][] = array( 'text' => iconv('UCS-4LE', 'UTF-8', pack('V', 0x21A9)) . ' Back', 'callback_data' => 'ImeiService:Back'); return $this->makeInlineActionsKeyboard($buttons); } public function getServerServices($catId) { //@file_put_contents(FCPATH . 'tele.txt', "In Get Server Services:\n\n\n" , FILE_APPEND); $sType = 0; $strPackIds = getUserPacksIds($this->userId, 2); $rsIds = search_cat_get_log_rsPackages($strPackIds,$catId); $strServiceIds = '0'; $buttons = array(); $iCount = 0; //@file_put_contents(FCPATH . 'tele.txt', "getting token:\n\n\n" , FILE_APPEND); $randomToken = $this->generate_one_time_token(); //@file_put_contents(FCPATH . 'tele.txt', "TOKEN:\n\n\n" . var_dump($randomToken) . "\n", FILE_APPEND); foreach ($rsIds as $row) { $strServiceIds .= ', ' . $row->PackageId; $buttons[$iCount++][] = array( 'text' => $row->LogPackageTitle, 'callback_data' => 'ServerService:' . $row->PackageId . ":{$catId}" //'url' => base_url("/page/telegramorder?service_id={$row->PackageId}&token={$randomToken}") ); } $buttons[$iCount++][] = array( 'text' => iconv('UCS-4LE', 'UTF-8', pack('V', 0x21A9)) . ' Back', 'callback_data' => 'ServerService:Back'); return $this->makeInlineActionsKeyboard($buttons); } public function getImeiServicesCategories() { try{ $categories = getServicesCategories(0,0,0); $reply = ' '; $buttons = []; $iCount = 0; foreach ($categories as $category) { $buttons[$iCount++][] = array( 'text' => $category->Category, 'callback_data' => 'imeiCat:' .$category->CategoryId ); //$buttons[] = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup([$newButton]); } $buttons[$iCount++][] = array( 'text' => iconv('UCS-4LE', 'UTF-8', pack('V', 0x274C)) . ' Close', 'callback_data' => 'imeiCat:Close'); //echo '<pre>'; //print_r($this->makeReplyKeyboardMarkup($buttons)); return $this->makeInlineActionsKeyboard($buttons); // return $buttons; } catch (Exception $e) { @file_put_contents(FCPATH . 'tele.txt', "getImeiServicesCategories function exception:\n\n\n" . print_r($e, true) . "\n", FILE_APPEND); } } public function getServerServicesCategories() { try{ $categories = getServicesCategories(1,0,0); $reply = ' '; $buttons = []; $iCount = 0; foreach ($categories as $category) { $buttons[$iCount++][] = array( 'text' => $category->Category, 'callback_data' => 'ServerCat:' .$category->CategoryId ); //$buttons[] = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup([$newButton]); } $buttons[$iCount++][] = array( 'text' => iconv('UCS-4LE', 'UTF-8', pack('V', 0x274C)) . ' Close', 'callback_data' => 'ServerCat:Close'); //echo '<pre>'; //print_r($this->makeReplyKeyboardMarkup($buttons)); return $this->makeInlineActionsKeyboard($buttons); // return $buttons; } catch (Exception $e) { @file_put_contents(FCPATH . 'tele.txt', "getServerServicesCategories function exception:\n\n\n" . print_r($e, true) . "\n", FILE_APPEND); } } private function makeInlineActionsKeyboard($buttons = array()) { // return new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup( // [ // [ // ['text' => 'link', 'url' => 'https://core.telegram.org'] // ] // ] // ); return new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup( $buttons ); } private function makeReplyKeyboardMarkup($buttons = array()) { // return new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup( // [ // [ // ['text' => 'link', 'url' => 'https://core.telegram.org'] // ] // ] // ); $keyboardMarkup = array(); foreach($buttons as $button) { $keyboardMarkup[] = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup([$button]); } $keyboard = array( array( array('text'=>'text1','callback_data'=>"1") ,array('text'=>'text2','callback_data'=>"2") ), array( array('text'=>'start','callback_data'=>"4") ) ); foreach($keyboard as $keys) { $keyboardMarkup[] = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup([$keys]); } $inlineKeyboardMarkup = array( 'inline_keyboard' => $keyboard ); return $keyboardMarkup; //return $keyboardMarkup[0]; } private function cleanEmojis($text) { // $text = preg_replace('/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}]+/u', '', $text); // return trim($text); preg_match('/[A-z0-9\s\/]+/', $text, $grps); return trim($grps[0]); } private function makePairAccountKeyboard($oneTimeKeyboard = false) { return new \TelegramBot\Api\Types\ReplyKeyboardMarkup([['Pair Account']], $oneTimeKeyboard, true); } private function commandsList(&$reply = '') { $reply = "/start - To pair your account\n"; $reply .= "/unpair - To unpair your linked account\n"; $reply .= "\n"; $reply .= "/me - get your account info\n"; $reply .= "/NewImeiOrders - Place new IMEI Order\n"; $reply .= "/NewServerOrders - Place new Server Order\n"; $reply .= "/imeiorders - get last 10 IMEI orders\n"; $reply .= "/serverorders - get last 10 Server orders\n"; $reply .= "/checkimei 111111111111119 - check status by imei number\n"; $reply .= "/checkserver 213456 - check status by server order id\n"; $reply .= "/help - To get list of all commands\n"; if (!(!isset($this->rsStngs->Brnd) || empty($this->rsStngs->Brnd))) { $reply .= "<i>Powered By GSM Tool</i>"; } return $reply; } private function makeActionsKeyboard($oneTimeKeyboard = false) { return new \TelegramBot\Api\Types\ReplyKeyboardMarkup([["\xF0\x9F\x93\x85 IMEI Orders", "\xF0\x9F\x93\x85 Server Orders"], ["\xF0\x9F\x86\x95 New IMEI Order", "\xF0\x9F\x86\x95 New Server Order"],["\xF0\x9F\x91\xA4 My Account", "\xE2\x84\xB9 Help"]], $oneTimeKeyboard, true); } private function getServicePrice($serviceType, $userId, $packageId) { $PACK_PRICES_USER = array(); $PACK_PRICES_PLAN = array(); $PACK_PRICES_BASE = array(); try{ //@file_put_contents(FCPATH . 'tele.txt', "ServiceType: $serviceType userId: $userId PackageId: $packageId\n\n\n", FILE_APPEND); $userDetails = $this->User_model->getUserDetails($userId); $s_ids=getServiceIds($serviceType); $s_ids = explode(',' , $s_ids); $s_ids = array_map('trim', $s_ids); if($serviceType == 2){ $PACK_PRICES_USER = $this->User_model->get_log_pack_prices_user($this->user_id); $PACK_PRICES_PLAN = $this->User_model->get_log_pack_prices_plan($this->user_id, $userDetails->CurrencyId); $PACK_PRICES_BASE = $this->User_model->get_log_pack_prices_base($userDetails->CurrencyId, $userDetails->ConversionRate); }else{ $PACK_PRICES_USER = $this->User_model->get_pack_prices_user($this->user_id , $s_ids); $PACK_PRICES_PLAN = $this->User_model->get_pack_prices_plan($serviceType , $s_ids , $userDetails->CurrencyId); $PACK_PRICES_BASE = $this->User_model->get_pack_prices_base($serviceType , $s_ids , $userDetails->CurrencyId, $userDetails->ConversionRate); } //@file_put_contents(FCPATH . 'tele.txt', "User details:\n\n\n" . print_r($userDetails, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "User Package:\n\n\n" . print_r($PACK_PRICES_USER, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "Plan Package:\n\n\n" . print_r($PACK_PRICES_PLAN, true) . "\n", FILE_APPEND); //@file_put_contents(FCPATH . 'tele.txt', "Base Package:\n\n\n" . print_r($PACK_PRICES_BASE, true) . "\n", FILE_APPEND); $myPackPrice = 0; if(isset($PACK_PRICES_USER[$packageId])) $myPackPrice = $PACK_PRICES_USER[$packageId]; else if(isset($PACK_PRICES_PLAN[$row->PackageId])) $myPackPrice = $PACK_PRICES_PLAN[$packageId]; else { if (isset($PACK_PRICES_BASE[$packageId])) $myPackPrice = $PACK_PRICES_BASE[$packageId]; } return $myPackPrice; } catch (Exception $e) { @file_put_contents(FCPATH . 'tele.txt', "getServicePrice function exception:\n\n\n" . print_r($e, true) . "\n", FILE_APPEND); } } public function delete_tele_user($id=null){ //d($_REQUEST); $this->db->where('id', $id)->delete('tbl_gf_telegram_auth'); echo json_encode(["status" => 1, "id" => $id]); die; } }