[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
// we will have two since we are not using 'other' argument yet
// see if version is before or after the name
if (strripos($agent, "Version") < strripos($agent, $userBrowser)) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
}
} else {
$version = $matches['version'][0];
}
// check if we have a number
if ($version == null || $version == "") {
$version = "?";
}
return [
'name' => $browserName,
'version' => $version,
'platform' => $platform,
];
}
function getBrowserFingerprint($user_id, $browser_fingerprint)
{
$getBrowserFingerprint = App\Models\DeviceLog::where(['user_id' => $user_id, 'browser_fingerprint' => $browser_fingerprint])->first(['browser_fingerprint']);
return $getBrowserFingerprint;
}
function coinPaymentInfo()
{
$transInfo = session('transInfo');
$cpm = \App\Models\CurrencyPaymentMethod::where(['method_id' => $transInfo['payment_method'], 'currency_id' => $transInfo['currency_id']])->first(['method_data']);
return json_decode($cpm->method_data);
}
function captchaCheck($enabledCaptcha, $key)
{
if (isset($enabledCaptcha) && ($enabledCaptcha == 'login' || $enabledCaptcha == 'registration' || $enabledCaptcha == 'login_and_registration')) {
\Illuminate\Support\Facades\Config::set([(($key == 'site_key') ? 'captcha.sitekey' : 'captcha.secret') => settings($key)]);
}
}
function getLanguageDefault()
{
return \App\Models\Language::where(['default' => '1'])->first(['id', 'short_name']);
}
function getDefaultCountry()
{
return \App\Models\Country::where(['is_default' => 'yes'])->first()->short_name;
}
function phpDefaultTimeZones()
{
$zones_array = array();
$timestamp = time();
foreach (timezone_identifiers_list() as $key => $zone)
{
date_default_timezone_set($zone);
$zones_array[$key]['zone'] = $zone;
$zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
}
return $zones_array;
}
function getAuthUserIdentity()
{
$getAuthUserIdentity = \App\Models\DocumentVerification::where(['user_id' => auth()->user()->id, 'verification_type' => 'identity'])->first(['verification_type', 'status']);
return $getAuthUserIdentity;
}
function getAuthUserAddress()
{
$getAuthUserAddress = \App\Models\DocumentVerification::where(['user_id' => auth()->user()->id, 'verification_type' => 'address'])->first(['verification_type', 'status']);
return $getAuthUserAddress;
}
function allowedDecimalPlaceMessage($decimalPosition)
{
$message = "*Allowed upto " . $decimalPosition . " decimal places.";
return $message;
}
function allowedImageDimension($width, $height, $panel = null)
{
if ($panel == 'user')
{
$message = "*" . __('Recommended Dimension') . ": " . $width . " px * " . $height . " px";
}
else
{
$message = "*Recommended Dimension: " . $width . " px * " . $height . " px";
}
return $message;
}
/**
* [CUSTOM AES-256 ENCRYPTION/DECRYPTION METHOD]
* param $action [encrypt/decrypt]
* param $string [string]
*/
function initAES256($action, $plaintext)
{
$output = '';
$cipher = "AES-256-CBC";
$password = 'K8m26hzj22TtZxnzX96vmRAVTzPxNXRB';
$key = substr(hash('sha256', $password, true), 0, 32); // Must be exact 32 chars (256 bit)
// $ivlen = openssl_cipher_iv_length($cipher);
// $iv = openssl_random_pseudo_bytes($ivlen); // IV must be exact 16 chars (128 bit)
$secretIv = 'UP4n2cr8Bwn83X4h';
$iv = substr(hash('sha256', $secretIv), 0, 16);
if ($plaintext != '')
{
if ($action == 'encrypt')
{
$output = base64_encode(openssl_encrypt($plaintext, $cipher, $key, OPENSSL_RAW_DATA, $iv));
}
if ($action == 'decrypt')
{
$output = openssl_decrypt(base64_decode($plaintext), $cipher, $key, OPENSSL_RAW_DATA, $iv);
}
}
return $output;
}
function getFormatedCurrencyList($rates, $rateAmount)
{
foreach ($rates as $coin => $coinDetails) {
if ((INT) $coinDetails['is_fiat'] === 0) {
if ($rates[$coin]['rate_btc'] != 0) {
$rate = ($rateAmount / $rates[$coin]['rate_btc']);
}
else {
$rate = $rateAmount;
}
$coins[] = [
'name' => $coinDetails['name'],
'rate' => number_format($rate, 8, '.', ''),
'iso' => $coin,
'icon' => 'https://www.coinpayments.net/images/coins/' . $coin . '.png',
'selected' => $coin == 'BTC' ? true : false,
'accepted' => $coinDetails['accepted'],
];
$aliases[$coin] = $coinDetails['name'];
}
if ((INT) $coinDetails['is_fiat'] === 0 && $coinDetails['accepted'] == 1) {
$renamedCoin = explode('.', $coin);
$rate = ($rateAmount / $rates[$coin]['rate_btc']);
$coins_accept[] = [
'name' => $coinDetails['name'],
'rate' => number_format($rate, 8, '.', ''),
'iso' => $coin,
'icon' => 'https://www.coinpayments.net/images/coins/' . ((count($renamedCoin) > 1) ? $renamedCoin[0] : $coin) . '.png',
'selected' => $coin == 'BTC' ? true : false,
'accepted' => $coinDetails['accepted'],
];
}
if ((INT) $coinDetails['is_fiat'] === 1) {
$fiat[$coin] = $coinDetails;
}
}
return ['coins' => $coins, 'coins_accept' => $coins_accept, 'fiat' => $fiat, 'aliases' => $aliases];
}
/**
* [CUSTOM AES-256 ENCRYPTION/DECRYPTION METHOD]
* param $action [encrypt/decrypt]
* param $string [string]
*/
function convert_string($action, $string) {
$output = '';
$encrypt_method = "AES-256-CBC";
$secret_key = 'XXD93D945143F656DD9094450F802743F5457551991C8CXX';
$secret_iv = 'XXE8327B11DA84769CB73FE4495C63XX';
// hash
$key = hash('sha256', $secret_key);
$initialization_vector = substr(hash('sha256', $secret_iv), 0, 16);
if ($string != '') {
if ($action == 'encrypt') {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $initialization_vector);
$output = base64_encode($output);
} if ($action == 'decrypt') {
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $initialization_vector);
}
}
return $output;
}
if (!function_exists('getStatuses')) {
/**
* Return status, class, colors
*
* @return string
*/
function getStatuses()
{
return [
'success' => ['text' => __('Success'), 'label' => 'success', 'color' => 'green'],
'pending' => ['text' => __('Pending'), 'label' => 'primary', 'color' => 'blue'],
'refund' => ['text' => __('Refunded'), 'label' => 'warning', 'color' => 'orange'],
'blocked' => ['text' => __('Cancelled'), 'label' => 'danger', 'color' => 'red'],
'active' => ['text' => __('Active'), 'label' => 'success', 'color' => 'green'],
'inactive' => ['text' => __('Inactive'), 'label' => 'danger', 'color' => 'red'],
'suspended' => ['text' => __('Suspended'), 'label' => 'warning', 'color' => 'orange'],
'open' => ['text' => __('Open'), 'label' => 'success', 'color' => 'green'],
'in progress' => ['text' => __('In Progress'), 'label' => 'primary', 'color' => 'blue'],
'hold' => ['text' => __('Hold'), 'label' => 'warning', 'color' => 'orange'],
'closed' => ['text' => __('Closed'), 'label' => 'danger', 'color' => 'red'],
'approved' => ['text' => __('Approved'), 'label' => 'success', 'color' => 'green'],
'rejected' => ['text' => __('Rejected'), 'label' => 'danger', 'color' => 'red'],
'solve' => ['text' => __('Solved'), 'label' => 'success', 'color' => 'green'],
'moderation' => ['text' => __('Moderation'), 'label' => 'primary', 'color' => 'blue'],
'disapproved' => ['text' => __('Disapproved'), 'label' => 'danger', 'color' => 'red'],
'draft' => ['text' => __('Draft'), 'label' => 'default', 'color' => 'default'],
'cancelled' => ['text' => __('Cancelled'), 'label' => 'danger', 'color' => 'red'],
'completed' => ['text' => __('Completed'), 'label' => 'info', 'color' => 'blue'],
];
}
}
if (!function_exists('getStatus')) {
/**
* Get transactions status by HTML Lable
*
* @param string $status
*
* @return HTMLString
*/
function getStatus($status = null)
{
if (empty($status)) {
return '';
}
$statuses = getStatuses();
$status = strtolower($status);
return $statuses[$status]['text'];
}
}
if (!function_exists('getStatusLabel')) {
/**
* Get transactions status by HTML Lable
*
* @param string $status
*
* @return HTMLString
*/
function getStatusLabel($status = null)
{
if (empty($status)) {
return '';
}
$statuses = getStatuses();
$status = strtolower($status);
return '' . $statuses[$status]['text'] . '';
}
}
if (!function_exists('getStatusBadge')) {
/**
* Get transactions status by HTML Lable
*
* @param string $status
*
* @return HTMLString
*/
function getStatusBadge($status = null)
{
if (empty($status)) {
return '';
}
$statuses = getStatuses();
$status = strtolower($status);
return '' . $statuses[$status]['text'] . '';
}
}
if (!function_exists('getStatusText')) {
/**
* Get transactions status by HTML text
*
* @param string $status
*
* @return HTMLString
*/
function getStatusText($status = null)
{
if (empty($status)) {
return '';
}
$statuses = getStatuses();
$status = strtolower($status);
return '' . $statuses[$status]['text'] . '';
}
}
if (!function_exists('getStatusInputLabel')) {
/**
* Transaction edit sender-receiver Title Text
*
* @param string $type [TransactionTypeId like Deposit, Withdrawal]
* @param string $userType [user - receiver]
*
* @return HtmlString
*/
function getStatusInputLabel($type = null, $userType = null)
{
if (empty($type) || empty($userType)) {
return '';
}
$transactionTypes = [
Deposit => ['user' => 'User', 'receiver' => 'Receiver'],
Exchange_From => ['user' => 'User', 'receiver' => 'Receiver'],
Exchange_To => ['user' => 'User', 'receiver' => 'Receiver'],
Withdrawal => ['user' => 'User', 'receiver' => 'Receiver'],
Payment_Sent => ['user' => 'User', 'receiver' => 'Receiver'],
Payment_Received => ['user' => 'User', 'receiver' => 'Receiver'],
Transferred => ['user' => 'Paid By', 'receiver' => 'Paid To'],
Received => ['user' => 'Paid By', 'receiver' => 'Paid To'],
Request_Sent => ['user' => 'Request From', 'receiver' => 'Request To'],
Request_Received => ['user' => 'Request From', 'receiver' => 'Request To']
];
return '';
}
}
if (! function_exists('getPaymoneySettings')) {
/**
* Get Paymoney configurations info
*
* @param string $type
*
* @return array
*/
function getPaymoneySettings($type = null)
{
if (empty($type)) {
return false;
}
$array = [
'transaction_types' => [
'web' => [
'sent' => [Deposit, Transferred, Exchange_From, Exchange_To, Request_Sent, Withdrawal, Payment_Sent],
'received' => [Received, Request_Received, Payment_Received]
],
'mobile' => [
'sent' => ['Deposit' => Deposit, 'Transferred' => Transferred, 'Exchange_From' => Exchange_From, 'Exchange_To' => Exchange_To, 'Request_Sent' => Request_Sent, 'Withdrawal' => Withdrawal, 'Payment_Sent' => Payment_Sent],
'received' => ['Received' => Received, 'Request_Received' => Request_Received, 'Payment_Received' => Payment_Received]
],
],
'payment_methods' => [
'web' => [
'all' => [Mts, Stripe, Paypal, PayUmoney, Bank, Coinpayments, Payeer, Crypto],
'deposit' => [Mts, Stripe, Paypal, PayUmoney, Bank, Coinpayments, Payeer],
'withdrawal' => [Paypal, Bank, Crypto],
'fiat' => [
'deposit' => [Mts, Stripe, Paypal, PayUmoney, Bank, Coinpayments, Payeer],
'withdrawal' => [Mts, Paypal, Bank],
],
'crypto' => [
'deposit' => [Mts, Coinpayments],
'withdrawal' => [Mts, Crypto],
]
],
'mobile' => [
'all' => ['Stripe' => Stripe, 'Paypal' => Paypal, 'Bank' => Bank, 'Coinpayments' => Coinpayments, 'Crypto' => Crypto],
'deposit' => ['Stripe' => Stripe,'Paypal' => Paypal, 'Bank' => Bank, 'Coinpayments' => Coinpayments],
'withdrawal' => ['Paypal' => Paypal, 'Bank' => Bank, 'Crypto' => Crypto],
'fiat' => [
'deposit' => ['Stripe' => Stripe, 'Paypal' => Paypal, 'Bank' => Bank],
'withdrawal' => ['Paypal' => Paypal, 'Bank' => Bank],
],
'crypto' => [
'deposit' => ['Coinpayments' => Coinpayments],
'withdrawal' => ['Crypto' => Crypto],
]
]
]
];
// Module Transaction Types
$modules = getAllModules();
foreach ($modules as $module) {
if (!empty(config($module->get('alias') . '.transaction_type_settings'))) {
// Web
$array['transaction_types']['web']['sent'] = array_merge($array['transaction_types']['web']['sent'], config($module->get('alias') . '.transaction_type_settings')['web']['sent']);
$array['transaction_types']['web']['received'] = array_merge($array['transaction_types']['web']['received'], config($module->get('alias') . '.transaction_type_settings')['web']['received']);
// Mobile
$array['transaction_types']['mobile']['sent'] = array_merge($array['transaction_types']['mobile']['sent'], config($module->get('alias') . '.transaction_type_settings')['mobile']['sent']);
$array['transaction_types']['mobile']['received'] = array_merge($array['transaction_types']['mobile']['received'], config($module->get('alias') . '.transaction_type_settings')['mobile']['received']);
}
}
// Mobile MOney - Payment method
if (config('mobilemoney.is_active')) {
if (defined('MobileMoney')) {
$array['payment_methods']['web']['all'][] = MobileMoney;
$array['payment_methods']['web']['deposit'][] = MobileMoney;
$array['payment_methods']['web']['withdrawal'][] = MobileMoney;
$array['payment_methods']['web']['fiat']['deposit'][] = MobileMoney;
$array['payment_methods']['web']['fiat']['withdrawal'][] = MobileMoney;
}
}
// Transaction Types
$array['transaction_types']['web']['all'] = array_merge($array['transaction_types']['web']['sent'], $array['transaction_types']['web']['received']);
$array['transaction_types']['mobile']['all'] = array_merge($array['transaction_types']['mobile']['sent'], $array['transaction_types']['mobile']['received']);
return $array[$type];
}
}
if (!function_exists('preference')) {
/**
* Get preference values
*
* @param string $field [return specific value]
* @param string $default [take default value as optional if not provide]
*
* @return void
*/
function preference($field = null, $default = null)
{
$preference = new App\Models\Preference();
if (is_null($field)) {
return $preference->getAll()->pluck('value', 'field')->toArray();
}
$value = $default;
$preferences = $preference->getAll()->pluck('value', 'field')->toArray();
if (array_key_exists($field, $preferences)) {
$value = $preferences[$field];
}
return $value;
}
}
if (!function_exists('settings')) {
/**
* Get settings values
*
* @param string $field [return specific value, if don't match provide type values]
*
* @return string
* @return array
*/
function settings($field = null)
{
$setting = new App\Models\Setting();
if (is_null($field)) {
return $setting->getAll()->pluck('value', 'name')->toArray();
}
$settings = $setting->getAll()->pluck('value', 'name')->toArray();
if (array_key_exists($field, $settings)) {
$result = $settings[$field];
} else {
$result = $setting->getAll()->where('type', $field)->pluck('value', 'name')->toArray();
}
return $result;
}
}
if (!function_exists('isDefault')) {
/**
* Get is_default status by HTML Label
*
* @param string $status
*
* @return HTMLString
*/
function isDefault($status = null)
{
if (empty($status)) {
return '';
}
$statuses = [
'yes' => ['text' => __('Yes'), 'label' => 'success', 'color' => 'green'],
'no' => ['text' => __('No'), 'label' => 'danger', 'color' => 'red']
];
$status = strtolower($status);
return '' . $statuses[$status]['text'] . '';
}
}
function dataTableOptions(array $options = [])
{
$default = [
'order' => [[0, 'desc']],
'pageLength' => preference('row_per_page'),
'language' => preference('language'),
];
return array_merge($default, $options);
}
if (!function_exists('templateHeaderText')) {
/**
* Get Email or sms template header text
*
* @param string $heading
*
* @return String
*/
function templateHeaderText($heading)
{
$heading = str_replace('!', '', $heading);
if (str_contains($heading, 'Notice of ')) {
$heading = str_replace('Notice of ', '', $heading);
} else if (str_contains($heading, 'Notice for')) {
$heading = str_replace('Notice for ', '', $heading);
} else if (str_contains($heading, 'Notice to')) {
$heading = str_replace('Notice to ', '', $heading);
}
return __('Compose :x Template', ['x' => $heading]);
}
}
if (!function_exists('n_as_k_c')) {
function n_as_k_c() {
if(!g_e_v()) {
return true;
}
if(!g_c_v()) {
try {
$d_ = g_d();
$e_ = g_e_v();
$e_ = explode('.', $e_);
$c_ = md5($d_ . $e_[1]);
if($e_[0] == $c_) {
p_c_v();
return false;
} else {
return true;
}
} catch(\Exception $e) {
return true;
}
}
return false;
}
}
if (!function_exists('xss_clean')) {
function xss_clean($data)
{
// Fix &entity\n;
$data = str_replace(array('&','<','>'), array('&','<','>'), $data);
$data = preg_replace('/(*\w+)[\x00-\x20]+;/u', '$1;', $data);
$data = preg_replace('/(*[0-9A-F]+);*/iu', '$1;', $data);
$data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
// Remove javascript: and vbscript: protocols
$data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data);
// Only works in IE:
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data);
// Remove namespaced elements (we do not need them)
$data = preg_replace('#*\w+:\w[^>]*+>#i', '', $data);
do {
// Remove really unwanted tags
$old_data = $data;
$data = preg_replace('#*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
} while ($old_data !== $data);
return $data;
}
}
if (!function_exists('stripBeforeSave')) {
/**
* stripBeforeSave method
* This function strips or skips HTML tags
*
* @param string $string [The text that will be stripped]
* @param array $options
*
* @return string
*/
function stripBeforeSave($string = null, $options = ['skipAllTags' => true, 'mergeTags' => false])
{
$finalString = [];
if ($options['skipAllTags'] === false) {
$allow = '