2022-09-10 16:08:10 +07:00
< ? php
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing ( https :// github . com / hotspotbilling / phpnuxbill / )
* by https :// t . me / ibnux
2022-09-10 16:08:10 +07:00
**/
2023-10-12 15:55:42 +07:00
2023-08-09 10:49:29 +07:00
class Lang
{
2024-02-13 13:54:01 +07:00
public static function T ( $key )
2023-08-09 10:49:29 +07:00
{
2024-02-13 13:54:01 +07:00
global $_L , $lan_file , $config ;
$L = $_SESSION [ 'Lang' ];
if ( ! empty ( $_L [ $key ])) {
return $_L [ $key ];
}
$val = $key ;
2024-02-13 17:41:55 +07:00
if ( isset ( $_L [ $key ])) {
return $_L [ $key ];
} else if ( isset ( $_L [ $key ])) {
2024-02-13 13:54:01 +07:00
return $_L [ $key ];
} else {
$iso = Lang :: getIsoLang ()[ $config [ 'language' ]];
2024-02-13 17:41:55 +07:00
if ( empty ( $iso )){
return $val ;
}
2024-02-13 13:54:01 +07:00
if ( ! empty ( $iso ) && ! empty ( $val )){
$temp = Lang :: translate ( $val , $iso );
if ( ! empty ( $temp )){
$val = $temp ;
}
}
$_L [ $key ] = $val ;
$_SESSION [ 'Lang' ][ $key ] = $val ;
2024-02-13 17:41:55 +07:00
file_put_contents ( $lan_file , json_encode ( $_SESSION [ 'Lang' ], JSON_PRETTY_PRINT ));
2024-02-13 13:54:01 +07:00
return $val ;
}
}
public static function getIsoLang (){
global $isolang ;
if ( empty ( $isolang ) || count ( $isolang ) == 0 ){
$isolang = json_decode ( file_get_contents ( File :: pathFixer ( " system/lan/country.json " )), true );
}
return $isolang ;
2022-09-10 16:08:10 +07:00
}
2023-03-06 14:51:05 +07:00
2023-08-09 10:49:29 +07:00
public static function htmlspecialchars ( $var )
{
2023-03-06 14:51:05 +07:00
return htmlspecialchars ( $var );
}
2023-08-09 10:49:29 +07:00
public static function moneyFormat ( $var )
{
global $config ;
2023-10-04 17:07:13 +07:00
return $config [ 'currency_code' ] . ' ' . number_format ( $var , 0 , $config [ 'dec_point' ], $config [ 'thousands_sep' ]);
2023-08-09 10:49:29 +07:00
}
2023-08-09 14:54:38 +07:00
public static function phoneFormat ( $phone )
{
global $config ;
2023-10-04 17:07:13 +07:00
if ( Validator :: UnsignedNumber ( $phone ) && ! empty ( $config [ 'country_code_phone' ])) {
2023-08-09 14:54:38 +07:00
return preg_replace ( '/^0/' , $config [ 'country_code_phone' ], $phone );
2023-10-04 17:07:13 +07:00
} else {
2023-08-09 14:54:38 +07:00
return $phone ;
}
}
2023-08-21 17:09:44 +07:00
2023-10-04 17:07:13 +07:00
public static function dateFormat ( $date )
{
2023-08-21 17:09:44 +07:00
global $config ;
return date ( $config [ 'date_format' ], strtotime ( $date ));
}
2023-10-04 17:07:13 +07:00
public static function dateTimeFormat ( $date )
{
2023-08-21 17:09:44 +07:00
global $config ;
2023-10-04 17:07:13 +07:00
if ( strtotime ( $date ) < strtotime ( " 2000-01-01 00:00:00 " )) {
2023-09-01 09:16:40 +07:00
return " " ;
2023-10-04 17:07:13 +07:00
} else {
return date ( $config [ 'date_format' ] . ' H:i' , strtotime ( $date ));
2023-09-01 09:16:40 +07:00
}
2023-08-21 17:09:44 +07:00
}
2023-10-04 17:07:13 +07:00
public static function dateAndTimeFormat ( $date , $time )
{
2023-08-24 15:12:31 +07:00
global $config ;
2023-10-04 17:07:13 +07:00
return date ( $config [ 'date_format' ] . ' H:i' , strtotime ( " $date $time " ));
2023-08-24 15:12:31 +07:00
}
2024-02-07 13:32:33 +07:00
public static function timeElapsed ( $time ){
$s = $time % 60 ;
$m = floor (( $time % 3600 ) / 60 );
$h = floor (( $time % 86400 ) / 3600 );
$d = floor (( $time % 2592000 ) / 86400 );
$M = floor ( $time / 2592000 );
$result = '' ;
if ( $M > 0 ){
$result = $M . 'm ' ;
}
if ( $d > 0 ){
$result .= $d . 'd ' ;
} else if ( $M > 0 ){
$result .= '0d ' ;
}
return " $result $h : $m : $s " ;
}
2023-10-04 17:07:13 +07:00
public static function nl2br ( $text )
{
2023-08-21 17:09:44 +07:00
return nl2br ( $text );
}
2023-10-04 17:07:13 +07:00
public static function arrayCount ( $arr )
{
if ( is_array ( $arr )) {
return count ( $arr );
} else if ( is_object ( $arr )) {
2023-09-26 13:50:02 +07:00
return count ( $arr );
2023-10-04 17:07:13 +07:00
} else {
2023-09-26 13:50:02 +07:00
return 0 ;
}
2023-08-21 17:09:44 +07:00
}
2023-08-24 11:35:23 +07:00
2023-10-04 17:07:13 +07:00
public static function getNotifText ( $key )
{
2023-08-24 11:35:23 +07:00
global $_notifmsg , $_notifmsg_default ;
2023-10-04 17:07:13 +07:00
if ( isset ( $_notifmsg [ $key ])) {
2023-08-24 11:35:23 +07:00
return $_notifmsg [ $key ];
2023-10-04 17:07:13 +07:00
} else {
2023-08-24 11:35:23 +07:00
return $_notifmsg_default [ $key ];
}
}
2023-10-12 16:15:50 +07:00
public static function ucWords ( $text )
{
return ucwords ( str_replace ( '_' , ' ' , $text ));
}
2023-10-18 17:23:47 +07:00
public static function randomUpLowCase ( $text ){
$jml = strlen ( $text );
$result = '' ;
for ( $i = 0 ; $i < $jml ; $i ++ ){
if ( rand ( 0 , 99 ) % 2 ){
$result .= strtolower ( substr ( $text , $i , 1 ));
} else {
$result .= substr ( $text , $i , 1 );
}
}
return $result ;
}
2024-01-16 10:32:59 +07:00
/**
* $pad_type
* 0 Left
* 1 right
* 2 center
* */
public static function pad ( $text , $pad_string = ' ' , $pad_type = 0 ){
global $config ;
$cols = 37 ;
if ( $config [ 'printer_cols' ]){
$cols = $config [ 'printer_cols' ];
}
2024-01-16 11:41:12 +07:00
$text = trim ( $text );
$texts = explode ( " \n " , $text );
if ( count ( $texts ) > 1 ){
$text = '' ;
foreach ( $texts as $t ){
$text .= self :: pad ( trim ( $t ), $pad_string , $pad_type ) . " \n " ;
}
return $text ;
} else {
return str_pad ( trim ( $text ), $cols , $pad_string , $pad_type );
}
2024-01-16 10:32:59 +07:00
}
public static function pads ( $textLeft , $textRight , $pad_string = ' ' ){
global $config ;
$cols = 37 ;
if ( $config [ 'printer_cols' ]){
$cols = $config [ 'printer_cols' ];
}
return $textLeft . str_pad ( $textRight , $cols - strlen ( $textLeft ), $pad_string , 0 );
}
2024-02-13 13:54:01 +07:00
public static function translate ( $txt , $to = 'id' ){
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , " https://translate.google.com/m?hl=en&sl=en&tl= $to &ie=UTF-8&prev=_m&q= " . urlencode ( $txt ));
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt ( $ch , CURLOPT_USERAGENT , " Mozilla/5.0 (iPhone; CPU OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/28.1 Mobile/15E148 Safari/605.1.15 " );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , 2 );
2024-02-15 16:13:55 +07:00
curl_setopt ( $ch , CURLOPT_TIMEOUT , 5 );
2024-02-13 13:54:01 +07:00
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
$hasil = curl_exec ( $ch );
curl_close ( $ch );
$temp = explode ( '<div class="result-container">' , $hasil );
if ( count ( $temp ) > 0 ){
$temp = explode ( " </div " , $temp [ 1 ]);
if ( ! empty ( $temp [ 0 ])){
return $temp [ 0 ];
}
}
return $txt ;
}
2022-09-10 16:08:10 +07:00
}